Skip to content
Permalink
Browse files
Merge pull request #4306 from boundlessgeo/sort_on_top
[attributetable] Fix "Move selection to top": for 2.18 regression fixes #15803
  • Loading branch information
elpaso committed May 11, 2017
2 parents 4a215ad + 8f862a5 commit 7ba28ec14be93047f8fbdbc971ea45c25aa42784
Showing with 27 additions and 6 deletions.
  1. +11 −2 src/core/qgsattributetableconfig.cpp
  2. +16 −4 src/gui/attributetable/qgsattributetablefiltermodel.cpp
@@ -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
@@ -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
@@ -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 );
@@ -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 ) ;
@@ -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();
}
}

0 comments on commit 7ba28ec

Please sign in to comment.