Skip to content

Commit

Permalink
Ensure messagebar is available for use by callout widgets in dock mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 11, 2019
1 parent 7f33c6e commit b944dd4
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 7 deletions.
19 changes: 19 additions & 0 deletions python/gui/auto_generated/qgstextformatwidget.sip.in
Expand Up @@ -55,6 +55,24 @@ Returns the current formatting settings defined by the widget.
Sets the current formatting settings

.. versionadded:: 3.2
%End

virtual void setContext( const QgsSymbolWidgetContext &context );
%Docstring
Sets the ``context`` in which the widget is shown, e.g., the associated map canvas and expression contexts.

.. seealso:: :py:func:`context`

.. versionadded:: 3.10
%End

QgsSymbolWidgetContext context() const;
%Docstring
Returns the context in which the widget is shown, e.g., the associated map canvas and expression contexts.

.. seealso:: :py:func:`setContext`

.. versionadded:: 3.10
%End

public slots:
Expand Down Expand Up @@ -116,6 +134,7 @@ Controls whether data defined alignment buttons are enabled.




protected slots:

void updateLinePlacementOptions();
Expand Down
9 changes: 8 additions & 1 deletion src/app/qgslabelingwidget.cpp
Expand Up @@ -26,10 +26,11 @@
#include "qgsvectorlayerlabeling.h"
#include "qgisapp.h"

QgsLabelingWidget::QgsLabelingWidget( QgsVectorLayer *layer, QgsMapCanvas *canvas, QWidget *parent )
QgsLabelingWidget::QgsLabelingWidget( QgsVectorLayer *layer, QgsMapCanvas *canvas, QWidget *parent, QgsMessageBar *messageBar )
: QgsMapLayerConfigWidget( layer, canvas, parent )
, mLayer( layer )
, mCanvas( canvas )
, mMessageBar( messageBar )

