Skip to content

Commit 7433d32

Browse files
committed
[Style Dock] Add interface for plugins to add panels to dock
1 parent a8a2246 commit 7433d32

13 files changed

+376
-117
lines changed

python/gui/gui.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
%Include qgsmaptoolpan.sip
119119
%Include qgsmaptooltouch.sip
120120
%Include qgsmaptoolzoom.sip
121+
%Include qgsmapstylepanel.sip
121122
%Include qgsmessagebar.sip
122123
%Include qgsmessagebaritem.sip
123124
%Include qgsmessagelogviewer.sip

python/gui/qgisinterface.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,12 @@ class QgisInterface : QObject
292292
*/
293293
virtual void unregisterMapLayerPropertiesFactory( QgsMapLayerPropertiesFactory* factory ) = 0;
294294

295+
/** Register a new tab in the layer properties dialog */
296+
virtual void registerMapStylePanelFactory( QgsMapStylePanelFactory* factory ) = 0;
297+
298+
/** Unregister a previously registered tab in the layer properties dialog */
299+
virtual void unregisterMapStylePanelFactory( QgsMapStylePanelFactory* factory ) = 0;
300+
295301
// @todo is this deprecated in favour of QgsContextHelp?
296302
/** Open a url in the users browser. By default the QGIS doc directory is used
297303
* as the base for the URL. To open a URL that is not relative to the installed

python/gui/qgsmapstylepanel.sip

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/** \ingroup gui
2+
* \class A panel widget that can be shown in the map style dock
3+
* \note added in QGIS 2.16
4+
*/
5+
class QgsMapStylePanel : public QWidget
6+
{
7+
%TypeHeaderCode
8+
#include <qgsmapstylepanel.h>
9+
%End
10+
public:
11+
/**
12+
* @brief A panel widget that can be shown in the map style dock
13+
* @param layer The layer active in the dock.
14+
* @param canvas The canvas object.
15+
* @param parent The parent of the widget.
16+
* @note The widget is created each time the panel is selected in the dock.
17+
* Keep the loading light as possible for speed in the UI.
18+
*/
19+
QgsMapStylePanel(QgsMapLayer* layer, QgsMapCanvas *canvas, QWidget *parent = 0);
20+
21+
signals:
22+
/**
23+
* @brief Nofity the map style dock that something has changed and
24+
* we need to update the map.
25+
* You should emit this when any of the widgets are changed if live
26+
* update is enabled apply() will get called to apply the changes to the layer.
27+
*/
28+
void widgetChanged();
29+
30+
public slots:
31+
32+
/**
33+
* @brief Called when changes to the layer need to be made.
34+
* Will be called when live update is enabled.
35+
*/
36+
virtual void apply() = 0;
37+
};
38+
39+
40+
/** \ingroup gui
41+
* \class QgsMapStylePanelFactory
42+
* \note added in QGIS 2.16
43+
*/
44+
class QgsMapStylePanelFactory
45+
{
46+
%TypeHeaderCode
47+
#include <qgsmapstylepanel.h>
48+
%End
49+
public:
50+
/** Constructor */
51+
QgsMapStylePanelFactory();
52+
53+
/** Destructor */
54+
virtual ~QgsMapStylePanelFactory();
55+
56+
/**
57+
* @brief The icon that will be shown in the UI for the panel.
58+
* @return A QIcon for the panel icon.
59+
*/
60+
virtual QIcon icon() = 0;
61+
62+
/**
63+
* @brief The title of the panel..
64+
* @note This may or may not be shown to the user.
65+
* @return Title of the panel
66+
*/
67+
virtual QString title() = 0;
68+
69+
/**
70+
* @brief Supported layer type for the widget.
71+
* @return The layer type this widget is supported for.
72+
*/
73+
virtual QgsMapLayer::LayerType layerType() = 0;
74+
75+
/**
76+
* @brief Factory fucntion to create the widget on demand as needed by the dock.
77+
* @note This function is called each time the panel is selected. Keep it light for better UX.
78+
* @param layer The active layer in the dock.
79+
* @param canvas The map canvas.
80+
* @param parent The parent of the widget.
81+
* @return A new QgsMapStylePanel which is shown in the map style dock.
82+
*/
83+
virtual QgsMapStylePanel* createPanel( QgsMapLayer* layer, QgsMapCanvas *canvas, QWidget* parent /TransferThis/ ) = 0 /Factory/;
84+
};

