diff options
author | Roberto C. Sanchez <roberto@connexer.com> | 2014-10-21 22:48:35 -0400 |
---|---|---|
committer | Roberto C. Sanchez <roberto@connexer.com> | 2014-10-21 22:48:35 -0400 |
commit | df8f1d512c60a96f9041f9663b3fdc2db51cba33 (patch) | |
tree | 3d2bdbd4732d417aca73be022ae9044eac96b7d3 /src/backend/bookshelfmodel | |
parent | 4885bfcef4d89cf0cb391e00af617b9fd19c9cbb (diff) |
Imported Upstream version 2.8.1
Diffstat (limited to 'src/backend/bookshelfmodel')
-rw-r--r-- | src/backend/bookshelfmodel/btbookshelffiltermodel.cpp | 23 | ||||
-rw-r--r-- | src/backend/bookshelfmodel/btbookshelffiltermodel.h | 2 | ||||
-rw-r--r-- | src/backend/bookshelfmodel/btbookshelfmodel.cpp | 125 | ||||
-rw-r--r-- | src/backend/bookshelfmodel/btbookshelfmodel.h | 110 | ||||
-rw-r--r-- | src/backend/bookshelfmodel/btbookshelftreemodel.cpp | 79 | ||||
-rw-r--r-- | src/backend/bookshelfmodel/btbookshelftreemodel.h | 64 | ||||
-rw-r--r-- | src/backend/bookshelfmodel/categoryitem.cpp | 6 | ||||
-rw-r--r-- | src/backend/bookshelfmodel/categoryitem.h | 2 | ||||
-rw-r--r-- | src/backend/bookshelfmodel/indexingitem.cpp | 2 | ||||
-rw-r--r-- | src/backend/bookshelfmodel/indexingitem.h | 2 | ||||
-rw-r--r-- | src/backend/bookshelfmodel/item.cpp | 2 | ||||
-rw-r--r-- | src/backend/bookshelfmodel/item.h | 2 | ||||
-rw-r--r-- | src/backend/bookshelfmodel/languageitem.cpp | 4 | ||||
-rw-r--r-- | src/backend/bookshelfmodel/languageitem.h | 2 | ||||
-rw-r--r-- | src/backend/bookshelfmodel/moduleitem.cpp | 2 | ||||
-rw-r--r-- | src/backend/bookshelfmodel/moduleitem.h | 8 |
16 files changed, 246 insertions, 189 deletions
diff --git a/src/backend/bookshelfmodel/btbookshelffiltermodel.cpp b/src/backend/bookshelfmodel/btbookshelffiltermodel.cpp index b896556..182d337 100644 --- a/src/backend/bookshelfmodel/btbookshelffiltermodel.cpp +++ b/src/backend/bookshelfmodel/btbookshelffiltermodel.cpp @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2009 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * @@ -25,7 +25,7 @@ BtBookshelfFilterModel::BtBookshelfFilterModel(QObject *parent) m_categoryFilterRole(BtBookshelfModel::ModuleCategoryRole), m_categoryFilterColumn(0) { - // Intentionally empty + setDynamicSortFilter(true); } BtBookshelfFilterModel::~BtBookshelfFilterModel() { @@ -125,16 +125,13 @@ bool BtBookshelfFilterModel::filterAcceptsRow(int row, return true; } -bool BtBookshelfFilterModel::nameFilterAcceptsRow(int row, const QModelIndex &p) - const -{ - if (!m_enabled) return true; +bool BtBookshelfFilterModel::nameFilterAcceptsRow(int row, const QModelIndex &parent) const { if (m_nameFilter.isEmpty()) return true; const QAbstractItemModel *m(sourceModel()); Q_ASSERT(m != 0); - QModelIndex itemIndex(m->index(row, m_nameFilterColumn, p)); + QModelIndex itemIndex(m->index(row, m_nameFilterColumn, parent)); int numChildren(m->rowCount(itemIndex)); if (numChildren == 0) { QVariant data(m->data(itemIndex, m_nameFilterRole)); @@ -148,14 +145,14 @@ bool BtBookshelfFilterModel::nameFilterAcceptsRow(int row, const QModelIndex &p) } } -bool BtBookshelfFilterModel::hiddenFilterAcceptsRow(int row, - const QModelIndex &parent) const +bool BtBookshelfFilterModel::hiddenFilterAcceptsRow(int row, const QModelIndex &parent) const { if (m_showHidden && m_showShown) return true; typedef Qt::CheckState CS; QAbstractItemModel *m(sourceModel()); + Q_ASSERT(m != 0); QModelIndex itemIndex(m->index(row, m_hiddenFilterColumn, parent)); int numChildren(m->rowCount(itemIndex)); @@ -181,17 +178,13 @@ bool BtBookshelfFilterModel::categoryFilterAcceptsRow(int row, if (m_categoryFilter == CSwordModuleInfo::AllCategories) return true; QAbstractItemModel *m(sourceModel()); + Q_ASSERT(m != 0); QModelIndex itemIndex(m->index(row, m_categoryFilterColumn, parent)); int numChildren(m->rowCount(itemIndex)); if (numChildren == 0) { int cat = m->data(itemIndex, m_categoryFilterRole).toInt(); - if (m_categoryFilter.testFlag((CSwordModuleInfo::Category) cat)) { - return true; - } - else { - return false; - } + return m_categoryFilter.testFlag((CSwordModuleInfo::Category) cat); } else { for (int i(0); i < numChildren; i++) { diff --git a/src/backend/bookshelfmodel/btbookshelffiltermodel.h b/src/backend/bookshelfmodel/btbookshelffiltermodel.h index e440c69..55322ed 100644 --- a/src/backend/bookshelfmodel/btbookshelffiltermodel.h +++ b/src/backend/bookshelfmodel/btbookshelffiltermodel.h @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2009 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * diff --git a/src/backend/bookshelfmodel/btbookshelfmodel.cpp b/src/backend/bookshelfmodel/btbookshelfmodel.cpp index ccbb5a5..c6aab1b 100644 --- a/src/backend/bookshelfmodel/btbookshelfmodel.cpp +++ b/src/backend/bookshelfmodel/btbookshelfmodel.cpp @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2009 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * @@ -12,9 +12,9 @@ #include "backend/bookshelfmodel/btbookshelfmodel.h" +#include <QIcon> #include <QSet> -#include "util/cresmgr.h" -#include "util/directory.h" +#include "util/macros.h" BtBookshelfModel::BtBookshelfModel(QObject *parent) @@ -37,7 +37,7 @@ QVariant BtBookshelfModel::data(CSwordModuleInfo *module, int role) const { case ModuleNameRole: // Qt::DisplayRole return module->name(); case ModuleIconRole: // Qt::DecorationRole - return moduleIcon(module); + return CSwordModuleInfo::moduleIcon(module); case ModulePointerRole: return qVariantFromValue((void*) module); case ModuleCategoryRole: @@ -52,6 +52,8 @@ QVariant BtBookshelfModel::data(CSwordModuleInfo *module, int role) const { return module->hasIndex(); case ModuleIndexSizeRole: return (qulonglong) module->indexSize(); + case ModuleDescriptionRole: + return module->config(CSwordModuleInfo::Description); default: return QVariant(); } @@ -93,107 +95,6 @@ bool BtBookshelfModel::setData(const QModelIndex &index, const QVariant &value, return false; } -QIcon BtBookshelfModel::moduleIcon(const CSwordModuleInfo *m) { - namespace DU = util::directory; - - /// \todo Make CSwordModuleInfo::isLocked() const and remove const_cast: - CSwordModuleInfo *module(const_cast<CSwordModuleInfo*>(m)); - - CSwordModuleInfo::Category cat(module->category()); - switch (cat) { - case CSwordModuleInfo::Bibles: - if (module->isLocked()) { - return DU::getIcon(CResMgr::modules::bible::icon_locked); - } - else { - return DU::getIcon(CResMgr::modules::bible::icon_unlocked); - } - case CSwordModuleInfo::Commentaries: - if (module->isLocked()) { - return DU::getIcon(CResMgr::modules::commentary::icon_locked); - } - else { - return DU::getIcon(CResMgr::modules::commentary::icon_unlocked); - } - case CSwordModuleInfo::Lexicons: - if (module->isLocked()) { - return DU::getIcon(CResMgr::modules::lexicon::icon_locked); - } - else { - return DU::getIcon(CResMgr::modules::lexicon::icon_unlocked); - } - case CSwordModuleInfo::Books: - if (module->isLocked()) { - return DU::getIcon(CResMgr::modules::book::icon_locked); - } - else { - return DU::getIcon(CResMgr::modules::book::icon_unlocked); - } - case CSwordModuleInfo::Cult: - case CSwordModuleInfo::Images: - case CSwordModuleInfo::DailyDevotional: - case CSwordModuleInfo::Glossary: - case CSwordModuleInfo::UnknownCategory: - default: - return categoryIcon(cat); - } -} - -QIcon BtBookshelfModel::categoryIcon(const CSwordModuleInfo::Category &category) { - namespace DU = util::directory; - - switch (category) { - case CSwordModuleInfo::Bibles: - return DU::getIcon(CResMgr::categories::bibles::icon); - case CSwordModuleInfo::Commentaries: - return DU::getIcon(CResMgr::categories::commentaries::icon); - case CSwordModuleInfo::Books: - return DU::getIcon(CResMgr::categories::books::icon); - case CSwordModuleInfo::Cult: - return DU::getIcon(CResMgr::categories::cults::icon); - case CSwordModuleInfo::Images: - return DU::getIcon(CResMgr::categories::images::icon); - case CSwordModuleInfo::DailyDevotional: - return DU::getIcon(CResMgr::categories::dailydevotional::icon); - case CSwordModuleInfo::Lexicons: - return DU::getIcon(CResMgr::categories::lexicons::icon); - case CSwordModuleInfo::Glossary: - return DU::getIcon(CResMgr::categories::glossary::icon); - case CSwordModuleInfo::UnknownCategory: - default: - return QIcon(); - } -} - -QString BtBookshelfModel::categoryName( - const CSwordModuleInfo::Category &category) { - switch (category) { - case CSwordModuleInfo::Bibles: - return tr("Bibles"); - case CSwordModuleInfo::Commentaries: - return tr("Commentaries"); - case CSwordModuleInfo::Books: - return tr("Books"); - case CSwordModuleInfo::Cult: - return tr("Cults/Unorthodox"); - case CSwordModuleInfo::Images: - return tr("Maps and Images"); - case CSwordModuleInfo::DailyDevotional: - return tr("Daily Devotionals"); - case CSwordModuleInfo::Lexicons: - return tr("Lexicons and Dictionaries"); - case CSwordModuleInfo::Glossary: - return tr("Glossaries"); - default: - return tr("Unknown"); - } -} - -QString BtBookshelfModel::languageName( - const CLanguageMgr::Language *language) { - return language->translatedName(); -} - void BtBookshelfModel::clear(bool destroy) { if (m_data.size() <= 0) return; @@ -217,6 +118,8 @@ void BtBookshelfModel::addModule(CSwordModuleInfo * const module) { this, SLOT(moduleHidden(bool))); connect(module, SIGNAL(hasIndexChanged(bool)), this, SLOT(moduleIndexed(bool))); + connect(module, SIGNAL(unlockedChanged(bool)), + this, SLOT(moduleUnlocked(bool))); endInsertRows(); } @@ -242,6 +145,8 @@ void BtBookshelfModel::addModules(const QSet<CSwordModuleInfo *> &modules) { this, SLOT(moduleHidden(bool))); connect(module, SIGNAL(hasIndexChanged(bool)), this, SLOT(moduleIndexed(bool))); + connect(module, SIGNAL(unlockedChanged(bool)), + this, SLOT(moduleUnlocked(bool))); } endInsertRows(); } @@ -256,6 +161,8 @@ void BtBookshelfModel::removeModule(CSwordModuleInfo * const module, this, SLOT(moduleHidden(bool))); disconnect(module, SIGNAL(hasIndexChanged(bool)), this, SLOT(moduleIndexed(bool))); + disconnect(module, SIGNAL(unlockedChanged(bool)), + this, SLOT(moduleUnlocked(bool))); m_data.removeAt(index); endRemoveRows(); if (destroy) delete module; @@ -276,7 +183,7 @@ void BtBookshelfModel::removeModules(const QSet<CSwordModuleInfo *> &modules, CSwordModuleInfo* BtBookshelfModel::getModule(const QString &name) const { Q_FOREACH(CSwordModuleInfo *module, m_data) { - if (module->name() == name) return module; + if (UNLIKELY(module->name() == name)) return module; } return 0; } @@ -293,6 +200,12 @@ void BtBookshelfModel::moduleIndexed(bool) { moduleDataChanged(static_cast<CSwordModuleInfo*>(sender())); } +void BtBookshelfModel::moduleUnlocked(bool) { + Q_ASSERT(qobject_cast<CSwordModuleInfo*>(sender()) != 0); + + moduleDataChanged(static_cast<CSwordModuleInfo*>(sender())); +} + void BtBookshelfModel::moduleDataChanged(CSwordModuleInfo *module) { Q_ASSERT(m_data.count(module) == 1); diff --git a/src/backend/bookshelfmodel/btbookshelfmodel.h b/src/backend/bookshelfmodel/btbookshelfmodel.h index 735c655..20f2b3d 100644 --- a/src/backend/bookshelfmodel/btbookshelfmodel.h +++ b/src/backend/bookshelfmodel/btbookshelfmodel.h @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2009 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * @@ -18,6 +18,12 @@ #include "backend/drivers/cswordmoduleinfo.h" +/** + Implements a simple list model projecting CSwordModuleInfo instances. This model is mostly + implemented to provide an interface the the underlying data and to provide notifications + when modules are added, removed or changed. If you want to use a model for widgets, the + BtBookshelfTreeModel might be a better choice, since it also provides sorting and grouping. +*/ class BtBookshelfModel: public QAbstractListModel { Q_OBJECT public: @@ -31,55 +37,135 @@ class BtBookshelfModel: public QAbstractListModel { ModuleInstallPathRole = Qt::UserRole + 4, ModuleHasIndexRole = Qt::UserRole + 5, ModuleIndexSizeRole = Qt::UserRole + 6, + ModuleDescriptionRole = Qt::UserRole + 7, UserRole = Qt::UserRole + 100 }; + public: BtBookshelfModel(QObject *parent = 0); - virtual ~BtBookshelfModel(); + ~BtBookshelfModel(); - virtual int rowCount(const QModelIndex &parent) const; - virtual QVariant data(CSwordModuleInfo *module, int role) const; - virtual QVariant data(const QModelIndex &index, int role) const; - virtual QVariant headerData(int section, Qt::Orientation orientation, + // Virtual methods implemented from QAbstractListModel: + int rowCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(CSwordModuleInfo *module, int role) const; + QVariant data(const QModelIndex &index, int role) const; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; bool setData(const QModelIndex &index, const QVariant &value, int role = ModuleHiddenRole); + /** + Given an index of this model, this method returns a pointer to the underlying + CSwordModuleInfo instance corresponding to the given index. + \param[in] index An index to this model. + */ inline CSwordModuleInfo *module(const QModelIndex &index) const { return (CSwordModuleInfo *) data(index, BtBookshelfModel::ModulePointerRole) .value<void *>(); } - static QIcon moduleIcon(const CSwordModuleInfo *module); - static QIcon categoryIcon(const CSwordModuleInfo::Category &category); - static QString categoryName(const CSwordModuleInfo::Category &category); - static QString languageName(const CLanguageMgr::Language *language); - + /** + Clears the data of the whole model by removing all items. + \param[in] destroy If true, all CSwordModuleInfo instances in this model are also + destroyed. + */ void clear(bool destroy = false); + + /** + Appends the given module to this model. + \param[in] module Module to add. + */ void addModule(CSwordModuleInfo * const module); + + /** + Appends the all the modules in the given set to this model. + \param[in] modules Set of modules to add. + */ void addModules(const QSet<CSwordModuleInfo *> &modules); + + /** + Appends the all the modules in the given list to this model. + \param[in] modules Set of modules to add. + */ void addModules(const QList<CSwordModuleInfo *> &modules); + + /** + Removes the given module from this model and optionally destroys it. + \param[in] module The module to remove from this model. + \param[in] destroy If true, the given CSwordModuleInfo instance is destroyed. + */ void removeModule(CSwordModuleInfo * const module, bool destroy = false); + + /** + Removes all modules from the given set from this model and optionally destroys + them. + \param[in] modules The set of modules to remove from this model. + \param[in] destroy If true, the given CSwordModuleInfo instances are destroyed. + */ void removeModules(const QSet<CSwordModuleInfo *> &modules, bool destroy = false); + + /** + Removes all modules from the given list from this model and optionally destroys + them. + \param[in] modules The list of modules to remove from this model. + \param[in] destroy If true, the given CSwordModuleInfo instances are destroyed. + */ void removeModules(const QList<CSwordModuleInfo *> &modules, bool destroy = false); + /** + Returns the first module found with the given name. + \param[in] name Name of the module to find. + */ CSwordModuleInfo* getModule(const QString &name) const; - inline const QList<CSwordModuleInfo *> &modules() const { + + /** + Returns the list of handled modules as a list of CSwordModuleInfo* pointers. + */ + inline const QList<CSwordModuleInfo *> &moduleList() const { return m_data; } protected slots: + /** + Slot DIRECTLY called by CSwordModuleInfo when the hidden status of the respective + module changes. + \param[in] hidden True, if the module was hidden; false, if the module was shown. + */ void moduleHidden(bool hidden); + + /** + Slot DIRECTLY called by CSwordModuleInfo when the indexed status of the respective + module changes. + \param[in] indexed True, if the module was indexed; false if the index was deleted. + */ void moduleIndexed(bool indexed); + /** + Slot DIRECTLY called by CSwordModuleInfo when the locked status of the respective + module changes. + \param[in] unlocked True, if the module was unlocked; false if the module was + locked. + */ + void moduleUnlocked(bool unlocked); + protected: + /** + Called internally when module data changes. This method emits any neccessary + signals for this model. + \pre The givem module is handled by this model. + \param[in] module The module that changed status. + */ void moduleDataChanged(CSwordModuleInfo *module); protected: + /** + The underlying data as a list of pointers to the respective CSwordModuleInfo + instances. + */ QList<CSwordModuleInfo *> m_data; }; diff --git a/src/backend/bookshelfmodel/btbookshelftreemodel.cpp b/src/backend/bookshelfmodel/btbookshelftreemodel.cpp index a2a988c..6444a81 100644 --- a/src/backend/bookshelfmodel/btbookshelftreemodel.cpp +++ b/src/backend/bookshelfmodel/btbookshelftreemodel.cpp @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2009 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * @@ -13,24 +13,50 @@ #include "backend/bookshelfmodel/btbookshelftreemodel.h" #include <QSet> +#include <QSettings> #include "backend/bookshelfmodel/categoryitem.h" #include "backend/bookshelfmodel/indexingitem.h" #include "backend/bookshelfmodel/languageitem.h" #include "backend/bookshelfmodel/moduleitem.h" +#include "backend/config/cbtconfig.h" +#include "util/macros.h" using namespace BookshelfModel; +bool BtBookshelfTreeModel::Grouping::loadFrom(const QString &configKey) { + Q_ASSERT(!configKey.isNull()); + QVariant v = CBTConfig::getConfig()->value(configKey); + (*this) = v.value<Grouping>(); + return v.canConvert<Grouping>(); +} + +void BtBookshelfTreeModel::Grouping::saveTo(const QString &configKey) const { + Q_ASSERT(!configKey.isNull()); + CBTConfig::getConfig()->setValue(configKey, QVariant::fromValue(*this)); +} + + BtBookshelfTreeModel::BtBookshelfTreeModel(QObject *parent) - : QAbstractItemModel(parent), m_sourceModel(0), m_rootItem(new RootItem), - m_defaultChecked(MODULE_HIDDEN), m_checkable(false) { - m_groupingOrder.push_back(GROUP_CATEGORY); - m_groupingOrder.push_back(GROUP_LANGUAGE); + : QAbstractItemModel(parent), m_sourceModel(0), m_rootItem(new RootItem), + m_defaultChecked(MODULE_HIDDEN), m_checkable(false) +{ + // Intentionally empty +} + +BtBookshelfTreeModel::BtBookshelfTreeModel(const QString &configKey, + QObject *parent) + : QAbstractItemModel(parent), m_sourceModel(0), m_rootItem(new RootItem), + m_groupingOrder(configKey), m_defaultChecked(MODULE_HIDDEN), + m_checkable(false) +{ + // Intentionally empty } BtBookshelfTreeModel::BtBookshelfTreeModel(const Grouping &g, QObject *parent) : QAbstractItemModel(parent), m_sourceModel(0), m_rootItem(new RootItem), - m_groupingOrder(g), m_defaultChecked(MODULE_HIDDEN), m_checkable(false) { + m_groupingOrder(g), m_defaultChecked(MODULE_HIDDEN), m_checkable(false) +{ // Intentionally empty } @@ -123,13 +149,14 @@ QVariant BtBookshelfTreeModel::data(CSwordModuleInfo *module, int role) const { bool BtBookshelfTreeModel::setData(const QModelIndex &itemIndex, const QVariant &value, int role) { + Q_ASSERT(itemIndex.isValid()); typedef QPair<Item *, QModelIndex> IP; Qt::CheckState newState; - if (role == Qt::CheckStateRole) { + if (LIKELY(role == Qt::CheckStateRole)) { bool ok; newState = (Qt::CheckState) value.toInt(&ok); - if (!ok) return false; + if (UNLIKELY(!ok)) return false; } else { return false; @@ -262,7 +289,9 @@ void BtBookshelfTreeModel::setSourceModel(QAbstractItemModel *sourceModel) { } } -void BtBookshelfTreeModel::setGroupingOrder(const Grouping &groupingOrder) { +void BtBookshelfTreeModel::setGroupingOrder(const Grouping &groupingOrder, + bool emitSignal) +{ if (m_groupingOrder == groupingOrder) return; m_groupingOrder = groupingOrder; @@ -291,6 +320,8 @@ void BtBookshelfTreeModel::setGroupingOrder(const Grouping &groupingOrder) { addModule(module, checked.contains(module)); } } + + if (emitSignal) emit groupingOrderChanged(groupingOrder); } void BtBookshelfTreeModel::setCheckable(bool checkable) { @@ -299,14 +330,29 @@ void BtBookshelfTreeModel::setCheckable(bool checkable) { if (m_sourceModel == 0) return; // Notify views that flags changed for all items: + resetData(); +} + +void BtBookshelfTreeModel::setCheckedModules(const QSet<CSwordModuleInfo*> &modules) { + typedef ModuleItemMap::const_iterator MIMCI; + + for (MIMCI it(m_modules.constBegin()); it != m_modules.constEnd(); it++) { + if (modules.contains(it.key())) { + setData(getIndex(it.value()), Qt::Checked, Qt::CheckStateRole); + } else { + setData(getIndex(it.value()), Qt::Unchecked, Qt::CheckStateRole); + } + } +} + +void BtBookshelfTreeModel::resetData() { QModelIndexList queue; queue.append(QModelIndex()); do { QModelIndex parent(queue.takeFirst()); - int numChildren(rowCount(parent)); emit dataChanged(index(0, 0, parent), - index(numChildren - 1, 0, parent)); - for (int i(0); i < numChildren; i++) { + index(rowCount(parent) - 1, columnCount() - 1, parent)); + for (int i(0); i < rowCount(parent); i++) { QModelIndex childIndex(index(i, 0, parent)); if (rowCount(childIndex) > 0) { queue.append(childIndex); @@ -402,7 +448,7 @@ void BtBookshelfTreeModel::removeModule(CSwordModuleInfo *module) { } Item *BtBookshelfTreeModel::getItem(const QModelIndex &index) const { - if (index.isValid()) { + if (LIKELY(index.isValid())) { Item *item(static_cast<Item*>(index.internalPointer())); Q_ASSERT(item != 0); return item; @@ -504,8 +550,7 @@ void BtBookshelfTreeModel::moduleDataChanged(const QModelIndex &topLeft, } } -void BtBookshelfTreeModel::moduleInserted(const QModelIndex &parent, int start, - int end) { +void BtBookshelfTreeModel::moduleInserted(const QModelIndex &parent, int start, int end) { typedef BtBookshelfModel BM; static const BM::ModuleRole PR(BM::ModulePointerRole); static const BM::ModuleRole HR(BM::ModuleHiddenRole); @@ -531,8 +576,7 @@ void BtBookshelfTreeModel::moduleInserted(const QModelIndex &parent, int start, } } -void BtBookshelfTreeModel::moduleRemoved(const QModelIndex &parent, int start, - int end) { +void BtBookshelfTreeModel::moduleRemoved(const QModelIndex &parent, int start, int end) { typedef BtBookshelfModel BM; static const BM::ModuleRole PR(BM::ModulePointerRole); @@ -557,6 +601,7 @@ QDataStream &operator<<(QDataStream &os, const BtBookshelfTreeModel::Grouping &o QDataStream &operator>>(QDataStream &is, BtBookshelfTreeModel::Grouping &o) { int s; is >> s; + o.clear(); for (int i(0); i < s; i++) { int g; is >> g; diff --git a/src/backend/bookshelfmodel/btbookshelftreemodel.h b/src/backend/bookshelfmodel/btbookshelftreemodel.h index 47ce672..2a28dd8 100644 --- a/src/backend/bookshelfmodel/btbookshelftreemodel.h +++ b/src/backend/bookshelfmodel/btbookshelftreemodel.h @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2009 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * @@ -36,7 +36,7 @@ class BtBookshelfTreeModel: public QAbstractItemModel { typedef QMap<CSwordModuleInfo*, BookshelfModel::ModuleItem*> ModuleItemMap; typedef QMap<CSwordModuleInfo*, QPersistentModelIndex> SourceIndexMap; - public: + public: /* Types: */ enum ModuleRole { CheckStateRole = BtBookshelfModel::UserRole, UserRole = BtBookshelfModel::UserRole + 100 @@ -52,9 +52,31 @@ class BtBookshelfTreeModel: public QAbstractItemModel { MODULE_HIDDEN, /**< By default, check only added modules that are not hidden. */ MODULE_INDEXED /**< By default, check only added modules that are indexed. */ }; - typedef QList<Group> Grouping; + class Grouping: public QList<Group> { + public: + /** + \warning Be careful using this constructor! + */ + explicit inline Grouping(bool empty = false) { + if (empty) return; + push_back(GROUP_CATEGORY); + push_back(GROUP_LANGUAGE); + } + explicit inline Grouping(Group group) { push_back(group); } + explicit inline Grouping(const QString &configKey) { + loadFrom(configKey); + } + inline Grouping(const Grouping ©) + : QList<Group>(copy) {} + + bool loadFrom(const QString &configKey); + void saveTo(const QString &configKey) const; + }; + + public: /* Methods: */ BtBookshelfTreeModel(QObject *parent = 0); + BtBookshelfTreeModel(const QString &configKey, QObject *parent = 0); BtBookshelfTreeModel(const Grouping &grouping, QObject *parent = 0); virtual ~BtBookshelfTreeModel(); @@ -75,30 +97,31 @@ class BtBookshelfTreeModel: public QAbstractItemModel { virtual bool setData(const QModelIndex &index, const QVariant &value, int role); - void setSourceModel(QAbstractItemModel *sourceModel); - inline QAbstractItemModel *sourceModel() const { - return m_sourceModel; - } - void setGroupingOrder(const Grouping &groupingOrder); - inline Grouping groupingOrder() const { - return m_groupingOrder; + inline QAbstractItemModel *sourceModel() const { return m_sourceModel; } + inline const Grouping &groupingOrder() const { return m_groupingOrder; } + inline bool checkable() const { return m_checkable; } + inline CheckedBehavior defaultChecked() const { return m_defaultChecked; } + inline QList<CSwordModuleInfo*> modules() const { return m_modules.keys(); } + inline const QSet<CSwordModuleInfo*> &checkedModules() const { + return m_checkedModulesCache; } + + public slots: + void setSourceModel(QAbstractItemModel *sourceModel); + void setGroupingOrder(const BtBookshelfTreeModel::Grouping &groupingOrder, + bool emitSignal = true); void setCheckable(bool checkable); - inline bool checkable() const { - return m_checkable; - } inline void setDefaultChecked(CheckedBehavior b) { m_defaultChecked = b; } - inline CheckedBehavior defaultChecked() const { - return m_defaultChecked; - } + void setCheckedModules(const QSet<CSwordModuleInfo*> &modules); - inline const QSet<CSwordModuleInfo*> &checkedModules() const { - return m_checkedModulesCache; - } + signals: + void groupingOrderChanged(BtBookshelfTreeModel::Grouping newGrouping); + void moduleChecked(CSwordModuleInfo *module, bool checked); protected: + void resetData(); QVariant parentData(BookshelfModel::ModuleItem *item, int role) const; void addModule(CSwordModuleInfo *module, bool checked); void addModule(CSwordModuleInfo *module, QModelIndex parentIndex, @@ -132,9 +155,6 @@ 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: QAbstractItemModel *m_sourceModel; BookshelfModel::Item *m_rootItem; diff --git a/src/backend/bookshelfmodel/categoryitem.cpp b/src/backend/bookshelfmodel/categoryitem.cpp index 46905d7..aaf5566 100644 --- a/src/backend/bookshelfmodel/categoryitem.cpp +++ b/src/backend/bookshelfmodel/categoryitem.cpp @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2009 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * @@ -23,9 +23,9 @@ CategoryItem::CategoryItem(CSwordModuleInfo *module) QVariant CategoryItem::data(int role) const { switch (role) { case Qt::DisplayRole: - return BtBookshelfModel::categoryName(m_category); + return CSwordModuleInfo::categoryName(m_category); case Qt::DecorationRole: - return BtBookshelfModel::categoryIcon(m_category); + return CSwordModuleInfo::categoryIcon(m_category); default: return Item::data(role); } diff --git a/src/backend/bookshelfmodel/categoryitem.h b/src/backend/bookshelfmodel/categoryitem.h index 879895f..75d5a7c 100644 --- a/src/backend/bookshelfmodel/categoryitem.h +++ b/src/backend/bookshelfmodel/categoryitem.h @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2009 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * diff --git a/src/backend/bookshelfmodel/indexingitem.cpp b/src/backend/bookshelfmodel/indexingitem.cpp index 898096f..5491ca5 100644 --- a/src/backend/bookshelfmodel/indexingitem.cpp +++ b/src/backend/bookshelfmodel/indexingitem.cpp @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2009 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * diff --git a/src/backend/bookshelfmodel/indexingitem.h b/src/backend/bookshelfmodel/indexingitem.h index f30fb2d..a1eb812 100644 --- a/src/backend/bookshelfmodel/indexingitem.h +++ b/src/backend/bookshelfmodel/indexingitem.h @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2009 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * diff --git a/src/backend/bookshelfmodel/item.cpp b/src/backend/bookshelfmodel/item.cpp index 809021b..02cd991 100644 --- a/src/backend/bookshelfmodel/item.cpp +++ b/src/backend/bookshelfmodel/item.cpp @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2009 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * diff --git a/src/backend/bookshelfmodel/item.h b/src/backend/bookshelfmodel/item.h index f10da04..652120b 100644 --- a/src/backend/bookshelfmodel/item.h +++ b/src/backend/bookshelfmodel/item.h @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2009 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * diff --git a/src/backend/bookshelfmodel/languageitem.cpp b/src/backend/bookshelfmodel/languageitem.cpp index 547c953..2fdab8b 100644 --- a/src/backend/bookshelfmodel/languageitem.cpp +++ b/src/backend/bookshelfmodel/languageitem.cpp @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2009 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * @@ -23,7 +23,7 @@ LanguageItem::LanguageItem(CSwordModuleInfo *module) QVariant LanguageItem::data(int role) const { switch (role) { case Qt::DisplayRole: - return BtBookshelfModel::languageName(m_language); + return m_language->translatedName(); case Qt::DecorationRole: return util::directory::getIcon("flag.svg"); default: diff --git a/src/backend/bookshelfmodel/languageitem.h b/src/backend/bookshelfmodel/languageitem.h index c6e4417..03a9ce3 100644 --- a/src/backend/bookshelfmodel/languageitem.h +++ b/src/backend/bookshelfmodel/languageitem.h @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2009 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * diff --git a/src/backend/bookshelfmodel/moduleitem.cpp b/src/backend/bookshelfmodel/moduleitem.cpp index e7aff92..ca9c3fb 100644 --- a/src/backend/bookshelfmodel/moduleitem.cpp +++ b/src/backend/bookshelfmodel/moduleitem.cpp @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2009 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * diff --git a/src/backend/bookshelfmodel/moduleitem.h b/src/backend/bookshelfmodel/moduleitem.h index 006ae97..5e6e1ba 100644 --- a/src/backend/bookshelfmodel/moduleitem.h +++ b/src/backend/bookshelfmodel/moduleitem.h @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2009 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * @@ -28,10 +28,10 @@ class ModuleItem: public Item { ModuleItem(CSwordModuleInfo *module, BtBookshelfTreeModel *parentModel); /** - Reimplementation of \ref Item::data which dispatches all requests to - the \ref BtBookshelfTreeModel parent model. + Reimplementation of Item::data() which dispatches all + requests to the parent model (BtBookshelfTreeModel). */ - QVariant data(int role = Qt::DisplayRole) const; + virtual QVariant data(int role = Qt::DisplayRole) const; inline CSwordModuleInfo *moduleInfo() const { return m_moduleInfo; |