Le vendredi 4 juillet 2014 08:13:58 Kevin Ottens a écrit : > On Thursday 03 July 2014 19:50:35 laurent Montel wrote: > > Hi, > > During kdepim porting I saw that it was not possible to add a ActionButton > > as QButtonBox is protected. > > => we can do it if we create a derived class. > > But it’s not a very easy method for just add a button. > > > > I would like to add a new method to do it. > > I created a patch for it. > > > > What do you think about it ? > > > > (Example when we need to add a ActionButton, it’s when we have a old > > "User1" button). > > Looks OK to me. Will it come with an automated test? We should get serious > about that in our reviews as well, and I know you've the necessary > testing-fu to get this simple case properly tested. ;-)
Yes indeed you’re right. I create a autotest there was not an autotest for it. It doesn’t look at all kpagedialog class but look at code that I added (and initialize state). Regards. > Regards. -- Laurent Montel | [email protected] | KDE/Qt Senior Software Engineer KDAB (France) S.A.S., a KDAB Group company Tel. France +33 (0)4 90 84 08 53, http://www.kdab.fr
diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 9f6fe6d..7ba9cfe 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -11,5 +11,6 @@ ecm_add_tests( kselectaction_unittest.cpp ktimecomboboxtest.cpp kmessagewidgetautotest.cpp + kpagedialogautotest.cpp LINK_LIBRARIES Qt5::Test KF5::WidgetsAddons ) diff --git a/autotests/kpagedialogautotest.cpp b/autotests/kpagedialogautotest.cpp index 69a08b9..37be428 100644 --- a/autotests/kpagedialogautotest.cpp +++ b/autotests/kpagedialogautotest.cpp @@ -1,5 +1,76 @@ +/* + Copyright 2014 Laurent Montel <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + #include "kpagedialogautotest.h" +#include <kpagedialog.h> + +#include <QDialogButtonBox> +#include <QPushButton> +#include <QtTest/QtTest> + +QTEST_MAIN(KPageDialogAutoTest) KPageDialogAutoTest::KPageDialogAutoTest() { } + +void KPageDialogAutoTest::shouldHaveDefaultValuesOnCreation() +{ + KPageDialog page; + QDialogButtonBox *dialogbuttonbox = page.findChild<QDialogButtonBox *>(QLatin1String("buttonbox")); + QVERIFY(dialogbuttonbox); + QDialogButtonBox::StandardButtons standardButton = dialogbuttonbox->standardButtons(); + QDialogButtonBox::StandardButtons defaultButton = QDialogButtonBox::Ok | QDialogButtonBox::Cancel; + QCOMPARE(standardButton, defaultButton); +} + +void KPageDialogAutoTest::shouldAddAnActionButton() +{ + KPageDialog page; + QDialogButtonBox *dialogbuttonbox = page.findChild<QDialogButtonBox *>(QLatin1String("buttonbox")); + QPushButton *actionButton = new QPushButton(QLatin1String("Action1")); + page.addActionButton(actionButton); + QCOMPARE(dialogbuttonbox->buttons().count(), 3); + QVERIFY(dialogbuttonbox->buttons().contains(actionButton)); +} + +void KPageDialogAutoTest::shouldAddTwoActionButton() +{ + KPageDialog page; + QDialogButtonBox *dialogbuttonbox = page.findChild<QDialogButtonBox *>(QLatin1String("buttonbox")); + QPushButton *actionButton = new QPushButton(QLatin1String("Action1")); + page.addActionButton(actionButton); + + QPushButton *actionButton2 = new QPushButton(QLatin1String("Action2")); + page.addActionButton(actionButton2); + + QCOMPARE(dialogbuttonbox->buttons().count(), 4); +} + +void KPageDialogAutoTest::shouldNotAddTwoSameActionButton() +{ + KPageDialog page; + QDialogButtonBox *dialogbuttonbox = page.findChild<QDialogButtonBox *>(QLatin1String("buttonbox")); + QPushButton *actionButton = new QPushButton(QLatin1String("Action1")); + page.addActionButton(actionButton); + + page.addActionButton(actionButton); + QCOMPARE(dialogbuttonbox->buttons().count(), 3); +} + diff --git a/autotests/kpagedialogautotest.h b/autotests/kpagedialogautotest.h index d32c6a8..6406da3 100644 --- a/autotests/kpagedialogautotest.h +++ b/autotests/kpagedialogautotest.h @@ -1,10 +1,38 @@ +/* + Copyright 2014 Laurent Montel <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + #ifndef KPAGEDIALOGAUTOTEST_H #define KPAGEDIALOGAUTOTEST_H -class KPageDialogAutoTest +#include <QObject> + +class KPageDialogAutoTest : public QObject { + Q_OBJECT public: KPageDialogAutoTest(); + +private Q_SLOTS: + void shouldHaveDefaultValuesOnCreation(); + void shouldAddAnActionButton(); + void shouldAddTwoActionButton(); + void shouldNotAddTwoSameActionButton(); }; #endif // KPAGEDIALOGAUTOTEST_H diff --git a/src/kpagedialog.cpp b/src/kpagedialog.cpp index b9096ca..b28873b 100644 --- a/src/kpagedialog.cpp +++ b/src/kpagedialog.cpp @@ -35,6 +35,7 @@ KPageDialog::KPageDialog(QWidget *parent, Qt::WindowFlags flags) Q_D(KPageDialog); d->mPageWidget = new KPageWidget(this); d->mButtonBox = new QDialogButtonBox(this); + d->mButtonBox->setObjectName(QLatin1String("buttonbox")); d->mButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); d->init(); @@ -49,6 +50,7 @@ KPageDialog::KPageDialog(KPageWidget *widget, QWidget *parent, Qt::WindowFlags f widget->setParent(this); d->mPageWidget = widget; d->mButtonBox = new QDialogButtonBox(this); + d->mButtonBox->setObjectName(QLatin1String("buttonbox")); d->mButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); d->init(); @@ -66,6 +68,7 @@ KPageDialog::KPageDialog(KPageDialogPrivate &dd, KPageWidget *widget, QWidget *p d->mPageWidget = new KPageWidget(this); } d->mButtonBox = new QDialogButtonBox(this); + d->mButtonBox->setObjectName(QLatin1String("buttonbox")); d->mButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); d->init(); } @@ -134,6 +137,11 @@ QPushButton *KPageDialog::button(QDialogButtonBox::StandardButton which) const return d_func()->mButtonBox->button(which); } +void KPageDialog::addActionButton(QAbstractButton *button) +{ + d_func()->mButtonBox->addButton(button, QDialogButtonBox::ActionRole); +} + KPageWidget *KPageDialog::pageWidget() { return d_func()->mPageWidget; diff --git a/src/kpagedialog.h b/src/kpagedialog.h index 09691a8..493698f 100644 --- a/src/kpagedialog.h +++ b/src/kpagedialog.h @@ -196,6 +196,11 @@ public: */ QPushButton *button(QDialogButtonBox::StandardButton which) const; + /** + * Set an action button. + */ + void addActionButton(QAbstractButton *button); + Q_SIGNALS: /** * This signal is emitted whenever the current page has changed.
_______________________________________________ Kde-frameworks-devel mailing list [email protected] https://mail.kde.org/mailman/listinfo/kde-frameworks-devel
