Skip to content

Commit

Permalink
Use word based search when filtering CRS
Browse files Browse the repository at this point in the history
So that typing eg "world winkel" will show the "World_Winkel_Tripel_NGS"
CRS
  • Loading branch information
nyalldawson committed Dec 12, 2024
1 parent 1adfe87 commit ae92a28
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/gui/proj/qgscoordinatereferencesystemmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,15 @@ bool QgsCoordinateReferenceSystemProxyModel::filterAcceptsRow( int sourceRow, co
if ( !mFilterString.trimmed().isEmpty() )
{
const QString name = sourceModel()->data( sourceIndex, static_cast<int>( QgsCoordinateReferenceSystemModel::CustomRole::Name ) ).toString();
if ( !( QgsStringUtils::containsByWord( name, mFilterString )
QString candidate = name;
const QString groupName = sourceModel()->data( sourceIndex, static_cast<int>( QgsCoordinateReferenceSystemModel::CustomRole::Group ) ).toString();
if ( !groupName.isEmpty() )
candidate += ' ' + groupName;
const QString projectionName = sourceModel()->data( sourceIndex, static_cast<int>( QgsCoordinateReferenceSystemModel::CustomRole::Projection ) ).toString();
if ( !projectionName.isEmpty() )
candidate += ' ' + projectionName;

if ( !( QgsStringUtils::containsByWord( candidate, mFilterString )
|| authid.contains( mFilterString, Qt::CaseInsensitive ) ) )
return false;
}
Expand Down
29 changes: 29 additions & 0 deletions tests/src/python/test_qgscoordinatereferencesystemmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,35 @@ def test_proxy_model(self):
][0]
self.assertTrue(epsg_4347_index.isValid())

model.setFilterString("equal gda2020 Area")
projected_index = [
model.index(row, 0, QModelIndex())
for row in range(model.rowCount(QModelIndex()))
if model.data(
model.index(row, 0, QModelIndex()),
QgsCoordinateReferenceSystemModel.Roles.RoleGroupId,
)
== "Projected"
][0]
aae_index = [
model.index(row, 0, projected_index)
for row in range(model.rowCount(projected_index))
if model.data(
model.index(row, 0, projected_index),
Qt.DisplayRole,
)
== "Albers Equal Area"
][0]
epsg_9473_index = [
model.index(row, 0, aae_index)
for row in range(model.rowCount(aae_index))
if model.data(
model.index(row, 0, aae_index),
QgsCoordinateReferenceSystemModel.Roles.RoleAuthId,
)
== "EPSG:9473"
][0]

model.setFilterString("")

# set filtered list of crs to show
Expand Down

0 comments on commit ae92a28

Please sign in to comment.