diff options
Diffstat (limited to 'src/frontend/searchdialog/analysis/csearchanalysisscene.cpp')
-rw-r--r-- | src/frontend/searchdialog/analysis/csearchanalysisscene.cpp | 136 |
1 files changed, 78 insertions, 58 deletions
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 { |