source: src/UIElements/QT4/QTDialog.cpp@ 63b56a7

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

Merge branch 'MenuRefactoring' into QT4Refactoring

Conflicts:

molecuilder/src/Actions/Process.cpp
molecuilder/src/Actions/Process.hpp
molecuilder/src/Actions/small_actions.hpp
molecuilder/src/Makefile.am
molecuilder/src/UIElements/TextDialog.cpp
molecuilder/src/World.cpp
molecuilder/src/unittests/Makefile.am

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