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, http://www.bibletime.info/. 6 * 7 * Copyright 1999-2016 by the BibleTime developers. 8 * The BibleTime source code is licensed under the GNU General Public License version 2.0. 9 * 10 **********/ 11 12 #ifndef CSWORDKEY_H 13 #define CSWORDKEY_H 14 15 #include <QPointer> 16 #include <QString> 17 #include "../btsignal.h" 18 19 20 class CSwordModuleInfo; 21 class QTextCodec; 22 23 /** Base class for all Sword based keys. */ 24 class CSwordKey { 25 26 public: /* Types: */ 27 28 enum TextRenderType { 29 Normal = 0, 30 HTMLEscaped = 1, 31 ProcessEntryAttributesOnly = 2 // in this case, renderText() will not return text, but only cause EntryAttribute processing 32 }; 33 34 public: /* Methods: */ 35 36 CSwordKey & operator=(CSwordKey const &) = delete; 37 ~CSwordKey()38 virtual inline ~CSwordKey() { delete m_beforeChangedSignaller; } 39 40 /** 41 \returns The key which belongs to the current object. 42 */ 43 virtual QString key() const = 0; 44 45 /** 46 Sets the current key using a utf8 enabled QString. 47 \param[in] key The key which should be used to set the current one. 48 */ 49 virtual bool setKey(const QString & key) = 0; 50 51 /** 52 Set the key using a utf8-decoded c-string. 53 \param[in] key The key which should be used to set the current one. 54 */ 55 virtual bool setKey(const char * key) = 0; 56 57 /** 58 \returns a clone of this object. 59 */ 60 virtual CSwordKey * copy() const = 0; 61 62 /** 63 \returns the module which belongs to this key. 64 */ module()65 inline const CSwordModuleInfo * module() const { 66 return m_module; 67 } 68 69 /** 70 Sets the module which belongs to this key. 71 \param[in] newModule the module to set. 72 */ setModule(const CSwordModuleInfo * newModule)73 virtual inline void setModule(const CSwordModuleInfo * newModule) { 74 m_module = newModule; 75 } 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 */ 87 QString renderedText(const CSwordKey::TextRenderType mode = CSwordKey::Normal); 88 89 /** 90 \returns the text after removing all markup tags from it. 91 */ 92 QString strippedText(); 93 94 const BtSignal * beforeChangedSignaller(); 95 const BtSignal * afterChangedSignaller(); 96 97 /** 98 \returns a new CSwordkey subclass instance for the given module, depending 99 on the type of the module. 100 */ 101 static CSwordKey * createInstance(const CSwordModuleInfo * module); 102 103 /** Check whether key is valid. Can be invalidated during av11n mapping. */ isValid()104 inline bool isValid() const { return m_valid; } 105 106 /** 107 This is called before a key change to emit a signal 108 */ 109 void emitBeforeChanged(); 110 111 /** 112 This is called after a key change to emit a signal 113 */ 114 void emitAfterChanged(); 115 116 protected: /* Methods: */ 117 118 inline CSwordKey(const CSwordModuleInfo * const module = nullptr) m_module(module)119 : m_module(module) 120 , m_valid(true) {} 121 CSwordKey(const CSwordKey & copy)122 inline CSwordKey(const CSwordKey & copy) 123 : m_module(copy.m_module) 124 , m_valid(copy.m_valid) {} 125 126 /** 127 \returns the encoded key appropriate for use directly with Sword. 128 */ 129 virtual const char * rawKey() const = 0; 130 cp1252Codec()131 static inline const QTextCodec * cp1252Codec() { return m_cp1252Codec; } 132 133 protected: /* Fields: */ 134 135 static const QTextCodec * m_cp1252Codec; 136 const CSwordModuleInfo * m_module; 137 QPointer<BtSignal> m_beforeChangedSignaller; 138 QPointer<BtSignal> m_afterChangedSignaller; 139 140 bool m_valid; 141 }; 142 143 #endif 144