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

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

Merge branch 'AtomicPositionEncapsulation' into stable

Conflicts:

src/Actions/AtomAction/ChangeElementAction.cpp
src/Actions/WorldAction/RemoveSphereOfAtomsAction.cpp
src/Makefile.am
src/UIElements/TextUI/TextDialog.cpp
src/analysis_correlation.hpp
src/atom.cpp
src/atom_atominfo.hpp
src/bond.cpp
src/boundary.cpp
src/molecule_geometry.cpp
src/tesselation.cpp
src/tesselationhelpers.cpp
src/triangleintersectionlist.cpp
src/unittests/Makefile.am

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