tests/auto/qdialogbuttonbox/tst_qdialogbuttonbox.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
   719 }
   719 }
   720 
   720 
   721 static int softKeyCount(QWidget *widget)
   721 static int softKeyCount(QWidget *widget)
   722 {
   722 {
   723     int softkeyCount = 0;
   723     int softkeyCount = 0;
       
   724 #ifndef QT_NO_ACTION
   724     QList<QAction *> actions = widget->actions();
   725     QList<QAction *> actions = widget->actions();
   725     foreach (QAction *action, actions) {
   726     foreach (QAction *action, actions) {
   726         if (action->softKeyRole() != QAction::NoSoftKey)
   727         if (action->softKeyRole() != QAction::NoSoftKey)
   727             softkeyCount++;
   728             softkeyCount++;
   728     }
   729     }
       
   730 #endif
   729     return softkeyCount;
   731     return softkeyCount;
   730 }
   732 }
   731 
   733 
   732 void tst_QDialogButtonBox::testS60SoftKeys()
   734 void tst_QDialogButtonBox::testS60SoftKeys()
   733 {
   735 {
   735     QDialog dialog(0);
   737     QDialog dialog(0);
   736     QDialogButtonBox buttonBox(&dialog);
   738     QDialogButtonBox buttonBox(&dialog);
   737     buttonBox.setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
   739     buttonBox.setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
   738     dialog.show();
   740     dialog.show();
   739 
   741 
       
   742 #ifndef QT_NO_ACTION
   740     QCOMPARE( softKeyCount(&dialog), 2);
   743     QCOMPARE( softKeyCount(&dialog), 2);
       
   744 #endif
   741 
   745 
   742     QDialog dialog2(0);
   746     QDialog dialog2(0);
   743     QDialogButtonBox buttonBox2(&dialog2);
   747     QDialogButtonBox buttonBox2(&dialog2);
   744     buttonBox2.setStandardButtons(QDialogButtonBox::Cancel);
   748     buttonBox2.setStandardButtons(QDialogButtonBox::Cancel);
   745     dialog2.show();
   749     dialog2.show();
   746 
   750 
       
   751 #ifndef QT_NO_ACTION
   747     QCOMPARE( softKeyCount(&dialog2), 1);
   752     QCOMPARE( softKeyCount(&dialog2), 1);
       
   753 #endif
   748 
   754 
   749 #else
   755 #else
   750     QSKIP("S60-specific test", SkipAll );
   756     QSKIP("S60-specific test", SkipAll );
   751 #endif
   757 #endif
   752 }
   758 }
   757     QDialog dialog;
   763     QDialog dialog;
   758     QDialogButtonBox *buttonBox = new QDialogButtonBox;
   764     QDialogButtonBox *buttonBox = new QDialogButtonBox;
   759     buttonBox->addButton(QDialogButtonBox::Ok);
   765     buttonBox->addButton(QDialogButtonBox::Ok);
   760     buttonBox->addButton(QDialogButtonBox::Cancel);
   766     buttonBox->addButton(QDialogButtonBox::Cancel);
   761 
   767 
       
   768 #ifndef QT_NO_ACTION
   762     QCOMPARE(softKeyCount(&dialog), 0);
   769     QCOMPARE(softKeyCount(&dialog), 0);
   763     QCOMPARE(softKeyCount(buttonBox), 2);
   770     QCOMPARE(softKeyCount(buttonBox), 2);
       
   771 #endif
   764 
   772 
   765     // Were the softkeys re-parented correctly?
   773     // Were the softkeys re-parented correctly?
   766     dialog.setLayout(new QVBoxLayout);
   774     dialog.setLayout(new QVBoxLayout);
   767     dialog.layout()->addWidget(buttonBox);
   775     dialog.layout()->addWidget(buttonBox);
       
   776 #ifndef QT_NO_ACTION
   768     QCOMPARE(softKeyCount(&dialog), 2);
   777     QCOMPARE(softKeyCount(&dialog), 2);
   769     QCOMPARE(softKeyCount(buttonBox), 0);
   778     QCOMPARE(softKeyCount(buttonBox), 0);
       
   779 #endif
   770 
   780 
   771     // Softkeys are only added to QDialog, not QWidget
   781     // Softkeys are only added to QDialog, not QWidget
   772     QWidget *nested = new QWidget;
   782     QWidget *nested = new QWidget;
   773     nested->setLayout(new QVBoxLayout);
   783     nested->setLayout(new QVBoxLayout);
   774     nested->layout()->addWidget(buttonBox);
   784     nested->layout()->addWidget(buttonBox);
       
   785 #ifndef QT_NO_ACTION
   775     QCOMPARE(softKeyCount(nested), 0);
   786     QCOMPARE(softKeyCount(nested), 0);
   776     QCOMPARE(softKeyCount(buttonBox), 2);
   787     QCOMPARE(softKeyCount(buttonBox), 2);
       
   788 #endif
   777 }
   789 }
   778 #endif
   790 #endif
   779 
   791 
   780 void tst_QDialogButtonBox::testDefaultButton()
   792 void tst_QDialogButtonBox::testDefaultButton()
   781 {
   793 {