diff options
Diffstat (limited to 'src/backend/keys/cswordkey.cpp')
-rw-r--r-- | src/backend/keys/cswordkey.cpp | 74 |
1 files changed, 44 insertions, 30 deletions
diff --git a/src/backend/keys/cswordkey.cpp b/src/backend/keys/cswordkey.cpp index 24f4909..9c5b25b 100644 --- a/src/backend/keys/cswordkey.cpp +++ b/src/backend/keys/cswordkey.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -16,6 +16,7 @@ #include "backend/keys/cswordldkey.h" #include "backend/keys/cswordtreekey.h" #include "backend/keys/cswordversekey.h" +#include "util/btsignal.h" // Sword includes: #include <swkey.h> @@ -26,12 +27,21 @@ #include <versekey.h> -CSwordKey::CSwordKey(CSwordModuleInfo* const module) : m_module(module) {} +const QTextCodec *CSwordKey::m_cp1252Codec = QTextCodec::codecForName("Windows-1252"); -CSwordKey::CSwordKey(const CSwordKey& k) { +CSwordKey::CSwordKey(const CSwordModuleInfo * const module) + : m_module(module), + m_signal(0) {} + +CSwordKey::CSwordKey(const CSwordKey& k) + : m_signal(0) { m_module = k.m_module; } +CSwordKey::~CSwordKey() { + delete m_signal; +} + QString CSwordKey::rawText() { if (!m_module) return QString::null; @@ -51,7 +61,6 @@ QString CSwordKey::renderedText( const CSwordKey::TextRenderType mode ) { if (k) { sword::VerseKey* vk_mod = dynamic_cast<sword::VerseKey*>(m_module->module()->getKey()); - if (vk_mod) { vk_mod->Headings(1); } @@ -74,25 +83,26 @@ QString CSwordKey::renderedText( const CSwordKey::TextRenderType mode ) { //Q_ASSERT(!key().isNull()); if (!key().isNull()) { //we have valid text - bool DoRender = (mode == ProcessEntryAttributesOnly) ? 0 : 1; - QString text = QString::fromUtf8( m_module->module()->RenderText(0, -1, DoRender) ); - if (!DoRender) return QString::null; + bool DoRender = mode != ProcessEntryAttributesOnly; + QString text = QString::fromUtf8( m_module->module()->RenderText(0,-1, DoRender)); + if (!DoRender) + return QString::null; // This is yucky, but if we want strong lexicon refs we have to do it here. if (m_module->type() == CSwordModuleInfo::Lexicon) { QString t(text); - QRegExp rx("(GREEK|HEBREW) for 0*([1-9]\\d*)"); // ignore 0's before number + QRegExp rx("(GREEK|HEBREW) for 0*([1-9]\\d*)"); // ignore 0's before number int pos = 0; while ( (pos = rx.indexIn(t, pos)) != -1 ) { QString language = rx.cap(1); - QString langcode = QString(language.at(0)); // "G" or "H" + QString langcode = QString(language.at(0)); // "G" or "H" QString number = rx.cap(2); - QString paddednumber = number.rightJustified(5, '0'); // Form 00123 + QString paddednumber = number.rightJustified(5, '0'); // Form 00123 text.replace( QRegExp( QString( - "(>[^<>]+)" // Avoid replacing inside tags - "\\b(0*%1)\\b").arg(number) ), // And span around 0's + "(>[^<>]+)" // Avoid replacing inside tags + "\\b(0*%1)\\b").arg(number) ), // And span around 0's QString("\\1<span lemma=\"%1%2\"><a href=\"strongs://%3/%4\">\\2</a></span>") .arg(langcode, paddednumber, language, paddednumber) ); @@ -101,23 +111,22 @@ QString CSwordKey::renderedText( const CSwordKey::TextRenderType mode ) { } if (mode == HTMLEscaped) { - //we have to encode all UTF-8 in HTML escapes - // go though every character and write down the escaped HTML unicode entity - // form is &#<decimal unicode value here>; + /* + Here we encode all non-latin1 characters as HTML unicode entities + in the form &#<decimal unicode value here>; + */ QString ret; - QChar c; - const unsigned int length = text.length(); - for (unsigned int i = 0; i < length; ++i) { - c = text.at(i); + // Reserve characters to reduce number of memory allocations: + ret.reserve(text.size()); + + for (int i = 0; i < text.size(); ++i) { + const QChar c = text.at(i); - if (c.toLatin1()) { //normal latin1 character + if (c.toLatin1()) { ret.append(c); - } - else {//unicode character, needs to be escaped - ret.append("&#") - .append(c.unicode()) - .append(";"); + } else { + ret.append("&#").append(c.unicode()).append(";"); } } @@ -144,14 +153,13 @@ QString CSwordKey::strippedText() { return QString::fromUtf8( m_module->module()->StripText() ); } -const QTextCodec* CSwordKey::cp1252Codec() { - static QTextCodec * codec = QTextCodec::codecForName("Windows-1252"); - return codec; +void CSwordKey::emitChanged() { + if (m_signal.isNull()) return; + m_signal->emitChanged(); } - /** This will create a proper key object from a given module */ -CSwordKey* CSwordKey::createInstance( CSwordModuleInfo* const module ) { +CSwordKey *CSwordKey::createInstance(const CSwordModuleInfo *module) { if (!module) { return 0; } @@ -173,3 +181,9 @@ CSwordKey* CSwordKey::createInstance( CSwordModuleInfo* const module ) { return 0; } } + +const BtSignal* CSwordKey::signaler() { + if (m_signal.isNull()) + m_signal = new BtSignal(); + return m_signal; +} |