From 2eff269e60061e3ec9ec1af6b06292f7fe89d16f Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sat, 20 Jun 2009 19:55:23 +0300 Subject: [PATCH] GUI: Make ThreadHandler class part of object tree. --- gui/mainwindow.cpp | 18 ++++++++++-------- gui/mainwindow.h | 8 ++++---- gui/threadhandler.cpp | 4 +++- gui/threadhandler.h | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index ccdc4b296..f269abdbc 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -27,6 +27,7 @@ #include #include #include "aboutdialog.h" +#include "threadhandler.h" #include "fileviewdialog.h" #include "../src/filelister.h" #include "../src/cppcheckexecutor.h" @@ -57,6 +58,7 @@ MainWindow::MainWindow() : { CreateMenus(); CreateToolbar(); + mThread = new ThreadHandler(this); setCentralWidget(&mResults); @@ -78,14 +80,14 @@ MainWindow::MainWindow() : connect(&mActionReCheck, SIGNAL(triggered()), this, SLOT(ReCheck())); - connect(&mActionStop, SIGNAL(triggered()), &mThread, SLOT(Stop())); + connect(&mActionStop, SIGNAL(triggered()), mThread, SLOT(Stop())); connect(&mActionSave, SIGNAL(triggered()), this, SLOT(Save())); connect(&mActionAbout, SIGNAL(triggered()), this, SLOT(About())); connect(&mActionShowLicense, SIGNAL(triggered()), this, SLOT(ShowLicense())); connect(&mActionShowAuthors, SIGNAL(triggered()), this, SLOT(ShowAuthors())); - connect(&mThread, SIGNAL(Done()), this, SLOT(CheckDone())); + connect(mThread, SIGNAL(Done()), this, SLOT(CheckDone())); connect(&mResults, SIGNAL(GotResults()), this, SLOT(ResultsAdded())); mActionCheckDirectory.setIcon(QIcon(":icon.png")); @@ -102,7 +104,7 @@ MainWindow::MainWindow() : mActionAbout.setShortcut(QKeySequence(Qt::Key_F1)); LoadSettings(); - mThread.Initialize(&mResults); + mThread->Initialize(&mResults); setWindowTitle(tr("Cppcheck")); EnableCheckButtons(true); @@ -248,7 +250,7 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode) } mResults.Clear(); - mThread.ClearFiles(); + mThread->ClearFiles(); if (fileNames.isEmpty()) { @@ -263,13 +265,13 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode) mResults.CheckingStarted(); - mThread.SetFiles(RemoveUnacceptedFiles(fileNames)); + mThread->SetFiles(RemoveUnacceptedFiles(fileNames)); QFileInfo inf(fileNames[0]); QString absDirectory = inf.absoluteDir().path(); mSettings.setValue(tr("Check path"), absDirectory); EnableCheckButtons(false); mResults.SetCheckDirectory(absDirectory); - mThread.Check(GetCppcheckSettings(), false); + mThread->Check(GetCppcheckSettings(), false); } } @@ -365,7 +367,7 @@ void MainWindow::ReCheck() { ClearResults(); EnableCheckButtons(false); - mThread.Check(GetCppcheckSettings(), true); + mThread->Check(GetCppcheckSettings(), true); } void MainWindow::ClearResults() @@ -422,7 +424,7 @@ void MainWindow::UncheckAll() void MainWindow::closeEvent(QCloseEvent *event) { // Check that we aren't checking files - if (!mThread.IsChecking()) + if (!mThread->IsChecking()) event->accept(); else { diff --git a/gui/mainwindow.h b/gui/mainwindow.h index eed36b83b..09a7b5ca6 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -21,15 +21,15 @@ #define MAINWINDOW_H #include -#include "resultsview.h" #include #include #include - -#include "threadhandler.h" +#include "resultsview.h" #include "settingsdialog.h" +class ThreadHandler; + /** * @brief Main window for cppcheck-gui * @@ -359,7 +359,7 @@ protected: * @brief Thread to check files * */ - ThreadHandler mThread; + ThreadHandler *mThread; /** * @brief List of user defined applications to open errors with diff --git a/gui/threadhandler.cpp b/gui/threadhandler.cpp index 37df356b0..479da40e6 100644 --- a/gui/threadhandler.cpp +++ b/gui/threadhandler.cpp @@ -20,7 +20,9 @@ #include "threadhandler.h" #include -ThreadHandler::ThreadHandler() : mRunningThreadCount(0) +ThreadHandler::ThreadHandler(QObject *parent) : + QObject(parent), + mRunningThreadCount(0) { SetThreadCount(1); } diff --git a/gui/threadhandler.h b/gui/threadhandler.h index 25de349aa..8906c7b6b 100644 --- a/gui/threadhandler.h +++ b/gui/threadhandler.h @@ -36,7 +36,7 @@ class ThreadHandler : public QObject { Q_OBJECT public: - ThreadHandler(); + ThreadHandler(QObject *parent = 0); virtual ~ThreadHandler(); /**