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

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

Member variable Vector and element of class atom are now private.

  • Property mode set to 100644
File size: 23.5 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 mainLayout= new QHBoxLayout();
482 titleLabel = new QLabel(QString(getTitle().c_str()));
483 mainLayout->addWidget(titleLabel);
484 subLayout = new QVBoxLayout();
485 mainLayout->addLayout(subLayout);
486 QComboBox* inputBox = new QComboBox();
487 coordLayout = new QHBoxLayout();
488 subLayout->addLayout(coordLayout);
489 coordLabel = new QLabel(QString("x,y,z"));
490 coordLayout->addWidget(coordLabel);
491 coordInput = new QDoubleSpinBox();
492// coordInput->setRange(0,M.at(i,i));
493 coordInput->setDecimals(3);
494 coordLayout->addWidget(coordInput);
495 pipe = new VectorQTQueryPipe(&(tmp),_dialog,inputBox);
496 //pipe->update(coordInput->value());
497 connect(coordInput,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
498 parent->addLayout(mainLayout);
499}
500
501QTDialog::VectorQTQuery::~VectorQTQuery()
502{}
503
504bool QTDialog::VectorQTQuery::handle() {
505 return true;
506}
507
508
509QTDialog::VectorsQTQuery::VectorsQTQuery(std::string title, bool _check,QBoxLayout *_parent,QTDialog *_dialog) :
510 Dialog::VectorsQuery(title,_check),
511 parent(_parent)
512{
513 mainLayout= new QHBoxLayout();
514 titleLabel = new QLabel(QString(getTitle().c_str()));
515 mainLayout->addWidget(titleLabel);
516 subLayout = new QVBoxLayout();
517 mainLayout->addLayout(subLayout);
518 QComboBox* inputBox = new QComboBox();
519 coordLayout = new QHBoxLayout();
520 subLayout->addLayout(coordLayout);
521 coordLabel = new QLabel(QString("x,y,z"));
522 coordLayout->addWidget(coordLabel);
523 coordInput = new QDoubleSpinBox();
524// coordInput->setRange(0,M.at(i,i));
525 coordInput->setDecimals(3);
526 coordLayout->addWidget(coordInput);
527 pipe = new VectorsQTQueryPipe(&(tmp),_dialog,inputBox);
528 //pipe->update(coordInput->value());
529 connect(coordInput,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
530 parent->addLayout(mainLayout);
531}
532
533QTDialog::VectorsQTQuery::~VectorsQTQuery()
534{}
535
536bool QTDialog::VectorsQTQuery::handle() {
537 return true;
538}
539
540
541QTDialog::ElementQTQuery::ElementQTQuery(std::string _title, QBoxLayout *_parent, QTDialog *_dialog) :
542 Dialog::ElementQuery(_title),
543 parent(_parent)
544{
545 periodentafel *periode = World::getInstance().getPeriode();
546 thisLayout = new QHBoxLayout();
547 titleLabel = new QLabel(QString(getTitle().c_str()));
548 inputBox = new QComboBox();
549 for(periodentafel::const_iterator iter = periode->begin();
550 iter!=periode->end();
551 ++iter)
552 {
553 stringstream sstr;
554 sstr << (*iter).first << "\t" << (*iter).second->name;
555 inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter).first));
556 }
557 parent->addLayout(thisLayout);
558 thisLayout->addWidget(titleLabel);
559 thisLayout->addWidget(inputBox);
560
561 pipe = new ElementQTQueryPipe(&tmp,_dialog,inputBox);
562 pipe->update(inputBox->currentIndex());
563 connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
564}
565
566QTDialog::ElementQTQuery::~ElementQTQuery()
567{
568 delete pipe;
569}
570
571bool QTDialog::ElementQTQuery::handle(){
572 return true;
573}
574
575
576QTDialog::ElementsQTQuery::ElementsQTQuery(std::string _title, QBoxLayout *_parent, QTDialog *_dialog) :
577 Dialog::ElementsQuery(_title),
578 parent(_parent)
579{
580 periodentafel *periode = World::getInstance().getPeriode();
581 thisLayout = new QHBoxLayout();
582 titleLabel = new QLabel(QString(getTitle().c_str()));
583 inputBox = new QComboBox();
584 for(periodentafel::const_iterator iter = periode->begin();
585 iter!=periode->end();
586 ++iter)
587 {
588 stringstream sstr;
589 sstr << (*iter).first << "\t" << (*iter).second->name;
590 inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter).first));
591 }
592 parent->addLayout(thisLayout);
593 thisLayout->addWidget(titleLabel);
594 thisLayout->addWidget(inputBox);
595
596 pipe = new ElementsQTQueryPipe(&tmp,_dialog,inputBox);
597 pipe->update(inputBox->currentIndex());
598 connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
599}
600
601QTDialog::ElementsQTQuery::~ElementsQTQuery()
602{
603 delete pipe;
604}
605
606bool QTDialog::ElementsQTQuery::handle(){
607 return true;
608}
609
610/*************************** Plumbing *******************************/
611
612
613template<typename T> QTQueryListPipe<T>::QTQueryListPipe(std::vector<T> *_content, QTDialog *_dialog, QLineEdit *_inputBox, QListWidget *_inputList, QPushButton *_AddButton, QPushButton *_RemoveButton) :
614 content(_content),
615 dialog(_dialog),
616 inputBox(_inputBox),
617 inputList(_inputList),
618 AddButton(_AddButton),
619 RemoveButton(_RemoveButton)
620{}
621
622template<typename T> QTQueryListPipe<T>::~QTQueryListPipe()
623{}
624
625template<typename T> void QTQueryListPipe<T>::IntegerEntered(const QString&)
626{
627 AddButton->setEnabled(true);
628}
629
630template<typename T> void QTQueryListPipe<T>::IntegerSelected()
631{
632 if (inputList->selectedItems().empty())
633 RemoveButton->setEnabled(false);
634 else
635 RemoveButton->setEnabled(true);
636}
637
638template<typename T> void QTQueryListPipe<T>::AddInteger() {
639 // type-check
640 std::string text = inputBox->text().toStdString();
641 int number = 0;
642 try {
643 number = boost::lexical_cast<int>(text);
644 } catch (boost::bad_lexical_cast&) {
645 return;
646 };
647 // add item to both
648 inputList->addItem(QString(number));
649 AddValue(number);
650}
651
652template<typename T> void QTQueryListPipe<T>::AddValue(T item) {
653 content->push_back(item);
654
655 dialog->update();
656}
657
658template<typename T> void QTQueryListPipe<T>::RemoveInteger() {
659 QList<QListWidgetItem *> items = inputList->selectedItems();
660 for (QList<QListWidgetItem *>::iterator iter = items.begin(); !items.empty(); iter = items.begin()) {
661 // obtain which position item has (by making it current item)
662 inputList->setCurrentItem(*iter);
663 // remove
664 QTQueryListPipe<T>::RemoteRow(inputList->currentRow()); // template parameters needs to be known, such that compiler knows which to call
665 inputList->removeItemWidget(*iter);
666 }
667}
668
669template<typename T> void QTQueryListPipe<T>::RemoveRow(int row) {
670 int counter = 0;
671 typename std::vector<T>::iterator iter = content->begin();
672 for (; iter != content->end(); ++iter)
673 if (counter++ == row)
674 break;
675 if (iter != content->end())
676 content->erase(iter);
677}
678
679
680StringQTQueryPipe::StringQTQueryPipe(string *_content, QTDialog *_dialog) :
681 content(_content),
682 dialog(_dialog)
683{}
684
685StringQTQueryPipe::~StringQTQueryPipe()
686{}
687
688void StringQTQueryPipe::update(const QString& newText) {
689 content->assign(newText.toStdString());
690 dialog->update();
691}
692
693IntQTQueryPipe::IntQTQueryPipe(int *_content, QTDialog *_dialog) :
694 content(_content),
695 dialog(_dialog)
696{}
697
698IntQTQueryPipe::~IntQTQueryPipe()
699{}
700
701void IntQTQueryPipe::update(int newInt) {
702 (*content) = newInt;
703 dialog->update();
704}
705
706DoubleQTQueryPipe::DoubleQTQueryPipe(double *_content, QTDialog *_dialog) :
707 content(_content),
708 dialog(_dialog)
709{}
710
711DoubleQTQueryPipe::~DoubleQTQueryPipe()
712{}
713
714void DoubleQTQueryPipe::update(double newDbl) {
715 (*content) = newDbl;
716 dialog->update();
717}
718
719VectorQTQueryPipe::VectorQTQueryPipe(Vector *_content, QTDialog *_dialog, QComboBox *_theBox) :
720 content(_content),
721 dialog(_dialog),
722 theBox(_theBox)
723{}
724
725VectorQTQueryPipe::~VectorQTQueryPipe()
726{}
727
728void VectorQTQueryPipe::update() {
729 dialog->update();
730}
731
732VectorsQTQueryPipe::VectorsQTQueryPipe(std::vector<Vector> *_content, QTDialog *_dialog, QComboBox *_theBox) :
733 content(_content),
734 dialog(_dialog),
735 theBox(_theBox)
736{}
737
738VectorsQTQueryPipe::~VectorsQTQueryPipe()
739{}
740
741void VectorsQTQueryPipe::update() {
742 dialog->update();
743}
744
745AtomQTQueryPipe::AtomQTQueryPipe(atom **_content, QTDialog *_dialog, QComboBox *_theBox) :
746 content(_content),
747 dialog(_dialog),
748 theBox(_theBox)
749{}
750
751AtomQTQueryPipe::~AtomQTQueryPipe()
752{}
753
754void AtomQTQueryPipe::update(int newIndex) {
755 QVariant data = theBox->itemData(newIndex);
756 int idx = data.toInt();
757 (*content) = World::getInstance().getAtom(AtomById(idx));
758 dialog->update();
759}
760
761
762AtomsQTQueryPipe::AtomsQTQueryPipe(std::vector<atom *>*_content, QTDialog *_dialog, QComboBox *_theBox) :
763 content(_content),
764 dialog(_dialog),
765 theBox(_theBox)
766{}
767
768AtomsQTQueryPipe::~AtomsQTQueryPipe()
769{}
770
771void AtomsQTQueryPipe::update(int newIndex) {
772 QVariant data = theBox->itemData(newIndex);
773 int idx = data.toInt();
774 atom *Walker = World::getInstance().getAtom(AtomById(idx));
775 if (Walker)
776 (*content).push_back(Walker) ;
777 dialog->update();
778}
779
780
781MoleculeQTQueryPipe::MoleculeQTQueryPipe(molecule **_content, QTDialog *_dialog, QComboBox *_theBox) :
782 content(_content),
783 dialog(_dialog),
784 theBox(_theBox)
785{}
786
787MoleculeQTQueryPipe::~MoleculeQTQueryPipe()
788{}
789
790void MoleculeQTQueryPipe::update(int newIndex) {
791 QVariant data = theBox->itemData(newIndex);
792 int idx = data.toInt();
793 (*content) = World::getInstance().getMolecule(MoleculeById(idx));
794 dialog->update();
795}
796
797
798MoleculesQTQueryPipe::MoleculesQTQueryPipe(std::vector<molecule *>*_content, QTDialog *_dialog, QComboBox *_theBox) :
799 content(_content),
800 dialog(_dialog),
801 theBox(_theBox)
802{}
803
804MoleculesQTQueryPipe::~MoleculesQTQueryPipe()
805{}
806
807void MoleculesQTQueryPipe::update(int newIndex) {
808 QVariant data = theBox->itemData(newIndex);
809 int idx = data.toInt();
810 molecule *mol = World::getInstance().getMolecule(MoleculeById(idx));
811 if (mol)
812 (*content).push_back(mol);
813 dialog->update();
814}
815
816ElementQTQueryPipe::ElementQTQueryPipe(element **_content, QTDialog *_dialog, QComboBox *_theBox) :
817 content(_content),
818 dialog(_dialog),
819 theBox(_theBox)
820{}
821
822ElementQTQueryPipe::~ElementQTQueryPipe()
823{}
824
825void ElementQTQueryPipe::update(int newIndex) {
826 QVariant data = theBox->itemData(newIndex);
827 int idx = data.toInt();
828 *content = World::getInstance().getPeriode()->FindElement(idx);
829 dialog->update();
830}
831
832ElementsQTQueryPipe::ElementsQTQueryPipe(std::vector<element *>*_content, QTDialog *_dialog, QComboBox *_theBox) :
833 content(_content),
834 dialog(_dialog),
835 theBox(_theBox)
836{}
837
838ElementsQTQueryPipe::~ElementsQTQueryPipe()
839{}
840
841void ElementsQTQueryPipe::update(int newIndex) {
842 QVariant data = theBox->itemData(newIndex);
843 int idx = data.toInt();
844 element *elemental = World::getInstance().getPeriode()->FindElement(idx);
845 if(elemental)
846 (*content).push_back(elemental);
847 dialog->update();
848}
849
850
Note: See TracBrowser for help on using the repository browser.