source: src/UIElements/QT4/QTDialog.cpp@ c96c66

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since c96c66 was c96c66, checked in by Frederik Heber <heber@…>, 15 years ago

Added Atom(s)QTQuery.

  • Property mode set to 100644
File size: 31.5 KB
Line 
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
53using namespace std;
54
55QTDialog::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
76QTDialog::~QTDialog()
77{
78}
79
80bool 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
94void QTDialog::update(){
95 buttons->button(QDialogButtonBox::Ok)->setEnabled(checkAll());
96}
97
98/************************** Query Infrastructure ************************/
99
100void QTDialog::queryEmpty(const char* title, std::string)
101{
102 registerQuery(new EmptyQTQuery(title,inputLayout,this));
103}
104
105void QTDialog::queryBoolean(const char* title,string)
106{
107 registerQuery(new BooleanQTQuery(title,inputLayout,this));
108}
109
110void QTDialog::queryAtom(const char* title, std::string)
111{
112 registerQuery(new AtomQTQuery(title,inputLayout,this));
113}
114
115void QTDialog::queryAtoms(const char* title, std::string)
116{
117 registerQuery(new AtomsQTQuery(title,inputLayout,this));
118}
119
120void QTDialog::queryBox(const char* title, std::string){
121 // TODO
122 ASSERT(false, "Not implemented yet");
123}
124
125
126void QTDialog::queryInt(const char *title,string)
127{
128 registerQuery(new IntQTQuery(title,inputLayout,this));
129}
130
131void QTDialog::queryInts(const char *title,string)
132{
133 registerQuery(new IntsQTQuery(title,inputLayout,this));
134}
135
136void QTDialog::queryDouble(const char* title,string)
137{
138 registerQuery(new DoubleQTQuery(title,inputLayout,this));
139}
140
141void QTDialog::queryDoubles(const char* title,string)
142{
143 registerQuery(new DoublesQTQuery(title,inputLayout,this));
144}
145
146void QTDialog::queryString(const char* title,string)
147{
148 registerQuery(new StringQTQuery(title,inputLayout,this));
149}
150
151void QTDialog::queryStrings(const char* title,string)
152{
153 registerQuery(new StringsQTQuery(title,inputLayout,this));
154}
155
156void QTDialog::queryMolecule(const char *title,string)
157{
158 registerQuery(new MoleculeQTQuery(title,inputLayout,this));
159}
160
161void QTDialog::queryMolecules(const char *title,string)
162{
163 // TODO
164 ASSERT(false, "Not implemented yet");
165}
166
167void QTDialog::queryVector(const char* title, bool check,string)
168{
169 registerQuery(new VectorQTQuery(title,check,inputLayout,this));
170}
171
172void QTDialog::queryVectors(const char* title, bool check,string)
173{
174 // TODO
175 ASSERT(false, "Not implemented yet");
176}
177
178void QTDialog::queryElement(const char* title, std::string)
179{
180 registerQuery(new ElementQTQuery(title,inputLayout,this));
181}
182
183void QTDialog::queryElements(const char* title, std::string)
184{
185 // TODO
186 ASSERT(false, "Not implemented yet");
187}
188
189void QTDialog::queryFile(const char* title, std::string)
190{
191 registerQuery(new FileQTQuery(title,inputLayout,this));
192}
193
194/************************** Query Objects *******************************/
195
196QTDialog::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
217QTDialog::AtomQTQuery::~AtomQTQuery()
218{
219 delete pipe;
220}
221
222bool QTDialog::AtomQTQuery::handle() {
223 return true;
224}
225
226
227QTDialog::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
267QTDialog::AtomsQTQuery::~AtomsQTQuery()
268{
269 delete pipe;
270}
271
272bool QTDialog::AtomsQTQuery::handle() {
273 return true;
274}
275
276QTDialog::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
293QTDialog::IntQTQuery::~IntQTQuery()
294{
295 delete pipe;
296}
297
298bool QTDialog::IntQTQuery::handle() {
299 return true;
300}
301
302
303QTDialog::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
340QTDialog::IntsQTQuery::~IntsQTQuery()
341{
342 delete pipe;
343}
344
345bool QTDialog::IntsQTQuery::handle() {
346 return true;
347}
348
349
350QTDialog::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
369QTDialog::DoubleQTQuery::~DoubleQTQuery()
370{
371 delete pipe;
372}
373
374bool QTDialog::DoubleQTQuery::handle() {
375 return true;
376}
377
378
379QTDialog::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
415QTDialog::DoublesQTQuery::~DoublesQTQuery()
416{
417 delete pipe;
418}
419
420bool QTDialog::DoublesQTQuery::handle() {
421 return true;
422}
423
424
425QTDialog::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
441QTDialog::StringQTQuery::~StringQTQuery()
442{
443 delete pipe;
444}
445
446// All values besides the empty std::string are valid
447bool QTDialog::StringQTQuery::handle()
448{
449 return tmp!="";
450}
451
452QTDialog::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
488QTDialog::StringsQTQuery::~StringsQTQuery()
489{
490 delete pipe;
491}
492
493// All values besides the empty std::string are valid
494bool 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
510QTDialog::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
535QTDialog::MoleculeQTQuery::~MoleculeQTQuery()
536{
537 delete pipe;
538}
539
540// Handling is easy, since the GUI makes it impossible to select invalid values
541bool QTDialog::MoleculeQTQuery::handle()
542{
543 return true;
544}
545
546QTDialog::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
571QTDialog::MoleculesQTQuery::~MoleculesQTQuery()
572{
573 delete pipe;
574}
575
576// Handling is easy, since the GUI makes it impossible to select invalid values
577bool QTDialog::MoleculesQTQuery::handle()
578{
579 return true;
580}
581
582QTDialog::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
606QTDialog::VectorQTQuery::~VectorQTQuery()
607{}
608
609bool QTDialog::VectorQTQuery::handle() {
610 return true;
611}
612
613
614QTDialog::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
638QTDialog::VectorsQTQuery::~VectorsQTQuery()
639{}
640
641bool QTDialog::VectorsQTQuery::handle() {
642 return true;
643}
644
645
646QTDialog::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
671QTDialog::ElementQTQuery::~ElementQTQuery()
672{
673 delete pipe;
674}
675
676bool QTDialog::ElementQTQuery::handle(){
677 return true;
678}
679
680
681QTDialog::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
706QTDialog::ElementsQTQuery::~ElementsQTQuery()
707{
708 delete pipe;
709}
710
711bool QTDialog::ElementsQTQuery::handle(){
712 return true;
713}
714
715QTDialog::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
727QTDialog::EmptyQTQuery::~EmptyQTQuery()
728{
729 delete pipe;
730}
731
732bool QTDialog::EmptyQTQuery::handle(){
733 return true;
734}
735
736
737QTDialog::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
754QTDialog::BooleanQTQuery::~BooleanQTQuery()
755{
756 delete pipe;
757}
758
759bool QTDialog::BooleanQTQuery::handle(){
760 return true;
761}
762
763
764QTDialog::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
789QTDialog::FileQTQuery::~FileQTQuery()
790{
791 delete pipe;
792}
793
794bool QTDialog::FileQTQuery::handle(){
795 return true;
796}
797
798/*************************** Plumbing *******************************/
799
800
801template<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
810template<typename T> QTQueryListPipe<T>::~QTQueryListPipe()
811{}
812
813template<typename T> void QTQueryListPipe<T>::IntegerEntered(const QString&)
814{
815 AddButton->setEnabled(true);
816}
817
818template<typename T> void QTQueryListPipe<T>::IntegerSelected()
819{
820 if (inputList->selectedItems().empty())
821 RemoveButton->setEnabled(false);
822 else
823 RemoveButton->setEnabled(true);
824}
825
826template<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
840template<typename T> void QTQueryListPipe<T>::AddValue(T item) {
841 content->push_back(item);
842
843 dialog->update();
844}
845
846template<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
857template<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
868StringQTQueryPipe::StringQTQueryPipe(string *_content, QTDialog *_dialog) :
869 content(_content),
870 dialog(_dialog)
871{}
872
873StringQTQueryPipe::~StringQTQueryPipe()
874{}
875
876void StringQTQueryPipe::update(const QString& newText) {
877 content->assign(newText.toStdString());
878 dialog->update();
879}
880
881IntQTQueryPipe::IntQTQueryPipe(int *_content, QTDialog *_dialog) :
882 content(_content),
883 dialog(_dialog)
884{}
885
886IntQTQueryPipe::~IntQTQueryPipe()
887{}
888
889void IntQTQueryPipe::update(int newInt) {
890 (*content) = newInt;
891 dialog->update();
892}
893
894DoubleQTQueryPipe::DoubleQTQueryPipe(double *_content, QTDialog *_dialog) :
895 content(_content),
896 dialog(_dialog)
897{}
898
899DoubleQTQueryPipe::~DoubleQTQueryPipe()
900{}
901
902void DoubleQTQueryPipe::update(double newDbl) {
903 (*content) = newDbl;
904 dialog->update();
905}
906
907VectorQTQueryPipe::VectorQTQueryPipe(Vector *_content, QTDialog *_dialog, QComboBox *_theBox) :
908 content(_content),
909 dialog(_dialog),
910 theBox(_theBox)
911{}
912
913VectorQTQueryPipe::~VectorQTQueryPipe()
914{}
915
916void VectorQTQueryPipe::update() {
917 dialog->update();
918}
919
920VectorsQTQueryPipe::VectorsQTQueryPipe(std::vector<Vector> *_content, QTDialog *_dialog, QComboBox *_theBox) :
921 content(_content),
922 dialog(_dialog),
923 theBox(_theBox)
924{}
925
926VectorsQTQueryPipe::~VectorsQTQueryPipe()
927{}
928
929void VectorsQTQueryPipe::update() {
930 dialog->update();
931}
932
933AtomQTQueryPipe::AtomQTQueryPipe(atom **_content, QTDialog *_dialog, QComboBox *_theBox) :
934 content(_content),
935 dialog(_dialog),
936 theBox(_theBox)
937{}
938
939AtomQTQueryPipe::~AtomQTQueryPipe()
940{}
941
942void 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
950AtomsQTQueryPipe::AtomsQTQueryPipe(std::vector<atom *>*_content, QTDialog *_dialog, QListWidget *_theList) :
951 content(_content),
952 dialog(_dialog),
953 theList(_theList)
954{}
955
956AtomsQTQueryPipe::~AtomsQTQueryPipe()
957{}
958
959void 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
967void 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
982void 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
995MoleculeQTQueryPipe::MoleculeQTQueryPipe(molecule **_content, QTDialog *_dialog, QComboBox *_theBox) :
996 content(_content),
997 dialog(_dialog),
998 theBox(_theBox)
999{}
1000
1001MoleculeQTQueryPipe::~MoleculeQTQueryPipe()
1002{}
1003
1004void 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
1012MoleculesQTQueryPipe::MoleculesQTQueryPipe(std::vector<molecule *>*_content, QTDialog *_dialog, QComboBox *_theBox) :
1013 content(_content),
1014 dialog(_dialog),
1015 theBox(_theBox)
1016{}
1017
1018MoleculesQTQueryPipe::~MoleculesQTQueryPipe()
1019{}
1020
1021void 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
1030ElementQTQueryPipe::ElementQTQueryPipe(const element **_content, QTDialog *_dialog, QComboBox *_theBox) :
1031 content(_content),
1032 dialog(_dialog),
1033 theBox(_theBox)
1034{}
1035
1036ElementQTQueryPipe::~ElementQTQueryPipe()
1037{}
1038
1039void 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
1046ElementsQTQueryPipe::ElementsQTQueryPipe(std::vector<const element *>*_content, QTDialog *_dialog, QComboBox *_theBox) :
1047 content(_content),
1048 dialog(_dialog),
1049 theBox(_theBox)
1050{}
1051
1052ElementsQTQueryPipe::~ElementsQTQueryPipe()
1053{}
1054
1055void 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
1064EmptyQTQueryPipe::EmptyQTQueryPipe(QTDialog *_dialog, QLabel *_textLabel) :
1065 dialog(_dialog),
1066 textLabel(_textLabel)
1067{}
1068
1069EmptyQTQueryPipe::~EmptyQTQueryPipe()
1070{}
1071
1072void EmptyQTQueryPipe::update() {
1073 dialog->update();
1074}
1075
1076BooleanQTQueryPipe::BooleanQTQueryPipe(const bool *_content, QTDialog *_dialog, QComboBox *_booleanComboBox) :
1077 content(_content),
1078 dialog(_dialog),
1079 booleanComboBox(_booleanComboBox)
1080{}
1081
1082BooleanQTQueryPipe::~BooleanQTQueryPipe()
1083{}
1084
1085void BooleanQTQueryPipe::update() {
1086 dialog->update();
1087}
1088
1089FileQTQueryPipe::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
1098FileQTQueryPipe::~FileQTQueryPipe()
1099{
1100 if (theFileDialog != NULL)
1101 delete theFileDialog;
1102}
1103
1104void 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
1112void 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
Note: See TracBrowser for help on using the repository browser.