Fixed #8169 (GUI: Show checking log in mainwindow)

This commit is contained in:
Daniel Marjamäki 2017-08-19 22:55:13 +02:00
parent 330ceccdc9
commit f6184bba0d
13 changed files with 94 additions and 253 deletions

View File

@ -51,7 +51,6 @@ RESOURCES = gui.qrc
FORMS = about.ui \ FORMS = about.ui \
application.ui \ application.ui \
file.ui \ file.ui \
logview.ui \
mainwindow.ui \ mainwindow.ui \
projectfiledialog.ui \ projectfiledialog.ui \
resultsview.ui \ resultsview.ui \
@ -95,7 +94,6 @@ HEADERS += aboutdialog.h \
erroritem.h \ erroritem.h \
filelist.h \ filelist.h \
fileviewdialog.h \ fileviewdialog.h \
logview.h \
mainwindow.h \ mainwindow.h \
platforms.h \ platforms.h \
printablereport.h \ printablereport.h \
@ -130,7 +128,6 @@ SOURCES += aboutdialog.cpp \
erroritem.cpp \ erroritem.cpp \
filelist.cpp \ filelist.cpp \
fileviewdialog.cpp \ fileviewdialog.cpp \
logview.cpp \
main.cpp \ main.cpp \
mainwindow.cpp\ mainwindow.cpp\
platforms.cpp \ platforms.cpp \

View File

@ -1,81 +0,0 @@
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2016 Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QFile>
#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>
#include <QTextStream>
#include <QPushButton>
#include "common.h"
#include "logview.h"
LogView::LogView(QWidget *parent)
: QWidget(parent)
{
mUI.setupUi(this);
setWindowFlags(Qt::Tool);
mUI.mButtonBox->button(QDialogButtonBox::Reset)->setText(tr("Clear"));
connect(mUI.mButtonBox->button(QDialogButtonBox::Close), SIGNAL(clicked()), this, SLOT(closeButtonClicked()));
connect(mUI.mButtonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()), this, SLOT(clearButtonClicked()));
connect(mUI.mButtonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()), this, SLOT(saveButtonClicked()));
QSettings settings;
resize(settings.value(SETTINGS_LOG_VIEW_WIDTH, 400).toInt(),
settings.value(SETTINGS_LOG_VIEW_HEIGHT, 300).toInt());
}
LogView::~LogView()
{
QSettings settings;
settings.setValue(SETTINGS_LOG_VIEW_WIDTH, size().width());
settings.setValue(SETTINGS_LOG_VIEW_HEIGHT, size().height());
}
void LogView::appendLine(const QString &line)
{
mUI.mLogEdit->appendPlainText(line);
}
void LogView::closeButtonClicked()
{
close();
}
void LogView::clearButtonClicked()
{
mUI.mLogEdit->clear();
}
void LogView::saveButtonClicked()
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Log"),
QString(), tr("Text files (*.txt *.log);;All files (*.*)"));
if (!fileName.isEmpty()) {
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QMessageBox::warning(this, tr("Cppcheck"),
tr("Could not open file for writing: \"%1\"").arg(fileName));
return;
}
QTextStream out(&file);
out << mUI.mLogEdit->toPlainText();
}
}

View File

@ -1,71 +0,0 @@
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2016 Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LOGVIEW_H
#define LOGVIEW_H
#include <QWidget>
#include "ui_logview.h"
/// @addtogroup GUI
/// @{
/**
* @brief A tool window that shows checking log.
*
*/
class LogView : public QWidget {
Q_OBJECT
public:
explicit LogView(QWidget *parent = 0);
~LogView();
/**
* @brief Append new log file to view.
* @param line String to add.
*
*/
void appendLine(const QString &line);
protected slots:
/**
* @brief Called when close button is clicked.
*
*/
void closeButtonClicked();
/**
* @brief Called when clear button is clicked.
*
*/
void clearButtonClicked();
/**
* @brief Called when save button is clicked.
*
*/
void saveButtonClicked();
private:
Ui::LogView mUI;
};
/// @}
#endif // LOGVIEW_H

View File

