OpenWalnut  1.5.0dev
WSettingAction.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WSETTINGACTION_H
26 #define WSETTINGACTION_H
27 
28 #include <string>
29 
30 #include <QAction>
31 #include <QMessageBox>
32 
33 #ifndef Q_MOC_RUN
34 // There is an issue with the moc compiler and some boost headers where
35 // moc for qt versions < 5.0 is not able to do a macro substitution.
36 // The issue occurs in the boost library versions 1.48 and higher,
37 // and is tested in boost version 1.52 using moc version 4.8.4
38 // Excluding the relevant headers removes the problem.
39 #include "WQtGui.h"
40 #endif
41 
42 class WMainWindow;
43 
44 /**
45  * Class to handle a certain setting with an action. The action is associated with a QSettings value. Please note, that this class is not able to
46  * handle async changes in the QSettings object. So, try to avoid multiple actions for one setting.
47  */
48 class WSettingAction: public QAction
49 {
50  Q_OBJECT
51 
52 public:
53  /**
54  * Constructs an action which handles a certain setting.
55  *
56  * \param parent the parent handling this
57  * \param settingName the name of the setting to handle
58  * \param actionName the name of the action
59  * \param defaultValue the default if setting not existing
60  * \param tooltip the tooltip text
61  * \param showRestartInfo if true, info dialog is shown which says that a restart is needed
62  * \param shortcut the shortcut keysequence
63  */
64  WSettingAction( QObject* parent, std::string settingName, std::string actionName, std::string tooltip, bool defaultValue,
65  bool showRestartInfo = false, const QKeySequence& shortcut = 0 );
66 
67  /**
68  * Destructor.
69  */
70  virtual ~WSettingAction();
71 
72  /**
73  * Gets the current state.
74  *
75  * \return state
76  */
77  bool get() const;
78 
79 signals:
80 
81  /**
82  * This signal is emitted if this setting changes.
83  *
84  * \param value the new setting value.
85  */
86  void change( bool value );
87 
88 protected:
89 private:
90  /**
91  * The name of the setting handled here.
92  */
93  QString m_settingName;
94 
95  /**
96  * If true, a change of the setting causes an restart notification dialog.
97  */
99 
100 private slots:
101 
102  /**
103  * The state has changed by the action. Handled here.
104  *
105  * \param state the state
106  */
107  void stateChange( bool state );
108 };
109 
110 #endif // WSETTINGACTION_H
111 
This class contains the main window and the layout of the widgets within the window.
Definition: WMainWindow.h:66
Class to handle a certain setting with an action.
WSettingAction(QObject *parent, std::string settingName, std::string actionName, std::string tooltip, bool defaultValue, bool showRestartInfo=false, const QKeySequence &shortcut=0)
Constructs an action which handles a certain setting.
bool get() const
Gets the current state.
virtual ~WSettingAction()
Destructor.
QString m_settingName
The name of the setting handled here.
void stateChange(bool state)
The state has changed by the action.
bool m_showRestartInfo
If true, a change of the setting causes an restart notification dialog.
void change(bool value)
This signal is emitted if this setting changes.