BibleTime
cswordkey.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 <QString>
16 
17 
18 class CSwordModuleInfo;
19 namespace sword { class SWKey; }
20 
21 /** Base class for all Sword based keys. */
22 class CSwordKey {
23 
24 public: // types:
25 
28  ProcessEntryAttributesOnly // in this case, renderText() will not return text, but only cause EntryAttribute processing
29  };
30 
31 public: // methods:
32 
33  virtual ~CSwordKey() noexcept;
34 
35  CSwordKey & operator=(CSwordKey const &) = delete;
36 
37  /** \returns a reference to this object as a sword::SWKey. */
38  virtual sword::SWKey const & asSwordKey() const noexcept = 0;
39 
40  /**
41  \returns The key which belongs to the current object.
42  */
43  virtual QString key() const = 0;
44 
45  /// \returns the normalized (English) key.
46  virtual QString normalizedKey() const;
47 
48  /**
49  Sets the current key using a utf8 enabled QString.
50  \param[in] key The key which should be used to set the current one.
51  */
52  virtual bool setKey(const QString & key) = 0;
53 
54  /**
55  Set the key using a utf8-decoded c-string.
56  \param[in] key The key which should be used to set the current one.
57  */
58  virtual bool setKey(const char * key) = 0;
59 
60  /**
61  \returns a clone of this object.
62  */
63  virtual CSwordKey * copy() const = 0;
64 
65  /**
66  \returns the module which belongs to this key.
67  */
68  CSwordModuleInfo const * module() const { return m_module; }
69 
70  /**
71  Sets the module which belongs to this key.
72  \param[in] newModule the module to set.
73  */
74  virtual void setModule(const CSwordModuleInfo * newModule)
75  { m_module = newModule; }
76 
77  /**
78  \returns the raw, unchanged text from the module (i.e. without any filter
79  modifications).
80  */
81  QString rawText();
82 
83  /**
84  \returns the rendered text by passing the text under the current key
85  through the filters.
86  */
88 
89  /**
90  \returns the text after removing all markup tags from it.
91  */
92  QString strippedText();
93 
94  /** Check whether key is valid. Can be invalidated during av11n mapping. */
95  bool isValid() const { return m_valid; }
96 
97 protected: // methods:
98 
99  CSwordKey(CSwordModuleInfo const * const module = nullptr)
100  : m_module(module)
101  {}
102 
103  CSwordKey(CSwordKey const & copy) = default;
104 
105  /**
106  \returns the encoded key appropriate for use directly with Sword.
107  */
108  virtual const char * rawKey() const = 0;
109 
110 protected: // fields:
111 
113  bool m_valid = true;
114 
115 };
QString strippedText()
Definition: cswordkey.cpp:118
virtual ~CSwordKey() noexcept
CSwordKey(CSwordKey const &copy)=default
virtual CSwordKey * copy() const =0
virtual const char * rawKey() const =0
const CSwordModuleInfo * m_module
Definition: cswordkey.h:112
QString renderedText(const CSwordKey::TextRenderType mode=CSwordKey::Normal)
Definition: cswordkey.cpp:58
bool isValid() const
Definition: cswordkey.h:95
CSwordKey(CSwordModuleInfo const *const module=nullptr)
Definition: cswordkey.h:99
virtual void setModule(const CSwordModuleInfo *newModule)
Definition: cswordkey.h:74
TextRenderType
Definition: cswordkey.h:26
@ ProcessEntryAttributesOnly
Definition: cswordkey.h:28
virtual QString normalizedKey() const
Definition: cswordkey.cpp:43
CSwordModuleInfo const * module() const
Definition: cswordkey.h:68
QString rawText()
Definition: cswordkey.cpp:45
bool m_valid
Definition: cswordkey.h:113
virtual sword::SWKey const & asSwordKey() const noexcept=0
virtual bool setKey(const QString &key)=0
virtual QString key() const =0