Skip to content

Commit

Permalink
Add remaining properties needed to unlock beautiful dark theme suppor…
Browse files Browse the repository at this point in the history
…t to the elevation profile canvas
  • Loading branch information
nirvn committed May 22, 2024
1 parent 5c715e9 commit a7869e6
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 6 deletions.
55 changes: 51 additions & 4 deletions src/core/qgsquick/qgsquickelevationprofilecanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@

#include "qgsabstractprofilegenerator.h"
#include "qgsabstractprofilesource.h"
#include "qgscolorutils.h"
#include "qgsexpressioncontextutils.h"
#include "qgsfillsymbol.h"
#include "qgsfillsymbollayer.h"
#include "qgslinesymbol.h"
#include "qgslinesymbollayer.h"
#include "qgsmaplayerelevationproperties.h"
#include "qgsmaplayerutils.h"
#include "qgsplot.h"
Expand Down Expand Up @@ -171,7 +176,7 @@ QgsQuickElevationProfileCanvas::QgsQuickElevationProfileCanvas( QQuickItem *pare
connect( mDeferredRedrawTimer, &QTimer::timeout, this, &QgsQuickElevationProfileCanvas::startDeferredRedraw );

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

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

QColor QgsQuickElevationProfileCanvas::backgroundColor() const
{
return mBackgroundColor;
}

void QgsQuickElevationProfileCanvas::setBackgroundColor( const QColor &color )
{
if ( mBackgroundColor == color )
return;

mBackgroundColor = color;
emit backgroundColorChanged();

updateStyle();
}

QColor QgsQuickElevationProfileCanvas::borderColor() const
{
return mBorderColor;
}

void QgsQuickElevationProfileCanvas::setBorderColor( const QColor &color )
{
if ( mBorderColor == color )
return;

mBorderColor = color;
emit borderColorChanged();

updateStyle();
}

QColor QgsQuickElevationProfileCanvas::axisLabelColor() const
{
return mAxisLabelColor;
Expand All @@ -740,7 +777,7 @@ void QgsQuickElevationProfileCanvas::setAxisLabelColor( const QColor &color )
mAxisLabelColor = color;
emit axisLabelColorChanged();

updateAxisLabelStyle();
updateStyle();
}

double QgsQuickElevationProfileCanvas::axisLabelSize() const
Expand All @@ -756,10 +793,10 @@ void QgsQuickElevationProfileCanvas::setAxisLabelSize( double size )
mAxisLabelSize = size;
emit axisLabelSizeChanged();

updateAxisLabelStyle();
updateStyle();
}

void QgsQuickElevationProfileCanvas::updateAxisLabelStyle()
void QgsQuickElevationProfileCanvas::updateStyle()
{
if ( mPlotItem )
{
Expand All @@ -775,6 +812,16 @@ void QgsQuickElevationProfileCanvas::updateAxisLabelStyle()
textFormat.setSizeUnit( Qgis::RenderUnit::Points );
mPlotItem->yAxis().setTextFormat( textFormat );

std::unique_ptr<QgsSimpleLineSymbolLayer> lineSymbolLayer = std::make_unique<QgsSimpleLineSymbolLayer>( mBorderColor, 0.1 );
lineSymbolLayer->setPenCapStyle( Qt::FlatCap );
mPlotItem->xAxis().setGridMinorSymbol( new QgsLineSymbol( QgsSymbolLayerList( { lineSymbolLayer->clone() } ) ) );
mPlotItem->yAxis().setGridMinorSymbol( new QgsLineSymbol( QgsSymbolLayerList( { lineSymbolLayer->clone() } ) ) );
mPlotItem->xAxis().setGridMajorSymbol( new QgsLineSymbol( QgsSymbolLayerList( { lineSymbolLayer->clone() } ) ) );
mPlotItem->yAxis().setGridMajorSymbol( new QgsLineSymbol( QgsSymbolLayerList( { lineSymbolLayer->clone() } ) ) );
mPlotItem->setChartBorderSymbol( new QgsFillSymbol( QgsSymbolLayerList( { lineSymbolLayer.release() } ) ) );
std::unique_ptr<QgsSimpleFillSymbolLayer> fillSymbolLayer = std::make_unique<QgsSimpleFillSymbolLayer>( mBackgroundColor, Qt::SolidPattern, mBackgroundColor );
mPlotItem->setChartBackgroundSymbol( new QgsFillSymbol( QgsSymbolLayerList( { fillSymbolLayer.release() } ) ) );

mDirty = true;
refresh();
}
Expand Down
40 changes: 39 additions & 1 deletion src/core/qgsquick/qgsquickelevationprofilecanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class QgsQuickElevationProfileCanvas : public QQuickItem
Q_PROPERTY( QgsGeometry profileCurve READ profileCurve WRITE setProfileCurve NOTIFY profileCurveChanged )
Q_PROPERTY( double tolerance READ tolerance WRITE setTolerance NOTIFY toleranceChanged )

Q_PROPERTY( QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged )
Q_PROPERTY( QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged )
Q_PROPERTY( QColor axisLabelColor READ axisLabelColor WRITE setAxisLabelColor NOTIFY axisLabelColorChanged )
Q_PROPERTY( double axisLabelSize READ axisLabelSize WRITE setAxisLabelSize NOTIFY axisLabelSizeChanged )

Expand Down Expand Up @@ -169,6 +171,34 @@ class QgsQuickElevationProfileCanvas : public QQuickItem
*/
QgsDoubleRange visibleElevationRange() const;

/**
* Returns the background color used when rendering the elevation profile.
*
* \see setBackgroundColor
*/
QColor backgroundColor() const;

/**
* Sets the background color used when rendering the elevation profile.
*
* \see backgroundColor
*/
void setBackgroundColor( const QColor &color );

/**
* Returns the border color used when rendering the elevation profile.
*
* \see setBorderColor
*/
QColor borderColor() const;

/**
* Sets the border color used when rendering the elevation profile.
*
* \see borderColor
*/
void setBorderColor( const QColor &color );

/**
* Returns the axis label color used when rendering the elevation profile.
*
Expand Down Expand Up @@ -217,6 +247,12 @@ class QgsQuickElevationProfileCanvas : public QQuickItem
//! \copydoc QgsQuickMapCanvasMap::isRendering
void isRenderingChanged();

//! Emitted when the background color changes.
void backgroundColorChanged();

//! Emitted when the border color changes.
void borderColorChanged();

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

Expand Down Expand Up @@ -262,7 +298,7 @@ class QgsQuickElevationProfileCanvas : public QQuickItem

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

QgsCoordinateReferenceSystem mCrs;
QgsProject *mProject = nullptr;
Expand Down Expand Up @@ -292,6 +328,8 @@ class QgsQuickElevationProfileCanvas : public QQuickItem

bool mDirty = false;

QColor mBackgroundColor = QColor( 255, 255, 255 );
QColor mBorderColor = QColor( 0, 0, 0 );
QColor mAxisLabelColor = QColor( 0, 0, 0 );
double mAxisLabelSize = 16;
};
Expand Down
4 changes: 3 additions & 1 deletion src/qml/ElevationProfile.qml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ Rectangle {

tolerance: crs.isGeographic ? 0.00005 : 5

axisLabelColor: Theme.mainTextColor
backgroundColor: Theme.mainBackgroundColorSemiOpaque
borderColor: Theme.controlBackgroundAlternateColor
axisLabelColor: Theme.secondaryTextColor
axisLabelSize: Theme.tipFont
}

Expand Down

0 comments on commit a7869e6

Please sign in to comment.