]> gitweb.hamatoma.de Git - reqt/commitdiff
ReSearch: block handling, current hit file/line
authorHamatoma <hamatoma@gmx.de>
Sun, 4 Dec 2016 01:21:28 +0000 (02:21 +0100)
committerHamatoma <hamatoma@gmx.de>
Sun, 4 Dec 2016 01:21:28 +0000 (02:21 +0100)
appl/research/filefilter.cpp
appl/research/filefilter.hpp
appl/research/filefinder.cpp
appl/research/mainwindow.cpp
appl/research/mainwindow.hpp
appl/research/mainwindow.ui
appl/research/research.hpp

index 681345028506f99912f25b6fb5f6ac1d7f0b1dab..79e84f0f5bed0460d63e3eb96622298c30b203a3 100644 (file)
@@ -7,7 +7,7 @@
  * @param list  list widget to store the filtered lines
  */
 FileFilter::FileFilter(QTableWidget &table, QListWidget &list, FileCache& cache,
-                       HitPosition& lastHitPosition) :
+                       HitPosition& lastHitPosition, QStringList& filenames) :
     m_table(table),
     m_list(list),
     m_cache(cache),
@@ -22,7 +22,8 @@ FileFilter::FileFilter(QTableWidget &table, QListWidget &list, FileCache& cache,
     m_linesAbove(0),
     m_linesBelow(0),
     m_lastHitPosition(lastHitPosition),
-    m_prefixMode(pmNone)
+    m_prefixMode(pmNone),
+    m_filenames(filenames)
 {
 
 }
@@ -70,14 +71,14 @@ void FileFilter::filter(const QString &includePattern,
     delete m_excludeExpr;
     delete m_blockStartExpr;
     delete m_blockEndExpr;
-
+    m_filenames.clear();
     QRegularExpression::PatternOption option = caseSensitive
             ? QRegularExpression::NoPatternOption
             : QRegularExpression::CaseInsensitiveOption;
     m_includeExpr = includePattern.isEmpty() ? NULL : new QRegularExpression(includePattern, option);
     m_excludeExpr = excludePattern.isEmpty() ? NULL : new QRegularExpression(excludePattern, option);
-    m_blockStartExpr = includePattern.isEmpty() ? NULL : new QRegularExpression(blockStart, option);
-    m_blockEndExpr = excludePattern.isEmpty() ? NULL : new QRegularExpression(blockEnd, option);
+    m_blockStartExpr = blockStart.isEmpty() ? NULL : new QRegularExpression(blockStart, option);
+    m_blockEndExpr = blockEnd.isEmpty() ? NULL : new QRegularExpression(blockEnd, option);
     QString full;
     QString node;
     int hitFileNo = -1;
@@ -143,8 +144,16 @@ int FileFilter::filterOneFile(const QString& filename, const QString& node,
         lineNo = m_lastHitPosition.m_line;
     }
     int firstHitFile = true;
+    int firstFileIndex = -1;
+    bool inBlock = m_blockStartExpr == NULL;
     while(lastHit < m_toHit && lineNo < lastIx){
         QString line = lines[++lineNo];
+        if (! inBlock){
+            if (m_blockStartExpr->match(line).hasMatch())
+                inBlock = true;
+            else
+                continue;
+        }
         if (m_includeExpr != NULL && ! m_includeExpr->match(line).hasMatch())
             continue;
         if (m_excludeExpr != NULL && m_excludeExpr->match(line).hasMatch())
@@ -165,10 +174,26 @@ int FileFilter::filterOneFile(const QString& filename, const QString& node,
             for (int ix = max(lastLine + 1, max(0, lineNo - m_linesAbove));
                  ix <= min(lineNo + m_linesBelow, lastIx);
                  ix++){
+                if (m_prefixMode != pmFull){
+                    if (firstFileIndex < 0){
+                        firstFileIndex = m_filenames.size();
+                        m_filenames.append(filename);
+                    } else {
+                        if ((firstFileIndex - m_filenames.size()) % 16 == 0)
+                            m_filenames.append("\t" + QString::number(firstFileIndex));
+                        else
+                            m_filenames.append("");
+                    }
+                }
                 m_list.addItem((ix == lineNo ? prefixHit : prefixOther)
                         + QString::number(ix + 1) + ": " + lines[ix]);
             }
         }
+        if (m_blockEndExpr != 0 && m_blockEndExpr->match(line).hasMatch()){
+            inBlock = false;
+            if (m_singleBlock)
+                break;
+        }
     }
     return lastHit;
 }
index 4b4dfe8229282ee5f6709b566d6f0763f9e1856f..08c79ff55a40484d03cfe06a390e54309313390a 100644 (file)
@@ -23,7 +23,7 @@ class FileFilter
 {
 public:
     FileFilter(QTableWidget& table, QListWidget& list, FileCache& cache,
-               HitPosition& lastHitPosition);
+               HitPosition& lastHitPosition, QStringList& filenames);
     virtual ~FileFilter();
 public:
     void filter(const QString& includePattern, const QString& excludePattern,
@@ -51,6 +51,11 @@ private:
    int m_linesBelow;
    HitPosition& m_lastHitPosition;
    PrefixMode m_prefixMode;
+   // m_filenames[ix] contains the filename with path of listWidgetHits[ix]
+   // or m_filenames[ix].isEmpty(): then the next (reverse) non empty entry
+   // contains the filename
+   // or m_filenames[ix] = "\t<no>" where m_filenames[no] contains the filename
+   QStringList& m_filenames;
 };
 
 #endif // FILEFILTER_H
index dd1c9cddb65d1f7abe99ce2a3d329a882fa71f30..e22935149a361d5f1fda2046bef5bd17f6fbe40a 100644 (file)
@@ -54,11 +54,16 @@ void FileFinder::addToTable(const QString& full, const QString &path,
         int last = m_table.rowCount();
         m_files.insert(full);
         m_table.setRowCount(last + 1);
-        m_table.setItem(last, colNode, new QTableWidgetItem(node));
-        m_table.setItem(last, colSize, new QTableWidgetItem(QString::number(info.size())));
+        QTableWidgetItem* current;
+        m_table.setItem(last, colNode, current = new QTableWidgetItem(node));
+        current->setFlags(current->flags() ^ Qt::ItemIsEditable);
+        m_table.setItem(last, colSize, current = new QTableWidgetItem(QString::number(info.size())));
+        current->setFlags(current->flags() ^ Qt::ItemIsEditable);
         QString date = info.lastModified().toString("yyyy.MM.dd hh:mm.ss");
-        m_table.setItem(last, colDate, new QTableWidgetItem(date));
-        m_table.setItem(last, colPath, new QTableWidgetItem(path));
+        m_table.setItem(last, colDate, current = new QTableWidgetItem(date));
+        current->setFlags(current->flags() ^ Qt::ItemIsEditable);
+        m_table.setItem(last, colPath, current = new QTableWidgetItem(path));
+        current->setFlags(current->flags() ^ Qt::ItemIsEditable);
     }
 }
 
