Core: Introduce a IContext::attach() version taking a help provider

... and use it to dissolve the DesignerContext as example.

Change-Id: I0b67989050390fd9017203ec48068c144e0b8ac9
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2024-07-05 13:47:00 +02:00
parent baf20b8491
commit 4156287a03
3 changed files with 17 additions and 16 deletions

View File

@@ -41,6 +41,15 @@ void IContext::attach(QWidget *widget, const Context &context, const HelpItem &h
ICore::addContextObject(icontext);
}
void IContext::attach(QWidget *widget, const Context &context, const HelpProvider &helpProvider)
{
auto icontext = new IContext(widget); // As QObject parent.
icontext->setContext(context);
icontext->setWidget(widget);
icontext->setContextHelpProvider(helpProvider);
ICore::addContextObject(icontext);
}
QDebug operator<<(QDebug debug, const Core::Context &context)
{
debug.nospace() << "Context(";

View File

@@ -69,6 +69,9 @@ public:
static void attach(QWidget *widget,
const Context &context,
const HelpItem &contextHelp = {});
static void attach(QWidget *widget,
const Context &context,
const HelpProvider &helpProvider);
protected:
Context m_context;

View File

@@ -92,21 +92,6 @@ using namespace Utils;
namespace Designer::Internal {
class DesignerContext final : public IContext
{
public:
DesignerContext(const Context &context, QWidget *widget, QObject *parent)
: IContext(parent)
{
setContext(context);
setWidget(widget);
setContextHelpProvider([](const HelpCallback &callback) {
const QDesignerFormEditorInterface *core = designerEditor();
callback(core->integration()->contextHelpId());
});
}
};
/* A stub-like, read-only text editor which displays UI files as text. Could be used as a
* read/write editor too, but due to lack of XML editor, highlighting and other such
* functionality, editing is disabled.
@@ -443,7 +428,11 @@ void FormEditorData::fullInit()
Context designerContexts = m_contexts;
designerContexts.add(Core::Constants::C_EDITORMANAGER);
ICore::addContextObject(new DesignerContext(designerContexts, m_modeWidget, this));
IContext::attach(m_modeWidget, designerContexts, [](const IContext::HelpCallback &callback) {
const QDesignerFormEditorInterface *core = designerEditor();
callback(core->integration()->contextHelpId());
});
DesignMode::registerDesignWidget(m_modeWidget,
QStringList(Utils::Constants::FORM_MIMETYPE),