source: src/UIElements/QT4/QTDialog.cpp@ 86cff86

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

New StringsQuery that returns space-separated vector of strings.

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 11.9 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
32
33using namespace std;
34
35QTDialog::QTDialog() :
36 QDialog(0)
37{
38 // creating and filling of the Dialog window
39 mainLayout = new QVBoxLayout();
40 inputLayout = new QVBoxLayout();
41 buttonLayout = new QVBoxLayout();
42 setLayout(mainLayout);
43 mainLayout->addLayout(inputLayout);
44 mainLayout->addLayout(buttonLayout);
45 buttons = new QDialogButtonBox(QDialogButtonBox::Ok| QDialogButtonBox::Cancel);
46 buttonLayout->addWidget(buttons);
47
48 // Disable the ok button until something was entered
49 buttons->button(QDialogButtonBox::Ok)->setEnabled(false);
50
51 // connect the buttons to their appropriate slots
52 connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
53 connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
54}
55
56QTDialog::~QTDialog()
57{
58}
59
60bool QTDialog::display(){
61 // Button state might have changed by some update that
62 // was done during query construction. To make sure
63 // the state is correct, we just call update one more time.
64 update();
65 if(exec()) {
66 setAll();
67 return true;
68 }
69 else {
70 return false;
71 }
72}
73
74void QTDialog::update(){
75 buttons->button(QDialogButtonBox::Ok)->setEnabled(checkAll());
76}
77
78/************************** Query Infrastructure ************************/
79
80void QTDialog::queryEmpty(char const*, string){
81 // TODO
82 ASSERT(false, "Not implemented yet");
83}
84
85void QTDialog::queryBoolean(char const*, bool*,string){
86 // TODO
87 ASSERT(false, "Not implemented yet");
88}
89
90void QTDialog::queryAtom(char const*, atom**, string){
91 // TODO
92 ASSERT(false, "Not implemented yet");
93}
94
95void QTDialog::queryBox(char const*, double**, string){
96 // TODO
97 ASSERT(false, "Not implemented yet");
98}
99
100
101void QTDialog::queryInt(const char *title, int *target,string)
102{
103 registerQuery(new IntQTQuery(title,target,inputLayout,this));
104}
105
106void QTDialog::queryDouble(const char* title, double* target,string){
107 registerQuery(new DoubleQTQuery(title,target,inputLayout,this));
108}
109
110void QTDialog::queryString(const char* title, std::string *target,string)
111{
112 registerQuery(new StringQTQuery(title,target,inputLayout,this));
113}
114
115void QTDialog::queryStrings(const char* title, std::vector<std::string> *target,string)
116{
117 registerQuery(new StringsQTQuery(title,target,inputLayout,this));
118}
119
120void QTDialog::queryMolecule(const char *title,molecule **target,string)
121{
122 registerQuery(new MoleculeQTQuery(title,target,inputLayout,this));
123}
124
125void QTDialog::queryVector(const char* title, Vector *target,const double *const cellSize, bool check,string) {
126 registerQuery(new VectorQTQuery(title,target,cellSize,check,inputLayout,this));
127}
128
129void QTDialog::queryElement(const char* title, std::vector<element *> *target,string){
130 registerQuery(new ElementQTQuery(title,target,inputLayout,this));
131}
132
133/************************** Query Objects *******************************/
134
135QTDialog::IntQTQuery::IntQTQuery(string _title,int *_target,QBoxLayout *_parent,QTDialog *_dialog) :
136 Dialog::IntQuery(_title,_target),
137 parent(_parent)
138{
139 thisLayout = new QHBoxLayout();
140 titleLabel = new QLabel(QString(getTitle().c_str()));
141 inputBox = new QSpinBox();
142 inputBox->setValue(0);
143 parent->addLayout(thisLayout);
144 thisLayout->addWidget(titleLabel);
145 thisLayout->addWidget(inputBox);
146
147 pipe = new IntQTQueryPipe(&tmp,_dialog);
148 pipe->update(inputBox->value());
149 connect(inputBox,SIGNAL(valueChanged(int)),pipe,SLOT(update(int)));
150}
151
152QTDialog::IntQTQuery::~IntQTQuery()
153{
154 delete pipe;
155}
156
157// Handling is easy since the GUI makes it impossible to enter invalid values
158bool QTDialog::IntQTQuery::handle()
159{
160 return true;
161}
162
163QTDialog::DoubleQTQuery::DoubleQTQuery(string title,double *_target,QBoxLayout *_parent,QTDialog *_dialog) :
164 Dialog::DoubleQuery(title,_target),
165 parent(_parent)
166{
167 thisLayout = new QHBoxLayout();
168 titleLabel = new QLabel(QString(getTitle().c_str()));
169 inputBox = new QDoubleSpinBox();
170 inputBox->setValue(0);
171 inputBox->setRange(-numeric_limits<double>::max(),numeric_limits<double>::max());
172 inputBox->setDecimals(3);
173 parent->addLayout(thisLayout);
174 thisLayout->addWidget(titleLabel);
175 thisLayout->addWidget(inputBox);
176
177 pipe = new DoubleQTQueryPipe(&tmp,_dialog);
178 pipe->update(inputBox->value());
179 connect(inputBox,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
180}
181
182QTDialog::DoubleQTQuery::~DoubleQTQuery()
183{
184 delete pipe;
185}
186
187bool QTDialog::DoubleQTQuery::handle() {
188 return true;
189}
190
191
192QTDialog::StringQTQuery::StringQTQuery(string _title,string *_target,QBoxLayout *_parent,QTDialog *_dialog) :
193 Dialog::StringQuery(_title,_target),
194 parent(_parent)
195{
196 thisLayout = new QHBoxLayout();
197 titleLabel = new QLabel(QString(getTitle().c_str()));
198 inputBox = new QLineEdit();
199 parent->addLayout(thisLayout);
200 thisLayout->addWidget(titleLabel);
201 thisLayout->addWidget(inputBox);
202
203 pipe = new StringQTQueryPipe(&tmp,_dialog);
204 pipe->update(inputBox->text());
205 connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(update(const QString&)));
206}
207
208QTDialog::StringQTQuery::~StringQTQuery()
209{
210 delete pipe;
211}
212
213// All values besides the empty string are valid
214bool QTDialog::StringQTQuery::handle()
215{
216 return tmp!="";
217}
218
219QTDialog::StringsQTQuery::StringsQTQuery(string _title,vector<string> *_target,QBoxLayout *_parent,QTDialog *_dialog) :
220 Dialog::StringsQuery(_title,_target),
221 parent(_parent)
222{
223 thisLayout = new QHBoxLayout();
224 titleLabel = new QLabel(QString(getTitle().c_str()));
225 inputBox = new QLineEdit();
226 parent->addLayout(thisLayout);
227 thisLayout->addWidget(titleLabel);
228 thisLayout->addWidget(inputBox);
229
230 pipe = new StringQTQueryPipe(&temp,_dialog);
231 pipe->update(inputBox->text());
232 connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(update(const QString&)));
233}
234
235QTDialog::StringsQTQuery::~StringsQTQuery()
236{
237 delete pipe;
238}
239
240// All values besides the empty string are valid
241bool QTDialog::StringsQTQuery::handle()
242{
243 // dissect by ","
244 string::iterator olditer = temp.begin();
245 for(string::iterator iter = temp.begin(); iter != temp.end(); ++iter) {
246 if (*iter == ' ') {
247 tmp.push_back(string(iter, olditer));
248 olditer = iter;
249 }
250 }
251 if (olditer != temp.begin()) // insert last part also
252 tmp.push_back(string(olditer, temp.end()));
253
254 return temp!="";
255}
256
257QTDialog::MoleculeQTQuery::MoleculeQTQuery(string _title, molecule **_target, QBoxLayout *_parent,QTDialog *_dialog) :
258 Dialog::MoleculeQuery(_title,_target),
259 parent(_parent)
260{
261 thisLayout = new QHBoxLayout();
262 titleLabel = new QLabel(QString(getTitle().c_str()));
263 inputBox = new QComboBox();
264 // add all molecules to the combo box
265 vector<molecule*> molecules = World::getInstance().getAllMolecules();
266 for(vector<molecule*>::iterator iter = molecules.begin();
267 iter != molecules.end();
268 ++iter) {
269 stringstream sstr;
270 sstr << (*iter)->IndexNr << "\t" << (*iter)->getName();
271 inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter)->IndexNr));
272 }
273 parent->addLayout(thisLayout);
274 thisLayout->addWidget(titleLabel);
275 thisLayout->addWidget(inputBox);
276
277 pipe = new MoleculeQTQueryPipe(&tmp,_dialog,inputBox);
278 pipe->update(inputBox->currentIndex());
279 connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
280}
281
282QTDialog::MoleculeQTQuery::~MoleculeQTQuery()
283{
284 delete pipe;
285}
286
287// Handling is easy, since the GUI makes it impossible to select invalid values
288bool QTDialog::MoleculeQTQuery::handle()
289{
290 return true;
291}
292
293QTDialog::VectorQTQuery::VectorQTQuery(std::string title, Vector *_target, const double *const _cellSize, bool _check,QBoxLayout *_parent,QTDialog *_dialog) :
294 Dialog::VectorQuery(title,_target,_cellSize,_check),
295 parent(_parent)
296{
297 // About the j: I don't know why it was done this way, but it was used this way in Vector::AskPosition, so I reused it
298 int j = -1;
299 const char *coords[3] = {"x:","y:","z:"};
300 mainLayout= new QHBoxLayout();
301 titleLabel = new QLabel(QString(getTitle().c_str()));
302 mainLayout->addWidget(titleLabel);
303 subLayout = new QVBoxLayout();
304 mainLayout->addLayout(subLayout);
305 for(int i=0; i<3; i++) {
306 j+=i+1;
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,cellSize[j]);
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, vector<element *> *_target, QBoxLayout *_parent, QTDialog *_dialog) :
332 Dialog::ElementQuery(_title,_target),
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(&elements,_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.