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