15 #include <QAbstractItemModel>
21 #include <QModelIndex>
22 #include <QPersistentModelIndex>
26 #include "../drivers/btconstmoduleset.h"
27 #include "../drivers/btmoduleset.h"
43 using ModuleItemMap = QMap<CSwordModuleInfo *, BookshelfModel::ModuleItem *>;
101 QString
const & configKey,
106 int rowCount(
const QModelIndex &
parent = QModelIndex())
const override;
109 QModelIndex
index(
int row,
111 const QModelIndex &
parent = QModelIndex())
113 QModelIndex
parent(
const QModelIndex &
index)
const override;
114 QVariant
data(
const QModelIndex &
index,
int role = Qt::DisplayRole)
117 Qt::ItemFlags
flags(
const QModelIndex &
index)
const override;
119 Qt::Orientation orientation,
120 int role = Qt::DisplayRole)
const override;
122 const QVariant & value,
145 bool emitSignal =
true);
162 const QModelIndex & bottomRight);
170 QModelIndex parentIndex,
181 QModelIndex parentIndex)
189 groupIndex = parentItem.
indexFor(*groupItem);
190 beginInsertRows(parentIndex, groupIndex, groupIndex);
194 return index(groupIndex, 0, parentIndex);
QDataStream & operator<<(QDataStream &os, const BtBookshelfTreeModel::Grouping &o)
QDataStream & operator>>(QDataStream &is, BtBookshelfTreeModel::Grouping &o)
T * getGroupItem(CSwordModuleInfo &module, int &outIndex)
int indexFor(Item const &newItem)
Returns the position for where the given child item would be inserted.
void insertChild(int index, Item *newItem)
Inserts the given item as a child at the given index.
Grouping & operator=(Grouping const ©)=default
void saveTo(BtConfigCore &config, QString const &key) const
Grouping(Grouping const ©)=default
Grouping(bool empty=false)
Grouping(BtConfigCore const &config, QString const &key)
bool loadFrom(BtConfigCore const &config, QString const &key)
void moduleInserted(const QModelIndex &parent, int start, int end)
CheckedBehavior m_defaultChecked
QModelIndex getGroup(CSwordModuleInfo &module, QModelIndex parentIndex)
std::unique_ptr< BookshelfModel::Item > m_rootItem
void groupingOrderChanged(BtBookshelfTreeModel::Grouping newGrouping)
void removeModule(CSwordModuleInfo &module)
void resetParentCheckStates(QModelIndex parentIndex)
BtModuleSet m_checkedModulesCache
Qt::ItemFlags flags(const QModelIndex &index) const override
QModelIndex getIndex(const BookshelfModel::Item &item)
void moduleRemoved(const QModelIndex &parent, int start, int end)
QModelIndex parent(const QModelIndex &index) const override
BookshelfModel::Item & getItem(const QModelIndex &index) const
std::shared_ptr< QAbstractItemModel > m_sourceModel
void setDefaultChecked(CheckedBehavior b)
void setCheckable(bool checkable)
void setCheckedModules(BtConstModuleSet const &modules)
BtBookshelfTreeModel(QObject *parent=nullptr)
std::shared_ptr< QAbstractItemModel > sourceModel() const noexcept
bool setData(const QModelIndex &index, const QVariant &value, int role) override
QMap< CSwordModuleInfo *, QPersistentModelIndex > SourceIndexMap
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
~BtBookshelfTreeModel() override
void setGroupingOrder(const BtBookshelfTreeModel::Grouping &groupingOrder, bool emitSignal=true)
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
SourceIndexMap m_sourceIndexMap
BtModuleSet const & checkedModules() const
CheckedBehavior defaultChecked() const
Grouping const & groupingOrder() const
void moduleDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
QList< CSwordModuleInfo * > modules() const
int rowCount(const QModelIndex &parent=QModelIndex()) const override
bool hasChildren(const QModelIndex &parent=QModelIndex()) const override
void setSourceModel(std::shared_ptr< QAbstractItemModel > sourceModel)
CSwordModuleInfo * module(QModelIndex const &index) const
QMap< CSwordModuleInfo *, BookshelfModel::ModuleItem * > ModuleItemMap
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void moduleChecked(CSwordModuleInfo *module, bool checked)
void addModule(CSwordModuleInfo &module, bool checked)