Skip to content

Commit

Permalink
use signals to mark project dirty when canvas layer or extents change (
Browse files Browse the repository at this point in the history
…fixes #943)

git-svn-id: http://svn.osgeo.org/qgis/trunk@12926 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Feb 11, 2010
1 parent 91ad1ec commit b1e241a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 49 deletions.
8 changes: 2 additions & 6 deletions src/app/legend/qgslegend.cpp
Expand Up @@ -161,6 +161,8 @@ void QgsLegend::selectAll( bool select )


// Turn on rendering (if it was on previously) // Turn on rendering (if it was on previously)
mMapCanvas->setRenderFlag( renderFlagState ); mMapCanvas->setRenderFlag( renderFlagState );

QgsProject::instance()->dirty( true );
} }


void QgsLegend::removeGroup( int groupIndex ) void QgsLegend::removeGroup( int groupIndex )
Expand Down Expand Up @@ -1619,9 +1621,6 @@ void QgsLegend::legendLayerZoom()
//zoom to bounding box //zoom to bounding box
mMapCanvas->setExtent( extent ); mMapCanvas->setExtent( extent );
mMapCanvas->refresh(); mMapCanvas->refresh();

// notify the project we've made a change
QgsProject::instance()->dirty( true );
} }


void QgsLegend::legendLayerZoomNative() void QgsLegend::legendLayerZoomNative()
Expand All @@ -1641,9 +1640,6 @@ void QgsLegend::legendLayerZoomNative()
mMapCanvas->refresh(); mMapCanvas->refresh();


QgsDebugMsg( "MapUnitsPerPixel after : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) ); QgsDebugMsg( "MapUnitsPerPixel after : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) );

// notify the project we've made a change
QgsProject::instance()->dirty( true );
} }
} }


Expand Down
57 changes: 14 additions & 43 deletions src/app/qgisapp.cpp
Expand Up @@ -1831,6 +1831,10 @@ void QgisApp::setupConnections()
connect( mMapCanvas, SIGNAL( selectionChanged( QgsMapLayer * ) ), connect( mMapCanvas, SIGNAL( selectionChanged( QgsMapLayer * ) ),
this, SLOT( activateDeactivateLayerRelatedActions( QgsMapLayer * ) ) ); this, SLOT( activateDeactivateLayerRelatedActions( QgsMapLayer * ) ) );


// track of canvas layers and extents and mark project dirty on changes
connect( mMapCanvas, SIGNAL( extentsChanged() ), this, SLOT( markDirty() ) );
connect( mMapCanvas, SIGNAL( layersChanged() ), this, SLOT( markDirty() ) );

connect( mRenderSuppressionCBox, SIGNAL( toggled( bool ) ), mMapCanvas, SLOT( setRenderFlag( bool ) ) ); connect( mRenderSuppressionCBox, SIGNAL( toggled( bool ) ), mMapCanvas, SLOT( setRenderFlag( bool ) ) );
// //
// Do we really need this ??? - its already connected to the esc key...TS // Do we really need this ??? - its already connected to the esc key...TS
Expand Down Expand Up @@ -2397,8 +2401,6 @@ bool QgisApp::addVectorLayers( QStringList const & theLayerQStringList, const QS
layer->setLayerName( elements.at( 1 ) ); layer->setLayerName( elements.at( 1 ) );
// Register this layer with the layers registry // Register this layer with the layers registry
QgsMapLayerRegistry::instance()->addMapLayer( layer ); QgsMapLayerRegistry::instance()->addMapLayer( layer );
// notify the project we've made a change
QgsProject::instance()->dirty( true );
} }
} }
else else
Expand Down Expand Up @@ -2553,8 +2555,6 @@ void QgisApp::addDatabaseLayer()
{ {
// register this layer with the central layers registry // register this layer with the central layers registry
QgsMapLayerRegistry::instance()->addMapLayer( layer ); QgsMapLayerRegistry::instance()->addMapLayer( layer );
// notify the project we've made a change
QgsProject::instance()->dirty( true );
} }
else else
{ {
Expand Down Expand Up @@ -2635,8 +2635,6 @@ void QgisApp::addSpatiaLiteLayer()
{ {
// register this layer with the central layers registry // register this layer with the central layers registry
QgsMapLayerRegistry::instance()->addMapLayer( layer ); QgsMapLayerRegistry::instance()->addMapLayer( layer );
// notify the project we've made a change
QgsProject::instance()->dirty( true );
} }
else else
{ {
Expand Down Expand Up @@ -3362,8 +3360,7 @@ void QgisApp::addAllToOverview()
mMapLegend->enableOverviewModeAllLayers( true ); mMapLegend->enableOverviewModeAllLayers( true );
} }


// notify the project we've made a change markDirty();
QgsProject::instance()->dirty( true );
} }


//reimplements method from base (gui) class //reimplements method from base (gui) class
Expand All @@ -3374,8 +3371,7 @@ void QgisApp::removeAllFromOverview()
mMapLegend->enableOverviewModeAllLayers( false ); mMapLegend->enableOverviewModeAllLayers( false );
} }


// notify the project we've made a change markDirty();
QgsProject::instance()->dirty( true );
} }


void QgisApp::toggleFullScreen() void QgisApp::toggleFullScreen()
Expand Down Expand Up @@ -3506,26 +3502,17 @@ void QgisApp::zoomIn()
QgsDebugMsg( "Setting map tool to zoomIn" ); QgsDebugMsg( "Setting map tool to zoomIn" );


mMapCanvas->setMapTool( mMapTools.mZoomIn ); mMapCanvas->setMapTool( mMapTools.mZoomIn );

// notify the project we've made a change
QgsProject::instance()->dirty( true );
} }




