Skip to content
Permalink
Browse files

Persist attribute table sort order when clicking on column header

And when sorting by preview expression
  • Loading branch information
m-kuhn committed Jun 23, 2016
1 parent 4d48072 commit 3661f92cc9d58f4dc40ad8dc5f8aefca5fa55558
@@ -22,7 +22,6 @@
#include "qgsattributetablemodel.h"
#include "qgsattributetablefiltermodel.h"
#include "qgsattributetableview.h"
#include "qgsorganizetablecolumnsdialog.h"

#include "qgsapplication.h"
#include "qgsvectorlayer.h"
@@ -66,6 +66,7 @@ void QgsAttributeTableFilterModel::sort( int column, Qt::SortOrder order )
int myColumn = mColumnMapping.at( column );
masterModel()->prefetchColumnData( myColumn );
QSortFilterProxyModel::sort( myColumn, order );
emit sortColumnChanged( column, order );
}

QVariant QgsAttributeTableFilterModel::data( const QModelIndex& index, int role ) const
@@ -214,6 +214,14 @@ class GUI_EXPORT QgsAttributeTableFilterModel: public QSortFilterProxyModel, pub
*/
void setAttributeTableConfig( const QgsAttributeTableConfig& config );

signals:
/**
* Is emitted whenever the sort column is changed
* @param column The sort column
* @param order The sort order
*/
void sortColumnChanged( int column, Qt::SortOrder order );

protected:
/**
* Returns true if the source row will be accepted
@@ -104,6 +104,7 @@ void QgsDualView::init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, const Qg
connect( mAttributeForm, SIGNAL( modeChanged( QgsAttributeForm::Mode ) ), this, SIGNAL( formModeChanged( QgsAttributeForm::Mode ) ) );
connect( mMasterModel, SIGNAL( modelChanged() ), mAttributeForm, SLOT( refreshFeature() ) );
connect( mAttributeForm, SIGNAL( filterExpressionSet( QString, QgsAttributeForm::FilterType ) ), this, SIGNAL( filterExpressionSet( QString, QgsAttributeForm::FilterType ) ) );
connect( mFilterModel, SIGNAL( sortColumnChanged( int, Qt::SortOrder ) ), this, SLOT( onSortColumnChanged() ) );
if ( mFeatureListPreviewButton->defaultAction() )
mFeatureList->setDisplayExpression( mDisplayExpression );
else
@@ -512,7 +513,6 @@ void QgsDualView::organizeColumns()
if ( dialog.exec() == QDialog::Accepted )
{
QgsAttributeTableConfig config = dialog.config();
mLayerCache->layer()->setAttributeTableConfig( config );
setAttributeTableConfig( config );
}
}
@@ -651,6 +651,13 @@ void QgsDualView::previewExpressionChanged( const QString& expression )
mLayerCache->layer()->setDisplayExpression( expression );
}

void QgsDualView::onSortColumnChanged()
{
QgsAttributeTableConfig cfg = mLayerCache->layer()->attributeTableConfig();
cfg.setSortExpression( mFilterModel->sortExpression() );
mLayerCache->layer()->setAttributeTableConfig( cfg );
}

void QgsDualView::sortByPreviewExpression()
{
setSortExpression( mFeatureList->displayExpression() );
@@ -684,6 +691,7 @@ void QgsDualView::setFeatureSelectionManager( QgsIFeatureSelectionManager* featu

void QgsDualView::setAttributeTableConfig( const QgsAttributeTableConfig& config )
{
mLayerCache->layer()->setAttributeTableConfig( config );
mFilterModel->setAttributeTableConfig( config );
mTableView->setAttributeTableConfig( config );
mConfig = config;
@@ -695,6 +703,10 @@ void QgsDualView::setSortExpression( const QString& sortExpression )
mFilterModel->sort( -1 );
else
mFilterModel->sort( sortExpression );

QgsAttributeTableConfig cfg = mLayerCache->layer()->attributeTableConfig();
cfg.setSortExpression( sortExpression );
mLayerCache->layer()->setAttributeTableConfig( cfg );
}

QString QgsDualView::sortExpression() const
@@ -290,6 +290,8 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas

void previewExpressionChanged( const QString& expression );

void onSortColumnChanged();

void sortByPreviewExpression();

/**

0 comments on commit 3661f92

Please sign in to comment.
You can’t perform that action at this time.