7 #include "fwGuiQt/dialog/MultiSelectorDialog.hpp" 9 #include <fwCore/base.hpp> 10 #include <fwGui/registry/macros.hpp> 12 #include <QApplication> 13 #include <QHBoxLayout> 15 #include <QListWidget> 16 #include <QPushButton> 17 #include <QPushButton> 18 #include <QVBoxLayout> 37 MultiSelectorDialog::~MultiSelectorDialog()
45 this->m_selections = _selections;
52 this->m_title = _title;
59 QWidget *parent = qApp->activeWindow();
61 QDialog* dialog =
new QDialog(parent);
62 dialog->setWindowTitle(QString::fromStdString(m_title));
64 QListWidget *selectionList =
new QListWidget(dialog);
65 for( Selections::value_type selection : m_selections)
67 QListWidgetItem* item =
new QListWidgetItem(QString::fromStdString(selection.first), selectionList);
68 item->setCheckState( (selection.second ? Qt::Checked : Qt::Unchecked) );
69 selectionList->addItem(item);
72 QListWidgetItem* firstItem = selectionList->item(0);
73 selectionList->setCurrentItem(firstItem);
75 QPushButton* okButton =
new QPushButton(tr(
"Ok"));
76 QPushButton* cancelButton =
new QPushButton(tr(
"Cancel"));
78 QHBoxLayout *hLayout =
new QHBoxLayout();
79 hLayout->addWidget(okButton);
80 hLayout->addWidget(cancelButton);
82 QVBoxLayout *vLayout =
new QVBoxLayout();
83 if(!m_message.empty())
85 QLabel* msgText =
new QLabel(QString::fromStdString(m_message), dialog);
86 vLayout->addWidget( msgText);
88 vLayout->addWidget(selectionList);
89 vLayout->addLayout(hLayout);
91 dialog->setLayout(vLayout);
92 QObject::connect(okButton, SIGNAL(clicked()), dialog, SLOT(accept()));
93 QObject::connect(cancelButton, SIGNAL(clicked()), dialog, SLOT(reject()));
94 QObject::connect(selectionList, SIGNAL(itemDoubleClicked( QListWidgetItem * )), dialog, SLOT(accept()));
96 Selections selections;
100 for( Selections::value_type selection : m_selections)
102 selections[selection.first] = (selectionList->item(indexItem)->checkState() == Qt::Checked);
MultiSelectorDialog allowing the choice of an element among severals (_selections) ...
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
FWGUI_API void setTitle(std::string title) override
Sets the selector title.
The namespace fwGuiQt contains classes which provide the implementation of the Gui using Qt library...
FWGUI_API Selections show() override
Show the selector and return the selection.
static FWGUI_API const FactoryRegistryKeyType REGISTRY_KEY
this unique key should be used for all factory for specific Selector(qt,wx,...)
virtual FWGUI_API void setMessage(const std::string &msg) override
Set the message.
virtual FWGUI_API void setSelections(Selections _selections) override
Set the string list that can be chosen by the selector.