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

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

Merge branch 'MenuRefactoring' into QT4Refactoring

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/builder.cpp
molecuilder/src/unittests/Makefile.am

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