Skip to content

Commit

Permalink
More consistency across scale API
Browse files Browse the repository at this point in the history
Use a real scale widget for point displacement label scale
  • Loading branch information
nyalldawson committed Jun 9, 2017
1 parent a3d919d commit 1be5fbd
Show file tree
Hide file tree
Showing 36 changed files with 296 additions and 224 deletions.
6 changes: 6 additions & 0 deletions doc/api_break.dox
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down
22 changes: 13 additions & 9 deletions python/core/dxf/qgsdxfexport.sip
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion python/core/layertree/qgslayertreemodel.sip
Expand Up @@ -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

Expand Down
15 changes: 13 additions & 2 deletions python/core/qgsvectorfilewriter.sip
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions python/core/symbology-ng/qgspointdistancerenderer.sip
Expand Up @@ -106,7 +106,7 @@ Optional label text
.. seealso:: labelAttributeName()
.. seealso:: setLabelFont()
.. seealso:: setLabelColor()
.. seealso:: setMaxLabelScaleDenominator()
.. seealso:: setMinimumLabelScale()
%End

QString labelAttributeName() const;
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/app/main.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -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() );
Expand Down
34 changes: 17 additions & 17 deletions src/core/dxf/qgsdxfexport.cpp
Expand Up @@ -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 )
Expand All @@ -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;
Expand Down Expand Up @@ -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() )
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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" ) );
Expand All @@ -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;
Expand All @@ -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 );
}

Expand Down Expand Up @@ -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
Expand Down
26 changes: 16 additions & 10 deletions src/core/dxf/qgsdxfexport.h
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1be5fbd

Please sign in to comment.