source: src/UIElements/QT4/QTDialog.cpp@ 0bb05a

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

BUGFIX: include for boost/lexical_cast.hpp was missing.

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