Skip to content
Permalink
Browse files

Ensure QgsMapLayer private QObject members are correctly parented

to the layer
  • Loading branch information
nyalldawson committed Feb 15, 2018
1 parent 2defaff commit bc23f1d6773c27add932b3af729a648f1bbb948f
Showing with 27 additions and 32 deletions.
  1. +19 −26 src/core/qgsmaplayer.cpp
  2. +8 −6 src/core/qgsmaplayer.h
@@ -70,12 +70,13 @@ QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
const QString &lyrname,
const QString &source )
: mDataSource( source )
, mLayerName( lyrname )
, mLayerType( type )
, mUndoStack( new QUndoStack( this ) )
, mUndoStackStyles( new QUndoStack( this ) )
, mStyleManager( new QgsMapLayerStyleManager( this ) )
, mRefreshTimer( new QTimer( this ) )
{
// Set the display name = internal name
mLayerName = lyrname;

//mShortName.replace( QRegExp( "[\\W]" ), "_" );

// Generate the unique ID of this layer
@@ -91,13 +92,8 @@ QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
// there for the compiler, so the pattern is actually \W
mID.replace( QRegExp( "[\\W]" ), QStringLiteral( "_" ) );

//set some generous defaults for scale based visibility
mMinScale = 0;
mMaxScale = 100000000;
mScaleBasedVisibility = false;

connect( mStyleManager, &QgsMapLayerStyleManager::currentStyleChanged, this, &QgsMapLayer::styleChanged );
connect( &mRefreshTimer, &QTimer::timeout, this, [ = ] { triggerRepaint( true ); } );
connect( mRefreshTimer, &QTimer::timeout, this, [ = ] { triggerRepaint( true ); } );
}

QgsMapLayer::~QgsMapLayer()
@@ -586,8 +582,8 @@ bool QgsMapLayer::writeLayerXml( QDomElement &layerElement, QDomDocument &docume
layerElement.appendChild( QgsXmlUtils::writeRectangle( mExtent, document ) );
}

layerElement.setAttribute( QStringLiteral( "autoRefreshTime" ), QString::number( mRefreshTimer.interval() ) );
layerElement.setAttribute( QStringLiteral( "autoRefreshEnabled" ), mRefreshTimer.isActive() ? 1 : 0 );
layerElement.setAttribute( QStringLiteral( "autoRefreshTime" ), QString::number( mRefreshTimer->interval() ) );
layerElement.setAttribute( QStringLiteral( "autoRefreshEnabled" ), mRefreshTimer->isActive() ? 1 : 0 );
layerElement.setAttribute( QStringLiteral( "refreshOnNotifyEnabled" ), mIsRefreshOnNofifyEnabled ? 1 : 0 );
layerElement.setAttribute( QStringLiteral( "refreshOnNotifyMessage" ), mRefreshOnNofifyMessage );

@@ -913,36 +909,36 @@ bool QgsMapLayer::hasScaleBasedVisibility() const

bool QgsMapLayer::hasAutoRefreshEnabled() const
{
return mRefreshTimer.isActive();
return mRefreshTimer->isActive();
}

int QgsMapLayer::autoRefreshInterval() const
{
return mRefreshTimer.interval();
return mRefreshTimer->interval();
}

void QgsMapLayer::setAutoRefreshInterval( int interval )
{
if ( interval <= 0 )
{
mRefreshTimer.stop();
mRefreshTimer.setInterval( 0 );
mRefreshTimer->stop();
mRefreshTimer->setInterval( 0 );
}
else
{
mRefreshTimer.setInterval( interval );
mRefreshTimer->setInterval( interval );
}
emit autoRefreshIntervalChanged( mRefreshTimer.isActive() ? mRefreshTimer.interval() : 0 );
emit autoRefreshIntervalChanged( mRefreshTimer->isActive() ? mRefreshTimer->interval() : 0 );
}

void QgsMapLayer::setAutoRefreshEnabled( bool enabled )
{
if ( !enabled )
mRefreshTimer.stop();
else if ( mRefreshTimer.interval() > 0 )
mRefreshTimer.start();
mRefreshTimer->stop();
else if ( mRefreshTimer->interval() > 0 )
mRefreshTimer->start();

emit autoRefreshIntervalChanged( mRefreshTimer.isActive() ? mRefreshTimer.interval() : 0 );
emit autoRefreshIntervalChanged( mRefreshTimer->isActive() ? mRefreshTimer->interval() : 0 );
}

const QgsLayerMetadata &QgsMapLayer::metadata() const
@@ -1824,7 +1820,6 @@ void QgsMapLayer::writeCommonStyle( QDomElement &layerElement, QDomDocument &doc
}
}


void QgsMapLayer::readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context )
{
QgsAbstract3DRenderer *r3D = nullptr;
@@ -1841,18 +1836,16 @@ void QgsMapLayer::readCommonStyle( const QDomElement &layerElement, const QgsRea
setRenderer3D( r3D );
}


QUndoStack *QgsMapLayer::undoStack()
{
return &mUndoStack;
return mUndoStack;
}

QUndoStack *QgsMapLayer::undoStackStyles()
{
return &mUndoStackStyles;
return mUndoStackStyles;
}


QStringList QgsMapLayer::customPropertyKeys() const
{
return mCustomProperties.keys();
@@ -1304,17 +1304,19 @@ class CORE_EXPORT QgsMapLayer : public QObject
//! Tag for embedding additional information
QString mTag;

//set some generous defaults for scale based visibility

//! Minimum scale denominator at which this layer should be displayed
double mMinScale;
double mMinScale = 0;
//! Maximum scale denominator at which this layer should be displayed
double mMaxScale;
double mMaxScale = 100000000;
//! A flag that tells us whether to use the above vars to restrict layer visibility
bool mScaleBasedVisibility;
bool mScaleBasedVisibility = false;

//! Collection of undoable operations for this layer. *
QUndoStack mUndoStack;
QUndoStack *mUndoStack = nullptr;

QUndoStack mUndoStackStyles;
QUndoStack *mUndoStackStyles = nullptr;

//! Layer's persistent storage of additional properties (may be used by plugins)
QgsObjectCustomProperties mCustomProperties;
@@ -1326,7 +1328,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
QgsMapLayerStyleManager *mStyleManager = nullptr;

//! Timer for triggering automatic refreshes of the layer
QTimer mRefreshTimer;
QTimer *mRefreshTimer = nullptr;

QgsLayerMetadata mMetadata;

0 comments on commit bc23f1d

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