QmlDesigner: Fix corrupted preview images in material editor/browser

Now a default preview image is shown if real preview is not yet
available.

Fixes: QDS-7055
Change-Id: Ia2f9ee3aa3b29f49224b6ba8ae8f22f1b36f629a
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Samuel Ghinet <samuel.ghinet@qt.io>
This commit is contained in:
Miikka Heikkinen
2022-05-31 17:42:18 +03:00
parent e1bb5d058d
commit ffe94d177c
6 changed files with 18 additions and 2 deletions

View File

@@ -320,6 +320,7 @@ extend_qtc_plugin(QmlDesigner
materialeditorqmlbackend.cpp materialeditorqmlbackend.h
materialeditortransaction.cpp materialeditortransaction.h
materialeditorview.cpp materialeditorview.h
materialeditor.qrc
)
extend_qtc_plugin(QmlDesigner

View File

@@ -81,11 +81,15 @@ public:
{
Q_UNUSED(requestedSize)
static QPixmap defaultPreview = QPixmap::fromImage(QImage(":/materialeditor/images/defaultmaterialpreview.png"));
QPixmap pixmap{150, 150};
qint32 internalId = id.toInt();
if (m_pixmaps.contains(internalId))
pixmap = m_pixmaps.value(internalId);
else
pixmap = defaultPreview;
if (size)
*size = pixmap.size();

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/materialeditor">
<file>images/defaultmaterialpreview.png</file>
</qresource>
</RCC>

View File

@@ -77,16 +77,21 @@ public:
{
Q_UNUSED(requestedSize)
static QPixmap defaultPreview = QPixmap::fromImage(QImage(":/materialeditor/images/defaultmaterialpreview.png"));
QPixmap pixmap{150, 150};
if (id == "preview") {
if (!m_previewPixmap.isNull())
pixmap = m_previewPixmap;
else
pixmap = defaultPreview;
} else {
QString path = Core::ICore::resourcePath("qmldesigner/materialEditorQmlSources/images/" + id).toString();
pixmap = QPixmap{path};
qWarning() << __FUNCTION__ << "Unsupported image id:" << id;
pixmap.fill(Qt::red);
}
if (size)
*size = pixmap.size();

View File

@@ -693,6 +693,7 @@ Project {
"materialeditor/materialeditortransaction.h",
"materialeditor/materialeditorview.cpp",
"materialeditor/materialeditorview.h",
"materialeditor/materialeditor.qrc",
"navigator/iconcheckboxitemdelegate.cpp",
"navigator/iconcheckboxitemdelegate.h",
"navigator/nameitemdelegate.cpp",