QmlDesigner: Add basic texture's info to tool tip

Fixes: QDS-8488
Change-Id: If4672863babef03bdc108109c514837a2587c6a8
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
Mahmoud Badri
2022-12-12 16:58:04 +02:00
parent 2a0a1181f9
commit 521f220efb
5 changed files with 58 additions and 14 deletions

View File

@@ -44,8 +44,18 @@ Rectangle {
ToolTip {
visible: mouseArea.containsMouse
text: textureSource ? textureSource : qsTr("Texture has no source image.")
// contentWidth is not calculated correctly by the toolTip (resulting in a wider tooltip than
// needed). Using a helper Text to calculate the correct width
contentWidth: helperText.width
bottomInset: -2
text: textureToolTip
delay: 1000
Text {
id: helperText
text: textureToolTip
visible: false
}
}
Image {

View File

@@ -3,6 +3,7 @@
#include "materialbrowsertexturesmodel.h"
#include "designeractionmanager.h"
#include "designmodewidget.h"
#include "qmldesignerplugin.h"
#include "qmlobjectnode.h"
@@ -31,8 +32,7 @@ QVariant MaterialBrowserTexturesModel::data(const QModelIndex &index, int role)
QTC_ASSERT(index.isValid() && index.row() < m_textureList.count(), return {});
QTC_ASSERT(roleNames().contains(role), return {});
QByteArray roleName = roleNames().value(role);
if (roleName == "textureSource") {
if (role == RoleTexSource) {
QString source = QmlObjectNode(m_textureList.at(index.row())).modelValue("source").toString();
if (source.isEmpty())
return {};
@@ -42,15 +42,36 @@ QVariant MaterialBrowserTexturesModel::data(const QModelIndex &index, int role)
->fileName().absolutePath().pathAppended(source).cleanPath().toString());
}
if (roleName == "textureVisible")
if (role == RoleTexVisible)
return isTextureVisible(index.row());
if (roleName == "hasDynamicProperties")
if (role == RoleTexHasDynamicProps)
return !m_textureList.at(index.row()).dynamicProperties().isEmpty();
if (roleName == "textureInternalId")
if (role == RoleTexInternalId)
return m_textureList.at(index.row()).internalId();
if (role == RoleTexToolTip) {
QString source = QmlObjectNode(m_textureList.at(index.row())).modelValue("source").toString();
if (source.isEmpty())
return tr("Texture has no source image.");
const QString noData = tr("Texture has no data.");
auto op = QmlDesignerPlugin::instance()->viewManager().designerActionManager()
.modelNodePreviewOperation(m_textureList.at(index.row()));
if (!op)
return noData;
QVariantMap imgMap = op(m_textureList.at(index.row())).toMap();
if (imgMap.isEmpty())
return noData;
return QLatin1String("%1\n%2\n%3").arg(imgMap.value("id").toString(),
source.split('/').last(),
imgMap.value("info").toString());
}
return {};
}
@@ -68,14 +89,14 @@ bool MaterialBrowserTexturesModel::isValidIndex(int idx) const
return idx > -1 && idx < rowCount();
}
QHash<int, QByteArray> MaterialBrowserTexturesModel::roleNames() const
{
static const QHash<int, QByteArray> roles {
{Qt::UserRole + 1, "textureSource"},
{Qt::UserRole + 2, "textureVisible"},
{Qt::UserRole + 3, "hasDynamicProperties"},
{Qt::UserRole + 4, "textureInternalId"}
{RoleTexHasDynamicProps, "hasDynamicProperties"},
{RoleTexInternalId, "textureInternalId"},
{RoleTexSource, "textureSource"},
{RoleTexToolTip, "textureToolTip"},
{RoleTexVisible, "textureVisible"}
};
return roles;
}
@@ -181,12 +202,12 @@ void MaterialBrowserTexturesModel::updateTextureSource(const ModelNode &texture)
{
int idx = textureIndex(texture);
if (idx != -1)
emit dataChanged(index(idx, 0), index(idx, 0), {roleNames().key("textureSource")});
emit dataChanged(index(idx, 0), index(idx, 0), {RoleTexSource, RoleTexToolTip});
}
void MaterialBrowserTexturesModel::updateAllTexturesSources()
{
emit dataChanged(index(0, 0), index(rowCount() - 1, 0), {roleNames().key("textureSource")});
emit dataChanged(index(0, 0), index(rowCount() - 1, 0), {RoleTexSource, RoleTexToolTip});
}
void MaterialBrowserTexturesModel::updateSelectedTexture()

View File

@@ -87,6 +87,12 @@ private:
bool m_isEmpty = true;
bool m_hasSingleModelSelection = false;
bool m_hasSceneEnv = false;
const static int RoleTexHasDynamicProps = Qt::UserRole + 1;
const static int RoleTexInternalId = Qt::UserRole + 2;
const static int RoleTexSource = Qt::UserRole + 3;
const static int RoleTexToolTip = Qt::UserRole + 4;
const static int RoleTexVisible = Qt::UserRole + 5;
};
} // namespace QmlDesigner

View File

@@ -323,12 +323,18 @@ void MaterialBrowserView::modelNodePreviewPixmapChanged(const ModelNode &node, c
m_widget->updateMaterialPreview(node, pixmap);
}
void MaterialBrowserView::nodeIdChanged(const ModelNode &node, [[maybe_unused]] const QString &newId,
[[maybe_unused]] const QString &oldId)
{
if (isTexture(node))
m_widget->materialBrowserTexturesModel()->updateTextureSource(node);
}
void MaterialBrowserView::variantPropertiesChanged(const QList<VariantProperty> &propertyList,
[[maybe_unused]] PropertyChangeFlags propertyChange)
{
for (const VariantProperty &property : propertyList) {
ModelNode node(property.parentModelNode());
if (isMaterial(node) && property.name() == "objectName") {
m_widget->materialBrowserModel()->updateMaterialName(node);
} else if (property.name() == "source") {

View File

@@ -36,6 +36,7 @@ public:
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
const QList<ModelNode> &lastSelectedNodeList) override;
void modelNodePreviewPixmapChanged(const ModelNode &node, const QPixmap &pixmap) override;
void nodeIdChanged(const ModelNode &node, const QString &newId, const QString &oldId) override;
void variantPropertiesChanged(const QList<VariantProperty> &propertyList, PropertyChangeFlags propertyChange) override;
void propertiesRemoved(const QList<AbstractProperty> &propertyList) override;
void nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent,