}
// 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
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)
#include <QObject>
#include <QString>
#include <QHash>
-#include <QList>
-#include <QPointer>
+#include <QVector>
+#include <QWeakPointer>
namespace eVaf {
QHash<uint, QString> mEvents;
/// List of subscribers
- QHash<uint, QList<QPointer<QObject> > > mSubscribers;
+ QHash<uint, QVector<QWeakPointer<QObject> > > mSubscribers;
};
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;
}
#include <QObject>
#include <QString>
-#include <QPointer>
+#include <QWeakPointer>
#include <QHash>
namespace eVaf {
* 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
{
private:
/// All the registered interfaces
- QHash<QString, QPointer<QObject> > mInterfaces;
+ QHash<QString, QWeakPointer<QObject> > mInterfaces;
};
/**
* 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)
// 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();
}
#include <QString>
#include <QWidget>
#include <QList>
-#include <QPointer>
+#include <QWeakPointer>
class QVBoxLayout;
QVBoxLayout * mLayout;
/// Widgets and layouts added to the main window
- QList<QPointer<QObject> > mItemsAdded;
+ QList<QWeakPointer<QObject> > mItemsAdded;
};
/**
* 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)