OpenWalnut  1.5.0dev
WQtCombinerActionList.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 WQTCOMBINERACTIONLIST_H
26 #define WQTCOMBINERACTIONLIST_H
27 
28 #include <string>
29 #include <vector>
30 
31 #include <QMenu>
32 #include <QtCore/QList>
33 #include <QAction>
34 #include <QWidget>
35 
36 #include "core/kernel/combiner/WApplyCombiner.h"
37 #include "core/kernel/combiner/WModuleOneToOneCombiner.h"
38 #include "core/kernel/WModuleCombinerTypes.h"
39 #include "core/kernel/WModule.h"
40 #include "core/kernel/WModuleCombiner.h"
41 #include "guiElements/WQtModuleOneToOneCombinerAction.h"
42 #include "WQtGui.h"
43 #include "WQtModuleConfig.h"
44 
45 #include "WIconManager.h"
46 
47 /**
48  * This class represents a list of actions to apply a bunch of modules to others. It basically interprets the WCompatiblesList or WDisconnectList and
49  * builds a list of appropriate actions. It can be used to build menus, toolbars and so on.
50  */
51 class WQtCombinerActionList: public QList< QAction* >
52 {
53 public:
54  /**
55  * This constructor creates a list of actions recursively from the specified compatibles list.
56  * \param parent the parent widget of this widget, i.e. the widget that manages it.
57  * \param icons the icon manager holding the right icons for all the prototypes
58  * \param compatibles the list of combiners
59  * \param advancedText if true, the complete connector/module name is displayed in all actions
60  * \param exclusionPredicate a predicate which checks for each module whether to exclude it or not. If 0, nothing is excluded.
61  *
62  * \tparam PredicateT the predicate used for excluding modules
63  */
64  WQtCombinerActionList( QWidget* parent, WIconManager* icons, WCombinerTypes::WCompatiblesList compatibles,
65  const WQtModuleConfig* exclusionPredicate = 0, bool advancedText = false );
66  /**
67  * This constructor creates a list of actions recursively from the specified disconnects list.
68  * \param parent the parent widget of this widget, i.e. the widget that manages it.
69  * \param icons the icon manager holding the right icons for all the prototypes
70  * \param disconnects the list of disconnections
71  */
72  WQtCombinerActionList( QWidget* parent, WIconManager* icons, WCombinerTypes::WDisconnectList disconnects );
73 
74  /**
75  * Creates a completely empty list.
76  */
78 
79  /**
80  * Destructor.
81  */
82  virtual ~WQtCombinerActionList();
83 
84  /**
85  * Clears a hierarchy of QActions in a list. This deeply clears and deletes the lists.
86  *
87  * \param l the list to clear and delete
88  */
89  static void deepDeleteActionList( QList< QAction* >& l ) // NOLINT - we need the non-const ref here.
90  {
91  // traverse
92  for( QList< QAction* >::iterator it = l.begin(); it != l.end(); ++it )
93  {
94  if( ( *it )->menu() )
95  {
96  // recursively remove sub-menu items
97  QList< QAction* > subs = ( *it )->menu()->actions();
98  deepDeleteActionList( subs );
99  }
100 
101  delete ( *it );
102  }
103 
104  // remove items afterwards
105  l.clear();
106  }
107 
108 protected:
109 private:
110 };
111 
112 #endif // WQTCOMBINERACTIONLIST_H
113 
Manages icon access.
Definition: WIconManager.h:41
This class represents a list of actions to apply a bunch of modules to others.
WQtCombinerActionList()
Creates a completely empty list.
virtual ~WQtCombinerActionList()
Destructor.
static void deepDeleteActionList(QList< QAction * > &l)
Clears a hierarchy of QActions in a list.
A class which acts as a binary predicate to check exclusion of modules by name using a whitelist and ...