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 }
67 
69 {
70  delete mSingleSymbol;
71 
72  delete mRenderer;
73 
74  delete mSelector;
75 }
76 
77 
79 {
80  return mRenderer;
81 }
82 
84 {
85  // update symbol from the GUI
87 }
88 
90 {
91  mRenderer->setSizeScaleField( fldName );
92 }
93 
95 {
96  mRenderer->setScaleMethod( scaleMethod );
97  // Set also on the symbol clone
98  QgsMarkerSymbolV2 *markerSymbol = dynamic_cast<QgsMarkerSymbolV2 *>( mSingleSymbol );
99  if ( markerSymbol )
100  {
101  markerSymbol->setScaleMethod( scaleMethod );
102  }
103 }
104 
106 {
108 }
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)
static QgsSingleSymbolRendererV2 * convertFromRenderer(const QgsFeatureRendererV2 *renderer)
creates a QgsSingleSymbolRendererV2 from an existing renderer.
QString tr(const char *sourceText, const char *disambiguation, int n)
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)
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
static QgsSymbolV2 * defaultSymbol(QGis::GeometryType geomType)
return new default symbol for specified geometry type
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)