source: src/UIElements/QT4/QTDialog.cpp@ 5ec8e3

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

Merge branch 'VectorRefactoring' into StructureRefactoring

Conflicts:

molecuilder/src/Makefile.am

  • Property mode set to 100644
File size: 10.5 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*, bool*,string){
88 // TODO
89 ASSERT(false, "Not implemented yet");
90}
91
92void QTDialog::queryAtom(char const*, atom**, string){
93 // TODO
94 ASSERT(false, "Not implemented yet");
95}
96
97void QTDialog::queryBox(char const*, Box*, string){
98 // TODO
99 ASSERT(false, "Not implemented yet");
100}
101
102
103void QTDialog::queryInt(const char *title, int *target,string)
104{
105 registerQuery(new IntQTQuery(title,target,inputLayout,this));
106}
107
108void QTDialog::queryDouble(const char* title, double* target,string){
109 registerQuery(new DoubleQTQuery(title,target,inputLayout,this));
110}
111
112void QTDialog::queryString(const char* title, std::string *target,string)
113{
114 registerQuery(new StringQTQuery(title,target,inputLayout,this));
115}
116
117void QTDialog::queryMolecule(const char *title,molecule **target,string)
118{
119 registerQuery(new MoleculeQTQuery(title,target,inputLayout,this));
120}
121
122void QTDialog::queryVector(const char* title, Vector *target, bool check,string) {
123 registerQuery(new VectorQTQuery(title,target,check,inputLayout,this));
124}
125
126void QTDialog::queryElement(const char* title, std::vector<element *> *target,string){
127 registerQuery(new ElementQTQuery(title,target,inputLayout,this));
128}
129
130/************************** Query Objects *******************************/
131
132QTDialog::IntQTQuery::IntQTQuery(string _title,int *_target,QBoxLayout *_parent,QTDialog *_dialog) :
133 Dialog::IntQuery(_title,_target),
134 parent(_parent)
135{
136 thisLayout = new QHBoxLayout();
137 titleLabel = new QLabel(QString(getTitle().c_str()));
138 inputBox = new QSpinBox();
139 inputBox->setValue(0);
140 parent->addLayout(thisLayout);
141 thisLayout->addWidget(titleLabel);
142 thisLayout->addWidget(inputBox);
143
144 pipe = new IntQTQueryPipe(&tmp,_dialog);
145 pipe->update(inputBox->value());
146 connect(inputBox,SIGNAL(valueChanged(int)),pipe,SLOT(update(int)));
147}
148
149QTDialog::IntQTQuery::~IntQTQuery()
150{
151 delete pipe;
152}
153
154// Handling is easy since the GUI makes it impossible to enter invalid values
155bool QTDialog::IntQTQuery::handle()
156{
157 return true;
158}
159
160QTDialog::DoubleQTQuery::DoubleQTQuery(string title,double *_target,QBoxLayout *_parent,QTDialog *_dialog) :
161 Dialog::DoubleQuery(title,_target),
162 parent(_parent)
163{
164 thisLayout = new QHBoxLayout();
165 titleLabel = new QLabel(QString(getTitle().c_str()));
166 inputBox = new QDoubleSpinBox();
167 inputBox->setValue(0);
168 inputBox->setRange(-numeric_limits<double>::max(),numeric_limits<double>::max());
169 inputBox->setDecimals(3);
170 parent->addLayout(thisLayout);
171 thisLayout->addWidget(titleLabel);
172 thisLayout->addWidget(inputBox);
173
174 pipe = new DoubleQTQueryPipe(&tmp,_dialog);
175 pipe->update(inputBox->value());
176 connect(inputBox,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
177}
178
179QTDialog::DoubleQTQuery::~DoubleQTQuery()
180{
181 delete pipe;
182}
183
184bool QTDialog::DoubleQTQuery::handle() {
185 return true;
186}
187
188
189QTDialog::StringQTQuery::StringQTQuery(string _title,string *_target,QBoxLayout *_parent,QTDialog *_dialog) :
190 Dialog::StringQuery(_title,_target),
191 parent(_parent)
192{
193 thisLayout = new QHBoxLayout();
194 titleLabel = new QLabel(QString(getTitle().c_str()));
195 inputBox = new QLineEdit();
196 parent->addLayout(thisLayout);
197 thisLayout->addWidget(titleLabel);
198 thisLayout->addWidget(inputBox);
199
200 pipe = new StringQTQueryPipe(&tmp,_dialog);
201 pipe->update(inputBox->text());
202 connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(update(const QString&)));
203}
204
205QTDialog::StringQTQuery::~StringQTQuery()
206{
207 delete pipe;
208}
209
210// All values besides the empty string are valid
211bool QTDialog::StringQTQuery::handle()
212{
213 return tmp!="";
214}
215
216QTDialog::MoleculeQTQuery::MoleculeQTQuery(string _title, molecule **_target, QBoxLayout *_parent,QTDialog *_dialog) :
217 Dialog::MoleculeQuery(_title,_target),
218 parent(_parent)
219{
220 thisLayout = new QHBoxLayout();
221 titleLabel = new QLabel(QString(getTitle().c_str()));
222 inputBox = new QComboBox();
223 // add all molecules to the combo box
224 vector<molecule*> molecules = World::getInstance().getAllMolecules();
225 for(vector<molecule*>::iterator iter = molecules.begin();
226 iter != molecules.end();
227 ++iter) {
228 stringstream sstr;
229 sstr << (*iter)->IndexNr << "\t" << (*iter)->getName();
230 inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter)->IndexNr));
231 }
232 parent->addLayout(thisLayout);
233 thisLayout->addWidget(titleLabel);
234 thisLayout->addWidget(inputBox);
235
236 pipe = new MoleculeQTQueryPipe(&tmp,_dialog,inputBox);
237 pipe->update(inputBox->currentIndex());
238 connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
239}
240
241QTDialog::MoleculeQTQuery::~MoleculeQTQuery()
242{
243 delete pipe;
244}
245
246// Handling is easy, since the GUI makes it impossible to select invalid values
247bool QTDialog::MoleculeQTQuery::handle()
248{
249 return true;
250}
251
252QTDialog::VectorQTQuery::VectorQTQuery(std::string title, Vector *_target, bool _check,QBoxLayout *_parent,QTDialog *_dialog) :
253 Dialog::VectorQuery(title,_target,_check),
254 parent(_parent)
255{
256 const Matrix& M = World::getInstance().getDomain().getM();
257 const char *coords[3] = {"x:","y:","z:"};
258 mainLayout= new QHBoxLayout();
259 titleLabel = new QLabel(QString(getTitle().c_str()));
260 mainLayout->addWidget(titleLabel);
261 subLayout = new QVBoxLayout();
262 mainLayout->addLayout(subLayout);
263 for(int i=0; i<3; i++) {
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,M.at(i,i));
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.