Skip to content

Commit

Permalink
Add CRS group name and projection name to CRS model data
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 11, 2024
1 parent fe45e21 commit 9e15a54
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
QgsCoordinateReferenceSystemModel.Roles.RoleProj = QgsCoordinateReferenceSystemModel.CustomRole.Proj
QgsCoordinateReferenceSystemModel.RoleProj.is_monkey_patched = True
QgsCoordinateReferenceSystemModel.RoleProj.__doc__ = "The coordinate reference system's PROJ representation. This is only used for non-standard CRS (i.e. those not present in the database)."
QgsCoordinateReferenceSystemModel.Group = QgsCoordinateReferenceSystemModel.CustomRole.Group
QgsCoordinateReferenceSystemModel.Group.is_monkey_patched = True
QgsCoordinateReferenceSystemModel.Group.__doc__ = "Group name. \n.. versionadded:: 3.42"
QgsCoordinateReferenceSystemModel.Projection = QgsCoordinateReferenceSystemModel.CustomRole.Projection
QgsCoordinateReferenceSystemModel.Projection.is_monkey_patched = True
QgsCoordinateReferenceSystemModel.Projection.__doc__ = "Projection name. \n.. versionadded:: 3.42"
QgsCoordinateReferenceSystemModel.CustomRole.__doc__ = """Custom model roles.
.. note::
Expand Down Expand Up @@ -73,6 +79,14 @@
Available as ``QgsCoordinateReferenceSystemModel.RoleProj`` in older QGIS releases.
* ``Group``: Group name.
.. versionadded:: 3.42
* ``Projection``: Projection name.
.. versionadded:: 3.42
"""
# --
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ A tree model for display of known coordinate reference systems.
GroupId,
Wkt,
Proj,
Group,
Projection,
};

QgsCoordinateReferenceSystemModel( QObject *parent /TransferThis/ = 0 );
Expand Down
14 changes: 14 additions & 0 deletions python/gui/auto_additions/qgscoordinatereferencesystemmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
QgsCoordinateReferenceSystemModel.Roles.RoleProj = QgsCoordinateReferenceSystemModel.CustomRole.Proj
QgsCoordinateReferenceSystemModel.RoleProj.is_monkey_patched = True
QgsCoordinateReferenceSystemModel.RoleProj.__doc__ = "The coordinate reference system's PROJ representation. This is only used for non-standard CRS (i.e. those not present in the database)."
QgsCoordinateReferenceSystemModel.Group = QgsCoordinateReferenceSystemModel.CustomRole.Group
QgsCoordinateReferenceSystemModel.Group.is_monkey_patched = True
QgsCoordinateReferenceSystemModel.Group.__doc__ = "Group name. \n.. versionadded:: 3.42"
QgsCoordinateReferenceSystemModel.Projection = QgsCoordinateReferenceSystemModel.CustomRole.Projection
QgsCoordinateReferenceSystemModel.Projection.is_monkey_patched = True
QgsCoordinateReferenceSystemModel.Projection.__doc__ = "Projection name. \n.. versionadded:: 3.42"
QgsCoordinateReferenceSystemModel.CustomRole.__doc__ = """Custom model roles.
.. note::
Expand Down Expand Up @@ -73,6 +79,14 @@
Available as ``QgsCoordinateReferenceSystemModel.RoleProj`` in older QGIS releases.
* ``Group``: Group name.
.. versionadded:: 3.42
* ``Projection``: Projection name.
.. versionadded:: 3.42
"""
# --
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ A tree model for display of known coordinate reference systems.
GroupId,
Wkt,
Proj,
Group,
Projection,
};