@ -1,41 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LogView</class>
<widget class="QWidget" name="LogView">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="windowTitle">
<string>Checking Log</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPlainTextEdit" name="mLogEdit">
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="mButtonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Close|QDialogButtonBox::Reset|QDialogButtonBox::Save</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -42,7 +42,6 @@
#include "settingsdialog.h" #include "settingsdialog.h"
#include "threadresult.h" #include "threadresult.h"
#include "translationhandler.h" #include "translationhandler.h"
#include "logview.h"
#include "filelist.h" #include "filelist.h"
#include "showtypes.h" #include "showtypes.h"
#include "librarydialog.h" #include "librarydialog.h"
@ -54,7 +53,6 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
mSettings(settings), mSettings(settings),
mApplications(new ApplicationList(this)), mApplications(new ApplicationList(this)),
mTranslation(th), mTranslation(th),
mLogView(nullptr),
mScratchPad(nullptr), mScratchPad(nullptr),
mProjectFile(nullptr), mProjectFile(nullptr),
mPlatformActions(new QActionGroup(this)), mPlatformActions(new QActionGroup(this)),
@ -102,7 +100,6 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
connect(mUI.mActionCollapseAll, &QAction::triggered, mUI.mResults, &ResultsView::collapseAllResults); connect(mUI.mActionCollapseAll, &QAction::triggered, mUI.mResults, &ResultsView::collapseAllResults);
connect(mUI.mActionExpandAll, &QAction::triggered, mUI.mResults, &ResultsView::expandAllResults); connect(mUI.mActionExpandAll, &QAction::triggered, mUI.mResults, &ResultsView::expandAllResults);
connect(mUI.mActionShowHidden, &QAction::triggered, mUI.mResults, &ResultsView::showHiddenResults); connect(mUI.mActionShowHidden, &QAction::triggered, mUI.mResults, &ResultsView::showHiddenResults);
connect(mUI.mActionViewLog, &QAction::triggered, this, &MainWindow::showLogView);
connect(mUI.mActionViewStats, &QAction::triggered, this, &MainWindow::showStatistics); connect(mUI.mActionViewStats, &QAction::triggered, this, &MainWindow::showStatistics);
connect(mUI.mActionLibraryEditor, &QAction::triggered, this, &MainWindow::showLibraryEditor); connect(mUI.mActionLibraryEditor, &QAction::triggered, this, &MainWindow::showLibraryEditor);
@ -123,6 +120,8 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
connect(mUI.mActionAuthors, &QAction::triggered, this, &MainWindow::showAuthors); connect(mUI.mActionAuthors, &QAction::triggered, this, &MainWindow::showAuthors);
connect(mThread, &ThreadHandler::done, this, &MainWindow::analysisDone); connect(mThread, &ThreadHandler::done, this, &MainWindow::analysisDone);
connect(mThread, &ThreadHandler::log, mUI.mResults, &ResultsView::log);
connect(mThread, &ThreadHandler::debugError, mUI.mResults, &ResultsView::debugError);
connect(mUI.mResults, &ResultsView::gotResults, this, &MainWindow::resultsAdded); connect(mUI.mResults, &ResultsView::gotResults, this, &MainWindow::resultsAdded);
connect(mUI.mResults, &ResultsView::resultsHidden, mUI.mActionShowHidden, &QAction::setEnabled); connect(mUI.mResults, &ResultsView::resultsHidden, mUI.mActionShowHidden, &QAction::setEnabled);
connect(mUI.mResults, &ResultsView::checkSelected, this, &MainWindow::performSelectedFilesCheck); connect(mUI.mResults, &ResultsView::checkSelected, this, &MainWindow::performSelectedFilesCheck);
@ -217,7 +216,6 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
delete mLogView;
delete mProjectFile; delete mProjectFile;
delete mScratchPad; delete mScratchPad;
} }
@ -1313,8 +1311,6 @@ void MainWindow::setLanguage(const QString &code)
//Translate everything that is visible here //Translate everything that is visible here
mUI.retranslateUi(this); mUI.retranslateUi(this);
mUI.mResults->translate(); mUI.mResults->translate();
delete mLogView;
mLogView = 0;
} }
} }
@ -1536,16 +1532,6 @@ void MainWindow::editProjectFile()
} }
} }
void MainWindow::showLogView()
{
if (mLogView == nullptr)
mLogView = new LogView;
mLogView->show();
if (!mLogView->isActiveWindow())
mLogView->activateWindow();
}
void MainWindow::showStatistics() void MainWindow::showStatistics()
{ {
StatsDialog statsDialog(this); StatsDialog statsDialog(this);
@ -1566,20 +1552,6 @@ void MainWindow::showLibraryEditor()
libraryDialog.exec(); libraryDialog.exec();
} }
void MainWindow::log(const QString &logline)
{
if (mLogView) {
mLogView->appendLine(logline);
}
}
void MainWindow::debugError(const ErrorItem &item)
{
if (mLogView) {
mLogView->appendLine(item.ToString());
}
}
void MainWindow::filterResults() void MainWindow::filterResults()
{ {
mUI.mResults->filterResults(mLineEditFilter->text()); mUI.mResults->filterResults(mLineEditFilter->text());

View File

@ -33,7 +33,6 @@
class ThreadHandler; class ThreadHandler;
class TranslationHandler; class TranslationHandler;
class ScratchPad; class ScratchPad;
class LogView;
class ProjectFile; class ProjectFile;
class ErrorItem; class ErrorItem;
class QAction; class QAction;
@ -168,9 +167,6 @@ public slots:
/** @brief Slot to edit project file. */ /** @brief Slot to edit project file. */
void editProjectFile(); void editProjectFile();
/** @brief Slot for showing the log view. */
void showLogView();
/** @brief Slot for showing the scan and project statistics. */ /** @brief Slot for showing the scan and project statistics. */
void showStatistics(); void showStatistics();
@ -206,12 +202,6 @@ protected slots:
/** @brief Open help file contents */ /** @brief Open help file contents */
void openHelpContents(); void openHelpContents();
/** @brief Add new line to log. */
void log(const QString &logline);
/** @brief Handle new debug error. */
void debugError(const ErrorItem &item);
/** @brief Filters the results in the result list. */ /** @brief Filters the results in the result list. */
void filterResults(); void filterResults();
@ -414,9 +404,6 @@ private:
/** @brief Current analyzed directory. */ /** @brief Current analyzed directory. */
QString mCurrentDirectory; QString mCurrentDirectory;
/** @brief Log view. */
LogView *mLogView;
/** @brief Scratchpad. */ /** @brief Scratchpad. */
ScratchPad* mScratchPad; ScratchPad* mScratchPad;

View File

@ -113,7 +113,6 @@
<addaction name="mActionShowHidden"/> <addaction name="mActionShowHidden"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="mActionShowScratchpad"/> <addaction name="mActionShowScratchpad"/>
<addaction name="mActionViewLog"/>
<addaction name="mActionViewStats"/> <addaction name="mActionViewStats"/>
<addaction name="mActionLibraryEditor"/> <addaction name="mActionLibraryEditor"/>
</widget> </widget>

View File

@ -635,13 +635,17 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
{ {
QAction *action = new QAction(tr("No tag"), tagMenu); QAction *action = new QAction(tr("No tag"), tagMenu);
tagMenu->addAction(action); tagMenu->addAction(action);
connect(action, &QAction::triggered, [=](){ tagSelectedItems(QString()); }); connect(action, &QAction::triggered, [=]() {
tagSelectedItems(QString());
});
} }
foreach (const QString tagstr, mTags) { foreach (const QString tagstr, mTags) {
QAction *action = new QAction(tagstr, tagMenu); QAction *action = new QAction(tagstr, tagMenu);
tagMenu->addAction(action); tagMenu->addAction(action);
connect(action, &QAction::triggered, [=](){ tagSelectedItems(tagstr); }); connect(action, &QAction::triggered, [=]() {
tagSelectedItems(tagstr);
});
} }
} }
} }

