Skip to content

Commit a62c6a9

Browse files
committedSep 16, 2015
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.
1 parent 60cce74 commit a62c6a9

36 files changed

+228
-12
lines changed
 

‎python/gui/symbology-ng/qgslayerpropertieswidget.sip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ class QgsLayerPropertiesWidget : QWidget
1515
*/
1616
QgsExpressionContext* expressionContext() const;
1717

18+
/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
19+
* map scale and other properties from the canvas.
20+
* @param canvas map canvas
21+
* @note added in QGIS 2.12
22+
*/
23+
virtual void setMapCanvas( QgsMapCanvas* canvas );
24+
1825
public slots:
1926
void layerTypeChanged();
2027
void emitSignalChanged();

‎python/gui/symbology-ng/qgspointdisplacementrendererwidget.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ class QgsPointDisplacementRendererWidget: QgsRendererV2Widget
99
~QgsPointDisplacementRendererWidget();
1010

1111
QgsFeatureRendererV2* renderer();
12+
void setMapCanvas( QgsMapCanvas* canvas );
1213
};

‎python/gui/symbology-ng/qgsrendererv2propertiesdialog.sip

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ class QgsRendererV2PropertiesDialog : QDialog
66

77
public:
88
QgsRendererV2PropertiesDialog( QgsVectorLayer* layer, QgsStyleV2* style, bool embedded = false );
9+
~QgsRendererV2PropertiesDialog();
10+
11+
/** Sets the map canvas associated with the dialog. This allows the widget to retrieve the current
12+
* map scale and other properties from the canvas.
13+
* @param canvas map canvas
14+
* @note added in QGIS 2.12
15+
*/
16+
void setMapCanvas( QgsMapCanvas* canvas );
917

1018
public slots:
1119
//! called when user changes renderer type

‎python/gui/symbology-ng/qgsrendererv2widget.sip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ class QgsRendererV2Widget : QWidget
1515
//! show a dialog with renderer's symbol level settings
1616
void showSymbolLevelsDialog( QgsFeatureRendererV2* r );
1717

18+
/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
19+
* map scale and other properties from the canvas.
20+
* @param canvas map canvas
21+
* @note added in QGIS 2.12
22+
*/
23+
virtual void setMapCanvas( QgsMapCanvas* canvas );
24+
1825
protected:
1926
/** Subclasses may provide the capability of changing multiple symbols at once by implementing the following two methods
2027
and by connecting the slot contextMenuViewCategories(const QPoint&)*/

‎python/gui/symbology-ng/qgsrulebasedrendererv2widget.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class QgsRendererRulePropsDialog : QDialog
106106
%End
107107

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

112112
QgsRuleBasedRendererV2::Rule* rule();

‎python/gui/symbology-ng/qgssinglesymbolrendererv2widget.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class QgsSingleSymbolRendererV2Widget : QgsRendererV2Widget
1111

1212
virtual QgsFeatureRendererV2* renderer();
1313

14+
virtual void setMapCanvas( QgsMapCanvas* canvas );
15+
1416
public slots:
1517
void changeSingleSymbol();
1618

‎python/gui/symbology-ng/qgssymbollayerv2widget.sip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ class QgsSymbolLayerV2Widget : QWidget
2020
*/
2121
QgsExpressionContext* expressionContext() const;
2222

23+
/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
24+
* map scale and other properties from the canvas.
25+
* @param canvas map canvas
26+
* @note added in QGIS 2.12
27+
*/
28+
virtual void setMapCanvas( QgsMapCanvas* canvas );
29+
2330
/** Returns the vector layer associated with the widget.
2431
* @note added in QGIS 2.12
2532
*/

‎python/gui/symbology-ng/qgssymbolslistwidget.sip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ class QgsSymbolsListWidget : QWidget
1414
*/
1515
QgsExpressionContext* expressionContext() const;
1616

17+
/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
18+
* map scale and other properties from the canvas.
19+
* @param canvas map canvas
20+
* @note added in QGIS 2.12
21+
*/
22+
virtual void setMapCanvas( QgsMapCanvas* canvas );
23+
1724
/** Returns the vector layer associated with the widget.
1825
* @note added in QGIS 2.12
1926
*/

‎python/gui/symbology-ng/qgssymbolv2selectordialog.sip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ class QgsSymbolV2SelectorDialog : QDialog
2727
*/
2828
QgsExpressionContext* expressionContext() const;
2929

