17#include <QtAlgorithms>
19#include "../../util/btassert.h"
20#include "../../util/btconnect.h"
21#include "../../util/macros.h"
22#include "../drivers/cswordmoduleinfo.h"
23#include "../drivers/btconstmoduleset.h"
46 return module->name();
47 case Qt::DecorationRole:
51 return QVariant::fromValue(
static_cast<void *
>(
module));
57 return module->isHidden();
59 return module->config(CSwordModuleInfo::AbsoluteDataPath);
61 return module->hasIndex();
63 return module->indexSize();
65 return module->config(CSwordModuleInfo::Description);
67 return QStringLiteral(
"<b>%1:</b><br/>%2")
77 if (!index.isValid() || index.column() != 0 || index.parent().isValid())
80 int const row = index.row();
88 Qt::Orientation
const orientation,
91 if (role == Qt::DisplayRole
92 && orientation == Qt::Horizontal
102 QVariant
const & value,
105 int const row = index.row();
109 && index.column() == 0)
117 return m_data.at(row)->setHidden(value.toBool());
126 beginRemoveRows(QModelIndex(), 0,
m_data.size() - 1);
139 const int index(
m_data.size());
140 beginInsertRows(QModelIndex(), index, index);
152 bool const destroy) {
157 beginRemoveRows(QModelIndex(), index, index);
174 for (
auto module: modules)
183 for (
auto const *
const module : modules)
195 BT_ASSERT(qobject_cast<CSwordModuleInfo *>(sender()));
201 BT_ASSERT(qobject_cast<CSwordModuleInfo *>(sender()));
207 BT_ASSERT(qobject_cast<CSwordModuleInfo *>(sender()));
216 Q_EMIT dataChanged(i, i);
bool setData(QModelIndex const &index, QVariant const &value, int role=ModuleHiddenRole) override
static std::shared_ptr< BtBookshelfModel > newInstance()
void removeModule(CSwordModuleInfo *const module, bool destroy=false)
void addModule(CSwordModuleInfo *const module)
void moduleIndexed(bool indexed)
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
~BtBookshelfModel() noexcept override
CSwordModuleInfo * getModule(QString const &name) const
CSwordModuleInfo * module(QModelIndex const &index) const
QList< CSwordModuleInfo * > m_data
QVariant data(CSwordModuleInfo *module, int role) const
void moduleHidden(bool hidden)
void moduleUnlocked(bool unlocked)
void moduleDataChanged(CSwordModuleInfo *module)
BtBookshelfModel(BtBookshelfModel &&)=delete
void removeModules(BtConstModuleSet const &modules, bool destroy=false)
void clear(bool destroy=false)
QString config(const CSwordModuleInfo::ConfigEntry entry) const
QString const & name() const
void hasIndexChanged(bool hasIndex)
void hiddenChanged(bool hidden)
void unlockedChanged(bool unlocked)
CSwordModuleInfo::Category category() const
#define UNLIKELY(c)
Gives the compiler a hint that the given conditional is likely to evaluate to false.
Used to restrict construction to newInstance() only.