From afe59531c715185fb8dbdcf4f49dda8f29e3e4f9 Mon Sep 17 00:00:00 2001 From: Maksim Derbasov Date: Mon, 4 Nov 2019 09:10:31 +0300 Subject: [PATCH] Triage cleanup (#2324) * regex for version * fields names improved * codestyle * m prefix for fsmodel * string duplication removed * find in files: show all entries * spaces * added hint to checkboxes; element naming fixed * layout naming improvement * spacing 6->1 --- tools/triage/mainwindow.cpp | 82 +++++++++++++++++++++---------------- tools/triage/mainwindow.h | 6 ++- tools/triage/mainwindow.ui | 61 ++++++++++++++++++++++----- 3 files changed, 101 insertions(+), 48 deletions(-) diff --git a/tools/triage/mainwindow.cpp b/tools/triage/mainwindow.cpp index ef4264779..7457082c4 100644 --- a/tools/triage/mainwindow.cpp +++ b/tools/triage/mainwindow.cpp @@ -19,7 +19,10 @@ const int MAX_ERRORS = 100; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), - ui(new Ui::MainWindow) + ui(new Ui::MainWindow), + mVersionRe("^(your|head|1.[0-9][0-9]) .*"), + hFiles{"*.hpp", "*.h", "*.hxx", "*.hh", "*.tpp", "*.txx"}, + srcFiles{"*.cpp", "*.cxx", "*.cc", "*.c++", "*.C", "*.c", "*.cl"} { ui->setupUi(this); std::srand(static_cast(std::time(Q_NULLPTR))); @@ -27,14 +30,18 @@ MainWindow::MainWindow(QWidget *parent) : if (!workFolder.exists()) { workFolder.mkdir(WORK_FOLDER); } - fsmodel.setRootPath(WORK_FOLDER); - fsmodel.setReadOnly(true); - fsmodel.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); - ui->directoryTree->setModel(&fsmodel); + + mFSmodel.setRootPath(WORK_FOLDER); + mFSmodel.setReadOnly(true); + mFSmodel.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); + ui->directoryTree->setModel(&mFSmodel); QHeaderView * header = ui->directoryTree->header(); - for(int i = 1; i < header->length(); ++i) + for(int i = 1; i < header->length(); ++i) // hide all except [0] header->hideSection(i); - ui->directoryTree->setRootIndex(fsmodel.index(WORK_FOLDER)); + ui->directoryTree->setRootIndex(mFSmodel.index(WORK_FOLDER)); + + ui->hFilesFilter->setToolTip(hFiles.join(',')); + ui->srcFilesFilter->setToolTip(srcFiles.join(',')); } MainWindow::~MainWindow() @@ -78,8 +85,8 @@ void MainWindow::load(QTextStream &textStream) mAllErrors << errorMessage; errorMessage.clear(); } else if (!url.isEmpty() && QRegExp(".*: (error|warning|style|note):.*").exactMatch(line)) { - if (QRegExp("^(head|1.[0-9][0-9]) .*").exactMatch(line)) { - const QString version = line.mid(0,4); + if (mVersionRe.exactMatch(line)) { + const QString version = line.mid(0, 4); if (versions.indexOf(version) < 0) versions << version; } @@ -136,7 +143,7 @@ void MainWindow::filter(QString filter) allErrors.removeAt(i); } std::random_shuffle(allErrors.begin(), allErrors.end()); - ui->results->addItems(allErrors.mid(0,MAX_ERRORS)); + ui->results->addItems(allErrors.mid(0, MAX_ERRORS)); ui->results->sortItems(); } else { ui->results->addItems(allErrors); @@ -170,7 +177,7 @@ bool MainWindow::runProcess(const QString &programName, const QStringList &argum bool MainWindow::wget(const QString &url) { - return runProcess("wget", QStringList() << url); + return runProcess("wget", QStringList{url}); } bool MainWindow::unpackArchive(const QString &archiveName) @@ -208,25 +215,27 @@ void MainWindow::showResult(QListWidgetItem *item) return; const QString url = lines[0]; QString msg = lines[1]; - if (QRegExp("^(head|1.[0-9][0-9]) .*").exactMatch(msg)) + if (mVersionRe.exactMatch(msg)) msg = msg.mid(5); const QString archiveName = url.mid(url.lastIndexOf("/") + 1); const int pos1 = msg.indexOf(":"); const int pos2 = msg.indexOf(":", pos1+1); const QString fileName = WORK_FOLDER + '/' + msg.left(msg.indexOf(":")); - const int lineNumber = msg.midRef(pos1+1,pos2-pos1-1).toInt(); + const int lineNumber = msg.midRef(pos1+1, pos2-pos1-1).toInt(); if (!QFileInfo::exists(fileName)) { - if (QFileInfo::exists(DACA2_PACKAGES + '/' + archiveName.mid(0,archiveName.indexOf(".tar.")) + ".tar.xz")) { - if (!unpackArchive(DACA2_PACKAGES + '/' + archiveName.mid(0,archiveName.indexOf(".tar.")) + ".tar.xz")) + const QString daca2archiveFile {DACA2_PACKAGES + '/' + archiveName.mid(0,archiveName.indexOf(".tar.")) + ".tar.xz"}; + if (QFileInfo::exists(daca2archiveFile)) { + if (!unpackArchive(daca2archiveFile)) return; } else { - if (!QFileInfo::exists(WORK_FOLDER + '/' + archiveName)) { + const QString archiveFullPath {WORK_FOLDER + '/' + archiveName}; + if (!QFileInfo::exists(archiveFullPath)) { // Download archive if (!wget(url)) return; } - if (!unpackArchive(WORK_FOLDER + '/' + archiveName)) + if (!unpackArchive(archiveFullPath)) return; } } @@ -246,31 +255,31 @@ void MainWindow::showSrcFile(const QString &fileName, const QString &url, const QTextStream textStream(&f); const QString fileData = textStream.readAll(); ui->code->setError(fileData, lineNumber, QStringList()); - - ui->edit1->setText(url); - ui->edit2->setText(fileName); f.close(); - ui->directoryTree->setCurrentIndex(fsmodel.index(fileName)); + + ui->urlEdit->setText(url); + ui->fileEdit->setText(fileName); + ui->directoryTree->setCurrentIndex(mFSmodel.index(fileName)); } } -void MainWindow::fileTreeFilter(QString str) { - fsmodel.setNameFilters(QStringList{"*" + str + "*"}); - fsmodel.setNameFilterDisables(false); +void MainWindow::fileTreeFilter(QString str) +{ + mFSmodel.setNameFilters(QStringList{"*" + str + "*"}); + mFSmodel.setNameFilterDisables(false); } -void MainWindow::findInFilesClicked() { +void MainWindow::findInFilesClicked() +{ ui->tabWidget->setCurrentIndex(1); ui->inFilesResult->clear(); - const QString text = ui->lineEdit->text(); + const QString text = ui->filterEdit->text(); QStringList filter; - if(ui->hFilesFilter->isChecked()) { - filter << "*.hpp" << "*.h" << "*.hxx" << "*.hh" << "*.tpp" << "*.txx"; - } - if(ui->srcFilter->isChecked()) { - filter << "*.cpp" << "*.cxx" << "*.cc" << "*.c++" << "*.C" << "*.c" << "*.cl"; - } + if(ui->hFilesFilter->isChecked()) + filter.append(hFiles); + if(ui->srcFilesFilter->isChecked()) + filter.append(srcFiles); QMimeDatabase mimeDatabase; QDirIterator it(WORK_FOLDER, filter, QDir::AllEntries | QDir::NoSymLinks | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); @@ -295,18 +304,19 @@ void MainWindow::findInFilesClicked() { line = in.readLine(); if (line.contains(text, Qt::CaseInsensitive)) { ui->inFilesResult->addItem(fileName.mid(common_path_len) + QString{":"} + QString::number(lineN)); - break; } } } } } -void MainWindow::directorytreeDoubleClick() { - showSrcFile(fsmodel.filePath(ui->directoryTree->currentIndex()), "", 1); +void MainWindow::directorytreeDoubleClick() +{ + showSrcFile(mFSmodel.filePath(ui->directoryTree->currentIndex()), "", 1); } -void MainWindow::searchResultsDoubleClick() { +void MainWindow::searchResultsDoubleClick() +{ QString filename = ui->inFilesResult->currentItem()->text(); const auto idx = filename.lastIndexOf(':'); const int line = filename.midRef(idx + 1).toInt(); diff --git a/tools/triage/mainwindow.h b/tools/triage/mainwindow.h index 32ed901d8..406e857c7 100644 --- a/tools/triage/mainwindow.h +++ b/tools/triage/mainwindow.h @@ -41,7 +41,11 @@ private: void showSrcFile(const QString &fileName, const QString &url, const int lineNumber); QStringList mAllErrors; - QFileSystemModel fsmodel; + QFileSystemModel mFSmodel; + const QRegExp mVersionRe; + + const QStringList hFiles; + const QStringList srcFiles; }; #endif // MAINWINDOW_H diff --git a/tools/triage/mainwindow.ui b/tools/triage/mainwindow.ui index edaffd814..540c48717 100644 --- a/tools/triage/mainwindow.ui +++ b/tools/triage/mainwindow.ui @@ -15,8 +15,14 @@ + + 1 + + + 1 + @@ -25,7 +31,10 @@ - + + + 1 + @@ -34,7 +43,7 @@ - + @@ -44,7 +53,7 @@ - + @@ -71,12 +80,21 @@ 1 - + + + 1 + - + + + 1 + - + + + 1 + @@ -117,7 +135,10 @@ - + + + 1 + @@ -165,14 +186,23 @@ 2 - + + + 1 + + + 1 + + + 1 + - + 16777215 @@ -212,6 +242,9 @@ Filesystem + + 1 + @@ -241,6 +274,9 @@ In Files Result + + 1 + @@ -253,6 +289,9 @@ + + 1 + @@ -264,7 +303,7 @@ - + *.c, *.cpp,... @@ -296,7 +335,7 @@ - lineEdit + filterEdit textChanged(QString) MainWindow fileTreeFilter(QString)