OpenWalnut  1.5.0dev
WQtModuleConfig.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 WQTMODULECONFIG_H
26 #define WQTMODULECONFIG_H
27 
28 #include <map>
29 #include <vector>
30 #include <string>
31 
32 #include <QAction>
33 #include <QDialog>
34 #include <QListWidget>
35 #include <QCheckBox>
36 #include <QComboBox>
37 
38 #include "core/kernel/WModule.h"
39 
40 /**
41  * A class which acts as a binary predicate to check exclusion of modules by name using a whitelist and a blacklist. It automatically handles the
42  * settings for it and provides proper QActions.
43  */
44 class WQtModuleConfig: public QDialog
45 {
46  Q_OBJECT
47 public:
48  /**
49  * Constructs excluder dialog and loads needed settings.
50  *
51  * \param parent parent widget
52  * \param f window flags
53  */
54  WQtModuleConfig( QWidget* parent = 0, Qt::WindowFlags f = Qt::WindowFlags() );
55 
56  /**
57  * Destructor.
58  */
59  virtual ~WQtModuleConfig();
60 
61  /**
62  * Checks exclusion by name.
63  *
64  * \param name the name of the module.
65  *
66  * \return true if it should be excluded.
67  */
68  bool operator()( std::string const& name ) const;
69 
70  /**
71  * Checks exclusion by name.
72  *
73  * \param module the module to check. Internally, the name is used.
74  *
75  * \return true if it should be excluded.
76  */
77  bool operator()( WModule::ConstSPtr module ) const;
78 
79  /**
80  * Creates an action instance allowing the configuration.
81  *
82  * \return the action which triggers this dialog
83  */
84  QAction* getConfigureAction() const;
85 
86  /**
87  * This function initializes the path helper by loading the module path settings. This is needed since the pathhelper needs to know all paths
88  * before the GUI really shows up.
89  */
90  static void initPathHelper();
91 
92 signals:
93  /**
94  * Signal getting emitted if the exclusion-lists changes.
95  */
96  void updated();
97 
98 public slots:
99  /**
100  * Uses a modal dialog to allow the user modifying it.
101  */
102  void configure();
103 
104  /**
105  * Hides the dialog, updates the internal lists and emits updated-signal.
106  */
107  virtual void accept();
108 
109  /**
110  * Hides the dialog, does not update the internal lists.
111  */
112  virtual void reject();
113 
114  /**
115  * Add a path to m_pathList;
116  */
117  virtual void addModulePath();
118 
119  /**
120  * Remove the selected item from m_pathList;
121  */
122  virtual void removeModulePath();
123 
124 private slots:
125 
126  /**
127  * Call this notify the remove button whether something is selected in m_pathList or not
128  */
129  virtual void pathListSelectionChanged();
130 
131  /**
132  * Call this to reset all checkboxes in the list of modules
133  */
135 
136  /**
137  * Call this to refresh the list of selected modules, e.g.
138  */
140 
141  /**
142  * Call this to show or hide the preset combobox
143  */
144  void toggleComboboxVisibility( int );
145 
146 protected:
147 private:
148  /**
149  * The list of available modules.
150  */
151  std::vector< WModule::ConstSPtr > m_moduleList;
152 
153  /**
154  * Maps between a name and a checkbox widget.
155  */
156  typedef std::map< std::string, QCheckBox* > ModuleItemMapType;
157 
158  /**
159  * List for all allowed/active modules.
160  */
161  typedef std::vector< std::string > AllowedModuleList;
162 
163  /**
164  * Maps between module name and item.
165  */
167 
168  /**
169  * The list of modules that are allowed
170  */
172 
173  /**
174  * Reloads the whitelist and the blacklist from the QSettings.
175  *
176  * \param defaultModulePaths if true, the module path list is set to default too.
177  */
178  void loadListsFromSettings( bool defaultModulePaths = false );
179 
180  /**
181  * Call this to refresh the combobox items
182  */
183  void refreshComboboxItems();
184 
185  /**
186  * Saves the whitelist and the blacklist to the settings.
187  */
188  void saveListToSettings();
189 
190  /**
191  * This widget contains the allowed module list
192  */
193  QListWidget* m_list;
194 
195  /**
196  * This list widget contains all additional search paths
197  */
198  QListWidget* m_pathList;
199 
200  /**
201  * Checkbox controlling whether all modules should be shown all the time.
202  */
203  QCheckBox* m_showThemAll;
204 
205  /**
206  * Control whether the list is interpreted as black list
207  */
208  QCheckBox* m_asBlackList;
209 
210  /**
211  * Check if you want to use a preset module list
212  */
213  QCheckBox* m_usePreset;
214 
215  /**
216  * Combobox to select a black list
217  */
219 
220  /**
221  * Button responsible for removing the currently selected path in m_pathList.
222  */
223  QPushButton* m_removePathButton;
224 
225 private slots:
226 
227  /**
228  * Triggered by the m_showThemAll checkbox.
229  */
230  void showThemAllUpdated();
231 
232  /**
233  * called by the reset button
234  */
235  void reset();
236 };
237 
238 #endif // WQTMODULECONFIG_H
std::shared_ptr< const WModule > ConstSPtr
Shared pointer to a const WModule.
Definition: WModule.h:111
A class which acts as a binary predicate to check exclusion of modules by name using a whitelist and ...
virtual void pathListSelectionChanged()
Call this notify the remove button whether something is selected in m_pathList or not.
QCheckBox * m_showThemAll
Checkbox controlling whether all modules should be shown all the time.
QPushButton * m_removePathButton
Button responsible for removing the currently selected path in m_pathList.
void configure()
Uses a modal dialog to allow the user modifying it.
QListWidget * m_list
This widget contains the allowed module list.
WQtModuleConfig(QWidget *parent=0, Qt::WindowFlags f=Qt::WindowFlags())
Constructs excluder dialog and loads needed settings.
QListWidget * m_pathList
This list widget contains all additional search paths.
virtual void removeModulePath()
Remove the selected item from m_pathList;.
void resetAllModuleCheckboxes()
Call this to reset all checkboxes in the list of modules.
QCheckBox * m_asBlackList
Control whether the list is interpreted as black list.
std::map< std::string, QCheckBox * > ModuleItemMapType
Maps between a name and a checkbox widget.
void showThemAllUpdated()
Triggered by the m_showThemAll checkbox.
std::vector< WModule::ConstSPtr > m_moduleList
The list of available modules.
static void initPathHelper()
This function initializes the path helper by loading the module path settings.
virtual void accept()
Hides the dialog, updates the internal lists and emits updated-signal.
bool operator()(std::string const &name) const
Checks exclusion by name.
void refreshComboboxItems()
Call this to refresh the combobox items.
void updated()
Signal getting emitted if the exclusion-lists changes.
void reset()
called by the reset button
virtual void addModulePath()
Add a path to m_pathList;.
QComboBox * m_selectPresetBlacklist
Combobox to select a black list.
void loadListsFromSettings(bool defaultModulePaths=false)
Reloads the whitelist and the blacklist from the QSettings.
virtual ~WQtModuleConfig()
Destructor.
std::vector< std::string > AllowedModuleList
List for all allowed/active modules.
QAction * getConfigureAction() const
Creates an action instance allowing the configuration.
QCheckBox * m_usePreset
Check if you want to use a preset module list.
virtual void reject()
Hides the dialog, does not update the internal lists.
void refreshModuleCheckboxes()
Call this to refresh the list of selected modules, e.g.
ModuleItemMapType m_moduleItemMap
Maps between module name and item.
AllowedModuleList m_allowedModules
The list of modules that are allowed.
void toggleComboboxVisibility(int)
Call this to show or hide the preset combobox.
void saveListToSettings()
Saves the whitelist and the blacklist to the settings.