diff options
Diffstat (limited to 'src/backend/btmoduletreeitem.cpp')
-rw-r--r-- | src/backend/btmoduletreeitem.cpp | 76 |
1 files changed, 41 insertions, 35 deletions
diff --git a/src/backend/btmoduletreeitem.cpp b/src/backend/btmoduletreeitem.cpp index c57d094..4c16231 100644 --- a/src/backend/btmoduletreeitem.cpp +++ b/src/backend/btmoduletreeitem.cpp @@ -9,7 +9,6 @@ #include "backend/btmoduletreeitem.h" -#include <QDebug> #include <QList> #include <QString> #include "backend/drivers/cswordmoduleinfo.h" @@ -24,7 +23,8 @@ BTModuleTreeItem::BTModuleTreeItem(QList<BTModuleTreeItem::Filter*>& filters, BT m_firstChild(0), m_next(0), m_type(BTModuleTreeItem::Root), - m_category(CSwordModuleInfo::UnknownCategory) { + m_category(CSwordModuleInfo::UnknownCategory), + m_grouping (grouping) { if (modules) { m_originalModuleList = *modules; } @@ -32,7 +32,7 @@ BTModuleTreeItem::BTModuleTreeItem(QList<BTModuleTreeItem::Filter*>& filters, BT m_originalModuleList = CSwordBackend::instance()->moduleList(); } //populate the tree with groups/modules - create_tree(filters, grouping); + create_tree(filters); } /** @@ -64,12 +64,10 @@ BTModuleTreeItem::~BTModuleTreeItem() { } QList<BTModuleTreeItem*> BTModuleTreeItem::children() const { - //qDebug() << "BTModuleTreeItem::children"; QList<BTModuleTreeItem*> childList; if (m_firstChild) { BTModuleTreeItem* child = m_firstChild; while (child) { - //qDebug() << "child:" << child->text(); childList.append(child); child = child->m_next; } @@ -120,26 +118,26 @@ QString BTModuleTreeItem::iconName() const { return QString::null; } - -void BTModuleTreeItem::create_tree(QList<BTModuleTreeItem::Filter*>& filters, BTModuleTreeItem::Grouping grouping) { - qDebug() << "BTModuleTreeItem::create_tree"; - static bool map_initialized = false; - static QMap<CSwordModuleInfo::Category, QString> CategoryNamesMap; - if (!map_initialized) { - CategoryNamesMap.insert(CSwordModuleInfo::Commentaries, QObject::tr("Commentaries")); - CategoryNamesMap.insert(CSwordModuleInfo::Cult, QObject::tr("Cults/Unorthodox")); - CategoryNamesMap.insert(CSwordModuleInfo::Images, QObject::tr("Maps and Images")); - CategoryNamesMap.insert(CSwordModuleInfo::DailyDevotional, QObject::tr("Daily Devotionals")); - CategoryNamesMap.insert(CSwordModuleInfo::Lexicons, QObject::tr("Lexicons and Dictionaries")); - CategoryNamesMap.insert(CSwordModuleInfo::Bibles, QObject::tr("Bibles")); - CategoryNamesMap.insert(CSwordModuleInfo::Glossary, QObject::tr("Glossaries")); - CategoryNamesMap.insert(CSwordModuleInfo::Books, QObject::tr("Books")); - - map_initialized = true; +bool BTModuleTreeItem::m_map_initialized = false; +QMap<CSwordModuleInfo::Category, QString> BTModuleTreeItem::m_CategoryNamesMap; + +void BTModuleTreeItem::create_tree(QList<BTModuleTreeItem::Filter*>& filters) { + if (!m_map_initialized) { + m_CategoryNamesMap.insert(CSwordModuleInfo::Commentaries, QObject::tr("Commentaries")); + m_CategoryNamesMap.insert(CSwordModuleInfo::Cult, QObject::tr("Cults/Unorthodox")); + m_CategoryNamesMap.insert(CSwordModuleInfo::Images, QObject::tr("Maps and Images")); + m_CategoryNamesMap.insert(CSwordModuleInfo::DailyDevotional, QObject::tr("Daily Devotionals")); + m_CategoryNamesMap.insert(CSwordModuleInfo::Lexicons, QObject::tr("Lexicons and Dictionaries")); + m_CategoryNamesMap.insert(CSwordModuleInfo::Bibles, QObject::tr("Bibles")); + m_CategoryNamesMap.insert(CSwordModuleInfo::Glossary, QObject::tr("Glossaries")); + m_CategoryNamesMap.insert(CSwordModuleInfo::Books, QObject::tr("Books")); + + m_map_initialized = true; } + add_items(filters); +} - //QList<CSwordModuleInfo*> originalInfoList = CSwordBackend::instance()()->moduleList(); - +void BTModuleTreeItem::add_items(QList<BTModuleTreeItem::Filter*>& filters) { foreach (CSwordModuleInfo* info, m_originalModuleList) { bool included; included = true; @@ -150,39 +148,37 @@ void BTModuleTreeItem::create_tree(QList<BTModuleTreeItem::Filter*>& filters, BT } } if (included) { - //qDebug() << "a module will be included: " << info->name(); - BTModuleTreeItem* parentGroupForModule = this; BTModuleTreeItem* parentGroupForLanguage = this; BTModuleTreeItem* parentGroupForCategory = this; //the order of if(grouping...) clauses is important - if (grouping == BTModuleTreeItem::LangMod || grouping == BTModuleTreeItem::LangCatMod) { + if (m_grouping == BTModuleTreeItem::LangMod || m_grouping == BTModuleTreeItem::LangCatMod) { BTModuleTreeItem* langItem = create_parent_item(parentGroupForLanguage, info->language()->translatedName(), BTModuleTreeItem::Language); - if (grouping == BTModuleTreeItem::LangMod) + if (m_grouping == BTModuleTreeItem::LangMod) parentGroupForModule = langItem; else parentGroupForCategory = langItem; } - if (grouping == BTModuleTreeItem::CatMod || grouping == BTModuleTreeItem::CatLangMod) { - BTModuleTreeItem* catItem = create_parent_item(parentGroupForCategory, CategoryNamesMap.value(info->category()), BTModuleTreeItem::Category, info->category()); + if (m_grouping == BTModuleTreeItem::CatMod || m_grouping == BTModuleTreeItem::CatLangMod) { + BTModuleTreeItem* catItem = create_parent_item(parentGroupForCategory, m_CategoryNamesMap.value(info->category()), BTModuleTreeItem::Category, info->category()); - if (grouping == BTModuleTreeItem::CatMod) + if (m_grouping == BTModuleTreeItem::CatMod) parentGroupForModule = catItem; else parentGroupForLanguage = catItem; } - if (grouping == BTModuleTreeItem::CatLangMod) { + if (m_grouping == BTModuleTreeItem::CatLangMod) { // category is there already, create language and make it the parent for the module parentGroupForModule = create_parent_item(parentGroupForLanguage, info->language()->translatedName(), BTModuleTreeItem::Language); } - if (grouping == BTModuleTreeItem::LangCatMod) { + if (m_grouping == BTModuleTreeItem::LangCatMod) { //language is there already, create category and make it the parent for the module - parentGroupForModule = create_parent_item(parentGroupForCategory, CategoryNamesMap.value(info->category()), BTModuleTreeItem::Category, info->category()); + parentGroupForModule = create_parent_item(parentGroupForCategory, m_CategoryNamesMap.value(info->category()), BTModuleTreeItem::Category, info->category()); } // the parent group for module has been set above, now just add the module to it @@ -214,8 +210,6 @@ BTModuleTreeItem* BTModuleTreeItem::create_parent_item( } void BTModuleTreeItem::sort_children(BTModuleTreeItem* parent) { - //qDebug() << "BTModuleTreeItem::sort_children"; - // sort each child recursively depth-first foreach(BTModuleTreeItem* item, parent->children()) { sort_children(item); @@ -259,3 +253,15 @@ bool BTModuleTreeItem::localeAwareLessThan(BTModuleTreeItem* first, BTModuleTree } return (QString::localeAwareCompare(first->text(), second->text()) < 0 ); } + +QDataStream &operator<<(QDataStream &out, const BTModuleTreeItem::Grouping &grouping) { + out << (qint8) grouping; + return out; +} + +QDataStream &operator>>(QDataStream &in, BTModuleTreeItem::Grouping &grouping) { + qint8 i; + in >> i; + grouping = (BTModuleTreeItem::Grouping) i; + return in; +} |