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

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 db7cb0 was 6f5dfe, checked in by Frederik Heber <heber@…>, 14 years ago

Added boost::filesystem usage for input files.

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