Optika GUI Toolik  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUI_UnitTests.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Optika: A Tool For Developing Parameter Obtaining GUIs
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the
8 // U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include <QtGui>
43 #include <QtTest/QtTest>
45 #include "Optika_treemodel.hpp"
46 #include "Optika_delegate.hpp"
47 #include "Optika_treeview.hpp"
48 #include <QApplication>
49 #include <QSpinBox>
50 #include "Optika_metawindow.hpp"
51 
52 namespace Optika{
53 
54 class ModalClicker : public QThread{
55 public:
56  void run();
57 };
58 
60  QWidget* modalDialog = QApplication::activeModalWidget();
61  while(modalDialog == NULL){
62  modalDialog = QApplication::activeModalWidget();
63  msleep(100);
64  }
65  QTest::keyClick(QApplication::activeModalWidget(), Qt::Key_Return);
66 }
67 
68 class OptikaGUITests: public QObject{
69 Q_OBJECT
70 private slots:
71  void typeTest();
72  void dependencyTests();
73  void arrayEditorTest();
74  void twoDEditorTest();
75  void twoDSymmetryTest();
76  void modelLoadTest();
77  void validatorApplierTests();
78  void settingsTest();
79  void displayRoleTest();
80  void cleanupTestCase();
81 private:
82  static inline QModelIndex getWidgetIndex(const QModelIndex& index);
83  QObjectCleanupHandler cleaner;
85 };
86 
88  cleaner.clear();
89  if(clicker.isRunning()){
90  clicker.terminate();
91  clicker.wait();
92  }
93  QVERIFY(!clicker.isRunning());
94 }
95 
96 
97 
98 //QModelIndex OptikaGUITests::getEntryIndex(
99 
100 #define GET_ENTRY_INDEX(\
101  PL, \
102  NAME, \
103  MODEL) \
104  RCP<ParameterEntry> NAME##Entry = PL->getEntryRCP( #NAME ); \
105  QVERIFY(nonnull( NAME##Entry )); \
106  QModelIndex NAME##Index = MODEL->findParameterEntryIndex( NAME##Entry ); \
107  QVERIFY( NAME##Index.isValid());
108 
109 #define VERIFY_PARAMETER_TYPE(PL, NAME, TYPE, MODEL) \
110  GET_ENTRY_INDEX( PL , NAME , MODEL ) \
111  QCOMPARE( MODEL->data( NAME##Index, Qt::DisplayRole).toString(), \
112  QString::fromStdString( #NAME) ); \
113  QModelIndex NAME##TypeIndex = NAME##Index.sibling(NAME##Index.row(),2); \
114  QVERIFY( NAME##TypeIndex.isValid()); \
115  QCOMPARE( MODEL->data( NAME##TypeIndex, Qt::DisplayRole).toString(), TYPE );
116 
117 
119  cleaner.clear();
120  RCP<ParameterList> My_List =
122 
125 
126  double *pointer = 0;
127  Array<double*> doubleStarArray;
128  Array<int> intArray;
129  My_List->set("Doublepointer", pointer);
130  My_List->set(
131  "MaxIters",
132  1550,
133  "Determines the maximum number of iterations in the solver",
134  intVali);
135  My_List->set(
136  "Tolerance", 1e-10, "The tolerance used for the convergence check");
137  My_List->set("DoublePointerArray", doubleStarArray);
138  My_List->set("IntArray", intArray);
139 
140  TreeModel* model = new TreeModel(My_List);
141  cleaner.add(model);
142 
143  VERIFY_PARAMETER_TYPE(My_List, MaxIters, intId, model)
144  VERIFY_PARAMETER_TYPE(My_List, Doublepointer, unrecognizedId, model)
145  VERIFY_PARAMETER_TYPE(My_List, Tolerance, doubleId, model)
146  VERIFY_PARAMETER_TYPE(My_List, DoublePointerArray, unrecognizedId, model)
147  VERIFY_PARAMETER_TYPE(My_List, IntArray, arrayId + " " + intId, model);
148  Delegate* delegate = new Delegate;
149  cleaner.add(delegate);
150 
151  QStyleOptionViewItem genericStyleItem;
152  QModelIndex widgetIndex = getWidgetIndex(MaxItersIndex);
153  QSpinBox* intSpin = ((QSpinBox*)delegate->createEditor(0, genericStyleItem, widgetIndex));
154  QCOMPARE(intSpin->maximum(), 2000);
155  QCOMPARE(intSpin->minimum(),0);
156  QCOMPARE(intSpin->singleStep(),3);
157 
158 
159  cleaner.remove(model);
160  cleaner.remove(delegate);
161  delete model;
162  delete delegate;
163 }
164 
165 
167  Array<double> testArray(4,4.5);
168  ParameterEntry testEntry(testArray);
169  DoubleArrayWidget* testWidget = new DoubleArrayWidget("tester", doubleId, null);
170  cleaner.add(testWidget);
171 
172  testWidget->initData(testArray);
173  Array<double> retrievedArray = testWidget->getArrayFromWidgets();
174  QVERIFY(testArray == retrievedArray);
175 
176  cleaner.remove(testWidget);
177  delete testWidget;
178 }
179 
181  TwoDArray<double> testArray(4,2,4.5);
182  ParameterEntry testEntry(testArray);
183  Double2DArrayWidget* testWidget =
184  new Double2DArrayWidget("tester", doubleId, null);
185  cleaner.add(testWidget);
186 
187  testWidget->initData(testArray);
188  testWidget->accept();
189  TwoDArray<double> retrievedArray = testWidget->getData();
190  QVERIFY(testArray == retrievedArray);
191 
192 
193  cleaner.remove(testWidget);
194  delete testWidget;
195 
196 }
197 
198 inline QModelIndex OptikaGUITests::getWidgetIndex(const QModelIndex& index){
199  return index.sibling(index.row(),1);
200 }
201 
202 
203 #define VERIFY_HIDDEN_ROW(INDEX) \
204  QVERIFY(treeView->isRowHidden( INDEX.row(), INDEX.parent()));
205 
206 #define VERIFY_SHOWN_ROW(INDEX) \
207  QVERIFY(!treeView->isRowHidden( INDEX.row(), INDEX.parent()));
208 
210  cleaner.clear();
211  RCP<DependencySheet> dependencySheet = rcp(new DependencySheet);
212  RCP<ParameterList> validParameters =
213  getParametersFromXmlFile("deptests.xml", dependencySheet);
214  TreeModel* model = new TreeModel(validParameters, dependencySheet);
215  Delegate* delegate = new Delegate;
216  TreeView* treeView = new TreeView(model, delegate);
217  cleaner.add(model);
218  cleaner.add(delegate);
219  cleaner.add(treeView);
220  QStyleOptionViewItem genericStyleItem;
221 
222  //Assert that the TreeModel has dependencies
223  QVERIFY(model->hasDependencies());
224 
225 //Testing Bool visual dependency
226  GET_ENTRY_INDEX(validParameters, Preconditioner, model)
227  GET_ENTRY_INDEX(validParameters, ShowPrecs, model)
228 
229  VERIFY_HIDDEN_ROW(PreconditionerIndex)
230  QModelIndex precWidgetIndex = getWidgetIndex(ShowPrecsIndex);
231  QComboBox* precBox = (QComboBox*)delegate->createEditor(
232  0, genericStyleItem, precWidgetIndex);
233  precBox->setCurrentIndex(precBox->findText(Delegate::getBoolEditorTrue()));
234  delegate->setModelData(precBox, model, precWidgetIndex);
235  VERIFY_SHOWN_ROW(PreconditionerIndex)
236 
237 
238 //StringVisualDependency testing
239  GET_ENTRY_INDEX(validParameters, Favorite_Cheese, model)
240  GET_ENTRY_INDEX(validParameters, Swiss_rating, model)
241 
242  VERIFY_HIDDEN_ROW(Swiss_ratingIndex)
243  QModelIndex cheeseWidgetIndex = getWidgetIndex(Favorite_CheeseIndex);
244  QComboBox* cheeseBox = (QComboBox*)delegate->createEditor(
245  0,genericStyleItem, cheeseWidgetIndex);
246  cheeseBox->setCurrentIndex(cheeseBox->findText("Swiss"));
247  delegate->setModelData(cheeseBox, model, cheeseWidgetIndex);
248  VERIFY_SHOWN_ROW(Swiss_ratingIndex)
249 
250 //Testing Number Visual Dependencies
251  GET_ENTRY_INDEX(validParameters, Temp, model)
252  GET_ENTRY_INDEX(validParameters, Num_ice_cubes, model)
253  VERIFY_SHOWN_ROW(Num_ice_cubesIndex)
254  QModelIndex tempWidgetIndex = getWidgetIndex(TempIndex);
255  QLineEdit* tempLineEdit = (QLineEdit*)delegate->createEditor(
256  0,genericStyleItem, tempWidgetIndex);
257  tempLineEdit->setText("33.0");
258  delegate->setModelData(tempLineEdit, model, tempWidgetIndex);
259  VERIFY_HIDDEN_ROW(Num_ice_cubesIndex)
260 
261  //Test condition visual dependency
262  GET_ENTRY_INDEX(validParameters, ParamA, model)
263  GET_ENTRY_INDEX(validParameters, ParamB, model)
264  GET_ENTRY_INDEX(validParameters, OptParam, model)
265  VERIFY_SHOWN_ROW(OptParamIndex)
266  QModelIndex paramAWidgetIndex = getWidgetIndex(ParamAIndex);
267  QModelIndex paramBWidgetIndex = getWidgetIndex(ParamBIndex);
268  QSpinBox* paramASpinner = (QSpinBox*)delegate->createEditor(
269  0, genericStyleItem, paramAWidgetIndex);
270  QSpinBox* paramBSpinner = (QSpinBox*)delegate->createEditor(
271  0, genericStyleItem, paramBWidgetIndex);
272  paramASpinner->setValue(0);
273  delegate->setModelData(paramASpinner, model, paramAWidgetIndex);
274  VERIFY_SHOWN_ROW(OptParamIndex)
275  paramBSpinner->setValue(0);
276  delegate->setModelData(paramBSpinner, model, paramBWidgetIndex);
277  VERIFY_HIDDEN_ROW(OptParamIndex)
278  paramBSpinner->setValue(1);
279  delegate->setModelData(paramBSpinner, model, paramBWidgetIndex);
280  VERIFY_SHOWN_ROW(OptParamIndex)
281 
282 
283  //Test Number Array Length Dependency
284  GET_ENTRY_INDEX(validParameters, NumBuckets, model)
285  GET_ENTRY_INDEX(validParameters, AmtInBuckets, model)
286  Array<double> bucketsArray = model->getArray<double>(AmtInBucketsIndex);
287  QCOMPARE(bucketsArray.size(),(Array<double>::size_type)3);
288  QModelIndex numBucketsWidgetIndex = getWidgetIndex(NumBucketsIndex);
289  QSpinBox* numBucketsSpinner = (QSpinBox*)delegate->createEditor(
290  0, genericStyleItem, numBucketsWidgetIndex);
291  numBucketsSpinner->setValue(5);
292  delegate->setModelData(numBucketsSpinner, model, numBucketsWidgetIndex);
293  bucketsArray = model->getArray<double>(AmtInBucketsIndex);
294  QCOMPARE(bucketsArray.size(),(Array<double>::size_type)5);
295 
296 
297  //Testing for Bool ValidatorDependency
298  GET_ENTRY_INDEX(validParameters, TempConst, model)
299  GET_ENTRY_INDEX(validParameters, BoolTemp, model)
300  QVERIFY(nonnull(model->getValidator(BoolTempIndex)));
301  QModelIndex tempConstWidgetIndex = getWidgetIndex(TempConstIndex);
302  QModelIndex boolTempWidgetIndex = getWidgetIndex(BoolTempIndex);
303  QLineEdit* boolTempEdit = (QLineEdit*)delegate->createEditor(
304  0, genericStyleItem, boolTempWidgetIndex);
305  QCOMPARE(((QDoubleValidator*)boolTempEdit->validator())->bottom(), 0.0);
306  QCOMPARE(((QDoubleValidator*)boolTempEdit->validator())->top(), 50.0);
307  QComboBox* tempConstCombo = (QComboBox*)delegate->createEditor(
308  0, genericStyleItem, tempConstWidgetIndex);
309  tempConstCombo->setCurrentIndex(
310  tempConstCombo->findText(Delegate::getBoolEditorFalse()));
311  delegate->setModelData(tempConstCombo, model, tempConstWidgetIndex);
312  QVERIFY(model->getValidator(BoolTempIndex).is_null());
313  boolTempEdit = (QLineEdit*)delegate->createEditor(
314  0, genericStyleItem, boolTempWidgetIndex);
315  QCOMPARE(((QDoubleValidator*)boolTempEdit->validator())->bottom(), EnhancedNumberTraits<double>::min());
316  QCOMPARE(((QDoubleValidator*)boolTempEdit->validator())->top(), EnhancedNumberTraits<double>::max());
317 
318 
319  //StringValidatorDepenecy tests
320  GET_ENTRY_INDEX(validParameters, FavFoodType, model)
321  GET_ENTRY_INDEX(validParameters, FavFood, model)
322  QVERIFY(nonnull(model->getValidator(FavFoodIndex)));
323  QModelIndex favFoodWidgetIndex = getWidgetIndex(FavFoodIndex);
324  QComboBox* favFoodCombo = (QComboBox*)delegate->createEditor(
325  0, genericStyleItem, favFoodWidgetIndex);
326  QCOMPARE(favFoodCombo->count(),3);
327  QVERIFY(favFoodCombo->findText("American") != -1);
328  QVERIFY(favFoodCombo->findText("Swiss") != -1);
329  QVERIFY(favFoodCombo->findText("Pepperjack") != -1);
330 
331  //Change to chips and verify new valid values
332  QSignalSpy badValSpy(model, SIGNAL(badValue(QModelIndex, QString)));
333  QModelIndex favFoodTypeWidgetIndex = getWidgetIndex(FavFoodTypeIndex);
334  QLineEdit* favFoodTypeEdit = (QLineEdit*)delegate->createEditor(
335  0, genericStyleItem, favFoodTypeWidgetIndex);
336  favFoodTypeEdit->setText("Chips");
337  clicker.start(QThread::IdlePriority);
338  delegate->setModelData(favFoodTypeEdit, model, favFoodTypeWidgetIndex);
339  QCOMPARE(badValSpy.count(), 1);
340  favFoodCombo = (QComboBox*)delegate->createEditor(
341  0, genericStyleItem, favFoodWidgetIndex);
342  QCOMPARE(favFoodCombo->count(),3);
343  QVERIFY(favFoodCombo->findText("Lays") != -1);
344  QVERIFY(favFoodCombo->findText("Ruffles") != -1);
345  QVERIFY(favFoodCombo->findText("Pringles") != -1);
346 
347  //Change to blah and validate ther validator is now null
348  favFoodTypeEdit->setText("blah");
349  delegate->setModelData(favFoodTypeEdit, model, favFoodTypeWidgetIndex);
350  QVERIFY(model->getValidator(FavFoodIndex).is_null());
351 
352  //Change Back to chips and verify that the valid vlues have returned.
353  favFoodTypeEdit->setText("Chips");
354  delegate->setModelData(favFoodTypeEdit, model, favFoodTypeWidgetIndex);
355  favFoodCombo = (QComboBox*)delegate->createEditor(
356  0, genericStyleItem, favFoodWidgetIndex);
357  QCOMPARE(favFoodCombo->count(),3);
358  QVERIFY(favFoodCombo->findText("Lays") != -1);
359  QVERIFY(favFoodCombo->findText("Ruffles") != -1);
360  QVERIFY(favFoodCombo->findText("Pringles") != -1);
361 
362 
363  //Test RangeValidatorDependency
364  GET_ENTRY_INDEX(validParameters, FondTemp, model)
365  GET_ENTRY_INDEX(validParameters, FondFood, model)
366  QVERIFY(nonnull(model->getValidator(FondFoodIndex)));
367  QModelIndex fondFoodWidgetIndex = getWidgetIndex(FondFoodIndex);
368  QComboBox* fondFoodCombo = (QComboBox*)delegate->createEditor(
369  0, genericStyleItem, fondFoodWidgetIndex);
370  QCOMPARE(fondFoodCombo->count(), 2);
371  QVERIFY(fondFoodCombo->findText("Cheese") != -1);
372  QVERIFY(fondFoodCombo->findText("Bread") != -1);
373 
374  QModelIndex fondTempWidgetIndex = getWidgetIndex(FondTempIndex);
375  QLineEdit* fondTempEdit = (QLineEdit*)delegate->createEditor(
376  0, genericStyleItem, fondTempWidgetIndex);
377  fondTempEdit->setText("120.1");
378  delegate->setModelData(fondTempEdit, model, fondTempWidgetIndex);
379  fondFoodCombo = (QComboBox*)delegate->createEditor(
380  0, genericStyleItem, fondFoodWidgetIndex);
381  QCOMPARE(fondFoodCombo->count(), 2);
382  QVERIFY(fondFoodCombo->findText("Chicken") != -1);
383  QVERIFY(fondFoodCombo->findText("Beef") != -1);
384 
385  fondTempEdit->setText("180.1");
386  delegate->setModelData(fondTempEdit, model, fondTempWidgetIndex);
387  QVERIFY(model->getValidator(FondFoodIndex).is_null());
388  QLineEdit* fondFoodLineEdit = (QLineEdit*)delegate->createEditor(
389  0, genericStyleItem, fondFoodWidgetIndex);
390  QVERIFY(fondFoodLineEdit != NULL);
391 
392 
393  fondTempEdit->setText("90");
394  delegate->setModelData(fondTempEdit, model, fondTempWidgetIndex);
395  fondFoodCombo = (QComboBox*)delegate->createEditor(
396  0, genericStyleItem, fondFoodWidgetIndex);
397  QCOMPARE(fondFoodCombo->count(), 2);
398  QVERIFY(fondFoodCombo->findText("Cheese") != -1);
399  QVERIFY(fondFoodCombo->findText("Bread") != -1);
400 
401 
402  //Test TwoDRowDependency
403  GET_ENTRY_INDEX(validParameters, NumRows, model)
404  GET_ENTRY_INDEX(validParameters, RowArray, model)
405  QModelIndex numRowsWidgetIndex = getWidgetIndex(NumRowsIndex);
406  QSpinBox* numRowSpin = (QSpinBox*)delegate->createEditor(
407  0, genericStyleItem, numRowsWidgetIndex);
408  numRowSpin->setValue(2);
409  delegate->setModelData(numRowSpin, model, numRowsWidgetIndex);
410  TwoDArray<double> rowArray = model->getTwoDArray<double>(RowArrayIndex);
411  QCOMPARE(rowArray.getNumRows(), (TwoDArray<double>::size_type)2);
412 
413  //Test TwoDColDependency
414  GET_ENTRY_INDEX(validParameters, NumCols, model)
415  GET_ENTRY_INDEX(validParameters, ColArray, model)
416  QModelIndex numColsWidgetIndex = getWidgetIndex(NumColsIndex);
417  QSpinBox* numColSpin = (QSpinBox*)delegate->createEditor(
418  0, genericStyleItem, numColsWidgetIndex);
419  numColSpin->setValue(2);
420  delegate->setModelData(numColSpin, model, numColsWidgetIndex);
421  TwoDArray<double> colArray = model->getTwoDArray<double>(ColArrayIndex);
422  QCOMPARE(colArray.getNumCols(), (TwoDArray<double>::size_type)2);
423 
424 
425 
426 
427  cleaner.remove(model);
428  cleaner.remove(treeView);
429  cleaner.remove(delegate);
430  delete model;
431  delete treeView;
432  delete delegate;
433 }
434 
435 
437  cleaner.clear();
438  TwoDArray<double> testArray(4,4,4.5);
439  testArray.setSymmetrical(true);
440  Double2DArrayWidget* testWidget =
441  new Double2DArrayWidget("tester", doubleId, null);
442  cleaner.add(testWidget);
443 
444  testWidget->initData(testArray);
445  QGridLayout* layout = (QGridLayout*)testWidget->layout();
446  QScrollArea* scrollArea = (QScrollArea*)(layout->itemAtPosition(0,0)->widget());
447  QWidget* actualWidget = scrollArea->widget();
448  QCOMPARE(((QGridLayout*)actualWidget->layout())->itemAtPosition(1,1), (QLayoutItem*)0);
449 
450  testWidget->accept();
451  TwoDArray<double> retrievedArray = testWidget->getData();
452  QVERIFY(testArray == retrievedArray);
453 
454 
455  cleaner.remove(testWidget);
456  delete testWidget;
457 
458 
459 }
460 
462  cleaner.clear();
463  RCP<ParameterList> validParameters =
464  getParametersFromXmlFile("loadtest.xml");
465  TreeModel* model = new TreeModel(validParameters);
466  Delegate* delegate = new Delegate;
467  TreeView* treeView = new TreeView(model, delegate);
468  cleaner.add(model);
469  cleaner.add(delegate);
470  cleaner.add(treeView);
471 
472  QCOMPARE(model->getCurrentParameters()->get<int>("Steve"), 4);
473  QCOMPARE(model->getCurrentParameters()->get<int>("Sam"), 4);
474  QCOMPARE(model->getCurrentParameters()->sublist("Prec").get<int>("Sam"), 9);
475  QCOMPARE(model->getCurrentParameters()->sublist("Prec").get<int>("Blah"), 1);
476  model->readInput("loadtest.in.xml");
477  QCOMPARE(model->getCurrentParameters()->get<int>("Steve"), 0);
478  QCOMPARE(model->getCurrentParameters()->sublist("Prec").get<int>("Blah"), 80);
479  QCOMPARE(model->getCurrentParameters()->sublist("Prec").get<int>("Sam"), 99);
480  QCOMPARE(model->getCurrentParameters()->get<int>("Sam"), 50);
481 
482  cleaner.remove(model);
483  cleaner.remove(treeView);
484  cleaner.remove(delegate);
485  delete model;
486  delete treeView;
487  delete delegate;
488 
489 }
490 
491 template<class T>
493  const RCP<EnhancedNumberValidator<T> > validator,
494  QAbstractSpinBox* spinner)
495 {
496  ValidatorApplier<T>::applyToSpinBox(validator, (QSpinBox*)spinner);
497 }
498 
499 template<>
501  const RCP<EnhancedNumberValidator<double> > validator,
502  QAbstractSpinBox* spinner)
503 {
504  ValidatorApplier<double>::applyToSpinBox(validator, (QDoubleSpinBox*)spinner);
505 }
506 
507 template<>
509  const RCP<EnhancedNumberValidator<float> > validator,
510  QAbstractSpinBox* spinner)
511 {
512  ValidatorApplier<float>::applyToSpinBox(validator, (QDoubleSpinBox*)spinner);
513 }
514 
515 template<class T>
516 QAbstractSpinBox* createDefaultSpinner(){
517  return new QSpinBox();
518 }
519 
520 template<>
521 QAbstractSpinBox* createDefaultSpinner<float>(){
522  return new QDoubleSpinBox();
523 }
524 
525 template<>
526 QAbstractSpinBox* createDefaultSpinner<double>(){
527  return new QDoubleSpinBox();
528 }
529 
530 template<class T>
531 void assertSpinnerDefaults(QAbstractSpinBox *spinBox){
532  QSpinBox* actualSpinner = (QSpinBox*)spinBox;
533  QCOMPARE(
534  Teuchos::as<T>(actualSpinner->singleStep()),
536 }
537 
538 template<>
539 void assertSpinnerDefaults<float>(QAbstractSpinBox *spinBox){
540  QDoubleSpinBox* actualSpinner = (QDoubleSpinBox*)spinBox;
541  QCOMPARE(
542  actualSpinner->decimals(),
544  QCOMPARE(
545  Teuchos::as<float>(actualSpinner->singleStep()),
547 }
548 
549 template<>
550 void assertSpinnerDefaults<double>(QAbstractSpinBox *spinBox){
551  QDoubleSpinBox* actualSpinner = (QDoubleSpinBox*)spinBox;
552  QCOMPARE(
553  actualSpinner->decimals(),
555  QCOMPARE(
556  Teuchos::as<double>(actualSpinner->singleStep()),
558 }
559 
560 
561 template<class T>
563  const QValidator* validator,
564  QString& val20,
565  QString& valneg1,
566  int& pos)
567 {
568  QCOMPARE(validator->validate(val20,pos), QValidator::Invalid);
569  QCOMPARE(validator->validate(valneg1,pos), QValidator::Invalid);
570 }
571 
572 template<>
574  const QValidator* validator,
575  QString& val20,
576  QString& valneg1,
577  int& pos)
578 {
579  QCOMPARE(validator->validate(val20,pos), QValidator::Intermediate);
580  QCOMPARE(validator->validate(valneg1,pos), QValidator::Invalid);
581  const QDoubleValidator* doubleValidator = (QDoubleValidator*)validator;
582  QCOMPARE(
583  doubleValidator->decimals(),
585 }
586 
587 template<>
589  const QValidator* validator,
590  QString& val20,
591  QString& valneg1,
592  int& pos)
593 {
594  QCOMPARE(validator->validate(val20,pos), QValidator::Intermediate);
595  QCOMPARE(validator->validate(valneg1,pos), QValidator::Invalid);
596  const QDoubleValidator* doubleValidator = (QDoubleValidator*)validator;
597  QCOMPARE(
598  doubleValidator->decimals(),
600 }
601 
602 template<class T>
604  EnhancedNumberValidator<T> validator(Teuchos::as<T>(0), Teuchos::as<T>(10));
605  RCP<EnhancedNumberValidator<T> > valPtr = rcpFromRef(validator);
606 
607  QString val10("10");
608  QString val20("20");
609  QString val5("5");
610  QString val0("0");
611  QString valneg1("-1");
612 
613 
615  QAbstractSpinBox* spinner = createDefaultSpinner<T>();
616  testingSpinBoxApply(valPtr, spinner);
617  int pos=0;
618  QCOMPARE(spinner->validate(val10,pos), QValidator::Acceptable);
619  QCOMPARE(spinner->validate(val20,pos), QValidator::Invalid);
620  QCOMPARE(spinner->validate(val5,pos), QValidator::Acceptable);
621  QCOMPARE(spinner->validate(val0,pos), QValidator::Acceptable);
622  QCOMPARE(spinner->validate(valneg1,pos), QValidator::Invalid);
623  assertSpinnerDefaults<T>(spinner);
624  delete spinner;
625 
627  QLineEdit lineEdit;
628  ValidatorApplier<T>::applyToLineEdit(valPtr, &lineEdit);
629  const QValidator* appliedValidator = lineEdit.validator();
630  QCOMPARE(appliedValidator->validate(val10,pos), QValidator::Acceptable);
631  QCOMPARE(appliedValidator->validate(val5,pos), QValidator::Acceptable);
632  QCOMPARE(appliedValidator->validate(val0,pos), QValidator::Acceptable);
633  assertLineEditDetails<T>(appliedValidator, val20, valneg1, pos);
634 }
635 
637  valApplyTestTemplate<int>();
638  valApplyTestTemplate<short>();
639  valApplyTestTemplate<double>();
640  valApplyTestTemplate<float>();
641 }
642 
644  RCP<ParameterList> validParameters = rcp(new ParameterList("Steve"));
645  validParameters->set("Don't care", "don't care");
646  MetaWindow* m1 = new MetaWindow(validParameters);
647  m1->move(30,99);
648  m1->resize(673,823);
649  delete m1;
650  MetaWindow* m2 = new MetaWindow(validParameters);
651  QCOMPARE(m2->width(),673);
652  QCOMPARE(m2->height(),823);
653  QCOMPARE(m2->x(),30);
654  QCOMPARE(m2->y(),99);
655  delete m2;
656 }
657 
659  cleaner.clear();
660  RCP<ParameterList> validParameters =
661  getParametersFromXmlFile("loadtest.xml");
662  validParameters->set("2dtest", Teuchos::TwoDArray<int>(2,2,4));
663  TreeModel* model = new TreeModel(validParameters);
664  Delegate* delegate = new Delegate;
665  TreeView* treeView = new TreeView(model, delegate);
666  cleaner.add(model);
667  cleaner.add(delegate);
668  cleaner.add(treeView);
669  RCP<const ParameterList> parameters = model->getCurrentParameters();
670 
671  RCP<const ParameterEntry> steveParameter = parameters->getEntryRCP("Steve");
672  QModelIndex steveIndex = model->findParameterEntryIndex(steveParameter);
673  QVariant data = model->data(
674  steveIndex.sibling(steveIndex.row(), 1), Qt::DisplayRole);
675  QCOMPARE(data.toString(), QString("4"));
676 
677  RCP<const ParameterEntry> twodParameter = parameters->getEntryRCP("2dtest");
678  QModelIndex twodIndex = model->findParameterEntryIndex(twodParameter);
679  data = model->data(
680  twodIndex.sibling(twodIndex.row(), 1), Qt::DisplayRole);
681  QCOMPARE(data.toString(), QString("Click to view 2D Array"));
682 
683  RCP<const ParameterEntry> listParameter = parameters->getEntryRCP("Prec");
684  QModelIndex listIndex = model->findParameterEntryIndex(listParameter);
685  data = model->data(
686  listIndex.sibling(listIndex.row(), 1), Qt::DisplayRole);
687  QCOMPARE(data.toString(), QString(""));
688 
689  cleaner.remove(model);
690  cleaner.remove(treeView);
691  cleaner.remove(delegate);
692  delete model;
693  delete treeView;
694  delete delegate;
695 
696 
697 
698 }
699 
700 } //namespace Optika
701 
702 QTEST_MAIN(Optika::OptikaGUITests)
703 #include "GUI_UnitTests.moc"
704 
The delegate used in the MVC framework for Optika.
QModelIndex findParameterEntryIndex(RCP< const ParameterEntry > parameterEntry)
Finds the index of a particular parameter entry.
static const QString & getBoolEditorTrue()
Gets the value the delegate uses to represent "true" when constructing comboboxes for boolean paramet...
QString intId
static QModelIndex getWidgetIndex(const QModelIndex &index)
void assertSpinnerDefaults< double >(QAbstractSpinBox *spinBox)
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
void setSymmetrical(bool symmetrical)
void testingSpinBoxApply(const RCP< EnhancedNumberValidator< T > > validator, QAbstractSpinBox *spinner)
void valApplyTestTemplate()
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
QString unrecognizedId
RCP< const ParameterList > getCurrentParameters()
Get a ParameterList containing all of the parameters at their current settings.
#define VERIFY_HIDDEN_ROW(INDEX)
Array< double > getArrayFromWidgets()
void assertSpinnerDefaults< float >(QAbstractSpinBox *spinBox)
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
void assertLineEditDetails< float >(const QValidator *validator, QString &val20, QString &valneg1, int &pos)
A 2DArrayWidget used for editing arrays whose template type is double.
#define VERIFY_SHOWN_ROW(INDEX)
TwoDArray< S > getTwoDArray(const QModelIndex &index)
Gets the TwoDArray for a particular TreeItem.
void initData(Array< S > array)
Initializes all of the data in the array widget so when it pops up, the individual widgets are popula...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static unsigned short defaultPrecision()
void assertLineEditDetails(const QValidator *validator, QString &val20, QString &valneg1, int &pos)
static const QString & getBoolEditorFalse()
Gets the value the delegate uses to represent "false" when constructing comboboxes for boolean parame...
void assertLineEditDetails< double >(const QValidator *validator, QString &val20, QString &valneg1, int &pos)
#define VERIFY_PARAMETER_TYPE(PL, NAME, TYPE, MODEL)
size_type getNumCols() const
void readInput(QString fileName)
Reads an xml file that describes the state of current parameters in xml format.
Class used to view TreeModels.
bool testArray(const int n, Teuchos::FancyOStream &out)
QAbstractSpinBox * createDefaultSpinner< double >()
RCP< const ParameterEntryValidator > getValidator(const QModelIndex &index) const
Gets the validator for a particular TreeItem.
#define GET_ENTRY_INDEX(PL, NAME, MODEL)
size_type getNumRows() const
QString doubleId
bool nonnull(const boost::shared_ptr< T > &p)
void initData(TwoDArray< S > array)
Initializes all of the data in the array widget so when it pops up, the individual widgets are popula...
static void applyToSpinBox(RCP< const EnhancedNumberValidator< S > > validator, QSpinBox *spinBox)
Applied attributes of the validator to the spin box.
The main window users interact with along with a small search widget used in the main window...
size_type size() const
The Main Window that contains all other widgets in the Optika GUI. For all undocumented functions ple...
QAbstractSpinBox * createDefaultSpinner< float >()
A widget for editing Arrays of type double.
void assertSpinnerDefaults(QAbstractSpinBox *spinBox)
static void applyToLineEdit(RCP< const EnhancedNumberValidator< S > > validator, QLineEdit *lineEdit)
QString arrayId
Array< S > getArray(const QModelIndex &index)
Gets the array for a particular TreeItem.
QAbstractSpinBox * createDefaultSpinner()
bool hasDependencies()
Determines whether or not a Dependent Parameter List is being used in the TreeModel.
TreeModel is a type of QAbstractItemModel that has a Tree like structure.
The delegate used for the Optika package. For non-documented functions please refer to the Qt API...
The view used in Optikas implementation of the MVC framework.
QObjectCleanupHandler cleaner
TwoDArray< S > getData() const
gets the data currently stored in baseArray.