Skip to content

Commit

Permalink
Consider scale based visibility in dxf export. Const correctness for …
Browse files Browse the repository at this point in the history
…maplayer accessors
  • Loading branch information
mhugent committed Jan 21, 2014
1 parent 7d2bf15 commit a5b0e04
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 17 deletions.
6 changes: 3 additions & 3 deletions python/core/qgsmaplayer.sip
Expand Up @@ -366,15 +366,15 @@ class QgsMapLayer : QObject

/** Accessor and mutator for the minimum scale denominator member */
void setMinimumScale( float theMinScale );
float minimumScale();
float minimumScale() const;

/** Accessor and mutator for the maximum scale denominator member */
void setMaximumScale( float theMaxScale );
float maximumScale();
float maximumScale() const;

/** Accessor and mutator for the scale based visilibility flag */
void toggleScaleBasedVisibility( bool theVisibilityFlag );
bool hasScaleBasedVisibility();
bool hasScaleBasedVisibility() const;

/** Clear cached image
* added in 1.5 */
Expand Down
25 changes: 23 additions & 2 deletions src/core/dxf/qgsdxfexport.cpp
Expand Up @@ -466,6 +466,11 @@ void QgsDxfExport::writeTables()
QList< QgsMapLayer* >::const_iterator layerIt = mLayers.constBegin();
for ( ; layerIt != mLayers.constEnd(); ++layerIt )
{
if ( !layerIsScaleBasedVisible(( *layerIt ) ) )
{
continue;
}

writeGroup( 0, "LAYER" );
QString layerName = *layerIt ? ( *layerIt )->name() : "";
writeGroup( 2, dxfLayerName( layerName ) );
Expand Down Expand Up @@ -559,15 +564,15 @@ void QgsDxfExport::writeEntities()
writeGroup( 2, "ENTITIES" );

//label engine
QgsDxfPalLabeling labelEngine( this, mExtent.isEmpty() ? dxfExtent() : mExtent, mSymbologyScaleDenominator );
QgsDxfPalLabeling labelEngine( this, mExtent.isEmpty() ? dxfExtent() : mExtent, mSymbologyScaleDenominator, mMapUnits );
QgsRenderContext& ctx = labelEngine.renderContext();

//iterate through the maplayers
QList< QgsMapLayer* >::iterator layerIt = mLayers.begin();
for ( ; layerIt != mLayers.end(); ++layerIt )
{
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( *layerIt );
if ( !vl )
if ( !vl || !layerIsScaleBasedVisible( vl ) )
{
continue;
}
Expand Down Expand Up @@ -1340,6 +1345,22 @@ QString QgsDxfExport::dxfLayerName( const QString& name )
return layerName;
}

bool QgsDxfExport::layerIsScaleBasedVisible( const QgsMapLayer* layer ) const
{
if ( !layer )
{
return false;
}

if ( mSymbologyExport == QgsDxfExport::NoSymbology || !layer->hasScaleBasedVisibility() )
{
return true;
}

return ( layer->minimumScale() < mSymbologyScaleDenominator &&
layer->minimumScale() > mSymbologyScaleDenominator );
}

/******************************************************Test with AC_1018 methods***************************************************************/

void QgsDxfExport::writeHeaderAC1018( QTextStream& stream )
Expand Down
1 change: 1 addition & 0 deletions src/core/dxf/qgsdxfexport.h
Expand Up @@ -163,6 +163,7 @@ class CORE_EXPORT QgsDxfExport
double dashSeparatorSize() const;
double sizeToMapUnits( double s ) const;
static QString lineNameFromPenStyle( Qt::PenStyle style );
bool layerIsScaleBasedVisible( const QgsMapLayer* layer ) const;
};

#endif // QGSDXFEXPORT_H
7 changes: 2 additions & 5 deletions src/core/dxf/qgsdxfpallabeling.cpp
Expand Up @@ -24,18 +24,15 @@

using namespace pal;

QgsDxfPalLabeling::QgsDxfPalLabeling( QgsDxfExport* dxf, const QgsRectangle& bbox, double scale ): QgsPalLabeling(), mDxfExport( dxf )
QgsDxfPalLabeling::QgsDxfPalLabeling( QgsDxfExport* dxf, const QgsRectangle& bbox, double scale, QGis::UnitType mapUnits ): QgsPalLabeling(), mDxfExport( dxf )
{
mMapRenderer.setExtent( bbox );

//todo: adapt to other map units than meters
int dpi = 96;
double factor = 1000 * dpi / scale / 25.4;
double factor = 1000 * dpi / scale / 25.4 * QGis::fromUnitToUnitFactor( mapUnits, QGis::Meters );
mMapRenderer.setOutputSize( QSizeF( bbox.width() * factor, bbox.height() * factor ), dpi );
mMapRenderer.setScale( scale );
mMapRenderer.setOutputUnits( QgsMapRenderer::Pixels );

//mMapRenderer.setLayer necessary?
init( &mMapRenderer );

mImage = new QImage( 10, 10, QImage::Format_ARGB32_Premultiplied );
Expand Down
2 changes: 1 addition & 1 deletion src/core/dxf/qgsdxfpallabeling.h
Expand Up @@ -27,7 +27,7 @@ class QgsDxfExport;
class CORE_EXPORT QgsDxfPalLabeling: public QgsPalLabeling
{
public:
QgsDxfPalLabeling( QgsDxfExport* dxf, const QgsRectangle& bbox, double scale );
QgsDxfPalLabeling( QgsDxfExport* dxf, const QgsRectangle& bbox, double scale, QGis::UnitType mapUnits );
~QgsDxfPalLabeling();

QgsRenderContext& renderContext() { return mRenderContext; }
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -628,7 +628,7 @@ void QgsMapLayer::toggleScaleBasedVisibility( bool theVisibilityFlag )
mScaleBasedVisibility = theVisibilityFlag;
}

bool QgsMapLayer::hasScaleBasedVisibility()
bool QgsMapLayer::hasScaleBasedVisibility() const
{
return mScaleBasedVisibility;
}
Expand All @@ -638,7 +638,7 @@ void QgsMapLayer::setMinimumScale( float theMinScale )
mMinScale = theMinScale;
}

float QgsMapLayer::minimumScale()
float QgsMapLayer::minimumScale() const
{
return mMinScale;
}
Expand All @@ -649,7 +649,7 @@ void QgsMapLayer::setMaximumScale( float theMaxScale )
mMaxScale = theMaxScale;
}

float QgsMapLayer::maximumScale()
float QgsMapLayer::maximumScale() const
{
return mMaxScale;
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsmaplayer.h
Expand Up @@ -380,15 +380,15 @@ class CORE_EXPORT QgsMapLayer : public QObject

/** Accessor and mutator for the minimum scale denominator member */
void setMinimumScale( float theMinScale );
float minimumScale();
float minimumScale() const;

/** Accessor and mutator for the maximum scale denominator member */
void setMaximumScale( float theMaxScale );
float maximumScale();
float maximumScale() const;

/** Accessor and mutator for the scale based visilibility flag */
void toggleScaleBasedVisibility( bool theVisibilityFlag );
bool hasScaleBasedVisibility();
bool hasScaleBasedVisibility() const;

/** Clear cached image
* added in 1.5 */
Expand Down

0 comments on commit a5b0e04

Please sign in to comment.