1 | /*
|
---|
2 | * QtQueryList.hpp
|
---|
3 | *
|
---|
4 | * Created on: Jul 24, 2012
|
---|
5 | * Author: ankele
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef QTQUERYLIST_HPP_
|
---|
9 | #define QTQUERYLIST_HPP_
|
---|
10 |
|
---|
11 |
|
---|
12 | // include config.h
|
---|
13 | #ifdef HAVE_CONFIG_H
|
---|
14 | #include <config.h>
|
---|
15 | #endif
|
---|
16 |
|
---|
17 | #include "UIElements/Dialog.hpp"
|
---|
18 | #include "Parameters/Parameter.hpp"
|
---|
19 | #include "Parameters/Validators/STLVectorValidator.hpp"
|
---|
20 |
|
---|
21 | class QListWidget;
|
---|
22 | class QPushButton;
|
---|
23 | class QVBoxLayout;
|
---|
24 | class QHBoxLayout;
|
---|
25 | class QBoxLayout;
|
---|
26 |
|
---|
27 | class QtQueryListUntyped {
|
---|
28 | public:
|
---|
29 | QtQueryListUntyped(QBoxLayout *parent, Dialog *_dialog);
|
---|
30 | virtual ~QtQueryListUntyped(){}
|
---|
31 |
|
---|
32 | virtual void onSubUpdate() = 0;
|
---|
33 |
|
---|
34 | void onUpdate();
|
---|
35 | void elementSelected();
|
---|
36 | void addElementToListWidget(const std::string &str);
|
---|
37 | std::vector<int> getSelectedRows();
|
---|
38 | void removeSelectedRows(const std::vector<int> &rows);
|
---|
39 |
|
---|
40 | protected:
|
---|
41 | QListWidget *inputList;
|
---|
42 | QPushButton *addButton;
|
---|
43 | QPushButton *removeButton;
|
---|
44 | QVBoxLayout *thisVLayout;
|
---|
45 | QHBoxLayout *thisHLayout;
|
---|
46 | QVBoxLayout *buttonBox;
|
---|
47 | Dialog *dialog;
|
---|
48 | };
|
---|
49 |
|
---|
50 | template<class T>
|
---|
51 | class QtQueryList : public QtQueryListUntyped {
|
---|
52 | public:
|
---|
53 | QtQueryList(Parameter<std::vector<T> > &parentParam, QBoxLayout *parent, Dialog *_dialog, std::vector<T> &_temp) : QtQueryListUntyped(parent, _dialog), tempRef(_temp)
|
---|
54 | {
|
---|
55 | STLVectorValidator<std::vector<T> > *val = dynamic_cast<STLVectorValidator<std::vector<T> > *>(&parentParam.getValidator());
|
---|
56 |
|
---|
57 | // do we have an STLVectorValidator?
|
---|
58 | if (val){
|
---|
59 | // if so, try to use its ElementwiseValidator
|
---|
60 | subParam = new Parameter<T>("sub-param", *(val->getElementwiseValidator()));
|
---|
61 | }else{
|
---|
62 | subParam = new Parameter<T>("sub-param");
|
---|
63 | }
|
---|
64 | }
|
---|
65 | virtual ~QtQueryList()
|
---|
66 | {
|
---|
67 | delete(subParam);
|
---|
68 | }
|
---|
69 |
|
---|
70 | void addElement() {
|
---|
71 | // add item to both
|
---|
72 | addElementToListWidget(subParam->getAsString());
|
---|
73 | tempRef.push_back(subParam->get());
|
---|
74 | onUpdate();
|
---|
75 | }
|
---|
76 | void removeElements()
|
---|
77 | {
|
---|
78 | std::vector<int> rows = getSelectedRows();
|
---|
79 | removeSelectedRows(rows);
|
---|
80 | for (int i = rows.size() - 1; i >= 0; i --){
|
---|
81 | ASSERT(rows[i] < tempRef.size(), "QtQueryList<T>::removeElements() trying to remove invalid element.");
|
---|
82 | tempRef.erase(tempRef.begin() + rows[i]);
|
---|
83 | }
|
---|
84 | onUpdate();
|
---|
85 | }
|
---|
86 | protected:
|
---|
87 | std::vector<T> &tempRef;
|
---|
88 | Parameter<T> *subParam;
|
---|
89 | };
|
---|
90 |
|
---|
91 |
|
---|
92 |
|
---|
93 | class ListQuerySubDialog : public Dialog
|
---|
94 | {
|
---|
95 | public:
|
---|
96 | ListQuerySubDialog(QtQueryListUntyped *_parent) : parent(_parent), sub(NULL){}
|
---|
97 | virtual void update()
|
---|
98 | {
|
---|
99 | if (sub)
|
---|
100 | if (sub->isValid())
|
---|
101 | sub->setResult();
|
---|
102 | parent->onSubUpdate();
|
---|
103 | }
|
---|
104 | void setSubQuery(Query *_sub){ sub = _sub; }
|
---|
105 |
|
---|
106 | virtual void queryEmpty(const char*, std::string){}
|
---|
107 | virtual void queryBoolean(Parameter<bool> &, const char *, std::string = ""){}
|
---|
108 | virtual void queryInt(Parameter<int> &, const char *,std::string = ""){}
|
---|
109 | virtual void queryInts(Parameter<std::vector<int> > &, const char *,std::string = ""){}
|
---|
110 | virtual void queryUnsignedInt(Parameter<unsigned int> &, const char *,std::string = ""){}
|
---|
111 | virtual void queryUnsignedInts(Parameter<std::vector<unsigned int> > &, const char *,std::string = ""){}
|
---|
112 | virtual void queryDouble(Parameter<double> &, const char*,std::string = ""){}
|
---|
113 | virtual void queryDoubles(Parameter<std::vector<double> > &, const char*,std::string = ""){}
|
---|
114 | virtual void queryString(Parameter<std::string> &, const char*,std::string = ""){}
|
---|
115 | virtual void queryStrings(Parameter<std::vector<std::string> > &, const char*,std::string = ""){}
|
---|
116 | virtual void queryAtom(Parameter<const atom *> &, const char*,std::string = ""){}
|
---|
117 | virtual void queryAtoms(Parameter<std::vector<const atom *> > &, const char*,std::string = ""){}
|
---|
118 | virtual void queryMolecule(Parameter<const molecule *> &, const char*,std::string = ""){}
|
---|
119 | virtual void queryMolecules(Parameter<std::vector<const molecule *> > &, const char*,std::string = ""){}
|
---|
120 | virtual void queryVector(Parameter<Vector> &, const char*,std::string = ""){}
|
---|
121 | virtual void queryVectors(Parameter<std::vector<Vector> > &, const char*,std::string = ""){}
|
---|
122 | virtual void queryRealSpaceMatrix(Parameter<RealSpaceMatrix> &, const char*, std::string = ""){}
|
---|
123 | virtual void queryElement(Parameter<const element *> &, const char*,std::string = ""){}
|
---|
124 | virtual void queryElements(Parameter<std::vector<const element *> > &, const char*,std::string = ""){}
|
---|
125 | virtual void queryFile(Parameter<boost::filesystem::path> &, const char*,std::string = ""){}
|
---|
126 | virtual void queryFiles(Parameter<std::vector< boost::filesystem::path> > &, const char*,std::string = ""){}
|
---|
127 | virtual void queryRandomNumberDistribution_Parameters(Parameter<RandomNumberDistribution_Parameters> &, const char*,std::string = ""){}
|
---|
128 | private:
|
---|
129 | QtQueryListUntyped *parent;
|
---|
130 | Query *sub;
|
---|
131 | };
|
---|
132 |
|
---|
133 |
|
---|
134 | #endif /* QTQUERYLIST_HPP_ */
|
---|