Skip to content

Commit a5b0e04

Browse files
committed
Consider scale based visibility in dxf export. Const correctness for maplayer accessors
1 parent 7d2bf15 commit a5b0e04

7 files changed

+36
-17
lines changed

python/core/qgsmaplayer.sip

+3-3
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,15 @@ class QgsMapLayer : QObject
366366

367367
/** Accessor and mutator for the minimum scale denominator member */
368368
void setMinimumScale( float theMinScale );
369-
float minimumScale();
369+
float minimumScale() const;
370370

371371
/** Accessor and mutator for the maximum scale denominator member */
372372
void setMaximumScale( float theMaxScale );
373-
float maximumScale();
373+
float maximumScale() const;
374374

375375
/** Accessor and mutator for the scale based visilibility flag */
376376
void toggleScaleBasedVisibility( bool theVisibilityFlag );
377-
bool hasScaleBasedVisibility();
377+
bool hasScaleBasedVisibility() const;
378378

379379
/** Clear cached image
380380
* added in 1.5 */

src/core/dxf/qgsdxfexport.cpp

+23-2
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,11 @@ void QgsDxfExport::writeTables()
466466
QList< QgsMapLayer* >::const_iterator layerIt = mLayers.constBegin();
467467
for ( ; layerIt != mLayers.constEnd(); ++layerIt )
468468
{
469+
if ( !layerIsScaleBasedVisible(( *layerIt ) ) )
470+
{
471+
continue;
472+
}
473+
469474
writeGroup( 0, "LAYER" );
470475
QString layerName = *layerIt ? ( *layerIt )->name() : "";
471476
writeGroup( 2, dxfLayerName( layerName ) );
@@ -559,15 +564,15 @@ void QgsDxfExport::writeEntities()
559564
writeGroup( 2, "ENTITIES" );
560565

561566
//label engine
562-
QgsDxfPalLabeling labelEngine( this, mExtent.isEmpty() ? dxfExtent() : mExtent, mSymbologyScaleDenominator );
567+
QgsDxfPalLabeling labelEngine( this, mExtent.isEmpty() ? dxfExtent() : mExtent, mSymbologyScaleDenominator, mMapUnits );
563568
QgsRenderContext& ctx = labelEngine.renderContext();
564569

565570
//iterate through the maplayers
566571
QList< QgsMapLayer* >::iterator layerIt = mLayers.begin();
567572
for ( ; layerIt != mLayers.end(); ++layerIt )
568573
{
569574
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( *layerIt );
570-
if ( !vl )
575+
if ( !vl || !layerIsScaleBasedVisible( vl ) )
571576
{
572577
continue;
573578
}
@@ -1340,6 +1345,22 @@ QString QgsDxfExport::dxfLayerName( const QString& name )
13401345
return layerName;
13411346
}
13421347

1348+
bool QgsDxfExport::layerIsScaleBasedVisible( const QgsMapLayer* layer ) const
1349+
{
1350+
if ( !layer )
1351+
{
1352+
return false;
1353+
}
1354+
1355+
if ( mSymbologyExport == QgsDxfExport::NoSymbology || !layer->hasScaleBasedVisibility() )
1356+
{
1357+
return true;
1358+
}
1359+
1360+
return ( layer->minimumScale() < mSymbologyScaleDenominator &&
1361+
layer->minimumScale() > mSymbologyScaleDenominator );
1362+
}
1363+
13431364
/******************************************************Test with AC_1018 methods***************************************************************/
13441365

13451366
void QgsDxfExport::writeHeaderAC1018( QTextStream& stream )

src/core/dxf/qgsdxfexport.h

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class CORE_EXPORT QgsDxfExport
163163
double dashSeparatorSize() const;
164164
double sizeToMapUnits( double s ) const;
165165
static QString lineNameFromPenStyle( Qt::PenStyle style );
166+
bool layerIsScaleBasedVisible( const QgsMapLayer* layer ) const;
166167
};
167168

168169
#endif // QGSDXFEXPORT_H

src/core/dxf/qgsdxfpallabeling.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@
2424

2525
using namespace pal;
2626

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

31-
//todo: adapt to other map units than meters
3231
int dpi = 96;
33-
double factor = 1000 * dpi / scale / 25.4;
32+
double factor = 1000 * dpi / scale / 25.4 * QGis::fromUnitToUnitFactor( mapUnits, QGis::Meters );
3433
mMapRenderer.setOutputSize( QSizeF( bbox.width() * factor, bbox.height() * factor ), dpi );
3534
mMapRenderer.setScale( scale );
3635
mMapRenderer.setOutputUnits( QgsMapRenderer::Pixels );
37-
38-
//mMapRenderer.setLayer necessary?
3936
init( &mMapRenderer );
4037

4138
mImage = new QImage( 10, 10, QImage::Format_ARGB32_Premultiplied );

src/core/dxf/qgsdxfpallabeling.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class QgsDxfExport;
2727
class CORE_EXPORT QgsDxfPalLabeling: public QgsPalLabeling
2828
{
2929
public:
30-
QgsDxfPalLabeling( QgsDxfExport* dxf, const QgsRectangle& bbox, double scale );
30+
QgsDxfPalLabeling( QgsDxfExport* dxf, const QgsRectangle& bbox, double scale, QGis::UnitType mapUnits );
3131
~QgsDxfPalLabeling();
3232

3333
QgsRenderContext& renderContext() { return mRenderContext; }

src/core/qgsmaplayer.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ void QgsMapLayer::toggleScaleBasedVisibility( bool theVisibilityFlag )
628628
mScaleBasedVisibility = theVisibilityFlag;
629629
}
630630

631-
bool QgsMapLayer::hasScaleBasedVisibility()
631+
bool QgsMapLayer::hasScaleBasedVisibility() const
632632
{
633633
return mScaleBasedVisibility;
634634
}
@@ -638,7 +638,7 @@ void QgsMapLayer::setMinimumScale( float theMinScale )
638638
mMinScale = theMinScale;
639639
}
640640

641-
float QgsMapLayer::minimumScale()
641+
float QgsMapLayer::minimumScale() const
642642
{
643643
return mMinScale;
644644
}
@@ -649,7 +649,7 @@ void QgsMapLayer::setMaximumScale( float theMaxScale )
649649
mMaxScale = theMaxScale;
650650
}
651651

652-
float QgsMapLayer::maximumScale()
652+
float QgsMapLayer::maximumScale() const
653653
{
654654
return mMaxScale;
655655
}

src/core/qgsmaplayer.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -380,15 +380,15 @@ class CORE_EXPORT QgsMapLayer : public QObject
380380

381381
/** Accessor and mutator for the minimum scale denominator member */
382382
void setMinimumScale( float theMinScale );
383-
float minimumScale();
383+
float minimumScale() const;
384384

385385
/** Accessor and mutator for the maximum scale denominator member */
386386
void setMaximumScale( float theMaxScale );
387-
float maximumScale();
387+
float maximumScale() const;
388388

389389
/** Accessor and mutator for the scale based visilibility flag */
390390
void toggleScaleBasedVisibility( bool theVisibilityFlag );
391-
bool hasScaleBasedVisibility();
391+
bool hasScaleBasedVisibility() const;
392392

393393
/** Clear cached image
394394
* added in 1.5 */

0 commit comments

Comments
 (0)