index 435c32ac8d6e3d19d0c524379361eb8a09919c37..a6a14456d2c7c8bd650495369a2b0061387ff456 100644 (file)
@@ -20,7 +20,8 @@ MainWindow::MainWindow(QApplication& application, const QString& homeDir,
        m_test(true),
     m_lastHitPosition(new HitPosition()),
     m_currentTask(ttUndef),
-    m_timer(new QTimer(this))
+    m_timer(new QTimer(this)),
+    m_filenames()
 {
        ReComboBox::setDefaultHistorySize(20);
     m_timer->setSingleShot(true);
@@ -101,6 +102,11 @@ void MainWindow::initializeGui(){
             this, SLOT(clearLastHitPosition(const QString&, const QString&)));
     connect(ui->comboBoxFromHit, SIGNAL(textEdited(QString,QString)),
             this, SLOT(onFromHitChanged(const QString&, const QString&)));
+    connect(ui->tableWidget, SIGNAL(cellEntered(int,int)),
+            this, SLOT(onCellEntered(int, int)));
+    connect(ui->listWidgetHits, SIGNAL(itemClicked(QListWidgetItem*)),
+            this, SLOT(onHitLineClicked(QListWidgetItem*)));
+
 
     connect(m_timer, SIGNAL(timeout()), this, SLOT(onTimerTask()));
 
@@ -114,6 +120,42 @@ void MainWindow::initializeGui(){
        if (m_test){
        }
 }
+void MainWindow::onCellEntered(int row, int column)
+{
+    row++;
+}
+
+/**
+ * Shows the current hit line as file and content in 2 fields.
+ *
+ * @param item  the current hit line
+ */
+void MainWindow::onHitLineClicked(QListWidgetItem* item){
+    if (ui->lineEditCurrentFile->isVisible()){
+        int row = item->listWidget()->row(item);
+        QString line = item->text();
+        int ix = line.indexOf(':');
+        ui->lineEditCurrentLine->setText(item->text().mid(ix + 1));
+        PrefixMode mode = (PrefixMode) ui->comboBoxPrefixMode->currentIndex();
+        if (mode == pmFull){
+            // format: <filename>-<lineNo>: <content>
+            line = line.mid(0, ix);
+            ui->lineEditCurrentFile->setText(line.mid(0, line.lastIndexOf('-')));
+        } else {
+            QString name;
+            while(row >= 0){
+                name = m_filenames[row--];
+                if (name.isEmpty()){
+                    continue;
+                } else if (name[0] == QChar('\t')){
+                    name = m_filenames[atoi(name.toLatin1().data() + 1)];
+                    break;
+                }
+            }
+            ui->lineEditCurrentFile->setText(name);
+        }
+    }
+}
 
 /**
  * Writes the known number of hits into the label.
@@ -219,7 +261,7 @@ void MainWindow::onFilter()
 {
     qint64 start = QDateTime::currentMSecsSinceEpoch();
        FileFilter filter(*ui->tableWidget, *ui->listWidgetHits, *m_fileCache,
-                                         *m_lastHitPosition);
+                      *m_lastHitPosition, m_filenames);
     int from = comboInt(ui->comboBoxFromHit, 0);
     int pageSize = comboInt(ui->comboBoxPageSize, s_defaultPageSize);
     int above = comboInt(ui->comboBoxLinesAbove, 0);
index ee9d3887f68df8b81ff5a221a4589bb14fbe2c28..f061af77b7d21f0b5a319294a771390465d3b308 100644 (file)
@@ -50,10 +50,12 @@ private slots:
     void clearLastHitPosition(const QString &, const QString &);
     void onAbout();
     void onAdd();
+    void onCellEntered(int row, int column);
     void onClear();
     void onDetach();
     void onFilter();
     void onFromHitChanged(const QString &oldValue, const QString &newValue);
+    void onHitLineClicked(QListWidgetItem *item);
     void onNext();
     void onPrevious();
     void onSelectBaseDirectory();
@@ -67,5 +69,10 @@ private:
    HitPosition* m_lastHitPosition;
    TimerTask m_currentTask;
    QTimer* m_timer;
+   // m_filenames[ix] contains the filename with path of listWidgetHits[ix]
+   // or m_filenames[ix].isEmpty(): then the next (reverse) non empty entry
+   // contains the filename
+   // or m_filenames[ix] = "\t<no>" where m_filenames[no] contains the filename
+   QStringList m_filenames;
 };
 #endif // MAINWINDOW_H
index 10db55db6ab7503aa07707d4b06b12988a8b5b6c..e1b42647b7b61a37883ea30f7a8a0e0331da845c 100644 (file)
@@ -448,9 +448,24 @@ If the checkbox &quot;inverse search&quot; is checked a file is found only if th
           </item>
           <item>
            <widget class="QTableWidget" name="tableWidget">
+            <property name="editTriggers">
+             <set>QAbstractItemView::AllEditTriggers</set>
+            </property>
+            <property name="selectionMode">
+             <enum>QAbstractItemView::MultiSelection</enum>
+            </property>
+            <property name="selectionBehavior">
+             <enum>QAbstractItemView::SelectRows</enum>
+            </property>
+            <property name="sortingEnabled">
+             <bool>true</bool>
+            </property>
             <attribute name="horizontalHeaderStretchLastSection">
              <bool>true</bool>
             </attribute>
+            <attribute name="verticalHeaderShowSortIndicator" stdset="0">
+             <bool>false</bool>
+            </attribute>
             <column>
              <property name="text">
               <string>Name</string>
@@ -679,17 +694,17 @@ If the checkbox &quot;inverse search&quot; is checked a file is found only if th
                   </property>
                   <item>
                    <property name="text">
-                    <string>Filename with path</string>
+                    <string>Placeholder</string>
                    </property>
                   </item>
                   <item>
                    <property name="text">
-                    <string>Filename without path</string>
+                    <string>Filename with path</string>
                    </property>
                   </item>
                   <item>
                    <property name="text">
-                    <string>Placeholder</string>
+                    <string>Filename without path</string>
                    </property>
                   </item>
                   <item>
@@ -896,6 +911,23 @@ If the checkbox &quot;inverse search&quot; is checked a file is found only if th
           </item>
          </layout>
         </item>
+        <item>
+         <layout class="QHBoxLayout" name="horizontalLayout_6">
+          <item>
+           <widget class="QLineEdit" name="lineEditCurrentFile"/>
+          </item>
+          <item>
+           <widget class="QLabel" name="labelCurrentSeparator">
+            <property name="text">
+             <string>:</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QLineEdit" name="lineEditCurrentLine"/>
+          </item>
+         </layout>
+        </item>
        </layout>
       </widget>
      </widget>
index 08f3f0c3ea7c2f7191b15b49ccb4ba40140d7816..e264f888c4fdc611ea3b7f2b36d8ac0e7c1cfbaf 100644 (file)
@@ -18,9 +18,9 @@ enum ColumnFiles {
 };
 
 enum PrefixMode {
+    pmPlaceholder,
     pmFull,
     pmNode,
-    pmPlaceholder,
     pmNone,
 };