From 446348b0d34ebd24b4c3a9085639465366bf7a7c Mon Sep 17 00:00:00 2001 From: Hamatoma Date: Sun, 4 Dec 2016 23:13:21 +0100 Subject: [PATCH] ReSearch: DEL key for detaching files --- appl/research/filefilter.cpp | 2 +- appl/research/mainwindow.cpp | 57 ++++++++++++++++++++++++++++++++++-- appl/research/mainwindow.hpp | 2 ++ appl/research/mainwindow.ui | 9 ++++++ base/ReQStringUtils.cpp | 19 ++++++++---- base/ReQStringUtils.hpp | 3 +- 6 files changed, 82 insertions(+), 10 deletions(-) diff --git a/appl/research/filefilter.cpp b/appl/research/filefilter.cpp index 79e84f0..16425ae 100644 --- a/appl/research/filefilter.cpp +++ b/appl/research/filefilter.cpp @@ -144,7 +144,7 @@ int FileFilter::filterOneFile(const QString& filename, const QString& node, lineNo = m_lastHitPosition.m_line; } int firstHitFile = true; - int firstFileIndex = -1; + int firstFileIndex = 0; bool inBlock = m_blockStartExpr == NULL; while(lastHit < m_toHit && lineNo < lastIx){ QString line = lines[++lineNo]; diff --git a/appl/research/mainwindow.cpp b/appl/research/mainwindow.cpp index a6a1445..24bd7e1 100644 --- a/appl/research/mainwindow.cpp +++ b/appl/research/mainwindow.cpp @@ -72,6 +72,50 @@ int MainWindow::addSingleFile(bool addNotDetach, const QString& filename, int& a } return rc; } +static bool intLessThan(const int& v1, const int& v2) + { + return v1 < v2; + } +/** + * General event handler. + * + * @param obj the receiver object + * @param event the event + * @return true: event is handled.
+ * false: the event should be handled by another hander + */ +bool MainWindow::eventFilter(QObject *obj, QEvent *event) +{ + bool rc = false; + if (event->type() == QEvent::KeyPress && obj == ui->tableWidget){ + // QWidget *widget = (QWidget*) obj; + // QString name = widget->objectName(); + QKeyEvent* key = static_cast(event); + if ( (key->key()==Qt::Key_Delete)){ + QList ranges = ui->tableWidget->selectedRanges(); + QList rows; + for (int ix = 0; ix < ranges.size(); ++ix){ + QTableWidgetSelectionRange range = ranges[ix]; + for (int row = range.bottomRow(); row >= range.topRow(); row--){ + rows.append(row); + } + } + if (rows.size() > 0){ + qSort(rows.begin(), rows.end(), intLessThan); + for (int row = rows.size() - 1; row >= 0; --row){ + ui->tableWidget->removeRow(row); + } + say(LOG_INFO, tr("%1 file(s) detached").arg(rows.size())); + logFiles(); + ui->tableWidget->clearSelection(); + } + rc = true; + } else { + rc = QObject::eventFilter(obj, event); + } + } + return rc; +} /** * Initializes the Graphical User Interface. @@ -106,7 +150,7 @@ void MainWindow::initializeGui(){ this, SLOT(onCellEntered(int, int))); connect(ui->listWidgetHits, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(onHitLineClicked(QListWidgetItem*))); - + ui->tableWidget->installEventFilter(this); connect(m_timer, SIGNAL(timeout()), this, SLOT(onTimerTask())); @@ -157,6 +201,14 @@ void MainWindow::onHitLineClicked(QListWidgetItem* item){ } } +/** + * Logs the current number of files. + */ +void MainWindow::logFiles(){ + ui->labelFileCount->setText(QString::number(ui->tableWidget->rowCount()) + + " " + tr("file(s)")); +} + /** * Writes the known number of hits into the label. */ @@ -416,8 +468,7 @@ void MainWindow::searchFiles(bool addNotDetach) atoi(ui->lineEditMinDepth->text().toLocal8Bit().data()), atoi(ui->lineEditMaxDepth->text().toLocal8Bit().data())); int files = ui->tableWidget->rowCount(); - ui->labelFileCount->setText(QString::number(files) - + " " + tr("file(s)")); + logFiles(); say(LOG_INFO, tr("files: %1 already found: %2 processed directories: %3") .arg(m_fileFinder->foundFiles()) .arg(m_fileFinder->ignoredFiles()) diff --git a/appl/research/mainwindow.hpp b/appl/research/mainwindow.hpp index f061af7..368d114 100644 --- a/appl/research/mainwindow.hpp +++ b/appl/research/mainwindow.hpp @@ -35,7 +35,9 @@ public: private: int addSingleFile(bool addNotDetach, const QString &filename, int &alreadyFound); + virtual bool eventFilter(QObject* obj, QEvent* event); void initializeGui(); + void logFiles(); void logHits(); void onAddTimer(); virtual void onAboutToQuit(); diff --git a/appl/research/mainwindow.ui b/appl/research/mainwindow.ui index e1b4264..b7a4fc0 100644 --- a/appl/research/mainwindow.ui +++ b/appl/research/mainwindow.ui @@ -451,6 +451,15 @@ If the checkbox "inverse search" is checked a file is found only if th QAbstractItemView::AllEditTriggers + + false + + + false + + + false + QAbstractItemView::MultiSelection diff --git a/base/ReQStringUtils.cpp b/base/ReQStringUtils.cpp index 9e24d3c..a930415 100644 --- a/base/ReQStringUtils.cpp +++ b/base/ReQStringUtils.cpp @@ -505,20 +505,29 @@ void ReQStringUtils::skipExpected(const ReString& text, QChar expected, /** * Converts a number into a name containing only characters 'A' - 'Z' and '_'. * - * Negative numbers are marked with '_' at the end. + * Negative numbers are marked with first member of charSet. * * @param number the number to convert + * @param charSet the characters used for the name. The first character is + * used to mark negative numbers. + * If NULL a standard characater (A-Z0-9) set is used * @return the name which is unique to the number */ -QString ReQStringUtils::numberToName(int number){ +QString ReQStringUtils::numberToName(int number, const char* charSet, int charSetSize){ QString rc; + if (charSet == NULL){ + charSet = "-$ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + charSetSize = 37+1; // strlen(charSet) + } if (number < 0){ number = -number; - rc = '_'; + rc = charSet[0]; } + ++charSet; + --charSetSize; do { - QChar cc('A' + number % 26); - number /= 26; + QChar cc(charSet[number % charSetSize]); + number /= charSetSize; rc.insert(0, cc); } while(number > 0); return rc; diff --git a/base/ReQStringUtils.hpp b/base/ReQStringUtils.hpp index 0c2aeac..dc23232 100644 --- a/base/ReQStringUtils.hpp +++ b/base/ReQStringUtils.hpp @@ -73,7 +73,8 @@ public: uint* pValue = NULL); static QString longestPrefix(const QStringList& list); static bool match(const QString& heap, const QStringList& needles); - static QString numberToName(int number); + static QString numberToName(int number, const char* charSet = NULL, + int charSetSize = 0); /** * Returns the path with native path separators. * -- 2.39.5