QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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( NULL )
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 
58  layout->setContentsMargins( 0, 0, 0, 0 );
59  layout->addWidget( mSelector );
60  setLayout( layout );
61 
62  // advanced actions - data defined rendering
63  QMenu* advMenu = mSelector->advancedMenu();
64 
65  advMenu->addAction( tr( "Symbol levels..." ), this, SLOT( showSymbolLevels() ) );
66 
72 }
73 
75 {
76  delete mSingleSymbol;
77 
78  delete mRenderer;
79 
80  delete mSelector;
81 
82  delete mDataDefinedMenus;
83 }
84 
85 
87 {
88  return mRenderer;
89 }
90 
92 {
93  // update symbol from the GUI
95 }
96 
98 {
99  mRenderer->setRotationField( fldName );
100 }
101 
103 {
104  mRenderer->setSizeScaleField( fldName );
105 }
106 
108 {
109  mRenderer->setScaleMethod( scaleMethod );
110  // Set also on the symbol clone
111  QgsMarkerSymbolV2 *markerSymbol = dynamic_cast<QgsMarkerSymbolV2 *>( mSingleSymbol );
112  if ( markerSymbol )
113  {
114  markerSymbol->setScaleMethod( scaleMethod );
115  }
116 }
117 
119 {
121 }
QLayout * layout() const
void showSymbolLevelsDialog(QgsFeatureRendererV2 *r)
show a dialog with renderer's symbol level settings
void scaleMethodChanged(QgsSymbolV2::ScaleMethod scaleMethod)
void setContentsMargins(int left, int top, int right, int bottom)
virtual QgsSymbolV2 * clone() const =0
void setSizeScaleField(QString fieldOrExpression)
void addAction(QAction *action)
QgsSymbolV2::ScaleMethod scaleMethod() const
static QgsSingleSymbolRendererV2 * convertFromRenderer(const QgsFeatureRendererV2 *renderer)
creates a QgsSingleSymbolRendererV2 from an existing renderer.
QString tr(const char *sourceText, const char *disambiguation, int n)
Utility class for providing GUI for data-defined rendering.
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QgsVectorLayer * mLayer
void setLayout(QLayout *layout)
QMenu * advancedMenu()
return menu for "advanced" button - create it if doesn't exist and show the advanced button ...
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)
QString rotationField() const override
return rotation field name (or empty string if not set or not supported by renderer) ...
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
static QgsSymbolV2 * defaultSymbol(QGis::GeometryType geomType)
return new default symbol for specified geometry type
QgsRendererV2DataDefinedMenus * mDataDefinedMenus
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.
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
void setRotationField(QString fieldOrExpression) override
sets rotation field of renderer (if supported by the renderer)