BibleTime
cswordversekey.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-2026 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 "cswordkey.h"
16
17#include <QPointer>
18#include <QString>
19#include "../btsignal.h"
20
21// Sword includes:
22#ifdef __GNUC__
23#pragma GCC diagnostic push
24#pragma GCC diagnostic ignored "-Wextra-semi"
25#pragma GCC diagnostic ignored "-Wsuggest-override"
26#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
27#endif
28#ifdef __clang__
29#pragma clang diagnostic push
30#pragma clang diagnostic ignored "-Wsuggest-destructor-override"
31#endif
32#include <versekey.h>
33#ifdef __clang__
34#pragma clang diagnostic pop
35#endif
36#ifdef __GNUC__
37#pragma GCC diagnostic pop
38#endif
39
40
42
43/**
44 * The CSwordKey implementation for verse based modules (Bibles and Commentaries)
45 *
46 * This class is the implementation of CKey for verse based modules like
47 * Bibles and commentaries.
48 * This class provides the special functions to work with the verse based modules.
49 *
50 * Useful functions are
51 * @see NextBook()
52 * @see PreviousBook()
53 * @see NextChapter()
54 * @see PreviousChapter()
55 * @see NextVerse()
56 * @see PreviousVerse().
57 *
58 * Call the constructor only with valid verse based modules, otherwise this key
59 * will be invalid and the application will probably crash.
60 *
61 * @version $Id: cswordversekey.h,v 1.26 2006/02/25 11:38:15 joachim Exp $
62 * @short CSwordKey implementation for Sword's VerseKey.
63 * @author The BibleTime team
64 */
65
66class CSwordVerseKey final : public CSwordKey {
67
68 public: // types:
74
75 public: // methods:
76
77 #define BibleTime_CSwordVerseKey_DEFINE_COMP(op) \
78 friend auto operator op(CSwordVerseKey const & lhs, \
79 CSwordVerseKey const & rhs) \
80 { \
81 return std::tuple(lhs.testament(), lhs.book(), lhs.chapter(), \
82 lhs.verse(), lhs.suffix()) op \
83 std::tuple(rhs.testament(), rhs.book(), rhs.chapter(), \
84 rhs.verse(), rhs.suffix()); \
85 }
88 #undef BibleTime_CSwordVerseKey_DEFINE_COMP
89
90 CSwordVerseKey & operator=(CSwordVerseKey const &) = delete;
91
92 /**
93 Constructs a versekey with the current module position and setups
94 the m_module members.
95 */
97
99
100 /**
101 * Constructs a CSwordVerseKey using the given module at the position given
102 * by the versekey.
103 *
104 * \param[in] k Position to use.
105 * \param[in] module Module to use.
106 */
107 CSwordVerseKey(const sword::VerseKey *k,
108 const CSwordModuleInfo *module);
109
110 ~CSwordVerseKey() override;
111
112 sword::SWKey const & asSwordKey() const noexcept final override;
113
114 CSwordVerseKey * copy() const final override;
115
116 QString key() const final override;
117 QString normalizedKey() const final override;
118
119 bool setKey(const QString &key) final override;
120
121 bool setKey(const char *key) final override;
122
123 /**
124 * Jumps to the next entry of the given type
125 */
126 bool next( const JumpType type = JumpType::UseVerse );
127 /**
128 * Jumps to the previous entry of the given type
129 */
130 bool previous ( const JumpType type = JumpType::UseVerse );
131 /**
132 * This functions returns the current book as localised text, not as book numer.
133 *
134 * Use "char Book()" to retrieve the book number of the current book.
135 * @return The name of the current book
136 */
137 QString bookName() const;
138
139 void setBookName(QString const & newBookName)
140 { m_key.setBookName(newBookName.toUtf8().constData()); }
141
142 void setModule(const CSwordModuleInfo *newModule) final override;
143
145 void setLowerBound(CSwordVerseKey const & bound);
146
148 void setUpperBound(CSwordVerseKey const & bound);
149
150 QString shortText() const
151 { return QString::fromUtf8(m_key.getShortText()); }
152
153 void setLocale(char const * const locale) { m_key.setLocale(locale); }
154 bool isBoundSet() const { return m_key.isBoundSet(); }
155 void setIntros(bool v) { m_key.setIntros(v); }
156 char testament() const { return m_key.getTestament(); }
157 void setTestament(char v) { m_key.setTestament(v); }
158
159 /** Return book number within a testament */
160 char book() const { return m_key.getBook(); }
161
162 void setBook(char v) { m_key.setBook(v); }
163 int chapter() const { return m_key.getChapter(); }
164 void setChapter(int v) { m_key.setChapter(v); }
165 int verse() const { return m_key.getVerse(); }
166 void setVerse(int v) { m_key.setVerse(v); }
167 char suffix() const { return m_key.getSuffix(); }
168 void setSuffix(char v) { m_key.setSuffix(v); }
169 long index() const { return m_key.getIndex(); }
170 void setIndex(long v) { m_key.setIndex(v); }
171 void positionToTop() { m_key.setPosition(sword::TOP); }
172
173 /** Return book number within entire bible */
174 char bibleBook() const;
175
176 QString versification() const {
177 return m_key.getVersificationSystem();
178 }
179 void setVersification(const char * name) {
180 m_key.setVersificationSystem(name);
181 }
182
184
185 /** This is called after a key change to emit a signal. */
186 void emitAfterChanged();
187
188 protected:
189
190 const char * rawKey() const final override;
191
192 private: // fields:
193
194 sword::VerseKey m_key;
196
197};
CSwordModuleInfo const * module() const
Definition cswordkey.h:68
CSwordKey & operator=(CSwordKey const &)=delete
CSwordKey implementation for Sword's VerseKey.
CSwordVerseKey upperBound() const
void setLowerBound(CSwordVerseKey const &bound)
char bibleBook() const
char book() const
void setChapter(int v)
~CSwordVerseKey() override
QString bookName() const
void setIndex(long v)
void setIntros(bool v)
bool next(const JumpType type=JumpType::UseVerse)
char testament() const
void setModule(const CSwordModuleInfo *newModule) final override
void setLocale(char const *const locale)
QString versification() const
void setTestament(char v)
bool previous(const JumpType type=JumpType::UseVerse)
QString key() const final override
sword::VerseKey m_key
QPointer< BtSignal > m_afterChangedSignaller
bool setKey(const QString &key) final override
const BtSignal * afterChangedSignaller()
void setVersification(const char *name)
int verse() const
bool isBoundSet() const
long index() const
CSwordVerseKey * copy() const final override
BibleTime_CSwordVerseKey_DEFINE_COMP(<=>) BibleTime_CSwordVerseKey_DEFINE_COMP(
char suffix() const
void setBook(char v)
void setSuffix(char v)
const char * rawKey() const final override
QString normalizedKey() const final override
void setUpperBound(CSwordVerseKey const &bound)
int chapter() const
QString shortText() const
void setVerse(int v)
sword::SWKey const & asSwordKey() const noexcept final override
CSwordVerseKey lowerBound() const
void setBookName(QString const &newBookName)
#define BibleTime_CSwordVerseKey_DEFINE_COMP(op)