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 <QtGui/QDoubleSpinBox>
|
---|
29 | #include <Qt/qboxlayout.h>
|
---|
30 | #include <Qt/qcombobox.h>
|
---|
31 | #include <Qt/qdialogbuttonbox.h>
|
---|
32 | #include <Qt/qlabel.h>
|
---|
33 | #include <Qt/qlineedit.h>
|
---|
34 | #include <Qt/qlistwidget.h>
|
---|
35 | #include <Qt/qpushbutton.h>
|
---|
36 | #include <Qt/qspinbox.h>
|
---|
37 | #include <Qt/qtablewidget.h>
|
---|
38 |
|
---|
39 | #include <boost/lexical_cast.hpp>
|
---|
40 |
|
---|
41 | #include "Helpers/MemDebug.hpp"
|
---|
42 |
|
---|
43 | #include "World.hpp"
|
---|
44 | #include "periodentafel.hpp"
|
---|
45 | #include "atom.hpp"
|
---|
46 | #include "element.hpp"
|
---|
47 | #include "molecule.hpp"
|
---|
48 | #include "Descriptors/AtomIdDescriptor.hpp"
|
---|
49 | #include "Descriptors/MoleculeIdDescriptor.hpp"
|
---|
50 | #include "LinearAlgebra/Matrix.hpp"
|
---|
51 | #include "Box.hpp"
|
---|
52 |
|
---|
53 |
|
---|
54 | using namespace std;
|
---|
55 |
|
---|
56 | QtDialog::QtDialog() :
|
---|
57 | QDialog(0)
|
---|
58 | {
|
---|
59 | // creating and filling of the Dialog window
|
---|
60 | mainLayout = new QVBoxLayout();
|
---|
61 | inputLayout = new QVBoxLayout();
|
---|
62 | buttonLayout = new QVBoxLayout();
|
---|
63 | setLayout(mainLayout);
|
---|
64 | mainLayout->addLayout(inputLayout);
|
---|
65 | mainLayout->addLayout(buttonLayout);
|
---|
66 | buttons = new QDialogButtonBox(QDialogButtonBox::Ok| QDialogButtonBox::Cancel);
|
---|
67 | buttonLayout->addWidget(buttons);
|
---|
68 |
|
---|
69 | // Disable the ok button until something was entered
|
---|
70 | buttons->button(QDialogButtonBox::Ok)->setEnabled(false);
|
---|
71 |
|
---|
72 | // connect the buttons to their appropriate slots
|
---|
73 | connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
|
---|
74 | connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
|
---|
75 | }
|
---|
76 |
|
---|
77 | QtDialog::~QtDialog()
|
---|
78 | {
|
---|
79 | }
|
---|
80 |
|
---|
81 | bool QtDialog::display(){
|
---|
82 | // Button state might have changed by some update that
|
---|
83 | // was done during query construction. To make sure
|
---|
84 | // the state is correct, we just call update one more time.
|
---|
85 | update();
|
---|
86 | if(exec()) {
|
---|
87 | setAll();
|
---|
88 | return true;
|
---|
89 | }
|
---|
90 | else {
|
---|
91 | return false;
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | void QtDialog::update(){
|
---|
96 | buttons->button(QDialogButtonBox::Ok)->setEnabled(checkAll());
|
---|
97 | }
|
---|
98 |
|
---|
99 | /************************** Query Infrastructure ************************/
|
---|
100 |
|
---|
101 | void QtDialog::queryEmpty(const char* title, std::string)
|
---|
102 | {
|
---|
103 | registerQuery(new EmptyQtQuery(title,inputLayout,this));
|
---|
104 | }
|
---|
105 |
|
---|
106 | void QtDialog::queryBoolean(const char* title,string)
|
---|
107 | {
|
---|
108 | registerQuery(new BooleanQtQuery(title,inputLayout,this));
|
---|
109 | }
|
---|
110 |
|
---|
111 | void QtDialog::queryAtom(const char* title, std::string)
|
---|
112 | {
|
---|
113 | registerQuery(new AtomQtQuery(title,inputLayout,this));
|
---|
114 | }
|
---|
115 |
|
---|
116 | void QtDialog::queryAtoms(const char* title, std::string)
|
---|
117 | {
|
---|
118 | registerQuery(new AtomsQtQuery(title,inputLayout,this));
|
---|
119 | }
|
---|
120 |
|
---|
121 | void QtDialog::queryBox(const char* title, std::string)
|
---|
122 | {
|
---|
123 | registerQuery(new BoxQtQuery(title,inputLayout,this));
|
---|
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 | registerQuery(new MoleculesQtQuery(title,inputLayout,this));
|
---|
164 | }
|
---|
165 |
|
---|
166 | void QtDialog::queryVector(const char* title, bool check,string)
|
---|
167 | {
|
---|
168 | registerQuery(new VectorQtQuery(title,check,inputLayout,this));
|
---|
169 | }
|
---|
170 |
|
---|
171 | void QtDialog::queryVectors(const char* title, bool check,string)
|
---|
172 | {
|
---|
173 | registerQuery(new VectorsQtQuery(title,check,inputLayout,this));
|
---|
174 | }
|
---|
175 |
|
---|
176 | void QtDialog::queryElement(const char* title, std::string)
|
---|
177 | {
|
---|
178 | registerQuery(new ElementQtQuery(title,inputLayout,this));
|
---|
179 | }
|
---|
180 |
|
---|
181 | void QtDialog::queryElements(const char* title, std::string)
|
---|
182 | {
|
---|
183 | registerQuery(new ElementsQtQuery(title,inputLayout,this));
|
---|
184 | }
|
---|
185 |
|
---|
186 | void QtDialog::queryFile(const char* title, std::string)
|
---|
187 | {
|
---|
188 | registerQuery(new FileQtQuery(title,inputLayout,this));
|
---|
189 | }
|
---|
190 |
|
---|
191 | /************************** Query Objects *******************************/
|
---|
192 |
|
---|
193 | QtDialog::BoxQtQuery::BoxQtQuery(string _title,QBoxLayout *_parent,QtDialog *_dialog) :
|
---|
194 | Dialog::BoxQuery(_title),
|
---|
195 | parent(_parent)
|
---|
196 | {
|
---|
197 | thisLayout = new QHBoxLayout();
|
---|
198 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
199 |
|
---|
200 | // init input table
|
---|
201 | inputTable = new QTableWidget(3,3, _dialog);
|
---|
202 | QStringList CoordinateList;
|
---|
203 | CoordinateList << "x" << "y" << "z";
|
---|
204 | inputTable->setHorizontalHeaderLabels(CoordinateList);
|
---|
205 | inputTable->setVerticalHeaderLabels(CoordinateList);
|
---|
206 |
|
---|
207 | pipe = new BoxQtQueryPipe(tmp,_dialog, inputTable);
|
---|
208 |
|
---|
209 | // fill the box with current matrix
|
---|
210 | const Matrix &domain = World::getInstance().getDomain().getM();
|
---|
211 | for (int i=0;i<3;i++)
|
---|
212 | for (int j=0;j<3;j++) {
|
---|
213 | QTableWidgetItem *newItem = new QTableWidgetItem(tr("%1").arg(domain.at(i,j)));
|
---|
214 | inputTable->setItem(i,j,newItem);
|
---|
215 | pipe->update(i,j);
|
---|
216 | }
|
---|
217 |
|
---|
218 | parent->addLayout(thisLayout);
|
---|
219 | thisLayout->addWidget(titleLabel);
|
---|
220 | thisLayout->addWidget(inputTable);
|
---|
221 |
|
---|
222 | connect(inputTable,SIGNAL(cellChanged(int,int)),pipe,SLOT(update(int,int)));
|
---|
223 | }
|
---|
224 |
|
---|
225 | QtDialog::BoxQtQuery::~BoxQtQuery()
|
---|
226 | {
|
---|
227 | delete pipe;
|
---|
228 | }
|
---|
229 |
|
---|
230 | bool QtDialog::BoxQtQuery::handle() {
|
---|
231 | return true;
|
---|
232 | }
|
---|
233 |
|
---|
234 |
|
---|
235 | QtDialog::AtomQtQuery::AtomQtQuery(string _title,QBoxLayout *_parent,QtDialog *_dialog) :
|
---|
236 | Dialog::AtomQuery(_title),
|
---|
237 | parent(_parent)
|
---|
238 | {
|
---|
239 | thisLayout = new QHBoxLayout();
|
---|
240 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
241 | inputBox = new QComboBox();
|
---|
242 | inputBox->insertItem(-1, QString("no atom"));
|
---|
243 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
---|
244 | for (std::vector<atom *>::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter)
|
---|
245 | inputBox->insertItem((*iter)->getNr(),QString::fromStdString((*iter)->getName()));
|
---|
246 |
|
---|
247 | parent->addLayout(thisLayout);
|
---|
248 | thisLayout->addWidget(titleLabel);
|
---|
249 | thisLayout->addWidget(inputBox);
|
---|
250 |
|
---|
251 | pipe = new AtomQtQueryPipe(&tmp,_dialog, inputBox);
|
---|
252 | pipe->update(inputBox->currentIndex());
|
---|
253 | connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
|
---|
254 | }
|
---|
255 |
|
---|
256 | QtDialog::AtomQtQuery::~AtomQtQuery()
|
---|
257 | {
|
---|
258 | delete pipe;
|
---|
259 | }
|
---|
260 |
|
---|
261 | bool QtDialog::AtomQtQuery::handle() {
|
---|
262 | return true;
|
---|
263 | }
|
---|
264 |
|
---|
265 |
|
---|
266 | QtDialog::AtomsQtQuery::AtomsQtQuery(string _title,QBoxLayout *_parent,QtDialog *_dialog) :
|
---|
267 | Dialog::AtomsQuery(_title),
|
---|
268 | parent(_parent)
|
---|
269 | {
|
---|
270 | QHBoxLayout * thisHLayout = new QHBoxLayout();
|
---|
271 | QVBoxLayout * thisV1Layout = new QVBoxLayout();
|
---|
272 | QVBoxLayout * thisV2Layout = new QVBoxLayout();
|
---|
273 |
|
---|
274 | QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
275 | QLabel *inputLabel = new QLabel("Enter to add");
|
---|
276 | QListWidget* inputList = new QListWidget();
|
---|
277 | inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
278 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
---|
279 | for (std::vector<atom *>::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter)
|
---|
280 | inputBox->insertItem((*iter)->getNr(),QString((*iter)->getNr()));
|
---|
281 |
|
---|
282 | QLineEdit* inputBox = new QLineEdit();
|
---|
283 | inputLabel->setBuddy(inputBox);
|
---|
284 | titleLabel->setBuddy(inputList);
|
---|
285 | QPushButton* AddButton = new QPushButton("Add");
|
---|
286 | AddButton->setEnabled(false);
|
---|
287 | QPushButton* RemoveButton = new QPushButton("Remove");
|
---|
288 | RemoveButton->setEnabled(false);
|
---|
289 |
|
---|
290 | thisV1Layout->addWidget(titleLabel);
|
---|
291 | thisV1Layout->addWidget(inputList);
|
---|
292 | thisV2Layout->addWidget(inputLabel);
|
---|
293 | thisV2Layout->addWidget(inputBox);
|
---|
294 | thisV2Layout->addWidget(AddButton);
|
---|
295 | thisV2Layout->addWidget(RemoveButton);
|
---|
296 | parent->addLayout(thisHLayout);
|
---|
297 | thisHLayout->addLayout(thisV1Layout);
|
---|
298 | thisHLayout->addLayout(thisV2Layout);
|
---|
299 |
|
---|
300 | pipe = new AtomsQtQueryPipe(&tmp,_dialog,inputList);
|
---|
301 | connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
|
---|
302 | connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(add()));
|
---|
303 | connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(remove()));
|
---|
304 | }
|
---|
305 |
|
---|
306 | QtDialog::AtomsQtQuery::~AtomsQtQuery()
|
---|
307 | {
|
---|
308 | delete pipe;
|
---|
309 | }
|
---|
310 |
|
---|
311 | bool QtDialog::AtomsQtQuery::handle() {
|
---|
312 | return true;
|
---|
313 | }
|
---|
314 |
|
---|
315 | QtDialog::IntQtQuery::IntQtQuery(string _title,QBoxLayout *_parent,QtDialog *_dialog) :
|
---|
316 | Dialog::IntQuery(_title),
|
---|
317 | parent(_parent)
|
---|
318 | {
|
---|
319 | thisLayout = new QHBoxLayout();
|
---|
320 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
321 | inputBox = new QSpinBox();
|
---|
322 | inputBox->setValue(0);
|
---|
323 | parent->addLayout(thisLayout);
|
---|
324 | thisLayout->addWidget(titleLabel);
|
---|
325 | thisLayout->addWidget(inputBox);
|
---|
326 |
|
---|
327 | pipe = new IntQtQueryPipe(&tmp,_dialog);
|
---|
328 | pipe->update(inputBox->value());
|
---|
329 | connect(inputBox,SIGNAL(valueChanged(int)),pipe,SLOT(update(int)));
|
---|
330 | }
|
---|
331 |
|
---|
332 | QtDialog::IntQtQuery::~IntQtQuery()
|
---|
333 | {
|
---|
334 | delete pipe;
|
---|
335 | }
|
---|
336 |
|
---|
337 | bool QtDialog::IntQtQuery::handle() {
|
---|
338 | return true;
|
---|
339 | }
|
---|
340 |
|
---|
341 |
|
---|
342 | QtDialog::IntsQtQuery::IntsQtQuery(string _title,QBoxLayout *_parent,QtDialog *_dialog) :
|
---|
343 | Dialog::IntsQuery(_title),
|
---|
344 | parent(_parent)
|
---|
345 | {
|
---|
346 | QHBoxLayout * thisHLayout = new QHBoxLayout();
|
---|
347 | QVBoxLayout * thisV1Layout = new QVBoxLayout();
|
---|
348 | QVBoxLayout * thisV2Layout = new QVBoxLayout();
|
---|
349 |
|
---|
350 | QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
351 | QLabel *inputLabel = new QLabel("Enter to add");
|
---|
352 | QListWidget* inputList = new QListWidget();
|
---|
353 | inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
354 | QLineEdit* inputBox = new QLineEdit();
|
---|
355 | inputLabel->setBuddy(inputBox);
|
---|
356 | titleLabel->setBuddy(inputList);
|
---|
357 | QPushButton* AddButton = new QPushButton("Add");
|
---|
358 | AddButton->setEnabled(false);
|
---|
359 | QPushButton* RemoveButton = new QPushButton("Remove");
|
---|
360 | RemoveButton->setEnabled(false);
|
---|
361 |
|
---|
362 | thisV1Layout->addWidget(titleLabel);
|
---|
363 | thisV1Layout->addWidget(inputList);
|
---|
364 | thisV2Layout->addWidget(inputLabel);
|
---|
365 | thisV2Layout->addWidget(inputBox);
|
---|
366 | thisV2Layout->addWidget(AddButton);
|
---|
367 | thisV2Layout->addWidget(RemoveButton);
|
---|
368 | parent->addLayout(thisHLayout);
|
---|
369 | thisHLayout->addLayout(thisV1Layout);
|
---|
370 | thisHLayout->addLayout(thisV2Layout);
|
---|
371 |
|
---|
372 | pipe = new QtQueryListPipe<int>(&tmp,_dialog,inputBox,inputList,AddButton,RemoveButton);
|
---|
373 | connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(IntegerEntered(const QString&)));
|
---|
374 | connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
|
---|
375 | connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(AddValue()));
|
---|
376 | connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(RemoveRow()));
|
---|
377 | }
|
---|
378 |
|
---|
379 | QtDialog::IntsQtQuery::~IntsQtQuery()
|
---|
380 | {
|
---|
381 | delete pipe;
|
---|
382 | }
|
---|
383 |
|
---|
384 | bool QtDialog::IntsQtQuery::handle() {
|
---|
385 | return true;
|
---|
386 | }
|
---|
387 |
|
---|
388 |
|
---|
389 | QtDialog::DoubleQtQuery::DoubleQtQuery(string title,QBoxLayout *_parent,QtDialog *_dialog) :
|
---|
390 | Dialog::DoubleQuery(title),
|
---|
391 | parent(_parent)
|
---|
392 | {
|
---|
393 | thisLayout = new QHBoxLayout();
|
---|
394 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
395 | inputBox = new QDoubleSpinBox();
|
---|
396 | inputBox->setValue(0);
|
---|
397 | inputBox->setRange(-numeric_limits<double>::max(),numeric_limits<double>::max());
|
---|
398 | inputBox->setDecimals(3);
|
---|
399 | parent->addLayout(thisLayout);
|
---|
400 | thisLayout->addWidget(titleLabel);
|
---|
401 | thisLayout->addWidget(inputBox);
|
---|
402 |
|
---|
403 | pipe = new DoubleQtQueryPipe(&tmp,_dialog);
|
---|
404 | pipe->update(inputBox->value());
|
---|
405 | connect(inputBox,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
|
---|
406 | }
|
---|
407 |
|
---|
408 | QtDialog::DoubleQtQuery::~DoubleQtQuery()
|
---|
409 | {
|
---|
410 | delete pipe;
|
---|
411 | }
|
---|
412 |
|
---|
413 | bool QtDialog::DoubleQtQuery::handle() {
|
---|
414 | return true;
|
---|
415 | }
|
---|
416 |
|
---|
417 |
|
---|
418 | QtDialog::DoublesQtQuery::DoublesQtQuery(string title,QBoxLayout *_parent,QtDialog *_dialog) :
|
---|
419 | Dialog::DoublesQuery(title),
|
---|
420 | parent(_parent)
|
---|
421 | {
|
---|
422 | QHBoxLayout * thisHLayout = new QHBoxLayout();
|
---|
423 | QVBoxLayout * thisV1Layout = new QVBoxLayout();
|
---|
424 | QVBoxLayout * thisV2Layout = new QVBoxLayout();
|
---|
425 |
|
---|
426 | QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
427 | QLabel *inputLabel = new QLabel("Enter to add");
|
---|
428 | QListWidget* inputList = new QListWidget();
|
---|
429 | inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
430 | QLineEdit* inputBox = new QLineEdit();
|
---|
431 | inputLabel->setBuddy(inputBox);
|
---|
432 | titleLabel->setBuddy(inputList);
|
---|
433 | QPushButton* AddButton = new QPushButton("Add");
|
---|
434 | AddButton->setEnabled(false);
|
---|
435 | QPushButton* RemoveButton = new QPushButton("Remove");
|
---|
436 | RemoveButton->setEnabled(false);
|
---|
437 |
|
---|
438 | thisV1Layout->addWidget(titleLabel);
|
---|
439 | thisV1Layout->addWidget(inputList);
|
---|
440 | thisV2Layout->addWidget(inputLabel);
|
---|
441 | thisV2Layout->addWidget(inputBox);
|
---|
442 | thisV2Layout->addWidget(AddButton);
|
---|
443 | thisV2Layout->addWidget(RemoveButton);
|
---|
444 | parent->addLayout(thisHLayout);
|
---|
445 | thisHLayout->addLayout(thisV1Layout);
|
---|
446 | thisHLayout->addLayout(thisV2Layout);
|
---|
447 |
|
---|
448 | pipe = new QtQueryListPipe<double>(&tmp,_dialog,inputBox,inputList,AddButton,RemoveButton);
|
---|
449 | connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(IntegerEntered(const QString&)));
|
---|
450 | connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
|
---|
451 | connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(AddValue()));
|
---|
452 | connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(RemoveRow()));}
|
---|
453 |
|
---|
454 | QtDialog::DoublesQtQuery::~DoublesQtQuery()
|
---|
455 | {
|
---|
456 | delete pipe;
|
---|
457 | }
|
---|
458 |
|
---|
459 | bool QtDialog::DoublesQtQuery::handle() {
|
---|
460 | return true;
|
---|
461 | }
|
---|
462 |
|
---|
463 |
|
---|
464 | QtDialog::StringQtQuery::StringQtQuery(string _title,QBoxLayout *_parent,QtDialog *_dialog) :
|
---|
465 | Dialog::StringQuery(_title),
|
---|
466 | parent(_parent)
|
---|
467 | {
|
---|
468 | thisLayout = new QHBoxLayout();
|
---|
469 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
470 | inputBox = new QLineEdit();
|
---|
471 | parent->addLayout(thisLayout);
|
---|
472 | thisLayout->addWidget(titleLabel);
|
---|
473 | thisLayout->addWidget(inputBox);
|
---|
474 |
|
---|
475 | pipe = new StringQtQueryPipe(&tmp,_dialog);
|
---|
476 | pipe->update(inputBox->text());
|
---|
477 | connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(update(const QString&)));
|
---|
478 | }
|
---|
479 |
|
---|
480 | QtDialog::StringQtQuery::~StringQtQuery()
|
---|
481 | {
|
---|
482 | delete pipe;
|
---|
483 | }
|
---|
484 |
|
---|
485 | // All values besides the empty std::string are valid
|
---|
486 | bool QtDialog::StringQtQuery::handle()
|
---|
487 | {
|
---|
488 | return tmp!="";
|
---|
489 | }
|
---|
490 |
|
---|
491 | QtDialog::StringsQtQuery::StringsQtQuery(string _title,QBoxLayout *_parent,QtDialog *_dialog) :
|
---|
492 | Dialog::StringsQuery(_title),
|
---|
493 | parent(_parent)
|
---|
494 | {
|
---|
495 | QHBoxLayout * thisHLayout = new QHBoxLayout();
|
---|
496 | QVBoxLayout * thisV1Layout = new QVBoxLayout();
|
---|
497 | QVBoxLayout * thisV2Layout = new QVBoxLayout();
|
---|
498 |
|
---|
499 | QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
500 | QLabel *inputLabel = new QLabel("Enter to add");
|
---|
501 | QListWidget* inputList = new QListWidget();
|
---|
502 | inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
503 | QLineEdit* inputBox = new QLineEdit();
|
---|
504 | inputLabel->setBuddy(inputBox);
|
---|
505 | titleLabel->setBuddy(inputList);
|
---|
506 | QPushButton* AddButton = new QPushButton("Add");
|
---|
507 | AddButton->setEnabled(false);
|
---|
508 | QPushButton* RemoveButton = new QPushButton("Remove");
|
---|
509 | RemoveButton->setEnabled(false);
|
---|
510 |
|
---|
511 | thisV1Layout->addWidget(titleLabel);
|
---|
512 | thisV1Layout->addWidget(inputList);
|
---|
513 | thisV2Layout->addWidget(inputLabel);
|
---|
514 | thisV2Layout->addWidget(inputBox);
|
---|
515 | thisV2Layout->addWidget(AddButton);
|
---|
516 | thisV2Layout->addWidget(RemoveButton);
|
---|
517 | parent->addLayout(thisHLayout);
|
---|
518 | thisHLayout->addLayout(thisV1Layout);
|
---|
519 | thisHLayout->addLayout(thisV2Layout);
|
---|
520 |
|
---|
521 | pipe = new QtQueryListPipe<std::string>(&tmp,_dialog,inputBox,inputList,AddButton,RemoveButton);
|
---|
522 | connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(IntegerEntered(const QString&)));
|
---|
523 | connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
|
---|
524 | connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(AddValue()));
|
---|
525 | connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(RemoveRow()));}
|
---|
526 |
|
---|
527 | QtDialog::StringsQtQuery::~StringsQtQuery()
|
---|
528 | {
|
---|
529 | delete pipe;
|
---|
530 | }
|
---|
531 |
|
---|
532 | // All values besides the empty std::string are valid
|
---|
533 | bool QtDialog::StringsQtQuery::handle()
|
---|
534 | {
|
---|
535 | // dissect by ","
|
---|
536 | std::string::iterator olditer = temp.begin();
|
---|
537 | for(string::iterator iter = temp.begin(); iter != temp.end(); ++iter) {
|
---|
538 | if (*iter == ' ') {
|
---|
539 | tmp.push_back(string(iter, olditer));
|
---|
540 | olditer = iter;
|
---|
541 | }
|
---|
542 | }
|
---|
543 | if (olditer != temp.begin()) // insert last part also
|
---|
544 | tmp.push_back(string(olditer, temp.end()));
|
---|
545 |
|
---|
546 | return temp!="";
|
---|
547 | }
|
---|
548 |
|
---|
549 | QtDialog::MoleculeQtQuery::MoleculeQtQuery(string _title, QBoxLayout *_parent,QtDialog *_dialog) :
|
---|
550 | Dialog::MoleculeQuery(_title),
|
---|
551 | parent(_parent)
|
---|
552 | {
|
---|
553 | thisLayout = new QHBoxLayout();
|
---|
554 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
555 | inputBox = new QComboBox();
|
---|
556 | // add all molecules to the combo box
|
---|
557 | vector<molecule*> molecules = World::getInstance().getAllMolecules();
|
---|
558 | for(vector<molecule*>::iterator iter = molecules.begin();
|
---|
559 | iter != molecules.end();
|
---|
560 | ++iter) {
|
---|
561 | std::stringstream sstr;
|
---|
562 | sstr << (*iter)->IndexNr << "\t" << (*iter)->getName();
|
---|
563 | inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter)->IndexNr));
|
---|
564 | }
|
---|
565 | parent->addLayout(thisLayout);
|
---|
566 | thisLayout->addWidget(titleLabel);
|
---|
567 | thisLayout->addWidget(inputBox);
|
---|
568 |
|
---|
569 | pipe = new MoleculeQtQueryPipe(&tmp,_dialog,inputBox);
|
---|
570 | pipe->update(inputBox->currentIndex());
|
---|
571 | connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
|
---|
572 | }
|
---|
573 |
|
---|
574 | QtDialog::MoleculeQtQuery::~MoleculeQtQuery()
|
---|
575 | {
|
---|
576 | delete pipe;
|
---|
577 | }
|
---|
578 |
|
---|
579 | // Handling is easy, since the GUI makes it impossible to select invalid values
|
---|
580 | bool QtDialog::MoleculeQtQuery::handle()
|
---|
581 | {
|
---|
582 | return true;
|
---|
583 | }
|
---|
584 |
|
---|
585 | QtDialog::MoleculesQtQuery::MoleculesQtQuery(string _title, QBoxLayout *_parent,QtDialog *_dialog) :
|
---|
586 | Dialog::MoleculesQuery(_title),
|
---|
587 | parent(_parent)
|
---|
588 | {
|
---|
589 | thisLayout = new QHBoxLayout();
|
---|
590 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
591 | inputBox = new QComboBox();
|
---|
592 | // add all molecules to the combo box
|
---|
593 | vector<molecule*> molecules = World::getInstance().getAllMolecules();
|
---|
594 | for(vector<molecule*>::iterator iter = molecules.begin();
|
---|
595 | iter != molecules.end();
|
---|
596 | ++iter) {
|
---|
597 | std::stringstream sstr;
|
---|
598 | sstr << (*iter)->IndexNr << "\t" << (*iter)->getName();
|
---|
599 | inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter)->IndexNr));
|
---|
600 | }
|
---|
601 | parent->addLayout(thisLayout);
|
---|
602 | thisLayout->addWidget(titleLabel);
|
---|
603 | thisLayout->addWidget(inputBox);
|
---|
604 |
|
---|
605 | pipe = new MoleculesQtQueryPipe(&tmp,_dialog,inputBox);
|
---|
606 | pipe->update(inputBox->currentIndex());
|
---|
607 | connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
|
---|
608 | }
|
---|
609 |
|
---|
610 | QtDialog::MoleculesQtQuery::~MoleculesQtQuery()
|
---|
611 | {
|
---|
612 | delete pipe;
|
---|
613 | }
|
---|
614 |
|
---|
615 | // Handling is easy, since the GUI makes it impossible to select invalid values
|
---|
616 | bool QtDialog::MoleculesQtQuery::handle()
|
---|
617 | {
|
---|
618 | return true;
|
---|
619 | }
|
---|
620 |
|
---|
621 | QtDialog::VectorQtQuery::VectorQtQuery(std::string title, bool _check,QBoxLayout *_parent,QtDialog *_dialog) :
|
---|
622 | Dialog::VectorQuery(title,_check),
|
---|
623 | parent(_parent)
|
---|
624 | {
|
---|
625 | mainLayout= new QHBoxLayout();
|
---|
626 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
627 | mainLayout->addWidget(titleLabel);
|
---|
628 | subLayout = new QVBoxLayout();
|
---|
629 | mainLayout->addLayout(subLayout);
|
---|
630 | QComboBox* inputBox = new QComboBox();
|
---|
631 | coordLayout = new QHBoxLayout();
|
---|
632 | subLayout->addLayout(coordLayout);
|
---|
633 | coordLabel = new QLabel(QString("x,y,z"));
|
---|
634 | coordLayout->addWidget(coordLabel);
|
---|
635 | coordInput = new QDoubleSpinBox();
|
---|
636 | // coordInput->setRange(0,M.at(i,i));
|
---|
637 | coordInput->setDecimals(3);
|
---|
638 | coordLayout->addWidget(coordInput);
|
---|
639 | pipe = new VectorQtQueryPipe(&(tmp),_dialog,inputBox);
|
---|
640 | //pipe->update(coordInput->value());
|
---|
641 | connect(coordInput,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
|
---|
642 | parent->addLayout(mainLayout);
|
---|
643 | }
|
---|
644 |
|
---|
645 | QtDialog::VectorQtQuery::~VectorQtQuery()
|
---|
646 | {}
|
---|
647 |
|
---|
648 | bool QtDialog::VectorQtQuery::handle() {
|
---|
649 | return true;
|
---|
650 | }
|
---|
651 |
|
---|
652 |
|
---|
653 | QtDialog::VectorsQtQuery::VectorsQtQuery(std::string title, bool _check,QBoxLayout *_parent,QtDialog *_dialog) :
|
---|
654 | Dialog::VectorsQuery(title,_check),
|
---|
655 | parent(_parent)
|
---|
656 | {
|
---|
657 | mainLayout= new QHBoxLayout();
|
---|
658 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
659 | mainLayout->addWidget(titleLabel);
|
---|
660 | subLayout = new QVBoxLayout();
|
---|
661 | mainLayout->addLayout(subLayout);
|
---|
662 | QComboBox* inputBox = new QComboBox();
|
---|
663 | coordLayout = new QHBoxLayout();
|
---|
664 | subLayout->addLayout(coordLayout);
|
---|
665 | coordLabel = new QLabel(QString("x,y,z"));
|
---|
666 | coordLayout->addWidget(coordLabel);
|
---|
667 | coordInput = new QDoubleSpinBox();
|
---|
668 | // coordInput->setRange(0,M.at(i,i));
|
---|
669 | coordInput->setDecimals(3);
|
---|
670 | coordLayout->addWidget(coordInput);
|
---|
671 | pipe = new VectorsQtQueryPipe(&(tmp),_dialog,inputBox);
|
---|
672 | //pipe->update(coordInput->value());
|
---|
673 | connect(coordInput,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
|
---|
674 | parent->addLayout(mainLayout);
|
---|
675 | }
|
---|
676 |
|
---|
677 | QtDialog::VectorsQtQuery::~VectorsQtQuery()
|
---|
678 | {}
|
---|
679 |
|
---|
680 | bool QtDialog::VectorsQtQuery::handle() {
|
---|
681 | return true;
|
---|
682 | }
|
---|
683 |
|
---|
684 |
|
---|
685 | QtDialog::ElementQtQuery::ElementQtQuery(std::string _title, QBoxLayout *_parent, QtDialog *_dialog) :
|
---|
686 | Dialog::ElementQuery(_title),
|
---|
687 | parent(_parent)
|
---|
688 | {
|
---|
689 | periodentafel *periode = World::getInstance().getPeriode();
|
---|
690 | thisLayout = new QHBoxLayout();
|
---|
691 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
692 | inputBox = new QComboBox();
|
---|
693 | for(periodentafel::const_iterator iter = periode->begin();
|
---|
694 | iter!=periode->end();
|
---|
695 | ++iter)
|
---|
696 | {
|
---|
697 | std::stringstream sstr;
|
---|
698 | sstr << (*iter).first << "\t" << (*iter).second->getName();
|
---|
699 | inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter).first));
|
---|
700 | }
|
---|
701 | parent->addLayout(thisLayout);
|
---|
702 | thisLayout->addWidget(titleLabel);
|
---|
703 | thisLayout->addWidget(inputBox);
|
---|
704 |
|
---|
705 | pipe = new ElementQtQueryPipe(&tmp,_dialog,inputBox);
|
---|
706 | pipe->update(inputBox->currentIndex());
|
---|
707 | connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
|
---|
708 | }
|
---|
709 |
|
---|
710 | QtDialog::ElementQtQuery::~ElementQtQuery()
|
---|
711 | {
|
---|
712 | delete pipe;
|
---|
713 | }
|
---|
714 |
|
---|
715 | bool QtDialog::ElementQtQuery::handle(){
|
---|
716 | return true;
|
---|
717 | }
|
---|
718 |
|
---|
719 |
|
---|
720 | QtDialog::ElementsQtQuery::ElementsQtQuery(std::string _title, QBoxLayout *_parent, QtDialog *_dialog) :
|
---|
721 | Dialog::ElementsQuery(_title),
|
---|
722 | parent(_parent)
|
---|
723 | {
|
---|
724 | periodentafel *periode = World::getInstance().getPeriode();
|
---|
725 | thisLayout = new QHBoxLayout();
|
---|
726 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
727 | inputBox = new QComboBox();
|
---|
728 | for(periodentafel::const_iterator iter = periode->begin();
|
---|
729 | iter!=periode->end();
|
---|
730 | ++iter)
|
---|
731 | {
|
---|
732 | std::stringstream sstr;
|
---|
733 | sstr << (*iter).first << "\t" << (*iter).second->getName();
|
---|
734 | inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter).first));
|
---|
735 | }
|
---|
736 | parent->addLayout(thisLayout);
|
---|
737 | thisLayout->addWidget(titleLabel);
|
---|
738 | thisLayout->addWidget(inputBox);
|
---|
739 |
|
---|
740 | pipe = new ElementsQtQueryPipe(&tmp,_dialog,inputBox);
|
---|
741 | pipe->update(inputBox->currentIndex());
|
---|
742 | connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
|
---|
743 | }
|
---|
744 |
|
---|
745 | QtDialog::ElementsQtQuery::~ElementsQtQuery()
|
---|
746 | {
|
---|
747 | delete pipe;
|
---|
748 | }
|
---|
749 |
|
---|
750 | bool QtDialog::ElementsQtQuery::handle(){
|
---|
751 | return true;
|
---|
752 | }
|
---|
753 |
|
---|
754 | QtDialog::EmptyQtQuery::EmptyQtQuery(std::string _title, QBoxLayout *_parent, QtDialog *_dialog) :
|
---|
755 | Dialog::EmptyQuery(_title),
|
---|
756 | parent(_parent)
|
---|
757 | {
|
---|
758 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
759 |
|
---|
760 | parent->addLayout(thisLayout);
|
---|
761 | thisLayout->addWidget(titleLabel);
|
---|
762 |
|
---|
763 | pipe = new EmptyQtQueryPipe(_dialog,titleLabel);
|
---|
764 | }
|
---|
765 |
|
---|
766 | QtDialog::EmptyQtQuery::~EmptyQtQuery()
|
---|
767 | {
|
---|
768 | delete pipe;
|
---|
769 | }
|
---|
770 |
|
---|
771 | bool QtDialog::EmptyQtQuery::handle(){
|
---|
772 | return true;
|
---|
773 | }
|
---|
774 |
|
---|
775 |
|
---|
776 | QtDialog::BooleanQtQuery::BooleanQtQuery(std::string _title, QBoxLayout *_parent, QtDialog *_dialog) :
|
---|
777 | Dialog::BooleanQuery(_title),
|
---|
778 | parent(_parent)
|
---|
779 | {
|
---|
780 | titleLabel = new QLabel(QString(getTitle().c_str()),_dialog);
|
---|
781 | booleanComboBox = new QComboBox(_dialog);
|
---|
782 | booleanComboBox->insertItem(1, QString("true"));
|
---|
783 | booleanComboBox->insertItem(0, QString("false"));
|
---|
784 |
|
---|
785 | parent->addLayout(thisLayout);
|
---|
786 | thisLayout->addWidget(titleLabel);
|
---|
787 | thisLayout->addWidget(booleanComboBox);
|
---|
788 |
|
---|
789 | pipe = new BooleanQtQueryPipe(&tmp,_dialog,booleanComboBox);
|
---|
790 | connect(booleanComboBox, SIGNAL(currentIndexChanged()), pipe, SLOT(update()));
|
---|
791 | }
|
---|
792 |
|
---|
793 | QtDialog::BooleanQtQuery::~BooleanQtQuery()
|
---|
794 | {
|
---|
795 | delete pipe;
|
---|
796 | }
|
---|
797 |
|
---|
798 | bool QtDialog::BooleanQtQuery::handle(){
|
---|
799 | return true;
|
---|
800 | }
|
---|
801 |
|
---|
802 |
|
---|
803 | QtDialog::FileQtQuery::FileQtQuery(std::string _title, QBoxLayout *_parent, QtDialog *_dialog) :
|
---|
804 | Dialog::FileQuery(_title),
|
---|
805 | parent(_parent)
|
---|
806 | {
|
---|
807 |
|
---|
808 | filenameLineEdit = new QLineEdit(_dialog);
|
---|
809 | filenameLineEdit->setText(QString());
|
---|
810 | filenameLineEdit->setReadOnly(true);
|
---|
811 |
|
---|
812 | filenameLabel = new QLabel(QString("Input file:"));
|
---|
813 | filenameLabel->setBuddy(filenameLineEdit);
|
---|
814 |
|
---|
815 | filedialogButton = new QPushButton("&Choose", _dialog);
|
---|
816 |
|
---|
817 | pipe = new FileQtQueryPipe(&tmp,_dialog,filenameLineEdit,filedialogButton);
|
---|
818 |
|
---|
819 | thisLayout = new QHBoxLayout();
|
---|
820 | parent->addLayout(thisLayout);
|
---|
821 | thisLayout->addWidget(filenameLabel);
|
---|
822 | thisLayout->addWidget(filenameLineEdit);
|
---|
823 | thisLayout->addWidget(filedialogButton);
|
---|
824 |
|
---|
825 | QObject::connect(filedialogButton,SIGNAL(clicked()),pipe,SLOT(showFileDialog()));
|
---|
826 | }
|
---|
827 |
|
---|
828 | QtDialog::FileQtQuery::~FileQtQuery()
|
---|
829 | {
|
---|
830 | delete pipe;
|
---|
831 | }
|
---|
832 |
|
---|
833 | bool QtDialog::FileQtQuery::handle(){
|
---|
834 | return true;
|
---|
835 | }
|
---|
836 |
|
---|
837 | /*************************** Plumbing *******************************/
|
---|
838 |
|
---|
839 |
|
---|
840 | template<typename T> QtQueryListPipe<T>::QtQueryListPipe(std::vector<T> *_content, QtDialog *_dialog, QLineEdit *_inputBox, QListWidget *_inputList, QPushButton *_AddButton, QPushButton *_RemoveButton) :
|
---|
841 | content(_content),
|
---|
842 | dialog(_dialog),
|
---|
843 | inputBox(_inputBox),
|
---|
844 | inputList(_inputList),
|
---|
845 | AddButton(_AddButton),
|
---|
846 | RemoveButton(_RemoveButton)
|
---|
847 | {}
|
---|
848 |
|
---|
849 | template<typename T> QtQueryListPipe<T>::~QtQueryListPipe()
|
---|
850 | {}
|
---|
851 |
|
---|
852 | template<typename T> void QtQueryListPipe<T>::IntegerEntered(const QString&)
|
---|
853 | {
|
---|
854 | AddButton->setEnabled(true);
|
---|
855 | }
|
---|
856 |
|
---|
857 | template<typename T> void QtQueryListPipe<T>::IntegerSelected()
|
---|
858 | {
|
---|
859 | if (inputList->selectedItems().empty())
|
---|
860 | RemoveButton->setEnabled(false);
|
---|
861 | else
|
---|
862 | RemoveButton->setEnabled(true);
|
---|
863 | }
|
---|
864 |
|
---|
865 | template<typename T> void QtQueryListPipe<T>::AddInteger() {
|
---|
866 | // type-check
|
---|
867 | std::string text = inputBox->text().toStdString();
|
---|
868 | int number = 0;
|
---|
869 | try {
|
---|
870 | number = boost::lexical_cast<int>(text);
|
---|
871 | } catch (boost::bad_lexical_cast&) {
|
---|
872 | return;
|
---|
873 | };
|
---|
874 | // add item to both
|
---|
875 | inputList->addItem(QString(number));
|
---|
876 | AddValue(number);
|
---|
877 | }
|
---|
878 |
|
---|
879 | template<typename T> void QtQueryListPipe<T>::AddValue(T item) {
|
---|
880 | content->push_back(item);
|
---|
881 |
|
---|
882 | dialog->update();
|
---|
883 | }
|
---|
884 |
|
---|
885 | template<typename T> void QtQueryListPipe<T>::RemoveInteger() {
|
---|
886 | QList<QListWidgetItem *> items = inputList->selectedItems();
|
---|
887 | for (QList<QListWidgetItem *>::iterator iter = items.begin(); !items.empty(); iter = items.begin()) {
|
---|
888 | // obtain which position item has (by making it current item)
|
---|
889 | inputList->setCurrentItem(*iter);
|
---|
890 | // remove
|
---|
891 | QtQueryListPipe<T>::RemoteRow(inputList->currentRow()); // template parameters needs to be known, such that compiler knows which to call
|
---|
892 | inputList->removeItemWidget(*iter);
|
---|
893 | }
|
---|
894 | }
|
---|
895 |
|
---|
896 | template<typename T> void QtQueryListPipe<T>::RemoveRow(int row) {
|
---|
897 | int counter = 0;
|
---|
898 | typename std::vector<T>::iterator iter = content->begin();
|
---|
899 | for (; iter != content->end(); ++iter)
|
---|
900 | if (counter++ == row)
|
---|
901 | break;
|
---|
902 | if (iter != content->end())
|
---|
903 | content->erase(iter);
|
---|
904 | }
|
---|
905 |
|
---|
906 |
|
---|
907 | StringQtQueryPipe::StringQtQueryPipe(string *_content, QtDialog *_dialog) :
|
---|
908 | content(_content),
|
---|
909 | dialog(_dialog)
|
---|
910 | {}
|
---|
911 |
|
---|
912 | StringQtQueryPipe::~StringQtQueryPipe()
|
---|
913 | {}
|
---|
914 |
|
---|
915 | void StringQtQueryPipe::update(const QString& newText) {
|
---|
916 | content->assign(newText.toStdString());
|
---|
917 | dialog->update();
|
---|
918 | }
|
---|
919 |
|
---|
920 | IntQtQueryPipe::IntQtQueryPipe(int *_content, QtDialog *_dialog) :
|
---|
921 | content(_content),
|
---|
922 | dialog(_dialog)
|
---|
923 | {}
|
---|
924 |
|
---|
925 | IntQtQueryPipe::~IntQtQueryPipe()
|
---|
926 | {}
|
---|
927 |
|
---|
928 | void IntQtQueryPipe::update(int newInt) {
|
---|
929 | (*content) = newInt;
|
---|
930 | dialog->update();
|
---|
931 | }
|
---|
932 |
|
---|
933 | DoubleQtQueryPipe::DoubleQtQueryPipe(double *_content, QtDialog *_dialog) :
|
---|
934 | content(_content),
|
---|
935 | dialog(_dialog)
|
---|
936 | {}
|
---|
937 |
|
---|
938 | DoubleQtQueryPipe::~DoubleQtQueryPipe()
|
---|
939 | {}
|
---|
940 |
|
---|
941 | void DoubleQtQueryPipe::update(double newDbl) {
|
---|
942 | (*content) = newDbl;
|
---|
943 | dialog->update();
|
---|
944 | }
|
---|
945 |
|
---|
946 | VectorQtQueryPipe::VectorQtQueryPipe(Vector *_content, QtDialog *_dialog, QComboBox *_theBox) :
|
---|
947 | content(_content),
|
---|
948 | dialog(_dialog),
|
---|
949 | theBox(_theBox)
|
---|
950 | {}
|
---|
951 |
|
---|
952 | VectorQtQueryPipe::~VectorQtQueryPipe()
|
---|
953 | {}
|
---|
954 |
|
---|
955 | void VectorQtQueryPipe::update() {
|
---|
956 | dialog->update();
|
---|
957 | }
|
---|
958 |
|
---|
959 | VectorsQtQueryPipe::VectorsQtQueryPipe(std::vector<Vector> *_content, QtDialog *_dialog, QComboBox *_theBox) :
|
---|
960 | content(_content),
|
---|
961 | dialog(_dialog),
|
---|
962 | theBox(_theBox)
|
---|
963 | {}
|
---|
964 |
|
---|
965 | VectorsQtQueryPipe::~VectorsQtQueryPipe()
|
---|
966 | {}
|
---|
967 |
|
---|
968 | void VectorsQtQueryPipe::update() {
|
---|
969 | dialog->update();
|
---|
970 | }
|
---|
971 |
|
---|
972 | BoxQtQueryPipe::BoxQtQueryPipe(Box &_content, QtDialog *_dialog, QTableWidget *_inputTable) :
|
---|
973 | content(_content),
|
---|
974 | dialog(_dialog),
|
---|
975 | inputTable(_inputTable)
|
---|
976 | {
|
---|
977 | tmpM = new Matrix();
|
---|
978 | tmpM->zero();
|
---|
979 | }
|
---|
980 |
|
---|
981 | BoxQtQueryPipe::~BoxQtQueryPipe()
|
---|
982 | {
|
---|
983 | delete tmpM;
|
---|
984 | }
|
---|
985 |
|
---|
986 | void BoxQtQueryPipe::update(int row, int column)
|
---|
987 | {
|
---|
988 | tmpM->at(row, column) = inputTable->item(row, column)->text().toDouble();
|
---|
989 | content.setM(*tmpM);
|
---|
990 | dialog->update();
|
---|
991 | }
|
---|
992 |
|
---|
993 |
|
---|
994 | AtomQtQueryPipe::AtomQtQueryPipe(atom **_content, QtDialog *_dialog, QComboBox *_theBox) :
|
---|
995 | content(_content),
|
---|
996 | dialog(_dialog),
|
---|
997 | theBox(_theBox)
|
---|
998 | {}
|
---|
999 |
|
---|
1000 | AtomQtQueryPipe::~AtomQtQueryPipe()
|
---|
1001 | {}
|
---|
1002 |
|
---|
1003 | void AtomQtQueryPipe::update(int newIndex) {
|
---|
1004 | QVariant data = theBox->itemData(newIndex);
|
---|
1005 | int idx = data.toInt();
|
---|
1006 | (*content) = World::getInstance().getAtom(AtomById(idx));
|
---|
1007 | dialog->update();
|
---|
1008 | }
|
---|
1009 |
|
---|
1010 |
|
---|
1011 | AtomsQtQueryPipe::AtomsQtQueryPipe(std::vector<atom *>*_content, QtDialog *_dialog, QListWidget *_theList) :
|
---|
1012 | content(_content),
|
---|
1013 | dialog(_dialog),
|
---|
1014 | theList(_theList)
|
---|
1015 | {}
|
---|
1016 |
|
---|
1017 | AtomsQtQueryPipe::~AtomsQtQueryPipe()
|
---|
1018 | {}
|
---|
1019 |
|
---|
1020 | void AtomsQtQueryPipe::update() {
|
---|
1021 | // clear target and put all atoms therein
|
---|
1022 | (*content).clear();
|
---|
1023 | for (std::set<atom *>::iterator iter = currentList.begin(); iter != currentList.end(); ++iter)
|
---|
1024 | (*content).push_back(*iter);
|
---|
1025 | dialog->update();
|
---|
1026 | }
|
---|
1027 |
|
---|
1028 | void AtomsQtQueryPipe::add() {
|
---|
1029 | QList<QListWidgetItem *> items = theList->selectedItems();
|
---|
1030 | for (QList<QListWidgetItem *>::iterator iter = items.begin();iter != items.end();++iter) {
|
---|
1031 | const int index = (*iter)->text().toInt();
|
---|
1032 | atom *Walker = World::getInstance().getAtom(AtomById(index));
|
---|
1033 | if (Walker) {
|
---|
1034 | (*content).push_back(Walker);
|
---|
1035 | currentList.insert(Walker);
|
---|
1036 | if (lookup.find(index) != lookup.end())
|
---|
1037 | lookup.insert(pair<int, atom*>(index, Walker));
|
---|
1038 | }
|
---|
1039 | }
|
---|
1040 | update();
|
---|
1041 | }
|
---|
1042 |
|
---|
1043 | void AtomsQtQueryPipe::remove() {
|
---|
1044 | QList<QListWidgetItem *> items = theList->selectedItems();
|
---|
1045 | for (QList<QListWidgetItem *>::iterator iter = items.begin();iter != items.end();++iter) {
|
---|
1046 | const int index = (*iter)->text().toInt();
|
---|
1047 | atom *Walker = World::getInstance().getAtom(AtomById(index));
|
---|
1048 | if (Walker) {
|
---|
1049 | currentList.erase(Walker);
|
---|
1050 | }
|
---|
1051 | }
|
---|
1052 | update();
|
---|
1053 | }
|
---|
1054 |
|
---|
1055 |
|
---|
1056 | MoleculeQtQueryPipe::MoleculeQtQueryPipe(molecule **_content, QtDialog *_dialog, QComboBox *_theBox) :
|
---|
1057 | content(_content),
|
---|
1058 | dialog(_dialog),
|
---|
1059 | theBox(_theBox)
|
---|
1060 | {}
|
---|
1061 |
|
---|
1062 | MoleculeQtQueryPipe::~MoleculeQtQueryPipe()
|
---|
1063 | {}
|
---|
1064 |
|
---|
1065 | void MoleculeQtQueryPipe::update(int newIndex) {
|
---|
1066 | QVariant data = theBox->itemData(newIndex);
|
---|
1067 | int idx = data.toInt();
|
---|
1068 | (*content) = World::getInstance().getMolecule(MoleculeById(idx));
|
---|
1069 | dialog->update();
|
---|
1070 | }
|
---|
1071 |
|
---|
1072 |
|
---|
1073 | MoleculesQtQueryPipe::MoleculesQtQueryPipe(std::vector<molecule *>*_content, QtDialog *_dialog, QComboBox *_theBox) :
|
---|
1074 | content(_content),
|
---|
1075 | dialog(_dialog),
|
---|
1076 | theBox(_theBox)
|
---|
1077 | {}
|
---|
1078 |
|
---|
1079 | MoleculesQtQueryPipe::~MoleculesQtQueryPipe()
|
---|
1080 | {}
|
---|
1081 |
|
---|
1082 | void MoleculesQtQueryPipe::update(int newIndex) {
|
---|
1083 | QVariant data = theBox->itemData(newIndex);
|
---|
1084 | int idx = data.toInt();
|
---|
1085 | molecule *mol = World::getInstance().getMolecule(MoleculeById(idx));
|
---|
1086 | if (mol)
|
---|
1087 | (*content).push_back(mol);
|
---|
1088 | dialog->update();
|
---|
1089 | }
|
---|
1090 |
|
---|
1091 | ElementQtQueryPipe::ElementQtQueryPipe(const element **_content, QtDialog *_dialog, QComboBox *_theBox) :
|
---|
1092 | content(_content),
|
---|
1093 | dialog(_dialog),
|
---|
1094 | theBox(_theBox)
|
---|
1095 | {}
|
---|
1096 |
|
---|
1097 | ElementQtQueryPipe::~ElementQtQueryPipe()
|
---|
1098 | {}
|
---|
1099 |
|
---|
1100 | void ElementQtQueryPipe::update(int newIndex) {
|
---|
1101 | QVariant data = theBox->itemData(newIndex);
|
---|
1102 | int idx = data.toInt();
|
---|
1103 | *content = World::getInstance().getPeriode()->FindElement(idx);
|
---|
1104 | dialog->update();
|
---|
1105 | }
|
---|
1106 |
|
---|
1107 | ElementsQtQueryPipe::ElementsQtQueryPipe(std::vector<const element *>*_content, QtDialog *_dialog, QComboBox *_theBox) :
|
---|
1108 | content(_content),
|
---|
1109 | dialog(_dialog),
|
---|
1110 | theBox(_theBox)
|
---|
1111 | {}
|
---|
1112 |
|
---|
1113 | ElementsQtQueryPipe::~ElementsQtQueryPipe()
|
---|
1114 | {}
|
---|
1115 |
|
---|
1116 | void ElementsQtQueryPipe::update(int newIndex) {
|
---|
1117 | QVariant data = theBox->itemData(newIndex);
|
---|
1118 | int idx = data.toInt();
|
---|
1119 | const element *elemental = World::getInstance().getPeriode()->FindElement(idx);
|
---|
1120 | if(elemental)
|
---|
1121 | (*content).push_back(elemental);
|
---|
1122 | dialog->update();
|
---|
1123 | }
|
---|
1124 |
|
---|
1125 | EmptyQtQueryPipe::EmptyQtQueryPipe(QtDialog *_dialog, QLabel *_textLabel) :
|
---|
1126 | dialog(_dialog),
|
---|
1127 | textLabel(_textLabel)
|
---|
1128 | {}
|
---|
1129 |
|
---|
1130 | EmptyQtQueryPipe::~EmptyQtQueryPipe()
|
---|
1131 | {}
|
---|
1132 |
|
---|
1133 | void EmptyQtQueryPipe::update() {
|
---|
1134 | dialog->update();
|
---|
1135 | }
|
---|
1136 |
|
---|
1137 | BooleanQtQueryPipe::BooleanQtQueryPipe(const bool *_content, QtDialog *_dialog, QComboBox *_booleanComboBox) :
|
---|
1138 | content(_content),
|
---|
1139 | dialog(_dialog),
|
---|
1140 | booleanComboBox(_booleanComboBox)
|
---|
1141 | {}
|
---|
1142 |
|
---|
1143 | BooleanQtQueryPipe::~BooleanQtQueryPipe()
|
---|
1144 | {}
|
---|
1145 |
|
---|
1146 | void BooleanQtQueryPipe::update() {
|
---|
1147 | dialog->update();
|
---|
1148 | }
|
---|
1149 |
|
---|
1150 | FileQtQueryPipe::FileQtQueryPipe(boost::filesystem::path *_content, QtDialog *_dialog, QLineEdit *_filenameLineEdit, QPushButton *_filedialogButton) :
|
---|
1151 | content(_content),
|
---|
1152 | dialog(_dialog),
|
---|
1153 | filenameLineEdit(_filenameLineEdit),
|
---|
1154 | filedialogButton(_filedialogButton)
|
---|
1155 | {
|
---|
1156 | theFileDialog = NULL;
|
---|
1157 | }
|
---|
1158 |
|
---|
1159 | FileQtQueryPipe::~FileQtQueryPipe()
|
---|
1160 | {
|
---|
1161 | if (theFileDialog != NULL)
|
---|
1162 | delete theFileDialog;
|
---|
1163 | }
|
---|
1164 |
|
---|
1165 | void FileQtQueryPipe::update() {
|
---|
1166 | QStringList ListOfFilenames = theFileDialog->selectedFiles();
|
---|
1167 | std::cout << "Selected File is " << ListOfFilenames.at(0).toStdString() << std::endl;
|
---|
1168 | (*content) = ListOfFilenames.at(0).toStdString();
|
---|
1169 | filenameLineEdit->setText(QString::fromStdString((*content).string()));
|
---|
1170 | dialog->update();
|
---|
1171 | }
|
---|
1172 |
|
---|
1173 | void FileQtQueryPipe::showFileDialog() {
|
---|
1174 | filedialogButton->setFlat(true);
|
---|
1175 | if (theFileDialog == NULL) {
|
---|
1176 | theFileDialog = new QFileDialog(NULL, tr("Open input file"), QString(), tr("ParallelCarParrinello (*.conf);;MassivelyParallelQuantumChemistry (*.mpqc);;ParticleDataBase (*.pdb);;XYZ (*.xyz)"));
|
---|
1177 | theFileDialog->setAcceptMode(QFileDialog::AcceptOpen);
|
---|
1178 | theFileDialog->setFileMode(QFileDialog::ExistingFile);
|
---|
1179 | theFileDialog->setViewMode(QFileDialog::List);
|
---|
1180 | }
|
---|
1181 | theFileDialog->exec();
|
---|
1182 |
|
---|
1183 | update();
|
---|
1184 | filedialogButton->setFlat(false);
|
---|
1185 | }
|
---|
1186 |
|
---|
1187 |
|
---|
1188 |
|
---|