Skip to content

Commit

Permalink
Add message bar to QgsSymbolWidgetContext
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 6, 2018
1 parent 89e9895 commit f3b7260
Show file tree
Hide file tree
Showing 25 changed files with 223 additions and 10 deletions.
15 changes: 15 additions & 0 deletions python/gui/auto_generated/qgsfilecontentsourcelineedit.sip.in
Expand Up @@ -29,6 +29,21 @@ urls.
QgsAbstractFileContentSourceLineEdit( QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsAbstractFileContentSourceLineEdit, with the specified ``parent`` widget.
%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

QString source() const;
Expand Down
19 changes: 19 additions & 0 deletions python/gui/auto_generated/qgssymbolbutton.sip.in
Expand Up @@ -88,6 +88,25 @@ Sets a map ``canvas`` to associate with the widget. This allows the
widget to fetch current settings from the map canvas, such as current scale.

.. seealso:: :py:func:`mapCanvas`
%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`

.. versionadded:: 3.6
%End

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

.. seealso:: :py:func:`setMessageBar`

.. versionadded:: 3.6
%End

QgsVectorLayer *layer() const;
Expand Down
Expand Up @@ -40,6 +40,13 @@ map scale and other properties from the canvas.
:param canvas: map canvas

.. versionadded:: 2.12
%End

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

.. versionadded:: 3.6
%End

void setDockMode( bool dockMode );
Expand Down
Expand Up @@ -28,7 +28,7 @@ Constructor for QgsSymbolLayerWidget.
virtual void setSymbolLayer( QgsSymbolLayer *layer ) = 0;
virtual QgsSymbolLayer *symbolLayer() = 0;

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

Expand Down Expand Up @@ -406,6 +406,9 @@ Creates a new QgsSvgMarkerSymbolLayerWidget.
virtual QgsSymbolLayer *symbolLayer();


virtual void setContext( const QgsSymbolWidgetContext &context );


protected:

void populateList();
Expand Down Expand Up @@ -449,6 +452,8 @@ Creates a new QgsRasterMarkerSymbolLayerWidget.

virtual QgsSymbolLayer *symbolLayer();

virtual void setContext( const QgsSymbolWidgetContext &context );


protected:

Expand Down Expand Up @@ -520,6 +525,8 @@ Creates a new QgsSVGFillSymbolLayerWidget.

virtual QgsSymbolLayer *symbolLayer();

virtual void setContext( const QgsSymbolWidgetContext &context );


protected:
void insertIcons();
Expand Down
Expand Up @@ -10,7 +10,6 @@




class QgsSymbolWidgetContext
{
%Docstring
Expand Down Expand Up @@ -53,6 +52,25 @@ map scale and other properties from the canvas.
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`

.. versionadded:: 3.6
%End

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

.. seealso:: :py:func:`setMessageBar`

.. versionadded:: 3.6
%End

void setExpressionContext( QgsExpressionContext *context );
Expand Down
2 changes: 2 additions & 0 deletions src/app/decorations/qgsdecorationgriddialog.cpp
Expand Up @@ -74,7 +74,9 @@ QgsDecorationGridDialog::QgsDecorationGridDialog( QgsDecorationGrid &deco, QWidg
connect( mAnnotationFontButton, &QgsFontButton::changed, this, &QgsDecorationGridDialog::annotationFontChanged );

mMarkerSymbolButton->setMapCanvas( QgisApp::instance()->mapCanvas() );
mMarkerSymbolButton->setMessageBar( QgisApp::instance()->messageBar() );
mLineSymbolButton->setMapCanvas( QgisApp::instance()->mapCanvas() );
mLineSymbolButton->setMessageBar( QgisApp::instance()->messageBar() );
}

void QgsDecorationGridDialog::updateGuiElements()
Expand Down
1 change: 1 addition & 0 deletions src/app/decorations/qgsdecorationlayoutextentdialog.cpp
Expand Up @@ -48,6 +48,7 @@ QgsDecorationLayoutExtentDialog::QgsDecorationLayoutExtentDialog( QgsDecorationL
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsDecorationLayoutExtentDialog::showHelp );

mSymbolButton->setMapCanvas( QgisApp::instance()->mapCanvas() );
mSymbolButton->setMessageBar( QgisApp::instance()->messageBar() );
}

void QgsDecorationLayoutExtentDialog::updateGuiElements()
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -564,6 +564,7 @@ void QgisApp::layerTreeViewDoubleClicked( const QModelIndex &index )
QgsSymbolSelectorDialog dlg( symbol.get(), QgsStyle::defaultStyle(), vlayer, this );
QgsSymbolWidgetContext context;
context.setMapCanvas( mMapCanvas );
context.setMessageBar( mInfoBar );
dlg.setContext( context );
if ( dlg.exec() )
{
Expand Down Expand Up @@ -987,7 +988,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
showStylingDock->setObjectName( QStringLiteral( "ShowLayerStylingPanel" ) );
showStylingDock->setWhatsThis( tr( "Show Style Panel" ) );

mMapStyleWidget = new QgsLayerStylingWidget( mMapCanvas, mMapLayerPanelFactories );
mMapStyleWidget = new QgsLayerStylingWidget( mMapCanvas, mInfoBar, mMapLayerPanelFactories );
mMapStylingDock->setWidget( mMapStyleWidget );
connect( mMapStyleWidget, &QgsLayerStylingWidget::styleChanged, this, &QgisApp::updateLabelToolButtons );
connect( mMapStylingDock, &QDockWidget::visibilityChanged, mActionStyleDock, &QAction::setChecked );
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsannotationwidget.cpp
Expand Up @@ -71,7 +71,9 @@ QgsAnnotationWidget::QgsAnnotationWidget( QgsMapCanvasAnnotationItem *item, QWid
blockAllSignals( false );
}
mMapMarkerButton->setMapCanvas( QgisApp::instance()->mapCanvas() );
mMapMarkerButton->setMessageBar( QgisApp::instance()->messageBar() );
mFrameStyleButton->setMapCanvas( QgisApp::instance()->mapCanvas() );
mFrameStyleButton->setMessageBar( QgisApp::instance()->messageBar() );
}

