Skip to content
Permalink
Browse files

More consistency across scale API

Use a real scale widget for point displacement label scale
  • Loading branch information
nyalldawson committed Jun 9, 2017
1 parent a3d919d commit 1be5fbda966282a6472a76deb54c3ec81be1bd52
Showing with 296 additions and 224 deletions.
  1. +6 −0 doc/api_break.dox
  2. +13 −9 python/core/dxf/qgsdxfexport.sip
  3. +11 −1 python/core/layertree/qgslayertreemodel.sip
  4. +13 −2 python/core/qgsvectorfilewriter.sip
  5. +10 −9 python/core/symbology-ng/qgspointdistancerenderer.sip
  6. +3 −3 src/app/main.cpp
  7. +1 −1 src/app/qgisapp.cpp
  8. +17 −17 src/core/dxf/qgsdxfexport.cpp
  9. +16 −10 src/core/dxf/qgsdxfexport.h
  10. +2 −2 src/core/layertree/qgslayertreemodel.cpp
  11. +16 −4 src/core/layertree/qgslayertreemodel.h
  12. +17 −17 src/core/qgsvectorfilewriter.cpp
  13. +18 −5 src/core/qgsvectorfilewriter.h
  14. +2 −2 src/core/symbology-ng/qgscategorizedsymbolrenderer.cpp
  15. +1 −1 src/core/symbology-ng/qgscategorizedsymbolrenderer.h
  16. +2 −2 src/core/symbology-ng/qgsfillsymbollayer.cpp
  17. +2 −2 src/core/symbology-ng/qgsgraduatedsymbolrenderer.cpp
  18. +1 −1 src/core/symbology-ng/qgsgraduatedsymbolrenderer.h
  19. +2 −2 src/core/symbology-ng/qgsinvertedpolygonrenderer.cpp
  20. +1 −1 src/core/symbology-ng/qgsinvertedpolygonrenderer.h
  21. +2 −2 src/core/symbology-ng/qgslinesymbollayer.cpp
  22. +1 −1 src/core/symbology-ng/qgspointclusterrenderer.cpp
  23. +3 −3 src/core/symbology-ng/qgspointdisplacementrenderer.cpp
  24. +5 −6 src/core/symbology-ng/qgspointdistancerenderer.cpp
  25. +15 −12 src/core/symbology-ng/qgspointdistancerenderer.h
  26. +2 −2 src/core/symbology-ng/qgsrenderer.cpp
  27. +6 −3 src/core/symbology-ng/qgsrenderer.h
  28. +5 −5 src/core/symbology-ng/qgsrulebasedrenderer.cpp
  29. +2 −2 src/core/symbology-ng/qgsrulebasedrenderer.h
  30. +2 −2 src/core/symbology-ng/qgssinglesymbolrenderer.cpp
  31. +1 −1 src/core/symbology-ng/qgssinglesymbolrenderer.h
  32. +1 −1 src/core/symbology-ng/qgssymbollayer.cpp
  33. +12 −16 src/gui/symbology-ng/qgspointdisplacementrendererwidget.cpp
  34. +1 −1 src/gui/symbology-ng/qgspointdisplacementrendererwidget.h
  35. +1 −1 src/server/services/wms/qgsdxfwriter.cpp
  36. +83 −75 src/ui/qgspointdisplacementrendererwidgetbase.ui
