summaryrefslogtreecommitdiff
path: root/src/backend/bookshelfmodel
diff options
context:
space:
mode:
authorRoberto C. Sanchez <roberto@connexer.com>2014-10-21 22:48:29 -0400
committerRoberto C. Sanchez <roberto@connexer.com>2014-10-21 22:48:29 -0400
commite8a196082586bb68e0bf254a8f6f4b8f39071f32 (patch)
treeb03dbbd1b5be6092ed5e9bcb3806aa2d4938bba3 /src/backend/bookshelfmodel
parentdd2f7ce46df53f2c377c02d1bf4df8adcf092072 (diff)
Imported Upstream version 2.3.3
Diffstat (limited to 'src/backend/bookshelfmodel')
-rw-r--r--src/backend/bookshelfmodel/btbookshelfmodel.cpp92
-rw-r--r--src/backend/bookshelfmodel/btbookshelfmodel.h18
-rw-r--r--src/backend/bookshelfmodel/btbookshelftreemodel.cpp97
-rw-r--r--src/backend/bookshelfmodel/btbookshelftreemodel.h41
-rw-r--r--src/backend/bookshelfmodel/btcheckstatefilterproxymodel.cpp14
-rw-r--r--src/backend/bookshelfmodel/btcheckstatefilterproxymodel.h14
-rw-r--r--src/backend/bookshelfmodel/btmodulenamefilterproxymodel.cpp9
-rw-r--r--src/backend/bookshelfmodel/btmodulenamefilterproxymodel.h6
-rw-r--r--src/backend/bookshelfmodel/categoryitem.cpp10
-rw-r--r--src/backend/bookshelfmodel/categoryitem.h4
-rw-r--r--src/backend/bookshelfmodel/distributionitem.cpp3
-rw-r--r--src/backend/bookshelfmodel/distributionitem.h10
-rw-r--r--src/backend/bookshelfmodel/item.cpp3
-rw-r--r--src/backend/bookshelfmodel/item.h26
-rw-r--r--src/backend/bookshelfmodel/languageitem.cpp3
-rw-r--r--src/backend/bookshelfmodel/languageitem.h4
-rw-r--r--src/backend/bookshelfmodel/moduleitem.cpp3
-rw-r--r--src/backend/bookshelfmodel/moduleitem.h10
18 files changed, 250 insertions, 117 deletions
diff --git a/src/backend/bookshelfmodel/btbookshelfmodel.cpp b/src/backend/bookshelfmodel/btbookshelfmodel.cpp
index 6764a88..99f83ba 100644
--- a/src/backend/bookshelfmodel/btbookshelfmodel.cpp
+++ b/src/backend/bookshelfmodel/btbookshelfmodel.cpp
@@ -17,8 +17,7 @@
#include "util/directoryutil.h"
BtBookshelfModel::BtBookshelfModel(QObject *parent)
- : QAbstractListModel(parent)
-{
+ : QAbstractListModel(parent) {
// Intentionally empty
}
@@ -41,7 +40,7 @@ QVariant BtBookshelfModel::data(const QModelIndex &index, int role) const {
case ModuleNameRole: // Qt::DisplayRole
return m_data.at(row)->name();
case ModuleIconRole: // Qt::DecorationRole
- return categoryIcon(m_data.at(row)->category());
+ return moduleIcon(m_data.at(row));
case ModulePointerRole:
return qVariantFromValue((void*) m_data.at(row));
default:
@@ -50,19 +49,58 @@ QVariant BtBookshelfModel::data(const QModelIndex &index, int role) const {
}
QVariant BtBookshelfModel::headerData(int section, Qt::Orientation orientation,
- int role) const
-{
+ int role) const {
if (role == Qt::DisplayRole && orientation == Qt::Horizontal &&
- section == 0)
- {
+ section == 0) {
return tr("Module");
}
return QVariant();
}
-QIcon BtBookshelfModel::categoryIcon(const CSwordModuleInfo::Category &category)
-{
+QIcon BtBookshelfModel::moduleIcon(const CSwordModuleInfo *m) {
+ typedef util::filesystem::DirectoryUtil DU;
+
+ /// \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) {
typedef util::filesystem::DirectoryUtil DU;
switch (category) {
@@ -89,8 +127,7 @@ QIcon BtBookshelfModel::categoryIcon(const CSwordModuleInfo::Category &category)
}
QString BtBookshelfModel::categoryName(
- const CSwordModuleInfo::Category &category)
-{
+ const CSwordModuleInfo::Category &category) {
switch (category) {
case CSwordModuleInfo::Bibles:
return tr("Bibles");
@@ -114,13 +151,17 @@ QString BtBookshelfModel::categoryName(
}
QString BtBookshelfModel::languageName(
- const CLanguageMgr::Language *language)
-{
+ const CLanguageMgr::Language *language) {
return language->translatedName();
}
-void BtBookshelfModel::clear() {
+void BtBookshelfModel::clear(bool destroy) {
+ if (m_data.size() <= 0) return;
+
beginRemoveRows(QModelIndex(), 0, m_data.size() - 1);
+ if (destroy) {
+ qDeleteAll(m_data);
+ }
m_data.clear();
endRemoveRows();
}
@@ -152,27 +193,40 @@ void BtBookshelfModel::addModules(const QSet<CSwordModuleInfo *> &modules) {
beginInsertRows(QModelIndex(), m_data.size(),
m_data.size() + newModules.size() - 1);
+#if QT_VERSION >= 0x040500
m_data.append(newModules);
+#else
+ Q_FOREACH(CSwordModuleInfo *module, newModules) {
+ m_data.append(module);
+ }
+#endif
endInsertRows();
}
-void BtBookshelfModel::removeModule(CSwordModuleInfo * const module) {
+void BtBookshelfModel::removeModule(CSwordModuleInfo * const module,
+ bool destroy)
+{
const int index(m_data.indexOf(module));
if (index == -1) return;
beginRemoveRows(QModelIndex(), index, index);
m_data.removeAt(index);
endRemoveRows();
+ if (destroy) delete module;
}
-void BtBookshelfModel::removeModules(const QList<CSwordModuleInfo *> &modules) {
- removeModules(modules.toSet());
+void BtBookshelfModel::removeModules(const QList<CSwordModuleInfo *> &modules,
+ bool destroy)
+{
+ removeModules(modules.toSet(), destroy);
}
-void BtBookshelfModel::removeModules(const QSet<CSwordModuleInfo *> &modules) {
+void BtBookshelfModel::removeModules(const QSet<CSwordModuleInfo *> &modules,
+ bool destroy)
+{
// This is inefficient, since signals are emitted for each removed module:
Q_FOREACH(CSwordModuleInfo *module, modules) {
- removeModule(module);
+ removeModule(module, destroy);
}
}
diff --git a/src/backend/bookshelfmodel/btbookshelfmodel.h b/src/backend/bookshelfmodel/btbookshelfmodel.h
index c268d2c..01fc260 100644
--- a/src/backend/bookshelfmodel/btbookshelfmodel.h
+++ b/src/backend/bookshelfmodel/btbookshelfmodel.h
@@ -18,7 +18,7 @@
#include "backend/drivers/cswordmoduleinfo.h"
class BtBookshelfModel: public QAbstractListModel {
- Q_OBJECT
+ Q_OBJECT
public:
enum ModuleRole {
ModuleNameRole = Qt::DisplayRole,
@@ -39,21 +39,25 @@ class BtBookshelfModel: public QAbstractListModel {
inline CSwordModuleInfo *module(const QModelIndex &index) const {
return (CSwordModuleInfo *)
- data(index, BtBookshelfModel::ModulePointerRole)
- .value<void *>();
+ 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);
- void clear();
+ void clear(bool destroy = false);
void addModule(CSwordModuleInfo * const module);
void addModules(const QSet<CSwordModuleInfo *> &modules);
void addModules(const QList<CSwordModuleInfo *> &modules);
- void removeModule(CSwordModuleInfo * const module);
- void removeModules(const QSet<CSwordModuleInfo *> &modules);
- void removeModules(const QList<CSwordModuleInfo *> &modules);
+ void removeModule(CSwordModuleInfo * const module,
+ bool destroy = false);
+ void removeModules(const QSet<CSwordModuleInfo *> &modules,
+ bool destroy = false);
+ void removeModules(const QList<CSwordModuleInfo *> &modules,
+ bool destroy = false);
CSwordModuleInfo* getModule(const QString &name) const;
inline const QList<CSwordModuleInfo *> &modules() const {
diff --git a/src/backend/bookshelfmodel/btbookshelftreemodel.cpp b/src/backend/bookshelfmodel/btbookshelftreemodel.cpp
index 47526e9..8e457e7 100644
--- a/src/backend/bookshelfmodel/btbookshelftreemodel.cpp
+++ b/src/backend/bookshelfmodel/btbookshelftreemodel.cpp
@@ -22,13 +22,18 @@
using namespace BookshelfModel;
BtBookshelfTreeModel::BtBookshelfTreeModel(QObject *parent)
- : QAbstractItemModel(parent), m_sourceModel(0), m_rootItem(new RootItem),
- m_checkable(false), m_defaultChecked(false)
-{
+ : QAbstractItemModel(parent), m_sourceModel(0), m_rootItem(new RootItem),
+ m_checkable(false), m_defaultChecked(false) {
m_groupingOrder.push_back(GROUP_CATEGORY);
m_groupingOrder.push_back(GROUP_LANGUAGE);
}
+BtBookshelfTreeModel::BtBookshelfTreeModel(const Grouping &g, QObject *parent)
+ : QAbstractItemModel(parent), m_sourceModel(0), m_rootItem(new RootItem),
+ m_groupingOrder(g), m_checkable(false), m_defaultChecked(false) {
+ // Intentionally empty
+}
+
BtBookshelfTreeModel::~BtBookshelfTreeModel() {
delete m_rootItem;
}
@@ -46,15 +51,15 @@ bool BtBookshelfTreeModel::hasChildren(const QModelIndex &parent) const {
}
QModelIndex BtBookshelfTreeModel::index(int row, int column,
- const QModelIndex &parent) const
-{
+ const QModelIndex &parent) const {
if (!hasIndex(row, column, parent)) return QModelIndex();
Item *parentItem(getItem(parent));
Item *childItem(parentItem->childAt(row));
if (childItem != 0) {
return createIndex(row, column, childItem);
- } else {
+ }
+ else {
return QModelIndex();
}
}
@@ -107,8 +112,7 @@ QVariant BtBookshelfTreeModel::data(const QModelIndex &index, int role) const {
bool BtBookshelfTreeModel::setData(const QModelIndex &itemIndex,
const QVariant &value,
- int role)
-{
+ int role) {
typedef QPair<Item *, QModelIndex> IP;
if (role == Qt::CheckStateRole) {
@@ -164,9 +168,8 @@ Qt::ItemFlags BtBookshelfTreeModel::flags(const QModelIndex &index) const {
}
QVariant BtBookshelfTreeModel::headerData(int section,
- Qt::Orientation orientation,
- int role) const
-{
+ Qt::Orientation orientation,
+ int role) const {
if (orientation == Qt::Horizontal) {
return m_sourceModel->headerData(section, orientation, role);
}
@@ -177,9 +180,9 @@ void BtBookshelfTreeModel::setSourceModel(QAbstractListModel *sourceModel) {
if (m_sourceModel == sourceModel) return;
if (m_sourceModel != 0) {
- disconnect(this, SLOT(moduleInserted(QModelIndex,int,int)));
- disconnect(this, SLOT(moduleRemoved(QModelIndex,int,int)));
- disconnect(this, SLOT(moduleDataChanged(QModelIndex,QModelIndex)));
+ disconnect(this, SLOT(moduleInserted(QModelIndex, int, int)));
+ disconnect(this, SLOT(moduleRemoved(QModelIndex, int, int)));
+ disconnect(this, SLOT(moduleDataChanged(QModelIndex, QModelIndex)));
beginRemoveRows(QModelIndex(), 0, m_rootItem->children().size() - 1);
delete m_rootItem;
m_modules.clear();
@@ -190,10 +193,10 @@ void BtBookshelfTreeModel::setSourceModel(QAbstractListModel *sourceModel) {
m_sourceModel = sourceModel;
if (sourceModel != 0) {
- connect(sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
- this, SLOT(moduleRemoved(QModelIndex,int,int)));
- connect(sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
- this, SLOT(moduleInserted(QModelIndex,int,int)));
+ connect(sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)),
+ this, SLOT(moduleRemoved(QModelIndex, int, int)));
+ connect(sourceModel, SIGNAL(rowsInserted(QModelIndex, int, int)),
+ this, SLOT(moduleInserted(QModelIndex, int, int)));
connect(sourceModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)),
this, SLOT(moduleDataChanged(QModelIndex, QModelIndex)));
@@ -202,7 +205,8 @@ void BtBookshelfTreeModel::setSourceModel(QAbstractListModel *sourceModel) {
Q_FOREACH(CSwordModuleInfo *module, m->modules()) {
addModule(module, m_defaultChecked);
}
- } else {
+ }
+ else {
for (int i(0); i < sourceModel->rowCount(); i++) {
CSwordModuleInfo *module(
static_cast<CSwordModuleInfo *>(
@@ -239,7 +243,8 @@ void BtBookshelfTreeModel::setGroupingOrder(const Grouping &groupingOrder) {
Q_FOREACH(CSwordModuleInfo *module, m->modules()) {
addModule(module, checked.contains(module));
}
- } else {
+ }
+ else {
for (int i(0); i < m_sourceModel->rowCount(); i++) {
CSwordModuleInfo *module(
static_cast<CSwordModuleInfo *>(
@@ -273,7 +278,8 @@ void BtBookshelfTreeModel::setCheckable(bool checkable) {
queue.append(childIndex);
}
}
- } while (!queue.isEmpty());
+ }
+ while (!queue.isEmpty());
}
}
@@ -306,8 +312,7 @@ void BtBookshelfTreeModel::addModule(CSwordModuleInfo *module, bool checked) {
void BtBookshelfTreeModel::addModule(CSwordModuleInfo *module,
QModelIndex parentIndex,
Grouping &intermediateGrouping,
- bool checked)
-{
+ bool checked) {
Q_ASSERT(module != 0);
if (!intermediateGrouping.empty()) {
@@ -325,7 +330,8 @@ void BtBookshelfTreeModel::addModule(CSwordModuleInfo *module,
}
intermediateGrouping.pop_front();
addModule(module, newIndex, intermediateGrouping, checked);
- } else {
+ }
+ else {
Item *parentItem(getItem(parentIndex));
ModuleItem *newItem(new ModuleItem(module));
newItem->setCheckState(checked ? Qt::Checked : Qt::Unchecked);
@@ -376,7 +382,8 @@ Item *BtBookshelfTreeModel::getItem(const QModelIndex &index) const {
Item *item(static_cast<Item*>(index.internalPointer()));
Q_ASSERT(item != 0);
return item;
- } else {
+ }
+ else {
return m_rootItem;
}
}
@@ -395,10 +402,12 @@ void BtBookshelfTreeModel::resetParentCheckStates(QModelIndex parentIndex) {
haveCheckedChildren = true;
haveUncheckedChildren = true;
break;
- } else if (state == Qt::Checked) {
+ }
+ else if (state == Qt::Checked) {
haveCheckedChildren = true;
if (haveUncheckedChildren) break;
- } else if (state == Qt::Unchecked) {
+ }
+ else if (state == Qt::Unchecked) {
haveUncheckedChildren = true;
if (haveCheckedChildren) break;
}
@@ -408,10 +417,12 @@ void BtBookshelfTreeModel::resetParentCheckStates(QModelIndex parentIndex) {
if (haveCheckedChildren) {
if (haveUncheckedChildren) {
newState = Qt::PartiallyChecked;
- } else {
+ }
+ else {
newState = Qt::Checked;
}
- } else {
+ }
+ else {
newState = Qt::Unchecked;
}
if (newState == oldState) break;
@@ -422,8 +433,7 @@ void BtBookshelfTreeModel::resetParentCheckStates(QModelIndex parentIndex) {
}
void BtBookshelfTreeModel::moduleDataChanged(const QModelIndex &topLeft,
- const QModelIndex &bottomRight)
-{
+ const QModelIndex &bottomRight) {
typedef BtBookshelfModel BM;
static const BM::ModuleRole PR(BM::ModulePointerRole);
@@ -444,8 +454,7 @@ void BtBookshelfTreeModel::moduleDataChanged(const QModelIndex &topLeft,
}
void BtBookshelfTreeModel::moduleInserted(const QModelIndex &parent, int start,
- int end)
-{
+ int end) {
typedef BtBookshelfModel BM;
static const BM::ModuleRole PR(BM::ModulePointerRole);
@@ -459,8 +468,7 @@ void BtBookshelfTreeModel::moduleInserted(const QModelIndex &parent, int start,
}
void BtBookshelfTreeModel::moduleRemoved(const QModelIndex &parent, int start,
- int end)
-{
+ int end) {
typedef BtBookshelfModel BM;
static const BM::ModuleRole PR(BM::ModulePointerRole);
@@ -472,3 +480,22 @@ void BtBookshelfTreeModel::moduleRemoved(const QModelIndex &parent, int start,
removeModule(module);
}
}
+
+QDataStream &operator<<(QDataStream &os, const BtBookshelfTreeModel::Grouping &o) {
+ os << o.size();
+ Q_FOREACH(BtBookshelfTreeModel::Group g, o) {
+ os << (int) g;
+ }
+ return os;
+}
+
+QDataStream &operator>>(QDataStream &is, BtBookshelfTreeModel::Grouping &o) {
+ int s;
+ is >> s;
+ for (int i(0); i < s; i++) {
+ int g;
+ is >> g;
+ o.append((BtBookshelfTreeModel::Group) g);
+ }
+ return is;
+}
diff --git a/src/backend/bookshelfmodel/btbookshelftreemodel.h b/src/backend/bookshelfmodel/btbookshelftreemodel.h
index 0a84ac3..84293e1 100644
--- a/src/backend/bookshelfmodel/btbookshelftreemodel.h
+++ b/src/backend/bookshelfmodel/btbookshelftreemodel.h
@@ -20,34 +20,37 @@
#include "backend/bookshelfmodel/item.h"
namespace BookshelfModel {
- class ModuleItem;
+class ModuleItem;
}
class CSwordModuleInfo;
+class QDataStream;
class BtBookshelfTreeModel: public QAbstractItemModel {
- Q_OBJECT
+ Q_OBJECT
+ Q_ENUMS(Group)
- typedef QMap<CSwordModuleInfo*, BookshelfModel::ModuleItem*> ModuleItemMap;
+ typedef QMap<CSwordModuleInfo*, BookshelfModel::ModuleItem*> ModuleItemMap;
public:
enum ModuleRole {
CheckStateRole = BtBookshelfModel::UserRole,
UserRole = BtBookshelfModel::UserRole + 100
};
- enum Group { GROUP_CATEGORY, GROUP_LANGUAGE, GROUP_DISTRIBUTION };
+ enum Group { GROUP_CATEGORY = 0, GROUP_LANGUAGE, GROUP_DISTRIBUTION };
typedef QList<Group> Grouping;
BtBookshelfTreeModel(QObject *parent = 0);
+ BtBookshelfTreeModel(const Grouping &grouping, QObject *parent = 0);
virtual ~BtBookshelfTreeModel();
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex &parent = QModelIndex())
- const;
+ const;
virtual bool hasChildren(const QModelIndex &parent = QModelIndex())
- const;
+ const;
virtual QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex())
- const;
+ 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;
@@ -57,15 +60,23 @@ class BtBookshelfTreeModel: public QAbstractItemModel {
int role);
void setSourceModel(QAbstractListModel *sourceModel);
- inline QAbstractListModel *sourceModel() const { return m_sourceModel; }
+ inline QAbstractListModel *sourceModel() const {
+ return m_sourceModel;
+ }
void setGroupingOrder(const Grouping &groupingOrder);
- inline Grouping groupingOrder() const { return m_groupingOrder; }
+ inline Grouping groupingOrder() const {
+ return m_groupingOrder;
+ }
void setCheckable(bool checkable);
- inline bool checkable() const { return m_checkable; }
+ inline bool checkable() const {
+ return m_checkable;
+ }
inline void setDefaultChecked(bool defaultChecked) {
m_defaultChecked = defaultChecked;
}
- inline bool defaultChecked() const { return m_defaultChecked; }
+ inline bool defaultChecked() const {
+ return m_defaultChecked;
+ }
QList<CSwordModuleInfo*> checkedModules() const;
@@ -80,8 +91,7 @@ class BtBookshelfTreeModel: public QAbstractItemModel {
template <class T>
QModelIndex getGroup(CSwordModuleInfo *module,
- QModelIndex parentIndex)
- {
+ QModelIndex parentIndex) {
BookshelfModel::Item *parentItem(getItem(parentIndex));
int groupIndex;
T *groupItem(parentItem->getGroupItem<T>(module, &groupIndex));
@@ -111,4 +121,9 @@ class BtBookshelfTreeModel: public QAbstractItemModel {
bool m_defaultChecked;
};
+QDataStream &operator<<(QDataStream &os, const BtBookshelfTreeModel::Grouping &o);
+QDataStream &operator>>(QDataStream &is, BtBookshelfTreeModel::Grouping &o);
+
+Q_DECLARE_METATYPE(BtBookshelfTreeModel::Grouping);
+
#endif // BTBOOKSHELFTREEMODEL_H
diff --git a/src/backend/bookshelfmodel/btcheckstatefilterproxymodel.cpp b/src/backend/bookshelfmodel/btcheckstatefilterproxymodel.cpp
index 4d9cfd6..184bd39 100644
--- a/src/backend/bookshelfmodel/btcheckstatefilterproxymodel.cpp
+++ b/src/backend/bookshelfmodel/btcheckstatefilterproxymodel.cpp
@@ -13,9 +13,8 @@
#include "backend/bookshelfmodel/btcheckstatefilterproxymodel.h"
BtCheckStateFilterProxyModel::BtCheckStateFilterProxyModel(QObject *parent)
- : QSortFilterProxyModel(parent), m_enabled(true), m_showChecked(true),
- m_showUnchecked(false), m_showPartiallyChecked(true)
-{
+ : QSortFilterProxyModel(parent), m_enabled(true), m_showChecked(true),
+ m_showUnchecked(false), m_showPartiallyChecked(true) {
setFilterRole(Qt::CheckStateRole);
}
@@ -48,8 +47,7 @@ void BtCheckStateFilterProxyModel::setShowPartiallyChecked(bool show) {
}
bool BtCheckStateFilterProxyModel::filterAcceptsRow(int row,
- const QModelIndex &parent) const
-{
+ const QModelIndex &parent) const {
typedef Qt::CheckState CS;
if (!m_enabled) return true;
@@ -62,9 +60,11 @@ bool BtCheckStateFilterProxyModel::filterAcceptsRow(int row,
state == Qt::PartiallyChecked);
if (state == Qt::Unchecked) {
return m_showUnchecked;
- } else if (state == Qt::Checked) {
+ }
+ else if (state == Qt::Checked) {
return m_showChecked;
- } else {
+ }
+ else {
return m_showPartiallyChecked;
}
}
diff --git a/src/backend/bookshelfmodel/btcheckstatefilterproxymodel.h b/src/backend/bookshelfmodel/btcheckstatefilterproxymodel.h
index b2081f1..78d324d 100644
--- a/src/backend/bookshelfmodel/btcheckstatefilterproxymodel.h
+++ b/src/backend/bookshelfmodel/btcheckstatefilterproxymodel.h
@@ -16,18 +16,24 @@
#include <QSortFilterProxyModel>
class BtCheckStateFilterProxyModel: public QSortFilterProxyModel {
- Q_OBJECT
+ Q_OBJECT
public:
BtCheckStateFilterProxyModel(QObject *parent = 0);
virtual ~BtCheckStateFilterProxyModel();
- inline bool enabled() const { return m_enabled; }
+ inline bool enabled() const {
+ return m_enabled;
+ }
void setEnabled(bool enable);
- inline bool showChecked() const { return m_showChecked; }
+ inline bool showChecked() const {
+ return m_showChecked;
+ }
void setShowChecked(bool show);
- inline bool showUnchecked() const { return m_showUnchecked; }
+ inline bool showUnchecked() const {
+ return m_showUnchecked;
+ }
void setShowUnchecked(bool show);
inline bool showPartiallyChecked() const {
diff --git a/src/backend/bookshelfmodel/btmodulenamefilterproxymodel.cpp b/src/backend/bookshelfmodel/btmodulenamefilterproxymodel.cpp
index f416175..31b93e1 100644
--- a/src/backend/bookshelfmodel/btmodulenamefilterproxymodel.cpp
+++ b/src/backend/bookshelfmodel/btmodulenamefilterproxymodel.cpp
@@ -13,8 +13,7 @@
#include "backend/bookshelfmodel/btmodulenamefilterproxymodel.h"
BtModuleNameFilterProxyModel::BtModuleNameFilterProxyModel(QObject *parent)
- : QSortFilterProxyModel(parent), m_enabled(true)
-{
+ : QSortFilterProxyModel(parent), m_enabled(true) {
setFilterCaseSensitivity(Qt::CaseInsensitive);
}
@@ -23,8 +22,7 @@ BtModuleNameFilterProxyModel::~BtModuleNameFilterProxyModel() {
}
bool BtModuleNameFilterProxyModel::filterAcceptsRow(int row,
- const QModelIndex &p) const
-{
+ const QModelIndex &p) const {
if (!m_enabled) return true;
const QAbstractItemModel *m(sourceModel());
@@ -34,7 +32,8 @@ bool BtModuleNameFilterProxyModel::filterAcceptsRow(int row,
int numChildren(m->rowCount(itemIndex));
if (numChildren == 0) {
return QSortFilterProxyModel::filterAcceptsRow(row, p);
- } else {
+ }
+ else {
for (int i(0); i < numChildren; i++) {
if (filterAcceptsRow(i, itemIndex)) return true;
}
diff --git a/src/backend/bookshelfmodel/btmodulenamefilterproxymodel.h b/src/backend/bookshelfmodel/btmodulenamefilterproxymodel.h
index dd6f652..e4499be 100644
--- a/src/backend/bookshelfmodel/btmodulenamefilterproxymodel.h
+++ b/src/backend/bookshelfmodel/btmodulenamefilterproxymodel.h
@@ -16,12 +16,14 @@
#include <QSortFilterProxyModel>
class BtModuleNameFilterProxyModel: public QSortFilterProxyModel {
- Q_OBJECT
+ Q_OBJECT
public:
BtModuleNameFilterProxyModel(QObject *parent = 0);
virtual ~BtModuleNameFilterProxyModel();
- inline bool enabled() const { return m_enabled; }
+ inline bool enabled() const {
+ return m_enabled;
+ }
void setEnabled(bool enable);
virtual bool filterAcceptsRow(int row, const QModelIndex &parent) const;
diff --git a/src/backend/bookshelfmodel/categoryitem.cpp b/src/backend/bookshelfmodel/categoryitem.cpp
index 0d4b853..3ce6e88 100644
--- a/src/backend/bookshelfmodel/categoryitem.cpp
+++ b/src/backend/bookshelfmodel/categoryitem.cpp
@@ -15,9 +15,15 @@
namespace BookshelfModel {
CategoryItem::CategoryItem(CSwordModuleInfo *module)
- : Item(ITEM_CATEGORY), m_category(module->category())
-{
+ : Item(ITEM_CATEGORY), m_category(module->category()) {
// Intentionally empty
}
+bool CategoryItem::operator<(const Item &other) const {
+ if (other.type() != ITEM_CATEGORY) {
+ return ITEM_CATEGORY < other.type();
+ }
+ return m_category < static_cast<const CategoryItem &>(other).m_category;
+}
+
} // namespace BookshelfModel
diff --git a/src/backend/bookshelfmodel/categoryitem.h b/src/backend/bookshelfmodel/categoryitem.h
index 3cf7996..40820a2 100644
--- a/src/backend/bookshelfmodel/categoryitem.h
+++ b/src/backend/bookshelfmodel/categoryitem.h
@@ -22,7 +22,7 @@
namespace BookshelfModel {
class CategoryItem: public Item {
- Q_DECLARE_TR_FUNCTIONS(CategoryItem);
+ Q_DECLARE_TR_FUNCTIONS(CategoryItem);
public:
static const Item::Type GROUP_TYPE = Item::ITEM_CATEGORY;
@@ -45,6 +45,8 @@ class CategoryItem: public Item {
return module->category() == m_category;
}
+ bool operator<(const Item &other) const;
+
protected:
CSwordModuleInfo::Category m_category;
};
diff --git a/src/backend/bookshelfmodel/distributionitem.cpp b/src/backend/bookshelfmodel/distributionitem.cpp
index 411e236..4ae81c5 100644
--- a/src/backend/bookshelfmodel/distributionitem.cpp
+++ b/src/backend/bookshelfmodel/distributionitem.cpp
@@ -15,8 +15,7 @@
namespace BookshelfModel {
DistributionItem::DistributionItem(CSwordModuleInfo *module)
- : Item(ITEM_DISTRIBUTION)
-{
+ : Item(ITEM_DISTRIBUTION) {
m_distribution = module->config(CSwordModuleInfo::DistributionSource);
}
diff --git a/src/backend/bookshelfmodel/distributionitem.h b/src/backend/bookshelfmodel/distributionitem.h
index ac3912d..44ae591 100644
--- a/src/backend/bookshelfmodel/distributionitem.h
+++ b/src/backend/bookshelfmodel/distributionitem.h
@@ -25,13 +25,17 @@ class DistributionItem: public Item {
DistributionItem(CSwordModuleInfo *module);
- inline QString distribution() const { return m_distribution; }
+ inline QString distribution() const {
+ return m_distribution;
+ }
- inline QString name() const { return m_distribution; }
+ inline QString name() const {
+ return m_distribution;
+ }
inline bool fitFor(CSwordModuleInfo *module) {
return module->config(CSwordModuleInfo::DistributionSource)
- == m_distribution;
+ == m_distribution;
}
protected:
diff --git a/src/backend/bookshelfmodel/item.cpp b/src/backend/bookshelfmodel/item.cpp
index 22bed91..8556274 100644
--- a/src/backend/bookshelfmodel/item.cpp
+++ b/src/backend/bookshelfmodel/item.cpp
@@ -19,8 +19,7 @@
namespace BookshelfModel {
Item::Item(Type type)
- : m_type(type), m_parent(0), m_checkState(Qt::Unchecked)
-{
+ : m_type(type), m_parent(0), m_checkState(Qt::Unchecked) {
// Intentionally empty
}
diff --git a/src/backend/bookshelfmodel/item.h b/src/backend/bookshelfmodel/item.h
index cb2e6d9..b24b503 100644
--- a/src/backend/bookshelfmodel/item.h
+++ b/src/backend/bookshelfmodel/item.h
@@ -38,18 +38,24 @@ class Item {
/**
\brief Returns the type of this item.
*/
- inline Type type() const { return m_type; }
+ inline Type type() const {
+ return m_type;
+ }
/**
\brief Returns a pointer to the parent item of this item.
\retval 0 if this item has no parent.
*/
- inline Item *parent() const { return m_parent; }
+ inline Item *parent() const {
+ return m_parent;
+ }
/**
\brief Returns the list of child items of this node.
*/
- inline const QList<Item*> &children() const { return m_children; }
+ inline const QList<Item*> &children() const {
+ return m_children;
+ }
/**
\brief Returns a pointer to the child item at the given index.
@@ -111,17 +117,23 @@ class Item {
/**
\brief Returns the visible name of the item.
*/
- inline virtual QString name() const { return QString::null; }
+ inline virtual QString name() const {
+ return QString::null;
+ }
/**
\brief Returns the visible icon of the item.
*/
- inline virtual QIcon icon() const { return QIcon(); }
+ inline virtual QIcon icon() const {
+ return QIcon();
+ }
/**
\brief Returns the check state of this item.
*/
- inline const Qt::CheckState checkState() const { return m_checkState; }
+ inline const Qt::CheckState checkState() const {
+ return m_checkState;
+ }
/**
\brief Sets the check state of this item.
@@ -145,7 +157,7 @@ class Item {
/**
\brief Comparsion operator used sorting child items.
*/
- bool operator<(const Item &other) const;
+ virtual bool operator<(const Item &other) const;
protected:
inline void setParent(Item *parent) {
diff --git a/src/backend/bookshelfmodel/languageitem.cpp b/src/backend/bookshelfmodel/languageitem.cpp
index 6c2af30..6758178 100644
--- a/src/backend/bookshelfmodel/languageitem.cpp
+++ b/src/backend/bookshelfmodel/languageitem.cpp
@@ -15,8 +15,7 @@
namespace BookshelfModel {
LanguageItem::LanguageItem(CSwordModuleInfo *module)
- : Item(ITEM_LANGUAGE), m_language(module->language())
-{
+ : Item(ITEM_LANGUAGE), m_language(module->language()) {
// Intentionally empty
}
diff --git a/src/backend/bookshelfmodel/languageitem.h b/src/backend/bookshelfmodel/languageitem.h
index 3b329f1..262ca65 100644
--- a/src/backend/bookshelfmodel/languageitem.h
+++ b/src/backend/bookshelfmodel/languageitem.h
@@ -27,7 +27,9 @@ class LanguageItem: public Item {
LanguageItem(CSwordModuleInfo *module);
- inline const CLanguageMgr::Language *language() const { return m_language; }
+ inline const CLanguageMgr::Language *language() const {
+ return m_language;
+ }
inline QString name() const {
return BtBookshelfModel::languageName(m_language);
diff --git a/src/backend/bookshelfmodel/moduleitem.cpp b/src/backend/bookshelfmodel/moduleitem.cpp
index 6a543bc..8d02111 100644
--- a/src/backend/bookshelfmodel/moduleitem.cpp
+++ b/src/backend/bookshelfmodel/moduleitem.cpp
@@ -17,8 +17,7 @@
namespace BookshelfModel {
ModuleItem::ModuleItem(CSwordModuleInfo *module)
- : Item(ITEM_MODULE), m_moduleInfo(module)
-{
+ : Item(ITEM_MODULE), m_moduleInfo(module) {
Q_ASSERT(module != 0);
}
diff --git a/src/backend/bookshelfmodel/moduleitem.h b/src/backend/bookshelfmodel/moduleitem.h
index 7bafc1f..40ecc79 100644
--- a/src/backend/bookshelfmodel/moduleitem.h
+++ b/src/backend/bookshelfmodel/moduleitem.h
@@ -24,12 +24,16 @@ class ModuleItem: public Item {
public:
ModuleItem(CSwordModuleInfo *module);
- CSwordModuleInfo *moduleInfo() const { return m_moduleInfo; }
+ CSwordModuleInfo *moduleInfo() const {
+ return m_moduleInfo;
+ }
- inline QString name() const { return m_moduleInfo->name(); }
+ inline QString name() const {
+ return m_moduleInfo->name();
+ }
inline QIcon icon() const {
- return BtBookshelfModel::categoryIcon(m_moduleInfo->category());
+ return BtBookshelfModel::moduleIcon(m_moduleInfo);
}
protected: