From 7e88d7b41d431d03c37fe6a3ce19e682d5b35dd5 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Fri, 16 Jul 2010 17:48:13 +0300 Subject: [PATCH 1/4] GUI: Add simple log view. Adding a simple log view which shows log messages the core code emits. --- gui/gui.pro | 10 ++++++--- gui/logview.cpp | 30 +++++++++++++++++++++++++ gui/logview.h | 51 +++++++++++++++++++++++++++++++++++++++++++ gui/logview.ui | 34 +++++++++++++++++++++++++++++ gui/main.ui | 9 ++++++++ gui/mainwindow.cpp | 25 ++++++++++++++++++++- gui/mainwindow.h | 18 +++++++++++++++ gui/threadhandler.cpp | 2 ++ gui/threadresult.cpp | 2 +- gui/threadresult.h | 7 ++++++ 10 files changed, 183 insertions(+), 5 deletions(-) create mode 100644 gui/logview.cpp create mode 100644 gui/logview.h create mode 100644 gui/logview.ui diff --git a/gui/gui.pro b/gui/gui.pro index 3e1de7f02..e4215cfe1 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -26,7 +26,8 @@ FORMS = main.ui \ settings.ui \ file.ui \ projectfile.ui \ - about.ui + about.ui \ + logview.ui TRANSLATIONS = cppcheck_fi.ts \ cppcheck_nl.ts \ @@ -60,7 +61,9 @@ HEADERS += mainwindow.h \ txtreport.h \ xmlreport.h \ translationhandler.h \ - csvreport.h + csvreport.h \ + logview.h + SOURCES += main.cpp \ mainwindow.cpp\ checkthread.cpp \ @@ -81,7 +84,8 @@ SOURCES += main.cpp \ txtreport.cpp \ xmlreport.cpp \ translationhandler.cpp \ - csvreport.cpp + csvreport.cpp \ + logview.cpp win32 { RC_FILE = cppcheck-gui.rc diff --git a/gui/logview.cpp b/gui/logview.cpp new file mode 100644 index 000000000..88b064684 --- /dev/null +++ b/gui/logview.cpp @@ -0,0 +1,30 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2010 Daniel Marjamäki and 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 . + */ + +#include "logview.h" + +LogView::LogView(QWidget *parent) +{ + mUI.setupUi(this); + setWindowFlags(Qt::Tool); +} + +void LogView::AppendLine(const QString &line) +{ + mUI.mLogEdit->appendPlainText(line); +} diff --git a/gui/logview.h b/gui/logview.h new file mode 100644 index 000000000..aa5b921f0 --- /dev/null +++ b/gui/logview.h @@ -0,0 +1,51 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2010 Daniel Marjamäki and 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 . + */ + +#ifndef LOGVIEW_H +#define LOGVIEW_H + +#include +#include "ui_logview.h" + +/// @addtogroup GUI +/// @{ + +/** +* @brief A tool window that shows checking log. +* +*/ +class LogView : public QWidget +{ + Q_OBJECT +public: + LogView(QWidget *parent = 0); + + /** + * @brief Append new log file to view. + * @param line String to add. + * + */ + void AppendLine(const QString &line); + +private: + Ui::LogView mUI; +}; + +/// @} + +#endif // LOGVIEW_H diff --git a/gui/logview.ui b/gui/logview.ui new file mode 100644 index 000000000..8c733213a --- /dev/null +++ b/gui/logview.ui @@ -0,0 +1,34 @@ + + + LogView + + + + 0 + 0 + 400 + 300 + + + + Qt::NoContextMenu + + + Checking Log + + + + + + false + + + true + + + + + + + + diff --git a/gui/main.ui b/gui/main.ui index 939106b55..72f62b145 100644 --- a/gui/main.ui +++ b/gui/main.ui @@ -100,6 +100,7 @@ + @@ -365,6 +366,14 @@ &New Project File... + + + &Log View + + + Log View + + diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 159327950..5202ee49b 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -33,6 +33,7 @@ #include "projectfile.h" #include "project.h" #include "report.h" +#include "logview.h" #include "../lib/filelister.h" // HTMLHelp is only available in Windows @@ -45,12 +46,14 @@ MainWindow::MainWindow() : mSettings(new QSettings("Cppcheck", "Cppcheck-GUI", this)), mApplications(new ApplicationList(this)), mTranslation(new TranslationHandler(this)), - mLanguages(new QActionGroup(this)) + mLanguages(new QActionGroup(this)), + mLogView(NULL) { mUI.setupUi(this); mUI.mResults->Initialize(mSettings, mApplications); mThread = new ThreadHandler(this); + mLogView = new LogView(this); connect(mUI.mActionQuit, SIGNAL(triggered()), this, SLOT(close())); connect(mUI.mActionCheckFiles, SIGNAL(triggered()), this, SLOT(CheckFiles())); @@ -65,6 +68,7 @@ MainWindow::MainWindow() : connect(mUI.mActionUncheckAll, SIGNAL(triggered()), this, SLOT(UncheckAll())); connect(mUI.mActionCollapseAll, SIGNAL(triggered()), mUI.mResults, SLOT(CollapseAllResults())); connect(mUI.mActionExpandAll, SIGNAL(triggered()), mUI.mResults, SLOT(ExpandAllResults())); + connect(mUI.mActionViewLog, SIGNAL(triggered()), this, SLOT(ShowLogView())); connect(mUI.mActionRecheck, SIGNAL(triggered()), this, SLOT(ReCheck())); @@ -114,6 +118,7 @@ MainWindow::MainWindow() : MainWindow::~MainWindow() { + delete mLogView; } void MainWindow::CreateLanguageMenuItems() @@ -731,3 +736,21 @@ void MainWindow::NewProjectFile() prj.Edit(); } } + +void MainWindow::ShowLogView() +{ + if (mLogView == NULL) + mLogView = new LogView(this); + + mLogView->show(); + if (!mLogView->isActiveWindow()) + mLogView->activateWindow(); +} + +void MainWindow::Log(const QString &logline) +{ + if (mLogView) + { + mLogView->AppendLine(logline); + } +} diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 1c8cae8b2..f37cc9b67 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -32,6 +32,7 @@ #include "ui_main.h" class ThreadHandler; +class LogView; /// @addtogroup GUI /// @{ @@ -143,6 +144,12 @@ public slots: */ void OpenProjectFile(); + /** + * @brief Slot for showing the log view. + * + */ + void ShowLogView(); + protected slots: /** @@ -190,6 +197,12 @@ protected slots: */ void OpenHelpContents(); + /** + * @brief Add new line to log. + * + */ + void Log(const QString &logline); + protected: /** @@ -325,6 +338,11 @@ protected: */ QString mCurrentDirectory; + /** + * @brief Log view.. + */ + LogView *mLogView; + }; /// @} #endif // MAINWINDOW_H diff --git a/gui/threadhandler.cpp b/gui/threadhandler.cpp index 7ea918437..9b1bca96f 100644 --- a/gui/threadhandler.cpp +++ b/gui/threadhandler.cpp @@ -144,6 +144,8 @@ void ThreadHandler::Initialize(ResultsView *view) connect(&mResults, SIGNAL(Error(const ErrorItem &)), view, SLOT(Error(const ErrorItem &))); + connect(&mResults, SIGNAL(Log(const QString &)), + parent(), SLOT(Log(const QString &))); } void ThreadHandler::LoadSettings(QSettings &settings) diff --git a/gui/threadresult.cpp b/gui/threadresult.cpp index 9a48be25c..7e933d64f 100644 --- a/gui/threadresult.cpp +++ b/gui/threadresult.cpp @@ -33,7 +33,7 @@ ThreadResult::~ThreadResult() void ThreadResult::reportOut(const std::string &outmsg) { - Q_UNUSED(outmsg); + emit Log(QString::fromStdString(outmsg)); } void ThreadResult::FileChecked(const QString &file) diff --git a/gui/threadresult.h b/gui/threadresult.h index 7e6b1a618..80133a90e 100644 --- a/gui/threadresult.h +++ b/gui/threadresult.h @@ -93,6 +93,13 @@ signals: */ void Error(const ErrorItem &item); + /** + * @brief Signal of a new log message + * + * @param logline Log line + */ + void Log(const QString &logline); + protected: /** From 7f3825d9229dfb714709f6c78f933daea0c7e492 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Fri, 16 Jul 2010 18:02:18 +0300 Subject: [PATCH 2/4] GUI: Add close-button to log view. --- gui/logview.cpp | 7 +++++++ gui/logview.h | 8 ++++++++ gui/logview.ui | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/gui/logview.cpp b/gui/logview.cpp index 88b064684..97fa7b0ab 100644 --- a/gui/logview.cpp +++ b/gui/logview.cpp @@ -22,9 +22,16 @@ LogView::LogView(QWidget *parent) { mUI.setupUi(this); setWindowFlags(Qt::Tool); + + connect(mUI.mCloseButton, SIGNAL(clicked()), this, SLOT(CloseButtonClicked())); } void LogView::AppendLine(const QString &line) { mUI.mLogEdit->appendPlainText(line); } + +void LogView::CloseButtonClicked() +{ + close(); +} diff --git a/gui/logview.h b/gui/logview.h index aa5b921f0..b0631c250 100644 --- a/gui/logview.h +++ b/gui/logview.h @@ -42,6 +42,14 @@ public: */ void AppendLine(const QString &line); +protected slots: + + /** + * @brief Called when close button is clicked. + * + */ + void CloseButtonClicked(); + private: Ui::LogView mUI; }; diff --git a/gui/logview.ui b/gui/logview.ui index 8c733213a..90367ea71 100644 --- a/gui/logview.ui +++ b/gui/logview.ui @@ -27,6 +27,30 @@ + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Close + + + + + From 8bf8dd4bf70200a7cd92d436b443e969d36381e4 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Fri, 16 Jul 2010 18:35:51 +0300 Subject: [PATCH 3/4] GUI: Add Clear-button to log view. --- gui/logview.cpp | 7 +++++++ gui/logview.h | 6 ++++++ gui/logview.ui | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/gui/logview.cpp b/gui/logview.cpp index 97fa7b0ab..94baae276 100644 --- a/gui/logview.cpp +++ b/gui/logview.cpp @@ -20,10 +20,12 @@ LogView::LogView(QWidget *parent) { + Q_UNUSED(parent); mUI.setupUi(this); setWindowFlags(Qt::Tool); connect(mUI.mCloseButton, SIGNAL(clicked()), this, SLOT(CloseButtonClicked())); + connect(mUI.mClearButton, SIGNAL(clicked()), this, SLOT(ClearButtonClicked())); } void LogView::AppendLine(const QString &line) @@ -35,3 +37,8 @@ void LogView::CloseButtonClicked() { close(); } + +void LogView::ClearButtonClicked() +{ + mUI.mLogEdit->clear(); +} diff --git a/gui/logview.h b/gui/logview.h index b0631c250..3923616db 100644 --- a/gui/logview.h +++ b/gui/logview.h @@ -50,6 +50,12 @@ protected slots: */ void CloseButtonClicked(); + /** + * @brief Called when clear button is clicked. + * + */ + void ClearButtonClicked(); + private: Ui::LogView mUI; }; diff --git a/gui/logview.ui b/gui/logview.ui index 90367ea71..642e34436 100644 --- a/gui/logview.ui +++ b/gui/logview.ui @@ -42,6 +42,13 @@ + + + + Clear + + + From de767a7cf195f4387c243032526ff344cc6ce546 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Fri, 16 Jul 2010 23:27:57 +0300 Subject: [PATCH 4/4] GUI: Remember log view size. --- gui/common.h | 2 ++ gui/logview.cpp | 14 +++++++++++++- gui/logview.h | 12 +++++++++++- gui/mainwindow.cpp | 4 ++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/gui/common.h b/gui/common.h index d0226db95..c4fd7c070 100644 --- a/gui/common.h +++ b/gui/common.h @@ -58,6 +58,8 @@ ShowTypes; #define SETTINGS_LANGUAGE "Application language" #define SETTINGS_TOOLBARS_MAIN_SHOW "Toolbars/ShowStandard" #define SETTINGS_TOOLBARS_VIEW_SHOW "Toolbars/ShowView" +#define SETTINGS_LOG_VIEW_WIDTH "Log/View width" +#define SETTINGS_LOG_VIEW_HEIGHT "Log/View height" /// @} #endif diff --git a/gui/logview.cpp b/gui/logview.cpp index 94baae276..8d3b6856a 100644 --- a/gui/logview.cpp +++ b/gui/logview.cpp @@ -16,9 +16,12 @@ * along with this program. If not, see . */ +#include +#include "common.h" #include "logview.h" -LogView::LogView(QWidget *parent) +LogView::LogView(QSettings *programSettings, QWidget *parent) + : mSettings(programSettings) { Q_UNUSED(parent); mUI.setupUi(this); @@ -26,6 +29,15 @@ LogView::LogView(QWidget *parent) connect(mUI.mCloseButton, SIGNAL(clicked()), this, SLOT(CloseButtonClicked())); connect(mUI.mClearButton, SIGNAL(clicked()), this, SLOT(ClearButtonClicked())); + + resize(mSettings->value(SETTINGS_LOG_VIEW_WIDTH, 400).toInt(), + mSettings->value(SETTINGS_LOG_VIEW_HEIGHT, 300).toInt()); +} + +LogView::~LogView() +{ + mSettings->setValue(SETTINGS_LOG_VIEW_WIDTH, size().width()); + mSettings->setValue(SETTINGS_LOG_VIEW_HEIGHT, size().height()); } void LogView::AppendLine(const QString &line) diff --git a/gui/logview.h b/gui/logview.h index 3923616db..d56ae2ef6 100644 --- a/gui/logview.h +++ b/gui/logview.h @@ -22,6 +22,8 @@ #include #include "ui_logview.h" +class QSettings; + /// @addtogroup GUI /// @{ @@ -33,7 +35,8 @@ class LogView : public QWidget { Q_OBJECT public: - LogView(QWidget *parent = 0); + LogView(QSettings *programSettings, QWidget *parent = 0); + ~LogView(); /** * @brief Append new log file to view. @@ -58,6 +61,13 @@ protected slots: private: Ui::LogView mUI; + + /** + * @brief Settings + * + */ + QSettings *mSettings; + }; /// @} diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 5202ee49b..67821c720 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -53,7 +53,7 @@ MainWindow::MainWindow() : mUI.mResults->Initialize(mSettings, mApplications); mThread = new ThreadHandler(this); - mLogView = new LogView(this); + mLogView = new LogView(mSettings); connect(mUI.mActionQuit, SIGNAL(triggered()), this, SLOT(close())); connect(mUI.mActionCheckFiles, SIGNAL(triggered()), this, SLOT(CheckFiles())); @@ -740,7 +740,7 @@ void MainWindow::NewProjectFile() void MainWindow::ShowLogView() { if (mLogView == NULL) - mLogView = new LogView(this); + mLogView = new LogView(mSettings); mLogView->show(); if (!mLogView->isActiveWindow())