MIRA
|
A dialog for providing the a list, where the items can be grouped in categories. More...
#include <widgets/SelectionListDialog.h>
Public Member Functions | |
SelectionListDialog (QWidget *parent=0) | |
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... | |
void | setMultiSelection (bool enable) |
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 one or more 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 one or more items, the selected items can be retrieved using the selectedItems() method. It returns strings-data pairs, that contain the first label of the selected items and their assigned data.
By default multiple selection is disabled. It can be enabled after constructing the dialog by calling the setMultiSelection() method.
Example: SelectionListDialog<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(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;
auto selection = d.selectedItems(); if(selection.empty()) return; // nothing chosen
// show the assigned int to the data that was chosen (111 or 222) std::cout << selection.begin()->second << std::endl;
|
inline |
|
inline |
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.
|
inline |
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.
|
inline |
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.
|
inlinevirtual |
|
inline |
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.
|
inline |
|
inline |
|
inlineprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |