Skip to content
Permalink
Browse files
Merge pull request #4444 from boundlessgeo/sort_on_top_portTo3
[attributetable] Fix "Move selection to top" for 3.x regression fixes #15803
  • Loading branch information
elpaso committed May 11, 2017
2 parents f131792 + a924915 commit 8e60510e658552a33066b407e21c588fc86f3a9f
Showing with 24 additions and 5 deletions.
  1. +8 −1 src/core/qgsattributetableconfig.cpp
  2. +16 −4 src/gui/attributetable/qgsattributetablefiltermodel.cpp
@@ -197,7 +197,8 @@ void QgsAttributeTableConfig::readXml( const QDomNode &node )
}

mSortExpression = configNode.toElement().attribute( QStringLiteral( "sortExpression" ) );
mSortOrder = static_cast<Qt::SortOrder>( configNode.toElement().attribute( QStringLiteral( "sortOrder" ) ).toInt() );
Qt::SortOrder sortOrder = static_cast<Qt::SortOrder>( configNode.toElement().attribute( QStringLiteral( "sortOrder" ) ).toInt() );
setSortOrder( sortOrder );
}

QString QgsAttributeTableConfig::sortExpression() const
@@ -242,6 +243,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 8e60510

Please sign in to comment.