Skip to content
Permalink
Browse files

Unify diagram scale API with rest of scale API

  • Loading branch information
nyalldawson committed Jun 9, 2017
1 parent 1be5fbd commit 37f86f5f046d8af090197c6660ef53c90ea3941d
@@ -1027,6 +1027,7 @@ QgsDiagramSettings {#qgis_api_break_3_0_QgsDiagramSettings}
- readXml() and writeXml() do not take QgsVectorLayer as an argument anymore.
- transparency was removed. Use opacity instead.
- angleOffset was removed. Use rotationOffset instead.
- minScaleDenominator and maxScaleDenominator were removed. Use maximumScale and minimumScale instead.


QgsDial {#qgis_api_break_3_0_QgsDial}
@@ -373,8 +373,22 @@ Opacity, from 0 (transparent) to 1.0 (opaque)
%End

bool scaleBasedVisibility;
double minScaleDenominator;
double maxScaleDenominator;

double maximumScale;
%Docstring
The maximum map scale (i.e. most "zoomed in" scale) at which the layer will be visible.
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
A scale of 0 indicates no maximum scale visibility.
.. seealso:: minimumScale
%End

double minimumScale;
%Docstring
The minimum map scale (i.e. most "zoomed out" scale) at which the layer will be visible.
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
A scale of 0 indicates no minimum scale visibility.
.. seealso:: maximumScale
%End

double minimumSize;
%Docstring
@@ -265,8 +265,8 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
mDiagramPenColorButton->setColor( settingList.at( 0 ).penColor );
mPenWidthSpinBox->setValue( settingList.at( 0 ).penWidth );
mDiagramSizeSpinBox->setValue( ( size.width() + size.height() ) / 2.0 );
mScaleRangeWidget->setScaleRange( ( settingList.at( 0 ).maxScaleDenominator > 0 ? settingList.at( 0 ).maxScaleDenominator : layer->minimumScale() ),
( settingList.at( 0 ).minScaleDenominator > 0 ? settingList.at( 0 ).minScaleDenominator : layer->maximumScale() ) );
mScaleRangeWidget->setScaleRange( ( settingList.at( 0 ).minimumScale > 0 ? settingList.at( 0 ).minimumScale : layer->minimumScale() ),
( settingList.at( 0 ).maximumScale > 0 ? settingList.at( 0 ).maximumScale : layer->maximumScale() ) );
mScaleVisibilityGroupBox->setChecked( settingList.at( 0 ).scaleBasedVisibility );
mDiagramUnitComboBox->setUnit( settingList.at( 0 ).sizeType );
mDiagramUnitComboBox->setMapUnitScale( settingList.at( 0 ).sizeScale );
@@ -772,9 +772,8 @@ void QgsDiagramProperties::apply()
ds.backgroundColor = mBackgroundColorButton->color();
ds.penColor = mDiagramPenColorButton->color();
ds.penWidth = mPenWidthSpinBox->value();
// caution: layer uses scale denoms, widget uses true scales
ds.maxScaleDenominator = mScaleRangeWidget->minimumScale();
ds.minScaleDenominator = mScaleRangeWidget->maximumScale();
ds.minimumScale = mScaleRangeWidget->minimumScale();
ds.maximumScale = mScaleRangeWidget->maximumScale();
ds.scaleBasedVisibility = mScaleVisibilityGroupBox->isChecked();

// Diagram angle offset (pie)
@@ -188,15 +188,15 @@ void QgsDiagramSettings::readXml( const QDomElement &elem )
penColor.setAlpha( penAlpha );
penWidth = elem.attribute( QStringLiteral( "penWidth" ) ).toDouble();

minScaleDenominator = elem.attribute( QStringLiteral( "minScaleDenominator" ), QStringLiteral( "-1" ) ).toDouble();
maxScaleDenominator = elem.attribute( QStringLiteral( "maxScaleDenominator" ), QStringLiteral( "-1" ) ).toDouble();
maximumScale = elem.attribute( QStringLiteral( "minScaleDenominator" ), QStringLiteral( "-1" ) ).toDouble();
minimumScale = elem.attribute( QStringLiteral( "maxScaleDenominator" ), QStringLiteral( "-1" ) ).toDouble();
if ( elem.hasAttribute( QStringLiteral( "scaleBasedVisibility" ) ) )
{
scaleBasedVisibility = ( elem.attribute( QStringLiteral( "scaleBasedVisibility" ), QStringLiteral( "1" ) ) != QLatin1String( "0" ) );
}
else
{
scaleBasedVisibility = minScaleDenominator >= 0 && maxScaleDenominator >= 0;
scaleBasedVisibility = maximumScale >= 0 && minimumScale >= 0;
}

//diagram size unit type and scale
@@ -320,8 +320,8 @@ void QgsDiagramSettings::writeXml( QDomElement &rendererElem, QDomDocument &doc
categoryElem.setAttribute( QStringLiteral( "penAlpha" ), penColor.alpha() );
categoryElem.setAttribute( QStringLiteral( "penWidth" ), QString::number( penWidth ) );
categoryElem.setAttribute( QStringLiteral( "scaleBasedVisibility" ), scaleBasedVisibility );
categoryElem.setAttribute( QStringLiteral( "minScaleDenominator" ), QString::number( minScaleDenominator ) );
categoryElem.setAttribute( QStringLiteral( "maxScaleDenominator" ), QString::number( maxScaleDenominator ) );
categoryElem.setAttribute( QStringLiteral( "minScaleDenominator" ), QString::number( maximumScale ) );
categoryElem.setAttribute( QStringLiteral( "maxScaleDenominator" ), QString::number( minimumScale ) );
categoryElem.setAttribute( QStringLiteral( "opacity" ), QString::number( opacity ) );

//diagram size unit type and scale
@@ -376,8 +376,6 @@ class CORE_EXPORT QgsDiagramSettings
, scaleByArea( true )
, rotationOffset( 270 ) //top
, scaleBasedVisibility( false )
, minScaleDenominator( -1 )
, maxScaleDenominator( -1 )
, minimumSize( 0.0 )
{}
bool enabled;
@@ -426,9 +424,22 @@ class CORE_EXPORT QgsDiagramSettings
double rotationOffset;

bool scaleBasedVisibility;
//scale range (-1 if no lower / upper bound )
double minScaleDenominator;
double maxScaleDenominator;

/**
* The maximum map scale (i.e. most "zoomed in" scale) at which the layer will be visible.
* The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
* A scale of 0 indicates no maximum scale visibility.
* \see minimumScale
*/
double maximumScale = 0;

/**
* The minimum map scale (i.e. most "zoomed out" scale) at which the layer will be visible.
* The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
* A scale of 0 indicates no minimum scale visibility.
* \see maximumScale
*/
double minimumScale = 0;

//! Scale diagrams smaller than mMinimumSize to mMinimumSize
double minimumSize;
@@ -177,14 +177,14 @@ QgsLabelFeature *QgsVectorLayerDiagramProvider::registerDiagram( QgsFeature &fea
QList<QgsDiagramSettings> settingList = dr->diagramSettings();
if ( !settingList.isEmpty() && settingList.at( 0 ).scaleBasedVisibility )
{
double minScale = settingList.at( 0 ).minScaleDenominator;
if ( minScale > 0 && context.rendererScale() < minScale )
double maxScale = settingList.at( 0 ).maximumScale;
if ( maxScale > 0 && context.rendererScale() < maxScale )
{
return nullptr;
}

double maxScale = settingList.at( 0 ).maxScaleDenominator;
if ( maxScale > 0 && context.rendererScale() > maxScale )
double minScale = settingList.at( 0 ).minimumScale;
if ( minScale > 0 && context.rendererScale() > minScale )
{
return nullptr;
}
@@ -166,6 +166,11 @@ void QgsPointDisplacementRendererWidget::setContext( const QgsSymbolWidgetContex
QgsRendererWidget::setContext( context );
if ( mDistanceUnitWidget )
mDistanceUnitWidget->setMapCanvas( context.mapCanvas() );
if ( mMinLabelScaleWidget )
{
mMinLabelScaleWidget->setMapCanvas( context.mapCanvas() );
mMinLabelScaleWidget->setShowCurrentScaleButton( true );
}
}

void QgsPointDisplacementRendererWidget::on_mLabelFieldComboBox_currentIndexChanged( const QString &text )
@@ -145,8 +145,8 @@ class TestQgsDiagram : public QObject
col2.setAlphaF( 0.5 );
ds.categoryColors = QList<QColor>() << col1 << col2;
ds.categoryAttributes = QList<QString>() << QStringLiteral( "\"Pilots\"" ) << QStringLiteral( "\"Cabin Crew\"" );
ds.maxScaleDenominator = -1;
ds.minScaleDenominator = -1;
ds.minimumScale = -1;
ds.maximumScale = -1;
ds.minimumSize = 0;
ds.penColor = Qt::green;
ds.penWidth = .5;
@@ -182,8 +182,8 @@ class TestQgsDiagram : public QObject
col2.setAlphaF( 0.5 );
ds.categoryColors = QList<QColor>() << col1 << col2;
ds.categoryAttributes = QList<QString>() << QStringLiteral( "ln(Pilots + 1)" ) << QStringLiteral( "ln(\"Cabin Crew\" + 1)" );
ds.maxScaleDenominator = -1;
ds.minScaleDenominator = -1;
ds.minimumScale = -1;
ds.maximumScale = -1;
ds.minimumSize = 0;
ds.penColor = Qt::green;
ds.penWidth = .5;
@@ -224,8 +224,8 @@ class TestQgsDiagram : public QObject
col2.setAlphaF( 0.5 );
ds.categoryColors = QList<QColor>() << col1 << col2;
ds.categoryAttributes = QList<QString>() << "\"Pilots\"" << "\"Cabin Crew\"";
ds.maxScaleDenominator = -1;
ds.minScaleDenominator = -1;
ds.minimumScale = -1;
ds.maximumScale = -1;
ds.minimumSize = 0;
ds.penColor = Qt::green;
ds.penWidth = .5;
@@ -261,8 +261,8 @@ class TestQgsDiagram : public QObject
col2.setAlphaF( 0.5 );
ds.categoryColors = QList<QColor>() << col1 << col2;
ds.categoryAttributes = QList<QString>() << "\"Pilots\"" << "\"Cabin Crew\"";
ds.maxScaleDenominator = -1;
ds.minScaleDenominator = -1;
ds.minimumScale = -1;
ds.maximumScale = -1;
ds.minimumSize = 0;
ds.penColor = Qt::green;
ds.penWidth = .5;
@@ -298,8 +298,8 @@ class TestQgsDiagram : public QObject
col2.setAlphaF( 0.5 );
ds.categoryColors = QList<QColor>() << col1 << col2;
ds.categoryAttributes = QList<QString>() << "\"Pilots\"" << "\"Cabin Crew\"";
ds.maxScaleDenominator = -1;
ds.minScaleDenominator = -1;
ds.minimumScale = -1;
ds.maximumScale = -1;
ds.minimumSize = 0;
ds.penColor = Qt::green;
ds.penWidth = .5;
@@ -334,8 +334,8 @@ class TestQgsDiagram : public QObject
col2.setAlphaF( 0.5 );
ds.categoryColors = QList<QColor>() << col1 << col2;
ds.categoryAttributes = QList<QString>() << "\"Pilots\"" << "\"Cabin Crew\"";
ds.maxScaleDenominator = -1;
ds.minScaleDenominator = -1;
ds.minimumScale = -1;
ds.maximumScale = -1;
ds.minimumSize = 0;
ds.penColor = Qt::green;
ds.penWidth = .5;
@@ -370,8 +370,8 @@ class TestQgsDiagram : public QObject
col2.setAlphaF( 0.5 );
ds.categoryColors = QList<QColor>() << col1 << col2;
ds.categoryAttributes = QList<QString>() << "\"Pilots\"" << "\"Cabin Crew\"";
ds.maxScaleDenominator = -1;
ds.minScaleDenominator = -1;
ds.minimumScale = -1;
ds.maximumScale = -1;
ds.minimumSize = 0;
ds.penColor = Qt::green;
ds.penWidth = .5;
@@ -406,8 +406,8 @@ class TestQgsDiagram : public QObject
col2.setAlphaF( 0.5 );
ds.categoryColors = QList<QColor>() << col1 << col2;
ds.categoryAttributes = QList<QString>() << "\"Pilots\"" << "\"Cabin Crew\"";
ds.maxScaleDenominator = -1;
ds.minScaleDenominator = -1;
ds.minimumScale = -1;
ds.maximumScale = -1;
ds.minimumSize = 0;
ds.penColor = Qt::green;
ds.penWidth = .5;
@@ -440,8 +440,8 @@ class TestQgsDiagram : public QObject
QColor col2 = Qt::yellow;
ds.categoryColors = QList<QColor>() << col1 << col2;
ds.categoryAttributes = QList<QString>() << "\"Pilots\"" << "\"Cabin Crew\"";
ds.maxScaleDenominator = -1;
ds.minScaleDenominator = -1;
ds.minimumScale = -1;
ds.maximumScale = -1;
ds.minimumSize = 0;
ds.penColor = Qt::green;
ds.penWidth = .5;
@@ -476,8 +476,8 @@ class TestQgsDiagram : public QObject
col2.setAlphaF( 0.5 );
ds.categoryColors = QList<QColor>() << col1 << col2;
ds.categoryAttributes = QList<QString>() << "\"Pilots\"" << "\"Cabin Crew\"";
ds.maxScaleDenominator = -1;
ds.minScaleDenominator = -1;
ds.minimumScale = -1;
ds.maximumScale = -1;
ds.minimumSize = 0;
ds.penColor = Qt::green;
ds.penWidth = .5;
@@ -517,8 +517,8 @@ class TestQgsDiagram : public QObject
col2.setAlphaF( 0 );
ds.categoryColors = QList<QColor>() << col1 << col2;
ds.categoryAttributes = QList<QString>() << "\"Pilots\"" << "\"Cabin Crew\"";
ds.maxScaleDenominator = -1;
ds.minScaleDenominator = -1;
ds.minimumScale = -1;
ds.maximumScale = -1;
ds.minimumSize = 0;
ds.penColor = Qt::green;
ds.penWidth = .5;

0 comments on commit 37f86f5

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