void QgsAnnotationWidget::apply()
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsapplayertreeviewmenuprovider.cpp
Expand Up @@ -691,6 +691,7 @@ void QgsAppLayerTreeViewMenuProvider::editVectorSymbol()
dlg.setWindowTitle( tr( "Symbol Selector" ) );
QgsSymbolWidgetContext context;
context.setMapCanvas( mCanvas );
context.setMessageBar( QgisApp::instance()->messageBar() );
dlg.setContext( context );
if ( dlg.exec() )
{
Expand Down Expand Up @@ -768,6 +769,7 @@ void QgsAppLayerTreeViewMenuProvider::editSymbolLegendNodeSymbol()
dlg.setWindowTitle( tr( "Symbol Selector" ) );
QgsSymbolWidgetContext context;
context.setMapCanvas( mCanvas );
context.setMessageBar( QgisApp::instance()->messageBar() );
dlg.setContext( context );
if ( dlg.exec() )
{
Expand Down
9 changes: 7 additions & 2 deletions src/app/qgslayerstylingwidget.cpp
Expand Up @@ -47,17 +47,19 @@
#include "qgsruntimeprofiler.h"
#include "qgsrasterminmaxwidget.h"
#include "qgisapp.h"
#include "qgssymbolwidgetcontext.h"

#ifdef HAVE_3D
#include "qgsvectorlayer3drendererwidget.h"
#endif


QgsLayerStylingWidget::QgsLayerStylingWidget( QgsMapCanvas *canvas, const QList<QgsMapLayerConfigWidgetFactory *> &pages, QWidget *parent )
QgsLayerStylingWidget::QgsLayerStylingWidget( QgsMapCanvas *canvas, QgsMessageBar *messageBar, const QList<QgsMapLayerConfigWidgetFactory *> &pages, QWidget *parent )
: QWidget( parent )
, mNotSupportedPage( 0 )
, mLayerPage( 1 )
, mMapCanvas( canvas )
, mMessageBar( messageBar )
, mBlockAutoApply( false )
, mPageFactories( pages )
{
Expand Down Expand Up @@ -382,7 +384,10 @@ void QgsLayerStylingWidget::updateCurrentWidgetLayer()
case 0: // Style
{
QgsRendererPropertiesDialog *styleWidget = new QgsRendererPropertiesDialog( vlayer, QgsStyle::defaultStyle(), true, mStackedWidget );
styleWidget->setMapCanvas( mMapCanvas );
QgsSymbolWidgetContext context;
context.setMapCanvas( mMapCanvas );
context.setMessageBar( mMessageBar );
styleWidget->setContext( context );
styleWidget->setDockMode( true );
connect( styleWidget, &QgsRendererPropertiesDialog::widgetChanged, this, &QgsLayerStylingWidget::autoApply );
QgsPanelWidgetWrapper *wrapper = new QgsPanelWidgetWrapper( styleWidget, mStackedWidget );
Expand Down
4 changes: 3 additions & 1 deletion src/app/qgslayerstylingwidget.h
Expand Up @@ -41,6 +41,7 @@ class QgsUndoWidget;
class QgsRasterHistogramWidget;
class QgsMapLayerStyleManagerWidget;
class QgsVectorLayer3DRendererWidget;
class QgsMessageBar;

class APP_EXPORT QgsLayerStyleManagerWidgetFactory : public QgsMapLayerConfigWidgetFactory
{
Expand Down Expand Up @@ -90,7 +91,7 @@ class APP_EXPORT QgsLayerStylingWidget : public QWidget, private Ui::QgsLayerSty
Symbology3D,
};

QgsLayerStylingWidget( QgsMapCanvas *canvas, const QList<QgsMapLayerConfigWidgetFactory *> &pages, QWidget *parent = nullptr );
QgsLayerStylingWidget( QgsMapCanvas *canvas, QgsMessageBar *messageBar, const QList<QgsMapLayerConfigWidgetFactory *> &pages, QWidget *parent = nullptr );
~QgsLayerStylingWidget() override;
QgsMapLayer *layer() { return mCurrentLayer; }

Expand Down Expand Up @@ -133,6 +134,7 @@ class APP_EXPORT QgsLayerStylingWidget : public QWidget, private Ui::QgsLayerSty
QTimer *mAutoApplyTimer = nullptr;
QDomNode mLastStyleXml;
QgsMapCanvas *mMapCanvas = nullptr;
QgsMessageBar *mMessageBar = nullptr;
bool mBlockAutoApply;
QgsUndoWidget *mUndoWidget = nullptr;
QgsMapLayer *mCurrentLayer = nullptr;
Expand Down
6 changes: 5 additions & 1 deletion src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -68,6 +68,7 @@
#include "qgsgeometrycheckregistry.h"
#include "qgsgeometrycheck.h"
#include "qgsanalysis.h"
#include "qgssymbolwidgetcontext.h"

#include "layertree/qgslayertreelayer.h"
#include "qgslayertree.h"
Expand Down Expand Up @@ -1515,7 +1516,10 @@ void QgsVectorLayerProperties::updateSymbologyPage()
{
mRendererDialog = new QgsRendererPropertiesDialog( mLayer, QgsStyle::defaultStyle(), true, this );
mRendererDialog->setDockMode( false );
mRendererDialog->setMapCanvas( QgisApp::instance()->mapCanvas() );
QgsSymbolWidgetContext context;
context.setMapCanvas( QgisApp::instance()->mapCanvas() );
context.setMessageBar( QgisApp::instance()->messageBar() );
mRendererDialog->setContext( context );
connect( mRendererDialog, &QgsRendererPropertiesDialog::showPanel, this, &QgsVectorLayerProperties::openPanel );
connect( mRendererDialog, &QgsRendererPropertiesDialog::layerVariablesChanged, this, &QgsVectorLayerProperties::updateVariableEditor );
connect( mRendererDialog, &QgsRendererPropertiesDialog::widgetChanged, this, [ = ] { updateAuxiliaryStoragePage(); } );
Expand Down
10 changes: 10 additions & 0 deletions src/gui/qgsfilecontentsourcelineedit.cpp
Expand Up @@ -308,3 +308,13 @@ QString QgsImageSourceLineEdit::defaultSettingsKey() const
}

///@endcond

void QgsAbstractFileContentSourceLineEdit::setMessageBar( QgsMessageBar *bar )
{
mMessageBar = bar;
}

QgsMessageBar *QgsAbstractFileContentSourceLineEdit::messageBar() const
{
return mMessageBar;
}
15 changes: 15 additions & 0 deletions src/gui/qgsfilecontentsourcelineedit.h
Expand Up @@ -23,6 +23,7 @@

class QLineEdit;
class QToolButton;
class QgsMessageBar;

/**
* \ingroup gui
Expand Down Expand Up @@ -52,6 +53,19 @@ class GUI_EXPORT QgsAbstractFileContentSourceLineEdit : public QWidget SIP_ABSTR
*/
QgsAbstractFileContentSourceLineEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr );

/**
* 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 );

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

/**
* Returns the current file source.
* \see setSource()
Expand Down Expand Up @@ -138,6 +152,7 @@ class GUI_EXPORT QgsAbstractFileContentSourceLineEdit : public QWidget SIP_ABSTR
QToolButton *mFileToolButton = nullptr;
QString mLastPathKey;
QString mBase64;
QgsMessageBar *mMessageBar = nullptr;

QString defaultPath() const;
QString settingsKey() const;
Expand Down
11 changes: 11 additions & 0 deletions src/gui/qgssymbolbutton.cpp
Expand Up @@ -100,6 +100,7 @@ void QgsSymbolButton::showSettingsDialog()
QgsSymbolWidgetContext symbolContext;
symbolContext.setExpressionContext( &context );
symbolContext.setMapCanvas( mMapCanvas );
symbolContext.setMessageBar( mMessageBar );

QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
if ( panel && panel->dockMode() )
Expand Down Expand Up @@ -154,6 +155,16 @@ void QgsSymbolButton::setMapCanvas( QgsMapCanvas *mapCanvas )
mMapCanvas = mapCanvas;
}

void QgsSymbolButton::setMessageBar( QgsMessageBar *bar )
{
mMessageBar = bar;
}

QgsMessageBar *QgsSymbolButton::messageBar() const
{
return mMessageBar;
}

QgsVectorLayer *QgsSymbolButton::layer() const
{
return mLayer;
Expand Down
17 changes: 17 additions & 0 deletions src/gui/qgssymbolbutton.h
Expand Up @@ -26,6 +26,7 @@ class QgsMapCanvas;
class QgsVectorLayer;
class QgsExpressionContextGenerator;
class QgsPanelWidget;
class QgsMessageBar;

/**
* \ingroup gui
Expand Down Expand Up @@ -122,6 +123,21 @@ class GUI_EXPORT QgsSymbolButton : public QToolButton
*/
void setMapCanvas( QgsMapCanvas *canvas );

/**
* Sets the message \a bar associated with the widget. This allows the widget to push feedback messages
* to the appropriate message bar.
* \see messageBar()
* \since QGIS 3.6
*/
void setMessageBar( QgsMessageBar *bar );

/**
* Returns the message bar associated with the widget.
* \see setMessageBar()
* \since QGIS 3.6
*/
QgsMessageBar *messageBar() const;

/**
* Returns the layer associated with the widget.
* \see setLayer()
Expand Down Expand Up @@ -234,6 +250,7 @@ class GUI_EXPORT QgsSymbolButton : public QToolButton
QgsSymbol::SymbolType mType = QgsSymbol::Fill;

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

QPoint mDragStartPosition;

Expand Down
3 changes: 3 additions & 0 deletions src/gui/symbology/qgspointclusterrendererwidget.cpp
Expand Up @@ -123,7 +123,10 @@ void QgsPointClusterRendererWidget::setContext( const QgsSymbolWidgetContext &co
if ( mDistanceUnitWidget )
mDistanceUnitWidget->setMapCanvas( context.mapCanvas() );
if ( mCenterSymbolToolButton )
{
mCenterSymbolToolButton->setMapCanvas( context.mapCanvas() );
mCenterSymbolToolButton->setMessageBar( context.messageBar() );
}
}

void QgsPointClusterRendererWidget::mRendererComboBox_currentIndexChanged( int index )
Expand Down

0 comments on commit f3b7260

Please sign in to comment.