30+
/** Sets the map canvas associated with the dialog. This allows the widget to retrieve the current
31+
* map scale and other properties from the canvas.
32+
* @param canvas map canvas
33+
* @note added in QGIS 2.12
34+
*/
35+
void setMapCanvas( QgsMapCanvas* canvas );
36+
3037
protected:
3138
//! Reimplements dialog keyPress event so we can ignore it
3239
void keyPressEvent( QKeyEvent * event );

‎src/app/qgsvectorlayerproperties.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,7 @@ void QgsVectorLayerProperties::updateSymbologyPage()
12371237
if ( layer->rendererV2() )
12381238
{
12391239
mRendererDialog = new QgsRendererV2PropertiesDialog( layer, QgsStyleV2::defaultStyle(), true );
1240+
mRendererDialog->setMapCanvas( QgisApp::instance()->mapCanvas() );
12401241

12411242
// display the menu to choose the output format (fix #5136)
12421243
mActionSaveStyleAs->setText( tr( "Save Style" ) );

‎src/app/qgsvectorlayerproperties.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class QgsVectorLayer;
4040
class QgsLabelingGui;
4141
class QgsDiagramProperties;
4242
class QgsFieldsProperties;
43+
class QgsRendererV2PropertiesDialog;
4344

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

166167
/** Renderer dialog which is shown*/
167-
QDialog* mRendererDialog;
168+
QgsRendererV2PropertiesDialog* mRendererDialog;
168169
/** Labeling dialog. If apply is pressed, options are applied to vector's QgsLabel */
169170
QgsLabelingGui* labelingDialog;
170171
/** Label dialog. If apply is pressed, options are applied to vector's QgsLabel */

‎src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ void QgsCategorizedSymbolRendererV2Widget::changeSelectedSymbols()
522522
{
523523
QgsSymbolV2* newSymbol = mCategorizedSymbol->clone();
524524
QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, mLayer, this );
525+
dlg.setMapCanvas( mMapCanvas );
525526
if ( !dlg.exec() )
526527
{
527528
delete newSymbol;
@@ -555,6 +556,7 @@ void QgsCategorizedSymbolRendererV2Widget::changeCategorizedSymbol()
555556
QgsSymbolV2* newSymbol = mCategorizedSymbol->clone();
556557

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

607609
QgsSymbolV2SelectorDialog dlg( symbol, mStyle, mLayer, this );
610+
dlg.setMapCanvas( mMapCanvas );
608611
if ( !dlg.exec() )
609612
{
610613
delete symbol;

‎src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ void QgsGraduatedSymbolRendererV2Widget::changeGraduatedSymbol()
773773
QgsSymbolV2* newSymbol = mGraduatedSymbol->clone();
774774

775775
QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, mLayer, this );
776+
dlg.setMapCanvas( mMapCanvas );
776777
if ( !dlg.exec() )
777778
{
778779
delete newSymbol;
@@ -860,6 +861,7 @@ void QgsGraduatedSymbolRendererV2Widget::changeSelectedSymbols()
860861
{
861862
QgsSymbolV2* newSymbol = mGraduatedSymbol->clone();
862863
QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, mLayer, this );
864+
dlg.setMapCanvas( mMapCanvas );
863865
if ( !dlg.exec() )
864866
{
865867
delete newSymbol;
@@ -885,6 +887,7 @@ void QgsGraduatedSymbolRendererV2Widget::changeRangeSymbol( int rangeIdx )
885887
QgsSymbolV2* newSymbol = mRenderer->ranges()[rangeIdx].symbol()->clone();
886888

887889
QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, mLayer, this );
890+
dlg.setMapCanvas( mMapCanvas );
888891
if ( !dlg.exec() )
889892
{
890893
delete newSymbol;

‎src/gui/symbology-ng/qgsheatmaprendererwidget.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ QgsFeatureRendererV2* QgsHeatmapRendererWidget::renderer()
120120
return mRenderer;
121121
}
122122

123+
void QgsHeatmapRendererWidget::setMapCanvas( QgsMapCanvas* canvas )
124+
{
125+
QgsRendererV2Widget::setMapCanvas( canvas );
126+
mRadiusUnitWidget->setMapCanvas( canvas );
127+
}
128+
123129
void QgsHeatmapRendererWidget::applyColorRamp()
124130
{
125131
if ( !mRenderer )

‎src/gui/symbology-ng/qgsheatmaprendererwidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class GUI_EXPORT QgsHeatmapRendererWidget : public QgsRendererV2Widget, private
4343
/** @returns the current feature renderer */
4444
virtual QgsFeatureRendererV2* renderer() override;
4545

46+
void setMapCanvas( QgsMapCanvas* canvas ) override;
47+
4648
protected:
4749
QgsHeatmapRenderer* mRenderer;
4850

‎src/gui/symbology-ng/qgsinvertedpolygonrendererwidget.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,20 @@ QgsFeatureRendererV2* QgsInvertedPolygonRendererWidget::renderer()
111111
return mRenderer.data();
112112
}
113113

114+
void QgsInvertedPolygonRendererWidget::setMapCanvas( QgsMapCanvas* canvas )
115+
{
116+
QgsRendererV2Widget::setMapCanvas( canvas );
117+
mEmbeddedRendererWidget->setMapCanvas( canvas );
118+
}
119+
114120
void QgsInvertedPolygonRendererWidget::on_mRendererComboBox_currentIndexChanged( int index )
115121
{
116122
QString rendererId = mRendererComboBox->itemData( index ).toString();
117123
QgsRendererV2AbstractMetadata* m = QgsRendererV2Registry::instance()->rendererMetadata( rendererId );
118124
if ( m )
119125
{
120126
mEmbeddedRendererWidget.reset( m->createRendererWidget( mLayer, mStyle, const_cast<QgsFeatureRendererV2*>( mRenderer->embeddedRenderer() )->clone() ) );
127+
mEmbeddedRendererWidget->setMapCanvas( mMapCanvas );
121128

122129
if ( mLayout->count() > 2 )
123130
{

‎src/gui/symbology-ng/qgsinvertedpolygonrendererwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class GUI_EXPORT QgsInvertedPolygonRendererWidget : public QgsRendererV2Widget,
4747

4848
/** @returns the current feature renderer */
4949
virtual QgsFeatureRendererV2* renderer() override;
50+
void setMapCanvas( QgsMapCanvas* canvas ) override;
5051

5152
protected:
5253
/** The mask renderer */

‎src/gui/symbology-ng/qgslayerpropertieswidget.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ static void _initWidgetFunctions()
8383
QgsLayerPropertiesWidget::QgsLayerPropertiesWidget( QgsSymbolLayerV2* layer, const QgsSymbolV2* symbol, const QgsVectorLayer* vl, QWidget* parent )
8484
: QWidget( parent )
8585
, mPresetExpressionContext( 0 )
86+
, mMapCanvas( 0 )
8687
{
8788

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

120+
void QgsLayerPropertiesWidget::setMapCanvas( QgsMapCanvas *canvas )
121+
{
122+
mMapCanvas = canvas;
123+
QgsSymbolLayerV2Widget* w = dynamic_cast< QgsSymbolLayerV2Widget* >( stackedWidget->currentWidget() );
124+
if ( w )
125+
w->setMapCanvas( mMapCanvas );
126+
}
127+
119128
void QgsLayerPropertiesWidget::setExpressionContext( QgsExpressionContext *context )
120129
{
121130
mPresetExpressionContext = context;
@@ -165,6 +174,8 @@ void QgsLayerPropertiesWidget::updateSymbolLayerWidget( QgsSymbolLayerV2* layer
165174
{
166175
w->setSymbolLayer( layer );
167176
w->setExpressionContext( mPresetExpressionContext );
177+
if ( mMapCanvas )
178+
w->setMapCanvas( mMapCanvas );
168179
stackedWidget->addWidget( w );
169180
stackedWidget->setCurrentWidget( w );
170181
// start receiving updates from widget

‎src/gui/symbology-ng/qgslayerpropertieswidget.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class QgsSymbolV2;
2222
class QgsSymbolLayerV2;
2323
class QgsSymbolLayerV2Widget;
2424
class QgsVectorLayer;
25+
class QgsMapCanvas;
2526

2627
class SymbolLayerItem;
2728

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

48+
/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
49+
* map scale and other properties from the canvas.
50+
* @param canvas map canvas
51+
* @note added in QGIS 2.12
52+
*/
53+
virtual void setMapCanvas( QgsMapCanvas* canvas );
54+
4755
public slots:
4856
void layerTypeChanged();
4957
void emitSignalChanged();
@@ -74,6 +82,8 @@ class GUI_EXPORT QgsLayerPropertiesWidget : public QWidget, private Ui::LayerPro
7482

7583
private:
7684
QgsExpressionContext* mPresetExpressionContext;
85+
QgsMapCanvas* mMapCanvas;
86+
7787
};
7888

7989
#endif //QGSLAYERPROPERTIESWIDGET_H

‎src/gui/symbology-ng/qgspointdisplacementrendererwidget.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ QgsFeatureRendererV2* QgsPointDisplacementRendererWidget::renderer()
160160
return mRenderer;
161161
}
162162

163+
void QgsPointDisplacementRendererWidget::setMapCanvas( QgsMapCanvas* canvas )
164+
{
165+
QgsRendererV2Widget::setMapCanvas( canvas );
166+
mDistanceUnitWidget->setMapCanvas( canvas );
167+
mEmbeddedRendererWidget->setMapCanvas( canvas );
168+
}
169+
163170
void QgsPointDisplacementRendererWidget::on_mLabelFieldComboBox_currentIndexChanged( const QString& text )
164171
{
165172
if ( mRenderer )
@@ -183,6 +190,7 @@ void QgsPointDisplacementRendererWidget::on_mRendererComboBox_currentIndexChange
183190
{
184191
delete mEmbeddedRendererWidget;
185192
mEmbeddedRendererWidget = m->createRendererWidget( mLayer, mStyle, mRenderer->embeddedRenderer()->clone() );
193+
mEmbeddedRendererWidget->setMapCanvas( mMapCanvas );
186194
}
187195
}
188196

@@ -332,6 +340,7 @@ void QgsPointDisplacementRendererWidget::on_mCenterSymbolPushButton_clicked()
332340
}
333341
QgsMarkerSymbolV2* markerSymbol = dynamic_cast<QgsMarkerSymbolV2*>( mRenderer->centerSymbol()->clone() );
334342
QgsSymbolV2SelectorDialog dlg( markerSymbol, QgsStyleV2::defaultStyle(), mLayer, this );
343+
dlg.setMapCanvas( mMapCanvas );
335344
if ( dlg.exec() == QDialog::Rejected )
336345
{
337346
delete markerSymbol;

‎src/gui/symbology-ng/qgspointdisplacementrendererwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class GUI_EXPORT QgsPointDisplacementRendererWidget: public QgsRendererV2Widget,
3232
~QgsPointDisplacementRendererWidget();
3333

3434
QgsFeatureRendererV2* renderer() override;
35+
void setMapCanvas( QgsMapCanvas* canvas ) override;
3536

3637
private:
3738
QgsPointDisplacementRenderer* mRenderer;

‎src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog( QgsVectorLayer* la
7878
, mStyle( style )
7979
, mActiveWidget( NULL )
8080
, mPaintEffect( 0 )
81+
, mMapCanvas( 0 )
8182
{
8283
setupUi( this );
8384

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

153+
void QgsRendererV2PropertiesDialog::setMapCanvas( QgsMapCanvas* canvas )
154+
{
155+
mMapCanvas = canvas;
156+
if ( mActiveWidget )
157+
mActiveWidget->setMapCanvas( mMapCanvas );
158+
}
159+
152160

153161
void QgsRendererV2PropertiesDialog::rendererChanged()
154162
{
@@ -193,6 +201,8 @@ void QgsRendererV2PropertiesDialog::rendererChanged()
193201
mActiveWidget = w;
194202
stackedWidget->addWidget( mActiveWidget );
195203
stackedWidget->setCurrentWidget( mActiveWidget );
204+
if ( mMapCanvas )
205+
mActiveWidget->setMapCanvas( mMapCanvas );
196206
}
197207
else
198208
{

‎src/gui/symbology-ng/qgsrendererv2propertiesdialog.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class QgsStyleV2;
2828
class QgsSymbolV2;
2929
class QgsPaintEffect;
3030
class QgsRendererV2Widget;
31+
class QgsMapCanvas;
3132

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

41+
/** Sets the map canvas associated with the dialog. This allows the widget to retrieve the current
42+
* map scale and other properties from the canvas.
43+
* @param canvas map canvas
44+
* @note added in QGIS 2.12
45+
*/
46+
void setMapCanvas( QgsMapCanvas* canvas );
47+
4048
public slots:
4149
//! called when user changes renderer type
4250
void rendererChanged();
@@ -56,6 +64,8 @@ class GUI_EXPORT QgsRendererV2PropertiesDialog : public QDialog, private Ui::Qgs
5664
QgsRendererV2Widget* mActiveWidget;
5765

5866
QgsPaintEffect* mPaintEffect;
67+
68+
QgsMapCanvas* mMapCanvas;
5969
};
6070

6171

0 commit comments

Comments
 (0)
Please sign in to comment.