fix outliner sorting using incorrect types for comparisons (#2052)
* fix outliner sorting using incorrect types for comparisons, fixes for [LY-122258] and [LYN-3666] Signed-off-by: Alex Montgomery <alexmont@amazon.com> * fix annoying but necessary Qt type cast Signed-off-by: Alex Montgomery <alexmont@amazon.com>
This commit is contained in:
+18
-1
@@ -32,7 +32,24 @@ bool OutlinerSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelI
|
||||
|
||||
bool OutlinerSortFilterProxyModel::lessThan(const QModelIndex& leftIndex, const QModelIndex& rightIndex) const
|
||||
{
|
||||
return sourceModel()->data(leftIndex).toString() < sourceModel()->data(rightIndex).toString();
|
||||
if (leftIndex.isValid() && rightIndex.isValid())
|
||||
{
|
||||
QVariant leftData = sourceModel()->data(leftIndex);
|
||||
QVariant rightData = sourceModel()->data(rightIndex);
|
||||
|
||||
// make sure to compare the correct data types for sorting the current column
|
||||
AZ_Assert(leftData.type() == rightData.type(), "OutlinerSortFilterProxyModel::lessThan types do not agree!");
|
||||
if (static_cast<QMetaType::Type>(leftData.type()) == QMetaType::QString)
|
||||
{
|
||||
return leftData.toString() < rightData.toString();
|
||||
}
|
||||
else if (static_cast<QMetaType::Type>(leftData.type()) == QMetaType::ULongLong)
|
||||
{
|
||||
return leftData.toULongLong() < rightData.toULongLong();
|
||||
}
|
||||
AZ_Error("Editor", false, "Error! Unhandled type \"%s\" in OutlinerSortFilterProxyModel::lessThan", leftData.typeName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void OutlinerSortFilterProxyModel::sort(int /*column*/, Qt::SortOrder /*order*/)
|
||||
|
||||
+18
-1
@@ -34,7 +34,24 @@ namespace AzToolsFramework
|
||||
|
||||
bool EntityOutlinerSortFilterProxyModel::lessThan(const QModelIndex& leftIndex, const QModelIndex& rightIndex) const
|
||||
{
|
||||
return sourceModel()->data(leftIndex).toString() < sourceModel()->data(rightIndex).toString();
|
||||
if (leftIndex.isValid() && rightIndex.isValid())
|
||||
{
|
||||
QVariant leftData = sourceModel()->data(leftIndex);
|
||||
QVariant rightData = sourceModel()->data(rightIndex);
|
||||
|
||||
// make sure to compare the correct data types for sorting the current column
|
||||
AZ_Assert(leftData.type() == rightData.type(), "EntityOutlinerSortFilterProxyModel::lessThan types do not agree!");
|
||||
if (static_cast<QMetaType::Type>(leftData.type()) == QMetaType::QString)
|
||||
{
|
||||
return leftData.toString() < rightData.toString();
|
||||
}
|
||||
else if (static_cast<QMetaType::Type>(leftData.type()) == QMetaType::ULongLong)
|
||||
{
|
||||
return leftData.toULongLong() < rightData.toULongLong();
|
||||
}
|
||||
AZ_Error("Editor", false, "Error! Unhandled type \"%s\" in EntityOutlinerSortFilterProxyModel::lessThan", leftData.typeName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void EntityOutlinerSortFilterProxyModel::sort(int /*column*/, Qt::SortOrder /*order*/)
|
||||
|
||||
Reference in New Issue
Block a user