Skip to content
Permalink
Browse files

Consider scale based visibility in dxf export. Const correctness for …

…maplayer accessors
  • Loading branch information
mhugent committed Jan 21, 2014
1 parent 7d2bf15 commit a5b0e045858afbc2df38827a959400a4ae4ffb20
@@ -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 */
@@ -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 ) );
@@ -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;
}
@@ -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 )
@@ -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
@@ -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 );
@@ -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; }
@@ -628,7 +628,7 @@ void QgsMapLayer::toggleScaleBasedVisibility( bool theVisibilityFlag )
mScaleBasedVisibility = theVisibilityFlag;
}

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

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

float QgsMapLayer::maximumScale()
float QgsMapLayer::maximumScale() const
{
return mMaxScale;
}
@@ -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 */

0 comments on commit a5b0e04

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