Пример #1
0
void test_CSwordVerseKey::CSwordVerseKey_versekey_module_constructor() {

    CSwordVerseKey* key = nullptr;
    try {
        key = new CSwordVerseKey(m_moduleKJVA);
        key->setKey("Matthew 15:39");
    }
    catch (...) {
        QFAIL("constructor failed");
    }

    CSwordVerseKey* key2 = nullptr;
    try {
        key2 = new CSwordVerseKey(key,m_moduleKJV);
        key2->setKey("Matthew 15:39");
    }
    catch (...) {
        QFAIL("constructor failed");
    }
    QCOMPARE(QString(key2->getBookName()), QString(key->getBookName()));
    QCOMPARE(QString(key2->getChapter()), QString(key->getChapter()));
    QCOMPARE(QString(key2->getVerse()), QString(key->getVerse()));


}
Пример #2
0
// Also tests key()
void test_CSwordVerseKey::setKey() {
    QFETCH(QString, moduleName);
    QFETCH(QString, reference);

    CSwordBackend* backend = CSwordBackend::instance();
    CSwordModuleInfo* module = backend->findModuleByName(moduleName);
    QVERIFY(module != 0);
    CSwordVerseKey* vKey = dynamic_cast<CSwordVerseKey*>(CSwordKey::createInstance(module));

    vKey->setKey(reference);
    QString newKey = vKey->key();
    QCOMPARE(newKey, reference);
}
bool CExportManager::saveKey(CSwordKey* key, const Format format, const bool addText) {
    if (!key) {
        return false;
    }
    if (!key->module()) {
        return false;
    }
    const QString filename = getSaveFileName(format);
    if (filename.isEmpty()) {
        return false;
    }

    CSwordBackend::FilterOptions filterOptions = m_filterOptions;
    filterOptions.footnotes = false;
    filterOptions.strongNumbers = false;
    filterOptions.morphTags = false;
    filterOptions.lemmas = false;
    filterOptions.scriptureReferences = false;
    filterOptions.textualVariants = false;

    CHTMLExportRendering::Settings settings(addText);
    boost::scoped_ptr<CTextRendering> render (
        (format == HTML)
        ? new CHTMLExportRendering(settings, m_displayOptions, filterOptions)
        : new CPlainTextExportRendering(settings, m_displayOptions, filterOptions)
    );

    QString text;
    QString startKey;
    QString stopKey;

    QList<CSwordModuleInfo*> modules;
    modules.append(key->module());

    CSwordVerseKey *vk = dynamic_cast<CSwordVerseKey*>(key);
    if (vk && vk->isBoundSet()) {
        text = render->renderKeyRange( QString::fromUtf8(vk->LowerBound()), QString::fromUtf8(vk->UpperBound()), modules );
    }
    else { //no range supported
        text = render->renderSingleKey(key->key(), modules);
    }

    if (!progressWasCancelled()) {
        CToolClass::savePlainFile(filename, text, false, (format == HTML) ? QTextCodec::codecForName("UTF-8") : QTextCodec::codecForLocale() );
        closeProgressDialog();
        return true;
    }
    return false;
}
Пример #4
0
void test_CSwordVerseKey::CSwordVerseKey_copy_constructor() {

    CSwordVerseKey* key = nullptr;
    try {
        key = new CSwordVerseKey(m_moduleKJVA);
        key->setKey("II Maccabees 15:39");
    }
    catch (...) {
        QFAIL("constructor failed");
    }

    const CSwordVerseKey* copyKey = new CSwordVerseKey(*key);
    QCOMPARE(QString(copyKey->getBookName()), QString(key->getBookName()));
    QCOMPARE(QString(copyKey->getChapter()), QString(key->getChapter()));
    QCOMPARE(QString(copyKey->getVerse()), QString(key->getVerse()));
}
Пример #5
0
void test_CSwordVerseKey::setModule() {
    CSwordVerseKey* vKey = dynamic_cast<CSwordVerseKey*>(CSwordKey::createInstance(m_moduleKJV));
    QVERIFY(vKey != 0);

    QSignalSpy beforeSpy(vKey->beforeChangedSignaller(), SIGNAL(signal()));
    QSignalSpy afterSpy(vKey->afterChangedSignaller(), SIGNAL(signal()));

    vKey->setModule(m_moduleKJVA);

    QCOMPARE(beforeSpy.count(), 1);
    QCOMPARE(afterSpy.count(), 1);

    const CSwordModuleInfo* module = vKey->module();
    QVERIFY(module != 0);
    QCOMPARE(module->name(), QString("KJVA"));
}
Пример #6
0
QString BtModuleTextModel::indexToKeyName(int index) const {
    QString keyName = "???";
    if (isBible() || isCommentary()) {
        CSwordVerseKey key = indexToVerseKey(index);
        keyName = key.key();
    }
    else if (isBook()) {
        CSwordTreeKey key = indexToBookKey(index);
        keyName = key.key();
    }
    else if (isLexicon()) {
        const CSwordLexiconModuleInfo *lexiconModule = qobject_cast<const CSwordLexiconModuleInfo*>(m_moduleInfoList.at(0));
        keyName = lexiconModule->entries()[index];
    }
    return keyName;
}
bool CExportManager::copyKey(CSwordKey* key, const Format format, const bool addText) {
    if (!key) {
        return false;
    }
    if (!key->module()) {
        return false;
    }

    CSwordBackend::FilterOptions filterOptions = m_filterOptions;
    filterOptions.footnotes = false;
    filterOptions.strongNumbers = false;
    filterOptions.morphTags = false;
    filterOptions.lemmas = false;
    filterOptions.scriptureReferences = false;
    filterOptions.textualVariants = false;

    CHTMLExportRendering::Settings settings(addText);
    boost::scoped_ptr<CTextRendering> render (
        (format == HTML)
        ? new CHTMLExportRendering(settings, m_displayOptions, filterOptions)
        : new CPlainTextExportRendering(settings, m_displayOptions, filterOptions)
    );

    QString text;
    QString startKey;
    QString stopKey;

    QList<CSwordModuleInfo*> modules;
    modules.append(key->module());

    CSwordVerseKey *vk = dynamic_cast<CSwordVerseKey*>(key);
    if (vk && vk->isBoundSet()) {
        text = render->renderKeyRange(
                   QString::fromUtf8(vk->LowerBound()),
                   QString::fromUtf8(vk->UpperBound()),
                   modules
               );
    }
    else { //no range supported
        text = render->renderSingleKey(key->key(), modules);
    }

    QApplication::clipboard()->setText(text);
    return true;
}
Пример #8
0
QVariant BtModuleTextModel::verseData(const QModelIndex & index, int role) const {
    int row = index.row();
    CSwordVerseKey key = indexToVerseKey(row);
    int verse = key.getVerse();
    if (role == ModuleEntry::TextRole) {
        if (verse == 0)
            return QString();
        QString text;

        QString chapterTitle;
        if (verse == 1)
            chapterTitle = key.book() + " " + QString::number(key.getChapter());

        text += Rendering::CEntryDisplay().textKeyRendering(m_moduleInfoList,
            key.key(), m_displayOptions, m_filterOptions,
            Rendering::CTextRendering::KeyTreeItem::Settings::SimpleKey);
        text.replace("#CHAPTERTITLE#", chapterTitle);
        text = replaceColors(text);
        return CSwordModuleSearch::highlightSearchedText(text, m_highlightWords);
    }
    return QString();
}
Пример #9
0
QVariant BtMiniModuleTextModel::data(const QModelIndex &index, int role) const
{
    Q_D(const BtMiniModuleTextModel);

    switch(role)
	{
    case BtMini::PreviewUpdateRole:
	case BtMini::PreviewRole:
		{
            const BtMiniModuleTextModelPrivate::List *list = d->indexList(index);

            // put to thread processing
            if(role == BtMini::PreviewUpdateRole)
            {
                ;
            }


            if(list->_module->type() == CSwordModuleInfo::GenericBook)
            {
                CSwordBookModuleInfo *b = qobject_cast<CSwordBookModuleInfo*>(list->_module);
                CSwordTreeKey k(b->tree(), b);

                k.setIndex(index.row() * 4);

                return QString("<word-breaks/><font color='#aaaaaa'><center>%1</center></font><font size='1'><br>"
                               "&nbsp;</br></font>").arg(k.key().replace('/', ' '));
            }
            else
            {

                // there was issue with VerseKey::freshtext at simoultaneous call
                static CSwordVerseKey vk(list->_module);
                vk.setModule(list->_module);
                vk.setIndex(index.row() + list->_firstEntry);
                int v = vk.getVerse();

                if(v == 0)
                    return QString();

                QString r("<font color='#aaaaaa'>");

                if(v == 1)
                    r += QString("<center><b><font size='+1'>%1 %2</font></b></center>"
                    "<font size='1'><br>&nbsp;</br></font>").arg(vk.book()).arg(vk.getChapter());

                if(v > 0)
                    r += QString("<center>%1</center></font><font size='1'><br>&nbsp;</br>").arg(v);

                return r + "</font>";
            }
		}

	case Qt::DisplayRole:
        {
			switch(d->indexDepth(index))
			{
			case 1:
                {
                    const BtMiniModuleTextModelPrivate::List & l = d->_lists[index.internalId()];
                    return l._module == 0 ? "" : l._module->name();
                }
			case 2:
				{
					QString r;
                    const BtMiniModuleTextModelPrivate::List *l = d->indexList(index);

					if(l->_module && (l->_module->type() == CSwordModuleInfo::Bible ||
						l->_module->type() == CSwordModuleInfo::Commentary))
					{
						CSwordVerseKey key(d->indexToVerseKey(index));
						const int v = key.getVerse();

                        QList<const CSwordModuleInfo*> modules;
                        modules << l->_module;

                        // parallel display
                        if(l->_name.contains(','))
                            foreach(QString s, l->_name.split(',').mid(1))
                                if(CSwordModuleInfo *m = CSwordBackend::instance()->findModuleByName(s)) modules << m;

                        if(!d->_isSearch && v == 1)
                            r += "<center><b><font size='+2' face=\"" + btConfig().getDefaultFont().family() + "\">"
                                    + key.book() + " " + QString::number(key.getChapter()) + "</font></b></center>";

                        if(v != 0)
                            r += Rendering::CEntryDisplay().textKeyRendering(modules, key.key(),
                                l->_displayOptions, l->_filterOptions,
                                l->_simpleVerseNumber ? Rendering::CTextRendering::KeyTreeItem::Settings::SimpleKey :
                                                        Rendering::CTextRendering::KeyTreeItem::Settings::CompleteShort,
                                l->_introdutions);

                        if(!d->_isSearch && v == key.getVerseMax())
                            r += "<font size='1'><br>&nbsp;</font>";
					}
					else if(l->_module && l->_module->type() == CSwordModuleInfo::Lexicon)
					{
						CSwordLexiconModuleInfo *lm = qobject_cast<CSwordLexiconModuleInfo*>(l->_module);

						Rendering::CEntryDisplay ed;
                        r += ed.textKeyRendering(QList<const CSwordModuleInfo*>() << lm, lm->entries()[l->_hasScope ?
                            l->_scopeMap[index.row()] : index.row()],
                            l->_displayOptions, l->_filterOptions,
                            l->_simpleVerseNumber ? Rendering::CTextRendering::KeyTreeItem::Settings::SimpleKey :
                                                    Rendering::CTextRendering::KeyTreeItem::Settings::CompleteShort,
                            l->_introdutions);
					}
                    else if(l->_module && l->_module->type() == CSwordModuleInfo::GenericBook)
                    {
                        CSwordBookModuleInfo *b = reinterpret_cast<CSwordBookModuleInfo*>(l->_module);
                        CSwordTreeKey key(b->tree(), b);
                        key.setIndex(l->_hasScope ? l->_scopeMap[index.row()] : index.row() * 4);

						Rendering::CEntryDisplay ed;
                        r += ed.textKeyRendering(QList<const CSwordModuleInfo*>() << l->_module,
                            key.key(), l->_displayOptions, l->_filterOptions,
                            l->_simpleVerseNumber ? Rendering::CTextRendering::KeyTreeItem::Settings::SimpleKey :
                                                    Rendering::CTextRendering::KeyTreeItem::Settings::CompleteShort,
                            l->_introdutions);
                    }

                    if(d->_isSearch && !d->_searchText.isEmpty())
                        r = CSwordModuleSearch::highlightSearchedText(r, d->_searchText);

					if(l->_hasContents)
						r += l->_contents.toString();

					return r;
				}
			}
        }
Пример #10
0
int BtModuleTextModel::verseKeyToIndex(const CSwordVerseKey& key) const {
    int index = key.getIndex() - m_firstEntry;
    return index;
}