Skip to content
Permalink
Browse files

[Style Dock] Add interface for plugins to add panels to dock

  • Loading branch information
NathanW2 committed Jun 2, 2016
1 parent a8a2246 commit 7433d32e8741994c703540f790b32f4425f6dca9
@@ -118,6 +118,7 @@
%Include qgsmaptoolpan.sip
%Include qgsmaptooltouch.sip
%Include qgsmaptoolzoom.sip
%Include qgsmapstylepanel.sip
%Include qgsmessagebar.sip
%Include qgsmessagebaritem.sip
%Include qgsmessagelogviewer.sip
@@ -292,6 +292,12 @@ class QgisInterface : QObject
*/
virtual void unregisterMapLayerPropertiesFactory( QgsMapLayerPropertiesFactory* factory ) = 0;

/** Register a new tab in the layer properties dialog */
virtual void registerMapStylePanelFactory( QgsMapStylePanelFactory* factory ) = 0;

/** Unregister a previously registered tab in the layer properties dialog */
virtual void unregisterMapStylePanelFactory( QgsMapStylePanelFactory* factory ) = 0;

// @todo is this deprecated in favour of QgsContextHelp?
/** Open a url in the users browser. By default the QGIS doc directory is used
* as the base for the URL. To open a URL that is not relative to the installed
@@ -0,0 +1,84 @@
/** \ingroup gui
* \class A panel widget that can be shown in the map style dock
* \note added in QGIS 2.16
*/
class QgsMapStylePanel : public QWidget
{
%TypeHeaderCode
#include <qgsmapstylepanel.h>
%End
public:
/**
* @brief A panel widget that can be shown in the map style dock
* @param layer The layer active in the dock.
* @param canvas The canvas object.
* @param parent The parent of the widget.
* @note The widget is created each time the panel is selected in the dock.
* Keep the loading light as possible for speed in the UI.
*/
QgsMapStylePanel(QgsMapLayer* layer, QgsMapCanvas *canvas, QWidget *parent = 0);

signals:
/**
* @brief Nofity the map style dock that something has changed and
* we need to update the map.
* You should emit this when any of the widgets are changed if live
* update is enabled apply() will get called to apply the changes to the layer.
*/
void widgetChanged();

public slots:

/**
* @brief Called when changes to the layer need to be made.
* Will be called when live update is enabled.
*/
virtual void apply() = 0;
};


/** \ingroup gui
* \class QgsMapStylePanelFactory
* \note added in QGIS 2.16
*/
class QgsMapStylePanelFactory
{
%TypeHeaderCode
#include <qgsmapstylepanel.h>
%End
public:
/** Constructor */
QgsMapStylePanelFactory();

/** Destructor */
virtual ~QgsMapStylePanelFactory();

/**
* @brief The icon that will be shown in the UI for the panel.
* @return A QIcon for the panel icon.
*/
virtual QIcon icon() = 0;

/**
* @brief The title of the panel..
* @note This may or may not be shown to the user.
* @return Title of the panel
*/
virtual QString title() = 0;

/**
* @brief Supported layer type for the widget.
* @return The layer type this widget is supported for.
*/
virtual QgsMapLayer::LayerType layerType() = 0;

/**
* @brief Factory fucntion to create the widget on demand as needed by the dock.
* @note This function is called each time the panel is selected. Keep it light for better UX.
* @param layer The active layer in the dock.
* @param canvas The map canvas.
* @param parent The parent of the widget.
* @return A new QgsMapStylePanel which is shown in the map style dock.
*/
virtual QgsMapStylePanel* createPanel( QgsMapLayer* layer, QgsMapCanvas *canvas, QWidget* parent /TransferThis/ ) = 0 /Factory/;
};
@@ -732,7 +732,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
mMapStylingDock = new QDockWidget( this );
mMapStylingDock->setWindowTitle( tr( "Map Styling" ) );
mMapStylingDock->setObjectName( "MapStyling" );
mMapStyleWidget = new QgsMapStylingWidget( mMapCanvas );
mMapStyleWidget = new QgsMapStylingWidget( mMapCanvas, mMapStylePanelFactories );
mMapStylingDock->setWidget( mMapStyleWidget );
connect( mMapStyleWidget, SIGNAL( styleChanged( QgsMapLayer* ) ), this, SLOT( updateLabelToolButtons() ) );
// connect( mMapStylingDock, SIGNAL( visibilityChanged( bool ) ), mActionStyleDock, SLOT( setChecked( bool ) ) );
@@ -5599,7 +5599,11 @@ void QgisApp::setMapStyleDockLayer( QgsMapLayer* layer )
// We don't set the layer if the dock isn't open mainly to save
// the extra work if it's not needed
if ( mMapStylingDock->isVisible() )
{
mMapStyleWidget->setPageFactories( mMapStylePanelFactories );
mMapStyleWidget->setLayer( layer );

}
}

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

