forked from qt-creator/qt-creator
QmlDesigner: MCU configurations metadata
-Removed c++ hardcoded info about QDS MCU restrictions -Instead replaced it with dynamically loaded qml files -Replaced QLists with QSet/QHash to improve performance Task: QDS-2794 Change-Id: Ifc23d1299155001b6573dc0ed789dda5d2cfaf24 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
37
share/qtcreator/qmldesigner/qt4mcu/metadata.qml
Normal file
37
share/qtcreator/qmldesigner/qt4mcu/metadata.qml
Normal file
@@ -0,0 +1,37 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2020 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
//list of files in the current system
|
||||
Metadata {
|
||||
id: metadataFile
|
||||
|
||||
defaultVersion: v14
|
||||
|
||||
VersionData {
|
||||
id: v14
|
||||
name: "QUL 1.4"
|
||||
path: "qul-14.qml"
|
||||
}
|
||||
}
|
154
share/qtcreator/qmldesigner/qt4mcu/qul-14.qml
Normal file
154
share/qtcreator/qmldesigner/qt4mcu/qul-14.qml
Normal file
@@ -0,0 +1,154 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2020 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
VersionData {
|
||||
name: "QUL 1.4"
|
||||
|
||||
bannedItems: ["QtQuick.AnimatedImage",
|
||||
"QtQuick.BorderImage",
|
||||
"QtQuick.FocusScope",
|
||||
"QtQuick.TextInput",
|
||||
"QtQuick.TextEdit",
|
||||
"QtQuick.Flow",
|
||||
"QtQuick.Grid",
|
||||
"QtQuick.GridView",
|
||||
"QtQuick.PathView",
|
||||
"QtQuick.Controls",
|
||||
"QtQuick.Controls.BusyIndicator",
|
||||
"QtQuick.Controls.ButtonGroup",
|
||||
"QtQuick.Controls.CheckDelegate",
|
||||
"QtQuick.Controls.Container",
|
||||
"QtQuick.Controls.ComboBox",
|
||||
"QtQuick.Controls.DelayButton",
|
||||
"QtQuick.Controls.Frame",
|
||||
"QtQuick.Controls.GroupBox",
|
||||
"QtQuick.Controls.ItemDelegate",
|
||||
"QtQuick.Controls.Label",
|
||||
"QtQuick.Controls.Page",
|
||||
"QtQuick.Controls.PageIndicator",
|
||||
"QtQuick.Controls.Pane",
|
||||
"QtQuick.Controls.RadioDelegate",
|
||||
"QtQuick.Controls.RangeSlider",
|
||||
"QtQuick.Controls.RoundButton",
|
||||
"QtQuick.Controls.ScrollView",
|
||||
"QtQuick.Controls.SpinBox",
|
||||
"QtQuick.Controls.StackView",
|
||||
"QtQuick.Controls.SwipeDelegate",
|
||||
"QtQuick.Controls.SwitchDelegate",
|
||||
"QtQuick.Controls.ToolBar",
|
||||
"QtQuick.Controls.ToolButton",
|
||||
"QtQuick.Controls.TabBar",
|
||||
"QtQuick.Controls.TabButton",
|
||||
"QtQuick.Controls.TextArea",
|
||||
"QtQuick.Controls.TextField",
|
||||
"QtQuick.Controls.ToolSeparator",
|
||||
"QtQuick.Controls.Tumbler"]
|
||||
|
||||
allowedImports: ["QtQuick",
|
||||
"QtQuick.Controls",
|
||||
"QtQuick.Timeline"]
|
||||
|
||||
bannedImports: ["FlowView"]
|
||||
|
||||
//ComplexProperty is not a type, it's just a way to handle bigger props
|
||||
ComplexProperty {
|
||||
prefix: "font"
|
||||
bannedProperties: ["wordSpacing", "letterSpacing", "hintingPreference",
|
||||
"kerning", "preferShaping", "capitalization",
|
||||
"strikeout", "underline", "styleName"]
|
||||
}
|
||||
|
||||
QtQuick.Item {
|
||||
bannedProperties: ["layer", "opacity", "gradient", "smooth", "antialiasing",
|
||||
"border", "baselineOffset", "focus", "activeFocusOnTab",
|
||||
"rotation", "scale", "transformOrigin"]
|
||||
}
|
||||
|
||||
QtQuick.Flickable {
|
||||
bannedProperties: ["boundsBehavior", "boundsMovement", "flickDeceleration",
|
||||
"flickableDirection", "leftMargin", "rightMargin", "bottomMargin", "topMargin",
|
||||
"originX", "originY", "pixelAligned", "pressDelay", "synchronousDrag"]
|
||||
}
|
||||
|
||||
QtQuick.MouseArea {
|
||||
bannedProperties: ["propagateComposedEvents", "preventStealing", "cursorShape",
|
||||
"scrollGestureEnabled", "drag", "acceptedButtons", "hoverEnabled"]
|
||||
}
|
||||
|
||||
QtQuick.Image {
|
||||
allowedProperties: ["rotation", "scale", "transformOrigin"]
|
||||
bannedProperties: ["mirror", "mipmap", "cache", "autoTransform", "asynchronous",
|
||||
"sourceSize", "smooth"]
|
||||
}
|
||||
|
||||
QtQuick.Text {
|
||||
allowedProperties: ["rotation", "scale", "transformOrigin"]
|
||||
bannedProperties: ["elide", "lineHeight", "lineHeightMode", "wrapMode", "style",
|
||||
"styleColor", "minimumPointSize", "minimumPixelSize", "styleColor",
|
||||
"fontSizeMode", "renderType", "textFormat", "maximumLineCount"]
|
||||
}
|
||||
|
||||
//Padding is not an actual item, but rather set of properties in Text
|
||||
Padding {
|
||||
bannedProperties: ["bottomPadding", "topPadding", "leftPadding", "rightPadding"]
|
||||
}
|
||||
|
||||
QtQuick.Column {
|
||||
bannedProperties: ["layoutDirection"]
|
||||
}
|
||||
|
||||
QtQuick.Row {
|
||||
bannedProperties: ["layoutDirection"]
|
||||
}
|
||||
|
||||
QtQuick.ListView {
|
||||
bannedProperties: ["cacheBuffer", "highlightRangeMode", "highlightMoveDuration",
|
||||
"highlightResizeDuration", "preferredHighlightBegin", "layoutDirection",
|
||||
"preferredHighlightEnd", "highlightFollowsCurrentItem", "keyNavigationWraps",
|
||||
"snapMode", "highlightMoveVelocity", "highlightResizeVelocity"]
|
||||
}
|
||||
|
||||
QtQuick.Animation {
|
||||
bannedProperties: ["paused"]
|
||||
}
|
||||
|
||||
//Quick Controls2 Items and properties:
|
||||
|
||||
QtQuick.Controls.Control {
|
||||
bannedProperties: ["focusPolicy", "hoverEnabled", "wheelEnabled"]
|
||||
}
|
||||
|
||||
QtQuick.Controls.AbstractButton {
|
||||
bannedProperties: ["display", "autoExclusive"]
|
||||
}
|
||||
|
||||
QtQuick.Controls.ProgressBar {
|
||||
bannedProperties: ["indeterminate"]
|
||||
}
|
||||
|
||||
QtQuick.Controls.Slider {
|
||||
bannedProperties: ["live", "snapMode", "touchDragThreshold"]
|
||||
}
|
||||
}
|
@@ -30,6 +30,7 @@ add_qtc_plugin(QmlDesigner
|
||||
settingspage.cpp settingspage.h settingspage.ui
|
||||
shortcutmanager.cpp shortcutmanager.h
|
||||
switchsplittabwidget.cpp switchsplittabwidget.h
|
||||
designermcumanager.cpp designermcumanager.h
|
||||
EXPLICIT_MOC
|
||||
components/propertyeditor/propertyeditorvalue.h
|
||||
components/connectioneditor/connectionviewwidget.h
|
||||
|
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <designdocument.h>
|
||||
#include <qmldesignerplugin.h>
|
||||
#include <designermcumanager.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
@@ -94,20 +95,20 @@ void ImportsWidget::setPossibleImports(QList<Import> possibleImports)
|
||||
Utils::sort(possibleImports, importLess);
|
||||
m_addImportComboBox->clear();
|
||||
|
||||
const DesignDocument *designDocument = QmlDesignerPlugin::instance()->currentDesignDocument();
|
||||
const bool isQtForMCUs = designDocument && designDocument->isQtForMCUsProject();
|
||||
const DesignerMcuManager &mcuManager = DesignerMcuManager::instance();
|
||||
const bool isQtForMCUs = mcuManager.isMCUProject();
|
||||
|
||||
QList<Import> filteredImports;
|
||||
|
||||
const QStringList mcuPostiveList = {"QtQuick", "QtQuick.Controls", "QtQuick.Timeline"};
|
||||
const QStringList mcuNegativeList = {"FlowView"};
|
||||
const QStringList mcuAllowedList = mcuManager.allowedImports();
|
||||
const QStringList mcuBannedList = mcuManager.bannedImports();
|
||||
|
||||
if (isQtForMCUs) {
|
||||
filteredImports = Utils::filtered(possibleImports,
|
||||
[mcuPostiveList, mcuNegativeList](const Import &import) {
|
||||
return (mcuPostiveList.contains(import.url())
|
||||
[mcuAllowedList, mcuBannedList](const Import &import) {
|
||||
return (mcuAllowedList.contains(import.url())
|
||||
|| !import.url().startsWith("Qt"))
|
||||
&& !mcuNegativeList.contains(import.url());
|
||||
&& !mcuBannedList.contains(import.url());
|
||||
});
|
||||
} else {
|
||||
filteredImports = possibleImports;
|
||||
|
@@ -35,6 +35,7 @@
|
||||
|
||||
#include <designdocument.h>
|
||||
#include <qmldesignerplugin.h>
|
||||
#include <designermcumanager.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -200,52 +201,12 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
|
||||
forceVisiblity = isItem;
|
||||
}
|
||||
|
||||
DesignDocument *designDocument = QmlDesignerPlugin::instance()
|
||||
->documentManager()
|
||||
.currentDesignDocument();
|
||||
const DesignerMcuManager &mcuManager = DesignerMcuManager::instance();
|
||||
|
||||
if (designDocument && designDocument->isQtForMCUsProject()) {
|
||||
const QList<TypeName> blockTypes = {"QtQuick.AnimatedImage",
|
||||
"QtQuick.BorderImage",
|
||||
"QtQuick.FocusScope",
|
||||
"QtQuick.TextInput",
|
||||
"QtQuick.TextEdit",
|
||||
"QtQuick.Flow",
|
||||
"QtQuick.Grid",
|
||||
"QtQuick.GridView",
|
||||
"QtQuick.PathView",
|
||||
"QtQuick.Controls",
|
||||
"QtQuick.Controls.BusyIndicator",
|
||||
"QtQuick.Controls.ButtonGroup",
|
||||
"QtQuick.Controls.CheckDelegate",
|
||||
"QtQuick.Controls.Container",
|
||||
"QtQuick.Controls.ComboBox",
|
||||
"QtQuick.Controls.DelayButton",
|
||||
"QtQuick.Controls.Frame",
|
||||
"QtQuick.Controls.GroupBox",
|
||||
"QtQuick.Controls.ItemDelegate",
|
||||
"QtQuick.Controls.Label",
|
||||
"QtQuick.Controls.Page",
|
||||
"QtQuick.Controls.PageIndicator",
|
||||
"QtQuick.Controls.Pane",
|
||||
"QtQuick.Controls.RadioDelegate",
|
||||
"QtQuick.Controls.RangeSlider",
|
||||
"QtQuick.Controls.RoundButton",
|
||||
"QtQuick.Controls.ScrollView",
|
||||
"QtQuick.Controls.SpinBox",
|
||||
"QtQuick.Controls.StackView",
|
||||
"QtQuick.Controls.SwipeDelegate",
|
||||
"QtQuick.Controls.SwitchDelegate",
|
||||
"QtQuick.Controls.ToolBar",
|
||||
"QtQuick.Controls.ToolButton",
|
||||
"QtQuick.Controls.TabBar",
|
||||
"QtQuick.Controls.TabButton",
|
||||
"QtQuick.Controls.TextArea",
|
||||
"QtQuick.Controls.TextField",
|
||||
"QtQuick.Controls.ToolSeparator",
|
||||
"QtQuick.Controls.Tumbler"};
|
||||
if (mcuManager.isMCUProject()) {
|
||||
const QSet<QString> blockTypes = mcuManager.bannedItems();
|
||||
|
||||
if (blockTypes.contains(entry.typeName()))
|
||||
if (blockTypes.contains(QString::fromUtf8(entry.typeName())))
|
||||
valid = false;
|
||||
}
|
||||
|
||||
|
@@ -39,6 +39,7 @@
|
||||
#include <qmldesignerplugin.h>
|
||||
#include <qmldesignerconstants.h>
|
||||
#include <designeractionmanager.h>
|
||||
#include <designermcumanager.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/flowlayout.h>
|
||||
@@ -351,8 +352,9 @@ void ItemLibraryWidget::reloadQmlSource()
|
||||
void ItemLibraryWidget::setupImportTagWidget()
|
||||
{
|
||||
QTC_ASSERT(m_model, return);
|
||||
const DesignDocument *designDocument = QmlDesignerPlugin::instance()->currentDesignDocument();
|
||||
const bool isQtForMCUs = designDocument && designDocument->isQtForMCUsProject();
|
||||
|
||||
const DesignerMcuManager &mcuManager = DesignerMcuManager::instance();
|
||||
const bool isQtForMCUs = mcuManager.isMCUProject();
|
||||
|
||||
const QStringList imports = m_model->metaInfo().itemLibraryInfo()->showTagsForImports();
|
||||
|
||||
|
@@ -32,6 +32,7 @@
|
||||
#include <nodemetainfo.h>
|
||||
#include <qmldesignerplugin.h>
|
||||
#include <qmlobjectnode.h>
|
||||
#include <designermcumanager.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -261,76 +262,12 @@ bool PropertyEditorValue::isTranslated() const
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool itemOrImage(const QmlDesigner::NodeMetaInfo &metaInfo)
|
||||
static bool isAllowedSubclassType(const QString &type, const QmlDesigner::NodeMetaInfo &metaInfo)
|
||||
{
|
||||
if (!metaInfo.isValid())
|
||||
return false;
|
||||
|
||||
if (metaInfo.isSubclassOf("QtQuick.Image") || metaInfo.isSubclassOf("QtQuick.Text"))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static QList<QByteArray> prepareNonMcuProperties()
|
||||
{
|
||||
QList<QByteArray> result;
|
||||
|
||||
//Builtins:
|
||||
const QList<QByteArray> itemProperties = {"layer", "opacity", "gradient", "smooth", "antialiasing",
|
||||
"border", "baselineOffset", "focus", "activeFocusOnTab"};
|
||||
const QList<QByteArray> mouseAreaProperties = {"propagateComposedEvents", "preventStealing", "cursorShape",
|
||||
"scrollGestureEnabled", "drag", "acceptedButtons", "hoverEnabled"};
|
||||
const QList<QByteArray> flickableProperties = {"boundsBehavior", "boundsMovement",
|
||||
"flickDeceleration", "flickableDirection",
|
||||
"leftMargin", "rightMargin", "bottomMargin", "topMargin",
|
||||
"originX", "originY",
|
||||
"pixelAligned", "pressDelay", "synchronousDrag"};
|
||||
const QList<QByteArray> imageProperties = {"mirror", "mipmap", "cache", "autoTransform", "asynchronous",
|
||||
"sourceSize", "smooth"};
|
||||
const QList<QByteArray> textProperties = {"elide", "lineHeight", "lineHeightMode", "wrapMode", "style",
|
||||
"styleColor", "minimumPointSize", "minimumPixelSize", "styleColor",
|
||||
"fontSizeMode", "renderType", "textFormat", "maximumLineCount"};
|
||||
const QList<QByteArray> paddingProperties = {"bottomPadding", "topPadding", "leftPadding", "rightPadding"};
|
||||
const QList<QByteArray> columnRowProperties = {"layoutDirection"};
|
||||
const QList<QByteArray> listViewProperties = {"cacheBuffer", "highlightRangeMode", "highlightMoveDuration",
|
||||
"highlightResizeDuration", "preferredHighlightBegin", "layoutDirection",
|
||||
"preferredHighlightEnd", "highlightFollowsCurrentItem", "keyNavigationWraps",
|
||||
"snapMode", "highlightMoveVelocity", "highlightResizeVelocity"};
|
||||
//Animations:
|
||||
const QList<QByteArray> animationProperties = {"paused"};
|
||||
|
||||
//QtQuick.Controls:
|
||||
const QList<QByteArray> controlProperties = {"focusPolicy", "hoverEnabled", "wheelEnabled"};
|
||||
const QList<QByteArray> abstractButtonProperties = {"display", "autoExclusive"};
|
||||
const QList<QByteArray> buttonProperties = {"flat", "highlighted"};
|
||||
const QList<QByteArray> dialProperties = {}; //nothing in propeditor
|
||||
const QList<QByteArray> progressBarProperties = {"indeterminate"};
|
||||
const QList<QByteArray> radioButton = {}; //nothing in propeditor
|
||||
const QList<QByteArray> sliderProperties = {"live", "snapMode", "touchDragThreshold"};
|
||||
const QList<QByteArray> swipeViewProperties = {}; //nothing in propeditor
|
||||
const QList<QByteArray> switchProperties = {}; //nothing in propeditor
|
||||
|
||||
result.append(itemProperties);
|
||||
result.append(mouseAreaProperties);
|
||||
result.append(flickableProperties);
|
||||
result.append(imageProperties);
|
||||
result.append(textProperties);
|
||||
result.append(paddingProperties);
|
||||
result.append(columnRowProperties);
|
||||
result.append(listViewProperties);
|
||||
result.append(animationProperties);
|
||||
result.append(controlProperties);
|
||||
result.append(abstractButtonProperties);
|
||||
result.append(buttonProperties);
|
||||
result.append(dialProperties);
|
||||
result.append(progressBarProperties);
|
||||
result.append(radioButton);
|
||||
result.append(sliderProperties);
|
||||
result.append(swipeViewProperties);
|
||||
result.append(switchProperties);
|
||||
|
||||
return result;
|
||||
return (metaInfo.isSubclassOf(type.toUtf8()));
|
||||
}
|
||||
|
||||
bool PropertyEditorValue::isAvailable() const
|
||||
@@ -338,31 +275,38 @@ bool PropertyEditorValue::isAvailable() const
|
||||
if (!m_modelNode.isValid())
|
||||
return true;
|
||||
|
||||
const QList<QByteArray> nonMcuProperties = prepareNonMcuProperties();
|
||||
const QmlDesigner::DesignerMcuManager &mcuManager = QmlDesigner::DesignerMcuManager::instance();
|
||||
|
||||
const QByteArray fontPrefix = {"font"};
|
||||
const QList<QByteArray> nonMcuFontProperties = {"wordSpacing", "letterSpacing", "hintingPreference",
|
||||
"kerning", "preferShaping", "capitalization",
|
||||
"strikeout", "underline", "styleName"};
|
||||
if (mcuManager.isMCUProject()) {
|
||||
const QSet<QString> nonMcuProperties = mcuManager.bannedProperties();
|
||||
const auto mcuAllowedItemProperties = mcuManager.allowedItemProperties();
|
||||
const auto mcuBannedComplexProperties = mcuManager.bannedComplexProperties();
|
||||
|
||||
const QList<QByteArray> mcuTransformProperties = {"rotation", "scale", "transformOrigin"};
|
||||
const QList<QByteArray> list = name().split('.');
|
||||
const QByteArray pureName = list.constFirst();
|
||||
const QString pureNameStr = QString::fromUtf8(pureName);
|
||||
|
||||
const QList<QByteArray> list = name().split('.');
|
||||
const QByteArray pureName = list.constFirst();
|
||||
const QByteArray ending = list.constLast();
|
||||
const QString endingStr = QString::fromUtf8(ending);
|
||||
|
||||
QmlDesigner::DesignDocument *designDocument = QmlDesigner::QmlDesignerPlugin::instance()
|
||||
->documentManager()
|
||||
.currentDesignDocument();
|
||||
|
||||
if (designDocument && designDocument->isQtForMCUsProject()) {
|
||||
if (pureName == fontPrefix) {
|
||||
if (nonMcuFontProperties.contains(list.constLast()))
|
||||
return false;
|
||||
//allowed item properties:
|
||||
const auto itemTypes = mcuAllowedItemProperties.keys();
|
||||
for (const auto &itemType : itemTypes) {
|
||||
if (isAllowedSubclassType(itemType, m_modelNode.metaInfo())
|
||||
&& mcuAllowedItemProperties.value(itemType).contains(pureNameStr)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (nonMcuProperties.contains(pureName))
|
||||
|
||||
//banned properties:
|
||||
//with prefixes:
|
||||
if (mcuBannedComplexProperties.value(pureNameStr).contains(endingStr))
|
||||
return false;
|
||||
if (mcuTransformProperties.contains(pureName) && !itemOrImage(m_modelNode.metaInfo()))
|
||||
|
||||
//general group:
|
||||
if (nonMcuProperties.contains(pureNameStr))
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
260
src/plugins/qmldesigner/designermcumanager.cpp
Normal file
260
src/plugins/qmldesigner/designermcumanager.cpp
Normal file
@@ -0,0 +1,260 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2020 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "designermcumanager.h"
|
||||
#include "qmldesignerconstants.h"
|
||||
#include "qmldesignerplugin.h"
|
||||
#include "designersettings.h"
|
||||
#include "designdocument.h"
|
||||
|
||||
#include <qmljs/qmljssimplereader.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
static QString readProperty(const QString property, const QmlJS::SimpleReaderNode::Ptr &node)
|
||||
{
|
||||
const QVariant propertyVar = node->property(property);
|
||||
|
||||
if (!propertyVar.isNull() && propertyVar.isValid())
|
||||
return propertyVar.value<QString>();
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
static QStringList readPropertyList(const QString &property, const QmlJS::SimpleReaderNode::Ptr &node)
|
||||
{
|
||||
const QVariant propertyVar = node->property(property);
|
||||
|
||||
if (!propertyVar.isNull() && propertyVar.isValid())
|
||||
return propertyVar.value<QStringList>();
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
DesignerMcuManager &DesignerMcuManager::instance()
|
||||
{
|
||||
static DesignerMcuManager instance;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
QString DesignerMcuManager::mcuResourcesPath()
|
||||
{
|
||||
return Core::ICore::resourcePath() + QStringLiteral("/qmldesigner/qt4mcu");
|
||||
}
|
||||
|
||||
bool DesignerMcuManager::isMCUProject() const
|
||||
{
|
||||
QmlDesigner::DesignDocument *designDocument = QmlDesigner::QmlDesignerPlugin::instance()
|
||||
->documentManager().currentDesignDocument();
|
||||
if (designDocument)
|
||||
return designDocument->isQtForMCUsProject();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void DesignerMcuManager::readMetadata()
|
||||
{
|
||||
const QString mainMetadataFileName = "metadata.qml";
|
||||
|
||||
m_defaultVersion = {};
|
||||
m_versionsList.clear();
|
||||
|
||||
QmlJS::SimpleReader reader;
|
||||
const QmlJS::SimpleReaderNode::Ptr metadata =
|
||||
reader.readFile(mcuResourcesPath() + "/" + mainMetadataFileName);
|
||||
if (!metadata) {
|
||||
qWarning() << "Designer MCU metadata:" << reader.errors();
|
||||
return;
|
||||
}
|
||||
|
||||
const QmlJS::SimpleReaderNode::List versions = metadata->children();
|
||||
|
||||
if (versions.isEmpty()) {
|
||||
qWarning() << "Designer MCU metadata: metadata list is empty";
|
||||
return;
|
||||
}
|
||||
|
||||
const QVariant defaultVersion = metadata->property("defaultVersion");
|
||||
if (!defaultVersion.isNull() && defaultVersion.isValid()) {
|
||||
for (const auto& version : versions) {
|
||||
Version newVersion;
|
||||
|
||||
const QVariant vId = version->property("id");
|
||||
if (vId.isNull() || !vId.isValid())
|
||||
continue;
|
||||
|
||||
const QVariant vName = version->property("name");
|
||||
if (!vName.isNull() && vName.isValid())
|
||||
newVersion.name = vName.value<QString>();
|
||||
else
|
||||
continue;
|
||||
|
||||
const QVariant vPath = version->property("path");
|
||||
if (!vPath.isNull() && vPath.isValid())
|
||||
newVersion.fileName = vPath.value<QString>();
|
||||
else
|
||||
continue;
|
||||
|
||||
m_versionsList.push_back(newVersion);
|
||||
|
||||
if (vId == defaultVersion)
|
||||
m_defaultVersion = newVersion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DesignerMcuManager::readVersionData(const DesignerMcuManager::Version &version)
|
||||
{
|
||||
m_currentVersion = {};
|
||||
m_bannedItems.clear();
|
||||
m_allowedImports.clear();
|
||||
m_bannedImports.clear();
|
||||
m_bannedProperties.clear();
|
||||
m_allowedItemProperties.clear();
|
||||
m_bannedComplexProperties.clear();
|
||||
|
||||
QmlJS::SimpleReader reader;
|
||||
const QmlJS::SimpleReaderNode::Ptr versionData =
|
||||
reader.readFile(mcuResourcesPath() + "/" + version.fileName);
|
||||
if (!versionData) {
|
||||
qWarning() << "Designer MCU metadata:" << reader.errors();
|
||||
return;
|
||||
}
|
||||
|
||||
const QmlJS::SimpleReaderNode::List info = versionData->children();
|
||||
|
||||
if (info.isEmpty()) {
|
||||
qWarning() << "Designer MCU metadata: metadata list is empty";
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& child : info) {
|
||||
//handling specific item types:
|
||||
if (child->name() == "ComplexProperty") {
|
||||
if (child->propertyNames().contains("prefix")
|
||||
&& child->propertyNames().contains("bannedProperties")) {
|
||||
const QString complexPropPrefix(readProperty("prefix", child));
|
||||
const QStringList complexPropBans(readPropertyList("bannedProperties", child));
|
||||
|
||||
if (!complexPropPrefix.isEmpty() && !complexPropBans.isEmpty())
|
||||
m_bannedComplexProperties.insert(complexPropPrefix, complexPropBans);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
//handling allowed properties:
|
||||
if (child->propertyNames().contains("allowedProperties")) {
|
||||
const QStringList allowedProperties(readPropertyList("allowedProperties", child));
|
||||
|
||||
if (!allowedProperties.isEmpty())
|
||||
m_allowedItemProperties.insert(child->name(), allowedProperties);
|
||||
}
|
||||
|
||||
//handling banned properties:
|
||||
const QStringList bannedProperties = readPropertyList("bannedProperties", child);
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
m_bannedProperties.unite(QSet<QString>(bannedProperties.begin(), bannedProperties.end()));
|
||||
#elif
|
||||
m_bannedProperties.unite(QSet<QString>::fromList(bannedProperties));
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
const QList<QString> bannedItems = readPropertyList("bannedItems", versionData);
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
m_bannedItems = QSet<QString>(bannedItems.begin(), bannedItems.end());
|
||||
#elif
|
||||
m_bannedItems = QSet<QString>::fromList(bannedItems);
|
||||
#endif
|
||||
|
||||
m_allowedImports = readPropertyList("allowedImports", versionData);
|
||||
m_bannedImports = readPropertyList("bannedImports", versionData);
|
||||
m_currentVersion = version;
|
||||
}
|
||||
|
||||
DesignerMcuManager::Version DesignerMcuManager::currentVersion() const
|
||||
{
|
||||
return m_currentVersion;
|
||||
}
|
||||
|
||||
DesignerMcuManager::Version DesignerMcuManager::defaultVersion() const
|
||||
{
|
||||
return m_defaultVersion;
|
||||
}
|
||||
|
||||
DesignerMcuManager::VersionsList DesignerMcuManager::versions() const
|
||||
{
|
||||
return m_versionsList;
|
||||
}
|
||||
|
||||
QSet<QString> DesignerMcuManager::bannedItems() const
|
||||
{
|
||||
return m_bannedItems;
|
||||
}
|
||||
|
||||
QSet<QString> DesignerMcuManager::bannedProperties() const
|
||||
{
|
||||
return m_bannedProperties;
|
||||
}
|
||||
|
||||
QStringList DesignerMcuManager::allowedImports() const
|
||||
{
|
||||
return m_allowedImports;
|
||||
}
|
||||
|
||||
QStringList DesignerMcuManager::bannedImports() const
|
||||
{
|
||||
return m_bannedImports;
|
||||
}
|
||||
|
||||
QHash<QString, QStringList> DesignerMcuManager::allowedItemProperties() const
|
||||
{
|
||||
return m_allowedItemProperties;
|
||||
}
|
||||
|
||||
QHash<QString, QStringList> DesignerMcuManager::bannedComplexProperties() const
|
||||
{
|
||||
return m_bannedComplexProperties;
|
||||
}
|
||||
|
||||
DesignerMcuManager::DesignerMcuManager()
|
||||
{
|
||||
readMetadata();
|
||||
|
||||
readVersionData(m_defaultVersion);
|
||||
}
|
||||
|
||||
DesignerMcuManager::~DesignerMcuManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // QmlDesigner
|
90
src/plugins/qmldesigner/designermcumanager.h
Normal file
90
src/plugins/qmldesigner/designermcumanager.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2020 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QSet>
|
||||
#include <QHash>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
class DesignerMcuManager
|
||||
{
|
||||
public:
|
||||
struct Version {
|
||||
QString name;
|
||||
QString fileName;
|
||||
};
|
||||
using VersionsList = QList<Version>;
|
||||
|
||||
static DesignerMcuManager& instance();
|
||||
|
||||
static QString mcuResourcesPath();
|
||||
|
||||
bool isMCUProject() const;
|
||||
|
||||
void readMetadata();
|
||||
void readVersionData(const DesignerMcuManager::Version &version);
|
||||
|
||||
DesignerMcuManager::Version currentVersion() const;
|
||||
DesignerMcuManager::Version defaultVersion() const;
|
||||
DesignerMcuManager::VersionsList versions() const;
|
||||
|
||||
QSet<QString> bannedItems() const;
|
||||
QSet<QString> bannedProperties() const;
|
||||
|
||||
QStringList allowedImports() const;
|
||||
QStringList bannedImports() const;
|
||||
|
||||
QHash<QString, QStringList> allowedItemProperties() const;
|
||||
QHash<QString, QStringList> bannedComplexProperties() const;
|
||||
|
||||
DesignerMcuManager(DesignerMcuManager const&) = delete;
|
||||
void operator=(DesignerMcuManager const&) = delete;
|
||||
|
||||
private:
|
||||
DesignerMcuManager();
|
||||
~DesignerMcuManager();
|
||||
|
||||
private:
|
||||
DesignerMcuManager::Version m_currentVersion;
|
||||
DesignerMcuManager::Version m_defaultVersion;
|
||||
|
||||
QSet<QString> m_bannedItems;
|
||||
QSet<QString> m_bannedProperties;
|
||||
QStringList m_allowedImports;
|
||||
QStringList m_bannedImports;
|
||||
QHash<QString, QStringList> m_allowedItemProperties;
|
||||
QHash<QString, QStringList> m_bannedComplexProperties;
|
||||
|
||||
DesignerMcuManager::VersionsList m_versionsList;
|
||||
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner
|
@@ -10,7 +10,8 @@ HEADERS += $$PWD/qmldesignerconstants.h \
|
||||
$$PWD/documentmanager.h \
|
||||
$$PWD/documentwarningwidget.h \
|
||||
$$PWD/qmldesignericons.h \
|
||||
$$PWD/openuiqmlfiledialog.h
|
||||
$$PWD/openuiqmlfiledialog.h \
|
||||
$$PWD/designermcumanager.h
|
||||
|
||||
SOURCES += $$PWD/qmldesignerplugin.cpp \
|
||||
$$PWD/shortcutmanager.cpp \
|
||||
@@ -22,7 +23,8 @@ SOURCES += $$PWD/qmldesignerplugin.cpp \
|
||||
$$PWD/designmodecontext.cpp \
|
||||
$$PWD/documentmanager.cpp \
|
||||
$$PWD/documentwarningwidget.cpp \
|
||||
$$PWD/openuiqmlfiledialog.cpp
|
||||
$$PWD/openuiqmlfiledialog.cpp \
|
||||
$$PWD/designermcumanager.cpp
|
||||
|
||||
FORMS += $$PWD/settingspage.ui \
|
||||
$$PWD/openuiqmlfiledialog.ui
|
||||
|
@@ -928,6 +928,8 @@ Project {
|
||||
"settingspage.ui",
|
||||
"shortcutmanager.cpp",
|
||||
"shortcutmanager.h",
|
||||
"designermcumanager.cpp",
|
||||
"designermcumanager.h",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user