1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #ifndef dialogoperation_H
22 #define dialogoperation_H
24 template <typename UI
, typename OP
>
25 class DialogOperation
;
27 #include "operation.h"
28 // #include "guimainwindow.h"
31 #include <QListWidget>
32 #include <QTextStream>
35 #include <vtkUnstructuredGrid.h>
36 #include <vtkIntArray.h>
37 #include <vtkCellData.h>
39 template <typename UI
, typename OP
>
40 class DialogOperation
: public QDialog
,
44 protected: // attributes
46 /** The user interface definition from QtDesigner */
51 EgVtkObject::l2g_t
getPartNodes() { return this->m_Part
.getNodes(); }
52 EgVtkObject::l2g_t
getPartCells()const { return this->m_Part
.getCells(); }
53 EgVtkObject::g2l_t
getPartLocalNodes() { return this->m_Part
.getLocalNodes(); }
54 EgVtkObject::g2l_t
getPartLocalCells() { return this->m_Part
.getLocalCells(); }
55 EgVtkObject::l2l_t
getPartN2N() { return this->m_Part
.getN2N(); }
56 EgVtkObject::l2l_t
getPartN2C() { return this->m_Part
.getN2C(); }
57 EgVtkObject::l2l_t
getPartC2C() { return this->m_Part
.getC2C(); }
61 /** Generic constructor to set up the user interface */
65 * Create a checkable QListWidgetItem and add it to a QListWidget.
66 * @param lw the QListWidget to add the item to
67 * @param item the text of the item
68 * @param checked the status of the item checked/unchecked
71 void addListItem(QListWidget
*lw
, T item
, bool checked
= false);
74 * Check if a certain text item is checked within a QListWidget.
75 * @param lw the QListWidget to check
76 * @param item the item to check
77 * @return true if the item is checked and false if not
80 bool checkListItem(QListWidget
*lw
, T item
);
83 * Get the name of the selected volume.
84 * @param lw the QListWidget for volume selection
85 * @return the name of the selected volume
87 QString
getSelectedVolume(QListWidget
*lw
);
90 * Get a set with all seleceted items from a QListWidget.
91 * @param lw The QListWidget.
92 * @param sel On return, this will hold all items.
94 void getSelectedItems(QListWidget
*lw
, QSet
<int> &sel
);
97 * Get a set with all seleceted items from a QListWidget.
98 * @param lw The QListWidget.
99 * @param sel On return, this will hold all items.
101 void getSelectedItems(QListWidget
*lw
, QSet
<QString
> &sel
);
104 * @brief set a line edit to a double value
105 * @param value the value to set
106 * @param line_edit the QLineEdit to use
108 void setDouble(double value
, QLineEdit
*line_edit
);
111 * @brief set the text of a QLineEdit widget to represent a vector in the form "x, y, z"
112 * @param value the vector to set
113 * @param line_edit the QLineEdit to use
115 void setVector(vec3_t value
, QLineEdit
*line_edit
);
118 * @brief get a vector from a QLineEdit widget which represents it in the form "x, y, z"
119 * @param line_edit the QLineEdit to use
122 vec3_t
getVector(QLineEdit
*line_edit
);
124 virtual void before() {}
125 virtual void operator()();
127 //connect(const QObject* a, const char* b, const QObject* c, const char* d) { QObject::connect(a,b,c,d); };
131 template <typename UI
, typename OP
>
132 DialogOperation
<UI
,OP
>::DialogOperation()
137 template <typename UI
, typename OP
>
139 void DialogOperation
<UI
,OP
>::addListItem(QListWidget
*lw
, T item
, bool checked
)
141 QListWidgetItem
*lwi
= new QListWidgetItem(lw
);
142 if (checked
) lwi
->setCheckState(Qt::Checked
);
143 else lwi
->setCheckState(Qt::Unchecked
);
145 QTextStream
ts(&text
);
148 lwi
->setFlags(Qt::ItemIsUserCheckable
| Qt::ItemIsEnabled
);
151 template <typename UI
, typename OP
>
153 bool DialogOperation
<UI
,OP
>::checkListItem(QListWidget
*lw
, T item
)
156 QTextStream
ts(&text
);
158 for (int i
= 0; i
< lw
->count(); ++i
) {
159 if (lw
->item(i
)->text() == text
) {
160 if (lw
->item(i
)->checkState() == Qt::Checked
) return true;
166 template <typename UI
, typename OP
>
167 QString DialogOperation
<UI
,OP
>::getSelectedVolume(QListWidget
*lw
)
170 for (int i
= 0; i
< lw
->count(); ++i
) {
171 if (lw
->item(i
)->isSelected()) {
172 volume_name
= lw
->item(i
)->text();
178 template <typename UI
, typename OP
>
179 void DialogOperation
<UI
,OP
>::getSelectedItems(QListWidget
*lw
, QSet
<QString
> &sel
)
182 for (int i
= 0; i
< lw
->count(); ++i
) {
183 if (lw
->item(i
)->checkState() == Qt::Checked
) {
184 QString item
= lw
->item(i
)->text();
190 template <typename UI
, typename OP
>
191 void DialogOperation
<UI
,OP
>::getSelectedItems(QListWidget
*lw
, QSet
<int> &sel
)
194 for (int i
= 0; i
< lw
->count(); ++i
) {
195 if (lw
->item(i
)->checkState() == Qt::Checked
) {
196 QString item_txt
= lw
->item(i
)->text();
197 QStringList items
= item_txt
.split(":");
198 int item
= items
[0].toInt(); ///\todo UiUiUi
204 template <typename UI
, typename OP
>
205 void DialogOperation
<UI
,OP
>::operator()()
212 } catch (Error err
) {
219 if (!QDialog::exec()) {
222 } catch (Error err
) {
230 } catch (Error err
) {
236 template <typename UI
, typename OP
>
237 void DialogOperation
<UI
,OP
>::setDouble(double value
, QLineEdit
*line_edit
)
241 line_edit
->setText(num
);
244 template <typename UI
, typename OP
>
245 void DialogOperation
<UI
,OP
>::setVector(vec3_t value
, QLineEdit
*line_edit
)
251 line_edit
->setText(x
+ ", " + y
+ ", " + z
);
254 template <typename UI
, typename OP
>
255 vec3_t DialogOperation
<UI
,OP
>::getVector(QLineEdit
*line_edit
)
257 QStringList items
= line_edit
->text().split(",");
259 if (items
.size() == 3) {
260 for (int i
= 0; i
< 3; ++i
) {
261 value
[i
] = items
[i
].toDouble();