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

List:       kde-commits
Subject:    koffice/libs/flake
From:       Thomas Zander <zander () kde ! org>
Date:       2011-01-04 10:17:59
Message-ID: 20110104101759.5B6D1AC8B0 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1211501 by zander:

Try to add a new setter

 M  +47 -4     KoResourceManager.cpp  
 M  +2 -0      KoResourceManager.h  


--- trunk/koffice/libs/flake/KoResourceManager.cpp #1211500:1211501
@@ -19,19 +19,35 @@
    Boston, MA 02110-1301, USA.
  */
 #include "KoResourceManager.h"
+#include "KoShape.h"
+#include "KoLineBorder.h"
 
 #include <QVariant>
+#include <QMetaObject>
 #include <KUndoStack>
 #include <KDebug>
 
-#include "KoShape.h"
-#include "KoLineBorder.h"
-
 class KoResourceManager::Private
 {
 public:
+    void fetchLazy(int key, const KoResourceManager *parent) {
+        Q_ASSERT(lazyResources.contains(key));
+        Slot slot = lazyResources.value(key);
+        lazyResources.remove(key);
+
+        KoResourceManager *rm = const_cast<KoResourceManager*>(parent);
+        slot.object->metaObject()->invokeMethod(slot.object, slot.slot,
+            Qt::DirectConnection, Q_ARG(KoResourceManager *, rm));
+    }
+
+
     QHash<int, QVariant> resources;
+    struct Slot {
+        QObject *object;
+        const char *slot;
 };
+    QHash<int, Slot> lazyResources;
+};
 
 KoResourceManager::KoResourceManager(QObject *parent)
         : QObject(parent),
@@ -53,12 +69,15 @@
         d->resources[key] = value;
     } else {
         d->resources.insert(key, value);
+        d->lazyResources.remove(key);
     }
     emit resourceChanged(key, value);
 }
 
 QVariant KoResourceManager::resource(int key) const
 {
+    if (d->lazyResources.contains(key))
+        d->fetchLazy(key, this);
     if (!d->resources.contains(key)) {
         QVariant empty;
         return empty;
@@ -89,6 +108,8 @@
 
 KoColor KoResourceManager::koColorResource(int key) const
 {
+    if (d->lazyResources.contains(key))
+        d->fetchLazy(key, this);
     if (! d->resources.contains(key)) {
         KoColor empty;
         return empty;
@@ -118,6 +139,8 @@
 
 KoShape *KoResourceManager::koShapeResource(int key) const
 {
+    if (d->lazyResources.contains(key))
+        d->fetchLazy(key, this);
     if (! d->resources.contains(key))
         return 0;
 
@@ -141,6 +164,8 @@
 
 KoUnit KoResourceManager::unitResource(int key) const
 {
+    if (d->lazyResources.contains(key))
+        d->fetchLazy(key, this);
     return resource(key).value<KoUnit>();
 }
 
@@ -175,6 +200,8 @@
 
 bool KoResourceManager::boolResource(int key) const
 {
+    if (d->lazyResources.contains(key))
+        d->fetchLazy(key, this);
     if (! d->resources.contains(key))
         return false;
     return d->resources[key].toBool();
@@ -182,6 +209,8 @@
 
 int KoResourceManager::intResource(int key) const
 {
+    if (d->lazyResources.contains(key))
+        d->fetchLazy(key, this);
     if (! d->resources.contains(key))
         return 0;
     return d->resources[key].toInt();
@@ -189,6 +218,8 @@
 
 QString KoResourceManager::stringResource(int key) const
 {
+    if (d->lazyResources.contains(key))
+        d->fetchLazy(key, this);
     if (! d->resources.contains(key)) {
         QString empty;
         return empty;
@@ -198,6 +229,8 @@
 
 QSizeF KoResourceManager::sizeResource(int key) const
 {
+    if (d->lazyResources.contains(key))
+        d->fetchLazy(key, this);
     if (! d->resources.contains(key)) {
         QSizeF empty;
         return empty;
@@ -207,7 +240,7 @@
 
 bool KoResourceManager::hasResource(int key) const
 {
-    return d->resources.contains(key);
+    return d->resources.contains(key) && d->lazyResources.contains(key);
 }
 
 void KoResourceManager::clearResource(int key)
@@ -219,6 +252,16 @@
     emit resourceChanged(key, empty);
 }
 
+void KoResourceManager::setLazyResourceSlot(int key, QObject *object, const char *slot)
+{
+    if (d->resources.contains(key) || d->lazyResources.contains(key))
+        return;
+    KoResourceManager::Private::Slot target;
+    target.object = object;
+    target.slot = slot;
+    d->lazyResources.insert(key, target);
+}
+
 KUndoStack *KoResourceManager::undoStack() const
 {
     if (!hasResource(KoDocumentResource::UndoStack))
--- trunk/koffice/libs/flake/KoResourceManager.h #1211500:1211501
@@ -286,6 +286,8 @@
      */
     void clearResource(int key);
 
+    void setLazyResourceSlot(int key, QObject *object, const char *slot);
+
     KUndoStack *undoStack() const;
     void setUndoStack(KUndoStack *undoStack);
 
[prev in list] [next in list] [prev in thread] [next in thread] 

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