OpenWalnut  1.5.0dev
WQtCombinerActionList.cpp
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 #include "WQtCombinerActionList.h"
26 
27 WQtCombinerActionList::WQtCombinerActionList( QWidget* parent, WIconManager* icons, WCombinerTypes::WCompatiblesList compatibles,
28  const WQtModuleConfig* exclusionPredicate, bool advancedText ):
29  QList< QAction* >()
30 {
31  // create an action for each group:
32  for( WCombinerTypes::WCompatiblesList::iterator groups = compatibles.begin(); groups != compatibles.end(); ++groups )
33  {
34  // check current prototype against whitelist and blacklist
35  if( exclusionPredicate && exclusionPredicate->operator()( groups->first ) )
36  {
37  continue;
38  }
39  // create a new action for this group
40  WQtModuleOneToOneCombinerAction* group = new WQtModuleOneToOneCombinerAction( parent, icons, *groups->second.begin(), advancedText );
41 
42  group->setIconVisibleInMenu( true );
43  push_back( group );
44 
45  // only add a sub menu if there are more than 1 items in the group
46  if( ( *groups ).second.size() > 1 )
47  {
48  QMenu* groupMenu = new QMenu( parent );
49  // iterate all the children
50  for( WCombinerTypes::WOneToOneCombiners::iterator combiner = ( *groups ).second.begin();
51  combiner != ( *groups ).second.end(); ++combiner )
52  {
53  WQtModuleOneToOneCombinerAction* a = new WQtModuleOneToOneCombinerAction( parent, icons, *combiner, true );
54 
55  a->setIconVisibleInMenu( true );
56  groupMenu->addAction( a );
57  }
58  group->setMenu( groupMenu );
59  }
60  }
61 }
62 
63 WQtCombinerActionList::WQtCombinerActionList( QWidget* parent, WIconManager* icons, WCombinerTypes::WDisconnectList disconnects ):
64  QList< QAction* >()
65 {
66  // create an action for each group:
67  for( WCombinerTypes::WDisconnectList::iterator groups = disconnects.begin(); groups != disconnects.end(); ++groups )
68  {
69  // create a new action for this group
70  WQtModuleOneToOneCombinerAction* group = new WQtModuleOneToOneCombinerAction( parent, icons, *groups->second.begin(), true );
71 
72  group->setIconVisibleInMenu( true );
73  push_back( group );
74 
75  // only add a sub menu if there are more than 1 items in the group
76  if( ( *groups ).second.size() > 1 )
77  {
78  QMenu* groupMenu = new QMenu( parent );
79  // iterate all the children
80  for( WCombinerTypes::WOneToOneCombiners::iterator combiner = ( *groups ).second.begin();
81  combiner != ( *groups ).second.end(); ++combiner )
82  {
83  WQtModuleOneToOneCombinerAction* a = new WQtModuleOneToOneCombinerAction( parent, icons, *combiner, true );
84 
85  a->setIconVisibleInMenu( true );
86  groupMenu->addAction( a );
87  }
88  group->setMenu( groupMenu );
89  }
90  }
91 }
92 
94  QList< QAction* >()
95 {
96  // do nothing here
97 }
98 
100 {
101  // cleanup
102  clear();
103 }
104 
Manages icon access.
Definition: WIconManager.h:41
WQtCombinerActionList()
Creates a completely empty list.
virtual ~WQtCombinerActionList()
Destructor.
A class which acts as a binary predicate to check exclusion of modules by name using a whitelist and ...
Implements a action which applies the specified combiners (of the specified group) if pressed.