@@ -1067,6 +1067,8 @@ QgsDxfExport {#qgis_api_break_3_0_QgsDxfExport}
- The signature for writeLine() has changed.
- writePoint(), writeFilledCircle(), writeCircle(), writeText() and writeMText() now take QgsPointV2 arguments
- setMapUnits() was removed. The map units are dictated by the units for the destination CRS.
- setSymbologyScaleDenominator() and symbologyScaleDenominator() were renamed to setSymbologyScale() and symbologyScale()
for consistency with other parts of the QGIS API.


QgsEditFormConfig {#qgis_api_break_3_0_QgsEditFormConfig}
@@ -1781,6 +1783,8 @@ QgsPointDisplacementRenderer {#qgis_api_break_3_0_QgsPointDisplacementRen
----------------------------

- The deprecated method setDisplacementGroups() has been removed. This method has had no effect since QGIS 2.4
- setMaxLabelScaleDenominator() and maxLabelScaleDenominator() were renamed to setMinimumLabelScale() and
minimumLabelScale() for consistency with other areas in the QGIS API.


QgsPointLocator {#qgis_api_break_3_0_QgsPointLocator}
@@ -2442,6 +2446,8 @@ QgsCoordinateReferenceSystem is now implicitly shared, using references to QgsCo
pointers makes for more robust, safer code. Use an invalid (default constructed) QgsCoordinateReferenceSystem
in code which previously passed a null pointer to QgsVectorFileWriter.
- writeAsVectorFormat() now takes a QgsCoordinateTransform reference, not a pointer. An invalid QgsCoordinateTransform should be used instead of a null pointer if no transformation is required.
- setSymbologyScaleDenominator() and symbologyScaleDenominator() were renamed to setSymbologyScale() and symbologyScale()
for consistency with other parts of the QGIS API.


QgsWMSLegendNode {#qgis_api_break_3_0_QgsWMSLegendNode}
@@ -43,17 +43,20 @@ class QgsDxfExport

int writeToFile( QIODevice *d, const QString &codec ); //maybe add progress dialog? other parameters (e.g. scale, dpi)?

void setSymbologyScaleDenominator( double d );
void setSymbologyScale( double scale );
%Docstring
Set reference scale for output
\param d scale denominator
Set reference ``scale`` for output.
The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
.. versionadded:: 3.0
.. seealso:: symbologyScale()
%End

double symbologyScaleDenominator() const;
double symbologyScale() const;
%Docstring
Retrieve reference scale for output
:return: reference scale
.. seealso:: setSymbologyScaleDenominator
Returns the reference scale for output.
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
.. versionadded:: 3.0
.. seealso:: setSymbologyScale()
:rtype: float
%End

@@ -263,9 +266,10 @@ class QgsDxfExport
.. versionadded:: 2.15
%End

static double mapUnitScaleFactor( double scaleDenominator, QgsUnitTypes::RenderUnit symbolUnits, QgsUnitTypes::DistanceUnit mapUnits );
static double mapUnitScaleFactor( double scale, QgsUnitTypes::RenderUnit symbolUnits, QgsUnitTypes::DistanceUnit mapUnits );
%Docstring
Calculates a scaling factor to convert from map units to a specified symbol unit.
Calculates a scaling factor to convert from map units to a specified symbol unit.
The ``scale`` parameter indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
:rtype: float
%End

@@ -211,12 +211,22 @@ Return at what number of legend nodes the layer node should be collapsed. -1 mea
:rtype: int
%End

void setLegendFilterByScale( double scaleDenominator );
void setLegendFilterByScale( double scale );
%Docstring
Force only display of legend nodes which are valid for a given ``scale``.
The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
Setting ``scale`` <= 0 will disable the functionality.
.. versionadded:: 2.6
.. seealso:: legendFilterByScale()
%End

double legendFilterByScale() const;
%Docstring
Returns the scale which restricts the legend nodes which are visible.
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
A scale <= 0 indicates that no scale filtering is being performed.
.. versionadded:: 2.6
.. seealso:: setLegendFilterByScale()
:rtype: float
%End

@@ -544,11 +544,22 @@ Close opened shapefile for writing
%End
void setSymbologyExport( QgsVectorFileWriter::SymbologyExport symExport );

double symbologyScaleDenominator() const;
double symbologyScale() const;
%Docstring
Returns the reference scale for output.
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
.. versionadded:: 3.0
.. seealso:: setSymbologyScale()
:rtype: float
%End
void setSymbologyScaleDenominator( double d );

void setSymbologyScale( double scale );
%Docstring
Set reference ``scale`` for output.
The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
.. versionadded:: 3.0
.. seealso:: symbologyScale()
%End

static bool driverMetadata( const QString &driverName, MetaData &driverMetadata );
%Docstring
@@ -106,7 +106,7 @@ Optional label text
.. seealso:: labelAttributeName()
.. seealso:: setLabelFont()
.. seealso:: setLabelColor()
.. seealso:: setMaxLabelScaleDenominator()
.. seealso:: setMinimumLabelScale()
%End

QString labelAttributeName() const;
@@ -115,7 +115,7 @@ Optional label text
will be done by the renderer.
.. seealso:: setLabelAttributeName()
.. seealso:: labelFont()
.. seealso:: maxLabelScaleDenominator()
.. seealso:: minimumLabelScale()
.. seealso:: labelColor()
:rtype: str
%End
@@ -138,18 +138,19 @@ Optional label text
:rtype: QFont
%End

void setMaxLabelScaleDenominator( double denominator );
void setMinimumLabelScale( double scale );
%Docstring
Sets the maximum scale at which points should be labeled by the renderer.
\param denominator maximum scale denominator
.. seealso:: maxLabelScaleDenominator()
Sets the minimum map ``scale`` (i.e. most "zoomed out") at which points should be labeled by the renderer.
The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
.. seealso:: minimumLabelScale()
.. seealso:: setLabelAttributeName()
%End

double maxLabelScaleDenominator() const;
double minimumLabelScale() const;
%Docstring
Returns the denominator for the maximum scale at which points should be labeled by the renderer.
.. seealso:: setMaxLabelScaleDenominator()
Returns the minimum map scale (i.e. most "zoomed out") at which points should be labeled by the renderer.
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
.. seealso:: setMinimumLabelScale()
.. seealso:: labelAttributeName()
:rtype: float
%End
@@ -511,7 +511,7 @@ int main( int argc, char *argv[] )

QString dxfOutputFile;
QgsDxfExport::SymbologyExport dxfSymbologyMode = QgsDxfExport::SymbolLayerSymbology;
double dxfScaleDenom = 50000.0;
double dxfScale = 50000.0;
QString dxfEncoding = QStringLiteral( "CP1252" );
QString dxfPreset;
QgsRectangle dxfExtent;
@@ -702,7 +702,7 @@ int main( int argc, char *argv[] )
{
bool ok;
QString scale( args[++i] );
dxfScaleDenom = scale.toDouble( &ok );
dxfScale = scale.toDouble( &ok );
if ( !ok )
{
std::cerr << "invalid dxf scale " << scale.toStdString() << std::endl;
@@ -1236,7 +1236,7 @@ int main( int argc, char *argv[] )
qgis->hide();

QgsDxfExport dxfExport;
dxfExport.setSymbologyScaleDenominator( dxfScaleDenom );
dxfExport.setSymbologyScale( dxfScale );
dxfExport.setSymbologyExport( dxfSymbologyMode );
dxfExport.setExtent( dxfExtent );

@@ -5406,7 +5406,7 @@ void QgisApp::dxfExport()
settings.setLayerStyleOverrides( QgsProject::instance()->mapThemeCollection()->mapThemeStyleOverrides( d.mapTheme() ) );
dxfExport.setMapSettings( settings );
dxfExport.addLayers( d.layers() );
dxfExport.setSymbologyScaleDenominator( d.symbologyScale() );
dxfExport.setSymbologyScale( d.symbologyScale() );
dxfExport.setSymbologyExport( d.symbologyMode() );
dxfExport.setLayerTitleAsName( d.layerTitleAsName() );
dxfExport.setDestinationCrs( d.crs() );
@@ -367,7 +367,7 @@ const char *QgsDxfExport::DXF_ENCODINGS[][2] =
};

QgsDxfExport::QgsDxfExport()
: mSymbologyScaleDenominator( 1.0 )
: mSymbologyScale( 1.0 )
, mSymbologyExport( NoSymbology )
, mMapUnits( QgsUnitTypes::DistanceMeters )
, mLayerTitleAsName( false )
@@ -387,7 +387,7 @@ QgsDxfExport &QgsDxfExport::operator=( const QgsDxfExport &dxfExport )
{
mMapSettings = dxfExport.mMapSettings;
mLayerNameAttribute = dxfExport.mLayerNameAttribute;
mSymbologyScaleDenominator = dxfExport.mSymbologyScaleDenominator;
mSymbologyScale = dxfExport.mSymbologyScale;
mSymbologyExport = dxfExport.mSymbologyExport;
mMapUnits = dxfExport.mMapUnits;
mLayerTitleAsName = dxfExport.mLayerTitleAsName;
@@ -540,7 +540,7 @@ int QgsDxfExport::writeToFile( QIODevice *d, const QString &encoding )
mMapSettings.setExtent( mExtent );

int dpi = 96;
mFactor = 1000 * dpi / mSymbologyScaleDenominator / 25.4 * QgsUnitTypes::fromUnitToUnitFactor( mapUnits, QgsUnitTypes::DistanceMeters );
mFactor = 1000 * dpi / mSymbologyScale / 25.4 * QgsUnitTypes::fromUnitToUnitFactor( mapUnits, QgsUnitTypes::DistanceMeters );
mMapSettings.setOutputSize( QSize( mExtent.width() * mFactor, mExtent.height() * mFactor ) );
mMapSettings.setOutputDpi( dpi );
if ( mCrs.isValid() )
@@ -921,13 +921,13 @@ void QgsDxfExport::writeBlocks()
// x/y/z coordinates of reference point
// todo: consider anchor point
// double size = ml->size();
// size *= mapUnitScaleFactor( mSymbologyScaleDenominator, ml->sizeUnit(), mMapUnits );
// size *= mapUnitScaleFactor( mSymbologyScale, ml->sizeUnit(), mMapUnits );
writeGroup( 0, QgsPoint( QgsWkbTypes::PointZ ) );
writeGroup( 3, block );
writeGroup( 1, QLatin1String( "" ) );

// maplayer 0 -> block receives layer from INSERT statement
ml->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, ml->sizeUnit(), mMapUnits ), QStringLiteral( "0" ), ctx );
ml->writeDxf( *this, mapUnitScaleFactor( mSymbologyScale, ml->sizeUnit(), mMapUnits ), QStringLiteral( "0" ), ctx );

writeGroup( 0, QStringLiteral( "ENDBLK" ) );
writeHandle();
@@ -956,7 +956,7 @@ void QgsDxfExport::writeEntities()

QgsRenderContext ctx;
ctx.setPainter( &painter );
ctx.setRendererScale( mSymbologyScaleDenominator );
ctx.setRendererScale( mSymbologyScale );
ctx.setExtent( mExtent );

ctx.setScaleFactor( 96.0 / 25.4 );
@@ -3398,7 +3398,7 @@ void QgsDxfExport::writePoint( const QgsPoint &pt, const QString &layer, const Q
const QgsMarkerSymbolLayer *msl = dynamic_cast< const QgsMarkerSymbolLayer * >( symbolLayer );
if ( msl )
{
double halfSize = msl->size() * mapUnitScaleFactor( mSymbologyScaleDenominator,
double halfSize = msl->size() * mapUnitScaleFactor( mSymbologyScale,
msl->sizeUnit(), mMapUnits ) / 2.0;
writeGroup( 0, "SOLID" );
writeGroup( 8, layer );
@@ -3418,7 +3418,7 @@ void QgsDxfExport::writePoint( const QgsPoint &pt, const QString &layer, const Q
const QgsMarkerSymbolLayer *msl = dynamic_cast< const QgsMarkerSymbolLayer * >( symbolLayer );
if ( msl && symbol )
{
if ( symbolLayer->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, msl->sizeUnit(), mMapUnits ), layer, ctx, QPointF( pt.x(), pt.y() ) ) )
if ( symbolLayer->writeDxf( *this, mapUnitScaleFactor( mSymbologyScale, msl->sizeUnit(), mMapUnits ), layer, ctx, QPointF( pt.x(), pt.y() ) ) )
{
return;
}
@@ -3960,18 +3960,18 @@ QRgb QgsDxfExport::createRgbEntry( qreal r, qreal g, qreal b )
QgsRenderContext QgsDxfExport::renderContext() const
{
QgsRenderContext context;
context.setRendererScale( mSymbologyScaleDenominator );
context.setRendererScale( mSymbologyScale );
return context;
}

double QgsDxfExport::mapUnitScaleFactor( double scaleDenominator, QgsUnitTypes::RenderUnit symbolUnits, QgsUnitTypes::DistanceUnit mapUnits )
double QgsDxfExport::mapUnitScaleFactor( double scale, QgsUnitTypes::RenderUnit symbolUnits, QgsUnitTypes::DistanceUnit mapUnits )
{
if ( symbolUnits == QgsUnitTypes::RenderMapUnits )
{
return 1.0;
}
// MM symbol unit
return scaleDenominator * QgsUnitTypes::fromUnitToUnitFactor( QgsUnitTypes::DistanceMeters, mapUnits ) / 1000.0;
return scale * QgsUnitTypes::fromUnitToUnitFactor( QgsUnitTypes::DistanceMeters, mapUnits ) / 1000.0;
}

QList< QPair< QgsSymbolLayer *, QgsSymbol * > > QgsDxfExport::symbolLayers( QgsRenderContext &context )
@@ -4102,7 +4102,7 @@ void QgsDxfExport::writeLinetype( const QString &styleName, const QVector<qreal>
QVector<qreal>::const_iterator dashIt = pattern.constBegin();
for ( ; dashIt != pattern.constEnd(); ++dashIt )
{
length += ( *dashIt * mapUnitScaleFactor( mSymbologyScaleDenominator, u, mMapUnits ) );
length += ( *dashIt * mapUnitScaleFactor( mSymbologyScale, u, mMapUnits ) );
}

writeGroup( 0, QStringLiteral( "LTYPE" ) );
@@ -4123,7 +4123,7 @@ void QgsDxfExport::writeLinetype( const QString &styleName, const QVector<qreal>
{
// map units or mm?
double segmentLength = ( isGap ? -*dashIt : *dashIt );
segmentLength *= mapUnitScaleFactor( mSymbologyScaleDenominator, u, mMapUnits );
segmentLength *= mapUnitScaleFactor( mSymbologyScale, u, mMapUnits );
writeGroup( 49, segmentLength );
writeGroup( 74, 0 );
isGap = !isGap;
@@ -4147,19 +4147,19 @@ bool QgsDxfExport::hasDataDefinedProperties( const QgsSymbolLayer *sl, const Qgs

double QgsDxfExport::dashSize() const
{
double size = mSymbologyScaleDenominator * 0.002;
double size = mSymbologyScale * 0.002;
return sizeToMapUnits( size );
}

double QgsDxfExport::dotSize() const
{
double size = mSymbologyScaleDenominator * 0.0006;
double size = mSymbologyScale * 0.0006;
return sizeToMapUnits( size );
}

double QgsDxfExport::dashSeparatorSize() const
{
double size = mSymbologyScaleDenominator * 0.0006;
double size = mSymbologyScale * 0.0006;
return sizeToMapUnits( size );
}

@@ -4227,7 +4227,7 @@ bool QgsDxfExport::layerIsScaleBasedVisible( const QgsMapLayer *layer ) const
if ( mSymbologyExport == QgsDxfExport::NoSymbology )
return true;

return layer->isInScaleRange( mSymbologyScaleDenominator );
return layer->isInScaleRange( mSymbologyScale );
}

QString QgsDxfExport::layerName( const QString &id, const QgsFeature &f ) const
@@ -79,17 +79,20 @@ class CORE_EXPORT QgsDxfExport
int writeToFile( QIODevice *d, const QString &codec ); //maybe add progress dialog? other parameters (e.g. scale, dpi)?

/**
* Set reference scale for output
* \param d scale denominator
* Set reference \a scale for output.
* The \a scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
* \since QGIS 3.0
* \see symbologyScale()
*/
void setSymbologyScaleDenominator( double d ) { mSymbologyScaleDenominator = d; }
void setSymbologyScale( double scale ) { mSymbologyScale = scale; }

/**
* Retrieve reference scale for output
* \returns reference scale
* \see setSymbologyScaleDenominator
* Returns the reference scale for output.
* The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
* \since QGIS 3.0
* \see setSymbologyScale()
*/
double symbologyScaleDenominator() const { return mSymbologyScaleDenominator; }
double symbologyScale() const { return mSymbologyScale; }

/**
* Retrieve map units
@@ -300,8 +303,11 @@ class CORE_EXPORT QgsDxfExport
//! \since QGIS 2.15
void writeMText( const QString &layer, const QString &text, const QgsPoint &pt, double width, double angle, const QColor &color );

//! Calculates a scaling factor to convert from map units to a specified symbol unit.
static double mapUnitScaleFactor( double scaleDenominator, QgsUnitTypes::RenderUnit symbolUnits, QgsUnitTypes::DistanceUnit mapUnits );
/**
* Calculates a scaling factor to convert from map units to a specified symbol unit.
* The \a scale parameter indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
*/
static double mapUnitScaleFactor( double scale, QgsUnitTypes::RenderUnit symbolUnits, QgsUnitTypes::DistanceUnit mapUnits );

//! Return cleaned layer name for use in DXF
static QString dxfLayerName( const QString &name );
@@ -332,7 +338,7 @@ class CORE_EXPORT QgsDxfExport
//! Extent for export, only intersecting features are exported. If the extent is an empty rectangle, all features are exported
QgsRectangle mExtent;
//! Scale for symbology export (used if symbols units are mm)
double mSymbologyScaleDenominator;
double mSymbologyScale;
SymbologyExport mSymbologyExport;
QgsUnitTypes::DistanceUnit mMapUnits;
bool mLayerTitleAsName;

0 comments on commit 1be5fbd

Please sign in to comment.
You can’t perform that action at this time.