Skip to content

Commit

Permalink
Add iface.layerTreeCanvasBridge()
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jul 26, 2015
1 parent 4984cae commit 70fe622
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
3 changes: 3 additions & 0 deletions python/gui/qgisinterface.sip
Expand Up @@ -159,6 +159,9 @@ class QgisInterface : QObject
/** Return a pointer to the map canvas */
virtual QgsMapCanvas * mapCanvas() = 0;

/** Returns a pointer to the layer tree canvas bridge */
virtual QgsLayerTreeMapCanvasBridge* layerTreeCanvasBridge() = 0;

/** Return a pointer to the main window (instance of QgisApp in case of QGIS) */
virtual QWidget * mainWindow() = 0;

Expand Down
5 changes: 5 additions & 0 deletions src/app/qgisappinterface.cpp
Expand Up @@ -311,6 +311,11 @@ QgsMapCanvas * QgisAppInterface::mapCanvas()
return qgis->mapCanvas();
}

QgsLayerTreeMapCanvasBridge* QgisAppInterface::layerTreeCanvasBridge()
{
return qgis->layerTreeCanvasBridge();
}

QWidget * QgisAppInterface::mainWindow()
{
return qgis;
Expand Down
13 changes: 10 additions & 3 deletions src/app/qgisappinterface.h
Expand Up @@ -168,6 +168,13 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
/** Return a pointer to the map canvas used by qgisapp */
QgsMapCanvas * mapCanvas() override;

/**
* Returns a pointer to the layer tree canvas bridge
*
* @note added in 2.12
*/
QgsLayerTreeMapCanvasBridge* layerTreeCanvasBridge() override;

/** Gives access to main QgisApp object
Plugins don't need to know about QgisApp, as we pass it as QWidget,
Expand Down Expand Up @@ -243,7 +250,7 @@ class APP_EXPORT QgisAppInterface : public QgisInterface

/** Add "add layer" action to the layer menu */
void insertAddLayerAction( QAction *action ) override;
/** remove "add layer" action from the layer menu */
/** Remove "add layer" action from the layer menu */
void removeAddLayerAction( QAction *action ) override;

/** Add a dock widget to the main window */
Expand All @@ -252,12 +259,12 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
/** Remove specified dock widget from main window (doesn't delete it). */
void removeDockWidget( QDockWidget * dockwidget ) override;

/** show layer properties dialog for layer
/** Show layer properties dialog for layer
* @param l layer to show properties table for
*/
virtual void showLayerProperties( QgsMapLayer *l ) override;

/** show layer attribute dialog for layer
/** Show layer attribute dialog for layer
* @param l layer to show attribute table for
*/
virtual void showAttributeTable( QgsVectorLayer *l ) override;
Expand Down
18 changes: 13 additions & 5 deletions src/gui/qgisinterface.h
Expand Up @@ -28,6 +28,7 @@ class QWidget;
class QgsAttributeDialog;
class QgsComposerView;
class QgsFeature;
class QgsLayerTreeMapCanvasBridge;
class QgsLayerTreeView;
class QgsLegendInterface;
class QgsMapCanvas;
Expand Down Expand Up @@ -205,6 +206,13 @@ class GUI_EXPORT QgisInterface : public QObject
/** Return a pointer to the map canvas */
virtual QgsMapCanvas * mapCanvas() = 0;

/**
* Returns a pointer to the layer tree canvas bridge
*
* @note added in 2.12
*/
virtual QgsLayerTreeMapCanvasBridge* layerTreeCanvasBridge() = 0;

/** Return a pointer to the main window (instance of QgisApp in case of QGIS) */
virtual QWidget * mainWindow() = 0;

Expand Down Expand Up @@ -291,10 +299,10 @@ class GUI_EXPORT QgisInterface : public QObject
/** Remove specified dock widget from main window (doesn't delete it). */
virtual void removeDockWidget( QDockWidget * dockwidget ) = 0;

/** open layer properties dialog */
/** Open layer properties dialog */
virtual void showLayerProperties( QgsMapLayer *l ) = 0;

/** open attribute table dialog */
/** Open attribute table dialog */
virtual void showAttributeTable( QgsVectorLayer *l ) = 0;

/** Add window to Window menu. The action title is the window title
Expand Down Expand Up @@ -568,14 +576,14 @@ class GUI_EXPORT QgisInterface : public QObject
* This signal is emitted when the initialization is complete
*/
void initializationCompleted();
/** emitted when a project file is successfully read
/** Emitted when a project file is successfully read
@note
This is useful for plug-ins that store properties with project files. A
plug-in can connect to this signal. When it is emitted, the plug-in
knows to then check the project properties for any relevant state.
*/
void projectRead();
/** emitted when starting an entirely new project
/** Emitted when starting an entirely new project
@note
This is similar to projectRead(); plug-ins might want to be notified
that they're in a new project. Yes, projectRead() could have been
Expand All @@ -585,7 +593,7 @@ class GUI_EXPORT QgisInterface : public QObject
*/
void newProjectCreated();

/**This signal is emitted when a layer has been saved using save as
/** This signal is emitted when a layer has been saved using save as
@note
added in version 2.7
*/
Expand Down

5 comments on commit 70fe622

@elpaso
Copy link
Contributor

@elpaso elpaso commented on 70fe622 Jul 28, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-kuhn can you please check that the manual example using the bridge is still valid? https://github.com/qgis/QGIS-Documentation/blob/master/source/docs/pyqgis_developer_cookbook/loadproject.rst#id21

@m-kuhn
Copy link
Member Author

@m-kuhn m-kuhn commented on 70fe622 Jul 28, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elpaso
Copy link
Contributor

@elpaso elpaso commented on 70fe622 Jul 28, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That part of the cookbook is not specific to standalone (look at the bridge example at the end of the page), anyway maybe worth adding that new iface method to the cookbook (possibly with a short example).

Generally speaking, I believe that when something is added to iface or to the bindings, it should be documented in the cookbook.

@m-kuhn
Copy link
Member Author

@m-kuhn m-kuhn commented on 70fe622 Jul 28, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked and the bridge example at the end of the page looks a bit odd to me.
A simple QgsProject.instance().read('test.qgs') works perfectly. fine, I don't see a reason why the bridge is required. (I left a comment there)

From my point of view:
The only reason for using an own bridge I have come across so far is for a standalone applicaiton.
Within the Qgis app it makes sense to use the one bridge which is created by Qgis itself (e.g. to synchronize the state between the layer rendering order widget and the map canvas layer rendering order).

@elpaso
Copy link
Contributor

@elpaso elpaso commented on 70fe622 Jul 28, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-kuhn , you are right, in master it's not needed, I don't remember if I added it while testing on an older version or if I messed up something while testing a long chain of commands.

Since you know very well how that part of the code works (or is supposed to work) It would be awesome if you could fix that part of the cookbook and add a short example/use case for the new iface.layerTreeCanvasBridge

Please sign in to comment.