source: src/UIElements/QT4/QTDialog.cpp@ 6d587e

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

Merge branch 'StructureRefactoring' into stable

Conflicts:

src/Actions/AnalysisAction/PairCorrelationAction.hpp
src/Actions/AnalysisAction/SurfaceCorrelationAction.hpp

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