QgsCoordinateReferenceSystemModel( QObject *parent /TransferThis/ = 0 );
Expand Down
9 changes: 9 additions & 0 deletions src/gui/proj/qgscoordinatereferencesystemmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ QVariant QgsCoordinateReferenceSystemModel::data( const QModelIndex &index, int
case static_cast<int>( CustomRole::Proj ):
return crsNode->proj();

case static_cast<int>( CustomRole::Group ):
return crsNode->group();

case static_cast<int>( CustomRole::Projection ):
return crsNode->projection();

default:
break;
}
Expand Down Expand Up @@ -424,6 +430,7 @@ QgsCoordinateReferenceSystemModelCrsNode *QgsCoordinateReferenceSystemModel::add
break;
}
}
crsNode->setGroup( groupName );

if ( QgsCoordinateReferenceSystemModelGroupNode *group = parentNode->getChildGroupNode( groupId ) )
{
Expand All @@ -441,6 +448,8 @@ QgsCoordinateReferenceSystemModelCrsNode *QgsCoordinateReferenceSystemModel::add
QString projectionName = QgsCoordinateReferenceSystemUtils::translateProjection( record.projectionAcronym );
if ( projectionName.isEmpty() )
projectionName = tr( "Other" );
else
crsNode->setProjection( projectionName );

if ( QgsCoordinateReferenceSystemModelGroupNode *group = parentNode->getChildGroupNode( record.projectionAcronym ) )
{
Expand Down
36 changes: 36 additions & 0 deletions src/gui/proj/qgscoordinatereferencesystemmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,44 @@ class GUI_EXPORT QgsCoordinateReferenceSystemModelCrsNode : public QgsCoordinate
*/
QString proj() const { return mProj; }

/**
* Sets the CRS's group name.
*
* \see group()
* \since QGIS 3.42
*/
void setGroup( const QString &group ) { mGroup = group; }

/**
* Returns the CRS's group name.
*
* \see setGroup()
* \since QGIS 3.42
*/
QString group() const { return mGroup; }

/**
* Sets the CRS's projection name.
*
* \see projection()
* \since QGIS 3.42
*/
void setProjection( const QString &projection ) { mProjection = projection; }

/**
* Returns the CRS's projection name.
*
* \see setProjection()
* \since QGIS 3.42
*/
QString projection() const { return mProjection; }

private:
const QgsCrsDbRecord mRecord;
QString mWkt;
QString mProj;
QString mGroup;
QString mProjection;
};

#endif
Expand Down Expand Up @@ -232,6 +266,8 @@ class GUI_EXPORT QgsCoordinateReferenceSystemModel : public QAbstractItemModel
GroupId SIP_MONKEYPATCH_COMPAT_NAME( RoleGroupId ) = Qt::UserRole + 5, //!< The node ID (for group nodes)
Wkt SIP_MONKEYPATCH_COMPAT_NAME( RoleWkt ) = Qt::UserRole + 6, //!< The coordinate reference system's WKT representation. This is only used for non-standard CRS (i.e. those not present in the database).
Proj SIP_MONKEYPATCH_COMPAT_NAME( RoleProj ) = Qt::UserRole + 7, //!< The coordinate reference system's PROJ representation. This is only used for non-standard CRS (i.e. those not present in the database).
Group = Qt::UserRole + 8, //!< Group name. \since QGIS 3.42
Projection = Qt::UserRole + 9, //!< Projection name. \since QGIS 3.42
};
Q_ENUM( CustomRole )
// *INDENT-ON*
Expand Down
10 changes: 10 additions & 0 deletions tests/src/python/test_qgscoordinatereferencesystemmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,16 @@ def test_model(self):
epsg_3577_index, QgsCoordinateReferenceSystemModel.Roles.RoleProj
)
)
self.assertEqual(
model.data(epsg_3577_index, QgsCoordinateReferenceSystemModel.Roles.Group),
"Projected",
)
self.assertEqual(
model.data(
epsg_3577_index, QgsCoordinateReferenceSystemModel.Roles.Projection
),
"Albers Equal Area",
)

# check that same result is returned by authIdToIndex
self.assertEqual(model.authIdToIndex("EPSG:3577"), epsg_3577_index)
Expand Down

0 comments on commit 9e15a54

Please sign in to comment.