diff options
Diffstat (limited to 'src/backend/bookshelfmodel/btbookshelftreemodel.h')
-rw-r--r-- | src/backend/bookshelfmodel/btbookshelftreemodel.h | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/backend/bookshelfmodel/btbookshelftreemodel.h b/src/backend/bookshelfmodel/btbookshelftreemodel.h index 84293e1..e73b154 100644 --- a/src/backend/bookshelfmodel/btbookshelftreemodel.h +++ b/src/backend/bookshelfmodel/btbookshelftreemodel.h @@ -16,9 +16,11 @@ #include <QAbstractItemModel> #include <QMap> +#include <QPersistentModelIndex> #include "backend/bookshelfmodel/btbookshelfmodel.h" #include "backend/bookshelfmodel/item.h" + namespace BookshelfModel { class ModuleItem; } @@ -30,6 +32,7 @@ class BtBookshelfTreeModel: public QAbstractItemModel { Q_ENUMS(Group) typedef QMap<CSwordModuleInfo*, BookshelfModel::ModuleItem*> ModuleItemMap; + typedef QMap<CSwordModuleInfo*, QPersistentModelIndex> SourceIndexMap; public: enum ModuleRole { @@ -37,6 +40,7 @@ class BtBookshelfTreeModel: public QAbstractItemModel { UserRole = BtBookshelfModel::UserRole + 100 }; enum Group { GROUP_CATEGORY = 0, GROUP_LANGUAGE, GROUP_DISTRIBUTION }; + enum CheckedBehavior { CHECKED, UNCHECKED, MODULE_HIDDEN }; typedef QList<Group> Grouping; BtBookshelfTreeModel(QObject *parent = 0); @@ -59,8 +63,8 @@ class BtBookshelfTreeModel: public QAbstractItemModel { virtual bool setData(const QModelIndex &index, const QVariant &value, int role); - void setSourceModel(QAbstractListModel *sourceModel); - inline QAbstractListModel *sourceModel() const { + void setSourceModel(QAbstractItemModel *sourceModel); + inline QAbstractItemModel *sourceModel() const { return m_sourceModel; } void setGroupingOrder(const Grouping &groupingOrder); @@ -71,22 +75,24 @@ class BtBookshelfTreeModel: public QAbstractItemModel { inline bool checkable() const { return m_checkable; } - inline void setDefaultChecked(bool defaultChecked) { - m_defaultChecked = defaultChecked; + inline void setDefaultChecked(CheckedBehavior b) { + m_defaultChecked = b; } - inline bool defaultChecked() const { + inline CheckedBehavior defaultChecked() const { return m_defaultChecked; } QList<CSwordModuleInfo*> checkedModules() const; protected: + QVariant parentData(BookshelfModel::ModuleItem *item, int role) const; void addModule(CSwordModuleInfo *module, bool checked); void addModule(CSwordModuleInfo *module, QModelIndex parentIndex, Grouping &intermediateGrouping, bool checked); void removeModule(CSwordModuleInfo *module); BookshelfModel::Item *getItem(const QModelIndex &index) const; + QModelIndex getIndex(const BookshelfModel::Item *item); void resetParentCheckStates(QModelIndex parentIndex); template <class T> @@ -112,13 +118,17 @@ class BtBookshelfTreeModel: public QAbstractItemModel { void moduleInserted(const QModelIndex &parent, int start, int end); void moduleRemoved(const QModelIndex &parent, int start, int end); + signals: + void moduleChecked(CSwordModuleInfo *module, bool checked); + protected: - QAbstractListModel *m_sourceModel; + QAbstractItemModel *m_sourceModel; BookshelfModel::Item *m_rootItem; ModuleItemMap m_modules; + SourceIndexMap m_sourceIndexMap; Grouping m_groupingOrder; + CheckedBehavior m_defaultChecked; bool m_checkable; - bool m_defaultChecked; }; QDataStream &operator<<(QDataStream &os, const BtBookshelfTreeModel::Grouping &o); |