From 15345b49c6c594503beb4c4e1c4ca1aff6e2d5c8 Mon Sep 17 00:00:00 2001 From: Hamatoma Date: Sat, 26 Nov 2016 00:37:56 +0100 Subject: [PATCH] Research: improvements --- appl/research/filefilter.cpp | 2 ++ appl/research/filefilter.hpp | 4 +++- appl/research/mainwindow.cpp | 45 ++++++++++++++++++++++++++++++++---- appl/research/mainwindow.hpp | 2 ++ appl/research/mainwindow.ui | 16 +++++++++++++ 5 files changed, 63 insertions(+), 6 deletions(-) diff --git a/appl/research/filefilter.cpp b/appl/research/filefilter.cpp index 2057757..68a8ecc 100644 --- a/appl/research/filefilter.cpp +++ b/appl/research/filefilter.cpp @@ -120,6 +120,8 @@ int FileFilter::filterOneFile(const QString& filename, int lastHit) } m_lastHitPosition.m_line = lineNo; m_lastHitPosition.m_hitNo = ++lastHit; + if (m_lastHitPosition.m_hitNo > m_lastHitPosition.m_maxHitNo) + m_lastHitPosition.m_maxHitNo = m_lastHitPosition.m_hitNo; if (lastHit >= m_fromHit){ for (int ix = max(lastLine + 1, max(0, lineNo - m_linesAbove)); ix <= min(lineNo + m_linesBelow, lastIx); diff --git a/appl/research/filefilter.hpp b/appl/research/filefilter.hpp index 827d625..a86dc2c 100644 --- a/appl/research/filefilter.hpp +++ b/appl/research/filefilter.hpp @@ -8,13 +8,15 @@ public: m_filename(), m_line(0), m_hitNo(0), - m_hitCount(-1) + m_hitCount(-1), + m_maxHitNo(0) {} public: QString m_filename; int m_line; int m_hitNo; int m_hitCount; + int m_maxHitNo; }; class FileFilter diff --git a/appl/research/mainwindow.cpp b/appl/research/mainwindow.cpp index d211ddb..581441e 100644 --- a/appl/research/mainwindow.cpp +++ b/appl/research/mainwindow.cpp @@ -5,7 +5,7 @@ #include "QFileDialog" -static const char* VERSION = "2016.11.16"; +static const char* VERSION = "2016.11.26"; MainWindow::MainWindow(QApplication& application, const QString& homeDir, QWidget *parent) : @@ -84,20 +84,34 @@ void MainWindow::initializeGui(){ ui->tableWidget->setColumnWidth(colNode, 200); ui->tableWidget->setColumnWidth(colSize, 125); ui->tableWidget->setColumnWidth(colDate, 175); - + switchFilter(true); if (m_test){ - ui->comboBoxBaseDirectory->setCurrentText("/etc"); - ui->comboBoxFilePatterns->setCurrentText("*asu*"); - ui->comboBoxIncludingPattern->setCurrentText("#!"); + ui->comboBoxBaseDirectory->setCurrentText("/home/mhm/labor"); + ui->comboBoxFilePatterns->setCurrentText("big*.txt"); + ui->comboBoxIncludingPattern->setCurrentText("47"); onAdd(); } } +/** + * Writes the known number of hits into the label. + */ +void MainWindow::logHits(){ + if (m_lastHitPosition->m_hitCount >= 0) + ui->labelHits->setText(tr("%1 hit(s)").arg(m_lastHitPosition->m_hitCount)); + else + ui->labelHits->setText(tr(">= %1 hit(s)").arg(m_lastHitPosition->m_maxHitNo)); +} + +/** + * Handles the change of the search criteria. + */ void MainWindow::clearLastHitPosition(const QString&, const QString&) { m_lastHitPosition->m_filename.clear(); m_lastHitPosition->m_hitCount = -1; m_lastHitPosition->m_hitNo = -1; + m_lastHitPosition->m_maxHitNo = 0; } /** @@ -157,6 +171,7 @@ void MainWindow::onFilter() filter.filter(ui->comboBoxIncludingPattern->currentText(), ui->comboBoxExcludingPattern->currentText(), from, to, above, below, false); + switchFilter(false); } /** @@ -260,6 +275,26 @@ void MainWindow::searchFiles(bool addNotDetach) } } +/** + * Switches the filter state. + * + * @param first true: a new resultset is expected. + */ +void MainWindow::switchFilter(bool first){ + ui->pushButtonFilter->setEnabled(first); + ui->pushButtonPrevious->setEnabled(! first); + ui->pushButtonNext->setEnabled(! first); + if (first){ + int start = comboInt(ui->comboBoxFromHit, 1); + int pageSize = comboInt(ui->comboBoxToHit, start + 50) - start + 1; + ui->comboBoxFromHit->setCurrentText("1"); + ui->comboBoxToHit->setCurrentText(QString::number(pageSize)); + ui->labelHits->setText(""); + } else { + logHits(); + } +} + /** * Event * @param oldString diff --git a/appl/research/mainwindow.hpp b/appl/research/mainwindow.hpp index 240f7a4..623d46f 100644 --- a/appl/research/mainwindow.hpp +++ b/appl/research/mainwindow.hpp @@ -30,10 +30,12 @@ public: private: int comboboxToInt(QComboBox &combobox, int defaultValue); void initializeGui(); + void logHits(); virtual void onAboutToQuit(); virtual void onGuiTimerUpdate(); virtual void onLanguageChange(); void searchFiles(bool addNotDetach); + void switchFilter(bool first); private slots: void clearLastHitPosition(const QString &, const QString &); void onAbout(); diff --git a/appl/research/mainwindow.ui b/appl/research/mainwindow.ui index 605bc0b..e6aa781 100644 --- a/appl/research/mainwindow.ui +++ b/appl/research/mainwindow.ui @@ -596,8 +596,21 @@ If the checkbox "inverse search" is checked a file is found only if th + + + + 123456 Hits + + + Qt::PlainText + + + + + false + 25 @@ -614,6 +627,9 @@ If the checkbox "inverse search" is checked a file is found only if th + + false + 25 -- 2.39.5