QmlDesigner: Register AssetsLibraryContext more directly

... in the constructor of the relevant AssetsLibraryWidget.

This simplifies the code and ensure the context gets set in all paths
creating such an object. One was missing.

Change-Id: I00daf9ef9f932a35bdc8b2b258c471a655b97fbf
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2024-07-05 14:01:32 +02:00
parent 4156287a03
commit c66b02d37e
4 changed files with 6 additions and 22 deletions

View File

@@ -4,7 +4,6 @@
#include "assetslibraryview.h" #include "assetslibraryview.h"
#include "assetslibrarywidget.h" #include "assetslibrarywidget.h"
#include "designmodecontext.h"
#include "qmldesignerplugin.h" #include "qmldesignerplugin.h"
#include <asynchronousimagecache.h> #include <asynchronousimagecache.h>
@@ -62,9 +61,6 @@ WidgetInfo AssetsLibraryView::widgetInfo()
m_widget = new AssetsLibraryWidget{imageCacheData()->asynchronousFontImageCache, m_widget = new AssetsLibraryWidget{imageCacheData()->asynchronousFontImageCache,
imageCacheData()->synchronousFontImageCache, imageCacheData()->synchronousFontImageCache,
this}; this};
auto context = new Internal::AssetsLibraryContext(m_widget.data());
Core::ICore::addContextObject(context);
} }
return createWidgetInfo(m_widget.data(), "Assets", WidgetInfo::LeftPane, 0, tr("Assets")); return createWidgetInfo(m_widget.data(), "Assets", WidgetInfo::LeftPane, 0, tr("Assets"));

View File

@@ -43,6 +43,8 @@
#include <QToolButton> #include <QToolButton>
#include <QVBoxLayout> #include <QVBoxLayout>
using namespace Core;
namespace QmlDesigner { namespace QmlDesigner {
static QString propertyEditorResourcesPath() static QString propertyEditorResourcesPath()
@@ -158,6 +160,10 @@ AssetsLibraryWidget::AssetsLibraryWidget(AsynchronousImageCache &asynchronousFon
reloadQmlSource(); reloadQmlSource();
setFocusProxy(m_assetsWidget->quickWidget()); setFocusProxy(m_assetsWidget->quickWidget());
IContext::attach(this,
Context(Constants::C_QMLASSETSLIBRARY, Constants::C_QT_QUICK_TOOLS_MENU),
[this](const IContext::HelpCallback &callback) { contextHelp(callback); });
} }
void AssetsLibraryWidget::contextHelp(const Core::IContext::HelpCallback &callback) const void AssetsLibraryWidget::contextHelp(const Core::IContext::HelpCallback &callback) const

View File

@@ -53,16 +53,6 @@ MaterialBrowserContext::MaterialBrowserContext(QWidget *widget)
}); });
} }
AssetsLibraryContext::AssetsLibraryContext(QWidget *widget)
: IContext(widget)
{
setWidget(widget);
setContext(Core::Context(Constants::C_QMLASSETSLIBRARY, Constants::C_QT_QUICK_TOOLS_MENU));
setContextHelpProvider([this](const HelpCallback &callback) {
qobject_cast<AssetsLibraryWidget *>(m_widget)->contextHelp(callback);
});
}
NavigatorContext::NavigatorContext(QWidget *widget) NavigatorContext::NavigatorContext(QWidget *widget)
: IContext(widget) : IContext(widget)
{ {

View File

@@ -43,14 +43,6 @@ public:
MaterialBrowserContext(QWidget *widget); MaterialBrowserContext(QWidget *widget);
}; };
class AssetsLibraryContext : public Core::IContext
{
Q_OBJECT
public:
AssetsLibraryContext(QWidget *widget);
};
class NavigatorContext : public Core::IContext class NavigatorContext : public Core::IContext
{ {
Q_OBJECT Q_OBJECT