From: Hamatoma Date: Thu, 1 Dec 2016 23:05:40 +0000 (+0100) Subject: ReSearch: placeholder as prefix X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=008e8662ca5cedbf8c88fa5934a871f0e53ee43f;p=reqt ReSearch: placeholder as prefix --- diff --git a/appl/research/filefilter.cpp b/appl/research/filefilter.cpp index adccf56..6813450 100644 --- a/appl/research/filefilter.cpp +++ b/appl/research/filefilter.cpp @@ -11,14 +11,18 @@ FileFilter::FileFilter(QTableWidget &table, QListWidget &list, FileCache& cache, m_table(table), m_list(list), m_cache(cache), - m_includeExpr(), - m_excludeExpr(), + m_includeExpr(NULL), + m_excludeExpr(NULL), + m_blockStartExpr(NULL), + m_blockEndExpr(NULL), + m_singleBlock(false), m_caseSensitive(false), m_fromHit(0), m_toHit(0), m_linesAbove(0), m_linesBelow(0), - m_lastHitPosition(lastHitPosition) + m_lastHitPosition(lastHitPosition), + m_prefixMode(pmNone) { } @@ -47,7 +51,9 @@ void FileFilter::filter(const QString &includePattern, const QString &excludePattern, int fromHit, int pageSize, int linesAbove, int linesBelow, - bool caseSensitive) + bool caseSensitive, PrefixMode prefixMode, + const QString& blockStart, const QString& blockEnd, + bool singleBlock) { int ixFile = -1; int hitNo = 0; @@ -57,22 +63,32 @@ void FileFilter::filter(const QString &includePattern, m_toHit = fromHit + pageSize - 1; m_linesAbove = linesAbove; m_linesBelow = linesBelow; + m_prefixMode = prefixMode; + m_singleBlock = singleBlock; + delete m_includeExpr; delete m_excludeExpr; + delete m_blockStartExpr; + delete m_blockEndExpr; 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); + QString full; + QString node; + int hitFileNo = -1; while (ixFile < fileCount - 1 && hitNo < m_toHit){ ++ixFile; - QString full = m_table.item(ixFile, colPath)->text(); + full = m_table.item(ixFile, colPath)->text(); full += OS_SEPARATOR_STR; - full += m_table.item(ixFile, colNode)->text(); + node = m_table.item(ixFile, colNode)->text(); + full += node; - hitNo = filterOneFile(full, hitNo); + hitNo = filterOneFile(full, node, hitNo, hitFileNo); } if (hitNo <= fromHit) m_lastHitPosition.m_hitCount = 0; @@ -85,10 +101,14 @@ void FileFilter::filter(const QString &includePattern, * Filters the lines of one file. * * @param filename filename with path + * @param node filename without path * @param lastHit the last found hit in the previous files - * @return the number of hits including the hits in the file + * @param hitFileNo IN/OUT: The files with hits are numbered. This is + * the current number + * @return the number of hits including the hits in the file */ -int FileFilter::filterOneFile(const QString& filename, int lastHit) +int FileFilter::filterOneFile(const QString& filename, const QString& node, + int lastHit, int& hitFileNo) { m_cache.addOrUpdate(filename); const QStringList& lines = m_cache.lines(filename); @@ -96,7 +116,19 @@ int FileFilter::filterOneFile(const QString& filename, int lastHit) int lineNo = -1; int lastLine = -1; int lastIx = lines.size() - 1; - QString prefixHit = filename + "-"; + QString prefixHit; + switch(m_prefixMode){ + case pmFull: + prefixHit = filename + "-"; + break; + case pmNode: + prefixHit = node + '-'; + break; + case pmNone: + case pmPlaceholder: + default: + break; + } QString prefixOther = prefixHit; if (m_linesAbove + m_linesBelow > 0){ prefixHit = ">" + prefixHit; @@ -110,6 +142,7 @@ int FileFilter::filterOneFile(const QString& filename, int lastHit) lastHit = m_lastHitPosition.m_hitNo; lineNo = m_lastHitPosition.m_line; } + int firstHitFile = true; while(lastHit < m_toHit && lineNo < lastIx){ QString line = lines[++lineNo]; if (m_includeExpr != NULL && ! m_includeExpr->match(line).hasMatch()) @@ -125,6 +158,10 @@ int FileFilter::filterOneFile(const QString& filename, int lastHit) if (m_lastHitPosition.m_hitNo > m_lastHitPosition.m_maxHitNo) m_lastHitPosition.m_maxHitNo = m_lastHitPosition.m_hitNo; if (lastHit >= m_fromHit){ + if (firstHitFile && m_prefixMode == pmPlaceholder){ + firstHitFile = false; + prefixHit = ReQStringUtils::numberToName(++hitFileNo) + '-'; + } for (int ix = max(lastLine + 1, max(0, lineNo - m_linesAbove)); ix <= min(lineNo + m_linesBelow, lastIx); ix++){ diff --git a/appl/research/filefilter.hpp b/appl/research/filefilter.hpp index a86dc2c..4b4dfe8 100644 --- a/appl/research/filefilter.hpp +++ b/appl/research/filefilter.hpp @@ -28,21 +28,29 @@ public: public: void filter(const QString& includePattern, const QString& excludePattern, int fromHit, int toHit, int linesAbove, int linesBelow, - bool caseSensitive); + bool caseSensitive, PrefixMode prefixMode, + const QString& blockStart, const QString& blockEnd, + bool singleBlock); + private: - int filterOneFile(const QString &filename, int lastHit); + int filterOneFile(const QString &filename, const QString& node, int lastHit, + int& hitFileNo); private: QTableWidget& m_table; QListWidget& m_list; FileCache& m_cache; QRegularExpression* m_includeExpr; QRegularExpression* m_excludeExpr; + QRegularExpression* m_blockStartExpr; + QRegularExpression* m_blockEndExpr; + bool m_singleBlock; bool m_caseSensitive; int m_fromHit; int m_toHit; int m_linesAbove; int m_linesBelow; HitPosition& m_lastHitPosition; + PrefixMode m_prefixMode; }; #endif // FILEFILTER_H diff --git a/appl/research/main.cpp b/appl/research/main.cpp index 8e26a2f..b5d69e3 100644 --- a/appl/research/main.cpp +++ b/appl/research/main.cpp @@ -1,11 +1,51 @@ #include "research.hpp" #include "mainwindow.hpp" char** g_argv; +void usage(const QString& error){ + printf("%s\n", (QObject::tr("Usage: %1").arg(" research [] []")).toLocal8Bit().data()); + printf(":\n"); + printf(" -d %s\n", QObject::tr("Sets the base directory").toLocal8Bit().data()); + printf(" -f %s\n", QObject::tr("Sets the file patterns").toLocal8Bit().data()); + printf("%s\n", QObject::tr("Examples:").toLocal8Bit().data()); + printf("research -d /home -f \"*.cpp;*.hpp;-*test*\"\n"); + printf("research -d d:\\dev\\sources -f \"*.cpp;*.hpp;-*test*\"\n"); + printf("%s\n", error.toLocal8Bit().data()); + exit(1); +} + int main(int argc, char* argv[]) { g_argv = argv; + const char* baseDirectory = NULL; + const char* filePatterns = NULL; + + while (argc > 1 && argv[1][0] == '-'){ + switch(argv[1][1]){ + case 'd': + if (argc < 3) + usage(QObject::tr("missing base directory")); + baseDirectory = argv[2]; + --argc; + ++argv; + break; + case 'f': + if (argc < 3) + usage(QObject::tr("missing base directory")); + filePatterns = argv[2]; + --argc; + ++argv; + break; + default: + usage(QObject::tr("unknown option: %1").arg(argv[1])); + break; + } + --argc; + ++argv; + } QString homeDir = argc > 1 ? argv[1] : ""; QApplication a(argc, argv); - MainWindow w(a, homeDir); + MainWindow w(a, homeDir, + baseDirectory == NULL ? QString("") : QString::fromLocal8Bit(baseDirectory), + filePatterns == NULL ? QString("") : QString::fromLocal8Bit(filePatterns)); w.show(); return a.exec(); } diff --git a/appl/research/mainwindow.cpp b/appl/research/mainwindow.cpp index 4b345dd..435c32a 100644 --- a/appl/research/mainwindow.cpp +++ b/appl/research/mainwindow.cpp @@ -9,7 +9,9 @@ static const char* VERSION = "2016.11.26"; static const int s_defaultPageSize = 10; MainWindow::MainWindow(QApplication& application, const QString& homeDir, - QWidget *parent) : + const QString& baseDirectory, + const QString& filePatterns, + QWidget *parent) : ReGuiApplication(application, "rsearch", homeDir, 2, 10100100, "de", parent), ReGuiValidator(), ui(new Ui::MainWindow), @@ -23,6 +25,10 @@ MainWindow::MainWindow(QApplication& application, const QString& homeDir, ReComboBox::setDefaultHistorySize(20); m_timer->setSingleShot(true); initializeGui(); + if (! baseDirectory.isEmpty()) + ui->comboBoxBaseDirectory->setCurrentText(baseDirectory); + if (! filePatterns.isEmpty()) + ui->comboBoxFilePatterns->setCurrentText(filePatterns); } /** @@ -106,9 +112,6 @@ void MainWindow::initializeGui(){ ui->tableWidget->setColumnWidth(colDate, 175); switchFilter(true); if (m_test){ - //ui->comboBoxBaseDirectory->setCurrentText("/home/mhm"); - //ui->comboBoxFilePatterns->setCurrentText("pflege.odt"); - onAdd(); } } @@ -224,7 +227,11 @@ void MainWindow::onFilter() ui->pushButtonFilter->setEnabled(false); filter.filter(ui->comboBoxIncludingPattern->currentText(), ui->comboBoxExcludingPattern->currentText(), - from, pageSize, above, below, false); + from, pageSize, above, below, false, + (PrefixMode) ui->comboBoxPrefixMode->currentIndex(), + ui->comboBoxStartPattern->currentText(), + ui->comboBoxEndPattern->currentText(), + ui->checkBoxSingleBlock->isChecked()); switchFilter(false); int found = pageSize; if (m_lastHitPosition->m_hitCount >= 0 diff --git a/appl/research/mainwindow.hpp b/appl/research/mainwindow.hpp index 8050657..ee9d388 100644 --- a/appl/research/mainwindow.hpp +++ b/appl/research/mainwindow.hpp @@ -26,7 +26,9 @@ public: public: explicit MainWindow(QApplication& application, const QString& homeDir, - QWidget *parent = 0); + const QString& baseDirectory, + const QString& filePatterns, + QWidget *parent = 0); ~MainWindow(); public: virtual bool say(ReLoggerLevel level, const QString& message); diff --git a/appl/research/mainwindow.ui b/appl/research/mainwindow.ui index 8cae060..10db55d 100644 --- a/appl/research/mainwindow.ui +++ b/appl/research/mainwindow.ui @@ -556,63 +556,204 @@ If the checkbox "inverse search" is checked a file is found only if th Options - + + + + + QLayout::SetMaximumSize + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Lines above: + + + + + + + + 0 + 0 + + + + + 175 + 16777215 + + + + true + + + 0 + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Lines below: + + + + + + + + 0 + 0 + + + + + 175 + 16777215 + + + + true + + + 0 + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Prefix: + + + + + + + + 0 + 0 + + + + + 175 + 16777215 + + + + + Filename with path + + + + + Filename without path + + + + + Placeholder + + + + + No filename + + + + + + + + + + + Block + + + + + + Start pattern: + + + + + + + true + + + + + + + End pattern: + + + + + + + true + + + + + + + + Block Options + + - 11 - 11 - 321 - 38 + 20 + 20 + 171 + 25 - - - - - Lines above: - - - - - - - - 50 - 16777215 - - - - true - - - 0 - - - - - - - Lines below: - - - - - - - - 50 - 16777215 - - - - true - - - 0 - - - - + + A single block only + @@ -757,11 +898,6 @@ If the checkbox "inverse search" is checked a file is found only if th - - - Block - - diff --git a/appl/research/research.hpp b/appl/research/research.hpp index 5c94a62..08f3f0c 100644 --- a/appl/research/research.hpp +++ b/appl/research/research.hpp @@ -10,10 +10,6 @@ #define RESEARCH_HPP #include "base/rebase.hpp" #include "gui/regui.hpp" -#include "filefinder.hpp" -#include "filecache.hpp" -#include "filefilter.hpp" - enum ColumnFiles { colNode = 0, colSize, @@ -21,5 +17,15 @@ enum ColumnFiles { colPath }; +enum PrefixMode { + pmFull, + pmNode, + pmPlaceholder, + pmNone, +}; + +#include "filefinder.hpp" +#include "filecache.hpp" +#include "filefilter.hpp" #endif // RESEARCH_HPP diff --git a/base/ReQStringUtils.cpp b/base/ReQStringUtils.cpp index bd60ebd..9e24d3c 100644 --- a/base/ReQStringUtils.cpp +++ b/base/ReQStringUtils.cpp @@ -502,6 +502,28 @@ 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. + * + * @param number the number to convert + * @return the name which is unique to the number + */ +QString ReQStringUtils::numberToName(int number){ + QString rc; + if (number < 0){ + number = -number; + rc = '_'; + } + do { + QChar cc('A' + number % 26); + number /= 26; + rc.insert(0, cc); + } while(number > 0); + return rc; +} + /** * Returns a readable string for a duration given by milliseconds. * diff --git a/base/ReQStringUtils.hpp b/base/ReQStringUtils.hpp index 9c44209..0c2aeac 100644 --- a/base/ReQStringUtils.hpp +++ b/base/ReQStringUtils.hpp @@ -73,6 +73,7 @@ public: uint* pValue = NULL); static QString longestPrefix(const QStringList& list); static bool match(const QString& heap, const QStringList& needles); + static QString numberToName(int number); /** * Returns the path with native path separators. * @@ -108,7 +109,7 @@ public: static char* utf8(const ReString& source, char buffer[], size_t bufferSize); public: static const QStringList m_emptyList; - static const QString m_empty; + static const QString m_empty; }; /**