Skip to content
Permalink
Browse files
[attributetable] fix sortOnTop due to sortOrder wrong enum values fro…
…m QgsAttributeTableConfig: fixes #15803

port to 3.0 for #4306
  • Loading branch information
luipir committed May 10, 2017
1 parent 212acc1 commit c092effc1c9f1add63b88ce36aa0deff19890496
Showing with 28 additions and 4 deletions.
  1. +12 −0 src/core/qgsattributetableconfig.cpp
  2. +16 −4 src/gui/attributetable/qgsattributetablefiltermodel.cpp
@@ -198,6 +198,12 @@ void QgsAttributeTableConfig::readXml( const QDomNode &node )

mSortExpression = configNode.toElement().attribute( QStringLiteral( "sortExpression" ) );
mSortOrder = static_cast<Qt::SortOrder>( configNode.toElement().attribute( QStringLiteral( "sortOrder" ) ).toInt() );
// fix https://hub.qgis.org/issues/15803
// because static_cast give umpredictable value if value is not in the enum range
if ( mSortOrder != Qt::AscendingOrder && mSortOrder != Qt::DescendingOrder )
{
mSortOrder = Qt::AscendingOrder;
}
}

QString QgsAttributeTableConfig::sortExpression() const
@@ -242,6 +248,12 @@ Qt::SortOrder QgsAttributeTableConfig::sortOrder() const

void QgsAttributeTableConfig::setSortOrder( Qt::SortOrder sortOrder )
{
// fix https://hub.qgis.org/issues/15803
if ( sortOrder != Qt::AscendingOrder && sortOrder != Qt::DescendingOrder )
{
sortOrder = Qt::AscendingOrder;
}

mSortOrder = sortOrder;
}

@@ -64,6 +64,9 @@ bool QgsAttributeTableFilterModel::lessThan( const QModelIndex &left, const QMod

void QgsAttributeTableFilterModel::sort( int column, Qt::SortOrder order )
{
if ( order != Qt::AscendingOrder && order != Qt::DescendingOrder )
order = Qt::AscendingOrder;

int myColumn = mColumnMapping.at( column );
masterModel()->prefetchColumnData( myColumn );
QSortFilterProxyModel::sort( myColumn, order );
@@ -211,6 +214,9 @@ void QgsAttributeTableFilterModel::setAttributeTableConfig( const QgsAttributeTa

void QgsAttributeTableFilterModel::sort( const QString &expression, Qt::SortOrder order )
{
if ( order != Qt::AscendingOrder && order != Qt::DescendingOrder )
order = Qt::AscendingOrder;

QSortFilterProxyModel::sort( -1 );
masterModel()->prefetchSortData( expression );
QSortFilterProxyModel::sort( 0, order ) ;
@@ -226,11 +232,17 @@ void QgsAttributeTableFilterModel::setSelectedOnTop( bool selectedOnTop )
if ( mSelectedOnTop != selectedOnTop )
{
mSelectedOnTop = selectedOnTop;
int column = sortColumn();
Qt::SortOrder order = sortOrder();

if ( sortColumn() == -1 )
{
sort( 0 );
}
// set default sort values if they are not correctly set
if ( column < 0 )
column = 0;

if ( order != Qt::AscendingOrder && order != Qt::DescendingOrder )
order = Qt::AscendingOrder;

sort( column, order );
invalidate();
}
}

0 comments on commit c092eff

Please sign in to comment.