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.
This commit is contained in:
Kimmo Varis 2011-10-02 22:08:12 +03:00
parent 417dc1ff2a
commit 56f6204cf7
6 changed files with 164 additions and 82 deletions

View File

@ -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 \

View File

@ -134,12 +134,7 @@
<addaction name="mActionRecheck"/>
<addaction name="mActionStop"/>
<addaction name="separator"/>
<addaction name="mActionPlatformDefault"/>
<addaction name="mActionPlatformUnix32Bit"/>
<addaction name="mActionPlatformUnix64Bit"/>
<addaction name="mActionPlatformWin32ANSI"/>
<addaction name="mActionPlatformWin32Unicode"/>
<addaction name="mActionPlatformWin64"/>
<addaction name="mActionPlatforms"/>
</widget>
<widget class="QMenu" name="mMenuEdit">
<property name="title">
@ -596,12 +591,15 @@
<string>Windows 64-bit</string>
</property>
</action>
<action name="mActionPlatformDefault">
<action name="mActionPlatforms">
<property name="checkable">
<bool>true</bool>
<bool>false</bool>
</property>
<property name="text">
<string>Default</string>
<string>Platforms</string>
</property>
<property name="visible">
<bool>false</bool>
</property>
</action>
</widget>

View File

@ -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<QAction *>(sender());
if (action)
{
const Settings::PlatformType platform = (Settings::PlatformType) action->data().toInt();
mSettings->setValue(SETTINGS_CHECKED_PLATFORM, platform);
}
}

View File

@ -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:

61
gui/platforms.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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<Platform>::iterator iter = mPlatforms.begin();
while (iter != mPlatforms.end())
{
if ((*iter).mType == platform)
{
return *iter;
}
}
return mPlatforms.first();
}

59
gui/platforms.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef PLATFORMS_H
#define PLATFORMS_H
#include <QObject>
#include <QString>
#include <QList>
#include <QAction>
#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<Platform> mPlatforms;
};
/// @}
#endif // PLATFORMS_H