summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Astals Cid <tsdgeos@terra.es>2012-02-23 22:12:45 (GMT)
committerAlbert Astals Cid <tsdgeos@terra.es>2012-02-23 22:13:37 (GMT)
commitc27b939ac971f23e8cf8950e76c3f2745c634d72 (patch)
tree59824b31b078fbad3e0d608f8279e1f57436d49f
parent87fe58ffeea83f5eac4d869e8fef4b1015c04d38 (diff)
Fix KConfigDialogManager fails to handle subclasses of QComboBox with custom property
BUGS: 293702 REVIEW: 103909 Acked by Christoph Feck
-rw-r--r--kdeui/dialogs/kconfigdialogmanager.cpp24
-rw-r--r--kdeui/tests/CMakeLists.txt1
-rw-r--r--kdeui/tests/kconfigdialog_unittest.cpp132
3 files changed, 151 insertions, 6 deletions
diff --git a/kdeui/dialogs/kconfigdialogmanager.cpp b/kdeui/dialogs/kconfigdialogmanager.cpp
index 18bc44e..dfa793d 100644
--- a/kdeui/dialogs/kconfigdialogmanager.cpp
+++ b/kdeui/dialogs/kconfigdialogmanager.cpp
@@ -418,6 +418,18 @@ QByteArray KConfigDialogManager::getUserProperty(const QWidget *widget) const
return QByteArray(); //no USER property
}
}
+ const QComboBox *cb = qobject_cast<const QComboBox *>(widget);
+ if (cb) {
+ const char *qcomboUserPropertyName = cb->QComboBox::metaObject()->userProperty().name();
+ const int qcomboUserPropertyIndex = qcomboUserPropertyName ? cb->QComboBox::metaObject()->indexOfProperty(qcomboUserPropertyName) : -1;
+ const char *widgetUserPropertyName = widget->metaObject()->userProperty().name();
+ const int widgetUserPropertyIndex = widgetUserPropertyName ? cb->metaObject()->indexOfProperty(widgetUserPropertyName) : -1;
+
+ if (qcomboUserPropertyIndex == widgetUserPropertyIndex) {
+ return QByteArray(); // use the q/kcombobox special code
+ }
+ }
+
return s_propertyMap->value( widget->metaObject()->className() );
}
@@ -448,6 +460,9 @@ void KConfigDialogManager::setProperty(QWidget *w, const QVariant &v)
QByteArray userproperty = getCustomProperty(w);
if (userproperty.isEmpty()) {
+ userproperty = getUserProperty(w);
+ }
+ if (userproperty.isEmpty()) {
QComboBox *cb = qobject_cast<QComboBox *>(w);
if (cb) {
if (cb->isEditable()) {
@@ -464,9 +479,6 @@ void KConfigDialogManager::setProperty(QWidget *w, const QVariant &v)
}
}
if (userproperty.isEmpty()) {
- userproperty = getUserProperty(w);
- }
- if (userproperty.isEmpty()) {
kWarning(d->debugArea()) << w->metaObject()->className() << " widget not handled!";
return;
}
@@ -482,6 +494,9 @@ QVariant KConfigDialogManager::property(QWidget *w) const
QByteArray userproperty = getCustomProperty(w);
if (userproperty.isEmpty()) {
+ userproperty = getUserProperty(w);
+ }
+ if (userproperty.isEmpty()) {
QComboBox *cb = qobject_cast<QComboBox *>(w);
if (cb) {
if (cb->isEditable()) {
@@ -492,9 +507,6 @@ QVariant KConfigDialogManager::property(QWidget *w) const
}
}
if (userproperty.isEmpty()) {
- userproperty = getUserProperty(w);
- }
- if (userproperty.isEmpty()) {
kWarning(d->debugArea()) << w->metaObject()->className() << " widget not handled!";
return QVariant();
}
diff --git a/kdeui/tests/CMakeLists.txt b/kdeui/tests/CMakeLists.txt
index 63788f6..c8b8c85 100644
--- a/kdeui/tests/CMakeLists.txt
+++ b/kdeui/tests/CMakeLists.txt
@@ -71,6 +71,7 @@ KDEUI_UNIT_TESTS(
ktimecomboboxtest
kdatecomboboxtest
kdatetimeedittest
+ kconfigdialog_unittest
)
KDEUI_PROXYMODEL_TESTS(
diff --git a/kdeui/tests/kconfigdialog_unittest.cpp b/kdeui/tests/kconfigdialog_unittest.cpp
new file mode 100644
index 0000000..79c35e4
--- /dev/null
+++ b/kdeui/tests/kconfigdialog_unittest.cpp
@@ -0,0 +1,132 @@
+/* This file is part of the KDE libraries
+
+ Copyright (c) 2012 Albert Astals Cid <aacid@kde.org>
+
+ 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 <qtest_kde.h>
+#include <qtestevent.h>
+
+#include <kconfigdialog.h>
+#include <kconfigskeleton.h>
+#include <kcombobox.h>
+#include <kcolorcombo.h>
+
+class ComboBoxPage : public QWidget
+{
+public:
+ ComboBoxPage()
+ {
+ colorCombo = new KColorCombo(this);
+ colorCombo->setObjectName("kcfg_Color");
+ colorCombo->setColor(Qt::red);
+
+ enumCombo = new KComboBox(this);
+ enumCombo->setObjectName("kcfg_Enum");
+ enumCombo->addItems(QStringList() << "A" << "B" << "C");
+
+ textCombo = new KComboBox(this);
+ textCombo->setObjectName("kcfg_Text");
+ textCombo->setEditable(true);
+ textCombo->addItems(QStringList() << "A" << "B" << "C");
+ }
+
+ KColorCombo *colorCombo;
+ KComboBox *enumCombo;
+ KComboBox *textCombo;
+};
+
+class ComboSettings : public KConfigSkeleton
+{
+public:
+ ComboSettings()
+ {
+ colorItem = new ItemColor( currentGroup(), QLatin1String( "Color" ), color, Qt::white );
+ addItem( colorItem, QLatin1String( "Color" ) );
+
+ QList<ItemEnum::Choice2> textValues;
+ {
+ ItemEnum::Choice2 choice;
+ choice.name = QLatin1String("A");
+ textValues.append( choice );
+ }
+ {
+ ItemEnum::Choice2 choice;
+ choice.name = QLatin1String("B");
+ textValues.append( choice );
+ }
+ {
+ ItemEnum::Choice2 choice;
+ choice.name = QLatin1String("C");
+ textValues.append( choice );
+ }
+ enumItem = new ItemEnum( currentGroup(), QLatin1String( "Enum" ), enumIndex, textValues, 1 );
+ addItem( enumItem, QLatin1String( "Enum" ) );
+
+ stringItem = new ItemString( currentGroup(), QLatin1String( "Text" ), string, QLatin1String( "hh:mm" ) );
+ addItem( stringItem, QLatin1String( "Text" ) );
+ }
+
+ ItemColor *colorItem;
+ QColor color;
+
+ ItemEnum *enumItem;
+ int enumIndex;
+
+ ItemString *stringItem;
+ QString string;
+};
+
+class KConfigDialog_UnitTest : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void combosTest()
+ {
+ ComboSettings *skeleton = new ComboSettings();
+ KConfigDialog *dialog = new KConfigDialog(0, "settings", skeleton);
+ ComboBoxPage *page = new ComboBoxPage();
+
+ QCOMPARE(page->colorCombo->color(), QColor(Qt::red));
+ QCOMPARE(page->enumCombo->currentIndex(), 0);
+ QCOMPARE(page->textCombo->currentText(), QString("A"));
+
+ dialog->addPage(page, "General");
+
+ QCOMPARE(page->colorCombo->color(), QColor(Qt::white));
+ QCOMPARE(page->enumCombo->currentIndex(), 1);
+ QCOMPARE(page->textCombo->currentText(), QLatin1String( "hh:mm" ));
+
+ page->colorCombo->setColor(Qt::blue);
+ page->enumCombo->setCurrentIndex(2);
+ page->textCombo->setCurrentIndex(2);
+
+ QMetaObject::invokeMethod(dialog, "applyClicked");
+ QCOMPARE(skeleton->colorItem->property().value<QColor>(), QColor(Qt::blue));
+ QCOMPARE(skeleton->enumItem->property().toInt(), 2);
+ QCOMPARE(skeleton->stringItem->property().toString(), QLatin1String("C"));
+
+ delete dialog;
+ delete skeleton;
+ }
+
+};
+
+QTEST_KDEMAIN(KConfigDialog_UnitTest, GUI)
+
+#include "kconfigdialog_unittest.moc"