forked from qt-creator/qt-creator
ExtensionSystem: Remove type based getObjects()
Since commit cc88302309, access to the
typed lists is cheaper via the local pools, and subsequently all users
of getObjects() have been adapted.
As getObjects() is unused now, and the local pool pattern is preferred,
having the function around is not needed anymore. If the provided
functionality would ever be needed, user code can use allObjects() and
manually filter.
Change-Id: I1e9d8fa11da2ed0e68090cce1a25a3dd62c1aef6
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -117,8 +117,8 @@ enum { debugLeaks = 0 };
|
||||
\section1 Object Pool
|
||||
Plugins (and everybody else) can add objects to a common 'pool' that is located in
|
||||
the plugin manager. Objects in the pool must derive from QObject, there are no other
|
||||
prerequisites. All objects of a specified type can be retrieved from the object pool
|
||||
via the getObjects() and getObject() functions.
|
||||
prerequisites. Objects can be retrieved from the object pool via the getObject()
|
||||
and getObjectByName() functions.
|
||||
|
||||
Whenever the state of the object pool changes a corresponding signal is emitted by the plugin manager.
|
||||
|
||||
@@ -132,8 +132,8 @@ enum { debugLeaks = 0 };
|
||||
MyMimeTypeHandler *handler = new MyMimeTypeHandler();
|
||||
PluginManager::instance()->addObject(handler);
|
||||
// In plugin A:
|
||||
QList<MimeTypeHandler *> mimeHandlers =
|
||||
PluginManager::getObjects<MimeTypeHandler>();
|
||||
MimeTypeHandler *mimeHandler =
|
||||
PluginManager::getObject<MimeTypeHandler>();
|
||||
\endcode
|
||||
|
||||
|
||||
@@ -249,29 +249,6 @@ enum { debugLeaks = 0 };
|
||||
\sa addObject()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QList<T *> PluginManager::getObjects()
|
||||
|
||||
Retrieves all objects of a given type from the object pool.
|
||||
|
||||
This function uses \c qobject_cast to determine the type of an object.
|
||||
|
||||
\sa addObject()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QList<T *> PluginManager::getObjects(Predicate predicate)
|
||||
|
||||
Retrieves all objects of a given type from the object pool that
|
||||
match the \a predicate.
|
||||
|
||||
This function uses \c qobject_cast to determine the type of an object.
|
||||
The predicate should be a unary function taking a T* parameter and
|
||||
returning a bool.
|
||||
|
||||
\sa addObject()
|
||||
*/
|
||||
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
@@ -319,7 +296,7 @@ PluginManager::~PluginManager()
|
||||
|
||||
\sa PluginManager::removeObject()
|
||||
\sa PluginManager::getObject()
|
||||
\sa PluginManager::getObjects()
|
||||
\sa PluginManager::getObjectByName()
|
||||
*/
|
||||
void PluginManager::addObject(QObject *obj)
|
||||
{
|
||||
@@ -341,7 +318,6 @@ void PluginManager::removeObject(QObject *obj)
|
||||
Usually, clients do not need to call this function.
|
||||
|
||||
\sa PluginManager::getObject()
|
||||
\sa PluginManager::getObjects()
|
||||
*/
|
||||
QList<QObject *> PluginManager::allObjects()
|
||||
{
|
||||
|
||||
@@ -57,31 +57,6 @@ public:
|
||||
static void removeObject(QObject *obj);
|
||||
static QList<QObject *> allObjects();
|
||||
static QReadWriteLock *listLock();
|
||||
template <typename T> static QList<T *> getObjects()
|
||||
{
|
||||
QReadLocker lock(listLock());
|
||||
QList<T *> results;
|
||||
QList<QObject *> all = allObjects();
|
||||
foreach (QObject *obj, all) {
|
||||
T *result = qobject_cast<T *>(obj);
|
||||
if (result)
|
||||
results += result;
|
||||
}
|
||||
return results;
|
||||
}
|
||||
template <typename T, typename Predicate>
|
||||
static QList<T *> getObjects(Predicate predicate)
|
||||
{
|
||||
QReadLocker lock(listLock());
|
||||
QList<T *> results;
|
||||
QList<QObject *> all = allObjects();
|
||||
foreach (QObject *obj, all) {
|
||||
T *result = qobject_cast<T *>(obj);
|
||||
if (result && predicate(result))
|
||||
results += result;
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
// This is useful for soft dependencies using pure interfaces.
|
||||
template <typename T> static T *getObject()
|
||||
|
||||
Reference in New Issue
Block a user