]> gitweb.hamatoma.de Git - reqt/commitdiff
ReSearch: DEL key for detaching files
authorHamatoma <hamatoma@gmx.de>
Sun, 4 Dec 2016 22:13:21 +0000 (23:13 +0100)
committerHamatoma <hamatoma@gmx.de>
Sun, 4 Dec 2016 22:13:21 +0000 (23:13 +0100)
appl/research/filefilter.cpp
appl/research/mainwindow.cpp
appl/research/mainwindow.hpp
appl/research/mainwindow.ui
base/ReQStringUtils.cpp
base/ReQStringUtils.hpp

index 79e84f0f5bed0460d63e3eb96622298c30b203a3..16425ae195331f918a19bb45e5675f31d06e2575 100644 (file)
@@ -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];
index a6a14456d2c7c8bd650495369a2b0061387ff456..24bd7e148fd0290aeff553acfd829fc01240b821 100644 (file)
@@ -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          <i>true</i>: event is handled.<br>
+ *                  <i>false</i>: 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<QKeyEvent*>(event);
+        if ( (key->key()==Qt::Key_Delete)){
+            QList<QTableWidgetSelectionRange> ranges = ui->tableWidget->selectedRanges();
+            QList<int> 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())
index f061af77b7d21f0b5a319294a771390465d3b308..368d1141d8263f47922f91cb402bd428184817b8 100644 (file)
@@ -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();
index e1b42647b7b61a37883ea30f7a8a0e0331da845c..b7a4fc0e56b1c7629cf2ced17508a69c7126f45c 100644 (file)
@@ -451,6 +451,15 @@ If the checkbox &quot;inverse search&quot; is checked a file is found only if th
             <property name="editTriggers">
              <set>QAbstractItemView::AllEditTriggers</set>
             </property>
+            <property name="tabKeyNavigation">
+             <bool>false</bool>
+            </property>
+            <property name="showDropIndicator" stdset="0">
+             <bool>false</bool>
+            </property>
+            <property name="dragDropOverwriteMode">
+             <bool>false</bool>
+            </property>
             <property name="selectionMode">
              <enum>QAbstractItemView::MultiSelection</enum>
             </property>
index 9e24d3cced8c6d3ddef9e016da346de472cf6e6a..a9304156fb142d113b178b1d5be7a30d1c414069 100644 (file)
@@ -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 <i>charSet</i>.
  *
  * @param number    the number to convert
+ * @param charSet   the characters used for the name. The first character is
+ *                  used to mark negative numbers.
+ *                  If <i>NULL</i> 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;
index 0c2aeacf73fcbf10a2e16c23492b5124bd861bf9..dc23232c3a9c3167e68e546e681cfa1c420b500c 100644 (file)
@@ -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.
         *