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
27 class DialogOperation
;
29 #include "operation.h"
32 #include <QListWidget>
33 #include <QTextStream>
35 #include <vtkUnstructuredGrid.h>
36 #include <vtkIntArray.h>
37 #include <vtkCellData.h>
40 class DialogOperation
: public QDialog
,
44 protected: // attributes
46 /** The user interface definition from QtDesigner */
51 /** Generic constructor to set up the user interface */
55 * Create a checkable QListWidgetItem and add it to a QListWidget.
56 * @param lw the QListWidget to add the item to
57 * @param item the text of the item
58 * @param checked the status of the item checked/unchecked
61 void addListItem(QListWidget
*lw
, T item
, bool checked
= false);
64 * Check if a certain text item is checked within a QListWidget.
65 * @param lw the QListWidget to check
66 * @param item the item to check
67 * @return true if the item is checked and false if not
70 bool checkListItem(QListWidget
*lw
, T item
);
73 * Get a set with all seleceted items from a QListWidget.
74 * @param lw The QListWidget.
75 * @param sel On return, this will hold all items.
77 void getSelectedItems(QListWidget
*lw
, QSet
<int> &sel
);
80 * Get a set with all seleceted items from a QListWidget.
81 * @param lw The QListWidget.
82 * @param sel On return, this will hold all items.
84 void getSelectedItems(QListWidget
*lw
, QSet
<QString
> &sel
);
86 virtual void before() {};
87 virtual void operator()();
89 //connect(const QObject* a, const char* b, const QObject* c, const char* d) { QObject::connect(a,b,c,d); };
94 DialogOperation
<UI
>::DialogOperation()
101 void DialogOperation
<UI
>::addListItem(QListWidget
*lw
, T item
, bool checked
)
103 QListWidgetItem
*lwi
= new QListWidgetItem(lw
);
104 if (checked
) lwi
->setCheckState(Qt::Checked
);
105 else lwi
->setCheckState(Qt::Unchecked
);
107 QTextStream
ts(&text
);
110 lwi
->setFlags(Qt::ItemIsUserCheckable
| Qt::ItemIsEnabled
);
115 bool DialogOperation
<UI
>::checkListItem(QListWidget
*lw
, T item
)
118 QTextStream
ts(&text
);
120 for (int i
= 0; i
< lw
->count(); ++i
) {
121 if (lw
->item(i
)->text() == text
) {
122 if (lw
->item(i
)->checkState() == Qt::Checked
) return true;
129 void DialogOperation
<UI
>::getSelectedItems(QListWidget
*lw
, QSet
<QString
> &sel
)
132 for (int i
= 0; i
< lw
->count(); ++i
) {
133 if (lw
->item(i
)->checkState() == Qt::Checked
) {
134 QString item
= lw
->item(i
)->text();
141 void DialogOperation
<UI
>::getSelectedItems(QListWidget
*lw
, QSet
<int> &sel
)
144 for (int i
= 0; i
< lw
->count(); ++i
) {
145 if (lw
->item(i
)->checkState() == Qt::Checked
) {
146 int item
= lw
->item(i
)->text().toInt();
153 void DialogOperation
<UI
>::operator()()
159 } catch (Error err
) {
164 if (QDialog::exec()) {
166 Operation::operator()();
167 } catch (Error err
) {