source: src/UIElements/Qt4/Query/QtQueryList.hpp@ 713a43

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 713a43 was 713a43, checked in by Frederik Heber <heber@…>, 12 years ago

QtQueryList can use STLVectorValidator's ElementwiseValidator

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[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"
[713a43]19#include "Parameters/Validators/STLVectorValidator.hpp"
[7b8a8e]20
21class QListWidget;
22class QPushButton;
23class QVBoxLayout;
24class QHBoxLayout;
25class QBoxLayout;
26
27class QtQueryListUntyped {
28public:
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
40protected:
41 QListWidget *inputList;
42 QPushButton *addButton;
43 QPushButton *removeButton;
44 QVBoxLayout *thisVLayout;
45 QHBoxLayout *thisHLayout;
46 QVBoxLayout *buttonBox;
47 Dialog *dialog;
48};
49
50template<class T>
51class QtQueryList : public QtQueryListUntyped {
52public:
[713a43]53 QtQueryList(Parameter<std::vector<T> > &parentParam, QBoxLayout *parent, Dialog *_dialog, std::vector<T> &_temp) : QtQueryListUntyped(parent, _dialog), tempRef(_temp)
[7b8a8e]54 {
[713a43]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 }
[7b8a8e]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 }
86protected:
87 std::vector<T> &tempRef;
88 Parameter<T> *subParam;
89};
90
91
92
93class ListQuerySubDialog : public Dialog
94{
95public:
96 ListQuerySubDialog(QtQueryListUntyped *_parent) : parent(_parent), sub(NULL){}
97 virtual void update()
98 {
99 if (sub)
[7e6a1b]100 if (sub->isValid())
101 sub->setResult();
[7b8a8e]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 = ""){}
128private:
129 QtQueryListUntyped *parent;
130 Query *sub;
131};
132
133
134#endif /* QTQUERYLIST_HPP_ */
Note: See TracBrowser for help on using the repository browser.