QGIS API Documentation  2.17.0-Master (06698cd)
qgssinglesymbolrendererv2widget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssinglesymbolrendererv2widget.cpp
3  ---------------------
4  begin : November 2009
5  copyright : (C) 2009 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
16 
18 #include "qgssymbolv2.h"
19 
20 #include "qgslogger.h"
21 #include "qgsvectorlayer.h"
22 
24 
25 #include <QMenu>
26 
28 {
29  return new QgsSingleSymbolRendererV2Widget( layer, style, renderer );
30 }
31 
33  : QgsRendererV2Widget( layer, style )
34  , mRenderer( nullptr )
35 {
36  // try to recognize the previous renderer
37  // (null renderer means "no previous renderer")
38 
39  if ( renderer )
40  {
42  }
43  if ( !mRenderer )
44  {
46 
47  mRenderer = new QgsSingleSymbolRendererV2( symbol );
48  }
49 
50  // load symbol from it
52 
53  // setup ui
55  connect( mSelector, SIGNAL( symbolModified() ), this, SLOT( changeSingleSymbol() ) );
56  connect( mSelector, SIGNAL( showPanel( QgsPanelWidget* ) ), this, SLOT( openPanel( QgsPanelWidget* ) ) );
57 
58  QVBoxLayout* layout = new QVBoxLayout( this );
59  layout->setContentsMargins( 0, 0, 0, 0 );
60  layout->addWidget( mSelector );
61 
62  // advanced actions - data defined rendering
63  QMenu* advMenu = mSelector->advancedMenu();
64 
65  advMenu->addAction( tr( "Symbol levels..." ), this, SLOT( showSymbolLevels() ) );
66 }
67 
69 {
70  delete mSingleSymbol;
71 
72  delete mRenderer;
73 
74  delete mSelector;
75 }
76 
77 
79 {
80  return mRenderer;
81 }
82 
84 {
86  if ( mSelector )
87  mSelector->setMapCanvas( canvas );
88 }
89 
91 {
93  if ( mSelector )
94  mSelector->setDockMode( dockMode );
95 }
96 
98 {
99  // update symbol from the GUI
101  emit widgetChanged();
102 }
103 
105 {
106  mRenderer->setSizeScaleField( fldName );
107 }
108 
110 {
111  mRenderer->setScaleMethod( scaleMethod );
112  // Set also on the symbol clone
113  QgsMarkerSymbolV2 *markerSymbol = dynamic_cast<QgsMarkerSymbolV2 *>( mSingleSymbol );
114  if ( markerSymbol )
115  {
116  markerSymbol->setScaleMethod( scaleMethod );
117  }
118 }
119 
121 {
123 }
QLayout * layout() const
void openPanel(QgsPanelWidget *panel)
Open a panel or dialog depending on dock mode setting If dock mode is true this method will emit the ...
void showSymbolLevelsDialog(QgsFeatureRendererV2 *r)
show a dialog with renderer&#39;s symbol level settings
Symbol selector widget that cna be used to select and build a symbol.
void scaleMethodChanged(QgsSymbolV2::ScaleMethod scaleMethod)
void setContentsMargins(int left, int top, int right, int bottom)
bool dockMode()
Return the dock mode state.
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the dialog.
QMenu * advancedMenu()
return menu for "advanced" button - create it if doesn&#39;t exist and show the advanced button ...
virtual void setMapCanvas(QgsMapCanvas *canvas) override
Sets the map canvas associated with the widget.
virtual QgsSymbolV2 * clone() const =0
QStyle * style() const
void addAction(QAction *action)
static QgsSingleSymbolRendererV2 * convertFromRenderer(const QgsFeatureRendererV2 *renderer)
creates a QgsSingleSymbolRendererV2 from an existing renderer.
virtual void setDockMode(bool dockMode) override
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs...
Base class for any widget that can be shown as a inline panel.
QString tr(const char *sourceText, const char *disambiguation, int n)
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:109
virtual void setDockMode(bool dockMode)
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs...
void showPanel(QgsPanelWidget *panel)
Emit when you require a panel to be show in the interface.
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QgsVectorLayer * mLayer
QgsSingleSymbolRendererV2Widget(QgsVectorLayer *layer, QgsStyleV2 *style, QgsFeatureRendererV2 *renderer)
static QgsRendererV2Widget * create(QgsVectorLayer *layer, QgsStyleV2 *style, QgsFeatureRendererV2 *renderer)
QGis::GeometryType geometryType() const
Returns point, line or polygon.
virtual QgsFeatureRendererV2 * renderer() override
return pointer to the renderer (no transfer of ownership)
void widgetChanged()
Emitted when the widget state changes.
void sizeScaleFieldChanged(const QString &fldName)
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
static QgsSymbolV2 * defaultSymbol(QGis::GeometryType geomType)
return new default symbol for specified geometry type
ScaleMethod
Scale method.
Definition: qgssymbolv2.h:90
void setSizeScaleField(const QString &fieldOrExpression)
Base class for renderer settings widgets.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Represents a vector layer which manages a vector based data sets.
virtual void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)