Skip to content
Permalink
Browse files

Give symbol widgets optional access to a map canvas

This allows symbol widgets to fetch properties from the main map
canvas, for instance fetching the current scale from the map.
  • Loading branch information
nyalldawson committed Sep 16, 2015
1 parent 60cce74 commit a62c6a917a3245cd35e5c6820fc12a71b1f727ce
Showing with 228 additions and 12 deletions.
  1. +7 −0 python/gui/symbology-ng/qgslayerpropertieswidget.sip
  2. +1 −0 python/gui/symbology-ng/qgspointdisplacementrendererwidget.sip
  3. +8 −0 python/gui/symbology-ng/qgsrendererv2propertiesdialog.sip
  4. +7 −0 python/gui/symbology-ng/qgsrendererv2widget.sip
  5. +1 −1 python/gui/symbology-ng/qgsrulebasedrendererv2widget.sip
  6. +2 −0 python/gui/symbology-ng/qgssinglesymbolrendererv2widget.sip
  7. +7 −0 python/gui/symbology-ng/qgssymbollayerv2widget.sip
  8. +7 −0 python/gui/symbology-ng/qgssymbolslistwidget.sip
  9. +7 −0 python/gui/symbology-ng/qgssymbolv2selectordialog.sip
  10. +1 −0 src/app/qgsvectorlayerproperties.cpp
  11. +2 −1 src/app/qgsvectorlayerproperties.h
  12. +3 −0 src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp
  13. +3 −0 src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp
  14. +6 −0 src/gui/symbology-ng/qgsheatmaprendererwidget.cpp
  15. +2 −0 src/gui/symbology-ng/qgsheatmaprendererwidget.h
  16. +7 −0 src/gui/symbology-ng/qgsinvertedpolygonrendererwidget.cpp
  17. +1 −0 src/gui/symbology-ng/qgsinvertedpolygonrendererwidget.h
  18. +11 −0 src/gui/symbology-ng/qgslayerpropertieswidget.cpp
  19. +10 −0 src/gui/symbology-ng/qgslayerpropertieswidget.h
  20. +9 −0 src/gui/symbology-ng/qgspointdisplacementrendererwidget.cpp
  21. +1 −0 src/gui/symbology-ng/qgspointdisplacementrendererwidget.h
  22. +10 −0 src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp
  23. +10 −0 src/gui/symbology-ng/qgsrendererv2propertiesdialog.h
  24. +9 −1 src/gui/symbology-ng/qgsrendererv2widget.cpp
  25. +9 −1 src/gui/symbology-ng/qgsrendererv2widget.h
  26. +8 −4 src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp
  27. +3 −1 src/gui/symbology-ng/qgsrulebasedrendererv2widget.h
  28. +6 −0 src/gui/symbology-ng/qgssinglesymbolrendererv2widget.cpp
  29. +3 −0 src/gui/symbology-ng/qgssinglesymbolrendererv2widget.h
  30. +9 −0 src/gui/symbology-ng/qgssymbollayerv2widget.cpp
  31. +11 −1 src/gui/symbology-ng/qgssymbollayerv2widget.h
  32. +8 −0 src/gui/symbology-ng/qgssymbolslistwidget.cpp
  33. +7 −0 src/gui/symbology-ng/qgssymbolslistwidget.h
  34. +20 −1 src/gui/symbology-ng/qgssymbolv2selectordialog.cpp
  35. +11 −0 src/gui/symbology-ng/qgssymbolv2selectordialog.h
  36. +1 −1 tests/src/python/test_qgsdoccoverage.py
@@ -15,6 +15,13 @@ class QgsLayerPropertiesWidget : QWidget
*/
QgsExpressionContext* expressionContext() const;

/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
* map scale and other properties from the canvas.
* @param canvas map canvas
* @note added in QGIS 2.12
*/
virtual void setMapCanvas( QgsMapCanvas* canvas );

public slots:
void layerTypeChanged();
void emitSignalChanged();
@@ -9,4 +9,5 @@ class QgsPointDisplacementRendererWidget: QgsRendererV2Widget
~QgsPointDisplacementRendererWidget();

