source: src/UIElements/QT4/QTDialog.cpp@ 9cd807

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 9cd807 was bf3817, checked in by Frederik Heber <heber@…>, 15 years ago

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

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