Workspace 6.21.5
Public Member Functions | Related Functions | List of all members
StringSelection Class Reference

Provides a list of strings, one of which will be considered selected. More...

#include <Workspace/DataExecution/DataObjects/stringselection.h>

Inheritance diagram for StringSelection:
[legend]

Public Member Functions

 StringSelection ()
 
 StringSelection (const StringSelection &array)
 
 ~StringSelection () override
 
QString & at (int i)
 
const QString & at (int i) const
 
bool canSerialize () const override
 
void clear ()
 
bool empty () const
 
int find (const QString &str)
 
QString getSelected () const
 
int getSelectedIndex () const
 
QStringList getStrings () const
 
bool load (const SerializedItem &item) override
 
bool operator!= (const StringSelection &s) const
 
StringSelectionoperator= (const StringSelection &list)
 
bool operator== (const StringSelection &s) const
 
QString & operator[] (int index)
 
const QString & operator[] (int index) const
 
void push_back (const QString &str)
 
void reserve (unsigned numItems)
 
bool save (SerializedItem &item) const override
 
void setNotificationAllow (bool b)
 
bool setSelected (const QRegExp &regex)
 
bool setSelected (const QString &str)
 
void setSelected (int index)
 
unsigned size () const
 
void swap (StringSelection &s)
 
- Public Member Functions inherited from Observable
virtual ~Observable ()
 
void attachObserver (Observer &observer)
 
void destroy ()
 
void detachObserver (Observer &observer)
 
void notifyEvent (const ObservableEvent &event)
 
- Public Member Functions inherited from Serialize
virtual ~Serialize ()=default
 
virtual bool canSerialize () const =0
 
virtual bool load (const SerializedItem &item)=0
 
virtual bool save (SerializedItem &item) const =0
 

Related Functions

(Note that these are not member functions.)

void swap (StringSelection &s1, StringSelection &s2)
 

Additional Inherited Members

- Protected Member Functions inherited from Observable
 Observable ()
 
 Observable (const Observable &)
 

Detailed Description

A StringSelection object is like a QStringList except that it also has the concept of a selection from the list of strings held. Something from the list is always considered to be selected except if the list is empty.