void QgisApp::registerMapStylePanelFactory(QgsMapStylePanelFactory *factory)
{
mMapStylePanelFactories << factory;
}

void QgisApp::unregisterMapStylePanelFactory(QgsMapStylePanelFactory *factory)
{
mMapStylePanelFactories.removeAll( factory );
}

/** Get a pointer to the currently selected map layer */
QgsMapLayer *QgisApp::activeLayer()
{
@@ -57,6 +57,7 @@ class QgsLayerTreeView;
class QgsMapCanvas;
class QgsMapLayer;
class QgsMapLayerPropertiesFactory;
class QgsMapStylePanelFactory;
class QgsMapTip;
class QgsMapTool;
class QgsMapToolAdvancedDigitizing;
@@ -508,6 +509,12 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
/** Unregister a previously registered tab in the layer properties dialog */
void unregisterMapLayerPropertiesFactory( QgsMapLayerPropertiesFactory* factory );

/** Register a new tab in the layer properties dialog */
void registerMapStylePanelFactory( QgsMapStylePanelFactory* factory );

/** Unregister a previously registered tab in the layer properties dialog */
void unregisterMapStylePanelFactory( QgsMapStylePanelFactory* factory );

public slots:
void layerTreeViewDoubleClicked( const QModelIndex& index );
//! 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
QgsSnappingUtils* mSnappingUtils;

QList<QgsMapLayerPropertiesFactory*> mMapLayerPropertiesFactories;
QList<QgsMapStylePanelFactory*> mMapStylePanelFactories;

QDateTime mProjectLastModified;

@@ -485,6 +485,16 @@ void QgisAppInterface::unregisterMapLayerPropertiesFactory( QgsMapLayerPropertie
qgis->unregisterMapLayerPropertiesFactory( factory );
}

void QgisAppInterface::registerMapStylePanelFactory(QgsMapStylePanelFactory *factory)
{
qgis->registerMapStylePanelFactory( factory );
}

void QgisAppInterface::unregisterMapStylePanelFactory(QgsMapStylePanelFactory *factory)
{
qgis->unregisterMapStylePanelFactory( factory );
}

//! Menus
Q_DECL_DEPRECATED QMenu *QgisAppInterface::fileMenu() { return qgis->projectMenu(); }
QMenu *QgisAppInterface::projectMenu() { return qgis->projectMenu(); }
@@ -301,6 +301,12 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
*/
virtual void unregisterMapLayerPropertiesFactory( QgsMapLayerPropertiesFactory* factory ) override;

/** Register a new tab in the layer properties dialog */
virtual void registerMapStylePanelFactory( QgsMapStylePanelFactory* factory ) override;

/** Unregister a previously registered tab in the layer properties dialog */
virtual void unregisterMapStylePanelFactory( QgsMapStylePanelFactory* factory ) override;

/** Accessors for inserting items into menus and toolbars.
* An item can be inserted before any existing action.
*/

0 comments on commit 7433d32

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