2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008,2009 Oliver Gloth +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #ifndef dialogoperation_H
24 #define dialogoperation_H
26 template <class UI
, class OP
>
27 class DialogOperation
;
29 #include "operation.h"
30 // #include "guimainwindow.h"
33 #include <QListWidget>
34 #include <QTextStream>
36 #include <vtkUnstructuredGrid.h>
37 #include <vtkIntArray.h>
38 #include <vtkCellData.h>
40 template <class UI
, class OP
>
41 class DialogOperation
: public QDialog
,
45 protected: // attributes
47 /** The user interface definition from QtDesigner */
52 EgVtkObject::l2g_t
getPartNodes() { return this->m_Part
.getNodes(); }
53 EgVtkObject::l2g_t
getPartCells()const { return this->m_Part
.getCells(); }
54 EgVtkObject::g2l_t
getPartLocalNodes() { return this->m_Part
.getLocalNodes(); }
55 EgVtkObject::g2l_t
getPartLocalCells() { return this->m_Part
.getLocalCells(); }
56 EgVtkObject::l2l_t
getPartN2N() { return this->m_Part
.getN2N(); }
57 EgVtkObject::l2l_t
getPartN2C() { return this->m_Part
.getN2C(); }
58 EgVtkObject::l2l_t
getPartC2C() { return this->m_Part
.getC2C(); }
62 /** Generic constructor to set up the user interface */
66 * Create a checkable QListWidgetItem and add it to a QListWidget.
67 * @param lw the QListWidget to add the item to
68 * @param item the text of the item
69 * @param checked the status of the item checked/unchecked
72 void addListItem(QListWidget
*lw
, T item
, bool checked
= false);
75 * Check if a certain text item is checked within a QListWidget.
76 * @param lw the QListWidget to check
77 * @param item the item to check
78 * @return true if the item is checked and false if not
81 bool checkListItem(QListWidget
*lw
, T item
);
84 * Get the name of the selected volume.
85 * @param lw the QListWidget for volume selection
86 * @return the name of the selected volume
88 QString
getSelectedVolume(QListWidget
*lw
);
91 * Get a set with all seleceted items from a QListWidget.
92 * @param lw The QListWidget.
93 * @param sel On return, this will hold all items.
95 void getSelectedItems(QListWidget
*lw
, QSet
<int> &sel
);
98 * Get a set with all seleceted items from a QListWidget.
99 * @param lw The QListWidget.
100 * @param sel On return, this will hold all items.
102 void getSelectedItems(QListWidget
*lw
, QSet
<QString
> &sel
);
104 virtual void before() {}
105 virtual void operator()();
107 //connect(const QObject* a, const char* b, const QObject* c, const char* d) { QObject::connect(a,b,c,d); };
111 template <class UI
, class OP
>
112 DialogOperation
<UI
,OP
>::DialogOperation()
117 template <class UI
, class OP
>
119 void DialogOperation
<UI
,OP
>::addListItem(QListWidget
*lw
, T item
, bool checked
)
121 QListWidgetItem
*lwi
= new QListWidgetItem(lw
);
122 if (checked
) lwi
->setCheckState(Qt::Checked
);
123 else lwi
->setCheckState(Qt::Unchecked
);
125 QTextStream
ts(&text
);
128 lwi
->setFlags(Qt::ItemIsUserCheckable
| Qt::ItemIsEnabled
);
131 template <class UI
, class OP
>
133 bool DialogOperation
<UI
,OP
>::checkListItem(QListWidget
*lw
, T item
)
136 QTextStream
ts(&text
);
138 for (int i
= 0; i
< lw
->count(); ++i
) {
139 if (lw
->item(i
)->text() == text
) {
140 if (lw
->item(i
)->checkState() == Qt::Checked
) return true;
146 template <class UI
, class OP
>
147 QString DialogOperation
<UI
,OP
>::getSelectedVolume(QListWidget
*lw
)
150 for (int i
= 0; i
< lw
->count(); ++i
) {
151 if (lw
->item(i
)->isSelected()) {
152 volume_name
= lw
->item(i
)->text();
158 template <class UI
, class OP
>
159 void DialogOperation
<UI
,OP
>::getSelectedItems(QListWidget
*lw
, QSet
<QString
> &sel
)
162 for (int i
= 0; i
< lw
->count(); ++i
) {
163 if (lw
->item(i
)->checkState() == Qt::Checked
) {
164 QString item
= lw
->item(i
)->text();
170 template <class UI
, class OP
>
171 void DialogOperation
<UI
,OP
>::getSelectedItems(QListWidget
*lw
, QSet
<int> &sel
)
174 for (int i
= 0; i
< lw
->count(); ++i
) {
175 if (lw
->item(i
)->checkState() == Qt::Checked
) {
176 QString item_txt
= lw
->item(i
)->text();
177 QStringList items
= item_txt
.split(":");
178 int item
= items
[0].toInt(); ///\todo UiUiUi
184 template <class UI
, class OP
>
185 void DialogOperation
<UI
,OP
>::operator()()
192 } catch (Error err
) {
198 if (QDialog::exec()) {
202 } catch (Error err
) {