One of the main uses of a StringSelection is for providing a selection of choices to the user, typically presented as a combo box. The data object with which the widget is associated is frequently downstream of where the StringSelection is actually created, so to allow upstream entities to be made aware of downstream changes to the selected item in the list the StringSelectionUpdatedEvent is raised whenever the current selection is changed. Operations that provide StringSelection objects on their outputs need to be careful to either handle these events or to pass them upstream through its inputs for something else to handle the event, as appropriate. For this reason, it is not advisable to create data type adaptors from other data types to StringSelection because adaptors are not able to propagate status changes upstream (they only operate directly on DataObject's, not inputs and outputs).

Constructor & Destructor Documentation

◆ StringSelection() [1/2]

◆ StringSelection() [2/2]

StringSelection ( const StringSelection array)

◆ ~StringSelection()

~StringSelection ( )
override

Member Function Documentation

◆ at() [1/2]

QString & at ( int  i)
inline

◆ at() [2/2]

const QString & at ( int  i) const
inline

◆ canSerialize()

bool canSerialize ( ) const
overridevirtual
Returns
True if this object can be serialized.

For objects that can be serialized, the save and load functions will be used to do the serialization. If this function returns false, both load() and save() must also return false.

Implements Serialize.

◆ clear()

void clear ( )

Unconditionally clears the string list and sets the selected index to -1.

◆ empty()

bool empty ( ) const
Returns
True if the list of strings is empty.

◆ find()

int find ( const QString &  str)
Parameters
strThe string to find in the string list.
Returns
The index of the first occurrence of str, or -1 if the string was not found in the list.

◆ getSelected()

QString getSelected ( ) const
Returns
The currently selected string. If the string list is empty, an empty string will be returned.

◆ getSelectedIndex()

int getSelectedIndex ( ) const
Returns
The index of the currently selected string. If the string list is empty, -1 will be returned.

◆ getStrings()

QStringList getStrings ( ) const

◆ load()

bool load ( const SerializedItem item)
overridevirtual
Parameters
itemSupplies the state to be loaded into this object.

This function will load the state of this object from item. For many object types, this is most easily implemented in terms of the object's input operator (>>).

It would be reasonable for subclass implementations to assume that the data provided in item is in the same form as would have been saved from a call to save.

Returns
If the state of the object could not be loaded, the function returns false. A return value of true implies that the object state was successfully loaded. If canSerialize() returns false, this function must do nothing except return false as well.

Implements Serialize.

◆ operator!=()

bool operator!= ( const StringSelection s) const

◆ operator=()

StringSelection & operator= ( const StringSelection list)

◆ operator==()

bool operator== ( const StringSelection s) const
Returns
True if the list of strings and the selected string are both the same for s and this object.

◆ operator[]() [1/2]

QString & operator[] ( int  index)
Returns
The string at the specified index within the list.
Precondition
index must refer to a valid item in the list.

◆ operator[]() [2/2]

const QString & operator[] ( int  index) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ push_back()

void push_back ( const QString &  str)

Append str to the list of strings. If the list was previously empty, str will become the selected string.

◆ reserve()

void reserve ( unsigned  numItems)
Parameters
numItemsThe number of items to reserve memory for.

Clients can (but don't have to) call this function when they have prior knowledge about how many items are likely to be added to the string list. Enough memory to hold numItems will be allocated, thereby eliminating any memory reallocations if no more than numItems are added to the string list. If more than numItems are added, memory reallocation will still occur transparently without error.

◆ save()

bool save ( SerializedItem item) const
overridevirtual
Parameters
itemWhere to save the state of this object.

This function will serialise the object by saving it to item. For most object types, this is most easily implemented in terms of the object's output operator (<<).

It is allowable for an object to only serialize part of itself. This would be useful if the data it represents has a set of defaults and only those values different to the defaults need to be serialized. Such an implementation then needs to be careful how it handles the complimentary load member function.

Returns
If an object could not be serialised or if the underlying object type does not support serialisation, this function should return false. A return value of true implies that the object was successfully saved to item. If canSerialize() returns false, this function must do nothing except return false as well.

Implements Serialize.

◆ setNotificationAllow()

void setNotificationAllow ( bool  b)
Parameters
bTrue if selection change notifications are allowed to be raised.

If the current state does not allow notifications and b is true, a notification will be raised as part of this call.

◆ setSelected() [1/3]

bool setSelected ( const QRegExp &  regex)
Parameters
regexRegular expression representing the string to select.

The first occurrence of regex in the string list will be made the currently selected string. If str does not appear in the string list, the current selection index is left unchanged.

Returns
True if the selected string regex was found and selected, false otherwise.
Note
This function may raise a StringSelectionUpdatedEvent notification before returning. See setSelected(int) for details.
See also
setSelected(int)
setSelected(QString)

◆ setSelected() [2/3]

bool setSelected ( const QString &  str)
Parameters
strThe string to select.

The first occurrence of str in the string list will be made the currently selected string. If str does not appear in the string list, the current selection index is left unchanged.

Returns
True if the selected string str was found and selected, false otherwise.
Note
This function may raise a StringSelectionUpdatedEvent notification before returning. See setSelected(int) for details.
See also
setSelected(int)

◆ setSelected() [3/3]

void setSelected ( int  index)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
indexThe new index to make current. If it is negative or not less than the result of calling size(), it will be ignored.

If the index is different to the currently set selection index, a StringSelectionUpdatedEvent notification will be raised before returning. This is true even if the string at the old and new index are both the same.

See also
setSelected(const String&)

◆ size()

unsigned size ( ) const
Returns
The number of strings in the string list.

◆ swap()

void swap ( StringSelection s)

Swaps the contents of this string list with s by swapping the private implementation objects. This is must faster than a deep copy of either string list.

If the index of the selected string in s is different to the currently set selection index, a StringSelectionUpdatedEvent notification will be raised before returning.

Friends And Related Function Documentation

◆ swap()

void swap ( StringSelection s1,
StringSelection s2 
)
related

Swaps the contents of s1 and s2 by simply swapping their private implementation objects. This is much faster than a deep copy of either string list and preserves observers on both lists. Both lists will receive selection event notifications if the selection of either one changes as a result of the swap.