summaryrefslogtreecommitdiff
path: root/src/backend/bookshelfmodel/btbookshelftreemodel.h
diff options
context:
space:
mode:
authorRoberto C. Sanchez <roberto@connexer.com>2014-10-21 22:48:27 -0400
committerRoberto C. Sanchez <roberto@connexer.com>2014-10-21 22:48:27 -0400
commitdd2f7ce46df53f2c377c02d1bf4df8adcf092072 (patch)
tree51d4bd5d66a45a24784695c4e99b452b417dc3d1 /src/backend/bookshelfmodel/btbookshelftreemodel.h
parentb954e6dbcceaba3b50aca624e1bddc6db4830829 (diff)
Imported Upstream version 2.3
Diffstat (limited to 'src/backend/bookshelfmodel/btbookshelftreemodel.h')
-rw-r--r--src/backend/bookshelfmodel/btbookshelftreemodel.h114
1 files changed, 114 insertions, 0 deletions
diff --git a/src/backend/bookshelfmodel/btbookshelftreemodel.h b/src/backend/bookshelfmodel/btbookshelftreemodel.h
new file mode 100644
index 0000000..0a84ac3
--- /dev/null
+++ b/src/backend/bookshelfmodel/btbookshelftreemodel.h
@@ -0,0 +1,114 @@
+/*********
+*
+* In the name of the Father, and of the Son, and of the Holy Spirit.
+*
+* This file is part of BibleTime's source code, http://www.bibletime.info/.
+*
+* Copyright 1999-2009 by the BibleTime developers.
+* The BibleTime source code is licensed under the GNU General Public License
+* version 2.0.
+*
+**********/
+
+#ifndef BTBOOKSHELFTREEMODEL_H
+#define BTBOOKSHELFTREEMODEL_H
+
+#include <QAbstractItemModel>
+
+#include <QMap>
+#include "backend/bookshelfmodel/btbookshelfmodel.h"
+#include "backend/bookshelfmodel/item.h"
+
+namespace BookshelfModel {
+ class ModuleItem;
+}
+class CSwordModuleInfo;
+
+class BtBookshelfTreeModel: public QAbstractItemModel {
+ Q_OBJECT
+
+ typedef QMap<CSwordModuleInfo*, BookshelfModel::ModuleItem*> ModuleItemMap;
+
+ public:
+ enum ModuleRole {
+ CheckStateRole = BtBookshelfModel::UserRole,
+ UserRole = BtBookshelfModel::UserRole + 100
+ };
+ enum Group { GROUP_CATEGORY, GROUP_LANGUAGE, GROUP_DISTRIBUTION };
+ typedef QList<Group> Grouping;
+
+ BtBookshelfTreeModel(QObject *parent = 0);
+ virtual ~BtBookshelfTreeModel();
+
+ virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ virtual int columnCount(const QModelIndex &parent = QModelIndex())
+ const;
+ virtual bool hasChildren(const QModelIndex &parent = QModelIndex())
+ const;
+ virtual QModelIndex index(int row, int column,
+ const QModelIndex &parent = QModelIndex())
+ const;
+ virtual QModelIndex parent(const QModelIndex &index) const;
+ virtual QVariant data(const QModelIndex &index, int role) const;
+ virtual Qt::ItemFlags flags(const QModelIndex &index) const;
+ virtual QVariant headerData(int section, Qt::Orientation orientation,
+ int role = Qt::DisplayRole) const;
+ virtual bool setData(const QModelIndex &index, const QVariant &value,
+ int role);
+
+ void setSourceModel(QAbstractListModel *sourceModel);
+ inline QAbstractListModel *sourceModel() const { return m_sourceModel; }
+ void setGroupingOrder(const Grouping &groupingOrder);
+ inline Grouping groupingOrder() const { return m_groupingOrder; }
+ void setCheckable(bool checkable);
+ inline bool checkable() const { return m_checkable; }
+ inline void setDefaultChecked(bool defaultChecked) {
+ m_defaultChecked = defaultChecked;
+ }
+ inline bool defaultChecked() const { return m_defaultChecked; }
+
+ QList<CSwordModuleInfo*> checkedModules() const;
+
+ protected:
+ 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;
+ void resetParentCheckStates(QModelIndex parentIndex);
+
+ template <class T>
+ QModelIndex getGroup(CSwordModuleInfo *module,
+ QModelIndex parentIndex)
+ {
+ BookshelfModel::Item *parentItem(getItem(parentIndex));
+ int groupIndex;
+ T *groupItem(parentItem->getGroupItem<T>(module, &groupIndex));
+
+ if (groupItem == 0) {
+ groupItem = new T(module);
+ groupIndex = parentItem->indexFor(groupItem);
+ beginInsertRows(parentIndex, groupIndex, groupIndex);
+ parentItem->insertChild(groupIndex, groupItem);
+ endInsertRows();
+ }
+ return index(groupIndex, 0, parentIndex);
+ }
+
+ protected slots:
+ void moduleDataChanged(const QModelIndex &topLeft,
+ const QModelIndex &bottomRight);
+ void moduleInserted(const QModelIndex &parent, int start, int end);
+ void moduleRemoved(const QModelIndex &parent, int start, int end);
+
+ protected:
+ QAbstractListModel *m_sourceModel;
+ BookshelfModel::Item *m_rootItem;
+ ModuleItemMap m_modules;
+ Grouping m_groupingOrder;
+ bool m_checkable;
+ bool m_defaultChecked;
+};
+
+#endif // BTBOOKSHELFTREEMODEL_H