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

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

Added dialogs for QT.

So far QTDialogs can query the same types a TextDialog can query.

  • Property mode set to 100644
File size: 5.7 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
13#include <Qt/qboxlayout.h>
14#include <Qt/qlabel.h>
15#include <Qt/qspinbox.h>
16#include <Qt/qlineedit.h>
17#include <Qt/qdialogbuttonbox.h>
18#include <Qt/qpushbutton.h>
19#include <Qt/qcombobox.h>
20
21#include "atom.hpp"
22#include "molecule.hpp"
23
24
25using namespace std;
26
27QTDialog::QTDialog() :
28 QDialog(0)
29{
30 // creating and filling of the Dialog window
31 mainLayout = new QVBoxLayout();
32 inputLayout = new QVBoxLayout();
33 buttonLayout = new QVBoxLayout();
34 setLayout(mainLayout);
35 mainLayout->addLayout(inputLayout);
36 mainLayout->addLayout(buttonLayout);
37 buttons = new QDialogButtonBox(QDialogButtonBox::Ok| QDialogButtonBox::Cancel);
38 buttonLayout->addWidget(buttons);
39
40 // Disable the ok button until something was entered
41 buttons->button(QDialogButtonBox::Ok)->setEnabled(false);
42
43 // connect the buttons to their appropriate slots
44 connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
45 connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
46}
47
48QTDialog::~QTDialog()
49{
50}
51
52bool QTDialog::display(){
53 // Button state might have changed by some update that
54 // was done during query construction. To make sure
55 // the state is correct, we just call update one more time.
56 update();
57 if(exec()) {
58 setAll();
59 return true;
60 }
61 else {
62 return false;
63 }
64}
65
66void QTDialog::update(){
67 buttons->button(QDialogButtonBox::Ok)->setEnabled(checkAll());
68}
69
70/************************** Query Infrastructure ************************/
71
72void QTDialog::queryInt(const char *title, int *target)
73{
74 registerQuery(new IntQTQuery(title,target,inputLayout,this));
75}
76
77void QTDialog::queryString(const char* title, std::string *target)
78{
79 registerQuery(new StringQTQuery(title,target,inputLayout,this));
80}
81
82void QTDialog::queryMolecule(const char *title,molecule **target,MoleculeListClass *molecules)
83{
84 registerQuery(new MoleculeQTQuery(title,target,molecules,inputLayout,this));
85}
86
87QTDialog::IntQTQuery::IntQTQuery(string _title,int *_target,QBoxLayout *_parent,QTDialog *_dialog) :
88 Dialog::IntQuery(_title,_target),
89 parent(_parent)
90{
91 thisLayout = new QHBoxLayout();
92 titleLabel = new QLabel(QString(getTitle().c_str()));
93 inputBox = new QSpinBox();
94 inputBox->setValue(0);
95 parent->addLayout(thisLayout);
96 thisLayout->addWidget(titleLabel);
97 thisLayout->addWidget(inputBox);
98
99 pipe = new IntQTQueryPipe(&tmp,_dialog);
100 pipe->update(inputBox->value());
101 connect(inputBox,SIGNAL(valueChanged(int)),pipe,SLOT(update(int)));
102}
103
104QTDialog::IntQTQuery::~IntQTQuery()
105{
106 delete pipe;
107}
108
109// Handling is easy since the GUI makes it impossible to enter invalid values
110bool QTDialog::IntQTQuery::handle()
111{
112 return true;
113}
114
115
116QTDialog::StringQTQuery::StringQTQuery(string _title,string *_target,QBoxLayout *_parent,QTDialog *_dialog) :
117 Dialog::StringQuery(_title,_target),
118 parent(_parent)
119{
120 thisLayout = new QHBoxLayout();
121 titleLabel = new QLabel(QString(getTitle().c_str()));
122 inputBox = new QLineEdit();
123 parent->addLayout(thisLayout);
124 thisLayout->addWidget(titleLabel);
125 thisLayout->addWidget(inputBox);
126
127 pipe = new StringQTQueryPipe(&tmp,_dialog);
128 pipe->update(inputBox->text());
129 connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(update(const QString&)));
130}
131
132QTDialog::StringQTQuery::~StringQTQuery()
133{
134 delete pipe;
135}
136
137// All values besides the empty string are valid
138bool QTDialog::StringQTQuery::handle()
139{
140 return tmp!="";
141}
142
143QTDialog::MoleculeQTQuery::MoleculeQTQuery(string _title, molecule **_target, MoleculeListClass *_molecules, QBoxLayout *_parent,QTDialog *_dialog) :
144 Dialog::MoleculeQuery(_title,_target,_molecules),
145 parent(_parent)
146{
147 MoleculeList::iterator iter;
148 thisLayout = new QHBoxLayout();
149 titleLabel = new QLabel(QString(getTitle().c_str()));
150 inputBox = new QComboBox();
151 // add all molecules to the combo box
152 for(iter = molecules->ListOfMolecules.begin();
153 iter != molecules->ListOfMolecules.end();
154 iter++) {
155 stringstream sstr;
156 sstr << (*iter)->IndexNr << "\t" << (*iter)->name;
157 inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter)->IndexNr));
158 }
159 parent->addLayout(thisLayout);
160 thisLayout->addWidget(titleLabel);
161 thisLayout->addWidget(inputBox);
162
163 pipe = new MoleculeQTQueryPipe(&tmp,_dialog,inputBox,_molecules);
164 pipe->update(inputBox->currentIndex());
165 connect(inputBox,SIGNAL(currentIndexChanged(int)),pipe,SLOT(update(int)));
166}
167
168QTDialog::MoleculeQTQuery::~MoleculeQTQuery()
169{
170 delete pipe;
171}
172
173// Handling is easy, since the GUI makes it impossible to select invalid values
174bool QTDialog::MoleculeQTQuery::handle()
175{
176 return true;
177}
178
179
180/*************************** Plumbing *******************************/
181
182StringQTQueryPipe::StringQTQueryPipe(string *_content, QTDialog *_dialog) :
183 content(_content),
184 dialog(_dialog)
185{}
186
187StringQTQueryPipe::~StringQTQueryPipe()
188{}
189
190void StringQTQueryPipe::update(const QString& newText) {
191 content->assign(newText.toStdString());
192 dialog->update();
193}
194
195IntQTQueryPipe::IntQTQueryPipe(int *_content, QTDialog *_dialog) :
196 content(_content),
197 dialog(_dialog)
198{}
199
200IntQTQueryPipe::~IntQTQueryPipe()
201{}
202
203void IntQTQueryPipe::update(int newInt) {
204 (*content) = newInt;
205 dialog->update();
206}
207
208MoleculeQTQueryPipe::MoleculeQTQueryPipe(molecule **_content, QTDialog *_dialog, QComboBox *_theBox, MoleculeListClass *_molecules) :
209 content(_content),
210 dialog(_dialog),
211 theBox(_theBox),
212 molecules(_molecules)
213{}
214
215MoleculeQTQueryPipe::~MoleculeQTQueryPipe()
216{}
217
218void MoleculeQTQueryPipe::update(int newIndex) {
219 QVariant data = theBox->itemData(newIndex);
220 int idx = data.toInt();
221 (*content) = molecules->ReturnIndex(idx);
222 dialog->update();
223}
224
Note: See TracBrowser for help on using the repository browser.