[7b8a8e] | 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 |
|
---|
| 20 | class QListWidget;
|
---|
| 21 | class QPushButton;
|
---|
| 22 | class QVBoxLayout;
|
---|
| 23 | class QHBoxLayout;
|
---|
| 24 | class QBoxLayout;
|
---|
| 25 |
|
---|
| 26 | class QtQueryListUntyped {
|
---|
| 27 | public:
|
---|
| 28 | QtQueryListUntyped(QBoxLayout *parent, Dialog *_dialog);
|
---|
| 29 | virtual ~QtQueryListUntyped(){}
|
---|
| 30 |
|
---|
| 31 | virtual void onSubUpdate() = 0;
|
---|
| 32 |
|
---|
| 33 | void onUpdate();
|
---|
| 34 | void elementSelected();
|
---|
| 35 | void addElementToListWidget(const std::string &str);
|
---|
| 36 | std::vector<int> getSelectedRows();
|
---|
| 37 | void removeSelectedRows(const std::vector<int> &rows);
|
---|
| 38 |
|
---|
| 39 | protected:
|
---|
| 40 | QListWidget *inputList;
|
---|
| 41 | QPushButton *addButton;
|
---|
| 42 | QPushButton *removeButton;
|
---|
| 43 | QVBoxLayout *thisVLayout;
|
---|
| 44 | QHBoxLayout *thisHLayout;
|
---|
| 45 | QVBoxLayout *buttonBox;
|
---|
| 46 | Dialog *dialog;
|
---|
| 47 | };
|
---|
| 48 |
|
---|
| 49 | template<class T>
|
---|
| 50 | class QtQueryList : public QtQueryListUntyped {
|
---|
| 51 | public:
|
---|
| 52 | QtQueryList(QBoxLayout *parent, Dialog *_dialog, std::vector<T> &_temp) : QtQueryListUntyped(parent, _dialog), tempRef(_temp)
|
---|
| 53 | {
|
---|
| 54 | subParam = new Parameter<T>("sub-param");
|
---|
| 55 | }
|
---|
| 56 | virtual ~QtQueryList()
|
---|
| 57 | {
|
---|
| 58 | delete(subParam);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | void addElement() {
|
---|
| 62 | // add item to both
|
---|
| 63 | addElementToListWidget(subParam->getAsString());
|
---|
| 64 | tempRef.push_back(subParam->get());
|
---|
| 65 | onUpdate();
|
---|
| 66 | }
|
---|
| 67 | void removeElements()
|
---|
| 68 | {
|
---|
| 69 | std::vector<int> rows = getSelectedRows();
|
---|
| 70 | removeSelectedRows(rows);
|
---|
| 71 | for (int i = rows.size() - 1; i >= 0; i --){
|
---|
| 72 | ASSERT(rows[i] < tempRef.size(), "QtQueryList<T>::removeElements() trying to remove invalid element.");
|
---|
| 73 | tempRef.erase(tempRef.begin() + rows[i]);
|
---|
| 74 | }
|
---|
| 75 | onUpdate();
|
---|
| 76 | }
|
---|
| 77 | protected:
|
---|
| 78 | std::vector<T> &tempRef;
|
---|
| 79 | Parameter<T> *subParam;
|
---|
| 80 | };
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | class ListQuerySubDialog : public Dialog
|
---|
| 85 | {
|
---|
| 86 | public:
|
---|
| 87 | ListQuerySubDialog(QtQueryListUntyped *_parent) : parent(_parent), sub(NULL){}
|
---|
| 88 | virtual void update()
|
---|
| 89 | {
|
---|
| 90 | if (sub)
|
---|
[7e6a1b] | 91 | if (sub->isValid())
|
---|
| 92 | sub->setResult();
|
---|
[7b8a8e] | 93 | parent->onSubUpdate();
|
---|
| 94 | }
|
---|
| 95 | void setSubQuery(Query *_sub){ sub = _sub; }
|
---|
| 96 |
|
---|
| 97 | virtual void queryEmpty(const char*, std::string){}
|
---|
| 98 | virtual void queryBoolean(Parameter<bool> &, const char *, std::string = ""){}
|
---|
| 99 | virtual void queryInt(Parameter<int> &, const char *,std::string = ""){}
|
---|
| 100 | virtual void queryInts(Parameter<std::vector<int> > &, const char *,std::string = ""){}
|
---|
| 101 | virtual void queryUnsignedInt(Parameter<unsigned int> &, const char *,std::string = ""){}
|
---|
| 102 | virtual void queryUnsignedInts(Parameter<std::vector<unsigned int> > &, const char *,std::string = ""){}
|
---|
| 103 | virtual void queryDouble(Parameter<double> &, const char*,std::string = ""){}
|
---|
| 104 | virtual void queryDoubles(Parameter<std::vector<double> > &, const char*,std::string = ""){}
|
---|
| 105 | virtual void queryString(Parameter<std::string> &, const char*,std::string = ""){}
|
---|
| 106 | virtual void queryStrings(Parameter<std::vector<std::string> > &, const char*,std::string = ""){}
|
---|
| 107 | virtual void queryAtom(Parameter<const atom *> &, const char*,std::string = ""){}
|
---|
| 108 | virtual void queryAtoms(Parameter<std::vector<const atom *> > &, const char*,std::string = ""){}
|
---|
| 109 | virtual void queryMolecule(Parameter<const molecule *> &, const char*,std::string = ""){}
|
---|
| 110 | virtual void queryMolecules(Parameter<std::vector<const molecule *> > &, const char*,std::string = ""){}
|
---|
| 111 | virtual void queryVector(Parameter<Vector> &, const char*,std::string = ""){}
|
---|
| 112 | virtual void queryVectors(Parameter<std::vector<Vector> > &, const char*,std::string = ""){}
|
---|
| 113 | virtual void queryRealSpaceMatrix(Parameter<RealSpaceMatrix> &, const char*, std::string = ""){}
|
---|
| 114 | virtual void queryElement(Parameter<const element *> &, const char*,std::string = ""){}
|
---|
| 115 | virtual void queryElements(Parameter<std::vector<const element *> > &, const char*,std::string = ""){}
|
---|
| 116 | virtual void queryFile(Parameter<boost::filesystem::path> &, const char*,std::string = ""){}
|
---|
| 117 | virtual void queryFiles(Parameter<std::vector< boost::filesystem::path> > &, const char*,std::string = ""){}
|
---|
| 118 | virtual void queryRandomNumberDistribution_Parameters(Parameter<RandomNumberDistribution_Parameters> &, const char*,std::string = ""){}
|
---|
| 119 | private:
|
---|
| 120 | QtQueryListUntyped *parent;
|
---|
| 121 | Query *sub;
|
---|
| 122 | };
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 | #endif /* QTQUERYLIST_HPP_ */
|
---|