]> vaikene.ee Git - evaf/commitdiff
Replaced QPointer<> with QWeakPointer<>
authorEnar Väikene <enar@vaikene.net>
Wed, 19 Oct 2011 09:06:18 +0000 (12:06 +0300)
committerEnar Väikene <enar@vaikene.net>
Wed, 19 Oct 2011 09:06:18 +0000 (12:06 +0300)
src/libs/Common/eventqueue.cpp
src/libs/Common/eventqueue.h
src/libs/Common/registry.cpp
src/libs/Common/registry.h
src/libs/Common/version.h
src/plugins/SdiWindow/sdiwindow.cpp
src/plugins/SdiWindow/sdiwindow.h
src/plugins/SdiWindow/version.h

index bbf30ed8ae2f12d1ff213ea6845f3517c8781a91..33e73c0d6e54e26888f3fd1e7651f3fe1435c5a8 100644 (file)
@@ -67,20 +67,20 @@ bool EventQueue::event(QEvent * e)
         }
 
         // Send the event to all the subscribers
-        QHash<uint, QList<QPointer<QObject> > >::const_iterator subscribersIt = mSubscribers.constFind(id);
+        QHash<uint, QVector<QWeakPointer<QObject> > >::const_iterator subscribersIt = mSubscribers.constFind(id);
         if (subscribersIt != mSubscribers.constEnd()) {
-            QList<QPointer<QObject> > subscribers = *subscribersIt;
+            QVector<QWeakPointer<QObject> > subscribers = *subscribersIt;
             int sz = subscribers.size();
             for (int i = 0; i < sz; ++i) {
 
                 // Get the subscriber object and make sure that it is still alive
-                QPointer<QObject> obj = subscribers.at(i);
+                QWeakPointer<QObject> obj = subscribers.at(i);
                 if (obj.isNull()) {
                     continue;
                 }
 
                 // Notify the subscriber
-                bool rval = QCoreApplication::sendEvent(obj, e);
+                bool rval = QCoreApplication::sendEvent(obj.data(), e);
 
                 if (rval) {
                     // The event was consumed and should be sent to any other subscribers
@@ -146,7 +146,15 @@ void EventQueue::unsubscribeEvent(uint id, QObject * obj)
     if (mEvents.constFind(id) == mEvents.constEnd())
         return;
 
-    mSubscribers[id].removeAll(obj);
+    // Remove from the list of subscribers
+    QVector<QWeakPointer<QObject> >::iterator it = mSubscribers[id].begin();
+    QVector<QWeakPointer<QObject> >::iterator e = mSubscribers[id].end();
+    while (it != e) {
+        if (!it->isNull() && it->data() == obj)
+            it = mSubscribers[id].erase(it);
+        else
+            ++it;
+    }
 }
 
 void EventQueue::broadcastEvent(Event * event)
index 92bcb06da4fa2e7920be2223018aaa085bd57a02..b02937692129f83c74fc3151d392e7c70e180718 100644 (file)
@@ -25,8 +25,8 @@
 #include <QObject>
 #include <QString>
 #include <QHash>
-#include <QList>
-#include <QPointer>
+#include <QVector>
+#include <QWeakPointer>
 
 
 namespace eVaf {
@@ -75,7 +75,7 @@ private: // Members
     QHash<uint, QString> mEvents;
 
     /// List of subscribers
-    QHash<uint, QList<QPointer<QObject> > > mSubscribers;
+    QHash<uint, QVector<QWeakPointer<QObject> > > mSubscribers;
 
 };
 
index d93e469eaeea97185e39c9e61b7f9db0146fa261..661d2c7d6717d2ad9bd1f43768a3679fb38b96d3 100644 (file)
@@ -54,13 +54,13 @@ Registry::~Registry()
 
 bool Registry::registerInterface(QString const & name, QObject * obj)
 {
-    mInterfaces.insert(name, QPointer<QObject>(obj));
+    mInterfaces.insert(name, QWeakPointer<QObject>(obj));
 
     return true;
 }
 
 QObject * Registry::queryInterface(QString const & name) const
 {
-    QHash<QString, QPointer<QObject> >::const_iterator it = mInterfaces.constFind(name);
-    return it != mInterfaces.constEnd() ? *it : 0;
+    QHash<QString, QWeakPointer<QObject> >::const_iterator it = mInterfaces.constFind(name);
+    return it != mInterfaces.constEnd() ? (*it).data() : 0;
 }
index 1046c485c798f8da67a8315d89a549306c7a39d0..9c05c5040e9f119fce27700bb84d6939b9def930 100644 (file)
@@ -24,7 +24,7 @@
 
 #include <QObject>
 #include <QString>
-#include <QPointer>
+#include <QWeakPointer>
 #include <QHash>
 
 namespace eVaf {
@@ -35,7 +35,7 @@ namespace Internal {
  * iRegistry interface implementation.
  *
  * This class implements the global registry for interfaces. Interfaces are stored in a QHash container
- * and quarded with QPointer.
+ * and quarded with QWeakPointer.
  */
 class Registry : public iRegistry
 {
@@ -59,7 +59,7 @@ public:
 private:
 
     /// All the registered interfaces
-    QHash<QString, QPointer<QObject> > mInterfaces;
+    QHash<QString, QWeakPointer<QObject> > mInterfaces;
 
 };
 
index 75847982cc86cf5115fcb1d77c22192b17cf299c..2a178f3aa954103ce60af5cc14ab7b2b54d6c96f 100644 (file)
 /**
  * Module/library version number in the form major,minor,release,build
  */
-#define VER_FILE_VERSION                0,1,1,3
+#define VER_FILE_VERSION                0,1,2,4
 
 /**
  * Module/library version number in the string format (shall end with \0)
  */
-#define VER_FILE_VERSION_STR            "0.1.1.3\0"
+#define VER_FILE_VERSION_STR            "0.1.2.4\0"
 
 /**
  * Module/library name (shall end with \0)
index d0294d8c83c1e18fddee8cc105170a9020de20eb..02de43a320a80ecf231a3b51d7305e93905764b5 100644 (file)
@@ -95,8 +95,8 @@ void MainWindow::done()
 
     // Delete all the items added to the main window
     while (mItemsAdded.count() > 0) {
-        QPointer<QObject> item = mItemsAdded.takeAt(0);
-        if (item)
+        QWeakPointer<QObject> item = mItemsAdded.takeAt(0);
+        if (!item.isNull())
             delete item.data();
     }
 
index 31b311d60454d8a4c4d04efa640f5fb88bf7b4b4..0032bc6dafd5986daabb74cc8b11d4f3e4800056 100644 (file)
@@ -28,7 +28,7 @@
 #include <QString>
 #include <QWidget>
 #include <QList>
-#include <QPointer>
+#include <QWeakPointer>
 
 class QVBoxLayout;
 
@@ -73,7 +73,7 @@ private: // Members
     QVBoxLayout * mLayout;
 
     /// Widgets and layouts added to the main window
-    QList<QPointer<QObject> > mItemsAdded;
+    QList<QWeakPointer<QObject> > mItemsAdded;
 
 };
 
index 44023e6fbbd6bdbba926504b27baaf16e94fd3a4..6df80cf90f37c33ae75382704848eb15112708ef 100644 (file)
 /**
  * Module/library version number in the form major,minor,release,build
  */
-#define VER_FILE_VERSION                0,2,2,3
+#define VER_FILE_VERSION                0,2,3,4
 
 /**
  * Module/library version number in the string format (shall end with \0)
  */
-#define VER_FILE_VERSION_STR            "0.2.2.3\0"
+#define VER_FILE_VERSION_STR            "0.2.3.4\0"
 
 /**
  * Module/library name (shall end with \0)