BibleTime
Classes | Public Types | Public Slots | Signals | Public Member Functions | Protected Slots | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
BtBookshelfTreeModel Class Reference

#include <btbookshelftreemodel.h>

Inheritance diagram for BtBookshelfTreeModel:

Classes

class  Grouping
 

Public Types

enum  CheckedBehavior { CHECKED , UNCHECKED , MODULE_HIDDEN , MODULE_INDEXED }
 
enum  Group { GROUP_CATEGORY = 0 , GROUP_LANGUAGE = 1 , GROUP_INDEXING }
 
enum  ModuleRole { CheckStateRole = BtBookshelfModel::UserRole , UserRole = BtBookshelfModel::UserRole + 100 }
 

Public Slots

void setCheckable (bool checkable)
 
void setCheckedModules (BtConstModuleSet const &modules)
 
void setDefaultChecked (CheckedBehavior b)
 
void setGroupingOrder (const BtBookshelfTreeModel::Grouping &groupingOrder, bool emitSignal=true)
 
void setSourceModel (std::shared_ptr< QAbstractItemModel > sourceModel)
 

Signals

void groupingOrderChanged (BtBookshelfTreeModel::Grouping newGrouping)
 
void moduleChecked (CSwordModuleInfo *module, bool checked)
 

Public Member Functions

 BtBookshelfTreeModel (BtConfigCore const &config, QString const &configKey, QObject *parent=nullptr)
 
 BtBookshelfTreeModel (const Grouping &grouping, QObject *parent=nullptr)
 
 BtBookshelfTreeModel (QObject *parent=nullptr)
 
bool checkable () const
 
BtModuleSet const & checkedModules () const
 
int columnCount (const QModelIndex &parent=QModelIndex()) const override
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
QVariant data (CSwordModuleInfo &module, int role=Qt::DisplayRole) const
 
CheckedBehavior defaultChecked () const
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 
Grouping const & groupingOrder () const
 
bool hasChildren (const QModelIndex &parent=QModelIndex()) const override
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const override
 
CSwordModuleInfomodule (QModelIndex const &index) const
 
QList< CSwordModuleInfo * > modules () const
 
QModelIndex parent (const QModelIndex &index) const override
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
bool setData (const QModelIndex &index, const QVariant &value, int role) override
 
std::shared_ptr< QAbstractItemModelsourceModel () const noexcept
 
 ~BtBookshelfTreeModel () override
 

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 Member Functions

void resetData ()
 

Private Types

using ModuleItemMap = QMap< CSwordModuleInfo *, BookshelfModel::ModuleItem * >
 
using SourceIndexMap = QMap< CSwordModuleInfo *, QPersistentModelIndex >
 

Private Member Functions

void addModule (CSwordModuleInfo &module, bool checked)
 
void addModule (CSwordModuleInfo &module, QModelIndex parentIndex, Grouping &intermediateGrouping, bool checked)
 
template<class T >
QModelIndex getGroup (CSwordModuleInfo &module, QModelIndex parentIndex)
 
QModelIndex getIndex (const BookshelfModel::Item &item)
 
BookshelfModel::ItemgetItem (const QModelIndex &index) const
 
void removeModule (CSwordModuleInfo &module)
 
void resetParentCheckStates (QModelIndex parentIndex)
 

Private Attributes

bool m_checkable
 
BtModuleSet m_checkedModulesCache
 
CheckedBehavior m_defaultChecked
 
Grouping m_groupingOrder
 
ModuleItemMap m_modules
 
std::unique_ptr< BookshelfModel::Itemm_rootItem
 
SourceIndexMap m_sourceIndexMap
 
std::shared_ptr< QAbstractItemModelm_sourceModel
 

Detailed Description

Definition at line 36 of file btbookshelftreemodel.h.

Member Typedef Documentation

◆ ModuleItemMap

Definition at line 43 of file btbookshelftreemodel.h.

◆ SourceIndexMap

using BtBookshelfTreeModel::SourceIndexMap = QMap<CSwordModuleInfo *, QPersistentModelIndex>
private

Definition at line 44 of file btbookshelftreemodel.h.

Member Enumeration Documentation

◆ CheckedBehavior

Enumerator
CHECKED 

Check all added modules by default.

UNCHECKED 

Uncheck all added modules by default.

MODULE_HIDDEN 

By default, check only added modules that are not hidden.

MODULE_INDEXED 

By default, check only added modules that are indexed.

Definition at line 59 of file btbookshelftreemodel.h.

