diff --git a/src/gui/text/qabstracttextdocumentlayout.cpp b/src/gui/text/qabstracttextdocumentlayout.cpp index e051178a47..b8f5aa70a9 100644 --- a/src/gui/text/qabstracttextdocumentlayout.cpp +++ b/src/gui/text/qabstracttextdocumentlayout.cpp @@ -436,6 +436,24 @@ void QAbstractTextDocumentLayout::registerHandler(int objectType, QObject *compo d->handlers.insert(objectType, h); } +/*! + \since 5.2 + + Unregisters the given \a component as a handler for items of the given \a objectType, or + any handler if the \a component is not specified. +*/ +void QAbstractTextDocumentLayout::unregisterHandler(int objectType, QObject *component) +{ + Q_D(QAbstractTextDocumentLayout); + + HandlerHash::iterator it = d->handlers.find(objectType); + if (it != d->handlers.end() && (!component || component == it->component)) { + if (component) + disconnect(component, SIGNAL(destroyed(QObject*)), this, SLOT(_q_handlerDestroyed(QObject*))); + d->handlers.erase(it); + } +} + /*! Returns a handler for objects of the given \a objectType. */ diff --git a/src/gui/text/qabstracttextdocumentlayout.h b/src/gui/text/qabstracttextdocumentlayout.h index 95733f5da7..4bae631b9c 100644 --- a/src/gui/text/qabstracttextdocumentlayout.h +++ b/src/gui/text/qabstracttextdocumentlayout.h @@ -98,6 +98,7 @@ public: QTextDocument *document() const; void registerHandler(int objectType, QObject *component); + void unregisterHandler(int objectType, QObject *component = 0); QTextObjectInterface *handlerForObject(int objectType) const; Q_SIGNALS: