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 \
application.ui \
file.ui \
logview.ui \
mainwindow.ui \
projectfiledialog.ui \
resultsview.ui \
@ -95,7 +94,6 @@ HEADERS += aboutdialog.h \
erroritem.h \
filelist.h \
fileviewdialog.h \
logview.h \
mainwindow.h \
platforms.h \
printablereport.h \
@ -130,7 +128,6 @@ SOURCES += aboutdialog.cpp \
erroritem.cpp \
filelist.cpp \
fileviewdialog.cpp \
logview.cpp \
main.cpp \
mainwindow.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 "threadresult.h"
#include "translationhandler.h"
#include "logview.h"
#include "filelist.h"
#include "showtypes.h"
#include "librarydialog.h"
@ -54,7 +53,6 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
mSettings(settings),
mApplications(new ApplicationList(this)),
mTranslation(th),
mLogView(nullptr),
mScratchPad(nullptr),
mProjectFile(nullptr),
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.mActionExpandAll, &QAction::triggered, mUI.mResults, &ResultsView::expandAllResults);
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.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(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::resultsHidden, mUI.mActionShowHidden, &QAction::setEnabled);
connect(mUI.mResults, &ResultsView::checkSelected, this, &MainWindow::performSelectedFilesCheck);
@ -217,7 +216,6 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
MainWindow::~MainWindow()
{
delete mLogView;
delete mProjectFile;
delete mScratchPad;
}
@ -1313,8 +1311,6 @@ void MainWindow::setLanguage(const QString &code)
//Translate everything that is visible here
mUI.retranslateUi(this);
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()
{
StatsDialog statsDialog(this);
@ -1566,20 +1552,6 @@ void MainWindow::showLibraryEditor()
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()
{
mUI.mResults->filterResults(mLineEditFilter->text());

View File

@ -33,7 +33,6 @@
class ThreadHandler;
class TranslationHandler;
class ScratchPad;
class LogView;
class ProjectFile;
class ErrorItem;
class QAction;
@ -168,9 +167,6 @@ public slots:
/** @brief Slot to edit project file. */
void editProjectFile();
/** @brief Slot for showing the log view. */
void showLogView();
/** @brief Slot for showing the scan and project statistics. */
void showStatistics();
@ -206,12 +202,6 @@ protected slots:
/** @brief Open help file contents */
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. */
void filterResults();
@ -414,9 +404,6 @@ private:
/** @brief Current analyzed directory. */
QString mCurrentDirectory;
/** @brief Log view. */
LogView *mLogView;
/** @brief Scratchpad. */
ScratchPad* mScratchPad;

View File

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

View File

@ -633,15 +633,19 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
menu.addSeparator();
QMenu *tagMenu = menu.addMenu(tr("Tag"));
{
QAction *action = new QAction(tr("No tag"), tagMenu);
tagMenu->addAction(action);
connect(action, &QAction::triggered, [=](){ tagSelectedItems(QString()); });
QAction *action = new QAction(tr("No tag"), tagMenu);
tagMenu->addAction(action);
connect(action, &QAction::triggered, [=]() {
tagSelectedItems(QString());
});
}
foreach (const QString tagstr, mTags) {
QAction *action = new QAction(tagstr, tagMenu);
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");
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();
/**
* \brief Log message
*/
void log(const QString &str);
/**
* \brief debug message
*/
void debugError(const ErrorItem &item);
protected:
/**
* @brief Should we show a "No errors found dialog" every time no errors were found?

View File

@ -70,13 +70,64 @@
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
</widget>
<widget class="QTextEdit" name="mDetails">
<property name="undoRedoEnabled">
<bool>false</bool>
<widget class="QTabWidget" name="tabWidget">
<property name="tabPosition">
<enum>QTabWidget::South</enum>
</property>
<property name="readOnly">
<bool>true</bool>
<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">
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
</item>

View File

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

View File

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