Skip to content

Commit

Permalink
Merge pull request #5259 from opengisch/canvas_margins
Browse files Browse the repository at this point in the history
Add a couple of properties to the elevation profile canvas to style axis labels + information cells tweaking
  • Loading branch information
nirvn authored May 21, 2024
2 parents ef39edd + 35c2273 commit eacc835
Show file tree
Hide file tree
Showing 7 changed files with 421 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
with:
build_dir: "build"
lgtm_comment_body: ''
exclude: 'cppcoreguidelines-avoid-magic-numbers,bugprone-easily-swappable-parameters,misc-non-private-member-variables-in-classes,cppcoreguidelines-macro-usage'
exclude: 'cppcoreguidelines-avoid-magic-numbers,bugprone-easily-swappable-parameters,misc-non-private-member-variables-in-classes,cppcoreguidelines-macro-usage,readability-braces-around-statements,readability-implicit-bool-conversion,cppcoreguidelines-avoid-magic-numbers'

- name: Package
run: |
Expand Down
54 changes: 54 additions & 0 deletions src/core/qgsquick/qgsquickelevationprofilecanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ QgsQuickElevationProfileCanvas::QgsQuickElevationProfileCanvas( QQuickItem *pare
connect( mDeferredRedrawTimer, &QTimer::timeout, this, &QgsQuickElevationProfileCanvas::startDeferredRedraw );

mPlotItem = new QgsElevationProfilePlotItem( this );
updateAxisLabelStyle();

setTransformOrigin( QQuickItem::TopLeft );
setFlags( QQuickItem::ItemHasContents );
Expand Down Expand Up @@ -726,6 +727,59 @@ void QgsQuickElevationProfileCanvas::setVisiblePlotRange( double minimumDistance
refineResults();
}

QColor QgsQuickElevationProfileCanvas::axisLabelColor() const
{
return mAxisLabelColor;
}

void QgsQuickElevationProfileCanvas::setAxisLabelColor( const QColor &color )
{
if ( mAxisLabelColor == color )
return;

mAxisLabelColor = color;
emit axisLabelColorChanged();

updateAxisLabelStyle();
}

double QgsQuickElevationProfileCanvas::axisLabelSize() const
{
return mAxisLabelSize;
}

void QgsQuickElevationProfileCanvas::setAxisLabelSize( double size )
{
if ( mAxisLabelSize == size )
return;

mAxisLabelSize = size;
emit axisLabelSizeChanged();

updateAxisLabelStyle();
}

void QgsQuickElevationProfileCanvas::updateAxisLabelStyle()
{
if ( mPlotItem )
{
QgsTextFormat textFormat = mPlotItem->xAxis().textFormat();
textFormat.setColor( mAxisLabelColor );
textFormat.setSize( mAxisLabelSize );
textFormat.setSizeUnit( Qgis::RenderUnit::Points );
mPlotItem->xAxis().setTextFormat( textFormat );

textFormat = mPlotItem->yAxis().textFormat();
textFormat.setColor( mAxisLabelColor );
textFormat.setSize( mAxisLabelSize );
textFormat.setSizeUnit( Qgis::RenderUnit::Points );
mPlotItem->yAxis().setTextFormat( textFormat );

mDirty = true;
refresh();
}
}

QgsDoubleRange QgsQuickElevationProfileCanvas::visibleDistanceRange() const
{
return QgsDoubleRange( mPlotItem->xMinimum(), mPlotItem->xMaximum() );
Expand Down
43 changes: 41 additions & 2 deletions src/core/qgsquick/qgsquickelevationprofilecanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ class QgsQuickElevationProfileCanvas : public QQuickItem
Q_PROPERTY( QgsProject *project READ project WRITE setProject NOTIFY projectChanged )

Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )

Q_PROPERTY( QgsGeometry profileCurve READ profileCurve WRITE setProfileCurve NOTIFY profileCurveChanged )

Q_PROPERTY( double tolerance READ tolerance WRITE setTolerance NOTIFY toleranceChanged )

Q_PROPERTY( QColor axisLabelColor READ axisLabelColor WRITE setAxisLabelColor NOTIFY axisLabelColorChanged )
Q_PROPERTY( double axisLabelSize READ axisLabelSize WRITE setAxisLabelSize NOTIFY axisLabelSizeChanged )

/**
* The isRendering property is set to true while a rendering job is pending for this
* elevation profile canvas. It can be used to show a notification icon about an
Expand Down Expand Up @@ -168,6 +169,34 @@ class QgsQuickElevationProfileCanvas : public QQuickItem
*/
QgsDoubleRange visibleElevationRange() const;

/**
* Returns the axis label color used when rendering the elevation profile.
*
* \see setAxisLabelColor
*/
QColor axisLabelColor() const;

/**
* Sets the axis label color used when rendering the elevation profile.
*
* \see axisLabelColor
*/
void setAxisLabelColor( const QColor &color );

/**
* Returns the axis label size (in point) used when rendering the elevation profile.
*
* \see setAxisLabelSize
*/
double axisLabelSize() const;

/**
* Sets the axis label size (in point) used when rendering the elevation profile.
*
* \see axisLabelSize
*/
void setAxisLabelSize( double size );

signals:

//! Emitted when the number of active background jobs changes.
Expand All @@ -188,6 +217,12 @@ class QgsQuickElevationProfileCanvas : public QQuickItem
//! \copydoc QgsQuickMapCanvasMap::isRendering
void isRenderingChanged();

//! Emitted when the axis label color changes.
void axisLabelColorChanged();

//! Emitted when the axis label size (in point) changes.
void axisLabelSizeChanged();

protected:
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
void geometryChanged( const QRectF &newGeometry, const QRectF &oldGeometry ) override;
Expand Down Expand Up @@ -227,6 +262,7 @@ class QgsQuickElevationProfileCanvas : public QQuickItem

private:
void setupLayerConnections( QgsMapLayer *layer, bool isDisconnect );
void updateAxisLabelStyle();

QgsCoordinateReferenceSystem mCrs;
QgsProject *mProject = nullptr;
Expand Down Expand Up @@ -255,6 +291,9 @@ class QgsQuickElevationProfileCanvas : public QQuickItem
static constexpr double MAX_ERROR_PIXELS = 2;

bool mDirty = false;

QColor mAxisLabelColor = QColor( 0, 0, 0 );
double mAxisLabelSize = 16;
};