◆ Group

Enumerator
GROUP_CATEGORY 
GROUP_LANGUAGE 
GROUP_INDEXING 

Definition at line 53 of file btbookshelftreemodel.h.

◆ ModuleRole

Enumerator
CheckStateRole 
UserRole 

Definition at line 48 of file btbookshelftreemodel.h.

Constructor & Destructor Documentation

◆ BtBookshelfTreeModel() [1/3]

BtBookshelfTreeModel::BtBookshelfTreeModel ( QObject parent = nullptr)

Definition at line 54 of file btbookshelftreemodel.cpp.

◆ BtBookshelfTreeModel() [2/3]

BtBookshelfTreeModel::BtBookshelfTreeModel ( BtConfigCore const &  config,
QString const &  configKey,
QObject parent = nullptr 
)

Definition at line 60 of file btbookshelftreemodel.cpp.

◆ BtBookshelfTreeModel() [3/3]

BtBookshelfTreeModel::BtBookshelfTreeModel ( const Grouping grouping,
QObject parent = nullptr 
)

Definition at line 69 of file btbookshelftreemodel.cpp.

◆ ~BtBookshelfTreeModel()

BtBookshelfTreeModel::~BtBookshelfTreeModel ( )
overridedefault

Member Function Documentation

◆ addModule() [1/2]

void BtBookshelfTreeModel::addModule ( CSwordModuleInfo module,
bool  checked 
)
private
Bug:
Calling reset() shouldn't be necessary here, but omitting it will will break things like switching to a grouped layout or installing new modules. As a side effect, all attached views will also reset themselves.

Definition at line 369 of file btbookshelftreemodel.cpp.

References m_groupingOrder, m_modules, and module().

Referenced by addModule(), moduleInserted(), setGroupingOrder(), and setSourceModel().

◆ addModule() [2/2]

void BtBookshelfTreeModel::addModule ( CSwordModuleInfo module,
QModelIndex  parentIndex,
Grouping intermediateGrouping,
bool  checked 
)
private

◆ checkable()

bool BtBookshelfTreeModel::checkable ( ) const
inline

Definition at line 134 of file btbookshelftreemodel.h.

References m_checkable.

Referenced by setCheckable().

◆ checkedModules()

BtModuleSet const& BtBookshelfTreeModel::checkedModules ( ) const
inline

◆ columnCount()

int BtBookshelfTreeModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 83 of file btbookshelftreemodel.cpp.

References parent().

Referenced by resetData().

◆ data() [1/2]

QVariant BtBookshelfTreeModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
override

◆ data() [2/2]

QVariant BtBookshelfTreeModel::data ( CSwordModuleInfo module,
int  role = Qt::DisplayRole 
) const

Definition at line 158 of file btbookshelftreemodel.cpp.

References BT_ASSERT, m_sourceIndexMap, m_sourceModel, and module().

◆ defaultChecked()

CheckedBehavior BtBookshelfTreeModel::defaultChecked ( ) const
inline

Definition at line 135 of file btbookshelftreemodel.h.

References m_defaultChecked.

◆ flags()

Qt::ItemFlags BtBookshelfTreeModel::flags ( const QModelIndex &  index) const
override

Definition at line 220 of file btbookshelftreemodel.cpp.

References index(), m_checkable, and BookshelfModel::Item::type().

◆ getGroup()

template<class T >
QModelIndex BtBookshelfTreeModel::getGroup ( CSwordModuleInfo module,
QModelIndex  parentIndex 
)
inlineprivate

◆ getIndex()

QModelIndex BtBookshelfTreeModel::getIndex ( const BookshelfModel::Item item)
private

◆ getItem()

Item & BtBookshelfTreeModel::getItem ( const QModelIndex &  index) const
private

Definition at line 461 of file btbookshelftreemodel.cpp.

References BT_ASSERT, index(), m_rootItem, and UNLIKELY.

Referenced by addModule(), getGroup(), hasChildren(), index(), and rowCount().

◆ groupingOrder()

Grouping const& BtBookshelfTreeModel::groupingOrder ( ) const
inline

Definition at line 133 of file btbookshelftreemodel.h.

References m_groupingOrder.

Referenced by BtBookshelfDockWidget::groupingOrder(), and setGroupingOrder().

◆ groupingOrderChanged

void BtBookshelfTreeModel::groupingOrderChanged ( BtBookshelfTreeModel::Grouping  newGrouping)
signal

◆ hasChildren()

