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 }
84 #undef BibleTime_CSwordVerseKey_DEFINE_COMP
85
86 CSwordVerseKey & operator=(CSwordVerseKey const &) = delete;
87
88 /**
89 Constructs a versekey with the current module position and setups
90 the m_module members.
91 */
93
95
96 /**
97 * Constructs a CSwordVerseKey using the given module at the position given
98 * by the versekey.
99 *
100 * \param[in] k Position to use.
101 * \param[in] module Module to use.
102 */
103 CSwordVerseKey(const sword::VerseKey *k,
104 const CSwordModuleInfo *module);
105
106 ~CSwordVerseKey() override;
107
108 sword::SWKey const & asSwordKey() const noexcept final override;
109
110 CSwordVerseKey * copy() const final override;
111
112 QString key() const final override;
113 QString normalizedKey() const final override;
114
115 bool setKey(const QString &key) final override;
116
117 bool setKey(const char *key) final override;
118
119 /**
120 * Jumps to the next entry of the given type
121 */
122 bool next( const JumpType type = JumpType::UseVerse );
123 /**
124 * Jumps to the previous entry of the given type
125 */
126 bool previous ( const JumpType type = JumpType::UseVerse );
127 /**
128 * This functions returns the current book as localised text, not as book numer.
129 *
130 * Use "char Book()" to retrieve the book number of the current book.
131 * @return The name of the current book
132 */
133 QString bookName() const;
134
135 void setBookName(QString const & newBookName)
136 { m_key.setBookName(newBookName.toUtf8().constData()); }
137
138 void setModule(const CSwordModuleInfo *newModule) final override;
139
141 void setLowerBound(CSwordVerseKey const & bound);
142
144 void setUpperBound(CSwordVerseKey const & bound);
145
146 QString shortText() const
147 { return QString::fromUtf8(m_key.getShortText()); }
148
149 void setLocale(char const * const locale) { m_key.setLocale(locale); }
150 bool isBoundSet() const { return m_key.isBoundSet(); }
151 void setIntros(bool v) { m_key.setIntros(v); }
152 char testament() const { return m_key.getTestament(); }
153 void setTestament(char v) { m_key.setTestament(v); }
154
155 /** Return book number within a testament */
156 char book() const { return m_key.getBook(); }
157
158 void setBook(char v) { m_key.setBook(v); }
159 int chapter() const { return m_key.getChapter(); }
160 void setChapter(int v) { m_key.setChapter(v); }
161 int verse() const { return m_key.getVerse(); }
162 void setVerse(int v) { m_key.setVerse(v); }
163 char suffix() const { return m_key.getSuffix(); }
164 void setSuffix(char v) { m_key.setSuffix(v); }
165 long index() const { return m_key.getIndex(); }
166 void setIndex(long v) { m_key.setIndex(v); }
167 void positionToTop() { m_key.setPosition(sword::TOP); }
168
169 /** Return book number within entire bible */
170 char bibleBook() const;
171
172 QString versification() const {
173 return m_key.getVersificationSystem();
174 }
175 void setVersification(const char * name) {
176 m_key.setVersificationSystem(name);
177 }
178
180
181 /** This is called after a key change to emit a signal. */
182 void emitAfterChanged();
183
184 protected:
185
186 const char * rawKey() const final override;
187
188 private: // fields:
189
190 sword::VerseKey m_key;
192
193};
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)