From 6e3108b33e51126d911a2939e4b555267227276b 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 (cherry picked from commit a1829f0317ccec21513ff813de35786dc63f2de7) Reviewed-by: Tim Jenssen --- .../collectiondatatypemodel.cpp | 3 +- .../collectioneditor/collectiondetails.cpp | 34 +++++-------------- .../collectioneditor/collectiondetails.h | 2 +- .../collectiondetailsmodel.cpp | 2 +- 4 files changed, 12 insertions(+), 29 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 9005882813d..d7cd3ccbf8f 100644 --- a/src/plugins/qmldesigner/components/collectioneditor/collectiondetails.cpp +++ b/src/plugins/qmldesigner/components/collectioneditor/collectiondetails.cpp @@ -107,18 +107,15 @@ static bool getCustomUrl(const QString &value, if (urlResult) urlResult->clear(); - if (subType) - subType->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. @@ -144,7 +141,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); @@ -176,7 +173,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: { @@ -187,7 +184,7 @@ static CollectionProperty::DataType dataTypeFromJsonValue(const QJsonValue &valu case JsonType::String: return dataTypeFromString(value.toString()); default: - return DataType::Unknown; + return DataType::String; } } @@ -208,9 +205,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; @@ -258,21 +253,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(); @@ -606,7 +590,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::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); }