LeechCraft
0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
Toggle main menu visibility
Loading...
Searching...
No Matches
modelitem.cpp
Go to the documentation of this file.
1
/**********************************************************************
2
* LeechCraft - modular cross-platform feature rich internet client.
3
* Copyright (C) 2006-2014 Georg Rudoy
4
*
5
* Distributed under the Boost Software License, Version 1.0.
6
* (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7
**********************************************************************/
8
9
#include "
modelitem.h
"
10
#include <algorithm>
11
12
namespace
LC::Util
13
{
14
ModelItem::ModelItem
(QAbstractItemModel *model,
const
QModelIndex& idx,
const
ModelItem_wtr
& parent)
15
:
ModelItemBase
{ parent }
16
, Model_ { model }
17
, SrcIdx_ { idx }
18
{
19
}
20
21
ModelItem
*
ModelItem::EnsureChild
(
int
row)
22
{
23
if
(
Children_
.value (row))
24
return
Children_
.at (row).get ();
25
26
if
(
Children_
.size () <= row)
27
Children_
.resize (row + 1);
28
29
const
auto
& childIdx = Model_->index (row, 0, SrcIdx_);
30
Children_
[row] = std::make_shared<ModelItem> (Model_, childIdx, shared_from_this ());
31
return
Children_
.at (row).get ();
32
}
33
34
const
QModelIndex&
ModelItem::GetIndex
()
const
35
{
36
return
SrcIdx_;
37
}
38
39
void
ModelItem::RefreshIndex
(
int
modelStartingRow)
40
{
41
if
(SrcIdx_.isValid ())
42
SrcIdx_ = Model_->index (
GetRow
() - modelStartingRow, 0,
Parent_
.lock ()->GetIndex ());
43
}
44
45
QAbstractItemModel*
ModelItem::GetModel
()
const
46
{
47
return
Model_;
48
}
49
50
ModelItem_ptr
ModelItem::FindChild
(QModelIndex index)
const
51
{
52
index = index.sibling (index.row (), 0);
53
54
const
auto
pos = std::find_if (
Children_
.begin (),
Children_
.end (),
55
[&index] (
const
ModelItem_ptr
& item) { return item->GetIndex () == index; });
56
return
pos ==
Children_
.end () ?
ModelItem_ptr
{} : *pos;
57
}
58
}
LC::Util::ModelItemBase< ModelItem >::Parent_
T_wptr Parent_
Definition
modelitembase.h:54
LC::Util::ModelItemBase< ModelItem >::ModelItemBase
ModelItemBase()=default
LC::Util::ModelItemBase< ModelItem >::GetRow
int GetRow(const T_ptr &item) const
Definition
modelitembase.h:295
LC::Util::ModelItemBase< ModelItem >::Children_
TList_t Children_
Definition
modelitembase.h:55
LC::Util::ModelItem::EnsureChild
ModelItem * EnsureChild(int row)
Ensures there is a child item at the given row.
Definition
modelitem.cpp:21
LC::Util::ModelItem::GetModel
QAbstractItemModel * GetModel() const
Returns the wrapped model.
Definition
modelitem.cpp:45
LC::Util::ModelItem::ModelItem
ModelItem()=default
Constructs a default (invalid) ModelItem having no model set.
LC::Util::ModelItem::RefreshIndex
void RefreshIndex(int modelStartingRow)
Updates the wrapped index so that it points at the given row.
Definition
modelitem.cpp:39
LC::Util::ModelItem::GetIndex
const QModelIndex & GetIndex() const
Returns the index this ModelItem instance wraps.
Definition
modelitem.cpp:34
LC::Util::ModelItem::FindChild
ModelItem_ptr FindChild(QModelIndex index) const
Finds a child item for the given index.
Definition
modelitem.cpp:50
modelitem.h
LC::Util
Definition
icoreproxy.h:34
LC::Util::ModelItem_ptr
std::shared_ptr< ModelItem > ModelItem_ptr
Definition
modelitem.h:19
LC::Util::ModelItem_wtr
std::weak_ptr< ModelItem > ModelItem_wtr
Definition
modelitem.h:20
src
util
models
modelitem.cpp
Generated by
1.17.0