From fcce43fb8d8c26b5e93bdc1aa824b033d022c56f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 30 Jul 2017 00:13:00 +0200 Subject: [PATCH] GUI: reopen project after restart. If build dir is specified the last results will also be shown. --- gui/common.h | 1 + gui/mainwindow.cpp | 38 +++++++++++++++++++++++++++++++++++--- gui/resultstree.cpp | 4 ++-- gui/resultsview.cpp | 15 +++++++++++++++ gui/resultsview.h | 7 +++++++ 5 files changed, 60 insertions(+), 5 deletions(-) diff --git a/gui/common.h b/gui/common.h index 958456054..f98e3a68a 100644 --- a/gui/common.h +++ b/gui/common.h @@ -85,6 +85,7 @@ #define SETTINGS_MRU_PROJECTS "MRU Projects" #define SETTINGS_SHOW_ERROR_ID "Show error Id" #define SETTINGS_SHOW_STATISTICS "Show statistics" +#define SETTINGS_OPEN_PROJECT "Open Project" // The maximum value for the progress bar #define PROGRESS_MAX 1024.0 diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index ca0d93974..86a4b1032 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -139,7 +139,10 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : loadSettings(); mThread->initialize(mUI.mResults); - formatAndSetTitle(); + if (mProject) + formatAndSetTitle(tr("Project:") + ' ' + mProject->getFilename()); + else + formatAndSetTitle(); enableCheckButtons(true); @@ -172,6 +175,9 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : handleCLIParams(args); } + mUI.mActionCloseProjectFile->setEnabled(mProject != nullptr); + mUI.mActionEditProjectFile->setEnabled(mProject != nullptr); + for (int i = 0; i < mPlatforms.getCount(); i++) { Platform plat = mPlatforms.mPlatforms[i]; QAction *act = new QAction(this); @@ -310,9 +316,23 @@ void MainWindow::loadSettings() QMessageBox::Ok, this); msgBox.exec(); - } + const QString project = mSettings->value(SETTINGS_OPEN_PROJECT, QString()).toString(); + if (!project.isEmpty() && QCoreApplication::arguments().size()==1) { + QFileInfo inf(project); + if (inf.exists() && inf.isReadable()) { + delete mProject; + mProject = new Project(project, this); + mProject->open(); + if (!mProject->getProjectFile()->getBuildDir().isEmpty()) { + const QString buildDir = QFileInfo(project).absolutePath() + '/' + mProject->getProjectFile()->getBuildDir(); + const QString lastResults = buildDir + "/lastResults.xml"; + if (QFileInfo(lastResults).exists()) + mUI.mResults->readErrorsXml(lastResults); + } + } + } } void MainWindow::saveSettings() const @@ -352,6 +372,9 @@ void MainWindow::saveSettings() const mApplications->saveSettings(); mSettings->setValue(SETTINGS_LANGUAGE, mTranslation->getCurrentLanguage()); + + mSettings->setValue(SETTINGS_OPEN_PROJECT, mProject ? mProject->getFilename() : QString()); + mUI.mResults->saveSettings(mSettings); } @@ -852,6 +875,15 @@ void MainWindow::checkDone() if (mScratchPad) mScratchPad->setEnabled(true); + if (mProject && !mProject->getProjectFile()->getBuildDir().isEmpty()) { + const QString prjpath = QFileInfo(mProject->getProjectFile()->getFilename()).absolutePath(); + const QString buildDir = prjpath + '/' + mProject->getProjectFile()->getBuildDir(); + if (QDir(buildDir).exists()) { + mUI.mResults->saveStatistics(buildDir + "/statistics.txt"); + mUI.mResults->save(buildDir + "/lastResults.xml", Report::XMLV2); + } + } + if (mUI.mResults->hasResults()) { mUI.mActionClearResults->setEnabled(true); mUI.mActionSave->setEnabled(true); @@ -1293,7 +1325,7 @@ void MainWindow::loadProjectFile(const QString &filePath) { QFileInfo inf(filePath); const QString filename = inf.fileName(); - formatAndSetTitle(tr("Project:") + QString(" ") + filename); + formatAndSetTitle(tr("Project:") + ' ' + filename); addProjectMRU(filePath); mIsLogfileLoaded = false; diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index e5824886e..632fed0c4 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -968,8 +968,8 @@ void ResultsTree::saveResults(Report *report) const for (int i = 0; i < mModel.rowCount(); i++) { QStandardItem *item = mModel.item(i, 0); - if (!isRowHidden(i, QModelIndex())) - saveErrors(report, item); + //if (!isRowHidden(i, QModelIndex())) + saveErrors(report, item); } report->writeFooter(); diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 2b433b958..3ad749ea0 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "common.h" #include "erroritem.h" #include "resultsview.h" @@ -134,6 +135,20 @@ void ResultsView::filterResults(const QString& filter) mUI.mTree->filterResults(filter); } +void ResultsView::saveStatistics(const QString &filename) const +{ + QFile f(filename); + if (!f.open(QIODevice::Text | QIODevice::Append)) + return; + QTextStream ts(&f); + ts << '[' << QDate::currentDate().toString("dd.MM.yyyy") << "]\n"; + ts << "error:" << mStatistics->getCount(ShowTypes::ShowErrors) << '\n'; + ts << "warning:" << mStatistics->getCount(ShowTypes::ShowWarnings) << '\n'; + ts << "style:" << mStatistics->getCount(ShowTypes::ShowStyle) << '\n'; + ts << "performance:" << mStatistics->getCount(ShowTypes::ShowPerformance) << '\n'; + ts << "portability:" << mStatistics->getCount(ShowTypes::ShowPortability) << '\n'; +} + void ResultsView::save(const QString &filename, Report::Type type) const { if (!hasResults()) { diff --git a/gui/resultsview.h b/gui/resultsview.h index 4c549afd6..750017e14 100644 --- a/gui/resultsview.h +++ b/gui/resultsview.h @@ -73,6 +73,13 @@ public: */ void clearRecheckFile(const QString &filename); + /** + * @brief Write statistics in file + * + * @param filename Filename to save statistics to + */ + void saveStatistics(const QString &filename) const; + /** * @brief Save results to a file *