Skip to content

Commit

Permalink
Add new class QgsMapLayerConfigWidgetContext
Browse files Browse the repository at this point in the history
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 39263a4
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 0 deletions.
69 changes: 69 additions & 0 deletions python/gui/auto_generated/qgsmaplayerconfigwidget.sip.in
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgslayerstylingwidget.cpp
Expand Up @@ -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 ) );

Expand Down Expand Up @@ -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 );
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgslayerstylingwidget.h
Expand Up @@ -29,6 +29,7 @@

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

class QgsLabelingWidget;
Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions src/gui/qgsmaplayerconfigwidget.cpp
Expand Up @@ -22,3 +22,8 @@ QgsMapLayerConfigWidget::QgsMapLayerConfigWidget( QgsMapLayer *layer, QgsMapCanv
{

}

void QgsMapLayerConfigWidget::setContext( const QgsMapLayerConfigWidgetContext &context )
{
mContext = context;
}
71 changes: 71 additions & 0 deletions src/gui/qgsmaplayerconfigwidget.h
Expand Up @@ -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
Expand Down Expand Up @@ -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:

/**
Expand All @@ -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.