15 #include <QAbstractItemModel>
17 #include <QActionGroup>
18 #include <QModelIndex>
19 #include <QSortFilterProxyModel>
22 #include "../../backend/bookshelfmodel/btbookshelfmodel.h"
23 #include "../../backend/bookshelfmodel/btbookshelftreemodel.h"
24 #include "../../backend/config/btconfig.h"
25 #include "../../backend/drivers/cswordmoduleinfo.h"
26 #include "../../backend/managers/cswordbackend.h"
27 #include "../../util/btassert.h"
28 #include "../../util/btconnect.h"
29 #include "../btmenuview.h"
41 , m_moduleType(moduleType)
42 , m_showHidden(
btConfig().value<bool>(
43 QStringLiteral(
"GUI/bookshelfShowHidden"),
48 setSourceModel(m_sourceModel);
52 QModelIndex
const & sourceParentIndex)
55 auto const & model = *sourceModel();
56 auto const itemIndex = model.index(sourceRow, 0, sourceParentIndex);
60 && model.data(itemIndex,
65 return filterAcceptsRowNoHiddenCheck(sourceRow, sourceParentIndex);
69 QModelIndex
const & sourceParentIndex)
74 auto const itemIndex = model.
index(sourceRow, 0, sourceParentIndex);
77 if (
auto const numRows = model.rowCount(itemIndex)) {
78 for (
int i = 0; i < numRows; ++i)
79 if (filterAcceptsRowNoHiddenCheck(i, itemIndex))
84 auto const *
const module = model.module(itemIndex);
86 return (module->type() == m_moduleType)
103 QString
const & title,
108 , m_moduleType(moduleType_)
109 , m_sortedModel(new SortModel(moduleType_, this))
114 [
this](QModelIndex
const itemIndex) {
115 if (itemIndex.isValid()) {
116 auto const & sortedModel =
117 *static_cast<SortModel *>(m_sortedModel);
118 Q_EMIT sigModuleChosen(
119 sortedModel.m_sourceModel->module(
120 sortedModel.mapToSource(itemIndex)));
122 Q_EMIT sigModuleChosen(nullptr);
129 actionGroup->setExclusive(
true);
133 noneAction->setCheckable(
true);
134 noneAction->setText(tr(
"NONE"));
136 noneAction->setDisabled(
139 noneAction->setActionGroup(actionGroup);
141 [
this]{ Q_EMIT
triggered(QModelIndex()); });
142 addAction(noneAction);
149 QModelIndex
const & itemIndex)
153 auto const & sortedModel = *
static_cast<SortModel *
>(
m_sortedModel);
155 auto const sourceItemIndex = sortedModel.mapToSource(itemIndex);
156 auto *
const module =
157 sortedModel.m_sourceModel->module(sourceItemIndex);
159 action->setCheckable(
true);
165 || module->isLocked());
169 || module->isLocked());
177 action->setDisabled(
true);
184 int newButtonIndexIndex,
185 int newLeftLikeModules)
197 m_selectedModule = newSelectedModule;
BtConfig & btConfig()
This is a shortchand for BtConfig::getInstance().
QList< CSwordModuleInfo * > BtModuleList
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
static CSwordBackend & instance() noexcept