1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * QTDialog.cpp
|
---|
10 | *
|
---|
11 | * Created on: Jan 18, 2010
|
---|
12 | * Author: crueger
|
---|
13 | */
|
---|
14 |
|
---|
15 | // include config.h
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #include "UIElements/QT4/QTDialog.hpp"
|
---|
21 |
|
---|
22 | #include <boost/lexical_cast.hpp>
|
---|
23 |
|
---|
24 | #include <string>
|
---|
25 | #include <sstream>
|
---|
26 | #include <limits>
|
---|
27 |
|
---|
28 | #include <Qt/qboxlayout.h>
|
---|
29 | #include <Qt/qlabel.h>
|
---|
30 | #include <Qt/qspinbox.h>
|
---|
31 | #include <QtGui/QDoubleSpinBox>
|
---|
32 | #include <Qt/qlineedit.h>
|
---|
33 | #include <Qt/qlistwidget.h>
|
---|
34 | #include <Qt/qdialogbuttonbox.h>
|
---|
35 | #include <Qt/qpushbutton.h>
|
---|
36 | #include <Qt/qcombobox.h>
|
---|
37 |
|
---|
38 | #include <boost/lexical_cast.hpp>
|
---|
39 |
|
---|
40 | #include "Helpers/MemDebug.hpp"
|
---|
41 |
|
---|
42 | #include "World.hpp"
|
---|
43 | #include "periodentafel.hpp"
|
---|
44 | #include "atom.hpp"
|
---|
45 | #include "element.hpp"
|
---|
46 | #include "molecule.hpp"
|
---|
47 | #include "Descriptors/AtomIdDescriptor.hpp"
|
---|
48 | #include "Descriptors/MoleculeIdDescriptor.hpp"
|
---|
49 | #include "LinearAlgebra/Matrix.hpp"
|
---|
50 | #include "Box.hpp"
|
---|
51 |
|
---|
52 |
|
---|
53 | using namespace std;
|
---|
54 |
|
---|
55 | QTDialog::QTDialog() :
|
---|
56 | QDialog(0)
|
---|
57 | {
|
---|
58 | // creating and filling of the Dialog window
|
---|
59 | mainLayout = new QVBoxLayout();
|
---|
60 | inputLayout = new QVBoxLayout();
|
---|
61 | buttonLayout = new QVBoxLayout();
|
---|
62 | setLayout(mainLayout);
|
---|
63 | mainLayout->addLayout(inputLayout);
|
---|
64 | mainLayout->addLayout(buttonLayout);
|
---|
65 | buttons = new QDialogButtonBox(QDialogButtonBox::Ok| QDialogButtonBox::Cancel);
|
---|
66 | buttonLayout->addWidget(buttons);
|
---|
67 |
|
---|
68 | // Disable the ok button until something was entered
|
---|
69 | buttons->button(QDialogButtonBox::Ok)->setEnabled(false);
|
---|
70 |
|
---|
71 | // connect the buttons to their appropriate slots
|
---|
72 | connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
|
---|
73 | connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
|
---|
74 | }
|
---|
75 |
|
---|
76 | QTDialog::~QTDialog()
|
---|
77 | {
|
---|
78 | }
|
---|
79 |
|
---|
80 | bool QTDialog::display(){
|
---|
81 | // Button state might have changed by some update that
|
---|
82 | // was done during query construction. To make sure
|
---|
83 | // the state is correct, we just call update one more time.
|
---|
84 | update();
|
---|
85 | if(exec()) {
|
---|
86 | setAll();
|
---|
87 | return true;
|
---|
88 | }
|
---|
89 | else {
|
---|
90 | return false;
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | void QTDialog::update(){
|
---|
95 | buttons->button(QDialogButtonBox::Ok)->setEnabled(checkAll());
|
---|
96 | }
|
---|
97 |
|
---|
98 | /************************** Query Infrastructure ************************/
|
---|
99 |
|
---|
100 | void QTDialog::queryEmpty(char const*, string){
|
---|
101 | // TODO
|
---|
102 | ASSERT(false, "Not implemented yet");
|
---|
103 | }
|
---|
104 |
|
---|
105 | void QTDialog::queryBoolean(char const*,string){
|
---|
106 | // TODO
|
---|
107 | ASSERT(false, "Not implemented yet");
|
---|
108 | }
|
---|
109 |
|
---|
110 | void QTDialog::queryAtom(char const*, string){
|
---|
111 | // TODO
|
---|
112 | ASSERT(false, "Not implemented yet");
|
---|
113 | }
|
---|
114 |
|
---|
115 | void QTDialog::queryAtoms(char const*, string){
|
---|
116 | // TODO
|
---|
117 | ASSERT(false, "Not implemented yet");
|
---|
118 | }
|
---|
119 |
|
---|
120 | void QTDialog::queryBox(char const*, string){
|
---|
121 | // TODO
|
---|
122 | ASSERT(false, "Not implemented yet");
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | void QTDialog::queryInt(const char *title,string)
|
---|
127 | {
|
---|
128 | registerQuery(new IntQTQuery(title,inputLayout,this));
|
---|
129 | }
|
---|
130 |
|
---|
131 | void QTDialog::queryInts(const char *title,string)
|
---|
132 | {
|
---|
133 | registerQuery(new IntsQTQuery(title,inputLayout,this));
|
---|
134 | }
|
---|
135 |
|
---|
136 | void QTDialog::queryDouble(const char* title,string){
|
---|
137 | registerQuery(new DoubleQTQuery(title,inputLayout,this));
|
---|
138 | }
|
---|
139 |
|
---|
140 | void QTDialog::queryDoubles(const char* title,string){
|
---|
141 | registerQuery(new DoublesQTQuery(title,inputLayout,this));
|
---|
142 | }
|
---|
143 |
|
---|
144 | void QTDialog::queryString(const char* title,string)
|
---|
145 | {
|
---|
146 | registerQuery(new StringQTQuery(title,inputLayout,this));
|
---|
147 | }
|
---|
148 |
|
---|
149 | void QTDialog::queryStrings(const char* title,string)
|
---|
150 | {
|
---|
151 | registerQuery(new StringsQTQuery(title,inputLayout,this));
|
---|
152 | }
|
---|
153 |
|
---|
154 | void QTDialog::queryMolecule(const char *title,string)
|
---|
155 | {
|
---|
156 | registerQuery(new MoleculeQTQuery(title,inputLayout,this));
|
---|
157 | }
|
---|
158 |
|
---|
159 | void QTDialog::queryMolecules(const char *title,string)
|
---|
160 | {
|
---|
161 | // TODO
|
---|
162 | ASSERT(false, "Not implemented yet");
|
---|
163 | }
|
---|
164 |
|
---|
165 | void QTDialog::queryVector(const char* title, bool check,string) {
|
---|
166 | registerQuery(new VectorQTQuery(title,check,inputLayout,this));
|
---|
167 | }
|
---|
168 |
|
---|
169 | void QTDialog::queryVectors(const char* title, bool check,string) {
|
---|
170 | // TODO
|
---|
171 | ASSERT(false, "Not implemented yet");
|
---|
172 | }
|
---|
173 |
|
---|
174 | void QTDialog::queryElement(const char* title, string){
|
---|
175 | registerQuery(new ElementQTQuery(title,inputLayout,this));
|
---|
176 | }
|
---|
177 |
|
---|
178 | void QTDialog::queryElements(const char* title, string){
|
---|
179 | // TODO
|
---|
180 | ASSERT(false, "Not implemented yet");
|
---|
181 | }
|
---|
182 |
|
---|
183 | /************************** Query Objects *******************************/
|
---|
184 |
|
---|
185 | QTDialog::IntQTQuery::IntQTQuery(string _title,QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
186 | Dialog::IntQuery(_title),
|
---|
187 | parent(_parent)
|
---|
188 | {
|
---|
189 | thisLayout = new QHBoxLayout();
|
---|
190 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
191 | inputBox = new QSpinBox();
|
---|
192 | inputBox->setValue(0);
|
---|
193 | parent->addLayout(thisLayout);
|
---|
194 | thisLayout->addWidget(titleLabel);
|
---|
195 | thisLayout->addWidget(inputBox);
|
---|
196 |
|
---|
197 | pipe = new IntQTQueryPipe(&tmp,_dialog);
|
---|
198 | pipe->update(inputBox->value());
|
---|
199 | connect(inputBox,SIGNAL(valueChanged(int)),pipe,SLOT(update(int)));
|
---|
200 | }
|
---|
201 |
|
---|
202 | QTDialog::IntQTQuery::~IntQTQuery()
|
---|
203 | {
|
---|
204 | delete pipe;
|
---|
205 | }
|
---|
206 |
|
---|
207 | bool QTDialog::IntQTQuery::handle() {
|
---|
208 | return true;
|
---|
209 | }
|
---|
210 |
|
---|
211 |
|
---|
212 | QTDialog::IntsQTQuery::IntsQTQuery(string _title,QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
213 | Dialog::IntsQuery(_title),
|
---|
214 | parent(_parent)
|
---|
215 | {
|
---|
216 | QHBoxLayout * thisHLayout = new QHBoxLayout();
|
---|
217 | QVBoxLayout * thisV1Layout = new QVBoxLayout();
|
---|
218 | QVBoxLayout * thisV2Layout = new QVBoxLayout();
|
---|
219 |
|
---|
220 | QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
221 | QLabel *inputLabel = new QLabel("Enter to add");
|
---|
222 | QListWidget* inputList = new QListWidget();
|
---|
223 | inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
224 | QLineEdit* inputBox = new QLineEdit();
|
---|
225 | inputLabel->setBuddy(inputBox);
|
---|
226 | titleLabel->setBuddy(inputList);
|
---|
227 | QPushButton* AddButton = new QPushButton("Add");
|
---|
228 | AddButton->setEnabled(false);
|
---|
229 | QPushButton* RemoveButton = new QPushButton("Remove");
|
---|
230 | RemoveButton->setEnabled(false);
|
---|
231 |
|
---|
232 | thisV1Layout->addWidget(titleLabel);
|
---|
233 | thisV1Layout->addWidget(inputList);
|
---|
234 | thisV2Layout->addWidget(inputLabel);
|
---|
235 | thisV2Layout->addWidget(inputBox);
|
---|
236 | thisV2Layout->addWidget(AddButton);
|
---|
237 | thisV2Layout->addWidget(RemoveButton);
|
---|
238 | parent->addLayout(thisHLayout);
|
---|
239 | thisHLayout->addLayout(thisV1Layout);
|
---|
240 | thisHLayout->addLayout(thisV2Layout);
|
---|
241 |
|
---|
242 | pipe = new QTQueryListPipe<int>(&tmp,_dialog,inputBox,inputList,AddButton,RemoveButton);
|
---|
243 | connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(IntegerEntered(const QString&)));
|
---|
244 | connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
|
---|
245 | connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(AddValue()));
|
---|
246 | connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(RemoveRow()));
|
---|
247 | }
|
---|
248 |
|
---|
249 | QTDialog::IntsQTQuery::~IntsQTQuery()
|
---|
250 | {
|
---|
251 | delete pipe;
|
---|
252 | }
|
---|
253 |
|
---|
254 | bool QTDialog::IntsQTQuery::handle() {
|
---|
255 | return true;
|
---|
256 | }
|
---|
257 |
|
---|
258 |
|
---|
259 | QTDialog::DoubleQTQuery::DoubleQTQuery(string title,QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
260 | Dialog::DoubleQuery(title),
|
---|
261 | parent(_parent)
|
---|
262 | {
|
---|
263 | thisLayout = new QHBoxLayout();
|
---|
264 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
265 | inputBox = new QDoubleSpinBox();
|
---|
266 | inputBox->setValue(0);
|
---|
267 | inputBox->setRange(-numeric_limits<double>::max(),numeric_limits<double>::max());
|
---|
268 | inputBox->setDecimals(3);
|
---|
269 | parent->addLayout(thisLayout);
|
---|
270 | thisLayout->addWidget(titleLabel);
|
---|
271 | thisLayout->addWidget(inputBox);
|
---|
272 |
|
---|
273 | pipe = new DoubleQTQueryPipe(&tmp,_dialog);
|
---|
274 | pipe->update(inputBox->value());
|
---|
275 | connect(inputBox,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
|
---|
276 | }
|
---|
277 |
|
---|
278 | QTDialog::DoubleQTQuery::~DoubleQTQuery()
|
---|
279 | {
|
---|
280 | delete pipe;
|
---|
281 | }
|
---|
282 |
|
---|
283 | bool QTDialog::DoubleQTQuery::handle() {
|
---|
284 | return true;
|
---|
285 | }
|
---|
286 |
|
---|
287 |
|
---|
288 | QTDialog::DoublesQTQuery::DoublesQTQuery(string title,QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
289 | Dialog::DoublesQuery(title),
|
---|
290 | parent(_parent)
|
---|
291 | {
|
---|
292 | QHBoxLayout * thisHLayout = new QHBoxLayout();
|
---|
293 | QVBoxLayout * thisV1Layout = new QVBoxLayout();
|
---|
294 | QVBoxLayout * thisV2Layout = new QVBoxLayout();
|
---|
295 |
|
---|
296 | QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
297 | QLabel *inputLabel = new QLabel("Enter to add");
|
---|
298 | QListWidget* inputList = new QListWidget();
|
---|
299 | inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
300 | QLineEdit* inputBox = new QLineEdit();
|
---|
301 | inputLabel->setBuddy(inputBox);
|
---|
302 | titleLabel->setBuddy(inputList);
|
---|
303 | QPushButton* AddButton = new QPushButton("Add");
|
---|
304 | AddButton->setEnabled(false);
|
---|
305 | QPushButton* RemoveButton = new QPushButton("Remove");
|
---|
306 | RemoveButton->setEnabled(false);
|
---|
307 |
|
---|
308 | thisV1Layout->addWidget(titleLabel);
|
---|
309 | thisV1Layout->addWidget(inputList);
|
---|
310 | thisV2Layout->addWidget(inputLabel);
|
---|
311 | thisV2Layout->addWidget(inputBox);
|
---|
312 | thisV2Layout->addWidget(AddButton);
|
---|
313 | thisV2Layout->addWidget(RemoveButton);
|
---|
314 | parent->addLayout(thisHLayout);
|
---|
315 | thisHLayout->addLayout(thisV1Layout);
|
---|
316 | thisHLayout->addLayout(thisV2Layout);
|
---|
317 |
|
---|
318 | pipe = new QTQueryListPipe<double>(&tmp,_dialog,inputBox,inputList,AddButton,RemoveButton);
|
---|
319 | connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(IntegerEntered(const QString&)));
|
---|
320 | connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
|
---|
321 | connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(AddValue()));
|
---|
322 | connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(RemoveRow()));}
|
---|
323 |
|
---|
324 | QTDialog::DoublesQTQuery::~DoublesQTQuery()
|
---|
325 | {
|
---|
326 | delete pipe;
|
---|
327 | }
|
---|
328 |
|
---|
329 | bool QTDialog::DoublesQTQuery::handle() {
|
---|
330 | return true;
|
---|
331 | }
|
---|
332 |
|
---|
333 |
|
---|
334 | QTDialog::StringQTQuery::StringQTQuery(string _title,QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
335 | Dialog::StringQuery(_title),
|
---|
336 | parent(_parent)
|
---|
337 | {
|
---|
338 | thisLayout = new QHBoxLayout();
|
---|
339 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
340 | inputBox = new QLineEdit();
|
---|
341 | parent->addLayout(thisLayout);
|
---|
342 | thisLayout->addWidget(titleLabel);
|
---|
343 | thisLayout->addWidget(inputBox);
|
---|
344 |
|
---|
345 | pipe = new StringQTQueryPipe(&tmp,_dialog);
|
---|
346 | pipe->update(inputBox->text());
|
---|
347 | connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(update(const QString&)));
|
---|
348 | }
|
---|
349 |
|
---|
350 | QTDialog::StringQTQuery::~StringQTQuery()
|
---|
351 | {
|
---|
352 | delete pipe;
|
---|
353 | }
|
---|
354 |
|
---|
355 | // All values besides the empty string are valid
|
---|
356 | bool QTDialog::StringQTQuery::handle()
|
---|
357 | {
|
---|
358 | return tmp!="";
|
---|
359 | }
|
---|
360 |
|
---|
361 | QTDialog::StringsQTQuery::StringsQTQuery(string _title,QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
362 | Dialog::StringsQuery(_title),
|
---|
363 | parent(_parent)
|
---|
364 | {
|
---|
365 | QHBoxLayout * thisHLayout = new QHBoxLayout();
|
---|
366 | QVBoxLayout * thisV1Layout = new QVBoxLayout();
|
---|
367 | QVBoxLayout * thisV2Layout = new QVBoxLayout();
|
---|
368 |
|
---|
369 | QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
370 | QLabel *inputLabel = new QLabel("Enter to add");
|
---|
371 | QListWidget* inputList = new QListWidget();
|
---|
372 | inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
373 | QLineEdit* inputBox = new QLineEdit();
|
---|
374 | inputLabel->setBuddy(inputBox);
|
---|
375 | titleLabel->setBuddy(inputList);
|
---|
376 | QPushButton* AddButton = new QPushButton("Add");
|
---|
377 | AddButton->setEnabled(false);
|
---|
378 | QPushButton* RemoveButton = new QPushButton("Remove");
|
---|
379 | RemoveButton->setEnabled(false);
|
---|
380 |
|
---|
381 | thisV1Layout->addWidget(titleLabel);
|
---|
382 | thisV1Layout->addWidget(inputList);
|
---|
383 | thisV2Layout->addWidget(inputLabel);
|
---|
384 | thisV2Layout->addWidget(inputBox);
|
---|
385 | thisV2Layout->addWidget(AddButton);
|
---|
386 | thisV2Layout->addWidget(RemoveButton);
|
---|
387 | parent->addLayout(thisHLayout);
|
---|
388 | thisHLayout->addLayout(thisV1Layout);
|
---|
389 | thisHLayout->addLayout(thisV2Layout);
|
---|
390 |
|
---|
391 | pipe = new QTQueryListPipe<std::string>(&tmp,_dialog,inputBox,inputList,AddButton,RemoveButton);
|
---|
392 | connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(IntegerEntered(const QString&)));
|
---|
393 | connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
|
---|
394 | connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(AddValue()));
|
---|
395 | connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(RemoveRow()));}
|
---|
396 |
|
---|
397 | QTDialog::StringsQTQuery::~StringsQTQuery()
|
---|
398 | {
|
---|
399 | delete pipe;
|
---|
400 | }
|
---|
401 |
|
---|
402 | // All values besides the empty string are valid
|
---|
403 | bool QTDialog::StringsQTQuery::handle()
|
---|
404 | {
|
---|
405 | // dissect by ","
|
---|
406 | string::iterator olditer = temp.begin();
|
---|
407 | for(string::iterator iter = temp.begin(); iter != temp.end(); ++iter) {
|
---|
408 | if (*iter == ' ') {
|
---|
409 | tmp.push_back(string(iter, olditer));
|
---|
410 | olditer = iter;
|
---|
411 | }
|
---|
412 | }
|
---|
413 | if (olditer != temp.begin()) // insert last part also
|
---|
414 | tmp.push_back(string(olditer, temp.end()));
|
---|
415 |
|
---|
416 | return temp!="";
|
---|
417 | }
|
---|
418 |
|
---|
419 | QTDialog::MoleculeQTQuery::MoleculeQTQuery(string _title, QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
420 | Dialog::MoleculeQuery(_title),
|
---|
421 | parent(_parent)
|
---|
422 | {
|
---|
423 | thisLayout = new QHBoxLayout();
|
---|
424 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
425 | inputBox = new QComboBox();
|
---|
426 | // add all molecules to the combo box
|
---|
427 | vector<molecule*> molecules = World::getInstance().getAllMolecules();
|
---|
428 | for(vector<molecule*>::iterator iter = molecules.begin();
|
---|
429 | iter != molecules.end();
|
---|
430 | ++iter) {
|
---|
431 | stringstream sstr;
|
---|
432 | sstr << (*iter)->IndexNr << "\t" << (*iter)->getName();
|
---|
433 | inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter)->IndexNr));
|
---|
434 | }
|
---|
435 | parent->addLayout(thisLayout);
|
---|
436 | thisLayout->addWidget(titleLabel);
|
---|
437 | thisLayout->addWidget(inputBox);
|
---|
438 |
|
---|
439 | pipe = new MoleculeQTQueryPipe(&tmp,_dialog,inputBox);
|
---|
440 | pipe->update(inputBox->currentIndex());
|
---|
441 | connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
|
---|
442 | }
|
---|
443 |
|
---|
444 | QTDialog::MoleculeQTQuery::~MoleculeQTQuery()
|
---|
445 | {
|
---|
446 | delete pipe;
|
---|
447 | }
|
---|
448 |
|
---|
449 | // Handling is easy, since the GUI makes it impossible to select invalid values
|
---|
450 | bool QTDialog::MoleculeQTQuery::handle()
|
---|
451 | {
|
---|
452 | return true;
|
---|
453 | }
|
---|
454 |
|
---|
455 | QTDialog::MoleculesQTQuery::MoleculesQTQuery(string _title, QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
456 | Dialog::MoleculesQuery(_title),
|
---|
457 | parent(_parent)
|
---|
458 | {
|
---|
459 | thisLayout = new QHBoxLayout();
|
---|
460 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
461 | inputBox = new QComboBox();
|
---|
462 | // add all molecules to the combo box
|
---|
463 | vector<molecule*> molecules = World::getInstance().getAllMolecules();
|
---|
464 | for(vector<molecule*>::iterator iter = molecules.begin();
|
---|
465 | iter != molecules.end();
|
---|
466 | ++iter) {
|
---|
467 | stringstream sstr;
|
---|
468 | sstr << (*iter)->IndexNr << "\t" << (*iter)->getName();
|
---|
469 | inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter)->IndexNr));
|
---|
470 | }
|
---|
471 | parent->addLayout(thisLayout);
|
---|
472 | thisLayout->addWidget(titleLabel);
|
---|
473 | thisLayout->addWidget(inputBox);
|
---|
474 |
|
---|
475 | pipe = new MoleculesQTQueryPipe(&tmp,_dialog,inputBox);
|
---|
476 | pipe->update(inputBox->currentIndex());
|
---|
477 | connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
|
---|
478 | }
|
---|
479 |
|
---|
480 | QTDialog::MoleculesQTQuery::~MoleculesQTQuery()
|
---|
481 | {
|
---|
482 | delete pipe;
|
---|
483 | }
|
---|
484 |
|
---|
485 | // Handling is easy, since the GUI makes it impossible to select invalid values
|
---|
486 | bool QTDialog::MoleculesQTQuery::handle()
|
---|
487 | {
|
---|
488 | return true;
|
---|
489 | }
|
---|
490 |
|
---|
491 | QTDialog::VectorQTQuery::VectorQTQuery(std::string title, bool _check,QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
492 | Dialog::VectorQuery(title,_check),
|
---|
493 | parent(_parent)
|
---|
494 | {
|
---|
495 | mainLayout= new QHBoxLayout();
|
---|
496 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
497 | mainLayout->addWidget(titleLabel);
|
---|
498 | subLayout = new QVBoxLayout();
|
---|
499 | mainLayout->addLayout(subLayout);
|
---|
500 | QComboBox* inputBox = new QComboBox();
|
---|
501 | coordLayout = new QHBoxLayout();
|
---|
502 | subLayout->addLayout(coordLayout);
|
---|
503 | coordLabel = new QLabel(QString("x,y,z"));
|
---|
504 | coordLayout->addWidget(coordLabel);
|
---|
505 | coordInput = new QDoubleSpinBox();
|
---|
506 | // coordInput->setRange(0,M.at(i,i));
|
---|
507 | coordInput->setDecimals(3);
|
---|
508 | coordLayout->addWidget(coordInput);
|
---|
509 | pipe = new VectorQTQueryPipe(&(tmp),_dialog,inputBox);
|
---|
510 | //pipe->update(coordInput->value());
|
---|
511 | connect(coordInput,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
|
---|
512 | parent->addLayout(mainLayout);
|
---|
513 | }
|
---|
514 |
|
---|
515 | QTDialog::VectorQTQuery::~VectorQTQuery()
|
---|
516 | {}
|
---|
517 |
|
---|
518 | bool QTDialog::VectorQTQuery::handle() {
|
---|
519 | return true;
|
---|
520 | }
|
---|
521 |
|
---|
522 |
|
---|
523 | QTDialog::VectorsQTQuery::VectorsQTQuery(std::string title, bool _check,QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
524 | Dialog::VectorsQuery(title,_check),
|
---|
525 | parent(_parent)
|
---|
526 | {
|
---|
527 | mainLayout= new QHBoxLayout();
|
---|
528 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
529 | mainLayout->addWidget(titleLabel);
|
---|
530 | subLayout = new QVBoxLayout();
|
---|
531 | mainLayout->addLayout(subLayout);
|
---|
532 | QComboBox* inputBox = new QComboBox();
|
---|
533 | coordLayout = new QHBoxLayout();
|
---|
534 | subLayout->addLayout(coordLayout);
|
---|
535 | coordLabel = new QLabel(QString("x,y,z"));
|
---|
536 | coordLayout->addWidget(coordLabel);
|
---|
537 | coordInput = new QDoubleSpinBox();
|
---|
538 | // coordInput->setRange(0,M.at(i,i));
|
---|
539 | coordInput->setDecimals(3);
|
---|
540 | coordLayout->addWidget(coordInput);
|
---|
541 | pipe = new VectorsQTQueryPipe(&(tmp),_dialog,inputBox);
|
---|
542 | //pipe->update(coordInput->value());
|
---|
543 | connect(coordInput,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
|
---|
544 | parent->addLayout(mainLayout);
|
---|
545 | }
|
---|
546 |
|
---|
547 | QTDialog::VectorsQTQuery::~VectorsQTQuery()
|
---|
548 | {}
|
---|
549 |
|
---|
550 | bool QTDialog::VectorsQTQuery::handle() {
|
---|
551 | return true;
|
---|
552 | }
|
---|
553 |
|
---|
554 |
|
---|
555 | QTDialog::ElementQTQuery::ElementQTQuery(std::string _title, QBoxLayout *_parent, QTDialog *_dialog) :
|
---|
556 | Dialog::ElementQuery(_title),
|
---|
557 | parent(_parent)
|
---|
558 | {
|
---|
559 | periodentafel *periode = World::getInstance().getPeriode();
|
---|
560 | thisLayout = new QHBoxLayout();
|
---|
561 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
562 | inputBox = new QComboBox();
|
---|
563 | for(periodentafel::const_iterator iter = periode->begin();
|
---|
564 | iter!=periode->end();
|
---|
565 | ++iter)
|
---|
566 | {
|
---|
567 | stringstream sstr;
|
---|
568 | sstr << (*iter).first << "\t" << (*iter).second->getName();
|
---|
569 | inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter).first));
|
---|
570 | }
|
---|
571 | parent->addLayout(thisLayout);
|
---|
572 | thisLayout->addWidget(titleLabel);
|
---|
573 | thisLayout->addWidget(inputBox);
|
---|
574 |
|
---|
575 | pipe = new ElementQTQueryPipe(&tmp,_dialog,inputBox);
|
---|
576 | pipe->update(inputBox->currentIndex());
|
---|
577 | connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
|
---|
578 | }
|
---|
579 |
|
---|
580 | QTDialog::ElementQTQuery::~ElementQTQuery()
|
---|
581 | {
|
---|
582 | delete pipe;
|
---|
583 | }
|
---|
584 |
|
---|
585 | bool QTDialog::ElementQTQuery::handle(){
|
---|
586 | return true;
|
---|
587 | }
|
---|
588 |
|
---|
589 |
|
---|
590 | QTDialog::ElementsQTQuery::ElementsQTQuery(std::string _title, QBoxLayout *_parent, QTDialog *_dialog) :
|
---|
591 | Dialog::ElementsQuery(_title),
|
---|
592 | parent(_parent)
|
---|
593 | {
|
---|
594 | periodentafel *periode = World::getInstance().getPeriode();
|
---|
595 | thisLayout = new QHBoxLayout();
|
---|
596 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
597 | inputBox = new QComboBox();
|
---|
598 | for(periodentafel::const_iterator iter = periode->begin();
|
---|
599 | iter!=periode->end();
|
---|
600 | ++iter)
|
---|
601 | {
|
---|
602 | stringstream sstr;
|
---|
603 | sstr << (*iter).first << "\t" << (*iter).second->getName();
|
---|
604 | inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter).first));
|
---|
605 | }
|
---|
606 | parent->addLayout(thisLayout);
|
---|
607 | thisLayout->addWidget(titleLabel);
|
---|
608 | thisLayout->addWidget(inputBox);
|
---|
609 |
|
---|
610 | pipe = new ElementsQTQueryPipe(&tmp,_dialog,inputBox);
|
---|
611 | pipe->update(inputBox->currentIndex());
|
---|
612 | connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
|
---|
613 | }
|
---|
614 |
|
---|
615 | QTDialog::ElementsQTQuery::~ElementsQTQuery()
|
---|
616 | {
|
---|
617 | delete pipe;
|
---|
618 | }
|
---|
619 |
|
---|
620 | bool QTDialog::ElementsQTQuery::handle(){
|
---|
621 | return true;
|
---|
622 | }
|
---|
623 |
|
---|
624 | /*************************** Plumbing *******************************/
|
---|
625 |
|
---|
626 |
|
---|
627 | template<typename T> QTQueryListPipe<T>::QTQueryListPipe(std::vector<T> *_content, QTDialog *_dialog, QLineEdit *_inputBox, QListWidget *_inputList, QPushButton *_AddButton, QPushButton *_RemoveButton) :
|
---|
628 | content(_content),
|
---|
629 | dialog(_dialog),
|
---|
630 | inputBox(_inputBox),
|
---|
631 | inputList(_inputList),
|
---|
632 | AddButton(_AddButton),
|
---|
633 | RemoveButton(_RemoveButton)
|
---|
634 | {}
|
---|
635 |
|
---|
636 | template<typename T> QTQueryListPipe<T>::~QTQueryListPipe()
|
---|
637 | {}
|
---|
638 |
|
---|
639 | template<typename T> void QTQueryListPipe<T>::IntegerEntered(const QString&)
|
---|
640 | {
|
---|
641 | AddButton->setEnabled(true);
|
---|
642 | }
|
---|
643 |
|
---|
644 | template<typename T> void QTQueryListPipe<T>::IntegerSelected()
|
---|
645 | {
|
---|
646 | if (inputList->selectedItems().empty())
|
---|
647 | RemoveButton->setEnabled(false);
|
---|
648 | else
|
---|
649 | RemoveButton->setEnabled(true);
|
---|
650 | }
|
---|
651 |
|
---|
652 | template<typename T> void QTQueryListPipe<T>::AddInteger() {
|
---|
653 | // type-check
|
---|
654 | std::string text = inputBox->text().toStdString();
|
---|
655 | int number = 0;
|
---|
656 | try {
|
---|
657 | number = boost::lexical_cast<int>(text);
|
---|
658 | } catch (boost::bad_lexical_cast&) {
|
---|
659 | return;
|
---|
660 | };
|
---|
661 | // add item to both
|
---|
662 | inputList->addItem(QString(number));
|
---|
663 | AddValue(number);
|
---|
664 | }
|
---|
665 |
|
---|
666 | template<typename T> void QTQueryListPipe<T>::AddValue(T item) {
|
---|
667 | content->push_back(item);
|
---|
668 |
|
---|
669 | dialog->update();
|
---|
670 | }
|
---|
671 |
|
---|
672 | template<typename T> void QTQueryListPipe<T>::RemoveInteger() {
|
---|
673 | QList<QListWidgetItem *> items = inputList->selectedItems();
|
---|
674 | for (QList<QListWidgetItem *>::iterator iter = items.begin(); !items.empty(); iter = items.begin()) {
|
---|
675 | // obtain which position item has (by making it current item)
|
---|
676 | inputList->setCurrentItem(*iter);
|
---|
677 | // remove
|
---|
678 | QTQueryListPipe<T>::RemoteRow(inputList->currentRow()); // template parameters needs to be known, such that compiler knows which to call
|
---|
679 | inputList->removeItemWidget(*iter);
|
---|
680 | }
|
---|
681 | }
|
---|
682 |
|
---|
683 | template<typename T> void QTQueryListPipe<T>::RemoveRow(int row) {
|
---|
684 | int counter = 0;
|
---|
685 | typename std::vector<T>::iterator iter = content->begin();
|
---|
686 | for (; iter != content->end(); ++iter)
|
---|
687 | if (counter++ == row)
|
---|
688 | break;
|
---|
689 | if (iter != content->end())
|
---|
690 | content->erase(iter);
|
---|
691 | }
|
---|
692 |
|
---|
693 |
|
---|
694 | StringQTQueryPipe::StringQTQueryPipe(string *_content, QTDialog *_dialog) :
|
---|
695 | content(_content),
|
---|
696 | dialog(_dialog)
|
---|
697 | {}
|
---|
698 |
|
---|
699 | StringQTQueryPipe::~StringQTQueryPipe()
|
---|
700 | {}
|
---|
701 |
|
---|
702 | void StringQTQueryPipe::update(const QString& newText) {
|
---|
703 | content->assign(newText.toStdString());
|
---|
704 | dialog->update();
|
---|
705 | }
|
---|
706 |
|
---|
707 | IntQTQueryPipe::IntQTQueryPipe(int *_content, QTDialog *_dialog) :
|
---|
708 | content(_content),
|
---|
709 | dialog(_dialog)
|
---|
710 | {}
|
---|
711 |
|
---|
712 | IntQTQueryPipe::~IntQTQueryPipe()
|
---|
713 | {}
|
---|
714 |
|
---|
715 | void IntQTQueryPipe::update(int newInt) {
|
---|
716 | (*content) = newInt;
|
---|
717 | dialog->update();
|
---|
718 | }
|
---|
719 |
|
---|
720 | DoubleQTQueryPipe::DoubleQTQueryPipe(double *_content, QTDialog *_dialog) :
|
---|
721 | content(_content),
|
---|
722 | dialog(_dialog)
|
---|
723 | {}
|
---|
724 |
|
---|
725 | DoubleQTQueryPipe::~DoubleQTQueryPipe()
|
---|
726 | {}
|
---|
727 |
|
---|
728 | void DoubleQTQueryPipe::update(double newDbl) {
|
---|
729 | (*content) = newDbl;
|
---|
730 | dialog->update();
|
---|
731 | }
|
---|
732 |
|
---|
733 | VectorQTQueryPipe::VectorQTQueryPipe(Vector *_content, QTDialog *_dialog, QComboBox *_theBox) :
|
---|
734 | content(_content),
|
---|
735 | dialog(_dialog),
|
---|
736 | theBox(_theBox)
|
---|
737 | {}
|
---|
738 |
|
---|
739 | VectorQTQueryPipe::~VectorQTQueryPipe()
|
---|
740 | {}
|
---|
741 |
|
---|
742 | void VectorQTQueryPipe::update() {
|
---|
743 | dialog->update();
|
---|
744 | }
|
---|
745 |
|
---|
746 | VectorsQTQueryPipe::VectorsQTQueryPipe(std::vector<Vector> *_content, QTDialog *_dialog, QComboBox *_theBox) :
|
---|
747 | content(_content),
|
---|
748 | dialog(_dialog),
|
---|
749 | theBox(_theBox)
|
---|
750 | {}
|
---|
751 |
|
---|
752 | VectorsQTQueryPipe::~VectorsQTQueryPipe()
|
---|
753 | {}
|
---|
754 |
|
---|
755 | void VectorsQTQueryPipe::update() {
|
---|
756 | dialog->update();
|
---|
757 | }
|
---|
758 |
|
---|
759 | AtomQTQueryPipe::AtomQTQueryPipe(atom **_content, QTDialog *_dialog, QComboBox *_theBox) :
|
---|
760 | content(_content),
|
---|
761 | dialog(_dialog),
|
---|
762 | theBox(_theBox)
|
---|
763 | {}
|
---|
764 |
|
---|
765 | AtomQTQueryPipe::~AtomQTQueryPipe()
|
---|
766 | {}
|
---|
767 |
|
---|
768 | void AtomQTQueryPipe::update(int newIndex) {
|
---|
769 | QVariant data = theBox->itemData(newIndex);
|
---|
770 | int idx = data.toInt();
|
---|
771 | (*content) = World::getInstance().getAtom(AtomById(idx));
|
---|
772 | dialog->update();
|
---|
773 | }
|
---|
774 |
|
---|
775 |
|
---|
776 | AtomsQTQueryPipe::AtomsQTQueryPipe(std::vector<atom *>*_content, QTDialog *_dialog, QComboBox *_theBox) :
|
---|
777 | content(_content),
|
---|
778 | dialog(_dialog),
|
---|
779 | theBox(_theBox)
|
---|
780 | {}
|
---|
781 |
|
---|
782 | AtomsQTQueryPipe::~AtomsQTQueryPipe()
|
---|
783 | {}
|
---|
784 |
|
---|
785 | void AtomsQTQueryPipe::update(int newIndex) {
|
---|
786 | QVariant data = theBox->itemData(newIndex);
|
---|
787 | int idx = data.toInt();
|
---|
788 | atom *Walker = World::getInstance().getAtom(AtomById(idx));
|
---|
789 | if (Walker)
|
---|
790 | (*content).push_back(Walker) ;
|
---|
791 | dialog->update();
|
---|
792 | }
|
---|
793 |
|
---|
794 |
|
---|
795 | MoleculeQTQueryPipe::MoleculeQTQueryPipe(molecule **_content, QTDialog *_dialog, QComboBox *_theBox) :
|
---|
796 | content(_content),
|
---|
797 | dialog(_dialog),
|
---|
798 | theBox(_theBox)
|
---|
799 | {}
|
---|
800 |
|
---|
801 | MoleculeQTQueryPipe::~MoleculeQTQueryPipe()
|
---|
802 | {}
|
---|
803 |
|
---|
804 | void MoleculeQTQueryPipe::update(int newIndex) {
|
---|
805 | QVariant data = theBox->itemData(newIndex);
|
---|
806 | int idx = data.toInt();
|
---|
807 | (*content) = World::getInstance().getMolecule(MoleculeById(idx));
|
---|
808 | dialog->update();
|
---|
809 | }
|
---|
810 |
|
---|
811 |
|
---|
812 | MoleculesQTQueryPipe::MoleculesQTQueryPipe(std::vector<molecule *>*_content, QTDialog *_dialog, QComboBox *_theBox) :
|
---|
813 | content(_content),
|
---|
814 | dialog(_dialog),
|
---|
815 | theBox(_theBox)
|
---|
816 | {}
|
---|
817 |
|
---|
818 | MoleculesQTQueryPipe::~MoleculesQTQueryPipe()
|
---|
819 | {}
|
---|
820 |
|
---|
821 | void MoleculesQTQueryPipe::update(int newIndex) {
|
---|
822 | QVariant data = theBox->itemData(newIndex);
|
---|
823 | int idx = data.toInt();
|
---|
824 | molecule *mol = World::getInstance().getMolecule(MoleculeById(idx));
|
---|
825 | if (mol)
|
---|
826 | (*content).push_back(mol);
|
---|
827 | dialog->update();
|
---|
828 | }
|
---|
829 |
|
---|
830 | ElementQTQueryPipe::ElementQTQueryPipe(const element **_content, QTDialog *_dialog, QComboBox *_theBox) :
|
---|
831 | content(_content),
|
---|
832 | dialog(_dialog),
|
---|
833 | theBox(_theBox)
|
---|
834 | {}
|
---|
835 |
|
---|
836 | ElementQTQueryPipe::~ElementQTQueryPipe()
|
---|
837 | {}
|
---|
838 |
|
---|
839 | void ElementQTQueryPipe::update(int newIndex) {
|
---|
840 | QVariant data = theBox->itemData(newIndex);
|
---|
841 | int idx = data.toInt();
|
---|
842 | *content = World::getInstance().getPeriode()->FindElement(idx);
|
---|
843 | dialog->update();
|
---|
844 | }
|
---|
845 |
|
---|
846 | ElementsQTQueryPipe::ElementsQTQueryPipe(std::vector<const element *>*_content, QTDialog *_dialog, QComboBox *_theBox) :
|
---|
847 | content(_content),
|
---|
848 | dialog(_dialog),
|
---|
849 | theBox(_theBox)
|
---|
850 | {}
|
---|
851 |
|
---|
852 | ElementsQTQueryPipe::~ElementsQTQueryPipe()
|
---|
853 | {}
|
---|
854 |
|
---|
855 | void ElementsQTQueryPipe::update(int newIndex) {
|
---|
856 | QVariant data = theBox->itemData(newIndex);
|
---|
857 | int idx = data.toInt();
|
---|
858 | const element *elemental = World::getInstance().getPeriode()->FindElement(idx);
|
---|
859 | if(elemental)
|
---|
860 | (*content).push_back(elemental);
|
---|
861 | dialog->update();
|
---|
862 | }
|
---|
863 |
|
---|
864 |
|
---|