OpenWalnut
1.5.0dev
|
This class represents a subset of a WItemSelection. More...
#include <WItemSelector.h>
Public Types | |
typedef std::vector< size_t > | IndexList |
The type used for storing index lists. More... | |
Public Member Functions | |
WItemSelector (const WItemSelector &other) | |
Copy constructor. More... | |
WItemSelector & | operator= (const WItemSelector &other) |
Copy assignment. More... | |
virtual | ~WItemSelector () |
Destructor. More... | |
WItemSelector | newSelector (IndexList selected) const |
Creates a new valid instance with the specified items selected. More... | |
WItemSelector | newSelector (size_t selected) const |
Creates a new valid instance with the specified items selected. More... | |
WItemSelector | newSelector (const std::string asString) const |
Creates a new valid instance with the specified items selected. More... | |
WItemSelector | newSelector () const |
Creates a new selector, but basing on this instance as old one. More... | |
bool | operator== (const WItemSelector &other) const |
Compares two selector. More... | |
std::ostream & | operator<< (std::ostream &out) const |
Write a selection in string representation to the given output stream. More... | |
virtual size_t | sizeAll () const |
Gives the count of elements in the set of selectable items. More... | |
virtual size_t | size () const |
The number of selected items. More... | |
virtual bool | empty () const |
True if the selection is empty. More... | |
virtual const std::shared_ptr< WItemSelectionItem > | atAll (size_t index) const |
Gets the item with the given index from the WItemSelection. More... | |
virtual const std::shared_ptr< WItemSelectionItem > | at (size_t index) const |
Gets the selected item with the given index. More... | |
virtual size_t | getItemIndexOfSelected (size_t index) const |
Helps to get the index of an selected item in the WItemSelection. More... | |
virtual bool | isValid () const |
Checks whether the selection is valid anymore. More... | |
void | lock () |
Read locks the underlying selection. More... | |
void | unlock () |
Unlocks the selection again. More... | |
operator unsigned int () const | |
Allow cast from selector to unsigned int. More... | |
IndexList | getIndexList () const |
Casts the selector to a list of indices currently selected. More... | |
Protected Member Functions | |
WItemSelector (std::shared_ptr< WItemSelection > selection, IndexList selected) | |
Constructor creates an selector for the specified selection of items. More... | |
Protected Attributes | |
std::shared_ptr< WItemSelection > | m_selection |
The selection handled by this selector. More... | |
IndexList | m_selected |
The list of items currently selected. More... | |
boost::signals2::connection | m_invalidateSignalConnection |
Stores the connection made using WItemSelection::subscribeInvalidateSignal. More... | |
Private Member Functions | |
WItemSelector | createSelector (const IndexList &selected) const |
Creates a new selector instance using the specified index list. More... | |
void | invalidate () |
Handles the case of invalidation. More... | |
Private Attributes | |
bool | m_valid |
If true the selector is valid. More... | |
WItemSelection::ReadTicket | m_lock |
This locks prevents the selection to be modified during selector iteration. More... | |
Friends | |
class | WItemSelection |
Only class allowed to instanciate this class. More... | |
This class represents a subset of a WItemSelection.
It is a class for managing selections. The class is kept very restrictive. The selection can't be edited after the instantiation of the class to keep the interface clean, easily usable and consistent among multiple threads. So please DO NOT extend it to provide methods for changing it!
This class can be seen as some kind of special "iterator" providing access to the underlying set without allowing it to be modified. The class provides methods to access the whole set and the subset represented by itself. The restrictive interface ensures thread-safety and enforces that each new selection is done by a new instance of this class, which is needed by the WPropertyVariable to work properly.
Definition at line 52 of file WItemSelector.h.
typedef std::vector< size_t > WItemSelector::IndexList |
The type used for storing index lists.
It is a list of integer correlating with the elements in the managed WItemSelection class.
Definition at line 59 of file WItemSelector.h.
WItemSelector::WItemSelector | ( | const WItemSelector & | other | ) |
Copy constructor.
Creates a new copy of the selector and ensure proper signal subscriptions to the underlying selection.
other | the selector to copy |
Definition at line 43 of file WItemSelector.cpp.
References invalidate(), m_invalidateSignalConnection, and m_selection.
Referenced by createSelector().
|
virtual |
Destructor.
Definition at line 66 of file WItemSelector.cpp.
References m_invalidateSignalConnection.
|
protected |
Constructor creates an selector for the specified selection of items.
Noting is selected after construction.
selection | the selection handled by this instance |
selected | the set of selected items |
Definition at line 33 of file WItemSelector.cpp.
References invalidate(), m_invalidateSignalConnection, and m_selection.
|
virtual |
Gets the selected item with the given index.
This is not the same index as the element has in the corresponding WItemSelection! This method is especially useful to iterate the through the selected items.
index | the index |
Definition at line 151 of file WItemSelector.cpp.
References getItemIndexOfSelected(), and m_selection.
Referenced by WMPickingDVREvaluation::interactionMapping(), WFilterPropertyHandler::isPDGTypeSelected(), WMPickingDVREvaluation::moduleMain(), WMTemplate::moduleMain(), WMCoordinateSystem::propertyChanged(), WColumnPropertyHandler::propertyNotifier(), WFilterPropertyHandler::selectPdgAndSaveEvent(), and WFilterPropertyHandler::setDefaultForRenameField().
|
virtual |
Gets the item with the given index from the WItemSelection.
This index does not equal the index of the same item for at. This method is useful to go through the list of ALL items (not only the selected).
index | the index |
Definition at line 146 of file WItemSelector.cpp.
References m_selection.
Referenced by WPropertySelectionWidget::update().
|
private |
Creates a new selector instance using the specified index list.
Handles all needed signal subscription stuff.
selected | the index list of selected items |
Definition at line 176 of file WItemSelector.cpp.
References m_selection, and WItemSelector().
Referenced by newSelector().
|
virtual |
True if the selection is empty.
Definition at line 161 of file WItemSelector.cpp.
References size().
Referenced by WFilterPropertyHandler::setDefaultForRenameField().
WItemSelector::IndexList WItemSelector::getIndexList | ( | ) | const |
Casts the selector to a list of indices currently selected.
It contains the list of index in the corresponding WItemSelection. This is especially useful if the whole index list is needed without nasty iterations.
Definition at line 199 of file WItemSelector.cpp.
References m_selected.
Referenced by WGEShaderPropertyDefineOptionsIndexAdapter< WPropSelection >::operator()().
|
virtual |
Helps to get the index of an selected item in the WItemSelection.
This is somehow similar to at, but does not return the item but the index to it.
index | the index in the selection (not the item index in WItemSelection) |
Definition at line 156 of file WItemSelector.cpp.
References m_selected.
Referenced by at(), WMCoordinateSystem::findBoundingBox(), WMScalarSegmentation::moduleMain(), WMTriangleMeshRenderer::moduleMain(), WMCoordinateSystem::propertyChanged(), WMSurfaceIllustrator::renderMesh(), WMTriangleMeshRenderer::renderMesh(), WPropertySelectionWidget::update(), and WMGridRenderer::updateNode().
|
private |
Handles the case of invalidation.
Definition at line 166 of file WItemSelector.cpp.
References m_valid.
Referenced by operator=(), and WItemSelector().
|
virtual |
Checks whether the selection is valid anymore.
If a selector is not valid anymore, you should ask the one providing the selectors (most probably a WPropSelection) for a new one.
Definition at line 171 of file WItemSelector.cpp.
References m_valid.
void WItemSelector::lock | ( | ) |
Read locks the underlying selection.
This ensure, that the selection stays fixed as long as this selector is locked. This also ensures that no invalidation can be issued as long as this selector has the lock. BUT it is possible that an invalidation occurs while this selector waits. So please always check for validity of the selector ater locking.
Definition at line 182 of file WItemSelector.cpp.
References m_lock, and m_selection.
Referenced by WPropertySelectionWidget::update().
WItemSelector WItemSelector::newSelector | ( | ) | const |
Creates a new selector, but basing on this instance as old one.
The new selector tries to keep the old selection but makes the internal selection list valid with the current underlying selection.
Definition at line 98 of file WItemSelector.cpp.
References m_selected, m_selection, and m_valid.
WItemSelector WItemSelector::newSelector | ( | const std::string | asString | ) | const |
Creates a new valid instance with the specified items selected.
This is especially useful to simply create a new selection if only the string representing it is known. This somehow correlates to the << operator.
asString | the selected items |
Definition at line 84 of file WItemSelector.cpp.
References createSelector(), and string_utils::tokenize().
WItemSelector WItemSelector::newSelector | ( | IndexList | selected | ) | const |
Creates a new valid instance with the specified items selected.
This is especially useful to simply create a new selection if only the old selection is known.
selected | the selected items (their index in WItemSelection). |
Definition at line 72 of file WItemSelector.cpp.
References createSelector().
Referenced by PROPERTY_TYPE_HELPER::WStringConversion< WPVBaseTypes::PV_SELECTION >::create(), and WMGridRenderer::properties().
WItemSelector WItemSelector::newSelector | ( | size_t | selected | ) | const |
Creates a new valid instance with the specified items selected.
This can be useful to add a certain index. The new selector has the selection from this AND the specified one. If you want to create a selector containing only one selected item, use the method that uses the IndexList.
selected | the selected item (the index in WItemSelection). |
Definition at line 77 of file WItemSelector.cpp.
References createSelector(), and m_selected.
WItemSelector::operator unsigned int | ( | ) | const |
Allow cast from selector to unsigned int.
Definition at line 194 of file WItemSelector.cpp.
std::ostream & WItemSelector::operator<< | ( | std::ostream & | out | ) | const |
Write a selection in string representation to the given output stream.
out | the output stream where to put the information |
Definition at line 113 of file WItemSelector.cpp.
References m_selected.
WItemSelector & WItemSelector::operator= | ( | const WItemSelector & | other | ) |
Copy assignment.
Creates a new copy of the selector and ensure proper signal subscriptions to the underlying selection.
other | the selector to copy |
Definition at line 51 of file WItemSelector.cpp.
References invalidate(), m_invalidateSignalConnection, m_selected, m_selection, and m_valid.
bool WItemSelector::operator== | ( | const WItemSelector & | other | ) | const |
Compares two selector.
They are assumed to be equal if the selected items are equal and if the underlying WItemSelection is the same.
other | the selector |
Definition at line 131 of file WItemSelector.cpp.
References m_selected, m_selection, and m_valid.
|
virtual |
The number of selected items.
Definition at line 141 of file WItemSelector.cpp.
References m_selected.
Referenced by empty(), WFilterPropertyHandler::isPDGTypeSelected(), WMTemplate::moduleMain(), WPropertySelectionWidget::update(), and WMGridRenderer::updateNode().
|
virtual |
Gives the count of elements in the set of selectable items.
This is size + number of unselected items.
Definition at line 136 of file WItemSelector.cpp.
References m_selection.
Referenced by WPropertySelectionWidget::update().
void WItemSelector::unlock | ( | ) |
Unlocks the selection again.
Always call this after a lock.
Definition at line 189 of file WItemSelector.cpp.
References m_lock.
|
friend |
Only class allowed to instanciate this class.
Definition at line 54 of file WItemSelector.h.
|
protected |
Stores the connection made using WItemSelection::subscribeInvalidateSignal.
Definition at line 259 of file WItemSelector.h.
Referenced by operator=(), WItemSelector(), and ~WItemSelector().
|
private |
This locks prevents the selection to be modified during selector iteration.
Definition at line 284 of file WItemSelector.h.
|
protected |
The list of items currently selected.
Definition at line 254 of file WItemSelector.h.
Referenced by getIndexList(), getItemIndexOfSelected(), newSelector(), operator<<(), operator=(), operator==(), and size().
|
protected |
The selection handled by this selector.
Definition at line 249 of file WItemSelector.h.
Referenced by at(), atAll(), createSelector(), lock(), newSelector(), operator=(), operator==(), sizeAll(), and WItemSelector().
|
private |
If true the selector is valid.
Definition at line 279 of file WItemSelector.h.
Referenced by invalidate(), isValid(), newSelector(), operator=(), and operator==().