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

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 b47bfc was 257c77, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Merge branch 'stable' into QT4Refactoring

Conflicts:

molecuilder/src/Actions/TesselationAction/ConvexEnvelopeAction.hpp
molecuilder/src/Helpers/MemDebug.hpp
molecuilder/src/Makefile.am
molecuilder/src/UIElements/Dialog.cpp
molecuilder/src/UIElements/MainWindow.cpp
molecuilder/src/UIElements/TextUI/TextUIFactory.cpp
molecuilder/src/builder.cpp

  • Property mode set to 100644
File size: 10.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 <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::queryMolecule(const char *title,molecule **target,string)
116{
117 registerQuery(new MoleculeQTQuery(title,target,inputLayout,this));
118}
119
120void QTDialog::queryVector(const char* title, Vector *target,const double *const cellSize, bool check,string) {
121 registerQuery(new VectorQTQuery(title,target,cellSize,check,inputLayout,this));
122}
123
124void QTDialog::queryElement(const char* title, std::vector<element *> *target,string){
125 registerQuery(new ElementQTQuery(title,target,inputLayout,this));
126}
127
128/************************** Query Objects *******************************/
129
130QTDialog::IntQTQuery::IntQTQuery(string _title,int *_target,QBoxLayout *_parent,QTDialog *_dialog) :
131 Dialog::IntQuery(_title,_target),
132 parent(_parent)
133{
134 thisLayout = new QHBoxLayout();
135 titleLabel = new QLabel(QString(getTitle().c_str()));
136 inputBox = new QSpinBox();
137 inputBox->setValue(0);
138 parent->addLayout(thisLayout);
139 thisLayout->addWidget(titleLabel);
140 thisLayout->addWidget(inputBox);
141
142 pipe = new IntQTQueryPipe(&tmp,_dialog);
143 pipe->update(inputBox->value());
144 connect(inputBox,SIGNAL(valueChanged(int)),pipe,SLOT(update(int)));
145}
146
147QTDialog::IntQTQuery::~IntQTQuery()
148{
149 delete pipe;
150}
151
152// Handling is easy since the GUI makes it impossible to enter invalid values
153bool QTDialog::IntQTQuery::handle()
154{
155 return true;
156}
157
158QTDialog::DoubleQTQuery::DoubleQTQuery(string title,double *_target,QBoxLayout *_parent,QTDialog *_dialog) :
159 Dialog::DoubleQuery(title,_target),
160 parent(_parent)
161{
162 thisLayout = new QHBoxLayout();
163 titleLabel = new QLabel(QString(getTitle().c_str()));
164 inputBox = new QDoubleSpinBox();
165 inputBox->setValue(0);
166 inputBox->setRange(-numeric_limits<double>::max(),numeric_limits<double>::max());
167 inputBox->setDecimals(3);
168 parent->addLayout(thisLayout);
169 thisLayout->addWidget(titleLabel);
170 thisLayout->addWidget(inputBox);
171
172 pipe = new DoubleQTQueryPipe(&tmp,_dialog);
173 pipe->update(inputBox->value());
174 connect(inputBox,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
175}
176
177QTDialog::DoubleQTQuery::~DoubleQTQuery()
178{
179 delete pipe;
180}
181
182bool QTDialog::DoubleQTQuery::handle() {
183 return true;
184}
185
186
187QTDialog::StringQTQuery::StringQTQuery(string _title,string *_target,QBoxLayout *_parent,QTDialog *_dialog) :
188 Dialog::StringQuery(_title,_target),
189 parent(_parent)
190{
191 thisLayout = new QHBoxLayout();
192 titleLabel = new QLabel(QString(getTitle().c_str()));
193 inputBox = new QLineEdit();
194 parent->addLayout(thisLayout);
195 thisLayout->addWidget(titleLabel);
196 thisLayout->addWidget(inputBox);
197
198 pipe = new StringQTQueryPipe(&tmp,_dialog);
199 pipe->update(inputBox->text());
200 connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(update(const QString&)));
201}
202
203QTDialog::StringQTQuery::~StringQTQuery()
204{
205 delete pipe;
206}
207
208// All values besides the empty string are valid
209bool QTDialog::StringQTQuery::handle()
210{
211 return tmp!="";
212}
213
214QTDialog::MoleculeQTQuery::MoleculeQTQuery(string _title, molecule **_target, QBoxLayout *_parent,QTDialog *_dialog) :
215 Dialog::MoleculeQuery(_title,_target),
216 parent(_parent)
217{
218 thisLayout = new QHBoxLayout();
219 titleLabel = new QLabel(QString(getTitle().c_str()));
220 inputBox = new QComboBox();
221 // add all molecules to the combo box
222 vector<molecule*> molecules = World::getInstance().getAllMolecules();
223 for(vector<molecule*>::iterator iter = molecules.begin();
224 iter != molecules.end();
225 ++iter) {
226 stringstream sstr;
227 sstr << (*iter)->IndexNr << "\t" << (*iter)->getName();
228 inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter)->IndexNr));
229 }
230 parent->addLayout(thisLayout);
231 thisLayout->addWidget(titleLabel);
232 thisLayout->addWidget(inputBox);
233
234 pipe = new MoleculeQTQueryPipe(&tmp,_dialog,inputBox);
235 pipe->update(inputBox->currentIndex());
236 connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
237}
238
239QTDialog::MoleculeQTQuery::~MoleculeQTQuery()
240{
241 delete pipe;
242}
243
244// Handling is easy, since the GUI makes it impossible to select invalid values
245bool QTDialog::MoleculeQTQuery::handle()
246{
247 return true;
248}
249
250QTDialog::VectorQTQuery::VectorQTQuery(std::string title, Vector *_target, const double *const _cellSize, bool _check,QBoxLayout *_parent,QTDialog *_dialog) :
251 Dialog::VectorQuery(title,_target,_cellSize,_check),
252 parent(_parent)
253{
254 // 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
255 int j = -1;
256 const char *coords[3] = {"x:","y:","z:"};
257 mainLayout= new QHBoxLayout();
258 titleLabel = new QLabel(QString(getTitle().c_str()));
259 mainLayout->addWidget(titleLabel);
260 subLayout = new QVBoxLayout();
261 mainLayout->addLayout(subLayout);
262 for(int i=0; i<3; i++) {
263 j+=i+1;
264 coordLayout[i] = new QHBoxLayout();
265 subLayout->addLayout(coordLayout[i]);
266 coordLabel[i] = new QLabel(QString(coords[i]));
267 coordLayout[i]->addWidget(coordLabel[i]);
268 coordInput[i] = new QDoubleSpinBox();
269 coordInput[i]->setRange(0,cellSize[j]);
270 coordInput[i]->setDecimals(3);
271 coordLayout[i]->addWidget(coordInput[i]);
272 pipe[i] = new DoubleQTQueryPipe(&((*tmp)[i]),_dialog);
273 pipe[i]->update(coordInput[i]->value());
274 connect(coordInput[i],SIGNAL(valueChanged(double)),pipe[i],SLOT(update(double)));
275
276 }
277 parent->addLayout(mainLayout);
278}
279
280QTDialog::VectorQTQuery::~VectorQTQuery()
281{}
282
283bool QTDialog::VectorQTQuery::handle() {
284 return true;
285}
286
287
288QTDialog::ElementQTQuery::ElementQTQuery(std::string _title, vector<element *> *_target, QBoxLayout *_parent, QTDialog *_dialog) :
289 Dialog::ElementQuery(_title,_target),
290 parent(_parent)
291{
292 periodentafel *periode = World::getInstance().getPeriode();
293 thisLayout = new QHBoxLayout();
294 titleLabel = new QLabel(QString(getTitle().c_str()));
295 inputBox = new QComboBox();
296 for(periodentafel::const_iterator iter = periode->begin();
297 iter!=periode->end();
298 ++iter)
299 {
300 stringstream sstr;
301 sstr << (*iter).first << "\t" << (*iter).second->name;
302 inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter).first));
303 }
304 parent->addLayout(thisLayout);
305 thisLayout->addWidget(titleLabel);
306 thisLayout->addWidget(inputBox);
307
308 pipe = new ElementQTQueryPipe(&elements,_dialog,inputBox);
309 pipe->update(inputBox->currentIndex());
310 connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
311}
312
313QTDialog::ElementQTQuery::~ElementQTQuery()
314{
315 delete pipe;
316}
317
318bool QTDialog::ElementQTQuery::handle(){
319 return true;
320}
321
322/*************************** Plumbing *******************************/
323
324StringQTQueryPipe::StringQTQueryPipe(string *_content, QTDialog *_dialog) :
325 content(_content),
326 dialog(_dialog)
327{}
328
329StringQTQueryPipe::~StringQTQueryPipe()
330{}
331
332void StringQTQueryPipe::update(const QString& newText) {
333 content->assign(newText.toStdString());
334 dialog->update();
335}
336
337IntQTQueryPipe::IntQTQueryPipe(int *_content, QTDialog *_dialog) :
338 content(_content),
339 dialog(_dialog)
340{}
341
342IntQTQueryPipe::~IntQTQueryPipe()
343{}
344
345void IntQTQueryPipe::update(int newInt) {
346 (*content) = newInt;
347 dialog->update();
348}
349
350DoubleQTQueryPipe::DoubleQTQueryPipe(double *_content, QTDialog *_dialog) :
351 content(_content),
352 dialog(_dialog)
353{}
354
355DoubleQTQueryPipe::~DoubleQTQueryPipe()
356{}
357
358void DoubleQTQueryPipe::update(double newDbl) {
359 (*content) = newDbl;
360 dialog->update();
361}
362
363MoleculeQTQueryPipe::MoleculeQTQueryPipe(molecule **_content, QTDialog *_dialog, QComboBox *_theBox) :
364 content(_content),
365 dialog(_dialog),
366 theBox(_theBox)
367{}
368
369MoleculeQTQueryPipe::~MoleculeQTQueryPipe()
370{}
371
372void MoleculeQTQueryPipe::update(int newIndex) {
373 QVariant data = theBox->itemData(newIndex);
374 int idx = data.toInt();
375 (*content) = World::getInstance().getMolecule(MoleculeById(idx));
376 dialog->update();
377}
378
379ElementQTQueryPipe::ElementQTQueryPipe(std::vector<element *> *_content, QTDialog *_dialog, QComboBox *_theBox) :
380 content(_content),
381 dialog(_dialog),
382 theBox(_theBox)
383{
384 content->resize(1);
385}
386
387ElementQTQueryPipe::~ElementQTQueryPipe()
388{}
389
390void ElementQTQueryPipe::update(int newIndex) {
391 QVariant data = theBox->itemData(newIndex);
392 int idx = data.toInt();
393 (*content)[0] = World::getInstance().getPeriode()->FindElement(idx);
394 dialog->update();
395}
396
Note: See TracBrowser for help on using the repository browser.