Skip to content
Permalink
Browse files

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
  • Loading branch information
wonder
wonder committed May 12, 2009
1 parent 2413981 commit 8a120782c4063515bfbba2f558a9e137de5f2e40
@@ -4,6 +4,18 @@
# sources

SET(QGIS_CORE_SRCS

symbology-ng/qgssymbolv2.cpp
symbology-ng/qgssymbollayerv2.cpp
symbology-ng/qgssymbollayerv2registry.cpp
symbology-ng/qgssymbollayerv2utils.cpp
symbology-ng/qgslinesymbollayerv2.cpp
symbology-ng/qgsmarkersymbollayerv2.cpp
symbology-ng/qgsfillsymbollayerv2.cpp
symbology-ng/qgsrendererv2.cpp
symbology-ng/qgsvectorcolorrampv2.cpp
symbology-ng/qgsstylev2.cpp

qgis.cpp
qgsapplication.cpp
qgsattributeaction.cpp
@@ -107,6 +119,7 @@ SET(QGIS_CORE_SRCS
symbology/qgssymbologyutils.cpp

spatialindex/qgsspatialindex.cpp

)

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

SET(QGIS_CORE_MOC_HDRS

qgsapplication.h
qgscontexthelp.h
qgscoordinatetransform.h
@@ -186,6 +200,7 @@ INCLUDE_DIRECTORIES(
renderer
symbology
spatialindex/include
symbology-ng
${PROJ_INCLUDE_DIR}
${GEOS_INCLUDE_DIR}
${GDAL_INCLUDE_DIR}
@@ -71,6 +71,8 @@
#include "qgslogger.h"
#include "qgsmaplayerregistry.h"

#include "qgsrendererv2.h"

#ifdef Q_WS_X11
#include "qgsclipper.h"
#endif
@@ -101,7 +103,9 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
mRenderer( 0 ),
mLabel( 0 ),
mLabelOn( false ),
mFetching( false )
mFetching( false ),
mRendererV2( NULL ),
mUsingRendererV2( false )
{
mActions = new QgsAttributeAction;

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

bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
{
if (mUsingRendererV2)
{
if (mRendererV2 == NULL)
return FALSE;

mRendererV2->startRender(rendererContext);

// TODO: really needed?
updateFeatureCount();
int totalFeatures = pendingFeatureCount();
int featureCount = 0;

QgsFeature fet;
QgsAttributeList attributes = mRendererV2->usedAttributes();
select( attributes, rendererContext.extent() );

while ( nextFeature( fet ) )
{
mRendererV2->renderFeature(fet, rendererContext);
}

mRendererV2->stopRender(rendererContext);
return TRUE;
}

//set update threshold before each draw to make sure the current setting is picked up
QSettings settings;
mUpdateThreshold = settings.value( "Map/updateThreshold", 0 ).toInt();
@@ -48,6 +48,8 @@ class QgsVectorOverlay;
class QgsGeometry;
class QgsRectangle;

class QgsFeatureRendererV2;

typedef QList<int> QgsAttributeList;
typedef QSet<int> QgsFeatureIds;
typedef QSet<int> QgsAttributeIds;
@@ -159,6 +161,15 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer

/** Sets the renderer. If a renderer is already present, it is deleted */
void setRenderer( QgsRenderer * r );

/** Return renderer V2. Added in QGIS 1.2 */
QgsFeatureRendererV2* rendererV2() { return mRendererV2; }
/** Set renderer V2. Added in QGIS 1.2 */
void setRendererV2(QgsFeatureRendererV2* r) { mRendererV2 = r; }
/** Return whether using renderer V2. Added in QGIS 1.2 */
bool isUsingRendererV2() { return mUsingRendererV2; }
/** set whether to use renderer V2 for drawing. Added in QGIS 1.2 */
void setUsingRendererV2(bool usingRendererV2) { mUsingRendererV2 = usingRendererV2; }

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

/** Renderer object which holds the information about how to display the features */
QgsRenderer *mRenderer;

/** Renderer V2 */
QgsFeatureRendererV2 *mRendererV2;

/** whether to use V1 or V2 renderer */
bool mUsingRendererV2;

/** Label */
QgsLabel *mLabel;
@@ -0,0 +1,84 @@

#include "qgsfillsymbollayerv2.h"
#include "qgssymbollayerv2utils.h"

#include "qgsrendercontext.h"

#include <QPainter>

QgsSimpleFillSymbolLayerV2::QgsSimpleFillSymbolLayerV2(QColor color, QColor borderColor, Qt::BrushStyle style)
: mBrushStyle(style), mBorderColor(borderColor)
{
mColor = color;
}


QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::create(const QgsStringMap& props)
{
QColor color = DEFAULT_SIMPLEFILL_COLOR;
QColor borderColor = DEFAULT_SIMPLEFILL_BORDERCOLOR;
Qt::BrushStyle style = DEFAULT_SIMPLEFILL_STYLE;

if (props.contains("color"))
color = QgsSymbolLayerV2Utils::decodeColor(props["color"]);
if (props.contains("color_border"))
borderColor = QgsSymbolLayerV2Utils::decodeColor(props["color_border"]);
if (props.contains("style"))
style = QgsSymbolLayerV2Utils::decodeBrushStyle(props["style"]);

return new QgsSimpleFillSymbolLayerV2(color, borderColor, style);
}


QString QgsSimpleFillSymbolLayerV2::layerType() const
{
return "SimpleFill";
}

void QgsSimpleFillSymbolLayerV2::startRender(QgsRenderContext& context)
{
mBrush = QBrush(mColor, mBrushStyle);
mPen = QPen(mBorderColor);
}

void QgsSimpleFillSymbolLayerV2::stopRender(QgsRenderContext& context)
{
}

void QgsSimpleFillSymbolLayerV2::renderPolygon(const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context)
{
QPainter* p = context.painter();
p->setBrush(mBrush);
p->setPen(mPen);

if (rings == NULL)
{
// simple polygon without holes
p->drawPolygon(points);
}
else
{
// polygon with holes must be drawn using painter path
QPainterPath path;
path.addPolygon(points);
QList<QPolygonF>::iterator it;
for (it = rings->begin(); it != rings->end(); ++it)
path.addPolygon(*it);

p->drawPath(path);
}
}

QgsStringMap QgsSimpleFillSymbolLayerV2::properties() const
{
QgsStringMap map;
map["color"] = QgsSymbolLayerV2Utils::encodeColor(mColor);
map["color_border"] = QgsSymbolLayerV2Utils::encodeColor(mBorderColor);
map["style"] = QgsSymbolLayerV2Utils::encodeBrushStyle(mBrushStyle);
return map;
}

QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::clone() const
{
return new QgsSimpleFillSymbolLayerV2(mColor, mBorderColor, mBrushStyle);
}
@@ -0,0 +1,52 @@

#ifndef QGSFILLSYMBOLLAYERV2_H
#define QGSFILLSYMBOLLAYERV2_H

#include "qgssymbollayerv2.h"

#define DEFAULT_SIMPLEFILL_COLOR QColor(0,0,255)
#define DEFAULT_SIMPLEFILL_STYLE Qt::SolidPattern
#define DEFAULT_SIMPLEFILL_BORDERCOLOR QColor(0,0,0)

#include <QPen>
#include <QBrush>

class QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2
{
public:
QgsSimpleFillSymbolLayerV2(QColor color = DEFAULT_SIMPLEFILL_COLOR,
QColor borderColor = DEFAULT_SIMPLEFILL_BORDERCOLOR,
Qt::BrushStyle style = DEFAULT_SIMPLEFILL_STYLE);

// static stuff

static QgsSymbolLayerV2* create(const QgsStringMap& properties = QgsStringMap());

// implemented from base classes

QString layerType() const;

void startRender(QgsRenderContext& context);

void stopRender(QgsRenderContext& context);

void renderPolygon(const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context);

QgsStringMap properties() const;

QgsSymbolLayerV2* clone() const;

Qt::BrushStyle brushStyle() const { return mBrushStyle; }
void setBrushStyle(Qt::BrushStyle style) { mBrushStyle = style; }

QColor borderColor() const { return mBorderColor; }
void setBorderColor(QColor borderColor) { mBorderColor = borderColor; }

protected:
QBrush mBrush;
Qt::BrushStyle mBrushStyle;
QColor mBorderColor;
QPen mPen;
};

#endif

0 comments on commit 8a12078

Please sign in to comment.
You can’t perform that action at this time.