From: Hamatoma Date: Sun, 4 Dec 2016 01:21:28 +0000 (+0100) Subject: ReSearch: block handling, current hit file/line X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=c1b94c6dbf86a225107163dc0f2d5b1eba8977dc;p=reqt ReSearch: block handling, current hit file/line --- diff --git a/appl/research/filefilter.cpp b/appl/research/filefilter.cpp index 6813450..79e84f0 100644 --- a/appl/research/filefilter.cpp +++ b/appl/research/filefilter.cpp @@ -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; } diff --git a/appl/research/filefilter.hpp b/appl/research/filefilter.hpp index 4b4dfe8..08c79ff 100644 --- a/appl/research/filefilter.hpp +++ b/appl/research/filefilter.hpp @@ -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" where m_filenames[no] contains the filename + QStringList& m_filenames; }; #endif // FILEFILTER_H diff --git a/appl/research/filefinder.cpp b/appl/research/filefinder.cpp index dd1c9cd..e229351 100644 --- a/appl/research/filefinder.cpp +++ b/appl/research/filefinder.cpp @@ -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); } } diff --git a/appl/research/mainwindow.cpp b/appl/research/mainwindow.cpp index 435c32a..a6a1445 100644 --- a/appl/research/mainwindow.cpp +++ b/appl/research/mainwindow.cpp @@ -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: -: + 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); diff --git a/appl/research/mainwindow.hpp b/appl/research/mainwindow.hpp index ee9d388..f061af7 100644 --- a/appl/research/mainwindow.hpp +++ b/appl/research/mainwindow.hpp @@ -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" where m_filenames[no] contains the filename + QStringList m_filenames; }; #endif // MAINWINDOW_H diff --git a/appl/research/mainwindow.ui b/appl/research/mainwindow.ui index 10db55d..e1b4264 100644 --- a/appl/research/mainwindow.ui +++ b/appl/research/mainwindow.ui @@ -448,9 +448,24 @@ If the checkbox "inverse search" is checked a file is found only if th + + QAbstractItemView::AllEditTriggers + + + QAbstractItemView::MultiSelection + + + QAbstractItemView::SelectRows + + + true + true + + false + Name @@ -679,17 +694,17 @@ If the checkbox "inverse search" is checked a file is found only if th - Filename with path + Placeholder - Filename without path + Filename with path - Placeholder + Filename without path @@ -896,6 +911,23 @@ If the checkbox "inverse search" is checked a file is found only if th + + + + + + + + + : + + + + + + + + diff --git a/appl/research/research.hpp b/appl/research/research.hpp index 08f3f0c..e264f88 100644 --- a/appl/research/research.hpp +++ b/appl/research/research.hpp @@ -18,9 +18,9 @@ enum ColumnFiles { }; enum PrefixMode { + pmPlaceholder, pmFull, pmNode, - pmPlaceholder, pmNone, };