16 #include <QContextMenuEvent>
18 #include <QProgressDialog>
19 #include <QStringList>
20 #include <QtAlgorithms>
21 #include <QTreeWidget>
22 #include <QTreeWidgetItem>
24 #include "../../backend/config/btconfig.h"
25 #include "../../backend/cswordmodulesearch.h"
26 #include "../../backend/drivers/cswordmoduleinfo.h"
27 #include "../../backend/managers/cswordbackend.h"
28 #include "../../backend/rendering/cdisplayrendering.h"
29 #include "../../backend/rendering/ctextrendering.h"
30 #include "../../util/btassert.h"
31 #include "../../util/btconnect.h"
32 #include "../../util/cresmgr.h"
33 #include "../../util/tool.h"
34 #include "../cexportmanager.h"
43 QString
const & lemmaText)
45 static constexpr Qt::CaseSensitivity
const cs = Qt::CaseInsensitive;
48 if (startIndex == 0) {
49 index = verseContent.indexOf(QStringLiteral(
"<body"));
55 while ((index = verseContent.indexOf(QStringLiteral(
"lemma="), index, cs))
60 auto const idx1 = verseContent.indexOf(
'"', index) + 1;
61 auto idx2 = verseContent.indexOf(
'"', idx1 + 1);
62 auto const sNumber = verseContent.mid(idx1, idx2 - idx1);
63 if (sNumber == lemmaText) {
67 index = verseContent.indexOf(
'>', index, cs) + 1;
68 idx2 = verseContent.indexOf(
'<', index, cs);
70 return verseContent.mid(index, idx2 - index);
82 QString
const & strongsNumber)
86 auto const count = result.size();
92 modules.append(module);
97 QProgressDialog progress(QObject::tr(
"Parsing Strong's Numbers"),
nullptr, 0, count);
104 qApp->processEvents(QEventLoop::AllEvents, 1);
107 for (
auto const & keyPtr : result) {
108 progress.setValue(index++);
109 qApp->processEvents(QEventLoop::AllEvents, 1);
111 QString key = QString::fromUtf8(keyPtr->getText());
113 for (
int sIndex = 0;;) {
116 if (rText.isEmpty())
break;
118 for (
auto & result : list) {
119 if (result.keyText() == rText) {
120 result.addKeyName(key);
146 setToolTip(tr(
"Works chosen for the search and the number of the hits in each work"));
147 setHeaderLabels( QStringList(tr(
"Work")) << tr(
"Hits") );
162 m_actions.copyMenu->setIcon(CResMgr::searchdialog::result::moduleList::copyMenu::icon());
166 if (auto * const m = activeModule())
167 CExportManager(true, tr(
"Copying search result"))
168 .copyKeyList(m_results[m],
170 CExportManager::Text,
174 m_actions.copy.resultWithText =
new QAction(tr(
"Reference with text"),
this);
177 if (auto * const m = activeModule())
178 CExportManager(true, tr(
"Copying search result"))
179 .copyKeyList(m_results[m],
181 CExportManager::Text,
188 m_actions.saveMenu->setIcon(CResMgr::searchdialog::result::moduleList::saveMenu::icon());
192 if (auto * const m = activeModule())
193 CExportManager(true, tr(
"Saving search result"))
194 .saveKeyList(m_results[m],
196 CExportManager::Text,
200 m_actions.save.resultWithText =
new QAction(tr(
"Reference with text"),
this);
203 if (auto * const m = activeModule())
204 CExportManager(true, tr(
"Saving search result"))
205 .saveKeyList(m_results[m],
207 CExportManager::Text,
214 m_actions.printMenu->setIcon(CResMgr::searchdialog::result::moduleList::printMenu::icon());
218 if (auto * const m = activeModule())
219 CExportManager(true, tr(
"Printing search result"))
220 .printKeyList(m_results[m],
222 btConfig().getDisplayOptions(),
223 btConfig().getFilterOptions());
232 BT_CONNECT(
this, &CModuleResultView::currentItemChanged,
237 const QString & searchedText)
245 bool strongsAvailable =
false;
247 for (
auto const &
result : results) {
248 auto const *
const m =
result.module;
251 QTreeWidgetItem *
const item =
252 new QTreeWidgetItem(
this,
253 QStringList(m->name())
254 << QString::number(
result.results.size()));
264 int sstIndex = searchedText.indexOf(QStringLiteral(
"strong:"), 0);
265 if (sstIndex != -1) {
272 const int sTokenIndex = searchedText.indexOf(
' ', sstIndex);
273 const QString sNumber(searchedText.mid(sstIndex, sTokenIndex - sstIndex));
280 for (
auto const & strongResult : strongResultList)
283 QStringList{strongResult.keyText(),
284 QString::number(strongResult.keyCount())});
288 strongsAvailable =
true;
293 setRootIsDecorated( strongsAvailable );
305 auto const & itemText = i->text(0);
313 if (strongsResult.keyText() == itemText) {
317 strongsResult.getKeyList());
325 QTreeWidgetItem * item = currentItem();
330 while (item->parent())
331 item = item->parent();
339 m_popup->exec(event->globalPos());
QList< CSwordModuleInfo const * > BtConstModuleList
CSwordModuleInfo * findModuleByName(const QString &name) const
Searches for a module with the given name.
static CSwordBackend & instance() noexcept
Rendering for the html display widget.
QString renderSingleKey(const QString &key, const BtConstModuleList &modules, const KeyTreeItem::Settings &settings=KeyTreeItem::Settings())
CSwordModuleInfo * activeModule()
CModuleResultView(QWidget *parent)
void strongsSelected(CSwordModuleInfo *, const QStringList &)
void setupTree(const CSwordModuleSearch::Results &results, const QString &searchedText)
struct Search::CModuleResultView::@9 m_actions
QHash< CSwordModuleInfo const *, CSwordModuleSearch::ModuleResultList > m_results
void contextMenuEvent(QContextMenuEvent *event) override
QHash< CSwordModuleInfo const *, QList< StrongsResult > > m_strongsResults
void executed(QTreeWidgetItem *, QTreeWidgetItem *)
void moduleSelected(CSwordModuleInfo const *, CSwordModuleSearch::ModuleResultList const &)
~CModuleResultView() override
std::vector< std::shared_ptr< sword::SWKey const > > ModuleResultList
std::vector< ModuleSearchResult > Results
void populateStrongsResultList(QList< StrongsResult > &list, CSwordModuleInfo const *module, CSwordModuleSearch::ModuleResultList const &result, QString const &strongsNumber)
QString getStrongsNumberText(QString const &verseContent, int &startIndex, QString const &lemmaText)