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
This commit is contained in:
Maksim Derbasov 2019-11-04 09:10:31 +03:00 committed by Daniel Marjamäki
parent acd2a92efc
commit afe59531c7
3 changed files with 101 additions and 48 deletions

View File

@ -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<unsigned int>(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,7 +85,7 @@ 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)) {
if (mVersionRe.exactMatch(line)) {
const QString version = line.mid(0, 4);
if (versions.indexOf(version) < 0)
versions << version;
@ -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,7 +215,7 @@ 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(":");
@ -217,16 +224,18 @@ void MainWindow::showResult(QListWidgetItem *item)
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();

View File

@ -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

View File

@ -15,8 +15,14 @@
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>1</number>
</property>
<item>
<layout class="QVBoxLayout" name="middleLayout">
<property name="spacing">
<number>1</number>
</property>
<item>
<widget class="CodeEditor" name="code">
<property name="readOnly">
@ -25,7 +31,10 @@
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="urlFileLayout">
<property name="spacing">
<number>1</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="urllabel">
<property name="text">
@ -34,7 +43,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="edit1"/>
<widget class="QLineEdit" name="urlEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="filelabel">
@ -44,7 +53,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="edit2"/>
<widget class="QLineEdit" name="fileEdit"/>
</item>
</layout>
</item>
@ -71,12 +80,21 @@
<attribute name="dockWidgetArea">
<number>1</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents">
<widget class="QWidget" name="leftDockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>1</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="leftDockVerticalLayout">
<property name="spacing">
<number>1</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QHBoxLayout" name="loadLayout">
<property name="spacing">
<number>1</number>
</property>
<item>
<widget class="QPushButton" name="loadFile">
<property name="text">
@ -117,7 +135,10 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<layout class="QHBoxLayout" name="versionLayout">
<property name="spacing">
<number>1</number>
</property>
<item>
<widget class="QLabel" name="versionLabel">
<property name="text">
@ -165,14 +186,23 @@
<attribute name="dockWidgetArea">
<number>2</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents_5">
<widget class="QWidget" name="rightDockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing">
<number>1</number>
</property>
<item>
<layout class="QVBoxLayout" name="filesNavigatorLayout">
<property name="spacing">
<number>1</number>
</property>
<item>
<layout class="QHBoxLayout" name="filterLayout">
<property name="spacing">
<number>1</number>
</property>
<item>
<widget class="QLineEdit" name="lineEdit">
<widget class="QLineEdit" name="filterEdit">
<property name="maximumSize">
<size>
<width>16777215</width>
@ -212,6 +242,9 @@
<string>Filesystem</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="spacing">
<number>1</number>
</property>
<item>
<widget class="QTreeView" name="directoryTree">
<property name="sizePolicy">
@ -241,6 +274,9 @@
<string>In Files Result</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_6">
<property name="spacing">
<number>1</number>
</property>
<item>
<widget class="QListWidget" name="inFilesResult">
<property name="sizePolicy">
@ -253,6 +289,9 @@
</item>
<item>
<layout class="QHBoxLayout" name="fileFilterLayout">
<property name="spacing">
<number>1</number>
</property>
<item>
<widget class="QCheckBox" name="hFilesFilter">
<property name="text">
@ -264,7 +303,7 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="srcFilter">
<widget class="QCheckBox" name="srcFilesFilter">
<property name="text">
<string>*.c, *.cpp,...</string>
</property>
@ -296,7 +335,7 @@
<resources/>
<connections>
<connection>
<sender>lineEdit</sender>
<sender>filterEdit</sender>
<signal>textChanged(QString)</signal>
<receiver>MainWindow</receiver>
<slot>fileTreeFilter(QString)</slot>