void QgisApp::zoomOut() void QgisApp::zoomOut()
{ {
mMapCanvas->setMapTool( mMapTools.mZoomOut ); mMapCanvas->setMapTool( mMapTools.mZoomOut );

// notify the project we've made a change
QgsProject::instance()->dirty( true );
} }


void QgisApp::zoomToSelected() void QgisApp::zoomToSelected()
{ {
mMapCanvas->zoomToSelected(); mMapCanvas->zoomToSelected();

// notify the project we've made a change
QgsProject::instance()->dirty( true );
} }


void QgisApp::pan() void QgisApp::pan()
Expand All @@ -3536,25 +3523,16 @@ void QgisApp::pan()
void QgisApp::zoomFull() void QgisApp::zoomFull()
{ {
mMapCanvas->zoomToFullExtent(); mMapCanvas->zoomToFullExtent();
// notify the project we've made a change
QgsProject::instance()->dirty( true );

} }


void QgisApp::zoomToPrevious() void QgisApp::zoomToPrevious()
{ {
mMapCanvas->zoomToPreviousExtent(); mMapCanvas->zoomToPreviousExtent();
// notify the project we've made a change
QgsProject::instance()->dirty( true );

} }


void QgisApp::zoomToNext() void QgisApp::zoomToNext()
{ {
mMapCanvas->zoomToNextExtent(); mMapCanvas->zoomToNextExtent();
// notify the project we've made a change
QgsProject::instance()->dirty( true );

} }


void QgisApp::zoomActualSize() void QgisApp::zoomActualSize()
Expand Down Expand Up @@ -3668,8 +3646,6 @@ void QgisApp::deleteSelected( QgsMapLayer *layer )
} }


vlayer->endEditCommand(); vlayer->endEditCommand();
// notify the project we've made a change
QgsProject::instance()->dirty( true );
} }


void QgisApp::moveFeature() void QgisApp::moveFeature()
Expand Down Expand Up @@ -4396,8 +4372,6 @@ void QgisApp::isInOverview()
void QgisApp::removeLayer() void QgisApp::removeLayer()
{ {
mMapLegend->removeCurrentLayer(); mMapLegend->removeCurrentLayer();
// notify the project we've made a change
QgsProject::instance()->dirty( true );
} }




Expand All @@ -4420,8 +4394,6 @@ void QgisApp::removeAllLayers()
} }


mMapCanvas->refresh(); mMapCanvas->refresh();
// notify the project we've made a change
QgsProject::instance()->dirty( true );
} //remove all layers } //remove all layers


void QgisApp::showGpsTool() void QgisApp::showGpsTool()
Expand Down Expand Up @@ -4783,9 +4755,6 @@ QgsVectorLayer* QgisApp::addVectorLayer( QString vectorLayerPath, QString baseNa
{ {
// Register this layer with the layers registry // Register this layer with the layers registry
QgsMapLayerRegistry::instance()->addMapLayer( layer ); QgsMapLayerRegistry::instance()->addMapLayer( layer );
// notify the project we've made a change
QgsProject::instance()->dirty( true );

statusBar()->showMessage( mMapCanvas->extent().toString( 2 ) ); statusBar()->showMessage( mMapCanvas->extent().toString( 2 ) );


} }
Expand Down Expand Up @@ -4830,9 +4799,6 @@ void QgisApp::addMapLayer( QgsMapLayer *theMapLayer )
// not necessary since adding to registry adds to canvas mMapCanvas->addLayer(theMapLayer); // not necessary since adding to registry adds to canvas mMapCanvas->addLayer(theMapLayer);


statusBar()->showMessage( mMapCanvas->extent().toString( 2 ) ); statusBar()->showMessage( mMapCanvas->extent().toString( 2 ) );
// notify the project we've made a change
QgsProject::instance()->dirty( true );

} }
else else
{ {
Expand Down Expand Up @@ -4877,7 +4843,8 @@ bool QgisApp::saveDirty()
{ {
// flag project as dirty since dirty state of canvas is reset if "dirty" // flag project as dirty since dirty state of canvas is reset if "dirty"
// is based on a zoom or pan // is based on a zoom or pan
QgsProject::instance()->dirty( true ); markDirty();

// old code: mProjectIsDirtyFlag = true; // old code: mProjectIsDirtyFlag = true;


// prompt user to save // prompt user to save
Expand Down Expand Up @@ -5095,6 +5062,12 @@ void QgisApp::extentsViewToggled( bool theFlag )
} }
} }


void QgisApp::markDirty()
{
// notify the project that there was a change
QgsProject::instance()->dirty( true );
}

void QgisApp::showExtents() void QgisApp::showExtents()
{ {
if ( !mToggleExtentsViewButton->isChecked() ) if ( !mToggleExtentsViewButton->isChecked() )
Expand Down Expand Up @@ -5634,8 +5607,6 @@ bool QgisApp::addRasterLayer( QgsRasterLayer * theRasterLayer )
SIGNAL( statusChanged( QString ) ), SIGNAL( statusChanged( QString ) ),
this, this,
SLOT( showStatusMessage( QString ) ) ); SLOT( showStatusMessage( QString ) ) );
// notify the project we've made a change
QgsProject::instance()->dirty( true );


return true; return true;
} }
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -365,6 +365,9 @@ class QgisApp : public QMainWindow
//! Zoom to selected features //! Zoom to selected features
void zoomToSelected(); void zoomToSelected();


//! mark project dirty
void markDirty();

void updateUndoActions(); void updateUndoActions();


//! cuts selected features on the active layer to the clipboard //! cuts selected features on the active layer to the clipboard
Expand Down

0 comments on commit b1e241a

Please sign in to comment.