OpenWalnut  1.4.0
WItemSelection.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 WITEMSELECTION_H
26 #define WITEMSELECTION_H
27 
28 #include <vector>
29 #include <string>
30 #include <utility>
31 
32 #ifndef Q_MOC_RUN
33 #include <boost/tuple/tuple.hpp>
34 #endif
35 #ifndef Q_MOC_RUN
36 #include <boost/shared_ptr.hpp>
37 #endif
38 #ifndef Q_MOC_RUN
39 #include <boost/signals2/signal.hpp>
40 #endif
41 #ifndef Q_MOC_RUN
42 #include <boost/enable_shared_from_this.hpp>
43 #endif
44 
45 #include "WSharedSequenceContainer.h"
46 #include "WItemSelectionItem.h"
47 
48 class WItemSelector;
49 
50 /**
51  * A class containing a list of named items. It is mainly a container for an std::vector but with the difference that there can be so called
52  * Selectors which are able to select some subset of the item set. This is especially useful in properties where item selection is needed. The
53  * class is kept very restrictive to keep the interface clean and sleek and to keep the item set consistent among several threads. So please do
54  * not implement any function that might change the item list, use the provided ones. If the item list changes, existing selectors get invalid
55  * automatically using the change condition of the inherited WSharedSequenceContainer.
56  */
57 class WItemSelection: public boost::enable_shared_from_this< WItemSelection >,
58  public WSharedSequenceContainer< std::vector< boost::shared_ptr< WItemSelectionItem > > >
59 {
60  friend class WItemSelector; // for proper locking and unlocking
61 public:
62  /**
63  * Convenience typedef for a boost::shared_ptr< WItemSelection >
64  */
65  typedef boost::shared_ptr< WItemSelection > SPtr;
66 
67  /**
68  * Convenience typedef for a boost::shared_ptr< const WItemSelection >
69  */
70  typedef boost::shared_ptr< const WItemSelection > ConstSPtr;
71 
72  /**
73  * Default constructor.
74  */
76 
77  /**
78  * Destructor.
79  */
80  virtual ~WItemSelection();
81 
82  /**
83  * Creates an default selection (all items selected). The selector gets invalid if another item is added.
84  *
85  * \return an selector.
86  */
87  virtual WItemSelector getSelectorAll();
88 
89  /**
90  * Creates an default selection (no items selected). The selector gets invalid if another item is added.
91  *
92  * \return an selector.
93  */
95 
96  /**
97  * Creates an default selection (first item selected). The selector gets invalid if another item is added.
98  *
99  * \return an selector.
100  */
102 
103  /**
104  * Creates an default selection (last item selected). The selector gets invalid if another item is added.
105  *
106  * \return an selector.
107  */
108  virtual WItemSelector getSelectorLast();
109 
110  /**
111  * Creates an default selection (a specified items selected). The selector gets invalid if another item is added.
112  *
113  * \param item the item to select.
114  *
115  * \return an selector.
116  */
117  virtual WItemSelector getSelector( size_t item );
118 
119  /**
120  * Convenience method to create a new item.
121  *
122  * \param name name of the item
123  * \param description the description, can be empty
124  * \param icon the icon, can be NULL
125  *
126  * \return the Item.
127  */
128  static boost::shared_ptr< WItemSelectionItem > Item( std::string name, std::string description = "", const char** icon = NULL )
129  {
130  return boost::shared_ptr< WItemSelectionItem >( new WItemSelectionItem( name, description, icon ) );
131  }
132 
133  /**
134  * Convenience method to add a new item.
135  *
136  * \param name name of the item
137  * \param description the description, can be empty
138  * \param icon the icon, can be NULL
139  *
140  */
141  void addItem( std::string name, std::string description = "", const char** icon = NULL );
142 
143  /**
144  * Method to add a new item, which can be derived from WItemSelectionItem.
145  *
146  * \param item WItemSelectionItem or derivation which should be add.
147  */
148  void addItem( boost::shared_ptr< WItemSelectionItem > item );
149 
150 private:
151 };
152 
153 #endif // WITEMSELECTION_H
154 
void addItem(std::string name, std::string description="", const char **icon=NULL)
Convenience method to add a new item.
boost::shared_ptr< WItemSelection > SPtr
Convenience typedef for a boost::shared_ptr< WItemSelection >
This class provides a common interface for thread-safe access to sequence containers (list...
virtual WItemSelector getSelectorAll()
Creates an default selection (all items selected).
virtual WItemSelector getSelectorNone()
Creates an default selection (no items selected).
static boost::shared_ptr< WItemSelectionItem > Item(std::string name, std::string description="", const char **icon=NULL)
Convenience method to create a new item.
virtual WItemSelector getSelector(size_t item)
Creates an default selection (a specified items selected).
virtual ~WItemSelection()
Destructor.
virtual WItemSelector getSelectorLast()
Creates an default selection (last item selected).
A class containing a list of named items.
This class represents a subset of a WItemSelection.
Definition: WItemSelector.h:56
virtual WItemSelector getSelectorFirst()
Creates an default selection (first item selected).
boost::shared_ptr< const WItemSelection > ConstSPtr
Convenience typedef for a boost::shared_ptr< const WItemSelection >
Class for keeping a single named item in a WItemSelection.
WItemSelection()
Default constructor.