Skip to content

Commit 3661f92

Browse files
committed
Persist attribute table sort order when clicking on column header
And when sorting by preview expression
1 parent 4d48072 commit 3661f92

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

src/app/qgsattributetabledialog.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "qgsattributetablemodel.h"
2323
#include "qgsattributetablefiltermodel.h"
2424
#include "qgsattributetableview.h"
25-
#include "qgsorganizetablecolumnsdialog.h"
2625

2726
#include "qgsapplication.h"
2827
#include "qgsvectorlayer.h"

src/gui/attributetable/qgsattributetablefiltermodel.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ void QgsAttributeTableFilterModel::sort( int column, Qt::SortOrder order )
6666
int myColumn = mColumnMapping.at( column );
6767
masterModel()->prefetchColumnData( myColumn );
6868
QSortFilterProxyModel::sort( myColumn, order );
69+
emit sortColumnChanged( column, order );
6970
}
7071

7172
QVariant QgsAttributeTableFilterModel::data( const QModelIndex& index, int role ) const

src/gui/attributetable/qgsattributetablefiltermodel.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ class GUI_EXPORT QgsAttributeTableFilterModel: public QSortFilterProxyModel, pub
214214
*/
215215
void setAttributeTableConfig( const QgsAttributeTableConfig& config );
216216

217+
signals:
218+
/**
219+
* Is emitted whenever the sort column is changed
220+
* @param column The sort column
221+
* @param order The sort order
222+
*/
223+
void sortColumnChanged( int column, Qt::SortOrder order );
224+
217225
protected:
218226
/**
219227
* Returns true if the source row will be accepted

src/gui/attributetable/qgsdualview.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ void QgsDualView::init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, const Qg
104104
connect( mAttributeForm, SIGNAL( modeChanged( QgsAttributeForm::Mode ) ), this, SIGNAL( formModeChanged( QgsAttributeForm::Mode ) ) );
105105
connect( mMasterModel, SIGNAL( modelChanged() ), mAttributeForm, SLOT( refreshFeature() ) );
106106
connect( mAttributeForm, SIGNAL( filterExpressionSet( QString, QgsAttributeForm::FilterType ) ), this, SIGNAL( filterExpressionSet( QString, QgsAttributeForm::FilterType ) ) );
107+
connect( mFilterModel, SIGNAL( sortColumnChanged( int, Qt::SortOrder ) ), this, SLOT( onSortColumnChanged() ) );
107108
if ( mFeatureListPreviewButton->defaultAction() )
108109
mFeatureList->setDisplayExpression( mDisplayExpression );
109110
else
@@ -512,7 +513,6 @@ void QgsDualView::organizeColumns()
512513
if ( dialog.exec() == QDialog::Accepted )
513514
{
514515
QgsAttributeTableConfig config = dialog.config();
515-
mLayerCache->layer()->setAttributeTableConfig( config );
516516
setAttributeTableConfig( config );
517517
}
518518
}
@@ -651,6 +651,13 @@ void QgsDualView::previewExpressionChanged( const QString& expression )
651651
mLayerCache->layer()->setDisplayExpression( expression );
652652
}
653653

654+
void QgsDualView::onSortColumnChanged()
655+
{
656+
QgsAttributeTableConfig cfg = mLayerCache->layer()->attributeTableConfig();
657+
cfg.setSortExpression( mFilterModel->sortExpression() );
658+
mLayerCache->layer()->setAttributeTableConfig( cfg );
659+
}
660+
654661
void QgsDualView::sortByPreviewExpression()
655662
{
656663
setSortExpression( mFeatureList->displayExpression() );
@@ -684,6 +691,7 @@ void QgsDualView::setFeatureSelectionManager( QgsIFeatureSelectionManager* featu
684691

685692
void QgsDualView::setAttributeTableConfig( const QgsAttributeTableConfig& config )
686693
{
694+
mLayerCache->layer()->setAttributeTableConfig( config );
687695
mFilterModel->setAttributeTableConfig( config );
688696
mTableView->setAttributeTableConfig( config );
689697
mConfig = config;
@@ -695,6 +703,10 @@ void QgsDualView::setSortExpression( const QString& sortExpression )
695703
mFilterModel->sort( -1 );
696704
else
697705
mFilterModel->sort( sortExpression );
706+
707+
QgsAttributeTableConfig cfg = mLayerCache->layer()->attributeTableConfig();
708+
cfg.setSortExpression( sortExpression );
709+
mLayerCache->layer()->setAttributeTableConfig( cfg );
698710
}
699711

700712
QString QgsDualView::sortExpression() const

src/gui/attributetable/qgsdualview.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
290290

291291
void previewExpressionChanged( const QString& expression );
292292

293+
void onSortColumnChanged();
294+
293295
void sortByPreviewExpression();
294296

295297
/**

0 commit comments

Comments
 (0)