BibleTime
btinstallpagemodel.cpp
Go to the documentation of this file.
1 /*********
2 *
3 * In the name of the Father, and of the Son, and of the Holy Spirit.
4 *
5 * This file is part of BibleTime's source code, https://bibletime.info/
6 *
7 * Copyright 1999-2021 by the BibleTime developers.
8 * The BibleTime source code is licensed under the GNU General Public License
9 * version 2.0.
10 *
11 **********/
12 
13 #include "btinstallpagemodel.h"
14 
15 #include <QtGlobal>
16 #include "../../backend/bookshelfmodel/btbookshelftreemodel.h"
17 #include "../../backend/drivers/cswordmoduleinfo.h"
18 #include "../../backend/managers/cswordbackend.h"
19 
20 
22  QObject * const parent)
23  : BtBookshelfTreeModel(grouping, parent)
24 {
26  setCheckable(true);
27 }
28 
29 QVariant BtInstallPageModel::data(QModelIndex const & i, int role) const {
30  switch (role) {
31  case Qt::DisplayRole:
32  switch (i.column()) {
33  case 0:
34  return BtBookshelfTreeModel::data(i, role);
35  case 1:
36  if (CSwordModuleInfo * const m =
37  module(index(i.row(), 0, i.parent())))
38  {
39  if (CSwordModuleInfo * imodule =
40  CSwordBackend::instance().findModuleByName(
41  m->name()))
42  return QStringLiteral("%1 => %2")
43  .arg(imodule->config(
45  m->config(
47  return m->config(CSwordModuleInfo::ModuleVersion);
48  }
49  break;
50  case 2:
51  if (CSwordModuleInfo * const m =
52  module(index(i.row(), 0, i.parent())))
53  return m->config(CSwordModuleInfo::Description);
54  break;
55  default:
56  break;
57  }
58  break;
59  default:
60  if (i.column() == 0)
61  return BtBookshelfTreeModel::data(i, role);
62  break;
63  }
64 
65  return QVariant();
66 }
67 
68 int BtInstallPageModel::columnCount(QModelIndex const & parent) const {
69  Q_UNUSED(parent)
70  return 3;
71 }
72 
73 QVariant BtInstallPageModel::headerData(int section,
74  Qt::Orientation orientation,
75  int role) const
76 {
77  if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
78  switch (section) {
79  case 0: return tr("Work");
80  case 1: return tr("Version");
81  case 2: return tr("Description");
82  default: break;
83  }
84  }
85  return QVariant();
86 }
QModelIndex parent(const QModelIndex &index) const override
void setDefaultChecked(CheckedBehavior b)
void setCheckable(bool checkable)
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
CSwordModuleInfo * module(QModelIndex const &index) const
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QVariant data(QModelIndex const &index, int role=Qt::DisplayRole) const final override
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const final override
BtInstallPageModel(Grouping const &grouping, QObject *const parent=nullptr)
int columnCount(QModelIndex const &parent=QModelIndex()) const final override
static CSwordBackend & instance() noexcept
Definition: cswordbackend.h:98