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

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

#include <widgets/SingleSelectionListDialog.h>

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

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
 

Detailed Description

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

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;

Constructor & Destructor Documentation

◆ SingleSelectionListDialog()

SingleSelectionListDialog ( QWidget *  parent = 0)
inline

Member Function Documentation

◆ setMultiSelection()

void setMultiSelection ( bool  enable)
inline

◆ selectedItem()

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

Returns a pairs of a string and the data that was assigned in addItem().

As string the string i that was entered by the user into the name field is returned, which by default is the first label specified in addItem().

Exceptions
XLogical,ifno item was selected.

◆ hasSelection()

bool hasSelection ( ) const
inline

Returns true, if an item was selected.

◆ setHeaderLabels()

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

◆ addItem() [1/2]

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

◆ addItem() [2/2]

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

◆ accept()

void accept ( )
inlinevirtualinherited

◆ setSelectOnlyOneItemPerCategory()

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

◆ selectedItems()

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

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)
inlineprotectedinherited

Member Data Documentation

◆ mAdditionalContentLayout

QVBoxLayout* mAdditionalContentLayout
protectedinherited

◆ mButtonBox

QDialogButtonBox* mButtonBox
protectedinherited

◆ mTreeWidget

QTreeWidget* mTreeWidget
protectedinherited

◆ mOnlyOnePerCategory

bool mOnlyOnePerCategory
protectedinherited

◆ mCategories

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

◆ mItems

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

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