From: Enar Väikene Date: Wed, 19 Oct 2011 09:06:18 +0000 (+0300) Subject: Replaced QPointer<> with QWeakPointer<> X-Git-Url: https://vaikene.ee/gitweb/index.html?a=commitdiff_plain;h=8e0779e2e5a9f947f79c28e2ff121f6ffdd78b3f;p=evaf Replaced QPointer<> with QWeakPointer<> --- diff --git a/src/libs/Common/eventqueue.cpp b/src/libs/Common/eventqueue.cpp index bbf30ed..33e73c0 100644 --- a/src/libs/Common/eventqueue.cpp +++ b/src/libs/Common/eventqueue.cpp @@ -67,20 +67,20 @@ bool EventQueue::event(QEvent * e) } // Send the event to all the subscribers - QHash > >::const_iterator subscribersIt = mSubscribers.constFind(id); + QHash > >::const_iterator subscribersIt = mSubscribers.constFind(id); if (subscribersIt != mSubscribers.constEnd()) { - QList > subscribers = *subscribersIt; + QVector > 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 obj = subscribers.at(i); + QWeakPointer 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 >::iterator it = mSubscribers[id].begin(); + QVector >::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) diff --git a/src/libs/Common/eventqueue.h b/src/libs/Common/eventqueue.h index 92bcb06..b029376 100644 --- a/src/libs/Common/eventqueue.h +++ b/src/libs/Common/eventqueue.h @@ -25,8 +25,8 @@ #include #include #include -#include -#include +#include +#include namespace eVaf { @@ -75,7 +75,7 @@ private: // Members QHash mEvents; /// List of subscribers - QHash > > mSubscribers; + QHash > > mSubscribers; }; diff --git a/src/libs/Common/registry.cpp b/src/libs/Common/registry.cpp index d93e469..661d2c7 100644 --- a/src/libs/Common/registry.cpp +++ b/src/libs/Common/registry.cpp @@ -54,13 +54,13 @@ Registry::~Registry() bool Registry::registerInterface(QString const & name, QObject * obj) { - mInterfaces.insert(name, QPointer(obj)); + mInterfaces.insert(name, QWeakPointer(obj)); return true; } QObject * Registry::queryInterface(QString const & name) const { - QHash >::const_iterator it = mInterfaces.constFind(name); - return it != mInterfaces.constEnd() ? *it : 0; + QHash >::const_iterator it = mInterfaces.constFind(name); + return it != mInterfaces.constEnd() ? (*it).data() : 0; } diff --git a/src/libs/Common/registry.h b/src/libs/Common/registry.h index 1046c48..9c05c50 100644 --- a/src/libs/Common/registry.h +++ b/src/libs/Common/registry.h @@ -24,7 +24,7 @@ #include #include -#include +#include #include 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 > mInterfaces; + QHash > mInterfaces; }; diff --git a/src/libs/Common/version.h b/src/libs/Common/version.h index 7584798..2a178f3 100644 --- a/src/libs/Common/version.h +++ b/src/libs/Common/version.h @@ -25,12 +25,12 @@ /** * 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) diff --git a/src/plugins/SdiWindow/sdiwindow.cpp b/src/plugins/SdiWindow/sdiwindow.cpp index d0294d8..02de43a 100644 --- a/src/plugins/SdiWindow/sdiwindow.cpp +++ b/src/plugins/SdiWindow/sdiwindow.cpp @@ -95,8 +95,8 @@ void MainWindow::done() // Delete all the items added to the main window while (mItemsAdded.count() > 0) { - QPointer item = mItemsAdded.takeAt(0); - if (item) + QWeakPointer item = mItemsAdded.takeAt(0); + if (!item.isNull()) delete item.data(); } diff --git a/src/plugins/SdiWindow/sdiwindow.h b/src/plugins/SdiWindow/sdiwindow.h index 31b311d..0032bc6 100644 --- a/src/plugins/SdiWindow/sdiwindow.h +++ b/src/plugins/SdiWindow/sdiwindow.h @@ -28,7 +28,7 @@ #include #include #include -#include +#include class QVBoxLayout; @@ -73,7 +73,7 @@ private: // Members QVBoxLayout * mLayout; /// Widgets and layouts added to the main window - QList > mItemsAdded; + QList > mItemsAdded; }; diff --git a/src/plugins/SdiWindow/version.h b/src/plugins/SdiWindow/version.h index 44023e6..6df80cf 100644 --- a/src/plugins/SdiWindow/version.h +++ b/src/plugins/SdiWindow/version.h @@ -25,12 +25,12 @@ /** * 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)