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

#include <btbookshelfmodel.h>

Inheritance diagram for BtBookshelfModel:

Classes

struct  ConstructInPrivate
 Used to restrict construction to newInstance() only. More...
 

Public Types

enum  ModuleRole {
  ModuleNameRole = Qt::UserRole , ModuleIconRole , ModulePointerRole , ModuleCategoryRole ,
  ModuleLanguageRole , ModuleHiddenRole , ModuleInstallPathRole , ModuleHasIndexRole ,
  ModuleIndexSizeRole , ModuleDescriptionRole , UserRole
}
 

Public Member Functions

void addModule (CSwordModuleInfo *const module)
 
 BtBookshelfModel (BtBookshelfModel &&)=delete
 
 BtBookshelfModel (BtBookshelfModel const &)=delete
 
 BtBookshelfModel (ConstructInPrivate const &)
 
void clear (bool destroy=false)
 
QVariant data (CSwordModuleInfo *module, int role) const
 
QVariant data (QModelIndex const &index, int role) const override
 
CSwordModuleInfogetModule (QString const &name) const
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 
CSwordModuleInfomodule (QModelIndex const &index) const
 
QList< CSwordModuleInfo * > const & moduleList () const
 
BtBookshelfModeloperator= (BtBookshelfModel &&)=delete
 
BtBookshelfModeloperator= (BtBookshelfModel const &)=delete
 
void removeModule (CSwordModuleInfo *const module, bool destroy=false)
 
void removeModules (BtConstModuleSet const &modules, bool destroy=false)
 
void removeModules (QList< CSwordModuleInfo * > const &modules, bool destroy=false)
 
int rowCount (QModelIndex const &parent=QModelIndex()) const override
 
bool setData (QModelIndex const &index, QVariant const &value, int role=ModuleHiddenRole) override
 
 ~BtBookshelfModel () noexcept override
 

Static Public Member Functions

static std::shared_ptr< BtBookshelfModelnewInstance ()
 

Protected Slots

void moduleHidden (bool hidden)
 
void moduleIndexed (bool indexed)
 
void moduleUnlocked (bool unlocked)
 

Private Member Functions

void moduleDataChanged (CSwordModuleInfo *module)
 

Private Attributes

QList< CSwordModuleInfo * > m_data
 

Detailed Description

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.

Definition at line 35 of file btbookshelfmodel.h.

Member Enumeration Documentation

◆ ModuleRole

Enumerator
ModuleNameRole 
ModuleIconRole 
ModulePointerRole 
ModuleCategoryRole 
ModuleLanguageRole 
ModuleHiddenRole 
ModuleInstallPathRole 
ModuleHasIndexRole 
ModuleIndexSizeRole 
ModuleDescriptionRole 
UserRole 

Definition at line 41 of file btbookshelfmodel.h.

Constructor & Destructor Documentation

◆ BtBookshelfModel() [1/3]

BtBookshelfModel::BtBookshelfModel ( BtBookshelfModel &&  )
delete

◆ BtBookshelfModel() [2/3]

BtBookshelfModel::BtBookshelfModel ( BtBookshelfModel const &  )
delete

◆ BtBookshelfModel() [3/3]

BtBookshelfModel::BtBookshelfModel ( ConstructInPrivate const &  )

Definition at line 26 of file btbookshelfmodel.cpp.

◆ ~BtBookshelfModel()

BtBookshelfModel::~BtBookshelfModel ( )
overridedefaultnoexcept

Member Function Documentation

◆ addModule()

void BtBookshelfModel::addModule ( CSwordModuleInfo *const  module)

Appends the given module to this model.

Parameters
[in]moduleModule to add.

Definition at line 133 of file btbookshelfmodel.cpp.

References BT_ASSERT, BT_CONNECT, CSwordModuleInfo::hasIndexChanged(), CSwordModuleInfo::hiddenChanged(), m_data, module(), moduleHidden(), moduleIndexed(), moduleUnlocked(), and CSwordModuleInfo::unlockedChanged().

◆ clear()

void BtBookshelfModel::clear ( bool  destroy = false)

Clears the data of the whole model by removing all items.

Parameters
[in]destroyIf true, all CSwordModuleInfo instances in this model are also destroyed.

Definition at line 122 of file btbookshelfmodel.cpp.

References m_data.

◆ data() [1/2]

QVariant BtBookshelfModel::data ( CSwordModuleInfo module,
int  role 
) const

◆ data() [2/2]

QVariant BtBookshelfModel::data ( QModelIndex const &  index,
int  role 
) const
override

Definition at line 75 of file btbookshelfmodel.cpp.

References data(), and m_data.

◆ getModule()

CSwordModuleInfo * BtBookshelfModel::getModule ( QString const &  name) const

Returns the first module found with the given name.

Parameters
[in]nameName of the module to find.

Definition at line 187 of file btbookshelfmodel.cpp.

References m_data, module(), CSwordModuleInfo::name(), and UNLIKELY.

◆ headerData()

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

Definition at line 87 of file btbookshelfmodel.cpp.

◆ module()

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

Given an index of this model, this method returns a pointer to the underlying CSwordModuleInfo instance corresponding to the given index.

