[8df74d] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[94d5ac6] | 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/>.
|
---|
[8df74d] | 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>
|
---|
[f79d65] | 39 | #include <Qt/qstackedwidget.h>
|
---|
[8df74d] | 40 |
|
---|
[9eb71b3] | 41 | //#include "CodePatterns/MemDebug.hpp"
|
---|
[8df74d] | 42 |
|
---|
[308aa4] | 43 | #include "UIElements/Qt4/Query/QtQuery.hpp"
|
---|
[8df74d] | 44 |
|
---|
[f79d65] | 45 | #include "CodePatterns/toString.hpp"
|
---|
| 46 |
|
---|
| 47 | #include "Geometry/GeometryRegistry.hpp"
|
---|
| 48 | #include "Parameters/Specifics/Value_vector.hpp"
|
---|
[8df74d] | 49 |
|
---|
[f130d4] | 50 | QtDialog::VectorQtQuery::VectorQtQuery(Parameter<Vector> &_param, const std::string &_title, const std::string &_description, QBoxLayout *_parent,Dialog *_dialog) :
|
---|
| 51 | QtQuery<Vector>(_param, _title, _description),
|
---|
[7c9921] | 52 | parent(_parent),
|
---|
| 53 | dialog(_dialog)
|
---|
[8df74d] | 54 | {
|
---|
[f79d65] | 55 | Vector temporary(0, 0, 0);
|
---|
| 56 | temp = "0, 0, 0";
|
---|
| 57 | if (param.isSet()) {
|
---|
| 58 | temporary = param.get();
|
---|
| 59 | temp = param.getAsString();
|
---|
| 60 | }
|
---|
[8df74d] | 61 | mainLayout= new QHBoxLayout();
|
---|
| 62 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
[f130d4] | 63 | titleLabel->setToolTip(QString(getDescription().c_str()));
|
---|
[8df74d] | 64 | mainLayout->addWidget(titleLabel);
|
---|
[f79d65] | 65 | subLayout = new QHBoxLayout();
|
---|
[8df74d] | 66 | mainLayout->addLayout(subLayout);
|
---|
[a2a2f7] | 67 | // QComboBox* inputBox = new QComboBox();
|
---|
[f79d65] | 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
|
---|
[8df74d] | 87 | coordLayout = new QHBoxLayout();
|
---|
[a14fe3] | 88 | coordInputX = new QDoubleSpinBox();
|
---|
[6e6b90] | 89 | coordInputX->setRange(-std::numeric_limits<double>::max(),std::numeric_limits<double>::max());
|
---|
[f79d65] | 90 | coordInputX->setValue(temporary[0]);
|
---|
[a14fe3] | 91 | // coordInputX->setRange(0,M.at(i,i));
|
---|
| 92 | coordInputX->setDecimals(3);
|
---|
| 93 | coordLayout->addWidget(coordInputX);
|
---|
| 94 | coordInputY = new QDoubleSpinBox();
|
---|
[6e6b90] | 95 | coordInputY->setRange(-std::numeric_limits<double>::max(),std::numeric_limits<double>::max());
|
---|
[f79d65] | 96 | coordInputY->setValue(temporary[1]);
|
---|
[a14fe3] | 97 | // coordInputY->setRange(0,M.at(i,i));
|
---|
| 98 | coordInputY->setDecimals(3);
|
---|
| 99 | coordLayout->addWidget(coordInputY);
|
---|
| 100 | coordInputZ = new QDoubleSpinBox();
|
---|
[6e6b90] | 101 | coordInputZ->setRange(-std::numeric_limits<double>::max(),std::numeric_limits<double>::max());
|
---|
[f79d65] | 102 | coordInputZ->setValue(temporary[2]);
|
---|
[a14fe3] | 103 | // coordInputZ->setRange(0,M.at(i,i));
|
---|
| 104 | coordInputZ->setDecimals(3);
|
---|
| 105 | coordLayout->addWidget(coordInputZ);
|
---|
[7c9921] | 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)));
|
---|
[f79d65] | 109 | firstPageWidget->setLayout(coordLayout);
|
---|
| 110 |
|
---|
| 111 | // second widget with string field
|
---|
| 112 | nameLayout = new QHBoxLayout();
|
---|
| 113 | nameComboBox = new QComboBox;
|
---|
| 114 | GeometryRegistry ® = 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 |
|
---|
[8df74d] | 127 | parent->addLayout(mainLayout);
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | QtDialog::VectorQtQuery::~VectorQtQuery()
|
---|
| 131 | {}
|
---|
| 132 |
|
---|
[f79d65] | 133 | static 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 |
|
---|
| 141 | void 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 |
|
---|
| 164 | void QtDialog::VectorQtQuery::onUpdateName(int index) {
|
---|
| 165 | const QString itemtext = nameComboBox->itemText(index);
|
---|
| 166 | temp = itemtext.toStdString();
|
---|
[f4b6bc9] | 167 | QtQuery<Vector>::handle();
|
---|
[f79d65] | 168 | dialog->update();
|
---|
| 169 | }
|
---|
| 170 |
|
---|
[7c9921] | 171 | void QtDialog::VectorQtQuery::onUpdateX(double newDouble) {
|
---|
[f79d65] | 172 | updateVectorString(temp, newDouble, 0);
|
---|
[f4b6bc9] | 173 | QtQuery<Vector>::handle();
|
---|
[7c9921] | 174 | dialog->update();
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | void QtDialog::VectorQtQuery::onUpdateY(double newDouble) {
|
---|
[f79d65] | 178 | updateVectorString(temp, newDouble, 1);
|
---|
[f4b6bc9] | 179 | QtQuery<Vector>::handle();
|
---|
[7c9921] | 180 | dialog->update();
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | void QtDialog::VectorQtQuery::onUpdateZ(double newDouble) {
|
---|
[f79d65] | 184 | updateVectorString(temp, newDouble, 2);
|
---|
[f4b6bc9] | 185 | QtQuery<Vector>::handle();
|
---|
[7c9921] | 186 | dialog->update();
|
---|
| 187 | }
|
---|
| 188 |
|
---|
[8df74d] | 189 |
|
---|