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 | * StringsQtQuery.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/qlabel.h>
|
---|
22 | #include <Qt/qlineedit.h>
|
---|
23 | #include <Qt/qlistwidget.h>
|
---|
24 | #include <Qt/qpushbutton.h>
|
---|
25 |
|
---|
26 | #include "CodePatterns/MemDebug.hpp"
|
---|
27 |
|
---|
28 | #include "UIElements/Qt4/Query/QtQuery.hpp"
|
---|
29 | #include "UIElements/Qt4/Pipe/QtQueryListPipe.hpp"
|
---|
30 |
|
---|
31 |
|
---|
32 | QtDialog::StringsQtQuery::StringsQtQuery(Parameter<std::vector<std::string> > ¶m, std::string _title,QBoxLayout *_parent,QtDialog *_dialog) :
|
---|
33 | Dialog::StringsQuery(param, _title),
|
---|
34 | parent(_parent)
|
---|
35 | {
|
---|
36 | QHBoxLayout * thisHLayout = new QHBoxLayout();
|
---|
37 | QVBoxLayout * thisV1Layout = new QVBoxLayout();
|
---|
38 | QVBoxLayout * thisV2Layout = new QVBoxLayout();
|
---|
39 |
|
---|
40 | QLabel *titleLabel = new QLabel(QString(getTitle().c_str()));
|
---|
41 | QLabel *inputLabel = new QLabel("Enter to add");
|
---|
42 | QListWidget* inputList = new QListWidget();
|
---|
43 | inputList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
44 | QLineEdit* inputBox = new QLineEdit();
|
---|
45 | inputLabel->setBuddy(inputBox);
|
---|
46 | titleLabel->setBuddy(inputList);
|
---|
47 | QPushButton* AddButton = new QPushButton("Add");
|
---|
48 | AddButton->setEnabled(false);
|
---|
49 | QPushButton* RemoveButton = new QPushButton("Remove");
|
---|
50 | RemoveButton->setEnabled(false);
|
---|
51 |
|
---|
52 | thisV1Layout->addWidget(titleLabel);
|
---|
53 | thisV1Layout->addWidget(inputList);
|
---|
54 | thisV2Layout->addWidget(inputLabel);
|
---|
55 | thisV2Layout->addWidget(inputBox);
|
---|
56 | thisV2Layout->addWidget(AddButton);
|
---|
57 | thisV2Layout->addWidget(RemoveButton);
|
---|
58 | parent->addLayout(thisHLayout);
|
---|
59 | thisHLayout->addLayout(thisV1Layout);
|
---|
60 | thisHLayout->addLayout(thisV2Layout);
|
---|
61 |
|
---|
62 | pipe = new QtQueryListPipe<std::string>(tmp,_dialog,inputBox,inputList,AddButton,RemoveButton);
|
---|
63 | connect(inputBox,SIGNAL(textChanged(const QString&)),pipe,SLOT(IntegerEntered(const QString&)));
|
---|
64 | connect(inputList,SIGNAL(itemSelectionChanged()),pipe,SLOT(IntegerSelected()));
|
---|
65 | connect(AddButton,SIGNAL(Clicked()),pipe,SLOT(AddValue()));
|
---|
66 | connect(RemoveButton,SIGNAL(Clicked()),pipe,SLOT(RemoveRow()));}
|
---|
67 |
|
---|
68 | QtDialog::StringsQtQuery::~StringsQtQuery()
|
---|
69 | {
|
---|
70 | delete pipe;
|
---|
71 | }
|
---|
72 |
|
---|
73 | // All values besides the empty std::string are valid
|
---|
74 | bool QtDialog::StringsQtQuery::handle()
|
---|
75 | {
|
---|
76 | // dissect by ","
|
---|
77 | std::string::iterator olditer = temp.begin();
|
---|
78 | std::vector<std::string> temp_strings;
|
---|
79 | for(std::string::iterator iter = temp.begin(); iter != temp.end(); ++iter) {
|
---|
80 | if (*iter == ' ') {
|
---|
81 | temp_strings.push_back(std::string(iter, olditer));
|
---|
82 | olditer = iter;
|
---|
83 | }
|
---|
84 | }
|
---|
85 | if (olditer != temp.begin()) // insert last part also
|
---|
86 | temp_strings.push_back(std::string(olditer, temp.end()));
|
---|
87 | tmp.set(temp_strings);
|
---|
88 |
|
---|
89 | return temp!="";
|
---|
90 | }
|
---|
91 |
|
---|