From a1829f0317ccec21513ff813de35786dc63f2de7 Mon Sep 17 00:00:00 2001 From: Shrief Gabr Date: Wed, 24 Apr 2024 11:30:08 +0300 Subject: [PATCH] QmlDesigner: Remove "Unknown" from available datatypes Task-number: QDS-12555 Change-Id: I9c3261ac23188bcd7db875bec49091d044231a9f Reviewed-by: Ali Kianian Reviewed-by: Qt CI Patch Build Bot Reviewed-by: Mahmoud Badri --- .../collectiondatatypemodel.cpp | 3 +- .../collectioneditor/collectiondetails.cpp | 33 ++++++------------- .../collectioneditor/collectiondetails.h | 2 +- .../collectiondetailsmodel.cpp | 2 +- 4 files changed, 13 insertions(+), 27 deletions(-) diff --git a/src/plugins/qmldesigner/components/collectioneditor/collectiondatatypemodel.cpp b/src/plugins/qmldesigner/components/collectioneditor/collectiondatatypemodel.cpp index cb306c58cb9..9a534ec88e6 100644 --- a/src/plugins/qmldesigner/components/collectioneditor/collectiondatatypemodel.cpp +++ b/src/plugins/qmldesigner/components/collectioneditor/collectiondatatypemodel.cpp @@ -23,7 +23,6 @@ const QList CollectionDataTypeModel::m_ordered {DataType::Color, "Color", "HEX value"}, {DataType::Url, "Url", "Resource locator"}, {DataType::Boolean, "Boolean", "True/false"}, - {DataType::Unknown, "Unknown", "Unknown data type"}, }; CollectionDataTypeModel::CollectionDataTypeModel(QObject *parent) @@ -76,7 +75,7 @@ CollectionDetails::DataType CollectionDataTypeModel::dataTypeFromString(const QS if (stringTypeHash.contains(dataType)) return stringTypeHash.value(dataType); - return DataType::Unknown; + return DataType::String; } void CollectionDataTypeModel::registerDeclarativeType() diff --git a/src/plugins/qmldesigner/components/collectioneditor/collectiondetails.cpp b/src/plugins/qmldesigner/components/collectioneditor/collectiondetails.cpp index bfe3ca59f53..3ff37a6fc27 100644 --- a/src/plugins/qmldesigner/components/collectioneditor/collectiondetails.cpp +++ b/src/plugins/qmldesigner/components/collectioneditor/collectiondetails.cpp @@ -59,7 +59,7 @@ public: * * @param value The input value to be evaluated * @param dataType if the value is a valid url, the data type - * will be stored to this parameter, otherwise, it will be Unknown + * will be stored to this parameter, otherwise, it will be String * @param urlResult if the value is a valid url, the address * will be stored in this parameter, otherwise it will be empty. * @return true if the result is url @@ -92,15 +92,15 @@ static bool getCustomUrl(const QString &value, if (urlResult) urlResult->clear(); - dataType = CollectionDetails::DataType::Unknown; + dataType = CollectionDetails::DataType::String; return false; } /** * @brief dataTypeFromString * @param value The string value to be evaluated - * @return Unknown if the string is empty, But returns Bool, Color, Integer, - * Real, Url, Image if these types are detected within the non-empty string, + * @return Bool, Color, Integer, Real, Url, + * Image if these types are detected within the non-empty string, * Otherwise it returns String. * If the value is integer, but it's out of the int range, it will be * considered as a Real. @@ -126,7 +126,7 @@ static CollectionDetails::DataType dataTypeFromString(const QString &value) }({boolIndex, colorIndex, integerIndex, realIndex}); if (value.isEmpty()) - return DataType::Unknown; + return DataType::String; const QString trimmedValue = value.trimmed(); QRegularExpressionMatch match = validator.match(trimmedValue); @@ -158,7 +158,7 @@ static CollectionProperty::DataType dataTypeFromJsonValue(const QJsonValue &valu switch (value.type()) { case JsonType::Null: case JsonType::Undefined: - return DataType::Unknown; + return DataType::String; case JsonType::Bool: return DataType::Boolean; case JsonType::Double: { @@ -169,7 +169,7 @@ static CollectionProperty::DataType dataTypeFromJsonValue(const QJsonValue &valu case JsonType::String: return dataTypeFromString(value.toString()); default: - return DataType::Unknown; + return DataType::String; } } @@ -190,9 +190,7 @@ static QList getColumnsFromImportedJsonArray(const QJsonArra const QString propertyName = element.key(); if (resultSet.contains(propertyName)) { CollectionProperty &property = result[resultSet.value(propertyName)]; - if (property.type == DataType::Unknown) { - property.type = dataTypeFromJsonValue(element.value()); - } else if (property.type == DataType::Integer) { + if (property.type == DataType::Integer) { const DataType currentCellDataType = dataTypeFromJsonValue(element.value()); if (currentCellDataType == DataType::Real) property.type = currentCellDataType; @@ -234,21 +232,10 @@ static QVariant valueToVariant(const QJsonValue &value, CollectionDetails::DataT } static QJsonValue variantToJsonValue( - const QVariant &variant, CollectionDetails::DataType type = CollectionDetails::DataType::Unknown) + const QVariant &variant, CollectionDetails::DataType type = CollectionDetails::DataType::String) { - using VariantType = QVariant::Type; using DataType = CollectionDetails::DataType; - if (type == CollectionDetails::DataType::Unknown) { - static const QHash typeMap = {{VariantType::Bool, DataType::Boolean}, - {VariantType::Double, DataType::Real}, - {VariantType::Int, DataType::Integer}, - {VariantType::String, DataType::String}, - {VariantType::Color, DataType::Color}, - {VariantType::Url, DataType::Url}}; - type = typeMap.value(variant.type(), DataType::Unknown); - } - switch (type) { case DataType::Boolean: return variant.toBool(); @@ -570,7 +557,7 @@ DataTypeWarning::Warning CollectionDetails::cellWarningCheck(int row, int column const DataType columnType = typeAt(column); const DataType cellType = typeAt(row, column); - if (columnType == DataType::Unknown || isEmptyJsonValue(cellValue)) + if (isEmptyJsonValue(cellValue)) return DataTypeWarning::Warning::None; if ((columnType == DataType::String || columnType == DataType::Real) && cellType == DataType::Integer) diff --git a/src/plugins/qmldesigner/components/collectioneditor/collectiondetails.h b/src/plugins/qmldesigner/components/collectioneditor/collectiondetails.h index b84c214570a..7243c585c6b 100644 --- a/src/plugins/qmldesigner/components/collectioneditor/collectiondetails.h +++ b/src/plugins/qmldesigner/components/collectioneditor/collectiondetails.h @@ -90,7 +90,7 @@ public: void insertColumn(const QString &propertyName, int colIdx = -1, const QVariant &defaultValue = {}, - DataType type = DataType::Unknown); + DataType type = DataType::String); bool removeColumns(int colIdx, int count = 1); void insertEmptyRows(int row = 0, int count = 1); diff --git a/src/plugins/qmldesigner/components/collectioneditor/collectiondetailsmodel.cpp b/src/plugins/qmldesigner/components/collectioneditor/collectiondetailsmodel.cpp index d2917ec3022..fcd6d686efd 100644 --- a/src/plugins/qmldesigner/components/collectioneditor/collectiondetailsmodel.cpp +++ b/src/plugins/qmldesigner/components/collectioneditor/collectiondetailsmodel.cpp @@ -197,7 +197,7 @@ QVariant CollectionDetailsModel::headerData(int section, Qt::Orientation orienta CollectionDetails::DataType CollectionDetailsModel::propertyDataType(int column) const { - QTC_ASSERT(m_currentCollection.hasValidReference(), return CollectionDetails::DataType::Unknown); + QTC_ASSERT(m_currentCollection.hasValidReference(), return CollectionDetails::DataType::String); return m_currentCollection.typeAt(column); }