BibleTime
btmoduletextmodel.h
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-2025 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#pragma once
14
15#include <optional>
16#include <QAbstractListModel>
17#include <QColor>
18#include <QStringList>
19#include "../btglobal.h"
20#include "../drivers/btmodulelist.h"
21#include "../keys/cswordversekey.h"
22#include "../keys/cswordtreekey.h"
23#include "../rendering/cdisplayrendering.h"
24
25
27
28/** For the BtFindWidget buttons (previous, next) */
29struct FindState {
30 // Model row for item with highlight
31 int index;
32
33 // 1st, 2nd, etc. word highlighted within the item
35};
36
38 enum TextRoles {
39 ReferenceRole = Qt::UserRole + 1,
40 TextRole = Qt::UserRole + 2,
41
42 Text0Role = Qt::UserRole + 10,
43 Text1Role = Qt::UserRole + 11,
44 Text2Role = Qt::UserRole + 12,
45 Text3Role = Qt::UserRole + 13,
46 Text4Role = Qt::UserRole + 14,
47 Text5Role = Qt::UserRole + 15,
48 Text6Role = Qt::UserRole + 16,
49 Text7Role = Qt::UserRole + 17,
50 Text8Role = Qt::UserRole + 18,
51 Text9Role = Qt::UserRole + 19,
52
53 Title0Role = Qt::UserRole + 20,
54 Title1Role = Qt::UserRole + 21,
55 Title2Role = Qt::UserRole + 22,
56 Title3Role = Qt::UserRole + 23,
57 Title4Role = Qt::UserRole + 24,
58 Title5Role = Qt::UserRole + 25,
59 Title6Role = Qt::UserRole + 26,
60 Title7Role = Qt::UserRole + 27,
61 Title8Role = Qt::UserRole + 28,
62 Title9Role = Qt::UserRole + 29,
63
64 Edit0Role = Qt::UserRole + 30,
65 Edit1Role = Qt::UserRole + 31,
66 Edit2Role = Qt::UserRole + 32,
67 Edit3Role = Qt::UserRole + 33,
68 Edit4Role = Qt::UserRole + 34,
69 Edit5Role = Qt::UserRole + 35,
70 Edit6Role = Qt::UserRole + 36,
71 Edit7Role = Qt::UserRole + 37,
72 Edit8Role = Qt::UserRole + 38,
73 Edit9Role = Qt::UserRole + 39,
74 };
75};
76
77
78/**
79 * @page modelviewmodel Details about the module text model
80 * <p>
81 * The BtModuleTextModel represents the text of a sword module. It uses
82 * an integer index to address each entry (verse, paragraph, etc).
83 * The html text is obtained using backend rendering functions.
84 * It is then post processed to fix a few things so that the QML
85 * ListView works correctly. The ListView supports a "rich text"
86 * that is a subset of html. The post processing is done in
87 * the class BtTextFilter which is installed into BtModuleTextModel
88 * by the frontend.
89 * </p>
90 */
91
92
93/**
94 \brief Model that represents the entire text of a given module
95
96 It is used by a QML ListView to view a small portion of the
97 available module text. Only the portions of the module that are
98 currently displayed and some just above or below this, are
99 instantiated.
100
101 \note Four parallel modules are supported.
102 */
103
104
106
107 Q_OBJECT
108
109public:
110
111 BtModuleTextModel(QObject *parent = nullptr);
112
113 /** Convert index(row) into CSwordVerseKey. */
115
116 /** Convert index(row) into verse. */
117 int indexToVerse(int index) const;
118
119 /** Convert index(row) into CSwordVerseKey. */
121 CSwordModuleInfo const & module) const;
122
123 /** Convert index(row) into CSwordVerseKey. */
124 CSwordKey* indexToKey(int index, int moduleNum) const;
125
126 /** Convert CSwordKey into index. */
127 int keyToIndex(CSwordKey const & key) const;
128
129 /** Convert CSwordVerseKey into index(row). */
130 int verseKeyToIndex(const CSwordVerseKey& key) const;
131
132 /** Get reference name from index(row). */
133 QString indexToKeyName(int index) const;
134
135 /** Get index offset of first entry of module */
136 int firstEntryIndex() const noexcept { return m_firstEntry; }
137
138 /** Reimplemented from QAbstractItemModel. */
139 int columnCount(const QModelIndex & parent = QModelIndex()) const override;
140
141 /** Reimplemented from QAbstractItemModel. */
142 QVariant data(const QModelIndex & index,
143 int role = Qt::DisplayRole) const override;
144
145 /** Reimplemented from QAbstractItemModel. */
146 int rowCount(const QModelIndex & parent = QModelIndex()) const override;
147
148 /** Reimplemented from QAbstractItemModel. */
149 virtual bool setData(const QModelIndex &index,
150 const QVariant &value, int role = Qt::EditRole) override;
151
152 /** Set the state of the currently found word functionality */
153 void setFindState(std::optional<FindState> findState);
154
155 /** Set the color of word that are highlighted */
156 void setHighlightWords(const QString& highlightWords, bool caseSensitive);
157
158 /** Used by model to get the roleNames and corresponding role numbers. */
160
161 /** Set the display and filter options used for rendering module text. */
162 void setOptions(DisplayOptions const & displayOptions,
163 FilterOptions const & filterOptions);
164
165 /** Specifies one or more module names for use by the model */
166 void setModules(const QStringList& modules);
167
168 /** Load module pointers from module names */
170
171private:
172
174
175 bool isBible() const;
176 bool isBook() const;
177 bool isCommentary() const;
178 bool isLexicon() const;
179 bool isSelected(int index) const;
180
181 /** returns text string for each model index */
182 QString bookData(const QModelIndex & index, int role = Qt::DisplayRole) const;
183 QString verseData(const QModelIndex & index, int role = Qt::DisplayRole) const;
184 QString lexiconData(const QModelIndex & index, int role = Qt::DisplayRole) const;
185
187 QStringList m_modules;
189
193 std::optional<FindState> m_findState;
194};
QList< CSwordModuleInfo const * > BtConstModuleList
Model that represents the entire text of a given module.
QString bookData(const QModelIndex &index, int role=Qt::DisplayRole) const
CSwordKey * indexToKey(int index, int moduleNum) const
int rowCount(const QModelIndex &parent=QModelIndex()) const override
int firstEntryIndex() const noexcept
bool isBible() const
std::optional< FindState > m_findState
int verseKeyToIndex(const CSwordVerseKey &key) const
int columnCount(const QModelIndex &parent=QModelIndex()) const override
CSwordTreeKey indexToBookKey(int index) const
BtConstModuleList m_moduleInfoList
BtModuleTextModel(QObject *parent=nullptr)
bool isLexicon() const
QString lexiconData(const QModelIndex &index, int role=Qt::DisplayRole) const
bool isCommentary() const
void setModules(const QStringList &modules)
void setHighlightWords(const QString &highlightWords, bool caseSensitive)
int keyToIndex(CSwordKey const &key) const
bool isSelected(int index) const
int indexToVerse(int index) const
CSwordVerseKey indexToVerseKey(int index, CSwordModuleInfo const &module) const
bool isBook() const
CSwordVerseKey indexToVerseKey(int index) const
QString verseData(const QModelIndex &index, int role=Qt::DisplayRole) const
void setOptions(DisplayOptions const &displayOptions, FilterOptions const &filterOptions)
QString indexToKeyName(int index) const
QHash< int, QByteArray > roleNames() const override
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Rendering::CDisplayRendering m_displayRendering
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void setFindState(std::optional< FindState > findState)
CSwordKey implementation for Sword's TreeKey.
CSwordKey implementation for Sword's VerseKey.
Rendering for the html display widget.