[8df74d] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[8df74d] | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
| 9 | * MoleculeQtQuery.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: Oct 25, 2010
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
| 20 | #include <Qt/qboxlayout.h>
|
---|
| 21 | #include <Qt/qcombobox.h>
|
---|
| 22 | #include <Qt/qlabel.h>
|
---|
| 23 |
|
---|
[ad011c] | 24 | #include "CodePatterns/MemDebug.hpp"
|
---|
[8df74d] | 25 |
|
---|
[308aa4] | 26 | #include "UIElements/Qt4/Query/QtQuery.hpp"
|
---|
[8df74d] | 27 |
|
---|
| 28 | #include "molecule.hpp"
|
---|
| 29 | #include "World.hpp"
|
---|
| 30 |
|
---|
| 31 |
|
---|
[7dfd07] | 32 | QtDialog::MoleculeQtQuery::MoleculeQtQuery(Parameter<const molecule *> &_param, std::string _title, QBoxLayout *_parent,Dialog *_dialog) :
|
---|
[b3a54d] | 33 | Dialog::MoleculeQuery(_param, _title),
|
---|
[7c9921] | 34 | parent(_parent),
|
---|
| 35 | dialog(_dialog)
|
---|
[8df74d] | 36 | {
|
---|
| 37 | thisLayout = new QHBoxLayout();
|
---|
| 38 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
| 39 | inputBox = new QComboBox();
|
---|
| 40 | // add all molecules to the combo box
|
---|
| 41 | vector<molecule*> molecules = World::getInstance().getAllMolecules();
|
---|
| 42 | for(vector<molecule*>::iterator iter = molecules.begin();
|
---|
| 43 | iter != molecules.end();
|
---|
| 44 | ++iter) {
|
---|
| 45 | std::stringstream sstr;
|
---|
| 46 | sstr << (*iter)->IndexNr << "\t" << (*iter)->getName();
|
---|
| 47 | inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter)->IndexNr));
|
---|
| 48 | }
|
---|
| 49 | parent->addLayout(thisLayout);
|
---|
| 50 | thisLayout->addWidget(titleLabel);
|
---|
| 51 | thisLayout->addWidget(inputBox);
|
---|
| 52 |
|
---|
[7c9921] | 53 | connect(inputBox,SIGNAL(currentIndexChanged(int)),this,SLOT(onUpdate(int)));
|
---|
[8df74d] | 54 | }
|
---|
| 55 |
|
---|
| 56 | QtDialog::MoleculeQtQuery::~MoleculeQtQuery()
|
---|
| 57 | {
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[7c9921] | 60 | void QtDialog::MoleculeQtQuery::onUpdate(int newIndex) {
|
---|
| 61 | QVariant data = inputBox->itemData(newIndex);
|
---|
| 62 | int idx = data.toInt();
|
---|
| 63 | temp = World::getInstance().getMolecule(MoleculeById(idx));
|
---|
| 64 | dialog->update();
|
---|
| 65 | }
|
---|
| 66 |
|
---|
[8df74d] | 67 | // Handling is easy, since the GUI makes it impossible to select invalid values
|
---|
| 68 | bool QtDialog::MoleculeQtQuery::handle()
|
---|
| 69 | {
|
---|
[9d5531] | 70 | if (param.isValid(temp)){
|
---|
| 71 | param.set(temp);
|
---|
| 72 | return true;
|
---|
| 73 | }
|
---|
| 74 | return false;
|
---|
[8df74d] | 75 | }
|
---|
| 76 |
|
---|