Parameters
[in]indexAn index to this model.

Definition at line 90 of file btbookshelfmodel.h.

References data(), and ModulePointerRole.

Referenced by addModule(), data(), getModule(), moduleDataChanged(), removeModule(), removeModules(), and removeModules().

◆ moduleDataChanged()

void BtBookshelfModel::moduleDataChanged ( CSwordModuleInfo module)
private

Called internally when module data changes. This method emits any neccessary signals for this model.

Precondition
The givem module is handled by this model.
Parameters
[in]moduleThe module that changed status.

Definition at line 212 of file btbookshelfmodel.cpp.

References BT_ASSERT, m_data, and module().

Referenced by moduleHidden(), moduleIndexed(), and moduleUnlocked().

◆ moduleHidden

void BtBookshelfModel::moduleHidden ( bool  hidden)
protectedslot

Slot DIRECTLY called by CSwordModuleInfo when the hidden status of the respective module changes.

Parameters
[in]hiddenTrue, if the module was hidden; false, if the module was shown.

Definition at line 194 of file btbookshelfmodel.cpp.

References BT_ASSERT, and moduleDataChanged().

Referenced by addModule(), and removeModule().

◆ moduleIndexed

void BtBookshelfModel::moduleIndexed ( bool  indexed)
protectedslot

Slot DIRECTLY called by CSwordModuleInfo when the indexed status of the respective module changes.

Parameters
[in]indexedTrue, if the module was indexed; false if the index was deleted.

Definition at line 200 of file btbookshelfmodel.cpp.

References BT_ASSERT, and moduleDataChanged().

Referenced by addModule(), and removeModule().

◆ moduleList()

QList< CSwordModuleInfo * > const & BtBookshelfModel::moduleList ( ) const
inline

Returns the list of handled modules as a list of CSwordModuleInfo* pointers.

Definition at line 144 of file btbookshelfmodel.h.

References m_data.

◆ moduleUnlocked

void BtBookshelfModel::moduleUnlocked ( bool  unlocked)
protectedslot

Slot DIRECTLY called by CSwordModuleInfo when the locked status of the respective module changes.

Parameters
[in]unlockedTrue, if the module was unlocked; false if the module was locked.

Definition at line 206 of file btbookshelfmodel.cpp.

References BT_ASSERT, and moduleDataChanged().

Referenced by addModule(), and removeModule().

◆ newInstance()

std::shared_ptr< BtBookshelfModel > BtBookshelfModel::newInstance ( )
static

Definition at line 28 of file btbookshelfmodel.cpp.

Referenced by BtBookshelfWorksPage::BtBookshelfWorksPage().

◆ operator=() [1/2]

BtBookshelfModel & BtBookshelfModel::operator= ( BtBookshelfModel &&  )
delete

◆ operator=() [2/2]

BtBookshelfModel & BtBookshelfModel::operator= ( BtBookshelfModel const &  )
delete

◆ removeModule()

void BtBookshelfModel::removeModule ( CSwordModuleInfo *const  module,
bool  destroy = false 
)

Removes the given module from this model and optionally destroys it.

Parameters
[in]moduleThe module to remove from this model.
[in]destroyIf true, the given CSwordModuleInfo instance is destroyed.

Definition at line 151 of file btbookshelfmodel.cpp.

References CSwordModuleInfo::hasIndexChanged(), CSwordModuleInfo::hiddenChanged(), m_data, module(), moduleHidden(), moduleIndexed(), moduleUnlocked(), and CSwordModuleInfo::unlockedChanged().

Referenced by removeModules().

◆ removeModules() [1/2]

void BtBookshelfModel::removeModules ( BtConstModuleSet const &  modules,
bool  destroy = false 
)

Removes all modules from the given set from this model and optionally destroys them.

Parameters
[in]modulesThe set of modules to remove from this model.
[in]destroyIf true, the given CSwordModuleInfo instances are destroyed.

Definition at line 179 of file btbookshelfmodel.cpp.

References module(), and removeModule().

Referenced by removeModules().

◆ removeModules() [2/2]

void BtBookshelfModel::removeModules ( QList< CSwordModuleInfo * > const &  modules,
bool  destroy = false 
)

Removes all modules from the given list from this model and optionally destroys them.

Parameters
[in]modulesThe list of modules to remove from this model.
[in]destroyIf true, the given CSwordModuleInfo instances are destroyed.

Definition at line 170 of file btbookshelfmodel.cpp.

References module(), and removeModules().

◆ rowCount()

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

Definition at line 33 of file btbookshelfmodel.cpp.

◆ setData()

bool BtBookshelfModel::setData ( QModelIndex const &  index,
QVariant const &  value,
int  role = ModuleHiddenRole 
)
override

Definition at line 101 of file btbookshelfmodel.cpp.

References m_data, and ModuleHiddenRole.

Member Data Documentation

◆ m_data

QList<CSwordModuleInfo *> BtBookshelfModel::m_data
private

The underlying data as a list of pointers to the respective CSwordModuleInfo instances.

Definition at line 186 of file btbookshelfmodel.h.

Referenced by addModule(), clear(), data(), getModule(), moduleDataChanged(), moduleList(), removeModule(), and setData().


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