bool BtBookshelfTreeModel::hasChildren ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 89 of file btbookshelftreemodel.cpp.

References BookshelfModel::Item::children(), getItem(), and parent().

◆ headerData()

QVariant BtBookshelfTreeModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
override

Definition at line 237 of file btbookshelftreemodel.cpp.

References m_sourceModel.

◆ index()

QModelIndex BtBookshelfTreeModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const
override

◆ module()

CSwordModuleInfo* BtBookshelfTreeModel::module ( QModelIndex const &  index) const
inline

◆ moduleChecked

void BtBookshelfTreeModel::moduleChecked ( CSwordModuleInfo module,
bool  checked 
)
signal

◆ moduleDataChanged

void BtBookshelfTreeModel::moduleDataChanged ( const QModelIndex &  topLeft,
const QModelIndex &  bottomRight 
)
protectedslot

◆ moduleInserted

void BtBookshelfTreeModel::moduleInserted ( const QModelIndex &  parent,
int  start,
int  end 
)
protectedslot

◆ moduleRemoved

void BtBookshelfTreeModel::moduleRemoved ( const QModelIndex &  parent,
int  start,
int  end 
)
protectedslot

◆ modules()

QList<CSwordModuleInfo *> BtBookshelfTreeModel::modules ( ) const
inline

Definition at line 136 of file btbookshelftreemodel.h.

References m_modules.

Referenced by setCheckedModules().

◆ parent()

QModelIndex BtBookshelfTreeModel::parent ( const QModelIndex &  index) const
override

◆ removeModule()

void BtBookshelfTreeModel::removeModule ( CSwordModuleInfo module)
private

◆ resetData()

void BtBookshelfTreeModel::resetData ( )
protected

Definition at line 354 of file btbookshelftreemodel.cpp.

References columnCount(), index(), parent(), and rowCount().

Referenced by setCheckable().

◆ resetParentCheckStates()

void BtBookshelfTreeModel::resetParentCheckStates ( QModelIndex  parentIndex)
private

◆ rowCount()

int BtBookshelfTreeModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 79 of file btbookshelftreemodel.cpp.

References BookshelfModel::Item::children(), getItem(), and parent().

Referenced by resetData().

◆ setCheckable

void BtBookshelfTreeModel::setCheckable ( bool  checkable)
slot

◆ setCheckedModules

void BtBookshelfTreeModel::setCheckedModules ( BtConstModuleSet const &  modules)
slot

◆ setData()

bool BtBookshelfTreeModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role 
)
override

◆ setDefaultChecked

void BtBookshelfTreeModel::setDefaultChecked ( CheckedBehavior  b)
inlineslot

◆ setGroupingOrder

void BtBookshelfTreeModel::setGroupingOrder ( const BtBookshelfTreeModel::Grouping groupingOrder,
bool  emitSignal = true 
)
slot

◆ setSourceModel

void BtBookshelfTreeModel::setSourceModel ( std::shared_ptr< QAbstractItemModel sourceModel)
slot

◆ sourceModel()

std::shared_ptr<QAbstractItemModel> BtBookshelfTreeModel::sourceModel ( ) const
inlinenoexcept

Definition at line 130 of file btbookshelftreemodel.h.

References m_sourceModel.

Referenced by setSourceModel(), and BtOpenWorkActionMenu::sourceModel().

Member Data Documentation

◆ m_checkable

bool BtBookshelfTreeModel::m_checkable
private

Definition at line 205 of file btbookshelftreemodel.h.

Referenced by checkable(), data(), flags(), and setCheckable().

◆ m_checkedModulesCache

BtModuleSet BtBookshelfTreeModel::m_checkedModulesCache
private

◆ m_defaultChecked

CheckedBehavior BtBookshelfTreeModel::m_defaultChecked
private

◆ m_groupingOrder

Grouping BtBookshelfTreeModel::m_groupingOrder
private

Definition at line 203 of file btbookshelftreemodel.h.

Referenced by addModule(), groupingOrder(), and setGroupingOrder().

◆ m_modules

ModuleItemMap BtBookshelfTreeModel::m_modules
private

◆ m_rootItem

std::unique_ptr<BookshelfModel::Item> BtBookshelfTreeModel::m_rootItem
private

◆ m_sourceIndexMap

SourceIndexMap BtBookshelfTreeModel::m_sourceIndexMap
private

◆ m_sourceModel

std::shared_ptr<QAbstractItemModel> BtBookshelfTreeModel::m_sourceModel
private

The documentation for this class was generated from the following files: