QmlDesigner: Remove "Unknown" from available datatypes

Task-number: QDS-12555
Change-Id: I9c3261ac23188bcd7db875bec49091d044231a9f
Reviewed-by: Ali Kianian <ali.kianian@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Shrief Gabr
2024-04-24 11:30:08 +03:00
parent d051348069
commit a1829f0317
4 changed files with 13 additions and 27 deletions

View File

@@ -23,7 +23,6 @@ const QList<CollectionDataTypeModel::Details> 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()

View File

@@ -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<CollectionProperty> 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<VariantType, DataType> 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)

View File

@@ -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);

View File

@@ -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);
}