source: src/UIElements/Qt4/Query/VectorQtQuery.cpp@ 06536b

Candidate_v1.6.1 ChemicalSpaceEvaluator Exclude_Hydrogens_annealWithBondGraph ForceAnnealing_with_BondGraph_contraction-expansion
Last change on this file since 06536b was f4b6bc9, checked in by Frederik Heber <frederik.heber@…>, 7 years ago

Query::handle() no longer returns bool but has internal result flag.

  • we use this flag conditionally in setResult(), i.e. if the handle() has failed, then we should not set its result which might overwrite a present default value in the parameter.
  • this fixes the problem with StepWorldTime which has a default value of 1 but which was overwritten with 0 because of the non-conditionally calling of setResult().
  • this required change of "output-types" default parameter to an empty vector. So far, we were just lucky that this actually worked.
  • also StoreSaturatedFragmentAction needed the same change as default values have to be consistent over the specific token.
  • Property mode set to 100644
File size: 6.2 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * VectorQtQuery.cpp
25 *
26 * Created on: Oct 25, 2010
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include <QtGui/QDoubleSpinBox>
36#include <Qt/qboxlayout.h>
37#include <Qt/qcombobox.h>
38#include <Qt/qlabel.h>
39#include <Qt/qstackedwidget.h>
40
41//#include "CodePatterns/MemDebug.hpp"
42
43#include "UIElements/Qt4/Query/QtQuery.hpp"
44
45#include "CodePatterns/toString.hpp"
46
47#include "Geometry/GeometryRegistry.hpp"
48#include "Parameters/Specifics/Value_vector.hpp"
49
50QtDialog::VectorQtQuery::VectorQtQuery(Parameter<Vector> &_param, const std::string &_title, const std::string &_description, QBoxLayout *_parent,Dialog *_dialog) :
51 QtQuery<Vector>(_param, _title, _description),
52 parent(_parent),
53 dialog(_dialog)
54{
55 Vector temporary(0, 0, 0);
56 temp = "0, 0, 0";
57 if (param.isSet()) {
58 temporary = param.get();
59 temp = param.getAsString();
60 }
61 mainLayout= new QHBoxLayout();
62 titleLabel = new QLabel(QString(getTitle().c_str()));
63 titleLabel->setToolTip(QString(getDescription().c_str()));
64 mainLayout->addWidget(titleLabel);
65 subLayout = new QHBoxLayout();
66 mainLayout->addLayout(subLayout);
67// QComboBox* inputBox = new QComboBox();
68
69 QWidget *firstPageWidget = new QWidget;
70 QWidget *secondPageWidget = new QWidget;
71
72 QStackedWidget *stackedWidget = new QStackedWidget;
73 stackedWidget->addWidget(firstPageWidget);
74 stackedWidget->addWidget(secondPageWidget);
75
76 QComboBox *pageComboBox = new QComboBox;
77 pageComboBox->addItem(tr("x,y,z"));
78 pageComboBox->addItem(tr("vector name"));
79 connect(pageComboBox, SIGNAL(activated(int)),
80 stackedWidget, SLOT(setCurrentIndex(int)));
81 connect(pageComboBox, SIGNAL(activated(int)),
82 this, SLOT(pageChanged(int)));
83 subLayout->addWidget(pageComboBox);
84 subLayout->addWidget(stackedWidget);
85
86 // first widget with coordinates
87 coordLayout = new QHBoxLayout();
88 coordInputX = new QDoubleSpinBox();
89 coordInputX->setRange(-std::numeric_limits<double>::max(),std::numeric_limits<double>::max());
90 coordInputX->setValue(temporary[0]);
91// coordInputX->setRange(0,M.at(i,i));
92 coordInputX->setDecimals(3);
93 coordLayout->addWidget(coordInputX);
94 coordInputY = new QDoubleSpinBox();
95 coordInputY->setRange(-std::numeric_limits<double>::max(),std::numeric_limits<double>::max());
96 coordInputY->setValue(temporary[1]);
97// coordInputY->setRange(0,M.at(i,i));
98 coordInputY->setDecimals(3);
99 coordLayout->addWidget(coordInputY);
100 coordInputZ = new QDoubleSpinBox();
101 coordInputZ->setRange(-std::numeric_limits<double>::max(),std::numeric_limits<double>::max());
102 coordInputZ->setValue(temporary[2]);
103// coordInputZ->setRange(0,M.at(i,i));
104 coordInputZ->setDecimals(3);
105 coordLayout->addWidget(coordInputZ);
106 connect(coordInputX,SIGNAL(valueChanged(double)),this,SLOT(onUpdateX(double)));
107 connect(coordInputY,SIGNAL(valueChanged(double)),this,SLOT(onUpdateY(double)));
108 connect(coordInputZ,SIGNAL(valueChanged(double)),this,SLOT(onUpdateZ(double)));
109 firstPageWidget->setLayout(coordLayout);
110
111 // second widget with string field
112 nameLayout = new QHBoxLayout();
113 nameComboBox = new QComboBox;
114 GeometryRegistry &reg = GeometryRegistry::getInstance();
115// nameComboBox->setEditable(true);
116 GeometryRegistry::const_iterator iter;
117 for (iter = reg.getBeginIter(); iter != reg.getEndIter(); iter ++){
118 GeometryObject *v = iter->second;
119 nameComboBox->addItem(tr(v->getName().c_str()));
120 nameComboBox->setItemData(nameComboBox->count()-1, tr(toString<Vector>(v->getVector()).c_str()), Qt::ToolTipRole);
121 }
122 connect(nameComboBox, SIGNAL(activated(int)),
123 this, SLOT(onUpdateName(int)));
124 nameLayout->addWidget(nameComboBox);
125 secondPageWidget->setLayout(nameLayout);
126
127 parent->addLayout(mainLayout);
128}
129
130QtDialog::VectorQtQuery::~VectorQtQuery()
131{}
132
133static void updateVectorString(std::string &_temp, const double newDouble, int component)
134{
135 //!> Internal converter from string to internal type
136 Vector vec = Value<Vector>::parseAsVector(_temp);
137 vec[component] = newDouble;
138 _temp = Value<Vector>::setFromVector(vec);
139}
140
141void QtDialog::VectorQtQuery::pageChanged(int pagenr) {
142 if (pagenr == 1) {
143 // change from x,y,z input
144 onUpdateName(nameComboBox->currentIndex());
145 dialog->update();
146 } else if (pagenr == 0) {
147 // change from name input
148 if (GeometryRegistry::getInstance().isPresentByName(temp)) {
149 const GeometryObject * const v = GeometryRegistry::getInstance().getByName(temp);
150 coordInputX->setValue(v->getVector()[0]);
151 coordInputY->setValue(v->getVector()[1]);
152 coordInputZ->setValue(v->getVector()[2]);
153 } else {
154 coordInputX->setValue(0.);
155 coordInputY->setValue(0.);
156 coordInputZ->setValue(0.);
157 }
158 dialog->update();
159 } else {
160 ASSERT(0, "VectorQtQuery::pageChanged() - unknown page for pageComboBox.");
161 }
162}
163
164void QtDialog::VectorQtQuery::onUpdateName(int index) {
165 const QString itemtext = nameComboBox->itemText(index);
166 temp = itemtext.toStdString();
167 QtQuery<Vector>::handle();
168 dialog->update();
169}
170
171void QtDialog::VectorQtQuery::onUpdateX(double newDouble) {
172 updateVectorString(temp, newDouble, 0);
173 QtQuery<Vector>::handle();
174 dialog->update();
175}
176
177void QtDialog::VectorQtQuery::onUpdateY(double newDouble) {
178 updateVectorString(temp, newDouble, 1);
179 QtQuery<Vector>::handle();
180 dialog->update();
181}
182
183void QtDialog::VectorQtQuery::onUpdateZ(double newDouble) {
184 updateVectorString(temp, newDouble, 2);
185 QtQuery<Vector>::handle();
186 dialog->update();
187}
188
189
Note: See TracBrowser for help on using the repository browser.