Skip to content
Permalink
Browse files
Add new class QgsMapLayerConfigWidgetContext
This class encapsulates the context in which a map layer config
widget is being shown (e.g. the corresponding map canvas, message
bar and other properties useful for the config widgets)
  • Loading branch information
nyalldawson committed Sep 7, 2021
1 parent fcbc243 commit 39263a421f6fdef56780ba342b4a6501758805d6
@@ -9,6 +9,68 @@



class QgsMapLayerConfigWidgetContext
{
%Docstring(signature="appended")
Encapsulates the context for a :py:class:`QgsMapLayerConfigWidget`.

.. versionadded:: 3.22
%End

%TypeHeaderCode
#include "qgsmaplayerconfigwidget.h"
%End
public:

QString annotationId() const;
%Docstring
Returns the item ID of the target annotation, when modifying
an annotation from a :py:class:`QgsAnnotationLayer`.

.. seealso:: :py:func:`setAnnotationId`
%End

void setAnnotationId( const QString &id );
%Docstring
Sets the item \id of the target annotation, when modifying
an annotation from a :py:class:`QgsAnnotationLayer`.

.. seealso:: :py:func:`annotationId`
%End

void setMapCanvas( QgsMapCanvas *canvas );
%Docstring
Sets the map ``canvas`` associated with the widget. This allows the widget to retrieve the current
map scale and other properties from the canvas.

.. seealso:: :py:func:`mapCanvas`
%End

QgsMapCanvas *mapCanvas() const;
%Docstring
Returns the map canvas associated with the widget.

.. seealso:: :py:func:`setMapCanvas`
%End

void setMessageBar( QgsMessageBar *bar );
%Docstring
Sets the message ``bar`` associated with the widget. This allows the widget to push feedback messages
to the appropriate message bar.

.. seealso:: :py:func:`messageBar`
%End

QgsMessageBar *messageBar() const;
%Docstring
Returns the message bar associated with the widget.

.. seealso:: :py:func:`setMessageBar`
%End

};


class QgsMapLayerConfigWidget : QgsPanelWidget
{
%Docstring(signature="appended")
@@ -50,6 +112,13 @@ be called for the layer after applying changes. This is ``True`` by default, but
Reset to original (vector layer) values

.. versionadded:: 3.14
%End

virtual void setContext( const QgsMapLayerConfigWidgetContext &context );
%Docstring
Sets the ``context`` under which the widget is being shown.

Subclasses should take care to call the base class implementation when overriding this method.
%End

public slots:
@@ -72,6 +72,9 @@ QgsLayerStylingWidget::QgsLayerStylingWidget( QgsMapCanvas *canvas, QgsMessageBa
{
setupUi( this );

mContext.setMapCanvas( canvas );
mContext.setMessageBar( messageBar );

mOptionsListWidget->setIconSize( QgisApp::instance()->iconSize( false ) );
mOptionsListWidget->setMaximumWidth( static_cast< int >( mOptionsListWidget->iconSize().width() * 1.18 ) );

@@ -442,6 +445,7 @@ void QgsLayerStylingWidget::updateCurrentWidgetLayer()
if ( panel )
{
panel->setDockMode( true );
panel->setContext( mContext );
connect( panel, &QgsPanelWidget::widgetChanged, this, &QgsLayerStylingWidget::autoApply );
mWidgetStack->setMainPanel( panel );
}
@@ -29,6 +29,7 @@

#include "ui_qgsmapstylingwidgetbase.h"
#include "qgsmaplayerconfigwidgetfactory.h"
#include "qgsmaplayerconfigwidget.h"
#include "qgis_app.h"

class QgsLabelingWidget;
@@ -157,6 +158,7 @@ class APP_EXPORT QgsLayerStylingWidget : public QWidget, private Ui::QgsLayerSty
QList<const QgsMapLayerConfigWidgetFactory *> mPageFactories;
QMap<int, const QgsMapLayerConfigWidgetFactory *> mUserPages;
QgsLayerStyleManagerWidgetFactory *mStyleManagerFactory = nullptr;
QgsMapLayerConfigWidgetContext mContext;
};

#endif // QGSLAYERSTYLESDOCK_H
@@ -22,3 +22,8 @@ QgsMapLayerConfigWidget::QgsMapLayerConfigWidget( QgsMapLayer *layer, QgsMapCanv
{

}

void QgsMapLayerConfigWidget::setContext( const QgsMapLayerConfigWidgetContext &context )
{
mContext = context;
}
@@ -23,6 +23,69 @@

class QgsMapCanvas;
class QgsMapLayer;
class QgsMessageBar;

/**
* \ingroup gui
* \class QgsMapLayerConfigWidgetContext
* \brief Encapsulates the context for a QgsMapLayerConfigWidget.
* \since QGIS 3.22
*/
class GUI_EXPORT QgsMapLayerConfigWidgetContext
{
public:

/**
* Returns the item ID of the target annotation, when modifying
* an annotation from a QgsAnnotationLayer.
*
* \see setAnnotationId()
*/
QString annotationId() const { return mAnnotationId; }

/**
* Sets the item \id of the target annotation, when modifying
* an annotation from a QgsAnnotationLayer.
*
* \see annotationId()
*/
void setAnnotationId( const QString &id ) { mAnnotationId = id; }

/**
* Sets the map \a canvas associated with the widget. This allows the widget to retrieve the current
* map scale and other properties from the canvas.
*
* \see mapCanvas()
*/
void setMapCanvas( QgsMapCanvas *canvas ) { mMapCanvas = canvas; }

/**
* Returns the map canvas associated with the widget.
* \see setMapCanvas()
*/
QgsMapCanvas *mapCanvas() const { return mMapCanvas; }

/**
* Sets the message \a bar associated with the widget. This allows the widget to push feedback messages
* to the appropriate message bar.
* \see messageBar()
*/
void setMessageBar( QgsMessageBar *bar ) { mMessageBar = bar; }

/**
* Returns the message bar associated with the widget.
* \see setMessageBar()
*/
QgsMessageBar *messageBar() const { return mMessageBar; }

private:

QString mAnnotationId;
QgsMapCanvas *mMapCanvas = nullptr;
QgsMessageBar *mMessageBar = nullptr;

};


/**
* \ingroup gui
@@ -59,6 +122,13 @@ class GUI_EXPORT QgsMapLayerConfigWidget : public QgsPanelWidget
*/
virtual void syncToLayer( QgsMapLayer *layer ) { Q_UNUSED( layer ) }

/**
* Sets the \a context under which the widget is being shown.
*
* Subclasses should take care to call the base class implementation when overriding this method.
*/
virtual void setContext( const QgsMapLayerConfigWidgetContext &context );

public slots:

/**
@@ -85,6 +155,7 @@ class GUI_EXPORT QgsMapLayerConfigWidget : public QgsPanelWidget

QgsMapLayer *mLayer = nullptr;
QgsMapCanvas *mMapCanvas = nullptr;
QgsMapLayerConfigWidgetContext mContext;
};

#endif // QGSMAPLAYERCONFIGWIDGET_H

0 comments on commit 39263a4

Please sign in to comment.