BibleTime
cswordldkey.cpp
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#include "cswordldkey.h"
14
15#include <QByteArray>
16#include "../../util/btassert.h"
17#include "../../util/cp1252.h"
18#include "../drivers/cswordmoduleinfo.h"
19
20// Sword includes:
21#pragma GCC diagnostic push
22#pragma GCC diagnostic ignored "-Wextra-semi"
23#pragma GCC diagnostic ignored "-Wsuggest-override"
24#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
25#ifdef __clang__
26#pragma clang diagnostic push
27#pragma clang diagnostic ignored "-Wsuggest-destructor-override"
28#endif
29#include <swkey.h>
30#include <swmodule.h>
31#ifdef __clang__
32#pragma clang diagnostic pop
33#endif
34#pragma GCC diagnostic pop
35
36
38 : CSwordKey(module)
39{ m_key = " "; }
40
41/** No descriptions */
43 : CSwordKey(k)
44 , m_key(k.m_key.getText())
45{}
46
47/** No descriptions */
48CSwordLDKey::CSwordLDKey(const sword::SWKey *k, const CSwordModuleInfo *module)
49 : CSwordKey(module)
50 , m_key(*k)
51{}
52
53sword::SWKey const & CSwordLDKey::asSwordKey() const noexcept { return m_key; }
54
55/** Clones this object by copying the members. */
57 return new CSwordLDKey(*this);
58}
59
60/** Sets the module of this key. */
62 BT_ASSERT(newModule);
63 if (m_module == newModule) return;
65
66 const QString oldKey = key();
67 m_module = newModule;
68 setKey(oldKey);
69}
70
71QString CSwordLDKey::key() const {
72 //return QString::fromUtf8((const char*)*this);
74
75 if (m_module->isUnicode()) {
76 return QString::fromUtf8(m_key.getText());
77 } else {
78 return util::cp1252::toUnicode(m_key.getText());
79 }
80}
81
82const char * CSwordLDKey::rawKey() const {
83 return m_key.getText();
84}
85
86bool CSwordLDKey::setKey(const QString &newKey) {
88
89 if (m_module->isUnicode()) {
90 return setKey(newKey.toUtf8().constData());
91 }
92 else {
93 return setKey(util::cp1252::fromUnicode(newKey).constData());
94 }
95}
96
97
98/** Sets the key of this instance */
99bool CSwordLDKey::setKey(const char *newKey) {
100 BT_ASSERT(newKey);
101
102 if (newKey) {
103 m_key = newKey; //set the key
104 m_module->swordModule().setKey(&m_key);
105 m_module->snap();
106 }
107
108 return !m_key.popError();
109}
110
111/** Uses the parameter to returns the next entry afer this key. */
113 auto & m = m_module->swordModule();
114 m.setKey(&m_key); // use this key as base for the next one!
115 // m.getKey()->setText( (const char*)key().utf8() );
116
117 m.setSkipConsecutiveLinks(true);
118 m++;
119 m.setSkipConsecutiveLinks(false);
120
121 setKey(m.getKeyText());
122 m_key.setText(m.getKeyText());
123
124 return this;
125}
126
127/** Uses the parameter to returns the next entry afer this key. */
129 auto & m = m_module->swordModule();
130 m.setKey(&m_key); // use this key as base for the next one!
131 // m.getKey()->setText( (const char*)key().utf8() );
132
133 m.setSkipConsecutiveLinks(true);
134 m--;
135 m.setSkipConsecutiveLinks(false);
136
137 m_key.setText(m.getKeyText());
138
139 return this;
140}
141
#define BT_ASSERT(...)
Definition btassert.h:17
const CSwordModuleInfo * m_module
Definition cswordkey.h:112
CSwordLDKey * NextEntry()
CSwordLDKey * PreviousEntry()
CSwordLDKey * copy() const final override
CSwordLDKey(const CSwordModuleInfo *module)
sword::SWKey m_key
void setModule(const CSwordModuleInfo *module) final override
bool setKey(const QString &newKey) final override
sword::SWKey const & asSwordKey() const noexcept final override
QString key() const final override
const char * rawKey() const final override
bool isUnicode() const noexcept
virtual bool snap() const
ModuleType type() const
sword::SWModule & swordModule() const
QString toUnicode(QByteArray const &data)
Definition cp1252.cpp:23
QByteArray fromUnicode(QString const &str)
Definition cp1252.cpp:31