src/app/qgisapp.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
732732
mMapStylingDock = new QDockWidget( this );
733733
mMapStylingDock->setWindowTitle( tr( "Map Styling" ) );
734734
mMapStylingDock->setObjectName( "MapStyling" );
735-
mMapStyleWidget = new QgsMapStylingWidget( mMapCanvas );
735+
mMapStyleWidget = new QgsMapStylingWidget( mMapCanvas, mMapStylePanelFactories );
736736
mMapStylingDock->setWidget( mMapStyleWidget );
737737
connect( mMapStyleWidget, SIGNAL( styleChanged( QgsMapLayer* ) ), this, SLOT( updateLabelToolButtons() ) );
738738
// connect( mMapStylingDock, SIGNAL( visibilityChanged( bool ) ), mActionStyleDock, SLOT( setChecked( bool ) ) );
@@ -5599,7 +5599,11 @@ void QgisApp::setMapStyleDockLayer( QgsMapLayer* layer )
55995599
// We don't set the layer if the dock isn't open mainly to save
56005600
// the extra work if it's not needed
56015601
if ( mMapStylingDock->isVisible() )
5602+
{
5603+
mMapStyleWidget->setPageFactories( mMapStylePanelFactories );
56025604
mMapStyleWidget->setLayer( layer );
5605+
5606+
}
56035607
}
56045608

56055609
void QgisApp::mapStyleDock( bool enabled )
@@ -8836,6 +8840,16 @@ void QgisApp::unregisterMapLayerPropertiesFactory( QgsMapLayerPropertiesFactory*
88368840
mMapLayerPropertiesFactories.removeAll( factory );
88378841
}
88388842

8843+
void QgisApp::registerMapStylePanelFactory(QgsMapStylePanelFactory *factory)
8844+
{
8845+
mMapStylePanelFactories << factory;
8846+
}
8847+
8848+
void QgisApp::unregisterMapStylePanelFactory(QgsMapStylePanelFactory *factory)
8849+
{
8850+
mMapStylePanelFactories.removeAll( factory );
8851+
}
8852+
88398853
/** Get a pointer to the currently selected map layer */
88408854
QgsMapLayer *QgisApp::activeLayer()
88418855
{

src/app/qgisapp.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class QgsLayerTreeView;
5757
class QgsMapCanvas;
5858
class QgsMapLayer;
5959
class QgsMapLayerPropertiesFactory;
60+
class QgsMapStylePanelFactory;
6061
class QgsMapTip;
6162
class QgsMapTool;
6263
class QgsMapToolAdvancedDigitizing;
@@ -508,6 +509,12 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
508509
/** Unregister a previously registered tab in the layer properties dialog */
509510
void unregisterMapLayerPropertiesFactory( QgsMapLayerPropertiesFactory* factory );
510511

512+
/** Register a new tab in the layer properties dialog */
513+
void registerMapStylePanelFactory( QgsMapStylePanelFactory* factory );
514+
515+
/** Unregister a previously registered tab in the layer properties dialog */
516+
void unregisterMapStylePanelFactory( QgsMapStylePanelFactory* factory );
517+
511518
public slots:
512519
void layerTreeViewDoubleClicked( const QModelIndex& index );
513520
//! Make sure the insertion point for new layers is up-to-date with the current item in layer tree view
@@ -1753,6 +1760,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
17531760
QgsSnappingUtils* mSnappingUtils;
17541761

17551762
QList<QgsMapLayerPropertiesFactory*> mMapLayerPropertiesFactories;
1763+
QList<QgsMapStylePanelFactory*> mMapStylePanelFactories;
17561764

17571765
QDateTime mProjectLastModified;
17581766

src/app/qgisappinterface.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,16 @@ void QgisAppInterface::unregisterMapLayerPropertiesFactory( QgsMapLayerPropertie
485485
qgis->unregisterMapLayerPropertiesFactory( factory );
486486
}
487487

488+
void QgisAppInterface::registerMapStylePanelFactory(QgsMapStylePanelFactory *factory)
489+
{
490+
qgis->registerMapStylePanelFactory( factory );
491+
}
492+
493+
void QgisAppInterface::unregisterMapStylePanelFactory(QgsMapStylePanelFactory *factory)
494+
{
495+
qgis->unregisterMapStylePanelFactory( factory );
496+
}
497+
488498
//! Menus
489499
Q_DECL_DEPRECATED QMenu *QgisAppInterface::fileMenu() { return qgis->projectMenu(); }
490500
QMenu *QgisAppInterface::projectMenu() { return qgis->projectMenu(); }

src/app/qgisappinterface.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
301301
*/
302302
virtual void unregisterMapLayerPropertiesFactory( QgsMapLayerPropertiesFactory* factory ) override;
303303

304+
/** Register a new tab in the layer properties dialog */
305+
virtual void registerMapStylePanelFactory( QgsMapStylePanelFactory* factory ) override;
306+
307+
/** Unregister a previously registered tab in the layer properties dialog */
308+
virtual void unregisterMapStylePanelFactory( QgsMapStylePanelFactory* factory ) override;
309+
304310
/** Accessors for inserting items into menus and toolbars.
305311
* An item can be inserted before any existing action.
306312
*/

0 commit comments

Comments
 (0)