forked from qt-creator/qt-creator
QmlDesigner: Add support for tooltip in item library
This allows to define tool tips in the .metainfo files. Change-Id: I3236c6e9f374a052e99b18d8c3983bfd0f072162 Reviewed-by: Henning Gründl <henning.gruendl@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -68,6 +68,8 @@ Item {
|
|||||||
id: mouseRegion
|
id: mouseRegion
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
|
tooltip: toolTip
|
||||||
|
|
||||||
onShowContextMenu: delegateRoot.showContextMenu()
|
onShowContextMenu: delegateRoot.showContextMenu()
|
||||||
onPressed: (mouse)=> {
|
onPressed: (mouse)=> {
|
||||||
allowTooltip = false
|
allowTooltip = false
|
||||||
|
@@ -5,7 +5,7 @@ import QtQuick 2.15
|
|||||||
import QtQuick.Layouts 1.15
|
import QtQuick.Layouts 1.15
|
||||||
import HelperWidgets 2.0
|
import HelperWidgets 2.0
|
||||||
|
|
||||||
MouseArea {
|
ToolTipArea {
|
||||||
id: mouseArea
|
id: mouseArea
|
||||||
|
|
||||||
property bool allowTooltip: true
|
property bool allowTooltip: true
|
||||||
|
@@ -47,6 +47,7 @@ public:
|
|||||||
QString requiredImport() const;
|
QString requiredImport() const;
|
||||||
QString customComponentSource() const;
|
QString customComponentSource() const;
|
||||||
QStringList extraFilePaths() const;
|
QStringList extraFilePaths() const;
|
||||||
|
QString toolTip() const;
|
||||||
|
|
||||||
using Property = QmlDesigner::PropertyContainer;
|
using Property = QmlDesigner::PropertyContainer;
|
||||||
|
|
||||||
@@ -62,6 +63,7 @@ public:
|
|||||||
void setCategory(const QString &category);
|
void setCategory(const QString &category);
|
||||||
void setQmlPath(const QString &qml);
|
void setQmlPath(const QString &qml);
|
||||||
void setRequiredImport(const QString &requiredImport);
|
void setRequiredImport(const QString &requiredImport);
|
||||||
|
void setToolTip(const QString &tooltip);
|
||||||
void addHints(const QHash<QString, QString> &hints);
|
void addHints(const QHash<QString, QString> &hints);
|
||||||
void setCustomComponentSource(const QString &source);
|
void setCustomComponentSource(const QString &source);
|
||||||
void addExtraFilePath(const QString &extraFile);
|
void addExtraFilePath(const QString &extraFile);
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "itemlibraryinfo.h"
|
#include "itemlibraryinfo.h"
|
||||||
#include "nodemetainfo.h"
|
#include "nodemetainfo.h"
|
||||||
|
#include "qregularexpression.h"
|
||||||
|
|
||||||
#include <invalidmetainfoexception.h>
|
#include <invalidmetainfoexception.h>
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ public:
|
|||||||
QHash<QString, QString> hints;
|
QHash<QString, QString> hints;
|
||||||
QString customComponentSource;
|
QString customComponentSource;
|
||||||
QStringList extraFilePaths;
|
QStringList extraFilePaths;
|
||||||
|
QString toolTip;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
@@ -96,6 +98,11 @@ QStringList ItemLibraryEntry::extraFilePaths() const
|
|||||||
return m_data->extraFilePaths;
|
return m_data->extraFilePaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ItemLibraryEntry::toolTip() const
|
||||||
|
{
|
||||||
|
return m_data->toolTip;
|
||||||
|
}
|
||||||
|
|
||||||
int ItemLibraryEntry::majorVersion() const
|
int ItemLibraryEntry::majorVersion() const
|
||||||
{
|
{
|
||||||
return m_data->majorVersion;
|
return m_data->majorVersion;
|
||||||
@@ -165,6 +172,16 @@ void ItemLibraryEntry::setRequiredImport(const QString &requiredImport)
|
|||||||
m_data->requiredImport = requiredImport;
|
m_data->requiredImport = requiredImport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ItemLibraryEntry::setToolTip(const QString &tooltip)
|
||||||
|
{
|
||||||
|
static QRegularExpression regularExpressionPattern(QLatin1String("^qsTr\\(\"(.*)\"\\)$"));
|
||||||
|
const QRegularExpressionMatch match = regularExpressionPattern.match(tooltip);
|
||||||
|
if (match.hasMatch())
|
||||||
|
m_data->toolTip = match.captured(1);
|
||||||
|
else
|
||||||
|
m_data->toolTip = tooltip;
|
||||||
|
}
|
||||||
|
|
||||||
void ItemLibraryEntry::addHints(const QHash<QString, QString> &hints)
|
void ItemLibraryEntry::addHints(const QHash<QString, QString> &hints)
|
||||||
{
|
{
|
||||||
Utils::addToHash(&m_data->hints, hints);
|
Utils::addToHash(&m_data->hints, hints);
|
||||||
|
@@ -266,6 +266,8 @@ void MetaInfoReader::readItemLibraryEntryProperty(const QString &name, const QVa
|
|||||||
setVersion(value.toString());
|
setVersion(value.toString());
|
||||||
} else if (name == QStringLiteral("requiredImport")) {
|
} else if (name == QStringLiteral("requiredImport")) {
|
||||||
m_currentEntry.setRequiredImport(value.toString());
|
m_currentEntry.setRequiredImport(value.toString());
|
||||||
|
} else if (name == QStringLiteral("toolTip")) {
|
||||||
|
m_currentEntry.setToolTip(value.toString());
|
||||||
} else {
|
} else {
|
||||||
addError(::QmlDesigner::Internal::MetaInfoReader::tr(
|
addError(::QmlDesigner::Internal::MetaInfoReader::tr(
|
||||||
"Unknown property for ItemLibraryEntry %1")
|
"Unknown property for ItemLibraryEntry %1")
|
||||||
|
Reference in New Issue
Block a user