diff options
Diffstat (limited to 'src/backend/bookshelfmodel/btbookshelfmodel.cpp')
-rw-r--r-- | src/backend/bookshelfmodel/btbookshelfmodel.cpp | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/src/backend/bookshelfmodel/btbookshelfmodel.cpp b/src/backend/bookshelfmodel/btbookshelfmodel.cpp index 6882b90..ccbb5a5 100644 --- a/src/backend/bookshelfmodel/btbookshelfmodel.cpp +++ b/src/backend/bookshelfmodel/btbookshelfmodel.cpp @@ -27,6 +27,8 @@ BtBookshelfModel::~BtBookshelfModel() { } int BtBookshelfModel::rowCount(const QModelIndex &parent) const { + if (parent.isValid()) return 0; + return m_data.size(); } @@ -44,6 +46,12 @@ QVariant BtBookshelfModel::data(CSwordModuleInfo *module, int role) const { return QVariant(); /// \todo Unimplemented case ModuleHiddenRole: return module->isHidden(); + case ModuleInstallPathRole: + return module->config(CSwordModuleInfo::AbsoluteDataPath); + case ModuleHasIndexRole: + return module->hasIndex(); + case ModuleIndexSizeRole: + return (qulonglong) module->indexSize(); default: return QVariant(); } @@ -73,8 +81,7 @@ bool BtBookshelfModel::setData(const QModelIndex &index, const QVariant &value, int role) { int row(index.row()); if (role == ModuleHiddenRole && row >= 0 && row < m_data.size() - && index.column() == 0) - { + && index.column() == 0) { /* Emitting dataChanged here is actually mandatory, but were not doing it directly. Since we're connected to the module, changing its hidden @@ -97,25 +104,29 @@ QIcon BtBookshelfModel::moduleIcon(const CSwordModuleInfo *m) { case CSwordModuleInfo::Bibles: if (module->isLocked()) { return DU::getIcon(CResMgr::modules::bible::icon_locked); - } else { + } + else { return DU::getIcon(CResMgr::modules::bible::icon_unlocked); } case CSwordModuleInfo::Commentaries: if (module->isLocked()) { return DU::getIcon(CResMgr::modules::commentary::icon_locked); - } else { + } + else { return DU::getIcon(CResMgr::modules::commentary::icon_unlocked); } case CSwordModuleInfo::Lexicons: if (module->isLocked()) { return DU::getIcon(CResMgr::modules::lexicon::icon_locked); - } else { + } + else { return DU::getIcon(CResMgr::modules::lexicon::icon_unlocked); } case CSwordModuleInfo::Books: if (module->isLocked()) { return DU::getIcon(CResMgr::modules::book::icon_locked); - } else { + } + else { return DU::getIcon(CResMgr::modules::book::icon_unlocked); } case CSwordModuleInfo::Cult: @@ -204,6 +215,8 @@ void BtBookshelfModel::addModule(CSwordModuleInfo * const module) { m_data.append(module); connect(module, SIGNAL(hiddenChanged(bool)), this, SLOT(moduleHidden(bool))); + connect(module, SIGNAL(hasIndexChanged(bool)), + this, SLOT(moduleIndexed(bool))); endInsertRows(); } @@ -227,33 +240,34 @@ void BtBookshelfModel::addModules(const QSet<CSwordModuleInfo *> &modules) { m_data.append(module); connect(module, SIGNAL(hiddenChanged(bool)), this, SLOT(moduleHidden(bool))); + connect(module, SIGNAL(hasIndexChanged(bool)), + this, SLOT(moduleIndexed(bool))); } endInsertRows(); } void BtBookshelfModel::removeModule(CSwordModuleInfo * const module, - bool destroy) -{ + bool destroy) { const int index(m_data.indexOf(module)); if (index == -1) return; beginRemoveRows(QModelIndex(), index, index); disconnect(module, SIGNAL(hiddenChanged(bool)), this, SLOT(moduleHidden(bool))); + disconnect(module, SIGNAL(hasIndexChanged(bool)), + this, SLOT(moduleIndexed(bool))); m_data.removeAt(index); endRemoveRows(); if (destroy) delete module; } void BtBookshelfModel::removeModules(const QList<CSwordModuleInfo *> &modules, - bool destroy) -{ + bool destroy) { removeModules(modules.toSet(), destroy); } void BtBookshelfModel::removeModules(const QSet<CSwordModuleInfo *> &modules, - bool destroy) -{ + bool destroy) { // This is inefficient, since signals are emitted for each removed module: Q_FOREACH(CSwordModuleInfo *module, modules) { removeModule(module, destroy); @@ -270,7 +284,16 @@ CSwordModuleInfo* BtBookshelfModel::getModule(const QString &name) const { void BtBookshelfModel::moduleHidden(bool) { Q_ASSERT(qobject_cast<CSwordModuleInfo*>(sender()) != 0); - CSwordModuleInfo *module(static_cast<CSwordModuleInfo*>(sender())); + moduleDataChanged(static_cast<CSwordModuleInfo*>(sender())); +} + +void BtBookshelfModel::moduleIndexed(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); QModelIndex i(index(m_data.indexOf(module), 0)); |