MIRA
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SelectionListDialog< T > Class Template Reference

A dialog for providing the a list, where the items can be grouped in categories. More...

#include <widgets/SelectionListDialog.h>

Inheritance diagram for SelectionListDialog< T >:
Inheritance graph
[legend]

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
 

Detailed Description

template<typename T>
class mira::SelectionListDialog< T >

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;

Constructor & Destructor Documentation

◆ SelectionListDialog()

SelectionListDialog ( QWidget *  parent = 0)
inline

Member Function Documentation

◆ setHeaderLabels()

void setHeaderLabels ( const QStringList &  labels)
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.

◆ addItem() [1/2]

void addItem ( const QStringList &  labels,
data = T(),
bool  selected = false 
)
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.

◆ addItem() [2/2]

void addItem ( const QString &  category,
const QStringList &  labels,
data = T(),
bool  selected = false 
)
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.

◆ accept()

void accept ( )
inlinevirtual

◆ setSelectOnlyOneItemPerCategory()

void setSelectOnlyOneItemPerCategory ( bool  onlyOne)
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.

◆ setMultiSelection()

void setMultiSelection ( bool  enable)
inline

◆ selectedItems()

std::list< std::pair< QString, T > > selectedItems ( ) const
inline

Returns a list containing the selected items as pairs of strings and the data that was assigned in addItem().

As string the first label that was set in addItem() is given. If the name field is enabled the string is the string that was entered by the user into the name field.

◆ addCategory()

QTreeWidgetItem * addCategory ( const QString &  category)
inlineprotected

Member Data Documentation

◆ mAdditionalContentLayout

QVBoxLayout* mAdditionalContentLayout
protected

◆ mButtonBox

QDialogButtonBox* mButtonBox
protected

◆ mTreeWidget

QTreeWidget* mTreeWidget
protected

◆ mOnlyOnePerCategory

bool mOnlyOnePerCategory
protected

◆ mCategories

std::map<QString, QTreeWidgetItem*> mCategories
protected

◆ mItems

std::map<const QTreeWidgetItem*, T> mItems
protected

The documentation for this class was generated from the following file: