| 1 | /* | 
|---|
| 2 | * QtQuery.hpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: Nov 8, 2010 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef QTQUERY_HPP_ | 
|---|
| 9 | #define QTQUERY_HPP_ | 
|---|
| 10 |  | 
|---|
| 11 | // include config.h | 
|---|
| 12 | #ifdef HAVE_CONFIG_H | 
|---|
| 13 | #include <config.h> | 
|---|
| 14 | #endif | 
|---|
| 15 |  | 
|---|
| 16 |  | 
|---|
| 17 | #include <Qt/qwidget.h> | 
|---|
| 18 | #include "Qt4/QtDialog.hpp" | 
|---|
| 19 | #include "Parameters/Parameter.hpp" | 
|---|
| 20 | #include "QtQueryList.hpp" | 
|---|
| 21 |  | 
|---|
| 22 | class QHBoxLayout; | 
|---|
| 23 | class QBoxLayout; | 
|---|
| 24 | class QDialogButtonBox; | 
|---|
| 25 | class QLabel; | 
|---|
| 26 | class QSpinBox; | 
|---|
| 27 | class QDoubleSpinBox; | 
|---|
| 28 | class QLineEdit; | 
|---|
| 29 | class QListWidget; | 
|---|
| 30 | class QPushButton; | 
|---|
| 31 | class QTableWidget; | 
|---|
| 32 | class QTextEdit; | 
|---|
| 33 | class QComboBox; | 
|---|
| 34 | class QCheckBox; | 
|---|
| 35 | class QFileDialog; | 
|---|
| 36 |  | 
|---|
| 37 | template<class T> | 
|---|
| 38 | class QtQuery : public Dialog::TQuery<T> | 
|---|
| 39 | { | 
|---|
| 40 | public: | 
|---|
| 41 | QtQuery(Parameter<T> &_param, std::string title, std::string _description = "") : | 
|---|
| 42 | Dialog::TQuery<T>(_param, title, _description) {} | 
|---|
| 43 | // QtQueries are interactive - no need for handle(). | 
|---|
| 44 | virtual bool handle(){  return true;  } | 
|---|
| 45 | }; | 
|---|
| 46 |  | 
|---|
| 47 | class QtDialog::AtomQtQuery : public QWidget, public QtQuery<const atom *> { | 
|---|
| 48 | Q_OBJECT | 
|---|
| 49 | public: | 
|---|
| 50 | AtomQtQuery(Parameter<const atom *> &, std::string _title, QBoxLayout *_parent,Dialog *_dialog); | 
|---|
| 51 | virtual ~AtomQtQuery(); | 
|---|
| 52 |  | 
|---|
| 53 | public slots: | 
|---|
| 54 | void onUpdate(int); | 
|---|
| 55 |  | 
|---|
| 56 | private: | 
|---|
| 57 | QBoxLayout *parent; | 
|---|
| 58 | QBoxLayout *thisLayout; | 
|---|
| 59 | QLabel *titleLabel; | 
|---|
| 60 | QComboBox *inputBox; | 
|---|
| 61 | Dialog *dialog; | 
|---|
| 62 | }; | 
|---|
| 63 |  | 
|---|
| 64 | class QtDialog::AtomsQtQuery : public QWidget, public QtQuery<std::vector<const atom *> >, public QtQueryList<const atom *> { | 
|---|
| 65 | Q_OBJECT | 
|---|
| 66 | public: | 
|---|
| 67 | AtomsQtQuery(Parameter<std::vector<const atom *> > &, std::string _title, QBoxLayout *_parent,Dialog *_dialog); | 
|---|
| 68 | virtual ~AtomsQtQuery(); | 
|---|
| 69 |  | 
|---|
| 70 | virtual void onSubUpdate(); | 
|---|
| 71 |  | 
|---|
| 72 | public slots: | 
|---|
| 73 | void onAddElement(); | 
|---|
| 74 | void onRemoveElement(); | 
|---|
| 75 | void onElementSelected(); | 
|---|
| 76 |  | 
|---|
| 77 | private: | 
|---|
| 78 | AtomQtQuery *subQuery; | 
|---|
| 79 | }; | 
|---|
| 80 |  | 
|---|
| 81 | class QtDialog::BooleanQtQuery : public QWidget, public QtQuery<bool> { | 
|---|
| 82 | Q_OBJECT | 
|---|
| 83 | public: | 
|---|
| 84 | BooleanQtQuery(Parameter<bool> &, std::string _title, QBoxLayout *_parent, Dialog *_dialog); | 
|---|
| 85 | virtual ~BooleanQtQuery(); | 
|---|
| 86 |  | 
|---|
| 87 | public slots: | 
|---|
| 88 | void onUpdate(int); | 
|---|
| 89 |  | 
|---|
| 90 | private: | 
|---|
| 91 | QBoxLayout *parent; | 
|---|
| 92 | QBoxLayout *thisLayout; | 
|---|
| 93 | QLabel *titleLabel; | 
|---|
| 94 | QCheckBox *booleanCheckBox; | 
|---|
| 95 | Dialog *dialog; | 
|---|
| 96 | }; | 
|---|
| 97 |  | 
|---|
| 98 | class QtDialog::RealSpaceMatrixQtQuery : public QWidget, public QtQuery<RealSpaceMatrix> { | 
|---|
| 99 | Q_OBJECT | 
|---|
| 100 | public: | 
|---|
| 101 | RealSpaceMatrixQtQuery(Parameter<RealSpaceMatrix> &, std::string _title, QBoxLayout *_parent,Dialog *_dialog); | 
|---|
| 102 | virtual ~RealSpaceMatrixQtQuery(); | 
|---|
| 103 |  | 
|---|
| 104 | public slots: | 
|---|
| 105 | void onUpdate(int, int); | 
|---|
| 106 |  | 
|---|
| 107 | private: | 
|---|
| 108 | QBoxLayout *parent; | 
|---|
| 109 | QBoxLayout *thisLayout; | 
|---|
| 110 | QLabel *titleLabel; | 
|---|
| 111 | QTableWidget *inputTable; | 
|---|
| 112 | Dialog *dialog; | 
|---|
| 113 | }; | 
|---|
| 114 |  | 
|---|
| 115 | class QtDialog::DoubleQtQuery : public QWidget, public QtQuery<double> { | 
|---|
| 116 | Q_OBJECT | 
|---|
| 117 | public: | 
|---|
| 118 | DoubleQtQuery(Parameter<double> &, std::string title,QBoxLayout *_parent,Dialog *_dialog); | 
|---|
| 119 | virtual ~DoubleQtQuery(); | 
|---|
| 120 |  | 
|---|
| 121 | public slots: | 
|---|
| 122 | void onUpdate(double); | 
|---|
| 123 |  | 
|---|
| 124 | private: | 
|---|
| 125 | QBoxLayout *parent; | 
|---|
| 126 | QBoxLayout *thisLayout; | 
|---|
| 127 | QLabel *titleLabel; | 
|---|
| 128 | QDoubleSpinBox *inputBox; | 
|---|
| 129 | Dialog *dialog; | 
|---|
| 130 | }; | 
|---|
| 131 |  | 
|---|
| 132 | class QtDialog::DoublesQtQuery : public QWidget, public QtQuery<std::vector<double> >, public QtQueryList<double> { | 
|---|
| 133 | Q_OBJECT | 
|---|
| 134 | public: | 
|---|
| 135 | DoublesQtQuery(Parameter<std::vector<double> > &, std::string _title, QBoxLayout *_parent,Dialog *_dialog); | 
|---|
| 136 | virtual ~DoublesQtQuery(); | 
|---|
| 137 |  | 
|---|
| 138 | virtual void onSubUpdate(); | 
|---|
| 139 |  | 
|---|
| 140 | public slots: | 
|---|
| 141 | void onAddElement(); | 
|---|
| 142 | void onRemoveElement(); | 
|---|
| 143 | void onElementSelected(); | 
|---|
| 144 |  | 
|---|
| 145 | private: | 
|---|
| 146 | DoubleQtQuery *subQuery; | 
|---|
| 147 | }; | 
|---|
| 148 |  | 
|---|
| 149 | class QtDialog::ElementQtQuery : public QWidget, public QtQuery<const element *> { | 
|---|
| 150 | Q_OBJECT | 
|---|
| 151 | public: | 
|---|
| 152 | ElementQtQuery(Parameter<const element *> &, std::string _title, QBoxLayout *_parent, Dialog *_dialog); | 
|---|
| 153 | virtual ~ElementQtQuery(); | 
|---|
| 154 |  | 
|---|
| 155 | public slots: | 
|---|
| 156 | void onUpdate(int); | 
|---|
| 157 |  | 
|---|
| 158 | private: | 
|---|
| 159 | QBoxLayout *parent; | 
|---|
| 160 | QBoxLayout *thisLayout; | 
|---|
| 161 | QLabel *titleLabel; | 
|---|
| 162 | QComboBox *inputBox; | 
|---|
| 163 | Dialog *dialog; | 
|---|
| 164 | }; | 
|---|
| 165 |  | 
|---|
| 166 | class QtDialog::ElementsQtQuery : public QWidget, public QtQuery<std::vector<const element *> >, public QtQueryList<const element *> { | 
|---|
| 167 | Q_OBJECT | 
|---|
| 168 | public: | 
|---|
| 169 | ElementsQtQuery(Parameter<std::vector<const element *> > &, std::string _title, QBoxLayout *_parent,Dialog *_dialog); | 
|---|
| 170 | virtual ~ElementsQtQuery(); | 
|---|
| 171 |  | 
|---|
| 172 | virtual void onSubUpdate(); | 
|---|
| 173 |  | 
|---|
| 174 | public slots: | 
|---|
| 175 | void onAddElement(); | 
|---|
| 176 | void onRemoveElement(); | 
|---|
| 177 | void onElementSelected(); | 
|---|
| 178 |  | 
|---|
| 179 | private: | 
|---|
| 180 | ElementQtQuery *subQuery; | 
|---|
| 181 | }; | 
|---|
| 182 |  | 
|---|
| 183 | class QtDialog::EmptyQtQuery : public Dialog::EmptyQuery { | 
|---|
| 184 | public: | 
|---|
| 185 | EmptyQtQuery(std::string _title, QBoxLayout *_parent, Dialog *_dialog); | 
|---|
| 186 | virtual ~EmptyQtQuery(); | 
|---|
| 187 | virtual bool handle(); | 
|---|
| 188 | private: | 
|---|
| 189 | QBoxLayout *parent; | 
|---|
| 190 | QBoxLayout *thisLayout; | 
|---|
| 191 | QLabel *titleLabel; | 
|---|
| 192 | Dialog *dialog; | 
|---|
| 193 | }; | 
|---|
| 194 |  | 
|---|
| 195 | class QtDialog::FileQtQuery : public QWidget, public QtQuery<boost::filesystem::path> { | 
|---|
| 196 | Q_OBJECT | 
|---|
| 197 | public: | 
|---|
| 198 | FileQtQuery(Parameter<boost::filesystem::path> &, std::string _title, QBoxLayout *_parent, Dialog *_dialog); | 
|---|
| 199 | virtual ~FileQtQuery(); | 
|---|
| 200 |  | 
|---|
| 201 | public slots: | 
|---|
| 202 | void onUpdate(); | 
|---|
| 203 | void showFileDialog(); | 
|---|
| 204 |  | 
|---|
| 205 | private: | 
|---|
| 206 | QBoxLayout *parent; | 
|---|
| 207 | QBoxLayout *thisLayout; | 
|---|
| 208 | QLabel *filenameLabel; | 
|---|
| 209 | QLineEdit *filenameLineEdit; | 
|---|
| 210 | QPushButton *filedialogButton; | 
|---|
| 211 | QFileDialog *theFileDialog; | 
|---|
| 212 | Dialog *dialog; | 
|---|
| 213 | }; | 
|---|
| 214 |  | 
|---|
| 215 | class QtDialog::FilesQtQuery : public QWidget, public QtQuery<std::vector<boost::filesystem::path> >, public QtQueryList<boost::filesystem::path> { | 
|---|
| 216 | Q_OBJECT | 
|---|
| 217 | public: | 
|---|
| 218 | FilesQtQuery(Parameter<std::vector<boost::filesystem::path> > &, std::string _title, QBoxLayout *_parent,Dialog *_dialog); | 
|---|
| 219 | virtual ~FilesQtQuery(); | 
|---|
| 220 |  | 
|---|
| 221 | virtual void onSubUpdate(); | 
|---|
| 222 |  | 
|---|
| 223 | public slots: | 
|---|
| 224 | void onAddElement(); | 
|---|
| 225 | void onRemoveElement(); | 
|---|
| 226 | void onElementSelected(); | 
|---|
| 227 |  | 
|---|
| 228 | private: | 
|---|
| 229 | FileQtQuery *subQuery; | 
|---|
| 230 | }; | 
|---|
| 231 |  | 
|---|
| 232 | class QtDialog::IntQtQuery : public QWidget, public QtQuery<int> { | 
|---|
| 233 | Q_OBJECT | 
|---|
| 234 | public: | 
|---|
| 235 | IntQtQuery(Parameter<int> &, std::string _title,QBoxLayout *_parent,Dialog *_dialog); | 
|---|
| 236 | virtual ~IntQtQuery(); | 
|---|
| 237 |  | 
|---|
| 238 | public slots: | 
|---|
| 239 | void onUpdate(int); | 
|---|
| 240 |  | 
|---|
| 241 | private: | 
|---|
| 242 | QBoxLayout *parent; | 
|---|
| 243 | QBoxLayout *thisLayout; | 
|---|
| 244 | QLabel *titleLabel; | 
|---|
| 245 | QSpinBox *inputBox; | 
|---|
| 246 | Dialog *dialog; | 
|---|
| 247 | }; | 
|---|
| 248 |  | 
|---|
| 249 | class QtDialog::IntsQtQuery : public QWidget, public QtQuery<std::vector<int> >, public QtQueryList<int> { | 
|---|
| 250 | Q_OBJECT | 
|---|
| 251 | public: | 
|---|
| 252 | IntsQtQuery(Parameter<std::vector<int> > &, std::string _title, QBoxLayout *_parent,Dialog *_dialog); | 
|---|
| 253 | virtual ~IntsQtQuery(); | 
|---|
| 254 |  | 
|---|
| 255 | virtual void onSubUpdate(); | 
|---|
| 256 |  | 
|---|
| 257 | public slots: | 
|---|
| 258 | void onAddElement(); | 
|---|
| 259 | void onRemoveElement(); | 
|---|
| 260 | void onElementSelected(); | 
|---|
| 261 |  | 
|---|
| 262 | private: | 
|---|
| 263 | IntQtQuery *subQuery; | 
|---|
| 264 | }; | 
|---|
| 265 |  | 
|---|
| 266 | class QtDialog::MoleculeQtQuery : public QWidget, public QtQuery<const molecule *> { | 
|---|
| 267 | Q_OBJECT | 
|---|
| 268 | public: | 
|---|
| 269 | MoleculeQtQuery(Parameter<const molecule *> &, std::string _title, QBoxLayout *_parent,Dialog *_dialog); | 
|---|
| 270 | virtual ~MoleculeQtQuery(); | 
|---|
| 271 |  | 
|---|
| 272 | public slots: | 
|---|
| 273 | void onUpdate(int); | 
|---|
| 274 |  | 
|---|
| 275 | private: | 
|---|
| 276 | QBoxLayout *parent; | 
|---|
| 277 | QBoxLayout *thisLayout; | 
|---|
| 278 | QLabel *titleLabel; | 
|---|
| 279 | QComboBox *inputBox; | 
|---|
| 280 | Dialog *dialog; | 
|---|
| 281 | }; | 
|---|
| 282 |  | 
|---|
| 283 | class QtDialog::MoleculesQtQuery : public QWidget, public QtQuery<std::vector<const molecule *> >, public QtQueryList<const molecule *> { | 
|---|
| 284 | Q_OBJECT | 
|---|
| 285 | public: | 
|---|
| 286 | MoleculesQtQuery(Parameter<std::vector<const molecule *> > &, std::string _title, QBoxLayout *_parent,Dialog *_dialog); | 
|---|
| 287 | virtual ~MoleculesQtQuery(); | 
|---|
| 288 |  | 
|---|
| 289 | virtual void onSubUpdate(); | 
|---|
| 290 |  | 
|---|
| 291 | public slots: | 
|---|
| 292 | void onAddElement(); | 
|---|
| 293 | void onRemoveElement(); | 
|---|
| 294 | void onElementSelected(); | 
|---|
| 295 |  | 
|---|
| 296 | private: | 
|---|
| 297 | MoleculeQtQuery *subQuery; | 
|---|
| 298 | }; | 
|---|
| 299 |  | 
|---|
| 300 | class QtDialog::StringQtQuery : public QWidget, public QtQuery<std::string> { | 
|---|
| 301 | Q_OBJECT | 
|---|
| 302 | public: | 
|---|
| 303 | StringQtQuery(Parameter<std::string> &, std::string _title, QBoxLayout *_parent,Dialog *_dialog); | 
|---|
| 304 | virtual ~StringQtQuery(); | 
|---|
| 305 |  | 
|---|
| 306 | public slots: | 
|---|
| 307 | void onUpdate(const QString&); | 
|---|
| 308 | void onUpdateCombo(int index); | 
|---|
| 309 |  | 
|---|
| 310 | private: | 
|---|
| 311 | QBoxLayout *parent; | 
|---|
| 312 | QBoxLayout *thisLayout; | 
|---|
| 313 | QLabel *titleLabel; | 
|---|
| 314 | QLineEdit *inputBox; | 
|---|
| 315 | QComboBox *comboBox; | 
|---|
| 316 | Dialog *dialog; | 
|---|
| 317 | }; | 
|---|
| 318 |  | 
|---|
| 319 | class QtDialog::StringsQtQuery : public QWidget, public QtQuery<std::vector<std::string> >, public QtQueryList<std::string> { | 
|---|
| 320 | Q_OBJECT | 
|---|
| 321 | public: | 
|---|
| 322 | StringsQtQuery(Parameter<std::vector<std::string> > &, std::string _title, QBoxLayout *_parent,Dialog *_dialog); | 
|---|
| 323 | virtual ~StringsQtQuery(); | 
|---|
| 324 |  | 
|---|
| 325 | virtual void onSubUpdate(); | 
|---|
| 326 |  | 
|---|
| 327 | public slots: | 
|---|
| 328 | void onAddElement(); | 
|---|
| 329 | void onRemoveElement(); | 
|---|
| 330 | void onElementSelected(); | 
|---|
| 331 |  | 
|---|
| 332 | private: | 
|---|
| 333 | StringQtQuery *subQuery; | 
|---|
| 334 | }; | 
|---|
| 335 |  | 
|---|
| 336 | class QtDialog::UnsignedIntQtQuery : public QWidget, public QtQuery<unsigned int> { | 
|---|
| 337 | Q_OBJECT | 
|---|
| 338 | public: | 
|---|
| 339 | UnsignedIntQtQuery(Parameter<unsigned int> &, std::string _title,QBoxLayout *_parent,Dialog *_dialog); | 
|---|
| 340 | virtual ~UnsignedIntQtQuery(); | 
|---|
| 341 |  | 
|---|
| 342 | public slots: | 
|---|
| 343 | void onUpdate(int); | 
|---|
| 344 |  | 
|---|
| 345 | private: | 
|---|
| 346 | QBoxLayout *parent; | 
|---|
| 347 | QBoxLayout *thisLayout; | 
|---|
| 348 | QLabel *titleLabel; | 
|---|
| 349 | QSpinBox *inputBox; | 
|---|
| 350 | Dialog *dialog; | 
|---|
| 351 | }; | 
|---|
| 352 |  | 
|---|
| 353 | class QtDialog::UnsignedIntsQtQuery : public QWidget, public QtQuery<std::vector<unsigned int> >, public QtQueryList<unsigned int> { | 
|---|
| 354 | Q_OBJECT | 
|---|
| 355 | public: | 
|---|
| 356 | UnsignedIntsQtQuery(Parameter<std::vector<unsigned int> > &, std::string _title, QBoxLayout *_parent,Dialog *_dialog); | 
|---|
| 357 | virtual ~UnsignedIntsQtQuery(); | 
|---|
| 358 |  | 
|---|
| 359 | virtual void onSubUpdate(); | 
|---|
| 360 |  | 
|---|
| 361 | public slots: | 
|---|
| 362 | void onAddElement(); | 
|---|
| 363 | void onRemoveElement(); | 
|---|
| 364 | void onElementSelected(); | 
|---|
| 365 |  | 
|---|
| 366 | private: | 
|---|
| 367 | UnsignedIntQtQuery *subQuery; | 
|---|
| 368 | }; | 
|---|
| 369 |  | 
|---|
| 370 | class QtDialog::VectorQtQuery : public QWidget, public QtQuery<Vector> { | 
|---|
| 371 | Q_OBJECT | 
|---|
| 372 | public: | 
|---|
| 373 | VectorQtQuery(Parameter<Vector> &, std::string title,QBoxLayout *,Dialog *); | 
|---|
| 374 | virtual ~VectorQtQuery(); | 
|---|
| 375 |  | 
|---|
| 376 | public slots: | 
|---|
| 377 | void onUpdateX(double); | 
|---|
| 378 | void onUpdateY(double); | 
|---|
| 379 | void onUpdateZ(double); | 
|---|
| 380 |  | 
|---|
| 381 | private: | 
|---|
| 382 | QBoxLayout *parent; | 
|---|
| 383 | QBoxLayout *mainLayout; | 
|---|
| 384 | QLabel *titleLabel; | 
|---|
| 385 | QBoxLayout *subLayout; | 
|---|
| 386 | QBoxLayout *coordLayout; | 
|---|
| 387 | QLabel *coordLabel; | 
|---|
| 388 | QDoubleSpinBox *coordInputX; | 
|---|
| 389 | QDoubleSpinBox *coordInputY; | 
|---|
| 390 | QDoubleSpinBox *coordInputZ; | 
|---|
| 391 | Dialog *dialog; | 
|---|
| 392 | }; | 
|---|
| 393 |  | 
|---|
| 394 | class QtDialog::VectorsQtQuery : public QWidget, public QtQuery<std::vector<Vector> >, public QtQueryList<Vector> { | 
|---|
| 395 | Q_OBJECT | 
|---|
| 396 | public: | 
|---|
| 397 | VectorsQtQuery(Parameter<std::vector<Vector> > &, std::string _title, QBoxLayout *_parent,Dialog *_dialog); | 
|---|
| 398 | virtual ~VectorsQtQuery(); | 
|---|
| 399 |  | 
|---|
| 400 | virtual void onSubUpdate(); | 
|---|
| 401 |  | 
|---|
| 402 | public slots: | 
|---|
| 403 | void onAddElement(); | 
|---|
| 404 | void onRemoveElement(); | 
|---|
| 405 | void onElementSelected(); | 
|---|
| 406 |  | 
|---|
| 407 | private: | 
|---|
| 408 | VectorQtQuery *subQuery; | 
|---|
| 409 | }; | 
|---|
| 410 |  | 
|---|
| 411 | class QtDialog::RandomNumberDistribution_ParametersQtQuery : public QWidget, public QtQuery<RandomNumberDistribution_Parameters> { | 
|---|
| 412 | Q_OBJECT | 
|---|
| 413 | public: | 
|---|
| 414 | RandomNumberDistribution_ParametersQtQuery(Parameter<RandomNumberDistribution_Parameters> &, std::string title,QBoxLayout *,Dialog *); | 
|---|
| 415 | virtual ~RandomNumberDistribution_ParametersQtQuery(); | 
|---|
| 416 |  | 
|---|
| 417 | public slots: | 
|---|
| 418 | void onUpdate(); | 
|---|
| 419 |  | 
|---|
| 420 | private: | 
|---|
| 421 | QBoxLayout *parent; | 
|---|
| 422 | QHBoxLayout *thisLayout; | 
|---|
| 423 | QLabel *titleLabel; | 
|---|
| 424 | QTextEdit *inputBox; | 
|---|
| 425 | QPushButton *okButton; | 
|---|
| 426 | Dialog *dialog; | 
|---|
| 427 | }; | 
|---|
| 428 |  | 
|---|
| 429 | #endif /* QTQUERY_HPP_ */ | 
|---|