Skip to content

Commit

Permalink
Refactor scale bar rendering
Browse files Browse the repository at this point in the history
Move all scalebar rendering code out of composer and ensure that
all scalebar rendering is done independant of QgsComposerScaleBar

This allows scalebar rendering code to be reused by plugins
and by non-composer code.

Also rename QgsScaleBarStyle -> QgsScaleBarRenderer, (and all
subclasses too). This name better reflects what these classes do.
  • Loading branch information
nyalldawson committed Apr 26, 2017
1 parent 13b4472 commit b40bc0c
Show file tree
Hide file tree
Showing 43 changed files with 2,189 additions and 1,226 deletions.
1 change: 1 addition & 0 deletions doc/CMakeLists.txt 100644 → 100755
Expand Up @@ -66,6 +66,7 @@ IF(WITH_APIDOC)
${CMAKE_SOURCE_DIR}/src/core/pal
${CMAKE_SOURCE_DIR}/src/core/processing
${CMAKE_SOURCE_DIR}/src/core/raster
${CMAKE_SOURCE_DIR}/src/core/scalebar
${CMAKE_SOURCE_DIR}/src/core/symbology-ng
${CMAKE_SOURCE_DIR}/src/gui
${CMAKE_SOURCE_DIR}/src/gui/auth
Expand Down
13 changes: 13 additions & 0 deletions doc/api_break.dox
Expand Up @@ -85,6 +85,7 @@ Renamed Classes {#qgis_api_break_3_0_renamed_classes}
<tr><td>QgsCurveV2<td>QgsCurve
<tr><td>QgsDbFilterProxyModel<td>QgsDatabaseFilterProxyModel
<tr><td>QgsDiagramRendererV2<td>QgsDiagramRenderer
<tr><td>QgsDoubleBoxBarStyle<td>QgsDoubleBoxScaleBarRenderer
<tr><td>QgsEditorWidgetV2<td>QgsEditorWidget
<tr><td>QgsEllipseSymbolLayerV2<td>QgsEllipseSymbolLayer
<tr><td>QgsEllipseSymbolLayerV2Widget<td>QgsEllipseSymbolLayerWidget
Expand Down Expand Up @@ -115,6 +116,7 @@ Renamed Classes {#qgis_api_break_3_0_renamed_classes}
<tr><td>QgsMultiCurveV2<td>QgsMultiCurve
<tr><td>QgsMultiLineStringV2<td>QgsMultiLineString
<tr><td>QgsMultiSurfaceV2<td>QgsMultiSurface
<tr><td>QgsNumericScaleBarStyle<td>QgsNumericScaleBarRenderer
<tr><td>QgsPointSequenceV2<td>QgsPointSequence
<tr><td>QgsProperty<td>QgsProjectProperty
<tr><td>QgsPropertyKey<td>QgsProjectPropertyKey
Expand All @@ -140,6 +142,7 @@ Renamed Classes {#qgis_api_break_3_0_renamed_classes}
<tr><td>QgsRuleBasedRendererV2Count<td>QgsRuleBasedRendererCount
<tr><td>QgsRuleBasedRendererV2Model<td>QgsRuleBasedRendererModel
<tr><td>QgsRuleBasedRendererV2Widget<td>QgsRuleBasedRendererWidget
<tr><td>QgsScaleBarStyle<td>QgsScaleBarRenderer
<tr><td>QgsShapeburstFillSymbolLayerV2<td>QgsShapeburstFillSymbolLayer
<tr><td>QgsShapeburstFillSymbolLayerV2Widget<td>QgsShapeburstFillSymbolLayerWidget
<tr><td>QgsSimpleFillSymbolLayerV2<td>QgsSimpleFillSymbolLayer
Expand All @@ -148,6 +151,7 @@ Renamed Classes {#qgis_api_break_3_0_renamed_classes}
<tr><td>QgsSimpleLineSymbolLayerV2Widget<td>QgsSimpleLineSymbolLayerWidget
<tr><td>QgsSimpleMarkerSymbolLayerV2<td>QgsSimpleMarkerSymbolLayer
<tr><td>QgsSimpleMarkerSymbolLayerV2Widget<td>QgsSimpleMarkerSymbolLayerWidget
<tr><td>QgsSingleBoxScaleBarStyle<td>QgsSingleBoxScaleBarRenderer
<tr><td>QgsSingleSymbolRendererV2<td>QgsSingleSymbolRenderer
<tr><td>QgsSingleSymbolRendererV2Widget<td>QgsSingleSymbolRendererWidget
<tr><td>QgsStyleV2<td>QgsStyle
Expand All @@ -171,6 +175,7 @@ Renamed Classes {#qgis_api_break_3_0_renamed_classes}
<tr><td>QgsSymbolV2RenderContext<td>QgsSymbolRenderContext
<tr><td>QgsSymbolV2SelectorDialog<td>QgsSymbolSelectorDialog
<tr><td>QgsSymbolV2SelectorWidget<td>QgsSymbolSelectorWidget
<tr><td>QgsTicksScaleBarStyle<td>QgsTicksScaleBarRenderer
<tr><td>QgsVectorColorBrewerColorRampV2<td>QgsColorBrewerColorRamp
<tr><td>QgsVectorColorBrewerColorRampV2Dialog<td>QgsColorBrewerColorRampDialog
<tr><td>QgsVectorColorBrewerColorRampV2DialogBase<td>QgsColorBrewerColorRampDialogBase
Expand Down Expand Up @@ -684,9 +689,12 @@ QgsComposerObject::setDataDefinedProperty() instead.
QgsComposerScaleBar {#qgis_api_break_3_0_QgsComposerScaleBar}
-------------------

- The Alignment and SegmentSizeMode enums were moved to QgsScaleBarSettings
- The ScaleBarUnits enum was removed. Use QgsUnitTypes::DistanceUnit instead.
- setBrush() was removed. Use setFillColor() instead.
- setBrush2() was removed. Use setFillColor2() instead.
- setPen() was removed. Use setLineColor() and setLineWidth() instead.
- segmentMillimeters() and firstLabelString() were removed.


QgsComposerTable {#qgis_api_break_3_0_QgsComposerTable}
Expand Down Expand Up @@ -1837,6 +1845,11 @@ QgsRuntimeProfiler {#qgis_api_break_3_0_QgsRuntimeProfiler}

- This class is no longer a singleton and instance() has been removed. Instead use QgsApplication::profiler() to access an application-wide profiler.

QgsScaleBarStyle {#qgis_api_break_3_0_QgsScaleBarStyle}
----------------

- The interface for QgsScaleBarStyle has been completely rewritten - any code using QgsScaleBarStyle or subclasses will need to update
to the new draw() and calculateBoxSize() methods.

QgsServer {#qgis_api_break_3_0_QgsServer}
----------
Expand Down
1 change: 1 addition & 0 deletions python/CMakeLists.txt 100644 → 100755
Expand Up @@ -107,6 +107,7 @@ INCLUDE_DIRECTORIES(
../src/core/layertree
../src/core/processing
../src/core/raster
../src/core/scalebar
../src/core/symbology-ng

../src/gui/raster
Expand Down
59 changes: 9 additions & 50 deletions python/core/composer/qgscomposerscalebar.sip
Expand Up @@ -10,29 +10,6 @@ class QgsComposerScaleBar: QgsComposerItem

public:

enum Alignment
{
Left,
Middle,
Right
};

enum ScaleBarUnits
{
MapUnits,
Meters,
Feet,
NauticalMiles
};

/** Modes for setting size for scale bar segments
*/
enum SegmentSizeMode
{
SegmentSizeFixed, /*!< Scale bar segment size is fixed to a map unit*/
SegmentSizeFitWidth /*!< Scale bar segment size is calculated to fit a size range*/
};

QgsComposerScaleBar( QgsComposition* composition /TransferThis/ );
~QgsComposerScaleBar();

Expand All @@ -58,7 +35,7 @@ class QgsComposerScaleBar: QgsComposerItem
* @see maxBarWidth
* @note added in QGIS 2.9
*/
SegmentSizeMode segmentSizeMode() const;
QgsScaleBarSettings::SegmentSizeMode segmentSizeMode() const;

/** Sets the size mode for scale bar segments.
* @param mode size mode
Expand All @@ -67,7 +44,7 @@ class QgsComposerScaleBar: QgsComposerItem
* @see setMaxBarWidth
* @note added in QGIS 2.9
*/
void setSegmentSizeMode( SegmentSizeMode mode );
void setSegmentSizeMode( QgsScaleBarSettings::SegmentSizeMode mode );

/** Returns the minimum size (in millimeters) for scale bar segments. This
* property is only effective if the @link segmentSizeMode @endlink is set
Expand Down Expand Up @@ -212,25 +189,23 @@ class QgsComposerScaleBar: QgsComposerItem
double height() const;
void setHeight( double h );

void setComposerMap( const QgsComposerMap* map );
const QgsComposerMap* composerMap();
void setComposerMap( QgsComposerMap* map );
QgsComposerMap* composerMap();

double labelBarSpace() const;
void setLabelBarSpace( double space );

double boxContentSpace() const;
void setBoxContentSpace( double space );

double segmentMillimeters() const;

/** Left / Middle/ Right */
Alignment alignment() const;
QgsScaleBarSettings::Alignment alignment() const;

void setAlignment( Alignment a );
void setAlignment( QgsScaleBarSettings::Alignment a );

ScaleBarUnits units() const;
QgsUnitTypes::DistanceUnit units() const;

void setUnits( ScaleBarUnits u );
void setUnits( QgsUnitTypes::DistanceUnit u );

/** Returns the join style used for drawing lines in the scalebar
* @returns Join style for lines
Expand Down Expand Up @@ -263,7 +238,7 @@ class QgsComposerScaleBar: QgsComposerItem
/** Apply default settings*/
void applyDefaultSettings();
/** Apply default size (scale bar 1/5 of map item width) */
void applyDefaultSize( ScaleBarUnits u = Meters );
void applyDefaultSize( QgsUnitTypes::DistanceUnit u = QgsUnitTypes::DistanceMeters );

/** Sets style by name
@param styleName (untranslated) style name. Possibilities are: 'Single Box', 'Double Box', 'Line Ticks Middle', 'Line Ticks Down', 'Line Ticks Up', 'Numeric'*/
Expand All @@ -272,21 +247,12 @@ class QgsComposerScaleBar: QgsComposerItem
/** Returns style name*/
QString style() const;

/** Returns the x - positions of the segment borders (in item coordinates) and the width
* of the segment
* @note not available in Python bindings
*/
// void segmentPositions( QList<QPair<double, double> >& posWidthList ) const;

/** Sets box size suitable to content*/
void adjustBoxSize();

/** Adjusts box size and calls QgsComposerItem::update()*/
void update();

/** Returns string of first label (important for drawing, labeling, size calculation*/
QString firstLabelString() const;

/** Stores state in Dom element
* @param elem is Dom element corresponding to 'Composer' tag
* @param doc Dom document
Expand All @@ -311,11 +277,4 @@ class QgsComposerScaleBar: QgsComposerItem
void invalidateCurrentMap();
virtual void refreshDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property = QgsComposerObject::AllProperties, const QgsExpressionContext* context = nullptr );

protected:
/** Calculates with of a segment in mm and stores it in mSegmentMillimeters*/
void refreshSegmentMillimeters();

/** Returns diagonal of composer map in selected units (map units / meters / feet / nautical miles)*/
double mapWidth() const;

};
13 changes: 0 additions & 13 deletions python/core/composer/qgsdoubleboxscalebarstyle.sip

This file was deleted.

16 changes: 0 additions & 16 deletions python/core/composer/qgsnumericscalebarstyle.sip

This file was deleted.

21 changes: 0 additions & 21 deletions python/core/composer/qgsscalebarstyle.sip

This file was deleted.

17 changes: 0 additions & 17 deletions python/core/composer/qgssingleboxscalebarstyle.sip

This file was deleted.

26 changes: 0 additions & 26 deletions python/core/composer/qgsticksscalebarstyle.sip

This file was deleted.

13 changes: 8 additions & 5 deletions python/core/core.sip
Expand Up @@ -230,13 +230,9 @@
%Include composer/qgscomposertexttable.sip
%Include composer/qgscomposerutils.sip
%Include composer/qgscomposition.sip
%Include composer/qgsdoubleboxscalebarstyle.sip
%Include composer/qgslayoutmanager.sip
%Include composer/qgsnumericscalebarstyle.sip
%Include composer/qgspaperitem.sip
%Include composer/qgsscalebarstyle.sip
%Include composer/qgssingleboxscalebarstyle.sip
%Include composer/qgsticksscalebarstyle.sip


%Include diagram/qgsdiagram.sip
%Include diagram/qgshistogramdiagram.sip
Expand Down Expand Up @@ -327,6 +323,13 @@
%Include raster/qgssinglebandpseudocolorrenderer.sip
%Include raster/qgshillshaderenderer.sip

%Include scalebar/qgsdoubleboxscalebarrenderer.sip
%Include scalebar/qgsnumericscalebarrenderer.sip
%Include scalebar/qgsscalebarrenderer.sip
%Include scalebar/qgsscalebarsettings.sip
%Include scalebar/qgssingleboxscalebarrenderer.sip
%Include scalebar/qgsticksscalebarrenderer.sip

%Include symbology-ng/qgscolorbrewerpalette.sip
%Include symbology-ng/qgscptcityarchive.sip
%Include symbology-ng/qgsstyle.sip
Expand Down
39 changes: 39 additions & 0 deletions python/core/scalebar/qgsdoubleboxscalebarrenderer.sip
@@ -0,0 +1,39 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/scalebar/qgsdoubleboxscalebarrenderer.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsDoubleBoxScaleBarRenderer: QgsScaleBarRenderer
{
%Docstring
Double box with alternating colors.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsdoubleboxscalebarrenderer.h"
%End
public:
QgsDoubleBoxScaleBarRenderer();

virtual QString name() const;

virtual void draw( QgsRenderContext &context,
const QgsScaleBarSettings &settings,
const QgsScaleBarRenderer::ScaleBarContext &scaleContext ) const;

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/scalebar/qgsdoubleboxscalebarrenderer.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

0 comments on commit b40bc0c

Please sign in to comment.