MIRA
|
A dialog for providing the a list, where the items can be grouped in categories. More...
#include <widgets/SingleSelectionListDialog.h>
Public Member Functions | |
SingleSelectionListDialog (QWidget *parent=0) | |
void | setMultiSelection (bool enable) |
std::pair< QString, T > | selectedItem () const |
Returns a pairs of a string and the data that was assigned in addItem(). More... | |
bool | hasSelection () const |
Returns true, if an item was selected. More... | |
void | setHeaderLabels (const QStringList &labels) |
Sets the labels of the columns. More... | |
void | addItem (const QStringList &labels, T data=T(), bool selected=false) |
Adds a new item to the list. More... | |
void | addItem (const QString &category, const QStringList &labels, T data=T(), bool selected=false) |
Adds a new item to the list into the specified category. More... | |
virtual void | accept () |
void | setSelectOnlyOneItemPerCategory (bool onlyOne) |
If set to true the user is allowed to only select one item per category. More... | |
std::list< std::pair< QString, T > > | selectedItems () const |
Returns a list containing the selected items as pairs of strings and the data that was assigned in addItem(). More... | |
Protected Member Functions | |
QTreeWidgetItem * | addCategory (const QString &category) |
Protected Attributes | |
QVBoxLayout * | mAdditionalContentLayout |
QDialogButtonBox * | mButtonBox |
QTreeWidget * | mTreeWidget |
bool | mOnlyOnePerCategory |
std::map< QString, QTreeWidgetItem * > | mCategories |
std::map< const QTreeWidgetItem *, T > | mItems |
A dialog for providing the a list, where the items can be grouped in categories.
The user can choose a single items from the list.
After constructing the dialog and before showing or executing the dialog, items can be added using the addItem() methods. Arbitrary data can be assigned to each item that is added to the list. For this reason, this is a template class. The template parameter must be set to the type of the data that is assigned.
After the dialog is shown and the user selected the item, the selected items can be retrieved using the selectedItem() method. It returns a strings-data pair, that contain the first label of the selected items and their assigned data.
Example: SingleSelectionListDialog<int> d(this); d.setWindowTitle(tr("Choose a something")); d.setHeaderLabels(QStringList() << "The item" << "Some Description"); d.resize(600,400);
// add item without category and assign 111 as data d.addItem("Some Category", QStringList() << "Item 1" << "Description 1", 111);
// add item into a category and assign 222 as data d.addItem("Some Category", QStringList() << "Item 2" << "Description 2", 222);
// execute as modal dialog if(d.exec()==0) return;
if(!d.hasSelectedItem()) return; // nothing chosen
// show the assigned int to the data that was chosen (111 or 222) std::cout << d.selectedItem().first.toStdString() << d.selectedItem().second << std::endl;
|
inline |
|
inline |
|
inline |
|
inline |
Returns true, if an item was selected.
|
inlineinherited |
Sets the labels of the columns.
The number of columns is arbitrary. However, the number of labels added here must be equal to the number of labels that is passed to the addItem methods.
|
inlineinherited |
Adds a new item to the list.
The number of labels must be equal through all addItem calls and the call to setHeaderLabels. Additional, data can be assigned to each item. The type of that data must be specified as template parameter of this template class.
|
inlineinherited |
Adds a new item to the list into the specified category.
The number of labels must be equal through all addItem calls and the call to setHeaderLabels. Additional, data can be assigned to each item. The type of that data must be specified as template parameter of this template class.
|
inlinevirtualinherited |
|
inlineinherited |
If set to true the user is allowed to only select one item per category.
The selected items are checked when the user clicks on OK and if more than one item per category is selected an appropriate error message is shown.
|
inlineinherited |
|
inlineprotectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |