VPTissue Reference Manual
ExplorationSelection.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "ExplorationSelection.h"
21 
22 #include <QVBoxLayout>
23 #include <QPushButton>
24 #include <QString>
25 #include <QStringList>
26 #include <QStringListModel>
27 
28 namespace SimPT_Parex {
29 
31  m_single_selection(false)
32 {
33  DrawGui();
34 }
35 
37  QDialog(parent), m_single_selection(single)
38 {
39  DrawGui();
40 }
41 
42 void ExplorationSelection::DrawGui()
43 {
44  setWindowTitle("Select Explorations");
45 
46  QVBoxLayout *layout = new QVBoxLayout;
47 
48  m_exploration_widget = new QListView;
49  m_exploration_widget->setEditTriggers(QAbstractItemView::NoEditTriggers);
50  if (m_single_selection)
51  m_exploration_widget->setSelectionMode(QAbstractItemView::SingleSelection);
52  else
53  m_exploration_widget->setSelectionMode(QAbstractItemView::MultiSelection);
54  m_exploration_widget->setSelectionBehavior(QAbstractItemView::SelectItems);
55  m_exploration_widget->clearSelection();
56 
57  QStringListModel *model = new QStringListModel();
58  QStringList list;
59  list << "Retrieving info from server...";
60  model->setStringList(list);
61 
62  m_exploration_widget->setModel(model);
63 
64  layout->addWidget(m_exploration_widget);
65 
66  QHBoxLayout *buttonLayout = new QHBoxLayout;
67  m_ok_button = new QPushButton("Ok");
68  buttonLayout->addWidget(m_ok_button);
69 
70  QPushButton *cancel = new QPushButton("Cancel");
71  buttonLayout->addWidget(cancel);
72 
73  layout->addLayout(buttonLayout);
74 
75  setLayout(layout);
76 
77  connect(m_ok_button, SIGNAL(clicked()), this, SLOT(Accept()));
78  connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
79 }
80 
82 {
83  delete m_exploration_widget;
84 }
85 
86 void ExplorationSelection::Accept()
87 {
88  m_selected_exploration.clear();
89 
90  auto selection = m_exploration_widget->selectionModel();
91  auto selected_indices = selection->selectedIndexes();
92  auto model = m_exploration_widget->model();
93 
94  for (auto index : selected_indices) {
95  m_selected_exploration.push_back(model->data(index, 0).toString().toStdString());
96  }
97 
98  accept();
99 }
100 
101 void ExplorationSelection::UpdateExplorations(std::vector<std::string> explorations)
102 {
103  QStringListModel* model = (QStringListModel*) m_exploration_widget->model();
104 
105  QStringList list;
106  if (explorations.size() == 0)
107  list << "No explorations found!";
108 
109  for (auto name : explorations)
110  list << QString(name.c_str());
111 
112  model->setStringList(list);
113 }
114 
115 std::vector<std::string> ExplorationSelection::GetSelection()
116 {
117  return m_selected_exploration;
118 }
119 
121 {
122  return (m_selected_exploration.size() != 0);
123 }
124 
125 } // namespace
bool Selected()
Return true if an exploration is selected.
Interface for ExplorationSelection.
ExplorationSelection(QWidget *parent=0)
Constructor.
void UpdateExplorations(std::vector< std::string > explorations)
updates the current displayed explorations
see the online Qt documentation
Namespace for SimPT parameter explorer package.
Definition: Client.cpp:52
std::vector< std::string > GetSelection()
Get the name of the selected exploration.
see the online Qt documentation