Skip to content

Commit 8a12078

Browse files
author
wonder
committed
Added a bunch of core symbology classes.
git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@10770 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 2413981 commit 8a12078

23 files changed

+3613
-1
lines changed

src/core/CMakeLists.txt

+15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44
# sources
55

66
SET(QGIS_CORE_SRCS
7+
8+
symbology-ng/qgssymbolv2.cpp
9+
symbology-ng/qgssymbollayerv2.cpp
10+
symbology-ng/qgssymbollayerv2registry.cpp
11+
symbology-ng/qgssymbollayerv2utils.cpp
12+
symbology-ng/qgslinesymbollayerv2.cpp
13+
symbology-ng/qgsmarkersymbollayerv2.cpp
14+
symbology-ng/qgsfillsymbollayerv2.cpp
15+
symbology-ng/qgsrendererv2.cpp
16+
symbology-ng/qgsvectorcolorrampv2.cpp
17+
symbology-ng/qgsstylev2.cpp
18+
719
qgis.cpp
820
qgsapplication.cpp
921
qgsattributeaction.cpp
@@ -107,6 +119,7 @@ SET(QGIS_CORE_SRCS
107119
symbology/qgssymbologyutils.cpp
108120

109121
spatialindex/qgsspatialindex.cpp
122+
110123
)
111124

112125
IF (WITH_INTERNAL_SPATIALITE)
@@ -154,6 +167,7 @@ SET_SOURCE_FILES_PROPERTIES(
154167
ENDIF (MSVC AND PEDANTIC)
155168

156169
SET(QGIS_CORE_MOC_HDRS
170+
157171
qgsapplication.h
158172
qgscontexthelp.h
159173
qgscoordinatetransform.h
@@ -186,6 +200,7 @@ INCLUDE_DIRECTORIES(
186200
renderer
187201
symbology
188202
spatialindex/include
203+
symbology-ng
189204
${PROJ_INCLUDE_DIR}
190205
${GEOS_INCLUDE_DIR}
191206
${GDAL_INCLUDE_DIR}

src/core/qgsvectorlayer.cpp

+30-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
#include "qgslogger.h"
7272
#include "qgsmaplayerregistry.h"
7373

74+
#include "qgsrendererv2.h"
75+
7476
#ifdef Q_WS_X11
7577
#include "qgsclipper.h"
7678
#endif
@@ -101,7 +103,9 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
101103
mRenderer( 0 ),
102104
mLabel( 0 ),
103105
mLabelOn( false ),
104-
mFetching( false )
106+
mFetching( false ),
107+
mRendererV2( NULL ),
108+
mUsingRendererV2( false )
105109
{
106110
mActions = new QgsAttributeAction;
107111

@@ -676,6 +680,31 @@ unsigned char *QgsVectorLayer::drawPolygon(
676680

677681
bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
678682
{
683+
if (mUsingRendererV2)
684+
{
685+
if (mRendererV2 == NULL)
686+
return FALSE;
687+
688+
mRendererV2->startRender(rendererContext);
689+
690+
// TODO: really needed?
691+
updateFeatureCount();
692+
int totalFeatures = pendingFeatureCount();
693+
int featureCount = 0;
694+
695+
QgsFeature fet;
696+
QgsAttributeList attributes = mRendererV2->usedAttributes();
697+
select( attributes, rendererContext.extent() );
698+
699+
while ( nextFeature( fet ) )
700+
{
701+
mRendererV2->renderFeature(fet, rendererContext);
702+
}
703+
704+
mRendererV2->stopRender(rendererContext);
705+
return TRUE;
706+
}
707+
679708
//set update threshold before each draw to make sure the current setting is picked up
680709
QSettings settings;
681710
mUpdateThreshold = settings.value( "Map/updateThreshold", 0 ).toInt();

src/core/qgsvectorlayer.h

+17
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class QgsVectorOverlay;
4848
class QgsGeometry;
4949
class QgsRectangle;
5050

51+
class QgsFeatureRendererV2;
52+
5153
typedef QList<int> QgsAttributeList;
5254
typedef QSet<int> QgsFeatureIds;
5355
typedef QSet<int> QgsAttributeIds;
@@ -159,6 +161,15 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
159161

160162
/** Sets the renderer. If a renderer is already present, it is deleted */
161163
void setRenderer( QgsRenderer * r );
164+
165+
/** Return renderer V2. Added in QGIS 1.2 */
166+
QgsFeatureRendererV2* rendererV2() { return mRendererV2; }
167+
/** Set renderer V2. Added in QGIS 1.2 */
168+
void setRendererV2(QgsFeatureRendererV2* r) { mRendererV2 = r; }
169+
/** Return whether using renderer V2. Added in QGIS 1.2 */
170+
bool isUsingRendererV2() { return mUsingRendererV2; }
171+
/** set whether to use renderer V2 for drawing. Added in QGIS 1.2 */
172+
void setUsingRendererV2(bool usingRendererV2) { mUsingRendererV2 = usingRendererV2; }
162173

163174
/** Returns point, line or polygon */
164175
QGis::GeometryType geometryType() const;
@@ -646,6 +657,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
646657

647658
/** Renderer object which holds the information about how to display the features */
648659
QgsRenderer *mRenderer;
660+
661+
/** Renderer V2 */
662+
QgsFeatureRendererV2 *mRendererV2;
663+
664+
/** whether to use V1 or V2 renderer */
665+
bool mUsingRendererV2;
649666

650667
/** Label */
651668
QgsLabel *mLabel;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
#include "qgsfillsymbollayerv2.h"
3+
#include "qgssymbollayerv2utils.h"
4+
5+
#include "qgsrendercontext.h"
6+
7+
#include <QPainter>
8+
9+
QgsSimpleFillSymbolLayerV2::QgsSimpleFillSymbolLayerV2(QColor color, QColor borderColor, Qt::BrushStyle style)
10+
: mBrushStyle(style), mBorderColor(borderColor)
11+
{
12+
mColor = color;
13+
}
14+
15+
16+
QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::create(const QgsStringMap& props)
17+
{
18+
QColor color = DEFAULT_SIMPLEFILL_COLOR;
19+
QColor borderColor = DEFAULT_SIMPLEFILL_BORDERCOLOR;
20+
Qt::BrushStyle style = DEFAULT_SIMPLEFILL_STYLE;
21+
22+
if (props.contains("color"))
23+
color = QgsSymbolLayerV2Utils::decodeColor(props["color"]);
24+
if (props.contains("color_border"))
25+
borderColor = QgsSymbolLayerV2Utils::decodeColor(props["color_border"]);
26+
if (props.contains("style"))
27+
style = QgsSymbolLayerV2Utils::decodeBrushStyle(props["style"]);
28+
29+
return new QgsSimpleFillSymbolLayerV2(color, borderColor, style);
30+
}
31+
32+
33+
QString QgsSimpleFillSymbolLayerV2::layerType() const
34+
{
35+
return "SimpleFill";
36+
}
37+
38+
void QgsSimpleFillSymbolLayerV2::startRender(QgsRenderContext& context)
39+
{
40+
mBrush = QBrush(mColor, mBrushStyle);
41+
mPen = QPen(mBorderColor);
42+
}
43+
44+
void QgsSimpleFillSymbolLayerV2::stopRender(QgsRenderContext& context)
45+
{
46+
}
47+
48+
void QgsSimpleFillSymbolLayerV2::renderPolygon(const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context)
49+
{
50+
QPainter* p = context.painter();
51+
p->setBrush(mBrush);
52+
p->setPen(mPen);
53+
54+
if (rings == NULL)
55+
{
56+
// simple polygon without holes
57+
p->drawPolygon(points);
58+
}
59+
else
60+
{
61+
// polygon with holes must be drawn using painter path
62+
QPainterPath path;
63+
path.addPolygon(points);
64+
QList<QPolygonF>::iterator it;
65+
for (it = rings->begin(); it != rings->end(); ++it)
66+
path.addPolygon(*it);
67+
68+
p->drawPath(path);
69+
}
70+
}
71+
72+
QgsStringMap QgsSimpleFillSymbolLayerV2::properties() const
73+
{
74+
QgsStringMap map;
75+
map["color"] = QgsSymbolLayerV2Utils::encodeColor(mColor);
76+
map["color_border"] = QgsSymbolLayerV2Utils::encodeColor(mBorderColor);
77+
map["style"] = QgsSymbolLayerV2Utils::encodeBrushStyle(mBrushStyle);
78+
return map;
79+
}
80+
81+
QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::clone() const
82+
{
83+
return new QgsSimpleFillSymbolLayerV2(mColor, mBorderColor, mBrushStyle);
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
#ifndef QGSFILLSYMBOLLAYERV2_H
3+
#define QGSFILLSYMBOLLAYERV2_H
4+
5+
#include "qgssymbollayerv2.h"
6+
7+
#define DEFAULT_SIMPLEFILL_COLOR QColor(0,0,255)
8+
#define DEFAULT_SIMPLEFILL_STYLE Qt::SolidPattern
9+
#define DEFAULT_SIMPLEFILL_BORDERCOLOR QColor(0,0,0)
10+
11+
#include <QPen>
12+
#include <QBrush>
13+
14+
class QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2
15+
{
16+
public:
17+
QgsSimpleFillSymbolLayerV2(QColor color = DEFAULT_SIMPLEFILL_COLOR,
18+
QColor borderColor = DEFAULT_SIMPLEFILL_BORDERCOLOR,
19+
Qt::BrushStyle style = DEFAULT_SIMPLEFILL_STYLE);
20+
21+
// static stuff
22+
23+
static QgsSymbolLayerV2* create(const QgsStringMap& properties = QgsStringMap());
24+
25+
// implemented from base classes
26+
27+
QString layerType() const;
28+
29+
void startRender(QgsRenderContext& context);
30+
31+
void stopRender(QgsRenderContext& context);
32+
33+
void renderPolygon(const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context);
34+
35+
QgsStringMap properties() const;
36+
37+
QgsSymbolLayerV2* clone() const;
38+
39+
Qt::BrushStyle brushStyle() const { return mBrushStyle; }
40+
void setBrushStyle(Qt::BrushStyle style) { mBrushStyle = style; }
41+
42+
QColor borderColor() const { return mBorderColor; }
43+
void setBorderColor(QColor borderColor) { mBorderColor = borderColor; }
44+
45+
protected:
46+
QBrush mBrush;
47+
Qt::BrushStyle mBrushStyle;
48+
QColor mBorderColor;
49+
QPen mPen;
50+
};
51+
52+
#endif

0 commit comments

Comments
 (0)