/* * QtQueryList.hpp * * Created on: Jul 24, 2012 * Author: ankele */ #ifndef QTQUERYLIST_HPP_ #define QTQUERYLIST_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "UIElements/Dialog.hpp" #include "Parameters/Parameter.hpp" #include "Parameters/Validators/STLVectorValidator.hpp" #include "Parameters/Validators/Ops_Validator_impl.hpp" class QListWidget; class QPushButton; class QVBoxLayout; class QHBoxLayout; class QBoxLayout; class QtQueryListUntyped { public: QtQueryListUntyped(QBoxLayout *parent, Dialog *_dialog); virtual ~QtQueryListUntyped(){} virtual void onSubUpdate() = 0; void onUpdate(); void elementSelected(); void addElementToListWidget(const std::string &str); std::vector getSelectedRows(); void removeSelectedRows(const std::vector &rows); protected: QListWidget *inputList; QPushButton *addButton; QPushButton *removeButton; QVBoxLayout *thisVLayout; QHBoxLayout *thisHLayout; QVBoxLayout *buttonBox; Dialog *dialog; }; template class QtQueryList : public QtQueryListUntyped { public: QtQueryList(Parameter > &parentParam, QBoxLayout *parent, Dialog *_dialog, std::vector &_temp) : QtQueryListUntyped(parent, _dialog), tempRef(_temp) { // do we have an STLVectorValidator? Validator > *val = &parentParam.getValidator(); STLVectorValidator > *vector_val = NULL; // might be hidden inside an And_Validator And_Validator > * and_val = dynamic_cast > *>(val); if (and_val){ if (dynamic_cast > *>(and_val->getA())) vector_val = dynamic_cast > *>(and_val->getA()); else if (dynamic_cast > *>(and_val->getB())) vector_val = dynamic_cast > *>(and_val->getB()); }else{ vector_val = dynamic_cast > *>(val); } if (vector_val){ // if so, try to use its ElementwiseValidator subParam = new Parameter("sub-param", *(vector_val->getElementwiseValidator())); }else{ subParam = new Parameter("sub-param"); } } virtual ~QtQueryList() { delete(subParam); } void addElement() { // add item to both addElementToListWidget(subParam->getAsString()); tempRef.push_back(subParam->get()); onUpdate(); } void removeElements() { std::vector rows = getSelectedRows(); removeSelectedRows(rows); for (int i = rows.size() - 1; i >= 0; i --){ ASSERT((size_t)(rows[i]) < tempRef.size(), "QtQueryList::removeElements() trying to remove invalid element."); tempRef.erase(tempRef.begin() + rows[i]); } onUpdate(); } protected: std::vector &tempRef; Parameter *subParam; }; class ListQuerySubDialog : public Dialog { public: ListQuerySubDialog(QtQueryListUntyped *_parent, const std::string &_title) : Dialog(_title), parent(_parent), sub(NULL) {} virtual void update() { if (sub) if (sub->isValid()) sub->setResult(); parent->onSubUpdate(); } void setSubQuery(Query *_sub){ sub = _sub; } virtual void queryEmpty(const std::string = "", const std::string = ""){} virtual void queryBoolean(Parameter &, const std::string = "", const std::string = ""){} virtual void queryInt(Parameter &, const std::string = "", const std::string = ""){} virtual void queryInts(Parameter > &, const std::string = "", const std::string = ""){} virtual void queryUnsignedInt(Parameter &, const std::string = "", const std::string = ""){} virtual void queryUnsignedInts(Parameter > &, const std::string = "", const std::string = ""){} virtual void queryDouble(Parameter &, const std::string = "", const std::string = ""){} virtual void queryDoubles(Parameter > &, const std::string = "", const std::string = ""){} virtual void queryString(Parameter &, const std::string = "", const std::string = ""){} virtual void queryStrings(Parameter > &, const std::string = "", const std::string = ""){} virtual void queryAtom(Parameter &, const std::string = "", const std::string = ""){} virtual void queryAtoms(Parameter > &, const std::string = "", const std::string = ""){} virtual void queryMolecule(Parameter &, const std::string = "", const std::string = ""){} virtual void queryMolecules(Parameter > &, const std::string = "", const std::string = ""){} virtual void queryVector(Parameter &, const std::string = "", const std::string = ""){} virtual void queryVectors(Parameter > &, const std::string = "", const std::string = ""){} virtual void queryRealSpaceMatrix(Parameter &, const std::string = "", const std::string = ""){} virtual void queryElement(Parameter &, const std::string = "", const std::string = ""){} virtual void queryElements(Parameter > &, const std::string = "", const std::string = ""){} virtual void queryFile(Parameter &, const std::string = "", const std::string = ""){} virtual void queryFiles(Parameter > &, const std::string = "", const std::string = ""){} virtual void queryRandomNumberDistribution_Parameters(Parameter &, const std::string = "", const std::string = ""){} private: QtQueryListUntyped *parent; Query *sub; }; #endif /* QTQUERYLIST_HPP_ */