QgsFeatureRendererV2* renderer();
void setMapCanvas( QgsMapCanvas* canvas );
};
@@ -6,6 +6,14 @@ class QgsRendererV2PropertiesDialog : QDialog

public:
QgsRendererV2PropertiesDialog( QgsVectorLayer* layer, QgsStyleV2* style, bool embedded = false );
~QgsRendererV2PropertiesDialog();

/** Sets the map canvas associated with the dialog. This allows the widget to retrieve the current
* map scale and other properties from the canvas.
* @param canvas map canvas
* @note added in QGIS 2.12
*/
void setMapCanvas( QgsMapCanvas* canvas );

public slots:
//! called when user changes renderer type
@@ -15,6 +15,13 @@ class QgsRendererV2Widget : QWidget
//! show a dialog with renderer's symbol level settings
void showSymbolLevelsDialog( QgsFeatureRendererV2* r );

/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
* map scale and other properties from the canvas.
* @param canvas map canvas
* @note added in QGIS 2.12
*/
virtual void setMapCanvas( QgsMapCanvas* canvas );

protected:
/** Subclasses may provide the capability of changing multiple symbols at once by implementing the following two methods
and by connecting the slot contextMenuViewCategories(const QPoint&)*/
@@ -106,7 +106,7 @@ class QgsRendererRulePropsDialog : QDialog
%End

public:
QgsRendererRulePropsDialog( QgsRuleBasedRendererV2::Rule* rule, QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent /TransferThis/ = 0 );
QgsRendererRulePropsDialog( QgsRuleBasedRendererV2::Rule* rule, QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent /TransferThis/ = 0, QgsMapCanvas* mapCanvas = 0 );
~QgsRendererRulePropsDialog();

QgsRuleBasedRendererV2::Rule* rule();
@@ -11,6 +11,8 @@ class QgsSingleSymbolRendererV2Widget : QgsRendererV2Widget

virtual QgsFeatureRendererV2* renderer();

virtual void setMapCanvas( QgsMapCanvas* canvas );

public slots:
void changeSingleSymbol();

@@ -20,6 +20,13 @@ class QgsSymbolLayerV2Widget : QWidget
*/
QgsExpressionContext* expressionContext() const;

/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
* map scale and other properties from the canvas.
* @param canvas map canvas
* @note added in QGIS 2.12
*/
virtual void setMapCanvas( QgsMapCanvas* canvas );

/** Returns the vector layer associated with the widget.
* @note added in QGIS 2.12
*/
@@ -14,6 +14,13 @@ class QgsSymbolsListWidget : QWidget
*/
QgsExpressionContext* expressionContext() const;

/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
* map scale and other properties from the canvas.
* @param canvas map canvas
* @note added in QGIS 2.12
*/
virtual void setMapCanvas( QgsMapCanvas* canvas );

/** Returns the vector layer associated with the widget.
* @note added in QGIS 2.12
*/
@@ -27,6 +27,13 @@ class QgsSymbolV2SelectorDialog : QDialog
*/
QgsExpressionContext* expressionContext() const;

/** Sets the map canvas associated with the dialog. This allows the widget to retrieve the current
* map scale and other properties from the canvas.
* @param canvas map canvas
* @note added in QGIS 2.12
*/
void setMapCanvas( QgsMapCanvas* canvas );

