forked from qt-creator/qt-creator
QmlDesigner: Sort keys
Instead to trust programmers to add the entries sorted, we us an constexpr to sort them. Change-Id: I9129d3771d0451def726b230f8cd58e556c6b4be Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
#include <utils/ranges.h>
|
#include <utils/ranges.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
@@ -24,32 +25,110 @@ namespace {
|
|||||||
|
|
||||||
enum class ImportError { EmptyImportName, HasAlreadyImport, NoModule };
|
enum class ImportError { EmptyImportName, HasAlreadyImport, NoModule };
|
||||||
|
|
||||||
constexpr std::u16string_view qmlKeywords[]{
|
template<typename Type, typename... Entries>
|
||||||
u"alias", u"as", u"break", u"case", u"catch", u"continue", u"debugger", u"default",
|
constexpr auto toSortedArray(const Entries &...entries)
|
||||||
u"delete", u"do", u"else", u"finally", u"for", u"function", u"if", u"import",
|
{
|
||||||
u"in", u"instanceof", u"new", u"print", u"return", u"switch", u"this", u"throw",
|
std::array<Type, sizeof...(entries)> sortedArray = {entries...};
|
||||||
u"try", u"typeof", u"var", u"void", u"while", u"with",
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr std::u16string_view qmlDiscouragedIds[]{
|
std::sort(std::begin(sortedArray), std::end(sortedArray));
|
||||||
u"action", u"anchors", u"baseState", u"border", u"bottom", u"clip",
|
|
||||||
u"data", u"enabled", u"flow", u"focus", u"font", u"height",
|
|
||||||
u"id", u"item", u"layer", u"left", u"margin", u"opacity",
|
|
||||||
u"padding", u"parent", u"right", u"scale", u"shaderInfo", u"source",
|
|
||||||
u"sprite", u"spriteSequence", u"state", u"text", u"texture", u"time",
|
|
||||||
u"top", u"visible", u"width", u"x", u"y", u"z",
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr std::u16string_view qmlBuiltinTypes[]{
|
return sortedArray;
|
||||||
u"bool", u"color", u"date", u"double", u"enumeration", u"font",
|
}
|
||||||
u"int", u"list", u"matrix4x4", u"point", u"quaternion", u"real",
|
|
||||||
u"rect", u"size", u"string", u"url", u"var", u"variant",
|
constexpr auto qmlKeywords = toSortedArray<std::u16string_view>(u"alias",
|
||||||
u"vector", u"vector2d", u"vector3d", u"vector4d",
|
u"as",
|
||||||
};
|
u"break",
|
||||||
|
u"case",
|
||||||
|
u"catch",
|
||||||
|
u"continue",
|
||||||
|
u"debugger",
|
||||||
|
u"default",
|
||||||
|
u"delete",
|
||||||
|
u"do",
|
||||||
|
u"else",
|
||||||
|
u"finally",
|
||||||
|
u"for",
|
||||||
|
u"function",
|
||||||
|
u"if",
|
||||||
|
u"import",
|
||||||
|
u"in",
|
||||||
|
u"instanceof",
|
||||||
|
u"new",
|
||||||
|
u"print",
|
||||||
|
u"return",
|
||||||
|
u"switch",
|
||||||
|
u"this",
|
||||||
|
u"throw",
|
||||||
|
u"try",
|
||||||
|
u"typeof",
|
||||||
|
u"var",
|
||||||
|
u"void",
|
||||||
|
u"while",
|
||||||
|
u"with");
|
||||||
|
|
||||||
|
constexpr auto qmlDiscouragedIds = toSortedArray<std::u16string_view>(u"action",
|
||||||
|
u"anchors",
|
||||||
|
u"baseState",
|
||||||
|
u"border",
|
||||||
|
u"bottom",
|
||||||
|
u"clip",
|
||||||
|
u"data",
|
||||||
|
u"enabled",
|
||||||
|
u"flow",
|
||||||
|
u"focus",
|
||||||
|
u"font",
|
||||||
|
u"height",
|
||||||
|
u"id",
|
||||||
|
u"item",
|
||||||
|
u"layer",
|
||||||
|
u"left",
|
||||||
|
u"margin",
|
||||||
|
u"opacity",
|
||||||
|
u"padding",
|
||||||
|
u"parent",
|
||||||
|
u"right",
|
||||||
|
u"scale",
|
||||||
|
u"shaderInfo",
|
||||||
|
u"source",
|
||||||
|
u"sprite",
|
||||||
|
u"spriteSequence",
|
||||||
|
u"state",
|
||||||
|
u"text",
|
||||||
|
u"texture",
|
||||||
|
u"time",
|
||||||
|
u"top",
|
||||||
|
u"visible",
|
||||||
|
u"width",
|
||||||
|
u"x",
|
||||||
|
u"y",
|
||||||
|
u"z");
|
||||||
|
|
||||||
|
constexpr auto qmlBuiltinTypes = toSortedArray<std::u16string_view>(u"bool",
|
||||||
|
u"color",
|
||||||
|
u"date",
|
||||||
|
u"double",
|
||||||
|
u"enumeration",
|
||||||
|
u"font",
|
||||||
|
u"int",
|
||||||
|
u"list",
|
||||||
|
u"matrix4x4",
|
||||||
|
u"point",
|
||||||
|
u"quaternion",
|
||||||
|
u"real",
|
||||||
|
u"rect",
|
||||||
|
u"size",
|
||||||
|
u"string",
|
||||||
|
u"url",
|
||||||
|
u"var",
|
||||||
|
u"variant",
|
||||||
|
u"vector",
|
||||||
|
u"vector2d",
|
||||||
|
u"vector3d",
|
||||||
|
u"vector4d");
|
||||||
|
|
||||||
constexpr auto createBannedQmlIds()
|
constexpr auto createBannedQmlIds()
|
||||||
{
|
{
|
||||||
std::array<std::u16string_view, sizeof(qmlKeywords) + sizeof(qmlDiscouragedIds) + sizeof(qmlBuiltinTypes)> ids;
|
std::array<std::u16string_view, qmlKeywords.size() + qmlDiscouragedIds.size() + qmlBuiltinTypes.size()> ids;
|
||||||
|
|
||||||
auto idsEnd = std::copy(std::begin(qmlKeywords), std::end(qmlKeywords), ids.begin());
|
auto idsEnd = std::copy(std::begin(qmlKeywords), std::end(qmlKeywords), ids.begin());
|
||||||
idsEnd = std::copy(std::begin(qmlDiscouragedIds), std::end(qmlDiscouragedIds), idsEnd);
|
idsEnd = std::copy(std::begin(qmlDiscouragedIds), std::end(qmlDiscouragedIds), idsEnd);
|
||||||
|
|||||||
Reference in New Issue
Block a user