Skip to content
Permalink
Browse files
Refactor scale bar rendering
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 b40bc0c1f7dd92c011e9e47a7dfcd5b564a9e54a
Showing with 2,189 additions and 1,226 deletions.
  1. +1 −0 doc/CMakeLists.txt
  2. +13 −0 doc/api_break.dox
  3. +1 −0 python/CMakeLists.txt
  4. +9 −50 python/core/composer/qgscomposerscalebar.sip
  5. +0 −13 python/core/composer/qgsdoubleboxscalebarstyle.sip
  6. +0 −16 python/core/composer/qgsnumericscalebarstyle.sip
  7. +0 −21 python/core/composer/qgsscalebarstyle.sip
  8. +0 −17 python/core/composer/qgssingleboxscalebarstyle.sip
  9. +0 −26 python/core/composer/qgsticksscalebarstyle.sip
  10. +8 −5 python/core/core.sip
  11. +39 −0 python/core/scalebar/qgsdoubleboxscalebarrenderer.sip
  12. +42 −0 python/core/scalebar/qgsnumericscalebarrenderer.sip
  13. +114 −0 python/core/scalebar/qgsscalebarrenderer.sip
  14. +399 −0 python/core/scalebar/qgsscalebarsettings.sip
  15. +41 −0 python/core/scalebar/qgssingleboxscalebarrenderer.sip
  16. +61 −0 python/core/scalebar/qgsticksscalebarrenderer.sip
  17. +1 −0 src/app/CMakeLists.txt
  18. +13 −13 src/app/composer/qgscomposerscalebarwidget.cpp
  19. +14 −10 src/core/CMakeLists.txt
  20. +199 −236 src/core/composer/qgscomposerscalebar.cpp
  21. +48 −123 src/core/composer/qgscomposerscalebar.h
  22. +0 −93 src/core/composer/qgsdoubleboxscalebarstyle.cpp
  23. +0 −123 src/core/composer/qgsnumericscalebarstyle.cpp
  24. +0 −132 src/core/composer/qgsscalebarstyle.cpp
  25. +0 −58 src/core/composer/qgsscalebarstyle.h
  26. +0 −83 src/core/composer/qgssingleboxscalebarstyle.cpp
  27. +0 −99 src/core/composer/qgsticksscalebarstyle.cpp
  28. +0 −54 src/core/composer/qgsticksscalebarstyle.h
  29. +81 −0 src/core/scalebar/qgsdoubleboxscalebarrenderer.cpp
  30. +19 −15 src/core/{composer/qgsdoubleboxscalebarstyle.h → scalebar/qgsdoubleboxscalebarrenderer.h}
  31. +75 −0 src/core/scalebar/qgsnumericscalebarrenderer.cpp
  32. +23 −19 src/core/{composer/qgsnumericscalebarstyle.h → scalebar/qgsnumericscalebarrenderer.h}
  33. +172 −0 src/core/scalebar/qgsscalebarrenderer.cpp
  34. +113 −0 src/core/scalebar/qgsscalebarrenderer.h
  35. +456 −0 src/core/scalebar/qgsscalebarsettings.h
  36. +67 −0 src/core/scalebar/qgssingleboxscalebarrenderer.cpp
  37. +18 −18 src/core/{composer/qgssingleboxscalebarstyle.h → scalebar/qgssingleboxscalebarrenderer.h}
  38. +92 −0 src/core/scalebar/qgsticksscalebarrenderer.cpp
  39. +66 −0 src/core/scalebar/qgsticksscalebarrenderer.h
  40. +1 −0 src/gui/CMakeLists.txt
  41. +1 −1 src/gui/qgscomposerview.cpp
  42. +1 −0 tests/src/core/CMakeLists.txt
  43. +1 −1 tests/src/core/testqgscomposerscalebar.cpp
1 doc/CMakeLists.txt 100644 → 100755
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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}
@@ -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}
----------
1 python/CMakeLists.txt 100644 → 100755
@@ -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
@@ -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();

@@ -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
@@ -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
@@ -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
@@ -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'*/
@@ -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
@@ -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;

};

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -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
@@ -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
@@ -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 *
************************************************************************/

Loading

0 comments on commit b40bc0c

Please sign in to comment.