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