protected:
//! Reimplements dialog keyPress event so we can ignore it
void keyPressEvent( QKeyEvent * event );
@@ -1237,6 +1237,7 @@ void QgsVectorLayerProperties::updateSymbologyPage()
if ( layer->rendererV2() )
{
mRendererDialog = new QgsRendererV2PropertiesDialog( layer, QgsStyleV2::defaultStyle(), true );
mRendererDialog->setMapCanvas( QgisApp::instance()->mapCanvas() );

// display the menu to choose the output format (fix #5136)
mActionSaveStyleAs->setText( tr( "Save Style" ) );
@@ -40,6 +40,7 @@ class QgsVectorLayer;
class QgsLabelingGui;
class QgsDiagramProperties;
class QgsFieldsProperties;
class QgsRendererV2PropertiesDialog;

class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private Ui::QgsVectorLayerPropertiesBase
{
@@ -164,7 +165,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
QAction* mActionSaveStyleAs;

/** Renderer dialog which is shown*/
QDialog* mRendererDialog;
QgsRendererV2PropertiesDialog* mRendererDialog;
/** Labeling dialog. If apply is pressed, options are applied to vector's QgsLabel */
QgsLabelingGui* labelingDialog;
/** Label dialog. If apply is pressed, options are applied to vector's QgsLabel */
@@ -522,6 +522,7 @@ void QgsCategorizedSymbolRendererV2Widget::changeSelectedSymbols()
{
QgsSymbolV2* newSymbol = mCategorizedSymbol->clone();
QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, mLayer, this );
dlg.setMapCanvas( mMapCanvas );
if ( !dlg.exec() )
{
delete newSymbol;
@@ -555,6 +556,7 @@ void QgsCategorizedSymbolRendererV2Widget::changeCategorizedSymbol()
QgsSymbolV2* newSymbol = mCategorizedSymbol->clone();

QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, mLayer, this );
dlg.setMapCanvas( mMapCanvas );
if ( !dlg.exec() )
{
delete newSymbol;
@@ -605,6 +607,7 @@ void QgsCategorizedSymbolRendererV2Widget::changeCategorySymbol()
}

QgsSymbolV2SelectorDialog dlg( symbol, mStyle, mLayer, this );
dlg.setMapCanvas( mMapCanvas );
if ( !dlg.exec() )
{
delete symbol;
@@ -773,6 +773,7 @@ void QgsGraduatedSymbolRendererV2Widget::changeGraduatedSymbol()
QgsSymbolV2* newSymbol = mGraduatedSymbol->clone();

QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, mLayer, this );
dlg.setMapCanvas( mMapCanvas );
if ( !dlg.exec() )
{
delete newSymbol;
@@ -860,6 +861,7 @@ void QgsGraduatedSymbolRendererV2Widget::changeSelectedSymbols()
{
QgsSymbolV2* newSymbol = mGraduatedSymbol->clone();
QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, mLayer, this );
dlg.setMapCanvas( mMapCanvas );
if ( !dlg.exec() )
{
delete newSymbol;
@@ -885,6 +887,7 @@ void QgsGraduatedSymbolRendererV2Widget::changeRangeSymbol( int rangeIdx )
QgsSymbolV2* newSymbol = mRenderer->ranges()[rangeIdx].symbol()->clone();

QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, mLayer, this );
dlg.setMapCanvas( mMapCanvas );
if ( !dlg.exec() )
{
delete newSymbol;
@@ -120,6 +120,12 @@ QgsFeatureRendererV2* QgsHeatmapRendererWidget::renderer()
return mRenderer;
}

void QgsHeatmapRendererWidget::setMapCanvas( QgsMapCanvas* canvas )
{
QgsRendererV2Widget::setMapCanvas( canvas );
mRadiusUnitWidget->setMapCanvas( canvas );
}

void QgsHeatmapRendererWidget::applyColorRamp()
{
if ( !mRenderer )
@@ -43,6 +43,8 @@ class GUI_EXPORT QgsHeatmapRendererWidget : public QgsRendererV2Widget, private
/** @returns the current feature renderer */
virtual QgsFeatureRendererV2* renderer() override;

void setMapCanvas( QgsMapCanvas* canvas ) override;

protected:
QgsHeatmapRenderer* mRenderer;

@@ -111,13 +111,20 @@ QgsFeatureRendererV2* QgsInvertedPolygonRendererWidget::renderer()
return mRenderer.data();
}

void QgsInvertedPolygonRendererWidget::setMapCanvas( QgsMapCanvas* canvas )
{
QgsRendererV2Widget::setMapCanvas( canvas );
mEmbeddedRendererWidget->setMapCanvas( canvas );
}

void QgsInvertedPolygonRendererWidget::on_mRendererComboBox_currentIndexChanged( int index )
{
QString rendererId = mRendererComboBox->itemData( index ).toString();
QgsRendererV2AbstractMetadata* m = QgsRendererV2Registry::instance()->rendererMetadata( rendererId );
if ( m )
{
mEmbeddedRendererWidget.reset( m->createRendererWidget( mLayer, mStyle, const_cast<QgsFeatureRendererV2*>( mRenderer->embeddedRenderer() )->clone() ) );
mEmbeddedRendererWidget->setMapCanvas( mMapCanvas );

if ( mLayout->count() > 2 )
{
@@ -47,6 +47,7 @@ class GUI_EXPORT QgsInvertedPolygonRendererWidget : public QgsRendererV2Widget,

/** @returns the current feature renderer */
virtual QgsFeatureRendererV2* renderer() override;
void setMapCanvas( QgsMapCanvas* canvas ) override;

protected:
/** The mask renderer */
@@ -83,6 +83,7 @@ static void _initWidgetFunctions()
QgsLayerPropertiesWidget::QgsLayerPropertiesWidget( QgsSymbolLayerV2* layer, const QgsSymbolV2* symbol, const QgsVectorLayer* vl, QWidget* parent )
: QWidget( parent )
, mPresetExpressionContext( 0 )
, mMapCanvas( 0 )
{

mLayer = layer;
@@ -116,6 +117,14 @@ QgsLayerPropertiesWidget::QgsLayerPropertiesWidget( QgsSymbolLayerV2* layer, con
mEffectWidget->setPaintEffect( mLayer->paintEffect() );
}

void QgsLayerPropertiesWidget::setMapCanvas( QgsMapCanvas *canvas )
{
mMapCanvas = canvas;
QgsSymbolLayerV2Widget* w = dynamic_cast< QgsSymbolLayerV2Widget* >( stackedWidget->currentWidget() );
if ( w )
w->setMapCanvas( mMapCanvas );
}

void QgsLayerPropertiesWidget::setExpressionContext( QgsExpressionContext *context )
{
mPresetExpressionContext = context;
@@ -165,6 +174,8 @@ void QgsLayerPropertiesWidget::updateSymbolLayerWidget( QgsSymbolLayerV2* layer
{
w->setSymbolLayer( layer );
w->setExpressionContext( mPresetExpressionContext );
if ( mMapCanvas )
w->setMapCanvas( mMapCanvas );
stackedWidget->addWidget( w );
stackedWidget->setCurrentWidget( w );
// start receiving updates from widget
@@ -22,6 +22,7 @@ class QgsSymbolV2;
class QgsSymbolLayerV2;
class QgsSymbolLayerV2Widget;
class QgsVectorLayer;
class QgsMapCanvas;

class SymbolLayerItem;

@@ -44,6 +45,13 @@ class GUI_EXPORT QgsLayerPropertiesWidget : public QWidget, private Ui::LayerPro
*/
QgsExpressionContext* expressionContext() const { return mPresetExpressionContext; }

/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
* map scale and other properties from the canvas.
* @param canvas map canvas
* @note added in QGIS 2.12
*/
virtual void setMapCanvas( QgsMapCanvas* canvas );

public slots:
void layerTypeChanged();
void emitSignalChanged();
@@ -74,6 +82,8 @@ class GUI_EXPORT QgsLayerPropertiesWidget : public QWidget, private Ui::LayerPro

private:
QgsExpressionContext* mPresetExpressionContext;
QgsMapCanvas* mMapCanvas;

};

#endif //QGSLAYERPROPERTIESWIDGET_H
@@ -160,6 +160,13 @@ QgsFeatureRendererV2* QgsPointDisplacementRendererWidget::renderer()
return mRenderer;
}

void QgsPointDisplacementRendererWidget::setMapCanvas( QgsMapCanvas* canvas )
{
QgsRendererV2Widget::setMapCanvas( canvas );
mDistanceUnitWidget->setMapCanvas( canvas );
mEmbeddedRendererWidget->setMapCanvas( canvas );
}

void QgsPointDisplacementRendererWidget::on_mLabelFieldComboBox_currentIndexChanged( const QString& text )
{
if ( mRenderer )
@@ -183,6 +190,7 @@ void QgsPointDisplacementRendererWidget::on_mRendererComboBox_currentIndexChange
{
delete mEmbeddedRendererWidget;
mEmbeddedRendererWidget = m->createRendererWidget( mLayer, mStyle, mRenderer->embeddedRenderer()->clone() );
mEmbeddedRendererWidget->setMapCanvas( mMapCanvas );
}
}

@@ -332,6 +340,7 @@ void QgsPointDisplacementRendererWidget::on_mCenterSymbolPushButton_clicked()
}
QgsMarkerSymbolV2* markerSymbol = dynamic_cast<QgsMarkerSymbolV2*>( mRenderer->centerSymbol()->clone() );
QgsSymbolV2SelectorDialog dlg( markerSymbol, QgsStyleV2::defaultStyle(), mLayer, this );
dlg.setMapCanvas( mMapCanvas );
if ( dlg.exec() == QDialog::Rejected )
{
delete markerSymbol;
@@ -32,6 +32,7 @@ class GUI_EXPORT QgsPointDisplacementRendererWidget: public QgsRendererV2Widget,
~QgsPointDisplacementRendererWidget();

QgsFeatureRendererV2* renderer() override;
void setMapCanvas( QgsMapCanvas* canvas ) override;

private:
QgsPointDisplacementRenderer* mRenderer;
@@ -78,6 +78,7 @@ QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog( QgsVectorLayer* la
, mStyle( style )
, mActiveWidget( NULL )
, mPaintEffect( 0 )
, mMapCanvas( 0 )
{
setupUi( this );

@@ -149,6 +150,13 @@ QgsRendererV2PropertiesDialog::~QgsRendererV2PropertiesDialog()
delete mPaintEffect;
}

void QgsRendererV2PropertiesDialog::setMapCanvas( QgsMapCanvas* canvas )
{
mMapCanvas = canvas;
if ( mActiveWidget )
mActiveWidget->setMapCanvas( mMapCanvas );
}


void QgsRendererV2PropertiesDialog::rendererChanged()
{
@@ -193,6 +201,8 @@ void QgsRendererV2PropertiesDialog::rendererChanged()
mActiveWidget = w;
stackedWidget->addWidget( mActiveWidget );
stackedWidget->setCurrentWidget( mActiveWidget );
if ( mMapCanvas )
mActiveWidget->setMapCanvas( mMapCanvas );
}
else
{
@@ -28,6 +28,7 @@ class QgsStyleV2;
class QgsSymbolV2;
class QgsPaintEffect;
class QgsRendererV2Widget;
class QgsMapCanvas;

class GUI_EXPORT QgsRendererV2PropertiesDialog : public QDialog, private Ui::QgsRendererV2PropsDialogBase
{
@@ -37,6 +38,13 @@ class GUI_EXPORT QgsRendererV2PropertiesDialog : public QDialog, private Ui::Qgs
QgsRendererV2PropertiesDialog( QgsVectorLayer* layer, QgsStyleV2* style, bool embedded = false );
~QgsRendererV2PropertiesDialog();

/** Sets the map canvas associated with the dialog. This allows the widget to retrieve the current
* map scale and other properties from the canvas.
* @param canvas map canvas
* @note added in QGIS 2.12
*/
void setMapCanvas( QgsMapCanvas* canvas );

public slots:
//! called when user changes renderer type
void rendererChanged();
@@ -56,6 +64,8 @@ class GUI_EXPORT QgsRendererV2PropertiesDialog : public QDialog, private Ui::Qgs
QgsRendererV2Widget* mActiveWidget;

QgsPaintEffect* mPaintEffect;

QgsMapCanvas* mMapCanvas;
};


0 comments on commit a62c6a9

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