{
setupUi( this );
Expand Down Expand Up @@ -190,6 +191,12 @@ void QgsLabelingWidget::labelModeChanged( int index )
mSimpleSettings->fieldName = mLayer->displayField();

QgsLabelingGui *simpleWidget = new QgsLabelingGui( mLayer, mCanvas, *mSimpleSettings, this );

QgsSymbolWidgetContext context;
context.setMapCanvas( mMapCanvas );
context.setMessageBar( mMessageBar );
simpleWidget->setContext( context );

simpleWidget->setDockMode( dockMode() );
connect( simpleWidget, &QgsTextFormatWidget::widgetChanged, this, &QgsLabelingWidget::widgetChanged );
connect( simpleWidget, &QgsLabelingGui::auxiliaryFieldCreated, this, &QgsLabelingWidget::auxiliaryFieldCreated );
Expand Down
4 changes: 3 additions & 1 deletion src/app/qgslabelingwidget.h
Expand Up @@ -28,6 +28,7 @@ class QgsMapCanvas;
class QgsRuleBasedLabelingWidget;
class QgsVectorLayer;
class QgsMapLayer;
class QgsMessageBar;

/**
* Master widget for configuration of labeling of a vector layer
Expand All @@ -36,7 +37,7 @@ class QgsLabelingWidget : public QgsMapLayerConfigWidget, private Ui::QgsLabelin
{
Q_OBJECT
public:
QgsLabelingWidget( QgsVectorLayer *layer, QgsMapCanvas *canvas, QWidget *parent = nullptr );
QgsLabelingWidget( QgsVectorLayer *layer, QgsMapCanvas *canvas, QWidget *parent = nullptr, QgsMessageBar *messageBar = nullptr );

/**
* Returns the labeling gui widget or NULLPTR if none.
Expand Down Expand Up @@ -69,6 +70,7 @@ class QgsLabelingWidget : public QgsMapLayerConfigWidget, private Ui::QgsLabelin
protected:
QgsVectorLayer *mLayer = nullptr;
QgsMapCanvas *mCanvas = nullptr;
QgsMessageBar *mMessageBar = nullptr;

QWidget *mWidget = nullptr;
std::unique_ptr< QgsPalLayerSettings > mSimpleSettings;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgslayerstylingwidget.cpp
Expand Up @@ -433,7 +433,7 @@ void QgsLayerStylingWidget::updateCurrentWidgetLayer()
{
if ( !mLabelingWidget )
{
mLabelingWidget = new QgsLabelingWidget( nullptr, mMapCanvas, mWidgetStack );
mLabelingWidget = new QgsLabelingWidget( nullptr, mMapCanvas, mWidgetStack, mMessageBar );
mLabelingWidget->setDockMode( true );
connect( mLabelingWidget, &QgsLabelingWidget::widgetChanged, this, &QgsLayerStylingWidget::autoApply );
}
Expand Down
1 change: 1 addition & 0 deletions src/gui/callouts/qgscalloutwidget.cpp
Expand Up @@ -56,6 +56,7 @@ void QgsCalloutWidget::setContext( const QgsSymbolWidgetContext &context )
for ( QgsSymbolButton *symbolWidget : symbolButtonWidgets )
{
symbolWidget->setMapCanvas( mContext.mapCanvas() );
symbolWidget->setMessageBar( mContext.messageBar() );
}
}

Expand Down
13 changes: 10 additions & 3 deletions src/gui/qgslabelinggui.cpp
Expand Up @@ -121,9 +121,7 @@ void QgsLabelingGui::updateCalloutWidget( QgsCallout *callout )
{
w->setCallout( callout );

QgsSymbolWidgetContext context;
context.setMapCanvas( mMapCanvas );
w->setContext( context );
w->setContext( context() );
mCalloutStackedWidget->addWidget( w );
mCalloutStackedWidget->setCurrentWidget( w );
// start receiving updates from widget
Expand Down Expand Up @@ -809,6 +807,15 @@ void QgsLabelingGui::setFormatFromStyle( const QString &name, QgsStyle::StyleEnt
}
}

void QgsLabelingGui::setContext( const QgsSymbolWidgetContext &context )
{
if ( QgsCalloutWidget *cw = qobject_cast< QgsCalloutWidget * >( mCalloutStackedWidget->currentWidget() ) )
{
cw->setContext( context );
}
QgsTextFormatWidget::setContext( context );
}

void QgsLabelingGui::saveFormat()
{
QgsStyle *style = QgsStyle::defaultStyle();
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgslabelinggui.h
Expand Up @@ -60,6 +60,8 @@ class GUI_EXPORT QgsLabelingGui : public QgsTextFormatWidget
*/
void deactivateField( QgsPalLayerSettings::Property key );

void setContext( const QgsSymbolWidgetContext &context ) override;

signals:

void auxiliaryFieldCreated();
Expand Down
18 changes: 17 additions & 1 deletion src/gui/qgstextformatwidget.cpp
Expand Up @@ -46,8 +46,8 @@ QgsTextFormatWidget::QgsTextFormatWidget( const QgsTextFormat &format, QgsMapCan

QgsTextFormatWidget::QgsTextFormatWidget( QgsMapCanvas *mapCanvas, QWidget *parent, Mode mode )
: QWidget( parent )
, mWidgetMode( mode )
, mMapCanvas( mapCanvas )
, mWidgetMode( mode )
{
initWidget();
setWidgetMode( mode );
Expand Down Expand Up @@ -926,13 +926,29 @@ void QgsTextFormatWidget::setFormat( const QgsTextFormat &format )
updateWidgetForFormat( format );
}

QgsSymbolWidgetContext QgsTextFormatWidget::context() const
{
return mContext;
}

void QgsTextFormatWidget::optionsStackedWidget_CurrentChanged( int indx )
{
mLabelingOptionsListWidget->blockSignals( true );
mLabelingOptionsListWidget->setCurrentRow( indx );
mLabelingOptionsListWidget->blockSignals( false );
}

void QgsTextFormatWidget::setContext( const QgsSymbolWidgetContext &context )
{
mContext = context;
const auto symbolButtonWidgets = findChildren<QgsSymbolButton *>();
for ( QgsSymbolButton *symbolWidget : symbolButtonWidgets )
{
symbolWidget->setMapCanvas( mContext.mapCanvas() );
symbolWidget->setMessageBar( mContext.messageBar() );
}
}

void QgsTextFormatWidget::collapseSample( bool collapse )
{
if ( collapse )
Expand Down
18 changes: 18 additions & 0 deletions src/gui/qgstextformatwidget.h
Expand Up @@ -22,6 +22,7 @@
#include "qgstextrenderer.h"
#include "qgsstringutils.h"
#include "qgsguiutils.h"
#include "qgssymbolwidgetcontext.h"
#include <QFontDatabase>
#include "qgis_gui.h"

Expand Down Expand Up @@ -74,6 +75,20 @@ class GUI_EXPORT QgsTextFormatWidget : public QWidget, public QgsExpressionConte
*/
void setFormat( const QgsTextFormat &format );

/**
* Sets the \a context in which the widget is shown, e.g., the associated map canvas and expression contexts.
* \see context()
* \since QGIS 3.10
*/
virtual void setContext( const QgsSymbolWidgetContext &context );

/**
* Returns the context in which the widget is shown, e.g., the associated map canvas and expression contexts.
* \see setContext()
* \since QGIS 3.10
*/
QgsSymbolWidgetContext context() const;

public slots:

/**
Expand Down Expand Up @@ -144,6 +159,9 @@ class GUI_EXPORT QgsTextFormatWidget : public QWidget, public QgsExpressionConte
//! Associated map canvas
QgsMapCanvas *mMapCanvas = nullptr;

//! Context in which widget is shown
QgsSymbolWidgetContext mContext;

protected slots:

//! Updates line placement options to reflect current state of widget
Expand Down

0 comments on commit b944dd4

Please sign in to comment.