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

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

Fixed remainder of Dialog and derived classes for still present _target's.

  • Property mode set to 100644
File size: 11.3 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 <string>
11#include <sstream>
12#include <limits>
13
14#include <Qt/qboxlayout.h>
15#include <Qt/qlabel.h>
16#include <Qt/qspinbox.h>
17#include <QtGui/QDoubleSpinBox>
18#include <Qt/qlineedit.h>
19#include <Qt/qdialogbuttonbox.h>
20#include <Qt/qpushbutton.h>
21#include <Qt/qcombobox.h>
22
23#include "Helpers/MemDebug.hpp"
24
25#include "World.hpp"
26#include "periodentafel.hpp"
27#include "atom.hpp"
28#include "element.hpp"
29#include "molecule.hpp"
30#include "Descriptors/MoleculeIdDescriptor.hpp"
31#include "Matrix.hpp"
32#include "Box.hpp"
33
34
35using namespace std;
36
37QTDialog::QTDialog() :
38 QDialog(0)
39{
40 // creating and filling of the Dialog window
41 mainLayout = new QVBoxLayout();
42 inputLayout = new QVBoxLayout();
43 buttonLayout = new QVBoxLayout();
44 setLayout(mainLayout);
45 mainLayout->addLayout(inputLayout);
46 mainLayout->addLayout(buttonLayout);
47 buttons = new QDialogButtonBox(QDialogButtonBox::Ok| QDialogButtonBox::Cancel);
48 buttonLayout->addWidget(buttons);
49
50 // Disable the ok button until something was entered
51 buttons->button(QDialogButtonBox::Ok)->setEnabled(false);
52
53 // connect the buttons to their appropriate slots
54 connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
55 connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
56}
57
58QTDialog::~QTDialog()
59{
60}
61
62bool QTDialog::display(){
63 // Button state might have changed by some update that
64 // was done during query construction. To make sure
65 // the state is correct, we just call update one more time.
66 update();
67 if(exec()) {
68 setAll();
69 return true;
70 }
71 else {
72 return false;
73 }
74}
75
76void QTDialog::update(){
77 buttons->button(QDialogButtonBox::Ok)->setEnabled(checkAll());
78}
79
80/************************** Query Infrastructure ************************/
81
82void QTDialog::queryEmpty(char const*, string){
83 // TODO
84 ASSERT(false, "Not implemented yet");
85}
86
87void QTDialog::queryBoolean(char const*,string){
88 // TODO
89 ASSERT(false, "Not implemented yet");
90}
91
92void QTDialog::queryAtom(char const*, string){
93 // TODO
94 ASSERT(false, "Not implemented yet");
95}
96
97void QTDialog::queryBox(char const*, string){
98 // TODO
99 ASSERT(false, "Not implemented yet");
100}
101
102
103void QTDialog::queryInt(const char *title,string)
104{
105 registerQuery(new IntQTQuery(title,inputLayout,this));
106}
107
108void QTDialog::queryDouble(const char* title,string){
109 registerQuery(new DoubleQTQuery(title,inputLayout,this));
110}
111
112void QTDialog::queryString(const char* title,string)
113{
114 registerQuery(new StringQTQuery(title,inputLayout,this));
115}
116
117void QTDialog::queryStrings(const char* title,string)
118{
119 registerQuery(new StringsQTQuery(title,inputLayout,this));
120}
121
122void QTDialog::queryMolecule(const char *title,string)
123{
124 registerQuery(new MoleculeQTQuery(title,inputLayout,this));
125}
126
127void QTDialog::queryVector(const char* title, bool check,string) {
128 registerQuery(new VectorQTQuery(title,check,inputLayout,this));
129}
130
131void QTDialog::queryElement(const char* title, string){
132 registerQuery(new ElementQTQuery(title,inputLayout,this));
133}
134
135/************************** Query Objects *******************************/
136
137QTDialog::IntQTQuery::IntQTQuery(string _title,QBoxLayout *_parent,QTDialog *_dialog) :
138 Dialog::IntQuery(_title),
139 parent(_parent)
140{
141 thisLayout = new QHBoxLayout();
142 titleLabel = new QLabel(QString(getTitle().c_str()));
143 inputBox = new QSpinBox();
144 inputBox->setValue(0);
145 parent->addLayout(thisLayout);
146 thisLayout->addWidget(titleLabel);
147 thisLayout->addWidget(inputBox);
148
149 pipe = new IntQTQueryPipe(&tmp,_dialog);
150 pipe->update(inputBox->value());
151 connect(inputBox,SIGNAL(valueChanged(int)),pipe,SLOT(update(int)));
152}
153
154QTDialog::IntQTQuery::~IntQTQuery()
155{
156 delete pipe;
157}
158
159// Handling is easy since the GUI makes it impossible to enter invalid values
160bool QTDialog::IntQTQuery::handle()
161{
162 return true;
163}
164
165QTDialog::DoubleQTQuery::DoubleQTQuery(string title,QBoxLayout *_parent,QTDialog *_dialog) :
166 Dialog::DoubleQuery(title),
167 parent(_parent)
168{
169 thisLayout = new QHBoxLayout();
170 titleLabel = new QLabel(QString(getTitle().c_str()));
171 inputBox = new QDoubleSpinBox();
172 inputBox->setValue(0);
173 inputBox->setRange(-numeric_limits<double>::max(),numeric_limits<double>::max());
174 inputBox->setDecimals(3);
175 parent->addLayout(thisLayout);
176 thisLayout->addWidget(titleLabel);
177 thisLayout->addWidget(inputBox);
178
179 pipe = new DoubleQTQueryPipe(&tmp,_dialog);
180 pipe->update(inputBox->value());
181 connect(inputBox,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
182}
183
184QTDialog::DoubleQTQuery::~DoubleQTQuery()
185{
186 delete pipe;
187}
188
189bool QTDialog::DoubleQTQuery::handle() {
190 return true;
191}
192
193
194QTDialog::StringQTQuery::StringQTQuery(string _title,QBoxLayout *_parent,QTDialog *_dialog) :
195 Dialog::StringQuery(_title),
196 parent(_parent)
197{
198 thisLayout = new QHBoxLayout();
199 titleLabel = new QLabel(QString(getTitle().c_str()));
200 inputBox = new QLineEdit();
201 parent->addLayout(thisLayout);
202 thisLayout->addWidget(titleLabel);
203 thisLayout->addWidget(inputBox);
204
205 pipe = new StringQTQueryPipe(&tmp,_dialog);
206 pipe->update(inputBox->text());
207 connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(update(const QString&)));
208}
209
210QTDialog::StringQTQuery::~StringQTQuery()
211{
212 delete pipe;
213}
214
215// All values besides the empty string are valid
216bool QTDialog::StringQTQuery::handle()
217{
218 return tmp!="";
219}
220
221QTDialog::StringsQTQuery::StringsQTQuery(string _title,QBoxLayout *_parent,QTDialog *_dialog) :
222 Dialog::StringsQuery(_title),
223 parent(_parent)
224{
225 thisLayout = new QHBoxLayout();
226 titleLabel = new QLabel(QString(getTitle().c_str()));
227 inputBox = new QLineEdit();
228 parent->addLayout(thisLayout);
229 thisLayout->addWidget(titleLabel);
230 thisLayout->addWidget(inputBox);
231
232 pipe = new StringQTQueryPipe(&temp,_dialog);
233 pipe->update(inputBox->text());
234 connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(update(const QString&)));
235}
236
237QTDialog::StringsQTQuery::~StringsQTQuery()
238{
239 delete pipe;
240}
241
242// All values besides the empty string are valid
243bool QTDialog::StringsQTQuery::handle()
244{
245 // dissect by ","
246 string::iterator olditer = temp.begin();
247 for(string::iterator iter = temp.begin(); iter != temp.end(); ++iter) {
248 if (*iter == ' ') {
249 tmp.push_back(string(iter, olditer));
250 olditer = iter;
251 }
252 }
253 if (olditer != temp.begin()) // insert last part also
254 tmp.push_back(string(olditer, temp.end()));
255
256 return temp!="";
257}
258
259QTDialog::MoleculeQTQuery::MoleculeQTQuery(string _title, QBoxLayout *_parent,QTDialog *_dialog) :
260 Dialog::MoleculeQuery(_title),
261 parent(_parent)
262{
263 thisLayout = new QHBoxLayout();
264 titleLabel = new QLabel(QString(getTitle().c_str()));
265 inputBox = new QComboBox();
266 // add all molecules to the combo box
267 vector<molecule*> molecules = World::getInstance().getAllMolecules();
268 for(vector<molecule*>::iterator iter = molecules.begin();
269 iter != molecules.end();
270 ++iter) {
271 stringstream sstr;
272 sstr << (*iter)->IndexNr << "\t" << (*iter)->getName();
273 inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter)->IndexNr));
274 }
275 parent->addLayout(thisLayout);
276 thisLayout->addWidget(titleLabel);
277 thisLayout->addWidget(inputBox);
278
279 pipe = new MoleculeQTQueryPipe(&tmp,_dialog,inputBox);
280 pipe->update(inputBox->currentIndex());
281 connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
282}
283
284QTDialog::MoleculeQTQuery::~MoleculeQTQuery()
285{
286 delete pipe;
287}
288
289// Handling is easy, since the GUI makes it impossible to select invalid values
290bool QTDialog::MoleculeQTQuery::handle()
291{
292 return true;
293}
294
295QTDialog::VectorQTQuery::VectorQTQuery(std::string title, bool _check,QBoxLayout *_parent,QTDialog *_dialog) :
296 Dialog::VectorQuery(title,_check),
297 parent(_parent)
298{
299 const Matrix& M = World::getInstance().getDomain().getM();
300 const char *coords[3] = {"x:","y:","z:"};
301 mainLayout= new QHBoxLayout();
302 titleLabel = new QLabel(QString(getTitle().c_str()));
303 mainLayout->addWidget(titleLabel);
304 subLayout = new QVBoxLayout();
305 mainLayout->addLayout(subLayout);
306 for(int i=0; i<3; i++) {
307 coordLayout[i] = new QHBoxLayout();
308 subLayout->addLayout(coordLayout[i]);
309 coordLabel[i] = new QLabel(QString(coords[i]));
310 coordLayout[i]->addWidget(coordLabel[i]);
311 coordInput[i] = new QDoubleSpinBox();
312 coordInput[i]->setRange(0,M.at(i,i));
313 coordInput[i]->setDecimals(3);
314 coordLayout[i]->addWidget(coordInput[i]);
315 pipe[i] = new DoubleQTQueryPipe(&((*tmp)[i]),_dialog);
316 pipe[i]->update(coordInput[i]->value());
317 connect(coordInput[i],SIGNAL(valueChanged(double)),pipe[i],SLOT(update(double)));
318
319 }
320 parent->addLayout(mainLayout);
321}
322
323QTDialog::VectorQTQuery::~VectorQTQuery()
324{}
325
326bool QTDialog::VectorQTQuery::handle() {
327 return true;
328}
329
330
331QTDialog::ElementQTQuery::ElementQTQuery(std::string _title, QBoxLayout *_parent, QTDialog *_dialog) :
332 Dialog::ElementQuery(_title),
333 parent(_parent)
334{
335 periodentafel *periode = World::getInstance().getPeriode();
336 thisLayout = new QHBoxLayout();
337 titleLabel = new QLabel(QString(getTitle().c_str()));
338 inputBox = new QComboBox();
339 for(periodentafel::const_iterator iter = periode->begin();
340 iter!=periode->end();
341 ++iter)
342 {
343 stringstream sstr;
344 sstr << (*iter).first << "\t" << (*iter).second->name;
345 inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter).first));
346 }
347 parent->addLayout(thisLayout);
348 thisLayout->addWidget(titleLabel);
349 thisLayout->addWidget(inputBox);
350
351 pipe = new ElementQTQueryPipe(&tmp,_dialog,inputBox);
352 pipe->update(inputBox->currentIndex());
353 connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
354}
355
356QTDialog::ElementQTQuery::~ElementQTQuery()
357{
358 delete pipe;
359}
360
361bool QTDialog::ElementQTQuery::handle(){
362 return true;
363}
364
365/*************************** Plumbing *******************************/
366
367StringQTQueryPipe::StringQTQueryPipe(string *_content, QTDialog *_dialog) :
368 content(_content),
369 dialog(_dialog)
370{}
371
372StringQTQueryPipe::~StringQTQueryPipe()
373{}
374
375void StringQTQueryPipe::update(const QString& newText) {
376 content->assign(newText.toStdString());
377 dialog->update();
378}
379
380IntQTQueryPipe::IntQTQueryPipe(int *_content, QTDialog *_dialog) :
381 content(_content),
382 dialog(_dialog)
383{}
384
385IntQTQueryPipe::~IntQTQueryPipe()
386{}
387
388void IntQTQueryPipe::update(int newInt) {
389 (*content) = newInt;
390 dialog->update();
391}
392
393DoubleQTQueryPipe::DoubleQTQueryPipe(double *_content, QTDialog *_dialog) :
394 content(_content),
395 dialog(_dialog)
396{}
397
398DoubleQTQueryPipe::~DoubleQTQueryPipe()
399{}
400
401void DoubleQTQueryPipe::update(double newDbl) {
402 (*content) = newDbl;
403 dialog->update();
404}
405
406MoleculeQTQueryPipe::MoleculeQTQueryPipe(molecule **_content, QTDialog *_dialog, QComboBox *_theBox) :
407 content(_content),
408 dialog(_dialog),
409 theBox(_theBox)
410{}
411
412MoleculeQTQueryPipe::~MoleculeQTQueryPipe()
413{}
414
415void MoleculeQTQueryPipe::update(int newIndex) {
416 QVariant data = theBox->itemData(newIndex);
417 int idx = data.toInt();
418 (*content) = World::getInstance().getMolecule(MoleculeById(idx));
419 dialog->update();
420}
421
422ElementQTQueryPipe::ElementQTQueryPipe(std::vector<element *> *_content, QTDialog *_dialog, QComboBox *_theBox) :
423 content(_content),
424 dialog(_dialog),
425 theBox(_theBox)
426{
427 content->resize(1);
428}
429
430ElementQTQueryPipe::~ElementQTQueryPipe()
431{}
432
433void ElementQTQueryPipe::update(int newIndex) {
434 QVariant data = theBox->itemData(newIndex);
435 int idx = data.toInt();
436 (*content)[0] = World::getInstance().getPeriode()->FindElement(idx);
437 dialog->update();
438}
439
Note: See TracBrowser for help on using the repository browser.