From b39c15410bb853d69f3d44953e6eaf6220aed491 Mon Sep 17 00:00:00 2001 From: Vesa Pikki Date: Sun, 1 Mar 2009 07:38:21 +0000 Subject: [PATCH] Began implementing a simple Qt based GUI. Also modified astyle scripts to format gui code aswell. --- gui/checkdialog.cpp | 257 +++++++++++++++++++++++++++++++++++++++++ gui/checkdialog.h | 214 ++++++++++++++++++++++++++++++++++ gui/checkthread.cpp | 79 +++++++++++++ gui/checkthread.h | 114 ++++++++++++++++++ gui/gui.pro | 63 ++++++++++ gui/main.cpp | 30 +++++ gui/mainwindow.cpp | 107 +++++++++++++++++ gui/mainwindow.h | 106 +++++++++++++++++ gui/resultstree.cpp | 96 +++++++++++++++ gui/resultstree.h | 99 ++++++++++++++++ gui/resultsview.cpp | 68 +++++++++++ gui/resultsview.h | 71 ++++++++++++ gui/settingsdialog.cpp | 31 +++++ gui/settingsdialog.h | 39 +++++++ runastyle | 2 + runastyle.bat | 2 + 16 files changed, 1378 insertions(+) create mode 100644 gui/checkdialog.cpp create mode 100644 gui/checkdialog.h create mode 100644 gui/checkthread.cpp create mode 100644 gui/checkthread.h create mode 100644 gui/gui.pro create mode 100644 gui/main.cpp create mode 100644 gui/mainwindow.cpp create mode 100644 gui/mainwindow.h create mode 100644 gui/resultstree.cpp create mode 100644 gui/resultstree.h create mode 100644 gui/resultsview.cpp create mode 100644 gui/resultsview.h create mode 100644 gui/settingsdialog.cpp create mode 100644 gui/settingsdialog.h diff --git a/gui/checkdialog.cpp b/gui/checkdialog.cpp new file mode 100644 index 000000000..db7204553 --- /dev/null +++ b/gui/checkdialog.cpp @@ -0,0 +1,257 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, + * Leandro Penz, Kimmo Varis, Vesa Pikki + * + * 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 +#include +#include +#include +#include +#include + +CheckDialog::CheckDialog(QSettings &programSettings) : + mSettings(programSettings) +{ + QPushButton *cancel = new QPushButton("Cancel"); + QPushButton *ok = new QPushButton("Ok"); + + //Main layout + QVBoxLayout *layout = new QVBoxLayout(); + + //Layout for ok/cancel buttons + QHBoxLayout *buttonLayout = new QHBoxLayout(); + + + //File selection tree + layout->addWidget(new QLabel("Select files to check")); + mFileTree = new QTreeView(); + layout->addWidget(mFileTree); + mFileTree->setModel(&mModel); + mFileTree->scrollTo(mModel.index(programSettings.value("Check path", QDir::currentPath()).toString())); + mFileTree->setSelectionMode(QAbstractItemView::ExtendedSelection); + + //Number of jobs + mJobs = new QLineEdit(programSettings.value("Check threads", 1).toString()); + layout->addWidget(new QLabel("Number of threads")); + layout->addWidget(mJobs); + mJobs->setValidator(new QIntValidator(this)); + + //Debug + mDebug = AddCheckbox(layout, "Debug", "Check debug", false); + + //Show All + mShowAll = AddCheckbox(layout, "Show all", "Check show all", false); + + //Check Coding Style + mCheckCodingStyle = AddCheckbox(layout, "Check Coding Style", "Check coding style", false); + + //Errors only + mErrorsOnly = AddCheckbox(layout, "Errors only", "Check errors only", false); + + //Verbose + mVerbose = AddCheckbox(layout, "Verbose", "Check verbose", false); + + //Force + mForce = AddCheckbox(layout, "Force", "Check force", false); + + //XML + mXml = AddCheckbox(layout, "XML", "Check xml", false); + + //Unused functions + mUnusedFunctions = AddCheckbox(layout, "Unused functions", "Check unused functions", false); + + //Security + mSecurity = AddCheckbox(layout, "Security", "Check security", false); + + //Vcl + mVcl = AddCheckbox(layout, "Vcl", "Check vcl", false); + + + + + + + buttonLayout->addWidget(ok); + buttonLayout->addWidget(cancel); + layout->addLayout(buttonLayout); + + + connect(ok, SIGNAL(clicked()), + this, SLOT(accept())); + connect(cancel, SIGNAL(clicked()), + this, SLOT(reject())); + + setWindowTitle("Select files to check"); + setLayout(layout); + + LoadSettings(); + +} + +CheckDialog::~CheckDialog() +{ + SaveSettings(); +} + + + + + +QStringList CheckDialog::GetSelectedFiles() +{ + QModelIndexList indexes = mFileTree->selectionModel()->selectedRows(); + QStringList list; + QModelIndex index; + + foreach(index, indexes) + { + list << mModel.filePath(index); + } + + return list; +} + + +Qt::CheckState CheckDialog::BoolToCheckState(bool yes) +{ + if (yes) + { + return Qt::Checked; + } + return Qt::Unchecked; +} + +bool CheckDialog::CheckStateToBool(Qt::CheckState state) +{ + if (state == Qt::Checked) + { + return true; + } + return false; +} + +QCheckBox* CheckDialog::AddCheckbox(QVBoxLayout *layout, + const QString &label, + const QString &settings, + bool value) +{ + QCheckBox *result = new QCheckBox(label); + result->setCheckState(BoolToCheckState(mSettings.value(settings, value).toInt())); + + //layout->addWidget(new QLabel(label)); + layout->addWidget(result); + + return result; +} + +Settings CheckDialog::GetSettings() +{ + Settings result; + result._debug = CheckStateToBool(mDebug->checkState()); + result._showAll = CheckStateToBool(mShowAll->checkState()); + result._checkCodingStyle = CheckStateToBool(mCheckCodingStyle->checkState()); + result._errorsOnly = CheckStateToBool(mErrorsOnly->checkState()); + result._verbose = CheckStateToBool(mVerbose->checkState()); + result._force = CheckStateToBool(mForce->checkState()); + result._xml = CheckStateToBool(mXml->checkState()); + result._unusedFunctions = CheckStateToBool(mUnusedFunctions->checkState()); + result._security = CheckStateToBool(mSecurity->checkState()); + result._vcl = CheckStateToBool(mVcl->checkState()); + result._jobs = mJobs->text().toInt(); + return result; +} + +QString CheckDialog::GetDefaultPath() +{ + QStringList list = GetSelectedFiles(); + int len = 9999; + QString file, shortest; + + if (list.size() == 0) + { + return QDir::currentPath(); + } + + foreach(file, list) + { + if (file.size() < len) + { + shortest = file; + len = file.size(); + } + } + + return shortest; +} + +void CheckDialog::LoadSettings() +{ + /* + if (mSettings.value("Check dialog maximized",false).toBool()) + { + showMaximized(); + } + else + {*/ + resize(mSettings.value("Check dialog width", 800).toInt(), mSettings.value("Check dialog height", 600).toInt()); + //} + + for (int i = 0;i < mModel.columnCount();i++) + { + //mFileTree.columnWidth(i); + QString temp = QString("Check dialog column %1 width").arg(i); + mFileTree->setColumnWidth(i, mSettings.value(temp, 800 / mModel.columnCount()).toInt()); + } +} + +void CheckDialog::SaveSettings() +{ + mSettings.setValue("Check dialog width", size().width()); + mSettings.setValue("Check dialog height", size().height()); + //mSettings.setValue("Check dialog maximized", isMaximized()); + + for (int i = 0;i < mModel.columnCount();i++) + { + QString temp = QString("Check dialog column %1 width").arg(i); + mSettings.setValue(temp, mFileTree->columnWidth(i)); + } +} + +void CheckDialog::SaveCheckboxValues() +{ + mSettings.setValue("Check threads", mJobs->text().toInt()); + SaveCheckboxValue(mDebug, "Check debug"); + SaveCheckboxValue(mShowAll, "Check show all"); + SaveCheckboxValue(mCheckCodingStyle, "Check coding style"); + SaveCheckboxValue(mErrorsOnly, "Check errors only"); + SaveCheckboxValue(mVerbose, "Check verbose"); + SaveCheckboxValue(mForce, "Check force"); + SaveCheckboxValue(mXml, "Check xml"); + SaveCheckboxValue(mUnusedFunctions, "Check unused functions"); + SaveCheckboxValue(mSecurity, "Check security"); + SaveCheckboxValue(mVcl, "Check vcl"); +} + +void CheckDialog::SaveCheckboxValue(QCheckBox *box, const QString &name) +{ + mSettings.setValue(name, CheckStateToBool(box->checkState())); +} diff --git a/gui/checkdialog.h b/gui/checkdialog.h new file mode 100644 index 000000000..40f74f12c --- /dev/null +++ b/gui/checkdialog.h @@ -0,0 +1,214 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, + * Leandro Penz, Kimmo Varis, Vesa Pikki + * + * 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 +#include +#include +#include +#include +#include "../src/settings.h" +#include +#include +#include +#include + +/** +* @brief Dialog to select what and how to check +* +*/ +class CheckDialog : public QDialog +{ + Q_OBJECT +public: + CheckDialog(QSettings &programSettings); + virtual ~CheckDialog(); + + /** + * @brief Get cppcheck settings based on user selections + * + * @return cppcheck settings + */ + Settings GetSettings(); + + /** + * @brief Get the root path of current selection + * + * @return default path to use next time + */ + QString GetDefaultPath(); + + /** + * @brief Get a list of selected files and directories + * + * @return list of selected files + */ + QStringList GetSelectedFiles(); + + /** + * @brief Save all checkbox values + * + */ + void SaveCheckboxValues(); +protected: + + /** + * @brief Load saved values + * Loads dialog size and column widths. + * + */ + void SaveSettings(); + + /** + * @brief Save settings + * Save dialog size and column widths. + * + */ + void LoadSettings(); + + /** + * @brief Save a single checkboxes value + * + * @param box checkbox to save + * @param name name for QSettings to store the value + */ + void SaveCheckboxValue(QCheckBox *box, const QString &name); + + /** + * @brief Add a new checkbox to layout + * + * @param layout layout to add to + * @param label label for the checkbox + * @param settings QSettings name for default value + * @return newly created QCheckBox + */ + QCheckBox* AddCheckbox(QVBoxLayout *layout, + const QString &label, + const QString &settings, + bool value); + + /** + * @brief Convert bool to Qt::CheckState + * + * @param yes value to convert + * @return value converted to Qt::CheckState + */ + Qt::CheckState BoolToCheckState(bool yes); + + /** + * @brief Converts Qt::CheckState to bool + * + * @param state Qt::CheckState to convert + * @return converted value + */ + bool CheckStateToBool(Qt::CheckState state); + + /** + * @brief Item model for mFileTree + * + */ + QDirModel mModel; + + /** + * @brief Filetree to select files from + * + */ + QTreeView *mFileTree; + + /** + * @brief How many threads should cppcheck have + * + */ + QLineEdit *mJobs; + + /** + * @brief Cppcheck setting + * + */ + QCheckBox *mDebug; + + /** + * @brief Cppcheck setting + * + */ + QCheckBox *mShowAll; + + /** + * @brief Cppcheck setting + * + */ + QCheckBox *mCheckCodingStyle; + + /** + * @brief Cppcheck setting + * + */ + QCheckBox *mErrorsOnly; + + /** + * @brief Cppcheck setting + * + */ + QCheckBox *mVerbose; + + /** + * @brief Cppcheck setting + * + */ + QCheckBox *mForce; + + /** + * @brief Cppcheck setting + * + */ + QCheckBox *mXml; + + /** + * @brief Cppcheck setting + * + */ + QCheckBox *mUnusedFunctions; + + /** + * @brief Cppcheck setting + * + */ + QCheckBox *mSecurity; + + /** + * @brief Cppcheck setting + * + */ + QCheckBox *mVcl; + + /** + * @brief Settings + * + */ + QSettings &mSettings; + + +private: +}; + +#endif // CHECKDIALOG_H diff --git a/gui/checkthread.cpp b/gui/checkthread.cpp new file mode 100644 index 000000000..b15bd07dd --- /dev/null +++ b/gui/checkthread.cpp @@ -0,0 +1,79 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, + * Leandro Penz, Kimmo Varis, Vesa Pikki + * + * 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 + +CheckThread::CheckThread() : mCppCheck(*this) +{ + //ctor +} + +CheckThread::~CheckThread() +{ + //dtor +} + +void CheckThread::SetSettings(Settings settings) +{ + mCppCheck.settings(settings); +} + +void CheckThread::AddFile(const QString &file) +{ + mCppCheck.addFile(file.toStdString()); +} + +void CheckThread::ClearFiles() +{ + mCppCheck.clearFiles(); +} + +void CheckThread::run() +{ + mCppCheck.check(); + emit Done(); +} + + +void CheckThread::reportOut(const std::string &outmsg) +{ + emit CurrentFile(QString(outmsg.c_str())); +} + +void CheckThread::reportErr(const ErrorLogger::ErrorMessage &msg) +{ + emit Error(QString(callStackToString(msg._callStack).c_str()), + QString(msg._severity.c_str()), + QString(msg._msg.c_str())); + /* + qDebug()<<"Error: "; + qDebug()< +#include "../src/cppcheck.h" +#include "../src/errorlogger.h" + +/** +* @brief Thread to run cppcheck +* +*/ +class CheckThread : public QThread, public ErrorLogger +{ + Q_OBJECT +public: + CheckThread(); + virtual ~CheckThread(); + + /** + * @brief Set settings for cppcheck + * + * @param settings settings for cppcheck + */ + void SetSettings(Settings settings); + + /** + * @brief Clear all files from cppcheck + * + */ + void ClearFiles(); + + /** + * @brief Add a single file to cppcheck + * + * @param file file to add + */ + void AddFile(const QString &file); + + /** + * @brief method that is run in a thread + * + */ + void run(); + + /** + * ErrorLogger methods + */ + void reportOut(const std::string &outmsg); + void reportErr(const ErrorLogger::ErrorMessage &msg); + void reportStatus(unsigned int index, unsigned int max); + +signals: + /** + * @brief Currently processed file + * + * @param filename filename + */ + void CurrentFile(const QString &filename); + + /** + * @brief Cppcheck progress + * + * @param value progress + * @param max maximum progress + */ + void Progress(int value, int max); + + /** + * @brief Error in file + * + * @param filename filename + * @param severity error's severity + * @param message error message + */ + void Error(const QString &filename, + const QString &severity, + const QString &message); + + /** + * @brief cpp checking is done + * + */ + void Done(); +protected: + + /** + * @brief CppCheck itself + * + */ + CppCheck mCppCheck; +private: +}; + +#endif // CHECKTHREAD_H diff --git a/gui/gui.pro b/gui/gui.pro new file mode 100644 index 000000000..a3080813f --- /dev/null +++ b/gui/gui.pro @@ -0,0 +1,63 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Sun Feb 22 10:14:18 2009 +###################################################################### + +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . +MOC_DIR = temp +OBJECTS_DIR = temp + +# Input +HEADERS += mainwindow.h \ + checkdialog.h \ + checkthread.h \ + resultsview.h \ + resultstree.h \ + settingsdialog.h \ + ../src/checkbufferoverrun.h \ + ../src/checkclass.h \ + ../src/checkdangerousfunctions.h \ + ../src/checkfunctionusage.h \ + ../src/checkheaders.h \ + ../src/checkmemoryleak.h \ + ../src/checkother.h \ + ../src/checksecurity.h \ + ../src/checkstl.h \ + ../src/cppcheck.h \ + ../src/cppcheckexecutor.h \ + ../src/errorlogger.h \ + ../src/filelister.h \ + ../src/preprocessor.h \ + ../src/resource.h \ + ../src/settings.h \ + ../src/threadexecutor.h \ + ../src/token.h \ + ../src/tokenize.h + +SOURCES += main.cpp \ + mainwindow.cpp\ + checkdialog.cpp \ + checkthread.cpp \ + resultsview.cpp \ + resultstree.cpp \ + settingsdialog.cpp \ + ../src/checkbufferoverrun.cpp \ + ../src/checkclass.cpp \ + ../src/checkdangerousfunctions.cpp \ + ../src/checkfunctionusage.cpp \ + ../src/checkheaders.cpp \ + ../src/checkmemoryleak.cpp \ + ../src/checkother.cpp \ + ../src/checksecurity.cpp \ + ../src/checkstl.cpp \ + ../src/cppcheck.cpp \ + ../src/cppcheckexecutor.cpp \ + ../src/errorlogger.cpp \ + ../src/filelister.cpp \ + ../src/preprocessor.cpp \ + ../src/settings.cpp \ + ../src/threadexecutor.cpp \ + ../src/token.cpp \ + ../src/tokenize.cpp diff --git a/gui/main.cpp b/gui/main.cpp new file mode 100644 index 000000000..7bf5e33d5 --- /dev/null +++ b/gui/main.cpp @@ -0,0 +1,30 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, + * Leandro Penz, Kimmo Varis, Vesa Pikki + * + * 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 "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow window; + window.show(); + return app.exec(); +} diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp new file mode 100644 index 000000000..404e6a46a --- /dev/null +++ b/gui/mainwindow.cpp @@ -0,0 +1,107 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, + * Leandro Penz, Kimmo Varis, Vesa Pikki + * + * 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 +#include + +MainWindow::MainWindow() : + mSettings("CppCheck", "CppCheck-GUI"), + mExit("E&xit", this), + mCheck("&Check", this), + mResults(mSettings) +{ + QMenu *menu = menuBar()->addMenu(tr("&File")); + menu->addAction(&mCheck); + menu->addSeparator(); + menu->addAction(&mExit); + + setCentralWidget(&mResults); + + + connect(&mExit, SIGNAL(triggered()), this, SLOT(close())); + connect(&mCheck, SIGNAL(triggered()), this, SLOT(Check())); + connect(&mThread, SIGNAL(Done()), this, SLOT(CheckDone())); + connect(&mThread, SIGNAL(CurrentFile(const QString &)), + &mResults, SLOT(CurrentFile(const QString &))); + + connect(&mThread, SIGNAL(Progress(int, int)), + &mResults, SLOT(Progress(int, int))); + connect(&mThread, SIGNAL(Error(const QString &, const QString &, const QString &)), + &mResults, SLOT(Error(const QString &, const QString &, const QString &))); + LoadSettings(); +} + +MainWindow::~MainWindow() +{ + //dtor +} + +void MainWindow::LoadSettings() +{ + if (mSettings.value("Window maximized", false).toBool()) + { + showMaximized(); + } + else + { + resize(mSettings.value("Window width", 800).toInt(), mSettings.value("Window height", 600).toInt()); + } +} + +void MainWindow::SaveSettings() +{ + mSettings.setValue("Window width", size().width()); + mSettings.setValue("Window height", size().height()); + mSettings.setValue("Window maximized", isMaximized()); +} + + +void MainWindow::Check() +{ + CheckDialog dialog(mSettings); + if (dialog.exec() == QDialog::Accepted) + { + mResults.Clear(); + mThread.ClearFiles(); + + QString str; + qDebug("Selected files:"); + foreach(str, dialog.GetSelectedFiles()) + { + qDebug() << str; + mThread.AddFile(str); + } + + mSettings.setValue("Check path", dialog.GetDefaultPath()); + dialog.SaveCheckboxValues(); + + mThread.SetSettings(dialog.GetSettings()); + mCheck.setDisabled(true); + + mThread.start(); + } +} + +void MainWindow::CheckDone() +{ + mCheck.setDisabled(false); +} diff --git a/gui/mainwindow.h b/gui/mainwindow.h new file mode 100644 index 000000000..9be28f1c7 --- /dev/null +++ b/gui/mainwindow.h @@ -0,0 +1,106 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, + * Leandro Penz, Kimmo Varis, Vesa Pikki + * + * 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 "resultsview.h" +#include +#include +#include "../src/settings.h" + +#include "checkdialog.h" +#include "checkthread.h" + +/** +* @brief Main window for cppcheck-gui +* +*/ +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + MainWindow(); + virtual ~MainWindow(); + +public slots: + + /** + * @brief Slot for check menu item + * + */ + void Check(); + +protected slots: + + /** + * @brief Slot for checkthread's done signal + * + */ + void CheckDone(); +protected: + + /** + * @brief Load program settings + * + */ + void LoadSettings(); + + /** + * @brief Save program settings + * + */ + void SaveSettings(); + + /** + * @brief Program settings + * + */ + QSettings mSettings; + + /** + * @brief Menu action to exit program + * + */ + QAction mExit; + + /** + * @brief Menu action to open checkdialog + * + */ + QAction mCheck; + + /** + * @brief Results for checking + * + */ + ResultsView mResults; + + /** + * @brief Thread to check files + * + */ + CheckThread mThread; + +private: +}; + +#endif // MAINWINDOW_H diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp new file mode 100644 index 000000000..9bcac5af0 --- /dev/null +++ b/gui/resultstree.cpp @@ -0,0 +1,96 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, + * Leandro Penz, Kimmo Varis, Vesa Pikki + * + * 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 setEditable(false); + return item; +} + + +void ResultsTree::AddErrorItem(const QString &file, + const QString &severity, + const QString &error) +{ + QStandardItem *fileitem = FindFileItem(file); + if (!fileitem) + { + fileitem = CreateItem(file); + } + + QList list; + list << CreateItem(severity); + list << CreateItem(error); + fileitem->appendRow(list); + mModel.appendRow(fileitem); +} + +QStandardItem *ResultsTree::FindFileItem(const QString &name) +{ + QList list = mModel.findItems(name); + if (list.size() > 0) + return list[0]; + return 0; +} + +void ResultsTree::Clear() +{ + mModel.removeRows(0, mModel.rowCount()); +} + +void ResultsTree::LoadSettings() +{ + for (int i = 0;i < mModel.columnCount();i++) + { + //mFileTree.columnWidth(i); + QString temp = QString("Result column %1 width").arg(i); + setColumnWidth(i, mSettings.value(temp, 800 / mModel.columnCount()).toInt()); + } +} + +void ResultsTree::SaveSettings() +{ + for (int i = 0;i < mModel.columnCount();i++) + { + QString temp = QString("Result column %1 width").arg(i); + mSettings.setValue(temp, columnWidth(i)); + } +} diff --git a/gui/resultstree.h b/gui/resultstree.h new file mode 100644 index 000000000..2faca73cc --- /dev/null +++ b/gui/resultstree.h @@ -0,0 +1,99 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, + * Leandro Penz, Kimmo Varis, Vesa Pikki + * + * 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 +#include +#include + + +/** +* @brief Cppcheck's results are shown in this tree +* +*/ +class ResultsTree : public QTreeView +{ +public: + ResultsTree(QSettings &settings); + virtual ~ResultsTree(); + + /** + * @brief Add a new item to the tree + * + * @param file filename + * @param severity error severity + * @param error error message + */ + void AddErrorItem(const QString &file, + const QString &severity, + const QString &error); + + /** + * @brief Clear all errors from the tree + * + */ + void Clear(); +protected: + /** + * @brief Load all settings + * Colum widths + */ + void LoadSettings(); + + /** + * @brief Save all settings + * Colum widths + */ + void SaveSettings(); + + /** + * @brief Create a new QStandardItem + * + * @param name name for the item + * @return new QStandardItem + */ + QStandardItem *CreateItem(const QString &name); + + /** + * @brief Finds a file item + * + * @param name name of the file item to find + * @return pointer to file item or null if none found + */ + QStandardItem *FindFileItem(const QString &name); + + /** + * @brief Item model for tree + * + */ + QStandardItemModel mModel; + + /** + * @brief Program settings + * + */ + QSettings &mSettings; +private: +}; + +#endif // RESULTSTREE_H diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp new file mode 100644 index 000000000..8473f8fc8 --- /dev/null +++ b/gui/resultsview.cpp @@ -0,0 +1,68 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, + * Leandro Penz, Kimmo Varis, Vesa Pikki + * + * 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 + +ResultsView::ResultsView(QSettings &settings) +{ + QVBoxLayout *layout = new QVBoxLayout(); + setLayout(layout); + + mProgress = new QProgressBar(); + layout->addWidget(mProgress); + mProgress->setMinimum(0); + + mTree = new ResultsTree(settings); + layout->addWidget(mTree); + +} + +ResultsView::~ResultsView() +{ + //dtor +} + + +void ResultsView::Clear() +{ + mTree->Clear(); +} + + +void ResultsView::CurrentFile(const QString &filename) +{ + mProgress->setFormat(filename); +} + +void ResultsView::Progress(int value, int max) +{ + mProgress->setMaximum(max); + mProgress->setValue(value); +} + +void ResultsView::Error(const QString &filename, + const QString &severity, + const QString &message) +{ + qDebug() << "Error" << filename << severity << message; + mTree->AddErrorItem(filename, severity, message); +} diff --git a/gui/resultsview.h b/gui/resultsview.h new file mode 100644 index 000000000..3b5cb40b3 --- /dev/null +++ b/gui/resultsview.h @@ -0,0 +1,71 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, + * Leandro Penz, Kimmo Varis, Vesa Pikki + * + * 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 +#include "../src/errorlogger.h" +#include "resultstree.h" + +/** +* @brief Widget to show cppcheck progressbar and result +* +*/ +class ResultsView : public QWidget +{ + Q_OBJECT +public: + ResultsView(QSettings &settings); + virtual ~ResultsView(); + + /** + * @brief Clear results + * + */ + void Clear(); +public slots: + /** + * Slots for CheckThread's signals + */ + void CurrentFile(const QString &filename); + void Progress(int value, int max); + void Error(const QString &filename, + const QString &severity, + const QString &message); +protected: + /** + * @brief Tree to show cppcheck's results + * + */ + ResultsTree *mTree; + + /** + * @brief Progressbar to show cppcheck's progress + * + */ + QProgressBar *mProgress; + +private: +}; + +#endif // RESULTSVIEW_H diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp new file mode 100644 index 000000000..7adecd7ff --- /dev/null +++ b/gui/settingsdialog.cpp @@ -0,0 +1,31 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, + * Leandro Penz, Kimmo Varis, Vesa Pikki + * + * 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 + +/** +* @brief Settings dialog +* +*/ +class SettingsDialog : public QDialog +{ +public: + SettingsDialog(); + virtual ~SettingsDialog(); +protected: +private: +}; + +#endif // SETTINGSDIALOG_H diff --git a/runastyle b/runastyle index fe57c96d2..73bf8e582 100755 --- a/runastyle +++ b/runastyle @@ -2,6 +2,8 @@ astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren src/*.cpp astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren src/*.h +astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren gui/*.cpp +astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren gui/*.h astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren test/*.cpp astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren test/*.h diff --git a/runastyle.bat b/runastyle.bat index 71f9c60bd..6632d9414 100644 --- a/runastyle.bat +++ b/runastyle.bat @@ -1,6 +1,8 @@ astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren src/*.cpp astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren src/*.h +astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren gui/*.cpp +astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren gui/*.h astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren test/*.cpp astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren test/*.h astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren tools/*.cpp