Skip to content

Commit

Permalink
Merge pull request #4306 from boundlessgeo/sort_on_top
Browse files Browse the repository at this point in the history
[attributetable] Fix "Move selection to top": for 2.18 regression fixes #15803
  • Loading branch information
elpaso authored May 11, 2017
2 parents 4a215ad + 8f862a5 commit 7ba28ec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
13 changes: 11 additions & 2 deletions src/core/qgsattributetableconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ void QgsAttributeTableConfig::readXml( const QDomNode& node )
}

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

QString QgsAttributeTableConfig::sortExpression() const
Expand Down Expand Up @@ -241,7 +242,15 @@ Qt::SortOrder QgsAttributeTableConfig::sortOrder() const

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

void QgsAttributeTableConfig::writeXml( QDomNode& node ) const
Expand Down
20 changes: 16 additions & 4 deletions src/gui/attributetable/qgsattributetablefiltermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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 );
Expand Down Expand Up @@ -210,6 +213,9 @@ void QgsAttributeTableFilterModel::setAttributeTableConfig( const QgsAttributeTa

void QgsAttributeTableFilterModel::sort( 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 ) ;
Expand All @@ -225,11 +231,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();
}
}
Expand Down

0 comments on commit 7ba28ec

Please sign in to comment.