source: src/UIElements/Qt4/Query/QtQueryList.hpp@ 163110

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 163110 was 163110, checked in by Frederik Heber <heber@…>, 10 years ago

In QTUI Dialog window now has a meaningful title.

  • Dialog cstor now requires a title.
  • UIFactory::makeDialog() needs to be provided with this title.
  • Menu::populateActions() uses addAction with twice just the token.
  • Action::createDialog() provides title from its Traits.
  • Property mode set to 100644
File size: 5.7 KB
Line 
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#include "Parameters/Validators/Ops_Validator_impl.hpp"
21
22class QListWidget;
23class QPushButton;
24class QVBoxLayout;
25class QHBoxLayout;
26class QBoxLayout;
27
28class QtQueryListUntyped {
29public:
30 QtQueryListUntyped(QBoxLayout *parent, Dialog *_dialog);
31 virtual ~QtQueryListUntyped(){}
32
33 virtual void onSubUpdate() = 0;
34
35 void onUpdate();
36 void elementSelected();
37 void addElementToListWidget(const std::string &str);
38 std::vector<int> getSelectedRows();
39 void removeSelectedRows(const std::vector<int> &rows);
40
41protected:
42 QListWidget *inputList;
43 QPushButton *addButton;
44 QPushButton *removeButton;
45 QVBoxLayout *thisVLayout;
46 QHBoxLayout *thisHLayout;
47 QVBoxLayout *buttonBox;
48 Dialog *dialog;
49};
50
51template<class T>
52class QtQueryList : public QtQueryListUntyped {
53public:
54 QtQueryList(Parameter<std::vector<T> > &parentParam, QBoxLayout *parent, Dialog *_dialog, std::vector<T> &_temp) : QtQueryListUntyped(parent, _dialog), tempRef(_temp)
55 {
56 // do we have an STLVectorValidator?
57 Validator<std::vector<T> > *val = &parentParam.getValidator();
58 STLVectorValidator<std::vector<T> > *vector_val = NULL;
59
60 // might be hidden inside an And_Validator
61 And_Validator<std::vector<T> > * and_val = dynamic_cast<And_Validator<std::vector<T> > *>(val);
62 if (and_val){
63 if (dynamic_cast<STLVectorValidator<std::vector<T> > *>(and_val->getA()))
64 vector_val = dynamic_cast<STLVectorValidator<std::vector<T> > *>(and_val->getA());
65 else if (dynamic_cast<STLVectorValidator<std::vector<T> > *>(and_val->getB()))
66 vector_val = dynamic_cast<STLVectorValidator<std::vector<T> > *>(and_val->getB());
67 }else{
68 vector_val = dynamic_cast<STLVectorValidator<std::vector<T> > *>(val);
69 }
70
71 if (vector_val){
72 // if so, try to use its ElementwiseValidator
73 subParam = new Parameter<T>("sub-param", *(vector_val->getElementwiseValidator()));
74 }else{
75 subParam = new Parameter<T>("sub-param");
76 }
77 }
78 virtual ~QtQueryList()
79 {
80 delete(subParam);
81 }
82
83 void addElement() {
84 // add item to both
85 addElementToListWidget(subParam->getAsString());
86 tempRef.push_back(subParam->get());
87 onUpdate();
88 }
89 void removeElements()
90 {
91 std::vector<int> rows = getSelectedRows();
92 removeSelectedRows(rows);
93 for (int i = rows.size() - 1; i >= 0; i --){
94 ASSERT((size_t)(rows[i]) < tempRef.size(), "QtQueryList<T>::removeElements() trying to remove invalid element.");
95 tempRef.erase(tempRef.begin() + rows[i]);
96 }
97 onUpdate();
98 }
99protected:
100 std::vector<T> &tempRef;
101 Parameter<T> *subParam;
102};
103
104
105
106class ListQuerySubDialog : public Dialog
107{
108public:
109 ListQuerySubDialog(QtQueryListUntyped *_parent, const std::string &_title) :
110 Dialog(_title),
111 parent(_parent),
112 sub(NULL)
113 {}
114 virtual void update()
115 {
116 if (sub)
117 if (sub->isValid())
118 sub->setResult();
119 parent->onSubUpdate();
120 }
121 void setSubQuery(Query *_sub){ sub = _sub; }
122
123 virtual void queryEmpty(const std::string = "", const std::string = ""){}
124 virtual void queryBoolean(Parameter<bool> &, const std::string = "", const std::string = ""){}
125 virtual void queryInt(Parameter<int> &, const std::string = "", const std::string = ""){}
126 virtual void queryInts(Parameter<std::vector<int> > &, const std::string = "", const std::string = ""){}
127 virtual void queryUnsignedInt(Parameter<unsigned int> &, const std::string = "", const std::string = ""){}
128 virtual void queryUnsignedInts(Parameter<std::vector<unsigned int> > &, const std::string = "", const std::string = ""){}
129 virtual void queryDouble(Parameter<double> &, const std::string = "", const std::string = ""){}
130 virtual void queryDoubles(Parameter<std::vector<double> > &, const std::string = "", const std::string = ""){}
131 virtual void queryString(Parameter<std::string> &, const std::string = "", const std::string = ""){}
132 virtual void queryStrings(Parameter<std::vector<std::string> > &, const std::string = "", const std::string = ""){}
133 virtual void queryAtom(Parameter<const atom *> &, const std::string = "", const std::string = ""){}
134 virtual void queryAtoms(Parameter<std::vector<const atom *> > &, const std::string = "", const std::string = ""){}
135 virtual void queryMolecule(Parameter<const molecule *> &, const std::string = "", const std::string = ""){}
136 virtual void queryMolecules(Parameter<std::vector<const molecule *> > &, const std::string = "", const std::string = ""){}
137 virtual void queryVector(Parameter<Vector> &, const std::string = "", const std::string = ""){}
138 virtual void queryVectors(Parameter<std::vector<Vector> > &, const std::string = "", const std::string = ""){}
139 virtual void queryRealSpaceMatrix(Parameter<RealSpaceMatrix> &, const std::string = "", const std::string = ""){}
140 virtual void queryElement(Parameter<const element *> &, const std::string = "", const std::string = ""){}
141 virtual void queryElements(Parameter<std::vector<const element *> > &, const std::string = "", const std::string = ""){}
142 virtual void queryFile(Parameter<boost::filesystem::path> &, const std::string = "", const std::string = ""){}
143 virtual void queryFiles(Parameter<std::vector< boost::filesystem::path> > &, const std::string = "", const std::string = ""){}
144 virtual void queryRandomNumberDistribution_Parameters(Parameter<RandomNumberDistribution_Parameters> &, const std::string = "", const std::string = ""){}
145private:
146 QtQueryListUntyped *parent;
147 Query *sub;
148};
149
150
151#endif /* QTQUERYLIST_HPP_ */
Note: See TracBrowser for help on using the repository browser.