Workspace 6.21.5
|
Provides a list of strings, one of which will be considered selected. More...
#include <Workspace/DataExecution/DataObjects/stringselection.h>
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 |
StringSelection & | operator= (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 ®ex) |
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 &) | |
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).
StringSelection | ( | ) |
StringSelection | ( | const StringSelection & | array | ) |
|
override |
|
inline |
|
inline |
|
overridevirtual |
void clear | ( | ) |
Unconditionally clears the string list and sets the selected index to -1.
bool empty | ( | ) | const |
int find | ( | const QString & | str | ) |
str | The string to find in the string list. |
QString getSelected | ( | ) | const |
int getSelectedIndex | ( | ) | const |
QStringList getStrings | ( | ) | const |
|
overridevirtual |
item | Supplies 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.
Implements Serialize.
bool operator!= | ( | const StringSelection & | s | ) | const |
StringSelection & operator= | ( | const StringSelection & | list | ) |
bool operator== | ( | const StringSelection & | s | ) | const |
QString & operator[] | ( | int | index | ) |
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.
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.
void reserve | ( | unsigned | numItems | ) |
numItems | The 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.
|
overridevirtual |
item | Where 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.
Implements Serialize.
void setNotificationAllow | ( | bool | b | ) |
b | True 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.
bool setSelected | ( | const QRegExp & | regex | ) |
regex | Regular 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.
bool setSelected | ( | const QString & | str | ) |
str | The 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.
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.
index | The 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.
unsigned size | ( | ) | const |
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.
|
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.