BibleTime
item.cpp
Go to the documentation of this file.
1/*********
2*
3* In the name of the Father, and of the Son, and of the Holy Spirit.
4*
5* This file is part of BibleTime's source code, https://bibletime.info/
6*
7* Copyright 1999-2025 by the BibleTime developers.
8* The BibleTime source code is licensed under the GNU General Public License
9* version 2.0.
10*
11**********/
12
13#include "item.h"
14
15#include <QtAlgorithms>
16#include <QString>
17#include "../../util/btassert.h"
18#include "btbookshelfmodel.h"
19
20
21namespace BookshelfModel {
22
24 qDeleteAll(m_children);
25}
26
27int Item::indexFor(Item const & newItem) {
28 if (m_children.empty())
29 return 0;
30
31 int i = 0;
32 for (;;) {
33 auto const & nextItem = *m_children.at(i);
34 BT_ASSERT(nextItem.type() == newItem.type());
35 if (newItem < nextItem)
36 return i;
37
38 i++;
39 if (i >= m_children.size())
40 return i;
41 }
42}
43
44QVariant Item::data(int const role) const {
45 switch (role) {
46
47 case Qt::CheckStateRole:
48 return m_checkState;
49
51 if (m_children.empty())
52 return true;
53
54 for (auto const * const child : m_children)
55 if (!child->data(role).toBool())
56 return false;
57 return true;
58
59 default:
60 return QVariant();
61
62 }
63}
64
65bool Item::operator<(Item const & other) const {
66 if (m_type != other.type())
67 return m_type < other.type();
68
69 auto const first(data(Qt::DisplayRole).toString().toLower());
70 auto const second(other.data(Qt::DisplayRole).toString().toLower());
71 return first.localeAwareCompare(second) < 0;
72}
73
74bool RootItem::fitFor(CSwordModuleInfo const &) const { return true; }
75
76} // namespace BookshelfModel
#define BT_ASSERT(...)
Definition btassert.h:17
Qt::CheckState m_checkState
Definition item.h:144
virtual QVariant data(int role=Qt::DisplayRole) const
Returns data for this item.
Definition item.cpp:44
int indexFor(Item const &newItem)
Returns the position for where the given child item would be inserted.
Definition item.cpp:27
virtual bool operator<(Item const &other) const
Comparsion operator used sorting child items.
Definition item.cpp:65
Type type() const
Returns the type of this item.
Definition item.h:49
virtual ~Item()
Definition item.cpp:23
QList< Item * > m_children
Definition item.h:143
bool fitFor(CSwordModuleInfo const &) const override
Returns whether this item is fit to contain the given module.
Definition item.cpp:74