Skip to content
Permalink
Browse files

Add method to interface to close map canvases

  • Loading branch information
nyalldawson committed Mar 14, 2017
1 parent 57637ca commit 2d37ca9bd95f46791b5195df126ccca60e2791d5
@@ -62,6 +62,8 @@ class QgisInterface : QObject

virtual QgsMapCanvas* createNewMapCanvas( const QString& name ) = 0;

virtual void closeMapCanvas( const QString &name ) = 0;

public slots:


@@ -3176,6 +3176,19 @@ QgsMapCanvas *QgisApp::createNewMapCanvas( const QString &name, bool isFloating,
return mapCanvas;
}

void QgisApp::closeMapCanvas( const QString &name )
{
Q_FOREACH ( QgsMapCanvasDockWidget *w, findChildren< QgsMapCanvasDockWidget * >() )
{
if ( w->mapCanvas()->objectName() == name )
{
w->close();
delete w;
break;
}
}
}

void QgisApp::closeAdditionalMapCanvases()
{
freezeCanvases( true ); // closing docks may cause canvases to resize, and we don't want a map refresh occurring
@@ -245,6 +245,11 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
bool synced = false, bool showCursor = true, bool scaleSynced = false,
double scaleFactor = 1.0 );

/**
* Closes the additional map canvas with matching \a name.
*/
void closeMapCanvas( const QString &name );

/**
* Closes any additional map canvases. The main map canvas will not
* be affected.
@@ -341,6 +341,11 @@ QgsMapCanvas *QgisAppInterface::createNewMapCanvas( const QString &name )
return qgis->createNewMapCanvas( name );
}

void QgisAppInterface::closeMapCanvas( const QString &name )
{
qgis->closeMapCanvas( name );
}

QgsLayerTreeMapCanvasBridge *QgisAppInterface::layerTreeCanvasBridge()
{
return qgis->layerTreeCanvasBridge();
@@ -181,6 +181,7 @@ class APP_EXPORT QgisAppInterface : public QgisInterface

QList< QgsMapCanvas * > mapCanvases() override;
QgsMapCanvas *createNewMapCanvas( const QString &name ) override;
virtual void closeMapCanvas( const QString &name ) override;

/**
* Returns a pointer to the layer tree canvas bridge
@@ -113,9 +113,17 @@ class GUI_EXPORT QgisInterface : public QObject
/**
* Create a new map canvas with the specified unique \a name.
* @note added in QGIS 3.0
* @see closeMapCanvas()
*/
virtual QgsMapCanvas *createNewMapCanvas( const QString &name ) = 0;

/**
* Closes the additional map canvas with matching \a name.
* @note added in QGIS 3.0
* @see createNewMapCanvas()
*/
virtual void closeMapCanvas( const QString &name ) = 0;

public slots: // TODO: do these functions really need to be slots?

/* Exposed functions */

0 comments on commit 2d37ca9

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