View File

@ -406,3 +406,13 @@ void ResultsView::updateDetails(const QModelIndex &index)
formattedMsg.prepend(tr("Id") + ": " + data["id"].toString() + "\n"); formattedMsg.prepend(tr("Id") + ": " + data["id"].toString() + "\n");
mUI.mDetails->setText(formattedMsg); mUI.mDetails->setText(formattedMsg);
} }
void ResultsView::log(const QString &str)
{
mUI.mListLog->addItem(str);
}
void ResultsView::debugError(const ErrorItem &item)
{
mUI.mListLog->addItem(item.ToString());
}

View File

@ -285,6 +285,16 @@ public slots:
*/ */
void printPreview(); void printPreview();
/**
* \brief Log message
*/
void log(const QString &str);
/**
* \brief debug message
*/
void debugError(const ErrorItem &item);
protected: protected:
/** /**
* @brief Should we show a "No errors found dialog" every time no errors were found? * @brief Should we show a "No errors found dialog" every time no errors were found?

View File

@ -70,6 +70,53 @@
<enum>QAbstractItemView::ExtendedSelection</enum> <enum>QAbstractItemView::ExtendedSelection</enum>
</property> </property>
</widget> </widget>
<widget class="QTabWidget" name="tabWidget">
<property name="tabPosition">
<enum>QTabWidget::South</enum>
</property>
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="mTabLog">
<attribute name="title">
<string>Analysis Log</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QListWidget" name="mListLog"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="mTabDetails">
<attribute name="title">
<string>Warning Details</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTextEdit" name="mDetails"> <widget class="QTextEdit" name="mDetails">
<property name="undoRedoEnabled"> <property name="undoRedoEnabled">
<bool>false</bool> <bool>false</bool>
@ -78,6 +125,10 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item>
</layout>
</widget>
</widget>
</widget> </widget>
</item> </item>
</layout> </layout>

View File

@ -190,11 +190,11 @@ void ThreadHandler::initialize(ResultsView *view)
connect(&mResults, &ThreadResult::error, connect(&mResults, &ThreadResult::error,
view, &ResultsView::error); view, &ResultsView::error);
connect(&mResults, SIGNAL(log(const QString &)), connect(&mResults, &ThreadResult::log,
parent(), SLOT(log(const QString &))); this, &ThreadHandler::log);
connect(&mResults, SIGNAL(debugError(const ErrorItem &)), connect(&mResults, &ThreadResult::debugError,
parent(), SLOT(debugError(const ErrorItem &))); this, &ThreadHandler::debugError);
} }
void ThreadHandler::loadSettings(QSettings &settings) void ThreadHandler::loadSettings(QSettings &settings)

View File

@ -191,6 +191,10 @@ signals:
*/ */
void done(); void done();
void log(const QString &msg);
void debugError(const ErrorItem &item);
public slots: public slots:
/** /**