[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    KShortcut and properties
From:       Jakub Stachowski <qbast () go2 ! pl>
Date:       2007-04-14 17:27:38
Message-ID: 200704141927.38451.qbast () go2 ! pl
[Download RAW message or body]

Hello,

KAction has two properties of type KShortcut: shortcut and globalShortcut. The 
problem is that KShortcut is not registered with Qt metatype system so it 
cannot really be used as type of property. This causes bug in 
KXMLGUIFactory::configureAction - it reads shortcuts from .ui file ( 
ActionProperties node) and tries to set them using setProperty("shortcut",
[QString with shortcut definition]. This will fail because bug mentioned 
above and because QString won't be casted to KShortcut automatically.
Attached is patch that fixes both KShortcut-as-property problem (did i put 
qRegisterMetaType calls in proper places?) and casting in KXMLGUIFactory.

["kshortcut-qmeta.diff" (text/x-diff)]

Index: shortcuts/kshortcut.cpp
===================================================================
--- shortcuts/kshortcut.cpp	(wersja 652527)
+++ shortcuts/kshortcut.cpp	(kopia robocza)
@@ -30,19 +30,23 @@
 #include "kglobal.h"
 #include "klocale.h"
 
+//static int id=qMetaTypeId<KShortcut>();
 
 KShortcut::KShortcut()
 {
+    qRegisterMetaType<KShortcut>();
 }
 
 KShortcut::KShortcut(const QKeySequence &primary)
 {
+    qRegisterMetaType<KShortcut>();
     if (!primary.isEmpty())
         append(primary);
 }
 
 KShortcut::KShortcut(const QKeySequence &primary, const QKeySequence &alternate)
 {
+    qRegisterMetaType<KShortcut>();
     if (!primary.isEmpty())
         append(primary);
     if (!alternate.isEmpty())
@@ -51,6 +55,7 @@
 
 KShortcut::KShortcut(int keyQtPri, int keyQtAlt)
 {
+    qRegisterMetaType<KShortcut>();
     if (keyQtPri)
         append(keyQtPri);
     if (keyQtAlt)
@@ -59,6 +64,7 @@
 
 KShortcut::KShortcut(const QString &s)
 {
+    qRegisterMetaType<KShortcut>();
     if (s == QLatin1String("none"))
         return;
 
@@ -78,6 +84,7 @@
 KShortcut::KShortcut(const QList<QKeySequence> &seqs)
     : QList<QKeySequence>(seqs)
 {
+    qRegisterMetaType<KShortcut>();
 }
 
 void KShortcut::setPrimary(const QKeySequence &newPrimary)
Index: shortcuts/kshortcut.h
===================================================================
--- shortcuts/kshortcut.h	(wersja 652527)
+++ shortcuts/kshortcut.h	(kopia robocza)
@@ -31,6 +31,7 @@
 
 #include <QtCore/QList>
 #include <QtGui/QKeySequence>
+#include <QMetaType>
 
 class KShortcutPrivate;
 
@@ -164,4 +165,6 @@
     return hash;
 }
 
+Q_DECLARE_METATYPE(KShortcut)
+
 #endif // KSHORTCUT_H
Index: xmlgui/kxmlguifactory.cpp
===================================================================
--- xmlgui/kxmlguifactory.cpp	(wersja 652527)
+++ xmlgui/kxmlguifactory.cpp	(kopia robocza)
@@ -531,9 +531,10 @@
         propertyValue = QVariant( attribute.value().toInt() );
     else if ( propertyType == QVariant::UInt )
         propertyValue = QVariant( attribute.value().toUInt() );
+    else if ( propertyType == QVariant::UserType && action->property( \
attrName.toLatin1() ).userType() == qMetaTypeId<KShortcut>() ) +	propertyValue = \
QVariant::fromValue( KShortcut( attribute.value() ) ) ;  else
         propertyValue = QVariant( attribute.value() );
-
     action->setProperty( attrName.toLatin1(), propertyValue );
 }
 



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic