diff options
Diffstat (limited to 'src/frontend/searchdialog/analysis')
10 files changed, 133 insertions, 104 deletions
diff --git a/src/frontend/searchdialog/analysis/csearchanalysisdialog.cpp b/src/frontend/searchdialog/analysis/csearchanalysisdialog.cpp index ece0ced..10e4566 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysisdialog.cpp +++ b/src/frontend/searchdialog/analysis/csearchanalysisdialog.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -18,7 +18,7 @@ #include "backend/drivers/cswordmoduleinfo.h" #include "frontend/searchdialog/analysis/csearchanalysisscene.h" #include "frontend/searchdialog/analysis/csearchanalysisview.h" -#include "util/dialogutil.h" +#include "frontend/messagedialog.h" namespace Search { @@ -59,7 +59,7 @@ void CSearchAnalysisDialog::initView() { m_buttonBox->setStandardButtons(QDialogButtonBox::Close); m_buttonBox->addButton(QDialogButtonBox::Save); //tr("Save as HTML"), - util::prepareDialogBox(m_buttonBox); + message::prepareDialogBox(m_buttonBox); vboxLayout->addWidget(m_buttonBox); bool ok = QObject::connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject())); diff --git a/src/frontend/searchdialog/analysis/csearchanalysisdialog.h b/src/frontend/searchdialog/analysis/csearchanalysisdialog.h index b4edcad..454e105 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysisdialog.h +++ b/src/frontend/searchdialog/analysis/csearchanalysisdialog.h @@ -1,8 +1,10 @@ /********* * +* In the name of the Father, and of the Son, and of the Holy Spirit. +* * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ diff --git a/src/frontend/searchdialog/analysis/csearchanalysisitem.cpp b/src/frontend/searchdialog/analysis/csearchanalysisitem.cpp index 23b2962..c516184 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysisitem.cpp +++ b/src/frontend/searchdialog/analysis/csearchanalysisitem.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -17,6 +17,7 @@ #include <QRect> #include "backend/drivers/cswordmoduleinfo.h" #include "frontend/searchdialog/analysis/csearchanalysisscene.h" +#include "util/htmlescape.h" namespace Search { @@ -61,17 +62,6 @@ CSearchAnalysisItem::~CSearchAnalysisItem() { delete m_bufferPixmap; } -/** Sets the resultcount of this item for the given module */ -void CSearchAnalysisItem::setCountForModule( const int moduleIndex, const int count) { - m_resultCountArray[moduleIndex] = count; -} - -/** Returns the resultcount of this item for the given module */ -int CSearchAnalysisItem::getCountForModule( const int moduleIndex) { - return m_resultCountArray[moduleIndex]; -} - - bool CSearchAnalysisItem::hasHitsInAnyModule() { foreach (const int hits, m_resultCountArray) { if (hits) return true; @@ -142,33 +132,36 @@ int CSearchAnalysisItem::width() { /** Returns the tooltip for this item. */ const QString CSearchAnalysisItem::getToolTip() { typedef CSwordModuleSearch::Results::const_iterator RCI; + using util::htmlEscape; - QString toolTipString = QString("<center><b>%1</b></center><hr/>").arg(m_bookName); - toolTipString += "<table cellspacing=\"0\" cellpadding=\"3\" width=\"100%\" height=\"100%\" align=\"center\">"; + QString toolTipString("<center><b>"); + toolTipString.append(htmlEscape(m_bookName)).append("</b></center><hr/>") + .append("<table cellspacing=\"0\" cellpadding=\"3\" width=\"10" + "0%\" height=\"100%\" align=\"center\">"); /// \todo Fix that loop int i = 0; - for (RCI it = m_results.begin(); it != m_results.end(); it++) { - const CSwordModuleInfo *info = it.key(); - - /// \warning This is a workaround for sword constness - sword::ListKey &results = const_cast<sword::ListKey &>(it.value()); - - const QColor c = CSearchAnalysisScene::getColor(i); - - toolTipString.append( - QString("<tr bgcolor=\"white\"><td><b><font color=\"%1\">%2</font></b></td><td>%3 (%4%)</td></tr>") - .arg(c.name()) - .arg(info ? info->name() : QString::null) - .arg( m_resultCountArray[i] ) - .arg( (info && m_resultCountArray[i]) ? ((double)m_resultCountArray[i] / (double)results.Count())*(double)100 : 0.0, 0, 'g', 2) - ); + for (RCI it = m_results.begin(); it != m_results.end(); ++it) { + const CSwordModuleInfo * const info = it.key(); + + const int count = it.value().getCount(); + const double percent = (info && count) + ? ((static_cast<double>(m_resultCountArray.at(i)) + * static_cast<double>(100.0)) + / static_cast<double>(count)) + : 0.0; + toolTipString.append("<tr bgcolor=\"white\"><td><b><font color=\"") + .append(CSearchAnalysisScene::getColor(i).name()).append("\">") + .append(info ? info->name() : QString::null) + .append("</font></b></td><td>") + .append(m_resultCountArray.at(i)) + .append(" (") + .append(QString::number(percent, 'g', 2)) + .append("%)</td></tr>"); ++i; } - toolTipString += "</table>"; - - return toolTipString; + return toolTipString.append("</table>"); } } diff --git a/src/frontend/searchdialog/analysis/csearchanalysisitem.h b/src/frontend/searchdialog/analysis/csearchanalysisitem.h index 7db96a9..ec2cd03 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysisitem.h +++ b/src/frontend/searchdialog/analysis/csearchanalysisitem.h @@ -1,8 +1,10 @@ /********* * +* In the name of the Father, and of the Son, and of the Holy Spirit. +* * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -27,15 +29,21 @@ class CSearchAnalysisItem : public QGraphicsRectItem { const CSwordModuleSearch::Results &results); ~CSearchAnalysisItem(); + /** - * Sets the resultcount of this item + Sets the resultcount of this item. */ - void setCountForModule( const int moduleIndex, const int count); + inline void setCountForModule(const int moduleIndex, const int count) { + m_resultCountArray[moduleIndex] = count; + } /** - * Returns the resultcount of this item + Returns the resultcount of this item. */ - int getCountForModule( const int moduleIndex); + inline int getCountForModule(const int moduleIndex) const { + return m_resultCountArray[moduleIndex]; + } + /** * Does one of the modules contain hits? */ diff --git a/src/frontend/searchdialog/analysis/csearchanalysislegenditem.cpp b/src/frontend/searchdialog/analysis/csearchanalysislegenditem.cpp index c5b9d02..e630846 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysislegenditem.cpp +++ b/src/frontend/searchdialog/analysis/csearchanalysislegenditem.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ diff --git a/src/frontend/searchdialog/analysis/csearchanalysislegenditem.h b/src/frontend/searchdialog/analysis/csearchanalysislegenditem.h index 232fe64..f199aaf 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysislegenditem.h +++ b/src/frontend/searchdialog/analysis/csearchanalysislegenditem.h @@ -1,8 +1,10 @@ /********* * +* In the name of the Father, and of the Son, and of the Holy Spirit. +* * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ diff --git a/src/frontend/searchdialog/analysis/csearchanalysisscene.cpp b/src/frontend/searchdialog/analysis/csearchanalysisscene.cpp index a039e19..9b375e8 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysisscene.cpp +++ b/src/frontend/searchdialog/analysis/csearchanalysisscene.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -13,10 +13,12 @@ #include <QFileDialog> #include <QHashIterator> #include <QTextCodec> +#include <QTextDocument> #include "backend/keys/cswordversekey.h" #include "frontend/searchdialog/analysis/csearchanalysisitem.h" #include "frontend/searchdialog/analysis/csearchanalysislegenditem.h" #include "frontend/searchdialog/csearchdialog.h" +#include "util/htmlescape.h" #include "util/tool.h" @@ -88,7 +90,7 @@ void CSearchAnalysisScene::analyse( bool ok = true; while (ok && analysisItem) { moduleIndex = 0; - for (RCI it = m_results.begin(); it != m_results.end(); it++) { + for (RCI it = m_results.begin(); it != m_results.end(); ++it) { qApp->processEvents( QEventLoop::AllEvents ); if (!m_lastPosList.contains(it.key())) { m_lastPosList.insert(it.key(), 0); @@ -120,7 +122,7 @@ void CSearchAnalysisScene::setResults( typedef CSwordModuleSearch::Results::const_iterator RCI; m_results.clear(); - for (RCI it = results.begin(); it != results.end(); it++) { + for (RCI it = results.begin(); it != results.end(); ++it) { const CSwordModuleInfo *m = it.key(); if ( (m->type() == CSwordModuleInfo::Bible) || (m->type() == CSwordModuleInfo::Commentary) ) { //a Bible or an commentary m_results.insert(m, it.value()); @@ -205,13 +207,12 @@ QColor CSearchAnalysisScene::getColor(int index) { unsigned int CSearchAnalysisScene::getCount(const QString &book, const CSwordModuleInfo* module) { - /// \warning This is a workaround for sword constness - sword::ListKey result = m_results[module]; + const sword::ListKey & result = m_results[module]; const int length = book.length(); unsigned int i = m_lastPosList[module]; unsigned int count = 0; - const unsigned int resultCount = result.Count(); + const unsigned int resultCount = result.getCount(); while (i < resultCount) { if (strncmp(book.toUtf8(), (const char *) *result.getElement(i), length)) break; @@ -223,67 +224,86 @@ unsigned int CSearchAnalysisScene::getCount(const QString &book, } void CSearchAnalysisScene::saveAsHTML() { - typedef CSwordModuleSearch::Results::const_iterator RCI; - - const QString fileName = QFileDialog::getSaveFileName(0, tr("Save Search Analysis"), QString::null, tr("HTML files (*.html;*.HTML;*.HTM;*.htm)") ); - if (fileName.isEmpty()) return; - - int count = 0; - QString countStr = ""; - QString m_searchAnalysisHTML = ""; - QString tableTitle = ""; - QString tableTotals = ""; - QString VerseRange = ""; - const QString txtCSS = QString("<style type=\"text/css\">\ntd {border:1px solid black;}\nth {font-size: 130%; text-align:left; vertical-align:top;}\n</style>\n"); - const QString metaEncoding = QString("<META http-equiv=Content-Type content=\"text/html; charset=utf-8\">"); - CSwordVerseKey key(0); + using util::htmlEscape; - key.setKey("Genesis 1:1"); - - CSearchAnalysisItem* analysisItem = m_itemList.value( key.book() ); - - QString text = "<html>\n<head>\n<title>" + tr("BibleTime Search Analysis") + "</title>\n" + txtCSS + metaEncoding + "</head>\n<body>\n"; - text += "<table>\n<tr><th>" + tr("Search text :") + "</th><th>" + CSearchDialog::getSearchDialog()->searchText() + "</th></tr>\n"; - - tableTitle = "<tr><th align=\"left\">" + tr("Book") + "</th>"; - tableTotals = "<tr><td align=\"left\">" + tr("Total hits") + "</td>"; - - for (RCI it = m_results.begin(); it != m_results.end(); it++) { - const CSwordModuleInfo *mod = it.key(); - tableTitle += QString("<th align=\"left\">") + mod->name() + QString("</th>"); + typedef CSwordModuleSearch::Results::const_iterator RCI; - /// \warning This is a workaround for sword constness - sword::ListKey searchResult = it.value(); - countStr.setNum(searchResult.Count()); + const QString fileName = QFileDialog::getSaveFileName(0, + tr("Save Search Analysis"), + QString::null, + tr("XHTML files (*.html *.HTML *.HTM *.htm);;All files (*)")); + if (fileName.isEmpty()) + return; - tableTotals += QString("<td align=\"right\">") + countStr + QString("</td>"); + QString text("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" " + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" + "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>"); + { + const QString title(tr("BibleTime Search Analysis")); + text += title; + text += "</title>" + "<style type=\"text/css\">" + "body{background-color:#fff;color:#000}" + "table{border-collapse:collapse}" + "td{border:1px solid #333}" + "th{font-size:130%;text-align:left;vertical-align:top}" + "td,th{text-align:left;padding:0.2em 0.5em}" + ".r{text-align:right}" + "</style>" + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>" + "</head><body><h1>"; + text += title; } - tableTitle += QString("</tr>\n"); - tableTotals += QString("</tr>\n"); - - m_searchAnalysisHTML = ""; - bool ok = true; - while (ok) { - m_searchAnalysisHTML += QString("<tr><td>") + key.book() + QString("</td>"); - analysisItem = m_itemList.value( key.book() ); + text += "</h1><p><span style=\"font-weight:bold\">"; + text += tr("Search text:"); + text += "</span> "; + text += htmlEscape(CSearchDialog::getSearchDialog()->searchText()); + text += "</p><table><caption>"; + text += tr("Results by work and book"); + text += "</caption><tr><th>"; + text += tr("Book"); + text += "</th>"; + + for (RCI it = m_results.begin(); it != m_results.end(); ++it) { + text += "<th>"; + text += htmlEscape(it.key()->name()); + text += "</th>"; + } + text += "</tr>"; - int moduleIndex = 0; - for (RCI it = m_results.begin(); it != m_results.end(); it++) { - count = analysisItem->getCountForModule(moduleIndex); - countStr.setNum(count); - m_searchAnalysisHTML += QString("<td align=\"right\">") + countStr + QString("</td>"); + CSwordVerseKey key(0); + key.setKey("Genesis 1:1"); - ++moduleIndex; + do { + text += "<tr><td>"; + const QString keyBook(key.book()); + text += htmlEscape(keyBook); + text += "</td>"; + + int mi = 0; // Module index + for (RCI it = m_results.begin(); it != m_results.end(); ++it, ++mi) { + text += "<td class=\"r\">"; + text += QString::number(m_itemList.value(keyBook)->getCountForModule(mi)); + text += "</td>"; } - m_searchAnalysisHTML += QString("</tr>\n"); - ok = key.next(CSwordVerseKey::UseBook); + text += "</tr>"; + } while (key.next(CSwordVerseKey::UseBook)); + text += "<tr><th class=\"r\">"; + text += tr("Total hits"); + text += "</th>"; + + for (RCI it = m_results.begin(); it != m_results.end(); ++it) { + text += "<td class=\"r\">"; + text += QString::number(it.value().getCount()); + text += "</td>"; } - text += QString("<table>\n") + tableTitle + tableTotals + m_searchAnalysisHTML + QString("</table>\n"); - text += QString("<center>") + tr("Created by <a href=\"http://www.bibletime.info/\">BibleTime</a>") + QString("</center>"); - text += QString("</body></html>"); + text += "</tr></table><p style=\"text-align:center;font-size:x-small\">"; + text += tr("Created by <a href=\"http://www.bibletime.info/\">BibleTime</a>"); + text += "</p></body></html>"; - util::tool::savePlainFile(fileName, text, false, QTextCodec::codecForName("UTF8")); + util::tool::savePlainFile(fileName, text, true, QTextCodec::codecForName("UTF8")); } void CSearchAnalysisScene::resizeHeight(int height) { @@ -291,4 +311,4 @@ void CSearchAnalysisScene::resizeHeight(int height) { slotResized(); } -} +} // namespace Search { diff --git a/src/frontend/searchdialog/analysis/csearchanalysisscene.h b/src/frontend/searchdialog/analysis/csearchanalysisscene.h index f8bb966..d1927d5 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysisscene.h +++ b/src/frontend/searchdialog/analysis/csearchanalysisscene.h @@ -1,8 +1,10 @@ /********* * +* In the name of the Father, and of the Son, and of the Holy Spirit. +* * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ diff --git a/src/frontend/searchdialog/analysis/csearchanalysisview.cpp b/src/frontend/searchdialog/analysis/csearchanalysisview.cpp index d177f63..277c1a3 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysisview.cpp +++ b/src/frontend/searchdialog/analysis/csearchanalysisview.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ diff --git a/src/frontend/searchdialog/analysis/csearchanalysisview.h b/src/frontend/searchdialog/analysis/csearchanalysisview.h index 19d53c1..4b072f3 100644 --- a/src/frontend/searchdialog/analysis/csearchanalysisview.h +++ b/src/frontend/searchdialog/analysis/csearchanalysisview.h @@ -1,8 +1,10 @@ /********* * +* In the name of the Father, and of the Son, and of the Holy Spirit. +* * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ |