From 56f6204cf734faf2f2bf25b3c05c81b6acb0b9fc Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sun, 2 Oct 2011 22:08:12 +0300 Subject: [PATCH] GUI: Make platforms in GUI more dynamic. We have now one list for checked platforms, menu items are created dynamically based on that list. This makes it much easier to alter the platforms list later on. --- gui/gui.pro | 2 ++ gui/main.ui | 16 +++++------ gui/mainwindow.cpp | 71 ++++++++++++++++++---------------------------- gui/mainwindow.h | 37 ++++++------------------ gui/platforms.cpp | 61 +++++++++++++++++++++++++++++++++++++++ gui/platforms.h | 59 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 164 insertions(+), 82 deletions(-) create mode 100644 gui/platforms.cpp create mode 100644 gui/platforms.h diff --git a/gui/gui.pro b/gui/gui.pro index e5b927c56..1d68a5569 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -63,6 +63,7 @@ HEADERS += aboutdialog.h \ fileviewdialog.h \ logview.h \ mainwindow.h \ + platforms.h \ project.h \ projectfile.h \ projectfiledialog.h \ @@ -92,6 +93,7 @@ SOURCES += aboutdialog.cpp \ logview.cpp \ main.cpp \ mainwindow.cpp\ + platforms.cpp \ project.cpp \ projectfile.cpp \ projectfiledialog.cpp \ diff --git a/gui/main.ui b/gui/main.ui index 0c6c3dbec..00d355bbb 100644 --- a/gui/main.ui +++ b/gui/main.ui @@ -134,12 +134,7 @@ - - - - - - + @@ -596,12 +591,15 @@ Windows 64-bit - + - true + false - Default + Platforms + + + false diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index dea8acea8..ceb9cb3f5 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -117,22 +117,6 @@ MainWindow::MainWindow() : connect(mUI.mActionHelpContents, SIGNAL(triggered()), this, SLOT(OpenHelpContents())); - QActionGroup* platformGroup = new QActionGroup(this); - mUI.mActionPlatformDefault->setActionGroup(platformGroup); - mUI.mActionPlatformUnix32Bit->setActionGroup(platformGroup); - mUI.mActionPlatformUnix64Bit->setActionGroup(platformGroup); - mUI.mActionPlatformWin32ANSI->setActionGroup(platformGroup); - mUI.mActionPlatformWin32Unicode->setActionGroup(platformGroup); - mUI.mActionPlatformWin64->setActionGroup(platformGroup); - mUI.mActionPlatformDefault->setChecked(true); - - connect(mUI.mActionPlatformDefault, SIGNAL(triggered()), this, SLOT(PlatformDefault())); - connect(mUI.mActionPlatformUnix32Bit, SIGNAL(triggered()), this, SLOT(PlatformUnix32Bit())); - connect(mUI.mActionPlatformUnix64Bit, SIGNAL(triggered()), this, SLOT(PlatformUnix64Bit())); - connect(mUI.mActionPlatformWin32ANSI, SIGNAL(triggered()), this, SLOT(PlatformWin32ANSI())); - connect(mUI.mActionPlatformWin32Unicode, SIGNAL(triggered()), this, SLOT(PlatformWin32Unicode())); - connect(mUI.mActionPlatformWin64, SIGNAL(triggered()), this, SLOT(PlatformWin64())); - LoadSettings(); mThread->Initialize(mUI.mResults); @@ -164,6 +148,26 @@ MainWindow::MainWindow() : mRecentProjectActs[MaxRecentProjects] = NULL; // The separator mUI.mActionProjectMRU->setVisible(false); UpdateMRUMenuItems(); + + QActionGroup* platformGroup = new QActionGroup(this); + for (int i = 0; i < mPlatforms.getCount(); i++) + { + Platform plat = mPlatforms.mPlatforms[i]; + QAction *act = new QAction(this); + plat.mActMainWindow = act; + mPlatforms.mPlatforms[i] = plat; + act->setText(plat.mTitle); + act->setData(plat.mType); + act->setCheckable(true); + act->setActionGroup(platformGroup); + mUI.mMenuCheck->insertAction(mUI.mActionPlatforms, act); + connect(act, SIGNAL(triggered()), this, SLOT(SelectPlatform())); + } + + // Set the "default" as selected initially + Platform &plat = mPlatforms.get(Settings::Unspecified); + plat.mActMainWindow->setChecked(true); + mSettings->setValue(SETTINGS_CHECKED_PLATFORM, Settings::Unspecified); } MainWindow::~MainWindow() @@ -1108,33 +1112,12 @@ void MainWindow::RemoveProjectMRU(const QString &project) UpdateMRUMenuItems(); } - -void MainWindow::PlatformDefault() +void MainWindow::SelectPlatform() { - mSettings->setValue(SETTINGS_CHECKED_PLATFORM, Settings::Unspecified); -} - -void MainWindow::PlatformUnix32Bit() -{ - mSettings->setValue(SETTINGS_CHECKED_PLATFORM, Settings::Unix32); -} - -void MainWindow::PlatformUnix64Bit() -{ - mSettings->setValue(SETTINGS_CHECKED_PLATFORM, Settings::Unix64); -} - -void MainWindow::PlatformWin32ANSI() -{ - mSettings->setValue(SETTINGS_CHECKED_PLATFORM, Settings::Win32A); -} - -void MainWindow::PlatformWin32Unicode() -{ - mSettings->setValue(SETTINGS_CHECKED_PLATFORM, Settings::Win32W); -} - -void MainWindow::PlatformWin64() -{ - mSettings->setValue(SETTINGS_CHECKED_PLATFORM, Settings::Win64); + QAction *action = qobject_cast(sender()); + if (action) + { + const Settings::PlatformType platform = (Settings::PlatformType) action->data().toInt(); + mSettings->setValue(SETTINGS_CHECKED_PLATFORM, platform); + } } diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 0ec00e19f..ddd0550f7 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -32,6 +32,7 @@ #include "settingsdialog.h" #include "translationhandler.h" #include "settings.h" +#include "platforms.h" #include "ui_main.h" class ThreadHandler; @@ -61,6 +62,11 @@ public: MainWindow(); virtual ~MainWindow(); + /** + * List of checked platforms. + */ + Platforms mPlatforms; + public slots: /** @@ -286,36 +292,9 @@ protected slots: void OpenRecentProject(); /** - * @brief Selects "default" as the checked platform. - * Selects the platform as the "default", meaning whichever platform the - * GUI was compiled with. + * @brief Selects the platform as checked platform. */ - void PlatformDefault(); - - /** - * @brief Selects 32-bit Unix as the checked platform. - */ - void PlatformUnix32Bit(); - - /** - * @brief Selects 64-bit Unix as the checked platform. - */ - void PlatformUnix64Bit(); - - /** - * @brief Selects 32-bit ANSI Windows as the checked platform. - */ - void PlatformWin32ANSI(); - - /** - * @brief Selects 32-bit Unicode Windows as the checked platform. - */ - void PlatformWin32Unicode(); - - /** - * @brief Selects 64-bit Windows as the checked platform. - */ - void PlatformWin64(); + void SelectPlatform(); protected: diff --git a/gui/platforms.cpp b/gui/platforms.cpp new file mode 100644 index 000000000..ce3566a54 --- /dev/null +++ b/gui/platforms.cpp @@ -0,0 +1,61 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2011 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 "platforms.h" + +Platforms::Platforms(QObject *parent) + : QObject(parent) +{ + init(); +} + +void Platforms::add(const QString &title, Settings::PlatformType platform) +{ + Platform plat; + plat.mTitle = title; + plat.mType = platform; + mPlatforms << plat; +} + +void Platforms::init() +{ + add(tr("Default"), Settings::Unspecified); + add(tr("Unix 32-bit"), Settings::Unix32); + add(tr("Unix 64-bit"), Settings::Unix64); + add(tr("Windows 32-bit ANSI"), Settings::Win32A); + add(tr("Windows 32-bit Unicode"), Settings::Win32W); + add(tr("Windows 64-bit"), Settings::Win64); +} + +int Platforms::getCount() const +{ + return mPlatforms.count(); +} + +Platform& Platforms::get(Settings::PlatformType platform) +{ + QList::iterator iter = mPlatforms.begin(); + while (iter != mPlatforms.end()) + { + if ((*iter).mType == platform) + { + return *iter; + } + } + return mPlatforms.first(); +} diff --git a/gui/platforms.h b/gui/platforms.h new file mode 100644 index 000000000..62de8b2bd --- /dev/null +++ b/gui/platforms.h @@ -0,0 +1,59 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2011 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 PLATFORMS_H +#define PLATFORMS_H + +#include +#include +#include +#include +#include "settings.h" + +/// @addtogroup GUI +/// @{ + +/** + * @brief Checked platform GUI-data. + */ +struct Platform +{ + QString mTitle; /**< Text visible in the GUI. */ + Settings::PlatformType mType; /**< Type in the core. */ + QAction *mActMainWindow; /**< Pointer to main window action item. */ +}; + +/** + * @brief List of checked platforms. + */ +class Platforms : public QObject +{ + Q_OBJECT + +public: + Platforms(QObject *parent = NULL); + void add(const QString &title, Settings::PlatformType platform); + int getCount() const; + void init(); + Platform& get(Settings::PlatformType platform); + + QList mPlatforms; +}; + +/// @} +#endif // PLATFORMS_H