43 #include <QtTest/QtTest>
48 #include <QApplication>
60 QWidget* modalDialog = QApplication::activeModalWidget();
61 while(modalDialog == NULL){
62 modalDialog = QApplication::activeModalWidget();
65 QTest::keyClick(QApplication::activeModalWidget(), Qt::Key_Return);
82 static inline QModelIndex
getWidgetIndex(
const QModelIndex& index);
100 #define GET_ENTRY_INDEX(\
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());
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 );
129 My_List->set(
"Doublepointer", pointer);
133 "Determines the maximum number of iterations in the solver",
136 "Tolerance", 1e-10,
"The tolerance used for the convergence check");
137 My_List->set(
"DoublePointerArray", doubleStarArray);
138 My_List->set(
"IntArray", intArray);
151 QStyleOptionViewItem genericStyleItem;
153 QSpinBox* intSpin = ((QSpinBox*)delegate->
createEditor(0, genericStyleItem, widgetIndex));
154 QCOMPARE(intSpin->maximum(), 2000);
155 QCOMPARE(intSpin->minimum(),0);
156 QCOMPARE(intSpin->singleStep(),3);
174 QVERIFY(testArray == retrievedArray);
190 QVERIFY(testArray == retrievedArray);
199 return index.sibling(index.row(),1);
203 #define VERIFY_HIDDEN_ROW(INDEX) \
204 QVERIFY(treeView->isRowHidden( INDEX.row(), INDEX.parent()));
206 #define VERIFY_SHOWN_ROW(INDEX) \
207 QVERIFY(!treeView->isRowHidden( INDEX.row(), INDEX.parent()));
213 getParametersFromXmlFile(
"deptests.xml", dependencySheet);
220 QStyleOptionViewItem genericStyleItem;
231 QComboBox* precBox = (QComboBox*)delegate->
createEditor(
232 0, genericStyleItem, precWidgetIndex);
234 delegate->
setModelData(precBox, model, precWidgetIndex);
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);
255 QLineEdit* tempLineEdit = (QLineEdit*)delegate->
createEditor(
256 0,genericStyleItem, tempWidgetIndex);
257 tempLineEdit->setText(
"33.0");
258 delegate->
setModelData(tempLineEdit, model, tempWidgetIndex);
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);
275 paramBSpinner->setValue(0);
276 delegate->
setModelData(paramBSpinner, model, paramBWidgetIndex);
278 paramBSpinner->setValue(1);
279 delegate->
setModelData(paramBSpinner, model, paramBWidgetIndex);
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);
301 QModelIndex tempConstWidgetIndex =
getWidgetIndex(TempConstIndex);
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(
311 delegate->
setModelData(tempConstCombo, model, tempConstWidgetIndex);
314 0, genericStyleItem, boolTempWidgetIndex);
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);
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);
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);
348 favFoodTypeEdit->setText(
"blah");
349 delegate->
setModelData(favFoodTypeEdit, model, favFoodTypeWidgetIndex);
353 favFoodTypeEdit->setText(
"Chips");
354 delegate->
setModelData(favFoodTypeEdit, model, favFoodTypeWidgetIndex);
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);
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);
375 QLineEdit* fondTempEdit = (QLineEdit*)delegate->
createEditor(
376 0, genericStyleItem, fondTempWidgetIndex);
377 fondTempEdit->setText(
"120.1");
378 delegate->
setModelData(fondTempEdit, model, fondTempWidgetIndex);
380 0, genericStyleItem, fondFoodWidgetIndex);
381 QCOMPARE(fondFoodCombo->count(), 2);
382 QVERIFY(fondFoodCombo->findText(
"Chicken") != -1);
383 QVERIFY(fondFoodCombo->findText(
"Beef") != -1);
385 fondTempEdit->setText(
"180.1");
386 delegate->
setModelData(fondTempEdit, model, fondTempWidgetIndex);
388 QLineEdit* fondFoodLineEdit = (QLineEdit*)delegate->
createEditor(
389 0, genericStyleItem, fondFoodWidgetIndex);
390 QVERIFY(fondFoodLineEdit != NULL);
393 fondTempEdit->setText(
"90");
394 delegate->
setModelData(fondTempEdit, model, fondTempWidgetIndex);
396 0, genericStyleItem, fondFoodWidgetIndex);
397 QCOMPARE(fondFoodCombo->count(), 2);
398 QVERIFY(fondFoodCombo->findText(
"Cheese") != -1);
399 QVERIFY(fondFoodCombo->findText(
"Bread") != -1);
406 QSpinBox* numRowSpin = (QSpinBox*)delegate->
createEditor(
407 0, genericStyleItem, numRowsWidgetIndex);
408 numRowSpin->setValue(2);
409 delegate->
setModelData(numRowSpin, model, numRowsWidgetIndex);
417 QSpinBox* numColSpin = (QSpinBox*)delegate->
createEditor(
418 0, genericStyleItem, numColsWidgetIndex);
419 numColSpin->setValue(2);
420 delegate->
setModelData(numColSpin, model, numColsWidgetIndex);
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);
452 QVERIFY(testArray == retrievedArray);
464 getParametersFromXmlFile(
"loadtest.xml");
494 QAbstractSpinBox* spinner)
502 QAbstractSpinBox* spinner)
510 QAbstractSpinBox* spinner)
517 return new QSpinBox();
522 return new QDoubleSpinBox();
527 return new QDoubleSpinBox();
532 QSpinBox* actualSpinner = (QSpinBox*)spinBox;
534 Teuchos::as<T>(actualSpinner->singleStep()),
540 QDoubleSpinBox* actualSpinner = (QDoubleSpinBox*)spinBox;
542 actualSpinner->decimals(),
545 Teuchos::as<float>(actualSpinner->singleStep()),
551 QDoubleSpinBox* actualSpinner = (QDoubleSpinBox*)spinBox;
553 actualSpinner->decimals(),
556 Teuchos::as<double>(actualSpinner->singleStep()),
563 const QValidator* validator,
568 QCOMPARE(validator->validate(val20,pos), QValidator::Invalid);
569 QCOMPARE(validator->validate(valneg1,pos), QValidator::Invalid);
574 const QValidator* validator,
579 QCOMPARE(validator->validate(val20,pos), QValidator::Intermediate);
580 QCOMPARE(validator->validate(valneg1,pos), QValidator::Invalid);
581 const QDoubleValidator* doubleValidator = (QDoubleValidator*)validator;
583 doubleValidator->decimals(),
589 const QValidator* validator,
594 QCOMPARE(validator->validate(val20,pos), QValidator::Intermediate);
595 QCOMPARE(validator->validate(valneg1,pos), QValidator::Invalid);
596 const QDoubleValidator* doubleValidator = (QDoubleValidator*)validator;
598 doubleValidator->decimals(),
611 QString valneg1(
"-1");
615 QAbstractSpinBox* spinner = createDefaultSpinner<T>();
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);
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);
637 valApplyTestTemplate<int>();
638 valApplyTestTemplate<short>();
639 valApplyTestTemplate<double>();
640 valApplyTestTemplate<float>();
645 validParameters->set(
"Don't care",
"don't care");
651 QCOMPARE(m2->width(),673);
652 QCOMPARE(m2->height(),823);
653 QCOMPARE(m2->x(),30);
654 QCOMPARE(m2->y(),99);
661 getParametersFromXmlFile(
"loadtest.xml");
673 QVariant data = model->
data(
674 steveIndex.sibling(steveIndex.row(), 1), Qt::DisplayRole);
675 QCOMPARE(data.toString(), QString(
"4"));
680 twodIndex.sibling(twodIndex.row(), 1), Qt::DisplayRole);
681 QCOMPARE(data.toString(), QString(
"Click to view 2D Array"));
686 listIndex.sibling(listIndex.row(), 1), Qt::DisplayRole);
687 QCOMPARE(data.toString(), QString(
""));
703 #include "GUI_UnitTests.moc"
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...
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
RCP< const ParameterList > getCurrentParameters()
Get a ParameterList containing all of the parameters at their current settings.
#define VERIFY_HIDDEN_ROW(INDEX)
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)
#define VERIFY_SHOWN_ROW(INDEX)
TwoDArray< S > getTwoDArray(const QModelIndex &index)
Gets the TwoDArray for a particular TreeItem.
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 >()
void validatorApplierTests()
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
bool nonnull(const boost::shared_ptr< T > &p)
static void applyToSpinBox(RCP< const EnhancedNumberValidator< S > > validator, QSpinBox *spinBox)
Applied attributes of the validator to the spin box.
QAbstractSpinBox * createDefaultSpinner< float >()
void assertSpinnerDefaults(QAbstractSpinBox *spinBox)
static void applyToLineEdit(RCP< const EnhancedNumberValidator< S > > validator, QLineEdit *lineEdit)
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