Changes in src/UIElements/Dialog.hpp [4cf323d:e4afb4]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Dialog.hpp
r4cf323d re4afb4 33 33 * string, but also advanced types such as element, molecule or Vector. There 34 34 * is also an empty query for displaying text. 35 * 36 * Note that the templatization of Dialog::query() allows for easy implementation 37 * of new types that correspond to/are derived from old ones. 38 * 39 * <H3>How do Dialogs operate?</H3> 40 * 41 * Dialogs are initiated by Action::FillDialog() function calls. Within Action::Call() 42 * a dialog is created and passed on to FillDialog(), which is specialized in each 43 * specific Action to ask for the specific parameter it needs. 44 * 45 * Dialogs are derived for each of the UI types 46 * -# CommandLineDialog 47 * -# QtDialog 48 * -# TextDialog 49 * 50 * This "asking" for parameters is done via the Query class. There are four types 51 * of Query types: 52 * -# Query, members in class Dialog 53 * -# CommandLineQuery, members in class CommandLineDialog 54 * -# QtQuery, members in class QtDialog 55 * -# TextQuery, members in class TextDialog 56 * Each embodies a certain way of asking the user for the specific type of parameter 57 * needed, e.g. a file via the TextMenu interface would be done in member functions of 58 * TextDialog::FileTextQuery. 59 * 60 * 61 * Generally, the sequence of events is as follows: 62 * -# Action::fillDialog() calls upon Dialog::query<T> for some type T, let's say T 63 * stands for double 64 * -# Dialog::query<double> call a function queryDouble() 65 * -# depending on the currently used UIFactory, the Dialog above is actually either 66 * of the three specialized types, let's say CommandLine. And we see that within 67 * CommandLineDialog we have the respective method ueryDouble() that registers 68 * a new instance of the class CommandLineDialog::DoubleCommandLineQuery. 69 * -# The Query's are first registered, as multiple parameters may be needed for 70 * a single Action and we don't want the popping up of a dialog window for each 71 * alone. Rather, we want to merge the Query's into a single Dialog. Therefore, 72 * they are first registered and then executed in sequence. This is done in 73 * Dialog::display(), i.e. when the dialog is finally shown to the user. 74 * -# Then each of the registered Query's, here our CommandLineDialog:: 75 * DoubleCommandLineQuery, constructor is called. 76 * -# This will call the constructor of its base class, where the actual value 77 * is stored and later stored into the ValueStorage class by 78 * Dialog::Query::setResult(). 79 * -# Also, e.g. for the Qt interface, the buttons, labels and so forth are 80 * created and added to the dialog. 81 * -# Now the users enters information for each UI something different happens: 82 * -# CommandLine: The actual value retrieval is done by the CommandLineParser and 83 * the boost::program_options library, the value is stored therein for the moment. 84 * (see here: http://www.boost.org/doc/libs/1_44_0/doc/html/program_options/) 85 * -# TextMenu: The value is requested via std::cin from the user. 86 * -# QtMenu: The users enters the value in a Dialog. Due to Qt necessities a 87 * Pipe class obtains the value from the Dialog with Qt's signal/slot mechanism 88 * and put it into Dialog::...Query value. 89 * -# in our case DoubleCommandLineQuery::handle() will be called. The value is 90 * retrieved and put into Dialog::DoubleQuery::tmp 91 * -# Finally, for each Query, also Dialog::DoubleQuery, setResult() is called which 92 * puts the value as a string into the ValueStorage under a given token that is 93 * associated with a type (and thereby we assure type-safety). 94 * 95 * <H3>Regarding derived types of types with already present queries</H3> 96 * 97 * Example: We have got a derived Vector class, called BoxVector, that is by any means 98 * a Vector but with one difference: it is always bound to lie within the current domain. 99 * With regards to type-casting it to and from a string however, nothing is different 100 * between Vector and BoxVector. 101 * 102 * So, do we need a new Query for this? 103 * No. 104 * 105 * We just have to do this: 106 * -# add a specialization of Dialog::query<BoxVector> where queryVector()is used. 107 * @code 108 * template <> void Dialog::query<BoxVector>(const char *token, std::string description) { 109 * queryVector(token, false, description); 110 * } 111 * @endcode 112 * -# make sure that 113 * -# ValueStorage::setCurrentValue() the specialization for class Vector has an 114 * if case also for BoxVector and does something appropriate. 115 * -# ValueStorage::queryCurrentValue() has another specialization doing the same 116 * as for Vector but for BoxVector in its signature. 117 * 118 * And that's all. 119 * 120 * 121 * <H3>Adding new queries</H3> 122 * 123 * Check first whether you really need a new query or whether we can derive it and re-use 124 * one of the present ones. 125 * 126 * Due to the three present UI interfaces we have to add a specific Query for each, here 127 * is a list: 128 * -# add ValueStorage::setCurrentValue() and ValueStorage::queryCurrentValue() for 129 * both types 130 * -# add Dialog::query...() 131 * -# add Dialog::query<>() specialization calling the above function 132 * -# add CommandLineDialog::query...(), TextDialog::query...(), and QtDialog::query...(), 133 * i.e. for each of the three interface 134 * -# add Dialog::...Query class with tmp value of desired type 135 * -# add CommandLineDialog::...Query, TextDialog::...Query, QtDialog::...Query 136 * -# you probably also need a QtDialog::...QueryPipe() to handle the signal/slot stuff, 137 * Qt's moc does not like nested classes. Hence, this has to go extra. 138 * 35 139 */ 36 140 class Dialog … … 210 314 virtual void setResult(); 211 315 protected: 212 molecule *tmp;316 const molecule *tmp; 213 317 }; 214 318 … … 220 324 virtual void setResult(); 221 325 protected: 222 molecule * temp;223 std::vector< molecule *> tmp;326 const molecule * temp; 327 std::vector<const molecule *> tmp; 224 328 }; 225 329 … … 231 335 virtual void setResult(); 232 336 protected: 233 atom *tmp;337 const atom *tmp; 234 338 }; 235 339 … … 241 345 virtual void setResult(); 242 346 protected: 243 atom *temp;244 std::vector< atom *> tmp;347 const atom *temp; 348 std::vector<const atom *> tmp; 245 349 }; 246 350
Note:
See TracChangeset
for help on using the changeset viewer.