#endif // QGSELEVATIONPROFILECANVAS_H
9 changes: 6 additions & 3 deletions src/qml/ElevationProfile.qml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Rectangle {
elevationProfileCanvas.clear();
}

color: "#bbfafafa"
color: Theme.mainBackgroundColorSemiOpaque
radius: 0

ElevationProfileCanvas {
Expand All @@ -37,6 +37,9 @@ Rectangle {
height: elevationProfile.height

tolerance: crs.isGeographic ? 0.00005 : 5

axisLabelColor: Theme.mainTextColor
axisLabelSize: Theme.tipFont
}

ProgressBar {
Expand Down Expand Up @@ -82,14 +85,14 @@ Rectangle {
visible: elevationProfileCanvas.isRendering || elevationProfileCanvas.profileCurve.isNull
anchors.centerIn: parent
width: parent.width
color: Theme.gray
color: Theme.mainTextColor
font: Theme.tinyFont
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WordWrap
text: elevationProfileCanvas.isRendering
? qsTr('Rendering elevation profile…')
: qsTr('Digitize a path to render the elevation profile')
style: Text.Outline
styleColor: "white"
styleColor: Theme.mainBackgroundColorSemiOpaque
}
}
102 changes: 72 additions & 30 deletions src/qml/NavigationInformationView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,28 @@ Rectangle {
width: grid.cellWidth
color: alternateBackgroundColor

Text {
RowLayout {
anchors.margins: cellPadding
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
font: Theme.tipFont
color: textColor
text: coordinatesIsXY
? (coordinatesIsGeographic ? qsTr( "Lon" ) : qsTr( "X" )) + ': '
+ Number( coordinates.x ).toLocaleString( Qt.locale(), 'f', coordinatesIsGeographic ? 7 : 3 )
: (coordinatesIsGeographic ? qsTr( "Lat" ) : qsTr( "Y" )) + ': '
+ Number( coordinates.y ).toLocaleString( Qt.locale(), 'f', coordinatesIsGeographic ? 7 : 3 )

Text {
Layout.fillWidth: false
font: Theme.tipFont
color: Theme.secondaryTextColor
text: coordinatesIsXY
? coordinatesIsGeographic ? qsTr( "Lon" ) : qsTr( "X" )
: coordinatesIsGeographic ? qsTr( "Lat" ) : qsTr( "Y" )
}

Text {
Layout.fillWidth: true
font: Theme.tipFont
color: textColor
text: coordinatesIsXY
? Number( coordinates.x ).toLocaleString( Qt.locale(), 'f', coordinatesIsGeographic ? 7 : 3 )
: Number( coordinates.y ).toLocaleString( Qt.locale(), 'f', coordinatesIsGeographic ? 7 : 3 )
}
}
}

Expand All @@ -151,17 +162,28 @@ Rectangle {
width: grid.cellWidth
color: backgroundColor

Text {
RowLayout {
anchors.margins: cellPadding
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
font: Theme.tipFont
color: textColor
text: coordinatesIsXY
? (coordinatesIsGeographic ? qsTr( "Lat" ) : qsTr( "Y" )) + ': '
+ Number( coordinates.y ).toLocaleString( Qt.locale(), 'f', coordinatesIsGeographic ? 7 : 3 )
: (coordinatesIsGeographic ? qsTr( "Lon" ) : qsTr( "X" )) + ': '
+ Number( coordinates.x ).toLocaleString( Qt.locale(), 'f', coordinatesIsGeographic ? 7 : 3 )

Text {
Layout.fillWidth: false
font: Theme.tipFont
color: Theme.secondaryTextColor
text: coordinatesIsXY
? coordinatesIsGeographic ? qsTr( "Lat" ) : qsTr( "Y" )
: coordinatesIsGeographic ? qsTr( "Lon" ) : qsTr( "X" )
}

Text {
Layout.fillWidth: true
font: Theme.tipFont
color: textColor
text: coordinatesIsXY
? Number( coordinates.y ).toLocaleString( Qt.locale(), 'f', coordinatesIsGeographic ? 7 : 3 )
: Number( coordinates.x ).toLocaleString( Qt.locale(), 'f', coordinatesIsGeographic ? 7 : 3 )
}
}
}

Expand All @@ -170,16 +192,26 @@ Rectangle {
width: grid.cellWidth
color: grid.rows == 2 ? backgroundColor : alternateBackgroundColor

Text {
RowLayout {
anchors.margins: cellPadding
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
font: Theme.tipFont
color: textColor
text: qsTr( "Dist." ) + ': ' +
( positionSource.active && positionSource.positionInformation && positionSource.positionInformation.latitudeValid
? ( UnitTypes.formatDistance( navigation.distance * UnitTypes.fromUnitToUnitFactor( navigation.distanceUnits, projectInfo.distanceUnits ), 3, projectInfo.distanceUnits ) )
: qsTr( "N/A" ) )

Text {
Layout.fillWidth: false
font: Theme.tipFont
color: Theme.secondaryTextColor
text: qsTr("Dist.")
}

Text {
Layout.fillWidth: true
font: Theme.tipFont
color: textColor
text: positionSource.active && positionSource.positionInformation && positionSource.positionInformation.latitudeValid
? UnitTypes.formatDistance( navigation.distance * UnitTypes.fromUnitToUnitFactor( navigation.distanceUnits, projectInfo.distanceUnits ), 3, projectInfo.distanceUnits )
: qsTr( "N/A" )
}
}
}

Expand All @@ -188,16 +220,26 @@ Rectangle {
width: grid.cellWidth
color: grid.rows == 2 ? alternateBackgroundColor : backgroundColor

Text {
RowLayout {
anchors.margins: cellPadding
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
font: Theme.tipFont
color: textColor
text: qsTr( "Bearing" ) + ': ' +
( positionSource.active && positionSource.positionInformation && positionSource.positionInformation.latitudeValid
? ( Number( navigation.bearing ).toLocaleString( Qt.locale(), 'f', 1 ) ) + '°'
: qsTr( "N/A" ) )

Text {
Layout.fillWidth: false
font: Theme.tipFont
color: Theme.secondaryTextColor
text: qsTr("Bearing")
}

Text {
Layout.fillWidth: true
font: Theme.tipFont
color: textColor
text: positionSource.active && positionSource.positionInformation && positionSource.positionInformation.latitudeValid
? Number( navigation.bearing ).toLocaleString( Qt.locale(), 'f', 1 ) + '°'
: qsTr( "N/A" )
}
}
}
}
Expand Down
Loading

0 comments on commit eacc835

Please sign in to comment.