Classes derived from QComboBox and KConfigDialog

Petri Damsten petri.damsten at iki.fi
Fri Jun 29 13:17:09 BST 2007


Hi,

I was advised to post this to kde-core-devel (instead of kde-devel)

Problem:
I have QComboBox derived class that has user property defined like this:
Q_PROPERTY(QString language READ language WRITE setLanguage USER true)

I want to use this KMFLanguageComboBox in KConfigDialog but 
KConfigDialogManager seems to give QComboBox (and derived classes) a special 
handling and seems to always return currentText/currentIndex which is not 
what I wanted. 

Patch:
Checks the user property first and handle QComboBox specially after that.

Index: kdeui/dialogs/kconfigdialogmanager.cpp
===================================================================
--- kdeui/dialogs/kconfigdialogmanager.cpp      (revision 679959)
+++ kdeui/dialogs/kconfigdialogmanager.cpp      (working copy)
@@ -82,6 +82,7 @@
   if ( s_propertyMap->isEmpty() ) {
     s_propertyMap->insert( "KButtonGroup", "current" );
     s_propertyMap->insert( "KColorButton", "color" );
+    s_propertyMap->insert( "KColorCombo", "color" );
     //s_propertyMap->insert( "KUrlRequester", "url" );
     //s_propertyMap->insert( "KUrlComboRequester", "url" );
   }
@@ -120,6 +121,7 @@
     s_changedMap->insert( "KFontRequester", SIGNAL(fontSelected(const QFont 
&)));
     s_changedMap->insert( "KFontChooser",  SIGNAL(fontSelected(const QFont 
&)));
     s_changedMap->insert( "KHistoryCombo", SIGNAL(activated (int)));
+    s_changedMap->insert( "KColorCombo", SIGNAL(activated (const QColor &)));

     s_changedMap->insert( "KColorButton", SIGNAL(changed(const QColor &)));
     s_changedMap->insert( "KDatePicker", SIGNAL(dateSelected (QDate)));
@@ -412,23 +414,22 @@
     return;
   }

-  QComboBox *cb = qobject_cast<QComboBox *>(w);
-  if (cb) {
-    if ( cb->isEditable() )
-    {
-      int i = cb->findText(v.toString());
-      if (i != -1)
-          cb->setCurrentIndex(i);
-      else
-          cb->setEditText(v.toString());
-    } else {
-      cb->setCurrentIndex( v.toInt() );
-    }
-    return;
-  }
-
   QByteArray userproperty = getUserProperty( w );
   if ( userproperty.isEmpty() ) {
+    QComboBox *cb = qobject_cast<QComboBox *>(w);
+    if (cb) {
+        if ( cb->isEditable() )
+        {
+            int i = cb->findText(v.toString());
+            if (i != -1)
+                cb->setCurrentIndex(i);
+            else
+                cb->setEditText(v.toString());
+        } else {
+            cb->setCurrentIndex( v.toInt() );
+        }
+        return;
+    }
     kWarning(178) << w->metaObject()->className() << " widget not handled!" 
<< endl;
     return;
   }
@@ -441,15 +442,15 @@
   if (bg && bg->checkedButton())
     return QVariant(bg->id(bg->checkedButton()));

-  QComboBox *cb = qobject_cast<QComboBox *>(w);
-  if (cb) {
-    if ( cb->isEditable() )
-      return QVariant(cb->currentText());
-    else
-      return QVariant(cb->currentIndex());
-  }
   QByteArray userproperty = getUserProperty( w );
   if ( userproperty.isEmpty() ) {
+    QComboBox *cb = qobject_cast<QComboBox *>(w);
+    if (cb) {
+        if ( cb->isEditable() )
+            return QVariant(cb->currentText());
+        else
+            return QVariant(cb->currentIndex());
+    }
     kWarning(178) << w->metaObject()->className() << " widget not handled!" 
<< endl;
     return QVariant();
   }

Petri

-- 
"Like car accidents, most hardware problems are due to driver error."
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20070629/f51747b0/attachment.sig>


More information about the kde-core-devel mailing list