1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * ElementQtQuery.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 |
|
---|
24 | #include "CodePatterns/MemDebug.hpp"
|
---|
25 |
|
---|
26 | #include "UIElements/Qt4/Query/QtQuery.hpp"
|
---|
27 | #include "UIElements/Qt4/Pipe/ElementQtQueryPipe.hpp"
|
---|
28 |
|
---|
29 | #include "Element/element.hpp"
|
---|
30 | #include "Element/periodentafel.hpp"
|
---|
31 | #include "World.hpp"
|
---|
32 |
|
---|
33 | QtDialog::ElementQtQuery::ElementQtQuery(Parameter<const element *> &_param, std::string _title, QBoxLayout *_parent, Dialog *_dialog) :
|
---|
34 | Dialog::ElementQuery(_param, _title),
|
---|
35 | parent(_parent),
|
---|
36 | dialog(_dialog)
|
---|
37 | {
|
---|
38 | periodentafel *periode = World::getInstance().getPeriode();
|
---|
39 | thisLayout = new QHBoxLayout();
|
---|
40 | titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
41 | inputBox = new QComboBox();
|
---|
42 | for(periodentafel::const_iterator iter = periode->begin();
|
---|
43 | iter!=periode->end();
|
---|
44 | ++iter)
|
---|
45 | {
|
---|
46 | std::stringstream sstr;
|
---|
47 | sstr << (*iter).first << "\t" << (*iter).second->getName();
|
---|
48 | inputBox->addItem(QString(sstr.str().c_str()),QVariant((*iter).first));
|
---|
49 | }
|
---|
50 | parent->addLayout(thisLayout);
|
---|
51 | thisLayout->addWidget(titleLabel);
|
---|
52 | thisLayout->addWidget(inputBox);
|
---|
53 |
|
---|
54 | connect(inputBox,SIGNAL(currentIndexChanged(int)),this,SLOT(onUpdate(int)));
|
---|
55 | }
|
---|
56 |
|
---|
57 | QtDialog::ElementQtQuery::~ElementQtQuery()
|
---|
58 | {
|
---|
59 | }
|
---|
60 |
|
---|
61 | void QtDialog::ElementQtQuery::onUpdate(int newIndex) {
|
---|
62 | QVariant data = inputBox->itemData(newIndex);
|
---|
63 | int idx = data.toInt();
|
---|
64 | temp = World::getInstance().getPeriode()->FindElement(idx);
|
---|
65 | dialog->update();
|
---|
66 | }
|
---|
67 |
|
---|
68 | bool QtDialog::ElementQtQuery::handle(){
|
---|
69 | if (param.isValid(temp)){
|
---|
70 | param.set(temp);
|
---|
71 | return true;
|
---|
72 | }
|
---|
73 | return false;
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|