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(const char* title, std::string)
|
---|
101 | {
|
---|
102 | registerQuery(new EmptyQTQuery(title,inputLayout,this));
|
---|
103 | }
|
---|
104 |
|
---|
105 | void QTDialog::queryBoolean(const char* title,string)
|
---|
106 | {
|
---|
107 | registerQuery(new BooleanQTQuery(title,inputLayout,this));
|
---|
108 | }
|
---|
109 |
|
---|
110 | void QTDialog::queryAtom(const char* title, std::string)
|
---|
111 | {
|
---|
112 | registerQuery(new AtomQTQuery(title,inputLayout,this));
|
---|
113 | }
|
---|
114 |
|
---|
115 | void QTDialog::queryAtoms(const char* title, std::string)
|
---|
116 | {
|
---|
117 | registerQuery(new AtomsQTQuery(title,inputLayout,this));
|
---|
118 | }
|
---|
119 |
|
---|
120 | void QTDialog::queryBox(const char* title, std::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 | {
|
---|
138 | registerQuery(new DoubleQTQuery(title,inputLayout,this));
|
---|
139 | }
|
---|
140 |
|
---|
141 | void QTDialog::queryDoubles(const char* title,string)
|
---|
142 | {
|
---|
143 | registerQuery(new DoublesQTQuery(title,inputLayout,this));
|
---|
144 | }
|
---|
145 |
|
---|
146 | void QTDialog::queryString(const char* title,string)
|
---|
147 | {
|
---|
148 | registerQuery(new StringQTQuery(title,inputLayout,this));
|
---|
149 | }
|
---|
150 |
|
---|
151 | void QTDialog::queryStrings(const char* title,string)
|
---|
152 | {
|
---|
153 | registerQuery(new StringsQTQuery(title,inputLayout,this));
|
---|
154 | }
|
---|
155 |
|
---|
156 | void QTDialog::queryMolecule(const char *title,string)
|
---|
157 | {
|
---|
158 | registerQuery(new MoleculeQTQuery(title,inputLayout,this));
|
---|
159 | }
|
---|
160 |
|
---|
161 | void QTDialog::queryMolecules(const char *title,string)
|
---|
162 | {
|
---|
163 | // TODO
|
---|
164 | ASSERT(false, "Not implemented yet");
|
---|
165 | }
|
---|
166 |
|
---|
167 | void QTDialog::queryVector(const char* title, bool check,string)
|
---|
168 | {
|
---|
169 | registerQuery(new VectorQTQuery(title,check,inputLayout,this));
|
---|
170 | }
|
---|
171 |
|
---|
172 | void QTDialog::queryVectors(const char* title, bool check,string)
|
---|
173 | {
|
---|
174 | // TODO
|
---|
175 | ASSERT(false, "Not implemented yet");
|
---|
176 | }
|
---|
177 |
|
---|
178 | void QTDialog::queryElement(const char* title, std::string)
|
---|
179 | {
|
---|
180 | registerQuery(new ElementQTQuery(title,inputLayout,this));
|
---|
181 | }
|
---|
182 |
|
---|
183 | void QTDialog::queryElements(const char* title, std::string)
|
---|
184 | {
|
---|
185 | // TODO
|
---|
186 | ASSERT(false, "Not implemented yet");
|
---|
187 | }
|
---|
188 |
|
---|
189 | void QTDialog::queryFile(const char* title, std::string)
|
---|
190 | {
|
---|
191 | registerQuery(new FileQTQuery(title,inputLayout,this));
|
---|
192 | }
|
---|
193 |
|
---|
194 | /************************** Query Objects *******************************/
|
---|
195 |
|
---|
196 | QTDialog::AtomQTQuery::AtomQTQuery(string _title,QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
197 | Dialog::AtomQuery(_title),
|
---|
198 | parent(_parent)
|
---|
199 | {
|
---|
200 | thisLayout = new QHBoxLayout();
|
---|
201 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
202 | inputBox = new QComboBox();
|
---|
203 | inputBox->insertItem(-1, QString("no atom"));
|
---|
204 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
---|
205 | for (std::vector<atom *>::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter)
|
---|
206 | inputBox->insertItem((*iter)->getNr(),QString::fromStdString((*iter)->getName()));
|
---|
207 |
|
---|
208 | parent->addLayout(thisLayout);
|
---|
209 | thisLayout->addWidget(titleLabel);
|
---|
210 | thisLayout->addWidget(inputBox);
|
---|
211 |
|
---|
212 | pipe = new AtomQTQueryPipe(&tmp,_dialog, inputBox);
|
---|
213 | pipe->update(inputBox->currentIndex());
|
---|
214 | connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
|
---|
215 | }
|
---|
216 |
|
---|
217 | QTDialog::AtomQTQuery::~AtomQTQuery()
|
---|
218 | {
|
---|
219 | delete pipe;
|
---|
220 | }
|
---|
221 |
|
---|
222 | bool QTDialog::AtomQTQuery::handle() {
|
---|
223 | return true;
|
---|
224 | }
|
---|
225 |
|
---|
226 |
|
---|
227 | QTDialog::AtomsQTQuery::AtomsQTQuery(string _title,QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
228 | Dialog::AtomsQuery(_title),
|
---|
229 | parent(_parent)
|
---|
230 | {
|
---|
231 | QHBoxLayout * thisHLayout = new QHBoxLayout();
|
---|
232 | QVBoxLayout * thisV1Layout = new QVBoxLayout();
|
---|
233 | QVBoxLayout * thisV2Layout = new QVBoxLayout();
|
---|
234 |
|
---|
235 | QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
236 | QLabel *inputLabel = new QLabel("Enter to add");
|
---|
237 | QListWidget* inputList = new QListWidget();
|
---|
238 | inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
239 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
---|
240 | for (std::vector<atom *>::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter)
|
---|
241 | inputBox->insertItem((*iter)->getNr(),QString((*iter)->getNr()));
|
---|
242 |
|
---|
243 | QLineEdit* inputBox = new QLineEdit();
|
---|
244 | inputLabel->setBuddy(inputBox);
|
---|
245 | titleLabel->setBuddy(inputList);
|
---|
246 | QPushButton* AddButton = new QPushButton("Add");
|
---|
247 | AddButton->setEnabled(false);
|
---|
248 | QPushButton* RemoveButton = new QPushButton("Remove");
|
---|
249 | RemoveButton->setEnabled(false);
|
---|
250 |
|
---|
251 | thisV1Layout->addWidget(titleLabel);
|
---|
252 | thisV1Layout->addWidget(inputList);
|
---|
253 | thisV2Layout->addWidget(inputLabel);
|
---|
254 | thisV2Layout->addWidget(inputBox);
|
---|
255 | thisV2Layout->addWidget(AddButton);
|
---|
256 | thisV2Layout->addWidget(RemoveButton);
|
---|
257 | parent->addLayout(thisHLayout);
|
---|
258 | thisHLayout->addLayout(thisV1Layout);
|
---|
259 | thisHLayout->addLayout(thisV2Layout);
|
---|
260 |
|
---|
261 | pipe = new AtomsQTQueryPipe(&tmp,_dialog,inputList);
|
---|
262 | connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
|
---|
263 | connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(add()));
|
---|
264 | connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(remove()));
|
---|
265 | }
|
---|
266 |
|
---|
267 | QTDialog::AtomsQTQuery::~AtomsQTQuery()
|
---|
268 | {
|
---|
269 | delete pipe;
|
---|
270 | }
|
---|
271 |
|
---|
272 | bool QTDialog::AtomsQTQuery::handle() {
|
---|
273 | return true;
|
---|
274 | }
|
---|
275 |
|
---|
276 | QTDialog::IntQTQuery::IntQTQuery(string _title,QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
277 | Dialog::IntQuery(_title),
|
---|
278 | parent(_parent)
|
---|
279 | {
|
---|
280 | thisLayout = new QHBoxLayout();
|
---|
281 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
282 | inputBox = new QSpinBox();
|
---|
283 | inputBox->setValue(0);
|
---|
284 | parent->addLayout(thisLayout);
|
---|
285 | thisLayout->addWidget(titleLabel);
|
---|
286 | thisLayout->addWidget(inputBox);
|
---|
287 |
|
---|
288 | pipe = new IntQTQueryPipe(&tmp,_dialog);
|
---|
289 | pipe->update(inputBox->value());
|
---|
290 | connect(inputBox,SIGNAL(valueChanged(int)),pipe,SLOT(update(int)));
|
---|
291 | }
|
---|
292 |
|
---|
293 | QTDialog::IntQTQuery::~IntQTQuery()
|
---|
294 | {
|
---|
295 | delete pipe;
|
---|
296 | }
|
---|
297 |
|
---|
298 | bool QTDialog::IntQTQuery::handle() {
|
---|
299 | return true;
|
---|
300 | }
|
---|
301 |
|
---|
302 |
|
---|
303 | QTDialog::IntsQTQuery::IntsQTQuery(string _title,QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
304 | Dialog::IntsQuery(_title),
|
---|
305 | parent(_parent)
|
---|
306 | {
|
---|
307 | QHBoxLayout * thisHLayout = new QHBoxLayout();
|
---|
308 | QVBoxLayout * thisV1Layout = new QVBoxLayout();
|
---|
309 | QVBoxLayout * thisV2Layout = new QVBoxLayout();
|
---|
310 |
|
---|
311 | QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
312 | QLabel *inputLabel = new QLabel("Enter to add");
|
---|
313 | QListWidget* inputList = new QListWidget();
|
---|
314 | inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
315 | QLineEdit* inputBox = new QLineEdit();
|
---|
316 | inputLabel->setBuddy(inputBox);
|
---|
317 | titleLabel->setBuddy(inputList);
|
---|
318 | QPushButton* AddButton = new QPushButton("Add");
|
---|
319 | AddButton->setEnabled(false);
|
---|
320 | QPushButton* RemoveButton = new QPushButton("Remove");
|
---|
321 | RemoveButton->setEnabled(false);
|
---|
322 |
|
---|
323 | thisV1Layout->addWidget(titleLabel);
|
---|
324 | thisV1Layout->addWidget(inputList);
|
---|
325 | thisV2Layout->addWidget(inputLabel);
|
---|
326 | thisV2Layout->addWidget(inputBox);
|
---|
327 | thisV2Layout->addWidget(AddButton);
|
---|
328 | thisV2Layout->addWidget(RemoveButton);
|
---|
329 | parent->addLayout(thisHLayout);
|
---|
330 | thisHLayout->addLayout(thisV1Layout);
|
---|
331 | thisHLayout->addLayout(thisV2Layout);
|
---|
332 |
|
---|
333 | pipe = new QTQueryListPipe<int>(&tmp,_dialog,inputBox,inputList,AddButton,RemoveButton);
|
---|
334 | connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(IntegerEntered(const QString&)));
|
---|
335 | connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
|
---|
336 | connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(AddValue()));
|
---|
337 | connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(RemoveRow()));
|
---|
338 | }
|
---|
339 |
|
---|
340 | QTDialog::IntsQTQuery::~IntsQTQuery()
|
---|
341 | {
|
---|
342 | delete pipe;
|
---|
343 | }
|
---|
344 |
|
---|
345 | bool QTDialog::IntsQTQuery::handle() {
|
---|
346 | return true;
|
---|
347 | }
|
---|
348 |
|
---|
349 |
|
---|
350 | QTDialog::DoubleQTQuery::DoubleQTQuery(string title,QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
351 | Dialog::DoubleQuery(title),
|
---|
352 | parent(_parent)
|
---|
353 | {
|
---|
354 | thisLayout = new QHBoxLayout();
|
---|
355 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
356 | inputBox = new QDoubleSpinBox();
|
---|
357 | inputBox->setValue(0);
|
---|
358 | inputBox->setRange(-numeric_limits<double>::max(),numeric_limits<double>::max());
|
---|
359 | inputBox->setDecimals(3);
|
---|
360 | parent->addLayout(thisLayout);
|
---|
361 | thisLayout->addWidget(titleLabel);
|
---|
362 | thisLayout->addWidget(inputBox);
|
---|
363 |
|
---|
364 | pipe = new DoubleQTQueryPipe(&tmp,_dialog);
|
---|
365 | pipe->update(inputBox->value());
|
---|
366 | connect(inputBox,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
|
---|
367 | }
|
---|
368 |
|
---|
369 | QTDialog::DoubleQTQuery::~DoubleQTQuery()
|
---|
370 | {
|
---|
371 | delete pipe;
|
---|
372 | }
|
---|
373 |
|
---|
374 | bool QTDialog::DoubleQTQuery::handle() {
|
---|
375 | return true;
|
---|
376 | }
|
---|
377 |
|
---|
378 |
|
---|
379 | QTDialog::DoublesQTQuery::DoublesQTQuery(string title,QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
380 | Dialog::DoublesQuery(title),
|
---|
381 | parent(_parent)
|
---|
382 | {
|
---|
383 | QHBoxLayout * thisHLayout = new QHBoxLayout();
|
---|
384 | QVBoxLayout * thisV1Layout = new QVBoxLayout();
|
---|
385 | QVBoxLayout * thisV2Layout = new QVBoxLayout();
|
---|
386 |
|
---|
387 | QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
388 | QLabel *inputLabel = new QLabel("Enter to add");
|
---|
389 | QListWidget* inputList = new QListWidget();
|
---|
390 | inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
391 | QLineEdit* inputBox = new QLineEdit();
|
---|
392 | inputLabel->setBuddy(inputBox);
|
---|
393 | titleLabel->setBuddy(inputList);
|
---|
394 | QPushButton* AddButton = new QPushButton("Add");
|
---|
395 | AddButton->setEnabled(false);
|
---|
396 | QPushButton* RemoveButton = new QPushButton("Remove");
|
---|
397 | RemoveButton->setEnabled(false);
|
---|
398 |
|
---|
399 | thisV1Layout->addWidget(titleLabel);
|
---|
400 | thisV1Layout->addWidget(inputList);
|
---|
401 | thisV2Layout->addWidget(inputLabel);
|
---|
402 | thisV2Layout->addWidget(inputBox);
|
---|
403 | thisV2Layout->addWidget(AddButton);
|
---|
404 | thisV2Layout->addWidget(RemoveButton);
|
---|
405 | parent->addLayout(thisHLayout);
|
---|
406 | thisHLayout->addLayout(thisV1Layout);
|
---|
407 | thisHLayout->addLayout(thisV2Layout);
|
---|
408 |
|
---|
409 | pipe = new QTQueryListPipe<double>(&tmp,_dialog,inputBox,inputList,AddButton,RemoveButton);
|
---|
410 | connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(IntegerEntered(const QString&)));
|
---|
411 | connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
|
---|
412 | connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(AddValue()));
|
---|
413 | connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(RemoveRow()));}
|
---|
414 |
|
---|
415 | QTDialog::DoublesQTQuery::~DoublesQTQuery()
|
---|
416 | {
|
---|
417 | delete pipe;
|
---|
418 | }
|
---|
419 |
|
---|
420 | bool QTDialog::DoublesQTQuery::handle() {
|
---|
421 | return true;
|
---|
422 | }
|
---|
423 |
|
---|
424 |
|
---|
425 | QTDialog::StringQTQuery::StringQTQuery(string _title,QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
426 | Dialog::StringQuery(_title),
|
---|
427 | parent(_parent)
|
---|
428 | {
|
---|
429 | thisLayout = new QHBoxLayout();
|
---|
430 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
431 | inputBox = new QLineEdit();
|
---|
432 | parent->addLayout(thisLayout);
|
---|
433 | thisLayout->addWidget(titleLabel);
|
---|
434 | thisLayout->addWidget(inputBox);
|
---|
435 |
|
---|
436 | pipe = new StringQTQueryPipe(&tmp,_dialog);
|
---|
437 | pipe->update(inputBox->text());
|
---|
438 | connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(update(const QString&)));
|
---|
439 | }
|
---|
440 |
|
---|
441 | QTDialog::StringQTQuery::~StringQTQuery()
|
---|
442 | {
|
---|
443 | delete pipe;
|
---|
444 | }
|
---|
445 |
|
---|
446 | // All values besides the empty std::string are valid
|
---|
447 | bool QTDialog::StringQTQuery::handle()
|
---|
448 | {
|
---|
449 | return tmp!="";
|
---|
450 | }
|
---|
451 |
|
---|
452 | QTDialog::StringsQTQuery::StringsQTQuery(string _title,QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
453 | Dialog::StringsQuery(_title),
|
---|
454 | parent(_parent)
|
---|
455 | {
|
---|
456 | QHBoxLayout * thisHLayout = new QHBoxLayout();
|
---|
457 | QVBoxLayout * thisV1Layout = new QVBoxLayout();
|
---|
458 | QVBoxLayout * thisV2Layout = new QVBoxLayout();
|
---|
459 |
|
---|
460 | QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
461 | QLabel *inputLabel = new QLabel("Enter to add");
|
---|
462 | QListWidget* inputList = new QListWidget();
|
---|
463 | inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
464 | QLineEdit* inputBox = new QLineEdit();
|
---|
465 | inputLabel->setBuddy(inputBox);
|
---|
466 | titleLabel->setBuddy(inputList);
|
---|
467 | QPushButton* AddButton = new QPushButton("Add");
|
---|
468 | AddButton->setEnabled(false);
|
---|
469 | QPushButton* RemoveButton = new QPushButton("Remove");
|
---|
470 | RemoveButton->setEnabled(false);
|
---|
471 |
|
---|
472 | thisV1Layout->addWidget(titleLabel);
|
---|
473 | thisV1Layout->addWidget(inputList);
|
---|
474 | thisV2Layout->addWidget(inputLabel);
|
---|
475 | thisV2Layout->addWidget(inputBox);
|
---|
476 | thisV2Layout->addWidget(AddButton);
|
---|
477 | thisV2Layout->addWidget(RemoveButton);
|
---|
478 | parent->addLayout(thisHLayout);
|
---|
479 | thisHLayout->addLayout(thisV1Layout);
|
---|
480 | thisHLayout->addLayout(thisV2Layout);
|
---|
481 |
|
---|
482 | pipe = new QTQueryListPipe<std::string>(&tmp,_dialog,inputBox,inputList,AddButton,RemoveButton);
|
---|
483 | connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(IntegerEntered(const QString&)));
|
---|
484 | connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
|
---|
485 | connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(AddValue()));
|
---|
486 | connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(RemoveRow()));}
|
---|
487 |
|
---|
488 | QTDialog::StringsQTQuery::~StringsQTQuery()
|
---|
489 | {
|
---|
490 | delete pipe;
|
---|
491 | }
|
---|
492 |
|
---|
493 | // All values besides the empty std::string are valid
|
---|
494 | bool QTDialog::StringsQTQuery::handle()
|
---|
495 | {
|
---|
496 | // dissect by ","
|
---|
497 | std::string::iterator olditer = temp.begin();
|
---|
498 | for(string::iterator iter = temp.begin(); iter != temp.end(); ++iter) {
|
---|
499 | if (*iter == ' ') {
|
---|
500 | tmp.push_back(string(iter, olditer));
|
---|
501 | olditer = iter;
|
---|
502 | }
|
---|
503 | }
|
---|
504 | if (olditer != temp.begin()) // insert last part also
|
---|
505 | tmp.push_back(string(olditer, temp.end()));
|
---|
506 |
|
---|
507 | return temp!="";
|
---|
508 | }
|
---|
509 |
|
---|
510 | QTDialog::MoleculeQTQuery::MoleculeQTQuery(string _title, QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
511 | Dialog::MoleculeQuery(_title),
|
---|
512 | parent(_parent)
|
---|
513 | {
|
---|
514 | thisLayout = new QHBoxLayout();
|
---|
515 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
516 | inputBox = new QComboBox();
|
---|
517 | // add all molecules to the combo box
|
---|
518 | vector<molecule*> molecules = World::getInstance().getAllMolecules();
|
---|
519 | for(vector<molecule*>::iterator iter = molecules.begin();
|
---|
520 | iter != molecules.end();
|
---|
521 | ++iter) {
|
---|
522 | std::stringstream sstr;
|
---|
523 | sstr << (*iter)->IndexNr << "\t" << (*iter)->getName();
|
---|
524 | inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter)->IndexNr));
|
---|
525 | }
|
---|
526 | parent->addLayout(thisLayout);
|
---|
527 | thisLayout->addWidget(titleLabel);
|
---|
528 | thisLayout->addWidget(inputBox);
|
---|
529 |
|
---|
530 | pipe = new MoleculeQTQueryPipe(&tmp,_dialog,inputBox);
|
---|
531 | pipe->update(inputBox->currentIndex());
|
---|
532 | connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
|
---|
533 | }
|
---|
534 |
|
---|
535 | QTDialog::MoleculeQTQuery::~MoleculeQTQuery()
|
---|
536 | {
|
---|
537 | delete pipe;
|
---|
538 | }
|
---|
539 |
|
---|
540 | // Handling is easy, since the GUI makes it impossible to select invalid values
|
---|
541 | bool QTDialog::MoleculeQTQuery::handle()
|
---|
542 | {
|
---|
543 | return true;
|
---|
544 | }
|
---|
545 |
|
---|
546 | QTDialog::MoleculesQTQuery::MoleculesQTQuery(string _title, QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
547 | Dialog::MoleculesQuery(_title),
|
---|
548 | parent(_parent)
|
---|
549 | {
|
---|
550 | thisLayout = new QHBoxLayout();
|
---|
551 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
552 | inputBox = new QComboBox();
|
---|
553 | // add all molecules to the combo box
|
---|
554 | vector<molecule*> molecules = World::getInstance().getAllMolecules();
|
---|
555 | for(vector<molecule*>::iterator iter = molecules.begin();
|
---|
556 | iter != molecules.end();
|
---|
557 | ++iter) {
|
---|
558 | std::stringstream sstr;
|
---|
559 | sstr << (*iter)->IndexNr << "\t" << (*iter)->getName();
|
---|
560 | inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter)->IndexNr));
|
---|
561 | }
|
---|
562 | parent->addLayout(thisLayout);
|
---|
563 | thisLayout->addWidget(titleLabel);
|
---|
564 | thisLayout->addWidget(inputBox);
|
---|
565 |
|
---|
566 | pipe = new MoleculesQTQueryPipe(&tmp,_dialog,inputBox);
|
---|
567 | pipe->update(inputBox->currentIndex());
|
---|
568 | connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
|
---|
569 | }
|
---|
570 |
|
---|
571 | QTDialog::MoleculesQTQuery::~MoleculesQTQuery()
|
---|
572 | {
|
---|
573 | delete pipe;
|
---|
574 | }
|
---|
575 |
|
---|
576 | // Handling is easy, since the GUI makes it impossible to select invalid values
|
---|
577 | bool QTDialog::MoleculesQTQuery::handle()
|
---|
578 | {
|
---|
579 | return true;
|
---|
580 | }
|
---|
581 |
|
---|
582 | QTDialog::VectorQTQuery::VectorQTQuery(std::string title, bool _check,QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
583 | Dialog::VectorQuery(title,_check),
|
---|
584 | parent(_parent)
|
---|
585 | {
|
---|
586 | mainLayout= new QHBoxLayout();
|
---|
587 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
588 | mainLayout->addWidget(titleLabel);
|
---|
589 | subLayout = new QVBoxLayout();
|
---|
590 | mainLayout->addLayout(subLayout);
|
---|
591 | QComboBox* inputBox = new QComboBox();
|
---|
592 | coordLayout = new QHBoxLayout();
|
---|
593 | subLayout->addLayout(coordLayout);
|
---|
594 | coordLabel = new QLabel(QString("x,y,z"));
|
---|
595 | coordLayout->addWidget(coordLabel);
|
---|
596 | coordInput = new QDoubleSpinBox();
|
---|
597 | // coordInput->setRange(0,M.at(i,i));
|
---|
598 | coordInput->setDecimals(3);
|
---|
599 | coordLayout->addWidget(coordInput);
|
---|
600 | pipe = new VectorQTQueryPipe(&(tmp),_dialog,inputBox);
|
---|
601 | //pipe->update(coordInput->value());
|
---|
602 | connect(coordInput,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
|
---|
603 | parent->addLayout(mainLayout);
|
---|
604 | }
|
---|
605 |
|
---|
606 | QTDialog::VectorQTQuery::~VectorQTQuery()
|
---|
607 | {}
|
---|
608 |
|
---|
609 | bool QTDialog::VectorQTQuery::handle() {
|
---|
610 | return true;
|
---|
611 | }
|
---|
612 |
|
---|
613 |
|
---|
614 | QTDialog::VectorsQTQuery::VectorsQTQuery(std::string title, bool _check,QBoxLayout *_parent,QTDialog *_dialog) :
|
---|
615 | Dialog::VectorsQuery(title,_check),
|
---|
616 | parent(_parent)
|
---|
617 | {
|
---|
618 | mainLayout= new QHBoxLayout();
|
---|
619 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
620 | mainLayout->addWidget(titleLabel);
|
---|
621 | subLayout = new QVBoxLayout();
|
---|
622 | mainLayout->addLayout(subLayout);
|
---|
623 | QComboBox* inputBox = new QComboBox();
|
---|
624 | coordLayout = new QHBoxLayout();
|
---|
625 | subLayout->addLayout(coordLayout);
|
---|
626 | coordLabel = new QLabel(QString("x,y,z"));
|
---|
627 | coordLayout->addWidget(coordLabel);
|
---|
628 | coordInput = new QDoubleSpinBox();
|
---|
629 | // coordInput->setRange(0,M.at(i,i));
|
---|
630 | coordInput->setDecimals(3);
|
---|
631 | coordLayout->addWidget(coordInput);
|
---|
632 | pipe = new VectorsQTQueryPipe(&(tmp),_dialog,inputBox);
|
---|
633 | //pipe->update(coordInput->value());
|
---|
634 | connect(coordInput,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
|
---|
635 | parent->addLayout(mainLayout);
|
---|
636 | }
|
---|
637 |
|
---|
638 | QTDialog::VectorsQTQuery::~VectorsQTQuery()
|
---|
639 | {}
|
---|
640 |
|
---|
641 | bool QTDialog::VectorsQTQuery::handle() {
|
---|
642 | return true;
|
---|
643 | }
|
---|
644 |
|
---|
645 |
|
---|
646 | QTDialog::ElementQTQuery::ElementQTQuery(std::string _title, QBoxLayout *_parent, QTDialog *_dialog) :
|
---|
647 | Dialog::ElementQuery(_title),
|
---|
648 | parent(_parent)
|
---|
649 | {
|
---|
650 | periodentafel *periode = World::getInstance().getPeriode();
|
---|
651 | thisLayout = new QHBoxLayout();
|
---|
652 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
653 | inputBox = new QComboBox();
|
---|
654 | for(periodentafel::const_iterator iter = periode->begin();
|
---|
655 | iter!=periode->end();
|
---|
656 | ++iter)
|
---|
657 | {
|
---|
658 | std::stringstream sstr;
|
---|
659 | sstr << (*iter).first << "\t" << (*iter).second->getName();
|
---|
660 | inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter).first));
|
---|
661 | }
|
---|
662 | parent->addLayout(thisLayout);
|
---|
663 | thisLayout->addWidget(titleLabel);
|
---|
664 | thisLayout->addWidget(inputBox);
|
---|
665 |
|
---|
666 | pipe = new ElementQTQueryPipe(&tmp,_dialog,inputBox);
|
---|
667 | pipe->update(inputBox->currentIndex());
|
---|
668 | connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
|
---|
669 | }
|
---|
670 |
|
---|
671 | QTDialog::ElementQTQuery::~ElementQTQuery()
|
---|
672 | {
|
---|
673 | delete pipe;
|
---|
674 | }
|
---|
675 |
|
---|
676 | bool QTDialog::ElementQTQuery::handle(){
|
---|
677 | return true;
|
---|
678 | }
|
---|
679 |
|
---|
680 |
|
---|
681 | QTDialog::ElementsQTQuery::ElementsQTQuery(std::string _title, QBoxLayout *_parent, QTDialog *_dialog) :
|
---|
682 | Dialog::ElementsQuery(_title),
|
---|
683 | parent(_parent)
|
---|
684 | {
|
---|
685 | periodentafel *periode = World::getInstance().getPeriode();
|
---|
686 | thisLayout = new QHBoxLayout();
|
---|
687 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
688 | inputBox = new QComboBox();
|
---|
689 | for(periodentafel::const_iterator iter = periode->begin();
|
---|
690 | iter!=periode->end();
|
---|
691 | ++iter)
|
---|
692 | {
|
---|
693 | std::stringstream sstr;
|
---|
694 | sstr << (*iter).first << "\t" << (*iter).second->getName();
|
---|
695 | inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter).first));
|
---|
696 | }
|
---|
697 | parent->addLayout(thisLayout);
|
---|
698 | thisLayout->addWidget(titleLabel);
|
---|
699 | thisLayout->addWidget(inputBox);
|
---|
700 |
|
---|
701 | pipe = new ElementsQTQueryPipe(&tmp,_dialog,inputBox);
|
---|
702 | pipe->update(inputBox->currentIndex());
|
---|
703 | connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
|
---|
704 | }
|
---|
705 |
|
---|
706 | QTDialog::ElementsQTQuery::~ElementsQTQuery()
|
---|
707 | {
|
---|
708 | delete pipe;
|
---|
709 | }
|
---|
710 |
|
---|
711 | bool QTDialog::ElementsQTQuery::handle(){
|
---|
712 | return true;
|
---|
713 | }
|
---|
714 |
|
---|
715 | QTDialog::EmptyQTQuery::EmptyQTQuery(std::string _title, QBoxLayout *_parent, QTDialog *_dialog) :
|
---|
716 | Dialog::EmptyQuery(_title),
|
---|
717 | parent(_parent)
|
---|
718 | {
|
---|
719 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
720 |
|
---|
721 | parent->addLayout(thisLayout);
|
---|
722 | thisLayout->addWidget(titleLabel);
|
---|
723 |
|
---|
724 | pipe = new EmptyQTQueryPipe(_dialog,titleLabel);
|
---|
725 | }
|
---|
726 |
|
---|
727 | QTDialog::EmptyQTQuery::~EmptyQTQuery()
|
---|
728 | {
|
---|
729 | delete pipe;
|
---|
730 | }
|
---|
731 |
|
---|
732 | bool QTDialog::EmptyQTQuery::handle(){
|
---|
733 | return true;
|
---|
734 | }
|
---|
735 |
|
---|
736 |
|
---|
737 | QTDialog::BooleanQTQuery::BooleanQTQuery(std::string _title, QBoxLayout *_parent, QTDialog *_dialog) :
|
---|
738 | Dialog::BooleanQuery(_title),
|
---|
739 | parent(_parent)
|
---|
740 | {
|
---|
741 | titleLabel = new QLabel(QString(getTitle().c_str()),_dialog);
|
---|
742 | booleanComboBox = new QComboBox(_dialog);
|
---|
743 | booleanComboBox->insertItem(1, QString("true"));
|
---|
744 | booleanComboBox->insertItem(0, QString("false"));
|
---|
745 |
|
---|
746 | parent->addLayout(thisLayout);
|
---|
747 | thisLayout->addWidget(titleLabel);
|
---|
748 | thisLayout->addWidget(booleanComboBox);
|
---|
749 |
|
---|
750 | pipe = new BooleanQTQueryPipe(&tmp,_dialog,booleanComboBox);
|
---|
751 | connect(booleanComboBox, SIGNAL(currentIndexChanged()), pipe, SLOT(update()));
|
---|
752 | }
|
---|
753 |
|
---|
754 | QTDialog::BooleanQTQuery::~BooleanQTQuery()
|
---|
755 | {
|
---|
756 | delete pipe;
|
---|
757 | }
|
---|
758 |
|
---|
759 | bool QTDialog::BooleanQTQuery::handle(){
|
---|
760 | return true;
|
---|
761 | }
|
---|
762 |
|
---|
763 |
|
---|
764 | QTDialog::FileQTQuery::FileQTQuery(std::string _title, QBoxLayout *_parent, QTDialog *_dialog) :
|
---|
765 | Dialog::FileQuery(_title),
|
---|
766 | parent(_parent)
|
---|
767 | {
|
---|
768 |
|
---|
769 | filenameLineEdit = new QLineEdit(_dialog);
|
---|
770 | filenameLineEdit->setText(QString());
|
---|
771 | filenameLineEdit->setReadOnly(true);
|
---|
772 |
|
---|
773 | filenameLabel = new QLabel(QString("Input file:"));
|
---|
774 | filenameLabel->setBuddy(filenameLineEdit);
|
---|
775 |
|
---|
776 | filedialogButton = new QPushButton("&Choose", _dialog);
|
---|
777 |
|
---|
778 | pipe = new FileQTQueryPipe(&tmp,_dialog,filenameLineEdit,filedialogButton);
|
---|
779 |
|
---|
780 | thisLayout = new QHBoxLayout();
|
---|
781 | parent->addLayout(thisLayout);
|
---|
782 | thisLayout->addWidget(filenameLabel);
|
---|
783 | thisLayout->addWidget(filenameLineEdit);
|
---|
784 | thisLayout->addWidget(filedialogButton);
|
---|
785 |
|
---|
786 | QObject::connect(filedialogButton,SIGNAL(clicked()),pipe,SLOT(showFileDialog()));
|
---|
787 | }
|
---|
788 |
|
---|
789 | QTDialog::FileQTQuery::~FileQTQuery()
|
---|
790 | {
|
---|
791 | delete pipe;
|
---|
792 | }
|
---|
793 |
|
---|
794 | bool QTDialog::FileQTQuery::handle(){
|
---|
795 | return true;
|
---|
796 | }
|
---|
797 |
|
---|
798 | /*************************** Plumbing *******************************/
|
---|
799 |
|
---|
800 |
|
---|
801 | template<typename T> QTQueryListPipe<T>::QTQueryListPipe(std::vector<T> *_content, QTDialog *_dialog, QLineEdit *_inputBox, QListWidget *_inputList, QPushButton *_AddButton, QPushButton *_RemoveButton) :
|
---|
802 | content(_content),
|
---|
803 | dialog(_dialog),
|
---|
804 | inputBox(_inputBox),
|
---|
805 | inputList(_inputList),
|
---|
806 | AddButton(_AddButton),
|
---|
807 | RemoveButton(_RemoveButton)
|
---|
808 | {}
|
---|
809 |
|
---|
810 | template<typename T> QTQueryListPipe<T>::~QTQueryListPipe()
|
---|
811 | {}
|
---|
812 |
|
---|
813 | template<typename T> void QTQueryListPipe<T>::IntegerEntered(const QString&)
|
---|
814 | {
|
---|
815 | AddButton->setEnabled(true);
|
---|
816 | }
|
---|
817 |
|
---|
818 | template<typename T> void QTQueryListPipe<T>::IntegerSelected()
|
---|
819 | {
|
---|
820 | if (inputList->selectedItems().empty())
|
---|
821 | RemoveButton->setEnabled(false);
|
---|
822 | else
|
---|
823 | RemoveButton->setEnabled(true);
|
---|
824 | }
|
---|
825 |
|
---|
826 | template<typename T> void QTQueryListPipe<T>::AddInteger() {
|
---|
827 | // type-check
|
---|
828 | std::string text = inputBox->text().toStdString();
|
---|
829 | int number = 0;
|
---|
830 | try {
|
---|
831 | number = boost::lexical_cast<int>(text);
|
---|
832 | } catch (boost::bad_lexical_cast&) {
|
---|
833 | return;
|
---|
834 | };
|
---|
835 | // add item to both
|
---|
836 | inputList->addItem(QString(number));
|
---|
837 | AddValue(number);
|
---|
838 | }
|
---|
839 |
|
---|
840 | template<typename T> void QTQueryListPipe<T>::AddValue(T item) {
|
---|
841 | content->push_back(item);
|
---|
842 |
|
---|
843 | dialog->update();
|
---|
844 | }
|
---|
845 |
|
---|
846 | template<typename T> void QTQueryListPipe<T>::RemoveInteger() {
|
---|
847 | QList<QListWidgetItem *> items = inputList->selectedItems();
|
---|
848 | for (QList<QListWidgetItem *>::iterator iter = items.begin(); !items.empty(); iter = items.begin()) {
|
---|
849 | // obtain which position item has (by making it current item)
|
---|
850 | inputList->setCurrentItem(*iter);
|
---|
851 | // remove
|
---|
852 | QTQueryListPipe<T>::RemoteRow(inputList->currentRow()); // template parameters needs to be known, such that compiler knows which to call
|
---|
853 | inputList->removeItemWidget(*iter);
|
---|
854 | }
|
---|
855 | }
|
---|
856 |
|
---|
857 | template<typename T> void QTQueryListPipe<T>::RemoveRow(int row) {
|
---|
858 | int counter = 0;
|
---|
859 | typename std::vector<T>::iterator iter = content->begin();
|
---|
860 | for (; iter != content->end(); ++iter)
|
---|
861 | if (counter++ == row)
|
---|
862 | break;
|
---|
863 | if (iter != content->end())
|
---|
864 | content->erase(iter);
|
---|
865 | }
|
---|
866 |
|
---|
867 |
|
---|
868 | StringQTQueryPipe::StringQTQueryPipe(string *_content, QTDialog *_dialog) :
|
---|
869 | content(_content),
|
---|
870 | dialog(_dialog)
|
---|
871 | {}
|
---|
872 |
|
---|
873 | StringQTQueryPipe::~StringQTQueryPipe()
|
---|
874 | {}
|
---|
875 |
|
---|
876 | void StringQTQueryPipe::update(const QString& newText) {
|
---|
877 | content->assign(newText.toStdString());
|
---|
878 | dialog->update();
|
---|
879 | }
|
---|
880 |
|
---|
881 | IntQTQueryPipe::IntQTQueryPipe(int *_content, QTDialog *_dialog) :
|
---|
882 | content(_content),
|
---|
883 | dialog(_dialog)
|
---|
884 | {}
|
---|
885 |
|
---|
886 | IntQTQueryPipe::~IntQTQueryPipe()
|
---|
887 | {}
|
---|
888 |
|
---|
889 | void IntQTQueryPipe::update(int newInt) {
|
---|
890 | (*content) = newInt;
|
---|
891 | dialog->update();
|
---|
892 | }
|
---|
893 |
|
---|
894 | DoubleQTQueryPipe::DoubleQTQueryPipe(double *_content, QTDialog *_dialog) :
|
---|
895 | content(_content),
|
---|
896 | dialog(_dialog)
|
---|
897 | {}
|
---|
898 |
|
---|
899 | DoubleQTQueryPipe::~DoubleQTQueryPipe()
|
---|
900 | {}
|
---|
901 |
|
---|
902 | void DoubleQTQueryPipe::update(double newDbl) {
|
---|
903 | (*content) = newDbl;
|
---|
904 | dialog->update();
|
---|
905 | }
|
---|
906 |
|
---|
907 | VectorQTQueryPipe::VectorQTQueryPipe(Vector *_content, QTDialog *_dialog, QComboBox *_theBox) :
|
---|
908 | content(_content),
|
---|
909 | dialog(_dialog),
|
---|
910 | theBox(_theBox)
|
---|
911 | {}
|
---|
912 |
|
---|
913 | VectorQTQueryPipe::~VectorQTQueryPipe()
|
---|
914 | {}
|
---|
915 |
|
---|
916 | void VectorQTQueryPipe::update() {
|
---|
917 | dialog->update();
|
---|
918 | }
|
---|
919 |
|
---|
920 | VectorsQTQueryPipe::VectorsQTQueryPipe(std::vector<Vector> *_content, QTDialog *_dialog, QComboBox *_theBox) :
|
---|
921 | content(_content),
|
---|
922 | dialog(_dialog),
|
---|
923 | theBox(_theBox)
|
---|
924 | {}
|
---|
925 |
|
---|
926 | VectorsQTQueryPipe::~VectorsQTQueryPipe()
|
---|
927 | {}
|
---|
928 |
|
---|
929 | void VectorsQTQueryPipe::update() {
|
---|
930 | dialog->update();
|
---|
931 | }
|
---|
932 |
|
---|
933 | AtomQTQueryPipe::AtomQTQueryPipe(atom **_content, QTDialog *_dialog, QComboBox *_theBox) :
|
---|
934 | content(_content),
|
---|
935 | dialog(_dialog),
|
---|
936 | theBox(_theBox)
|
---|
937 | {}
|
---|
938 |
|
---|
939 | AtomQTQueryPipe::~AtomQTQueryPipe()
|
---|
940 | {}
|
---|
941 |
|
---|
942 | void AtomQTQueryPipe::update(int newIndex) {
|
---|
943 | QVariant data = theBox->itemData(newIndex);
|
---|
944 | int idx = data.toInt();
|
---|
945 | (*content) = World::getInstance().getAtom(AtomById(idx));
|
---|
946 | dialog->update();
|
---|
947 | }
|
---|
948 |
|
---|
949 |
|
---|
950 | AtomsQTQueryPipe::AtomsQTQueryPipe(std::vector<atom *>*_content, QTDialog *_dialog, QListWidget *_theList) :
|
---|
951 | content(_content),
|
---|
952 | dialog(_dialog),
|
---|
953 | theList(_theList)
|
---|
954 | {}
|
---|
955 |
|
---|
956 | AtomsQTQueryPipe::~AtomsQTQueryPipe()
|
---|
957 | {}
|
---|
958 |
|
---|
959 | void AtomsQTQueryPipe::update() {
|
---|
960 | // clear target and put all atoms therein
|
---|
961 | (*content).clear();
|
---|
962 | for (std::set<atom *>::iterator iter = currentList.begin(); iter != currentList.end(); ++iter)
|
---|
963 | (*content).push_back(*iter);
|
---|
964 | dialog->update();
|
---|
965 | }
|
---|
966 |
|
---|
967 | void AtomsQTQueryPipe::add() {
|
---|
968 | QList<QListWidgetItem *> items = theList->selectedItems();
|
---|
969 | for (QList<QListWidgetItem *>::iterator iter = items.begin();iter != items.end();++iter) {
|
---|
970 | const int index = (*iter)->text().toInt();
|
---|
971 | atom *Walker = World::getInstance().getAtom(AtomById(index));
|
---|
972 | if (Walker) {
|
---|
973 | (*content).push_back(Walker);
|
---|
974 | currentList.insert(Walker);
|
---|
975 | if (lookup.find(index) != lookup.end())
|
---|
976 | lookup.insert(pair<int, atom*>(index, Walker));
|
---|
977 | }
|
---|
978 | }
|
---|
979 | update();
|
---|
980 | }
|
---|
981 |
|
---|
982 | void AtomsQTQueryPipe::remove() {
|
---|
983 | QList<QListWidgetItem *> items = theList->selectedItems();
|
---|
984 | for (QList<QListWidgetItem *>::iterator iter = items.begin();iter != items.end();++iter) {
|
---|
985 | const int index = (*iter)->text().toInt();
|
---|
986 | atom *Walker = World::getInstance().getAtom(AtomById(index));
|
---|
987 | if (Walker) {
|
---|
988 | currentList.erase(Walker);
|
---|
989 | }
|
---|
990 | }
|
---|
991 | update();
|
---|
992 | }
|
---|
993 |
|
---|
994 |
|
---|
995 | MoleculeQTQueryPipe::MoleculeQTQueryPipe(molecule **_content, QTDialog *_dialog, QComboBox *_theBox) :
|
---|
996 | content(_content),
|
---|
997 | dialog(_dialog),
|
---|
998 | theBox(_theBox)
|
---|
999 | {}
|
---|
1000 |
|
---|
1001 | MoleculeQTQueryPipe::~MoleculeQTQueryPipe()
|
---|
1002 | {}
|
---|
1003 |
|
---|
1004 | void MoleculeQTQueryPipe::update(int newIndex) {
|
---|
1005 | QVariant data = theBox->itemData(newIndex);
|
---|
1006 | int idx = data.toInt();
|
---|
1007 | (*content) = World::getInstance().getMolecule(MoleculeById(idx));
|
---|
1008 | dialog->update();
|
---|
1009 | }
|
---|
1010 |
|
---|
1011 |
|
---|
1012 | MoleculesQTQueryPipe::MoleculesQTQueryPipe(std::vector<molecule *>*_content, QTDialog *_dialog, QComboBox *_theBox) :
|
---|
1013 | content(_content),
|
---|
1014 | dialog(_dialog),
|
---|
1015 | theBox(_theBox)
|
---|
1016 | {}
|
---|
1017 |
|
---|
1018 | MoleculesQTQueryPipe::~MoleculesQTQueryPipe()
|
---|
1019 | {}
|
---|
1020 |
|
---|
1021 | void MoleculesQTQueryPipe::update(int newIndex) {
|
---|
1022 | QVariant data = theBox->itemData(newIndex);
|
---|
1023 | int idx = data.toInt();
|
---|
1024 | molecule *mol = World::getInstance().getMolecule(MoleculeById(idx));
|
---|
1025 | if (mol)
|
---|
1026 | (*content).push_back(mol);
|
---|
1027 | dialog->update();
|
---|
1028 | }
|
---|
1029 |
|
---|
1030 | ElementQTQueryPipe::ElementQTQueryPipe(const element **_content, QTDialog *_dialog, QComboBox *_theBox) :
|
---|
1031 | content(_content),
|
---|
1032 | dialog(_dialog),
|
---|
1033 | theBox(_theBox)
|
---|
1034 | {}
|
---|
1035 |
|
---|
1036 | ElementQTQueryPipe::~ElementQTQueryPipe()
|
---|
1037 | {}
|
---|
1038 |
|
---|
1039 | void ElementQTQueryPipe::update(int newIndex) {
|
---|
1040 | QVariant data = theBox->itemData(newIndex);
|
---|
1041 | int idx = data.toInt();
|
---|
1042 | *content = World::getInstance().getPeriode()->FindElement(idx);
|
---|
1043 | dialog->update();
|
---|
1044 | }
|
---|
1045 |
|
---|
1046 | ElementsQTQueryPipe::ElementsQTQueryPipe(std::vector<const element *>*_content, QTDialog *_dialog, QComboBox *_theBox) :
|
---|
1047 | content(_content),
|
---|
1048 | dialog(_dialog),
|
---|
1049 | theBox(_theBox)
|
---|
1050 | {}
|
---|
1051 |
|
---|
1052 | ElementsQTQueryPipe::~ElementsQTQueryPipe()
|
---|
1053 | {}
|
---|
1054 |
|
---|
1055 | void ElementsQTQueryPipe::update(int newIndex) {
|
---|
1056 | QVariant data = theBox->itemData(newIndex);
|
---|
1057 | int idx = data.toInt();
|
---|
1058 | const element *elemental = World::getInstance().getPeriode()->FindElement(idx);
|
---|
1059 | if(elemental)
|
---|
1060 | (*content).push_back(elemental);
|
---|
1061 | dialog->update();
|
---|
1062 | }
|
---|
1063 |
|
---|
1064 | EmptyQTQueryPipe::EmptyQTQueryPipe(QTDialog *_dialog, QLabel *_textLabel) :
|
---|
1065 | dialog(_dialog),
|
---|
1066 | textLabel(_textLabel)
|
---|
1067 | {}
|
---|
1068 |
|
---|
1069 | EmptyQTQueryPipe::~EmptyQTQueryPipe()
|
---|
1070 | {}
|
---|
1071 |
|
---|
1072 | void EmptyQTQueryPipe::update() {
|
---|
1073 | dialog->update();
|
---|
1074 | }
|
---|
1075 |
|
---|
1076 | BooleanQTQueryPipe::BooleanQTQueryPipe(const bool *_content, QTDialog *_dialog, QComboBox *_booleanComboBox) :
|
---|
1077 | content(_content),
|
---|
1078 | dialog(_dialog),
|
---|
1079 | booleanComboBox(_booleanComboBox)
|
---|
1080 | {}
|
---|
1081 |
|
---|
1082 | BooleanQTQueryPipe::~BooleanQTQueryPipe()
|
---|
1083 | {}
|
---|
1084 |
|
---|
1085 | void BooleanQTQueryPipe::update() {
|
---|
1086 | dialog->update();
|
---|
1087 | }
|
---|
1088 |
|
---|
1089 | FileQTQueryPipe::FileQTQueryPipe(boost::filesystem::path *_content, QTDialog *_dialog, QLineEdit *_filenameLineEdit, QPushButton *_filedialogButton) :
|
---|
1090 | content(_content),
|
---|
1091 | dialog(_dialog),
|
---|
1092 | filenameLineEdit(_filenameLineEdit),
|
---|
1093 | filedialogButton(_filedialogButton)
|
---|
1094 | {
|
---|
1095 | theFileDialog = NULL;
|
---|
1096 | }
|
---|
1097 |
|
---|
1098 | FileQTQueryPipe::~FileQTQueryPipe()
|
---|
1099 | {
|
---|
1100 | if (theFileDialog != NULL)
|
---|
1101 | delete theFileDialog;
|
---|
1102 | }
|
---|
1103 |
|
---|
1104 | void FileQTQueryPipe::update() {
|
---|
1105 | QStringList ListOfFilenames = theFileDialog->selectedFiles();
|
---|
1106 | std::cout << "Selected File is " << ListOfFilenames.at(0).toStdString() << std::endl;
|
---|
1107 | (*content) = ListOfFilenames.at(0).toStdString();
|
---|
1108 | filenameLineEdit->setText(QString::fromStdString((*content).string()));
|
---|
1109 | dialog->update();
|
---|
1110 | }
|
---|
1111 |
|
---|
1112 | void FileQTQueryPipe::showFileDialog() {
|
---|
1113 | filedialogButton->setFlat(true);
|
---|
1114 | if (theFileDialog == NULL) {
|
---|
1115 | theFileDialog = new QFileDialog(NULL, tr("Open input file"), QString(), tr("ParallelCarParrinello (*.conf);;MassivelyParallelQuantumChemistry (*.mpqc);;ParticleDataBase (*.pdb);;XYZ (*.xyz)"));
|
---|
1116 | theFileDialog->setAcceptMode(QFileDialog::AcceptOpen);
|
---|
1117 | theFileDialog->setFileMode(QFileDialog::ExistingFile);
|
---|
1118 | theFileDialog->setViewMode(QFileDialog::List);
|
---|
1119 | }
|
---|
1120 | theFileDialog->exec();
|
---|
1121 |
|
---|
1122 | update();
|
---|
1123 | filedialogButton->setFlat(false);
|
---|
1124 | }
|
---|
1125 |
|
---|
1126 |
|
---|
1127 |
|
---|