Skip to content

Commit

Permalink
Don't sort FeaturesModels by default
Browse files Browse the repository at this point in the history
  • Loading branch information
uclaros committed Oct 8, 2024
1 parent 2de2e33 commit fed0c81
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/featuresmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void FeaturesModel::setupFeatureRequest( QgsFeatureRequest &request )
request.setFilterExpression( buildSearchExpression() );
}

if ( mLayer && !mLayer->attributeTableConfig().sortExpression().isEmpty() )
if ( mUseAttributeTableSortOrder && mLayer && !mLayer->attributeTableConfig().sortExpression().isEmpty() )
{
// get a context with global, project and layer scopes
// QGIS docs are not very clear, but this context is also used for evaluation of the request's 'order by' expressions too
Expand Down
6 changes: 6 additions & 0 deletions app/featuresmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class FeaturesModel : public QAbstractListModel
// Name of the property is intentionally `count` so that it matches ListModel's count property
Q_PROPERTY( int count READ count NOTIFY countChanged )

// Returns if the model should be sorted according to the layer's attribute table configuration sort order
Q_PROPERTY( bool useAttributeTableSortOrder MEMBER mUseAttributeTableSortOrder )

public:

enum ModelRoles
Expand Down Expand Up @@ -160,6 +163,9 @@ class FeaturesModel : public QAbstractListModel
QAtomicInt mNextSearchId = 0;
QFutureWatcher<QgsFeatureList> mSearchResultWatcher;
bool mFetchingResults = false;
bool mUseAttributeTableSortOrder = false;

friend class TestModels;
};

#endif // FEATURESMODEL_H
1 change: 1 addition & 0 deletions app/qml/layers/MMFeaturesListPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ MMComponents.MMPage {
model: MM.FeaturesModel {
id: featuresModel

useAttributeTableSortOrder: true
layer: root.selectedLayer
}

Expand Down
4 changes: 2 additions & 2 deletions app/test/testmodels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void TestModels::testFeaturesModelSorted()
QVERIFY( layer && layer->isValid() );

// enable sorting
model.mUseAttributeTableSortOrder = true;
QgsAttributeTableConfig conf = layer->attributeTableConfig();
conf.setSortExpression( QStringLiteral( "Name" ) );
layer->setAttributeTableConfig( conf );
Expand Down Expand Up @@ -105,8 +106,7 @@ void TestModels::testFeaturesModelSorted()

// disable sorting and filtering
// should get all items with default ordering
conf.setSortExpression( QString() );
layer->setAttributeTableConfig( conf );
model.mUseAttributeTableSortOrder = false;

model.setSearchExpression( QString() );

Expand Down

1 comment on commit fed0c81

@inputapp-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS - version 24.10.668611 just submitted!

Please sign in to comment.