diff --git a/python/core/symbology-ng-core.sip b/python/core/symbology-ng-core.sip index 33808baaf04..f4d392f1841 100644 --- a/python/core/symbology-ng-core.sip +++ b/python/core/symbology-ng-core.sip @@ -626,6 +626,9 @@ class QgsSymbolV2RenderContext //! @note added in 1.5 void setRenderHints( int hints ); + void setFeature( const QgsFeature* f ); + const QgsFeature* feature() const; + // Color used for selections static QColor selectionColor(); @@ -759,7 +762,7 @@ public: void setSize(double size); double size(); - void renderPoint(const QPointF& point, QgsRenderContext& context, int layer = -1, bool selected = false ); + void renderPoint(const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false ); virtual QgsSymbolV2* clone() const /Factory/; }; @@ -784,7 +787,7 @@ public: void setWidth(double width); double width(); - void renderPolyline(const QPolygonF& points, QgsRenderContext& context, int layer = -1, bool selected = false ); + void renderPolyline(const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false ); virtual QgsSymbolV2* clone() const /Factory/; }; @@ -807,7 +810,7 @@ public: QgsFillSymbolV2(QgsSymbolLayerV2List layers /Transfer/ = QgsSymbolLayerV2List()); void setAngle( double angle ); - void renderPolygon(const QPolygonF& points, QList* rings, QgsRenderContext& context, int layer = -1, bool selected = false ); + void renderPolygon(const QPolygonF& points, QList* rings, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false ); virtual QgsSymbolV2* clone() const /Factory/; }; @@ -839,7 +842,7 @@ class QgsSymbolLayerV2AbstractMetadata /** create a symbol layer of this type given the map of properties. */ virtual QgsSymbolLayerV2* createSymbolLayer( const QgsStringMap& map ) = 0 /Factory/; /** create widget for symbol layer of this type. Can return NULL if there's no GUI */ - virtual QgsSymbolLayerV2Widget* createSymbolLayerWidget() /Factory/; + virtual QgsSymbolLayerV2Widget* createSymbolLayerWidget( const QgsVectorLayer* vl ) /Factory/; }; ////////// diff --git a/python/gui/symbology-ng-gui.sip b/python/gui/symbology-ng-gui.sip index 83a1d2d475e..6dcfe0301c9 100644 --- a/python/gui/symbology-ng-gui.sip +++ b/python/gui/symbology-ng-gui.sip @@ -7,7 +7,7 @@ class QgsSymbolV2PropertiesDialog : QDialog //, private Ui::DlgSymbolV2Propertie %End public: - QgsSymbolV2PropertiesDialog(QgsSymbolV2* symbol, QWidget* parent = NULL); + QgsSymbolV2PropertiesDialog(QgsSymbolV2* symbol, const QgsVectorLayer* vl, QWidget* parent = NULL); public slots: @@ -75,7 +75,7 @@ class QgsSymbolV2SelectorDialog : QDialog //, private Ui::QgsSymbolV2SelectorDia %End public: - QgsSymbolV2SelectorDialog(QgsSymbolV2* symbol, QgsStyleV2* style, QWidget* parent = NULL, bool embedded = false); + QgsSymbolV2SelectorDialog(QgsSymbolV2* symbol, QgsStyleV2* style, const QgsVectorLayer* vl, QWidget* parent = NULL, bool embedded = false); protected: void populateSymbolView(); @@ -106,7 +106,7 @@ class QgsSymbolLayerV2Widget : QWidget %End public: - QgsSymbolLayerV2Widget( QWidget* parent ); + QgsSymbolLayerV2Widget( QWidget* parent, const QgsVectorLayer* vl = 0 ); virtual ~QgsSymbolLayerV2Widget(); virtual void setSymbolLayer( QgsSymbolLayerV2* layer ) = 0; diff --git a/src/app/qgsannotationwidget.cpp b/src/app/qgsannotationwidget.cpp index 8cc4081bcf1..f3b758af328 100644 --- a/src/app/qgsannotationwidget.cpp +++ b/src/app/qgsannotationwidget.cpp @@ -87,7 +87,7 @@ void QgsAnnotationWidget::on_mMapMarkerButton_clicked() return; } QgsMarkerSymbolV2* markerSymbol = dynamic_cast( mMarkerSymbol->clone() ); - QgsSymbolV2SelectorDialog dlg( markerSymbol, QgsStyleV2::defaultStyle(), this ); + QgsSymbolV2SelectorDialog dlg( markerSymbol, QgsStyleV2::defaultStyle(), 0, this ); if ( dlg.exec() == QDialog::Rejected ) { delete markerSymbol; diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index bad42df0316..9b05bd65c4a 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -38,6 +38,7 @@ SET(QGIS_CORE_SRCS symbology-ng/qgsstylev2.cpp symbology-ng/qgssymbologyv2conversion.cpp symbology-ng/qgssvgcache.cpp + symbology-ng/qgsellipsesymbollayerv2.cpp qgis.cpp qgsapplication.cpp diff --git a/src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp b/src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp index 2b38187053a..a3deb7beceb 100644 --- a/src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp +++ b/src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp @@ -284,13 +284,27 @@ void QgsCategorizedSymbolRendererV2::stopRender( QgsRenderContext& context ) QList QgsCategorizedSymbolRendererV2::usedAttributes() { - QList lst; - lst.append( mAttrName ); + QSet attributes; + attributes.insert( mAttrName ); if ( !mRotationField.isEmpty() ) - lst.append( mRotationField ); + { + attributes.insert( mRotationField ); + } if ( !mSizeScaleField.isEmpty() ) - lst.append( mSizeScaleField ); - return lst; + { + attributes.insert( mSizeScaleField ); + } + + QgsCategoryList::const_iterator catIt = mCategories.constBegin(); + for ( ; catIt != mCategories.constEnd(); ++catIt ) + { + QgsSymbolV2* catSymbol = catIt->symbol(); + if ( catSymbol ) + { + attributes.unite( catSymbol->usedAttributes() ); + } + } + return attributes.toList(); } QString QgsCategorizedSymbolRendererV2::dump() diff --git a/src/core/symbology-ng/qgsellipsesymbollayerv2.cpp b/src/core/symbology-ng/qgsellipsesymbollayerv2.cpp new file mode 100644 index 00000000000..e4ffa536f9e --- /dev/null +++ b/src/core/symbology-ng/qgsellipsesymbollayerv2.cpp @@ -0,0 +1,331 @@ +#include "qgsellipsesymbollayerv2.h" +#include "qgsfeature.h" +#include "qgsrendercontext.h" +#include +#include + +QgsEllipseSymbolLayerV2::QgsEllipseSymbolLayerV2(): mSymbolName( "circle" ), mSymbolWidth( 4 ), mSymbolHeight( 3 ), + mFillColor( Qt::black ), mOutlineColor( Qt::white ), mOutlineWidth( 0 ) +{ + mPen.setColor( mOutlineColor ); + mPen.setWidth( 1.0 ); + mPen.setJoinStyle( Qt::MiterJoin ); + mBrush.setColor( mFillColor ); + mBrush.setStyle( Qt::SolidPattern ); + + mAngle = 0; + mWidthField.first = -1; + mHeightField.first = -1; + mRotationField.first = -1; + mOutlineWidthField.first = -1; + mFillColorField.first = -1; + mOutlineColorField.first = -1; + mSymbolNameField.first = -1; +} + +QgsEllipseSymbolLayerV2::~QgsEllipseSymbolLayerV2() +{ +} + +QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& properties ) +{ + QgsEllipseSymbolLayerV2* layer = new QgsEllipseSymbolLayerV2(); + if ( properties.contains( "symbol_name" ) ) + { + layer->setSymbolName( properties[ "symbol_name" ] ); + } + if ( properties.contains( "symbol_width" ) ) + { + layer->setSymbolWidth( properties["symbol_width"].toDouble() ); + } + if ( properties.contains( "symbol_height" ) ) + { + layer->setSymbolHeight( properties["symbol_height"].toDouble() ); + } + if ( properties.contains( "angle" ) ) + { + layer->setAngle( properties["angle"].toDouble() ); + } + if ( properties.contains( "outline_width" ) ) + { + layer->setOutlineWidth( properties["outline_width"].toDouble() ); + } + if ( properties.contains( "fill_color" ) ) + { + layer->setFillColor( QgsSymbolLayerV2Utils::decodeColor( properties["fill_color"] ) ); + } + if ( properties.contains( "outline_color" ) ) + { + layer->setOutlineColor( QgsSymbolLayerV2Utils::decodeColor( properties["outline_color"] ) ); + } + + //data defined properties + if ( properties.contains( "height_index" ) && properties.contains( "height_field" ) ) + { + layer->setHeightField( properties["height_index"].toInt(), properties["height_field"] ); + } + if ( properties.contains( "width_index" ) && properties.contains( "width_field" ) ) + { + layer->setWidthField( properties["width_index"].toInt(), properties["width_field"] ); + } + if ( properties.contains( "rotation_index" ) && properties.contains( "rotation_field" ) ) + { + layer->setRotationField( properties["rotation_index"].toInt(), properties["rotation_field"] ); + } + if ( properties.contains( "outline_width_index" ) && properties.contains( "outline_width_field" ) ) + { + layer->setOutlineWidthField( properties["outline_width_index"].toInt(), properties["outline_width_field"] ); + } + if ( properties.contains( "fill_color_index" ) && properties.contains( "fill_color_field" ) ) + { + layer->setFillColorField( properties["fill_color_index"].toInt(), properties["fill_color_field"] ); + } + if ( properties.contains( "outline_color_index" ) && properties.contains( "outline_color_field" ) ) + { + layer->setOutlineColorField( properties["outline_color_index"].toInt(), properties["outline_color_field"] ); + } + if ( properties.contains( "symbol_name_index" ) && properties.contains( "symbol_name_field" ) ) + { + layer->setSymbolNameField( properties["symbol_name_index"].toInt(), properties["symbol_name_field"] ); + } + + return layer; +} + +void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ) +{ + const QgsFeature* f = context.feature(); + + if ( f ) + { + if ( mOutlineWidthField.first != -1 ) + { + double width = context.outputLineWidth( f->attributeMap()[mOutlineWidthField.first].toDouble() ); + mPen.setWidth( width ); + } + if ( mFillColorField.first != -1 ) + { + mBrush.setColor( QColor( f->attributeMap()[mFillColorField.first].toString() ) ); + } + if ( mOutlineColorField.first != -1 ) + { + mPen.setColor( QColor( f->attributeMap()[mOutlineColorField.first].toString() ) ); + } + + if ( mWidthField.first != -1 || mHeightField.first != -1 || mSymbolNameField.first != -1 ) + { + QString symbolName = ( mSymbolNameField.first == -1 ) ? mSymbolName : f->attributeMap()[mSymbolNameField.first].toString(); + preparePath( symbolName, context, f ); + } + } + + QPainter* p = context.renderContext().painter(); + if ( !p ) + { + return; + } + + //priority for rotation: 1. data defined, 2. symbol layer rotation (mAngle) + double rotation = 0.0; + if ( f && mRotationField.first != -1 ) + { + rotation = f->attributeMap()[mRotationField.first].toDouble(); + } + else if ( !doubleNear( mAngle, 0.0 ) ) + { + rotation = mAngle; + } + + QMatrix transform; + transform.translate( point.x(), point.y() ); + if ( !doubleNear( rotation, 0.0 ) ) + { + transform.rotate( rotation ); + } + + p->setPen( mPen ); + p->setBrush( mBrush ); + p->drawPath( transform.map( mPainterPath ) ); +} + +QString QgsEllipseSymbolLayerV2::layerType() const +{ + return "EllipseMarker"; +} + +void QgsEllipseSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context ) +{ + if ( !context.feature() || !hasDataDefinedProperty() ) + { + preparePath( mSymbolName, context ); + } + mPen.setColor( mOutlineColor ); + mPen.setWidth( context.outputLineWidth( mOutlineWidth ) ); + mBrush.setColor( mFillColor ); +} + +void QgsEllipseSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context ) +{ +} + +QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::clone() const +{ + return QgsEllipseSymbolLayerV2::create( properties() ); +} + +QgsStringMap QgsEllipseSymbolLayerV2::properties() const +{ + QgsStringMap map; + map["symbol_name"] = mSymbolName; + map["symbol_width"] = QString::number( mSymbolWidth ); + map["width_index"] = QString::number( mWidthField.first ); + map["width_field"] = mWidthField.second; + map["symbol_height"] = QString::number( mSymbolHeight ); + map["height_index"] = QString::number( mHeightField.first ); + map["height_field"] = mHeightField.second; + map["angle"] = QString::number( mAngle ); + map["rotation_index"] = QString::number( mRotationField.first ); + map["rotation_field"] = mRotationField.second; + map["outline_width"] = QString::number( mOutlineWidth ); + map["outline_width_index"] = QString::number( mOutlineWidthField.first ); + map["outline_width_field"] = mOutlineWidthField.second; + map["fill_color"] = QgsSymbolLayerV2Utils::encodeColor( mFillColor ); + map["fill_color_index"] = QString::number( mFillColorField.first ); + map["fill_color_field"] = mFillColorField.second; + map["outline_color"] = QgsSymbolLayerV2Utils::encodeColor( mOutlineColor ); + map["outline_color_index"] = QString::number( mOutlineColorField.first ); + map["outline_color_field"] = mOutlineColorField.second; + map["symbol_name_index"] = QString::number( mSymbolNameField.first ); + map["symbol_name_field"] = mSymbolNameField.second; + return map; +} + +bool QgsEllipseSymbolLayerV2::hasDataDefinedProperty() const +{ + return ( mWidthField.first != -1 || mHeightField.first != -1 || mOutlineWidthField.first != -1 + || mFillColorField.first != -1 || mOutlineColorField.first != -1 ); +} + +void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV2RenderContext& context, const QgsFeature* f ) +{ + mPainterPath = QPainterPath(); + + double width = 0; + if ( f && mWidthField.first != -1 ) + { + width = context.outputLineWidth( f->attributeMap()[mWidthField.first].toDouble() ); + } + else + { + width = context.outputLineWidth( mSymbolWidth ); + } + + double height = 0; + if ( f && mHeightField.first != -1 ) + { + height = context.outputLineWidth( f->attributeMap()[mHeightField.first].toDouble() ); + } + else + { + height = context.outputLineWidth( mSymbolHeight ); + } + + if ( symbolName == "circle" ) + { + mPainterPath.addEllipse( QRectF( -width / 2.0, -height / 2.0, width, height ) ); + } + else if ( symbolName == "rectangle" ) + { + mPainterPath.addRect( QRectF( -width / 2.0, -height / 2.0, width, height ) ); + } + else if ( symbolName == "cross" ) + { + mPainterPath.moveTo( 0, -height / 2.0 ); + mPainterPath.lineTo( 0, height / 2.0 ); + mPainterPath.moveTo( -width / 2.0, 0 ); + mPainterPath.lineTo( width / 2.0, 0 ); + } + else if ( symbolName == "triangle" ) + { + mPainterPath.moveTo( 0, -height / 2.0 ); + mPainterPath.lineTo( -width / 2.0, height / 2.0 ); + mPainterPath.lineTo( width / 2.0, height / 2.0 ); + mPainterPath.lineTo( 0, -height / 2.0 ); + } +} + +QSet QgsEllipseSymbolLayerV2::usedAttributes() const +{ + QSet dataDefinedAttributes; + if ( mWidthField.first != -1 ) + { + dataDefinedAttributes.insert( mWidthField.second ); + } + if ( mHeightField.first != -1 ) + { + dataDefinedAttributes.insert( mHeightField.second ); + } + if ( mRotationField.first != -1 ) + { + dataDefinedAttributes.insert( mRotationField.second ); + } + if ( mOutlineWidthField.first != -1 ) + { + dataDefinedAttributes.insert( mOutlineWidthField.second ); + } + if ( mFillColorField.first != -1 ) + { + dataDefinedAttributes.insert( mFillColorField.second ); + } + if ( mOutlineColorField.first != -1 ) + { + dataDefinedAttributes.insert( mOutlineColorField.second ); + } + if ( mSymbolNameField.first != -1 ) + { + dataDefinedAttributes.insert( mSymbolNameField.second ); + } + return dataDefinedAttributes; +} + +void QgsEllipseSymbolLayerV2::setSymbolNameField( int index, const QString& field ) +{ + mSymbolNameField.first = index; + mSymbolNameField.second = field; +} + +void QgsEllipseSymbolLayerV2::setWidthField( int index, const QString& field ) +{ + mWidthField.first = index; + mWidthField.second = field; +} + +void QgsEllipseSymbolLayerV2::setHeightField( int index, const QString& field ) +{ + mHeightField.first = index; + mHeightField.second = field; +} + +void QgsEllipseSymbolLayerV2::setRotationField( int index, const QString& field ) +{ + mRotationField.first = index; + mRotationField.second = field; +} + +void QgsEllipseSymbolLayerV2::setOutlineWidthField( int index, const QString& field ) +{ + mOutlineWidthField.first = index; + mOutlineWidthField.second = field; +} + +void QgsEllipseSymbolLayerV2::setFillColorField( int index, const QString& field ) +{ + mFillColorField.first = index; + mFillColorField.second = field; +} + +void QgsEllipseSymbolLayerV2::setOutlineColorField( int index, const QString& field ) +{ + mOutlineColorField.first = index; + mOutlineColorField.second = field; +} diff --git a/src/core/symbology-ng/qgsellipsesymbollayerv2.h b/src/core/symbology-ng/qgsellipsesymbollayerv2.h new file mode 100644 index 00000000000..6bc53765c2e --- /dev/null +++ b/src/core/symbology-ng/qgsellipsesymbollayerv2.h @@ -0,0 +1,100 @@ +#ifndef QGSELLIPSESYMBOLLAYERV2_H +#define QGSELLIPSESYMBOLLAYERV2_H + +#include "qgsmarkersymbollayerv2.h" +#include + +/**A symbol layer for rendering objects with major and minor axis (e.g. ellipse, rectangle )*/ +class CORE_EXPORT QgsEllipseSymbolLayerV2: public QgsMarkerSymbolLayerV2 +{ + public: + QgsEllipseSymbolLayerV2(); + ~QgsEllipseSymbolLayerV2(); + + static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() ); + + void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ); + QString layerType() const; + void startRender( QgsSymbolV2RenderContext& context ); + void stopRender( QgsSymbolV2RenderContext& context ); + QgsSymbolLayerV2* clone() const; + QgsStringMap properties() const; + + void setSymbolName( const QString& name ){ mSymbolName = name; } + QString symbolName() const{ return mSymbolName; } + + void setSymbolNameField( int index, const QString& field ); + const QPair& symbolNameField() const { return mSymbolNameField; } + + void setSymbolWidth( double w ){ mSymbolWidth = w; } + double symbolWidth() const { return mSymbolWidth; } + + void setWidthField( int index, const QString& field ); + const QPair& widthField() const { return mWidthField; } + + void setSymbolHeight( double h ){ mSymbolHeight = h; } + double symbolHeight() const { return mSymbolHeight; } + + void setHeightField( int index, const QString& field ); + const QPair& heightField() const { return mHeightField; } + + void setRotationField( int index, const QString& field ); + const QPair& rotationField() const { return mRotationField; } + + void setOutlineWidth( double w ){ mOutlineWidth = w; } + double outlineWidth() const { return mOutlineWidth; } + + void setOutlineWidthField( int index, const QString& field ); + const QPair& outlineWidthField() const { return mOutlineWidthField; } + + void setFillColor( const QColor& c ){ mFillColor = c;} + QColor fillColor() const { return mFillColor; } + + void setFillColorField( int index, const QString& field ); + const QPair& fillColorField() const { return mFillColorField; } + + void setOutlineColor( const QColor& c ){ mOutlineColor = c; } + QColor outlineColor() const { return mOutlineColor; } + + void setOutlineColorField( int index, const QString& field ); + const QPair& outlineColorField() const { return mOutlineColorField; } + + QSet usedAttributes() const; + + private: + QString mSymbolName; + double mSymbolWidth; + double mSymbolHeight; + QColor mFillColor; + QColor mOutlineColor; + double mOutlineWidth; + + /**Take width from attribute (-1 if fixed width)*/ + QPair mWidthField; + /**Take height from attribute (-1 if fixed height)*/ + QPair mHeightField; + /**Take symbol rotation from attribute (-1 if fixed rotation)*/ + QPair mRotationField; + /**Take outline width from attribute (-1 if fixed outline width)*/ + QPair mOutlineWidthField; + /**Take fill color from attribute (-1 if fixed fill color)*/ + QPair mFillColorField; + /**Take outline color from attribute (-1 if fixed outline color)*/ + QPair mOutlineColorField; + /**Take shape name from attribute (-1 if fixed shape type)*/ + QPair mSymbolNameField; + + QPainterPath mPainterPath; + + QPen mPen; + QBrush mBrush; + + /**Setup mPainterPath + @param feature to render (0 if no data defined rendering)*/ + void preparePath( const QString& symbolName, QgsSymbolV2RenderContext& context, const QgsFeature* f = 0 ); + + /**True if this symbol layer uses a data defined property*/ + bool hasDataDefinedProperty() const; +}; + +#endif // QGSELLIPSESYMBOLLAYERV2_H diff --git a/src/core/symbology-ng/qgsfillsymbollayerv2.cpp b/src/core/symbology-ng/qgsfillsymbollayerv2.cpp index 79ec459f9b2..2b751c0b544 100644 --- a/src/core/symbology-ng/qgsfillsymbollayerv2.cpp +++ b/src/core/symbology-ng/qgsfillsymbollayerv2.cpp @@ -268,13 +268,13 @@ void QgsSVGFillSymbolLayer::renderPolygon( const QPolygonF& points, QListrenderPolyline( points, context.renderContext(), -1, selectFillBorder && context.selected() ); + mOutline->renderPolyline( points, context.feature(), context.renderContext(), -1, selectFillBorder && context.selected() ); if ( rings ) { QList::const_iterator ringIt = rings->constBegin(); for ( ; ringIt != rings->constEnd(); ++ringIt ) { - mOutline->renderPolyline( *ringIt, context.renderContext(), -1, selectFillBorder && context.selected() ); + mOutline->renderPolyline( *ringIt, context.feature(), context.renderContext(), -1, selectFillBorder && context.selected() ); } } } @@ -416,7 +416,7 @@ void QgsCentroidFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QList cx /= sum; cy /= sum; - mMarker->renderPoint( QPointF( cx, cy ), context.renderContext(), -1, context.selected() ); + mMarker->renderPoint( QPointF( cx, cy ), context.feature(), context.renderContext(), -1, context.selected() ); } QgsStringMap QgsCentroidFillSymbolLayerV2::properties() const diff --git a/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp b/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp index 5fec980ea4a..a07a45c96d9 100644 --- a/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp +++ b/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp @@ -218,13 +218,28 @@ void QgsGraduatedSymbolRendererV2::stopRender( QgsRenderContext& context ) QList QgsGraduatedSymbolRendererV2::usedAttributes() { - QList lst; - lst.append( mAttrName ); + QSet attributes; + attributes.insert( mAttrName ); if ( !mRotationField.isEmpty() ) - lst.append( mRotationField ); + { + attributes.insert( mRotationField ); + } if ( !mSizeScaleField.isEmpty() ) - lst.append( mSizeScaleField ); - return lst; + { + attributes.insert( mSizeScaleField ); + } + + QgsSymbolV2* symbol = 0; + QgsRangeList::const_iterator range_it = mRanges.constBegin(); + for ( ; range_it != mRanges.constEnd(); ++range_it ) + { + symbol = range_it->symbol(); + if ( symbol ) + { + attributes.unite( symbol->usedAttributes() ); + } + } + return attributes.toList(); } bool QgsGraduatedSymbolRendererV2::updateRangeSymbol( int rangeIndex, QgsSymbolV2* symbol ) diff --git a/src/core/symbology-ng/qgslinesymbollayerv2.cpp b/src/core/symbology-ng/qgslinesymbollayerv2.cpp index 8dfee7baada..b1a3f5a12e7 100644 --- a/src/core/symbology-ng/qgslinesymbollayerv2.cpp +++ b/src/core/symbology-ng/qgslinesymbollayerv2.cpp @@ -355,7 +355,7 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineInterval( const QPolygonF& points // draw first marker if ( first ) { - mMarker->renderPoint( lastPt, rc, -1, context.selected() ); + mMarker->renderPoint( lastPt, context.feature(), rc, -1, context.selected() ); first = false; } @@ -365,7 +365,7 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineInterval( const QPolygonF& points // "c" is 1 for regular point or in interval (0,1] for begin of line segment lastPt += c * diff; lengthLeft -= painterUnitInterval; - mMarker->renderPoint( lastPt, rc, -1, context.selected() ); + mMarker->renderPoint( lastPt, context.feature(), rc, -1, context.selected() ); c = 1; // reset c (if wasn't 1 already) } @@ -474,7 +474,7 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineVertex( const QPolygonF& points, mMarker->setAngle( origAngle + angle * 180 / M_PI ); } - mMarker->renderPoint( points.at( i ), rc, -1, context.selected() ); + mMarker->renderPoint( points.at( i ), context.feature(), rc, -1, context.selected() ); } // restore original rotation @@ -521,7 +521,7 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineCentral( const QPolygonF& points, double origAngle = mMarker->angle(); if ( mRotateMarker ) mMarker->setAngle( origAngle + l.angle() * 180 / M_PI ); - mMarker->renderPoint( pt, context.renderContext(), -1, context.selected() ); + mMarker->renderPoint( pt, context.feature(), context.renderContext(), -1, context.selected() ); if ( mRotateMarker ) mMarker->setAngle( origAngle ); } diff --git a/src/core/symbology-ng/qgsrendererv2.cpp b/src/core/symbology-ng/qgsrendererv2.cpp index 33cf8bfa878..ed95707d061 100644 --- a/src/core/symbology-ng/qgsrendererv2.cpp +++ b/src/core/symbology-ng/qgsrendererv2.cpp @@ -202,7 +202,7 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext& } QPointF pt; _getPoint( pt, context, geom->asWkb() ); - (( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, context, layer, selected ); + (( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected ); //if ( drawVertexMarker ) // renderVertexMarker( pt, context ); @@ -219,7 +219,7 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext& } QPolygonF pts; _getLineString( pts, context, geom->asWkb() ); - (( QgsLineSymbolV2* )symbol )->renderPolyline( pts, context, layer, selected ); + (( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected ); if ( drawVertexMarker ) renderVertexMarkerPolyline( pts, context ); @@ -237,7 +237,7 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext& QPolygonF pts; QList holes; _getPolygon( pts, holes, context, geom->asWkb() ); - (( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), context, layer, selected ); + (( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected ); if ( drawVertexMarker ) renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context ); @@ -261,7 +261,7 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext& for ( unsigned int i = 0; i < num; ++i ) { ptr = _getPoint( pt, context, ptr ); - (( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, context, layer, selected ); + (( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected ); //if ( drawVertexMarker ) // renderVertexMarker( pt, context ); @@ -286,7 +286,7 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext& for ( unsigned int i = 0; i < num; ++i ) { ptr = _getLineString( pts, context, ptr ); - (( QgsLineSymbolV2* )symbol )->renderPolyline( pts, context, layer, selected ); + (( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected ); if ( drawVertexMarker ) renderVertexMarkerPolyline( pts, context ); @@ -312,7 +312,7 @@ void QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext& for ( unsigned int i = 0; i < num; ++i ) { ptr = _getPolygon( pts, holes, context, ptr ); - (( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), context, layer, selected ); + (( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected ); if ( drawVertexMarker ) renderVertexMarkerPolygon( pts, ( holes.count() ? &holes : NULL ), context ); diff --git a/src/core/symbology-ng/qgsrulebasedrendererv2.cpp b/src/core/symbology-ng/qgsrulebasedrendererv2.cpp index 44dfb2ab9ac..29e18d898db 100644 --- a/src/core/symbology-ng/qgsrulebasedrendererv2.cpp +++ b/src/core/symbology-ng/qgsrulebasedrendererv2.cpp @@ -192,6 +192,10 @@ QList QgsRuleBasedRendererV2::usedAttributes() { Rule& rule = *it; attrs.unite( rule.needsFields().toSet() ); + if ( rule.symbol() ) + { + attrs.unite( rule.symbol()->usedAttributes() ); + } } return attrs.values(); } diff --git a/src/core/symbology-ng/qgssinglesymbolrendererv2.cpp b/src/core/symbology-ng/qgssinglesymbolrendererv2.cpp index 0c7f66052ea..fd83af4f6a9 100644 --- a/src/core/symbology-ng/qgssinglesymbolrendererv2.cpp +++ b/src/core/symbology-ng/qgssinglesymbolrendererv2.cpp @@ -122,12 +122,20 @@ void QgsSingleSymbolRendererV2::stopRender( QgsRenderContext& context ) QList QgsSingleSymbolRendererV2::usedAttributes() { - QList lst; + QSet attributes; + if( mSymbol ) + { + attributes.unite( mSymbol->usedAttributes() ); + } if ( !mRotationField.isEmpty() ) - lst.append( mRotationField ); + { + attributes.insert( mRotationField ); + } if ( !mSizeScaleField.isEmpty() ) - lst.append( mSizeScaleField ); - return lst; + { + attributes.insert( mSizeScaleField ); + } + return attributes.toList(); } QgsSymbolV2* QgsSingleSymbolRendererV2::symbol() const diff --git a/src/core/symbology-ng/qgssymbollayerv2.h b/src/core/symbology-ng/qgssymbollayerv2.h index bd6cce8973d..0c798b9009d 100644 --- a/src/core/symbology-ng/qgssymbollayerv2.h +++ b/src/core/symbology-ng/qgssymbollayerv2.h @@ -1,10 +1,12 @@ #ifndef QGSSYMBOLLAYERV2_H #define QGSSYMBOLLAYERV2_H -#include + #include +#include #include +#include #include "qgssymbolv2.h" @@ -52,6 +54,9 @@ class CORE_EXPORT QgsSymbolLayerV2 void setRenderingPass( int renderingPass ) { mRenderingPass = renderingPass; } int renderingPass() const { return mRenderingPass; } + // symbol layers normally only use additional attributes to provide data defined settings + virtual QSet usedAttributes() const { return QSet(); } + protected: QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false ) : mType( type ), mLocked( locked ), mRenderingPass( 0 ) {} diff --git a/src/core/symbology-ng/qgssymbollayerv2registry.cpp b/src/core/symbology-ng/qgssymbollayerv2registry.cpp index c430a249339..212b200d4b6 100644 --- a/src/core/symbology-ng/qgssymbollayerv2registry.cpp +++ b/src/core/symbology-ng/qgssymbollayerv2registry.cpp @@ -1,6 +1,7 @@ #include "qgssymbollayerv2registry.h" +#include "qgsellipsesymbollayerv2.h" #include "qgsmarkersymbollayerv2.h" #include "qgslinesymbollayerv2.h" #include "qgsfillsymbollayerv2.h" @@ -23,6 +24,8 @@ QgsSymbolLayerV2Registry::QgsSymbolLayerV2Registry() QgsSvgMarkerSymbolLayerV2::create ) ); addSymbolLayerType( new QgsSymbolLayerV2Metadata( "FontMarker", QObject::tr( "Font marker" ), QgsSymbolV2::Marker, QgsFontMarkerSymbolLayerV2::create ) ); + addSymbolLayerType( new QgsSymbolLayerV2Metadata( "EllipseMarker", QObject::tr("Ellipse marker"), QgsSymbolV2::Marker, + QgsEllipseSymbolLayerV2::create ) ); addSymbolLayerType( new QgsSymbolLayerV2Metadata( "SimpleFill", QObject::tr( "Simple fill" ), QgsSymbolV2::Fill, QgsSimpleFillSymbolLayerV2::create ) ); diff --git a/src/core/symbology-ng/qgssymbollayerv2registry.h b/src/core/symbology-ng/qgssymbollayerv2registry.h index 70e377241a5..2b0615a8ff2 100644 --- a/src/core/symbology-ng/qgssymbollayerv2registry.h +++ b/src/core/symbology-ng/qgssymbollayerv2registry.h @@ -5,6 +5,8 @@ #include "qgssymbolv2.h" #include "qgssymbollayerv2.h" +class QgsVectorLayer; + /** Stores metadata about one symbol layer class. @@ -24,7 +26,7 @@ class CORE_EXPORT QgsSymbolLayerV2AbstractMetadata /** create a symbol layer of this type given the map of properties. */ virtual QgsSymbolLayerV2* createSymbolLayer( const QgsStringMap& map ) = 0; /** create widget for symbol layer of this type. Can return NULL if there's no GUI */ - virtual QgsSymbolLayerV2Widget* createSymbolLayerWidget() { return NULL; } + virtual QgsSymbolLayerV2Widget* createSymbolLayerWidget( const QgsVectorLayer* vl ) { return NULL; } protected: QString mName; @@ -33,7 +35,7 @@ class CORE_EXPORT QgsSymbolLayerV2AbstractMetadata }; typedef QgsSymbolLayerV2*( *QgsSymbolLayerV2CreateFunc )( const QgsStringMap& ); -typedef QgsSymbolLayerV2Widget*( *QgsSymbolLayerV2WidgetFunc )(); +typedef QgsSymbolLayerV2Widget*( *QgsSymbolLayerV2WidgetFunc )( const QgsVectorLayer* ); /** Convenience metadata class that uses static functions to create symbol layer and its widget. @@ -53,7 +55,7 @@ class CORE_EXPORT QgsSymbolLayerV2Metadata : public QgsSymbolLayerV2AbstractMeta void setWidgetFunction( QgsSymbolLayerV2WidgetFunc f ) { mWidgetFunc = f; } virtual QgsSymbolLayerV2* createSymbolLayer( const QgsStringMap& map ) { return mCreateFunc ? mCreateFunc( map ) : NULL; } - virtual QgsSymbolLayerV2Widget* createSymbolLayerWidget() { return mWidgetFunc ? mWidgetFunc() : NULL; } + virtual QgsSymbolLayerV2Widget* createSymbolLayerWidget( const QgsVectorLayer* vl ) { return mWidgetFunc ? mWidgetFunc( vl ) : NULL; } protected: QgsSymbolLayerV2CreateFunc mCreateFunc; diff --git a/src/core/symbology-ng/qgssymbolv2.cpp b/src/core/symbology-ng/qgssymbolv2.cpp index 9b5d37d1fd9..dfe9d06d708 100644 --- a/src/core/symbology-ng/qgssymbolv2.cpp +++ b/src/core/symbology-ng/qgssymbolv2.cpp @@ -215,17 +215,17 @@ QImage QgsSymbolV2::bigSymbolPreviewImage() { QPolygonF poly; poly << QPointF( 0, 50 ) << QPointF( 99, 50 ); - static_cast( this )->renderPolyline( poly, context ); + static_cast( this )->renderPolyline( poly, 0, context ); } else if ( mType == QgsSymbolV2::Fill ) { QPolygonF polygon; polygon << QPointF( 20, 20 ) << QPointF( 80, 20 ) << QPointF( 80, 80 ) << QPointF( 20, 80 ) << QPointF( 20, 20 ); - static_cast( this )->renderPolygon( polygon, NULL, context ); + static_cast( this )->renderPolygon( polygon, NULL, 0, context ); } else // marker { - static_cast( this )->renderPoint( QPointF( 50, 50 ), context ); + static_cast( this )->renderPoint( QPointF( 50, 50 ), 0, context ); } stopRender( context ); @@ -265,10 +265,24 @@ QgsSymbolLayerV2List QgsSymbolV2::cloneLayers() const return lst; } +QSet QgsSymbolV2::usedAttributes() const +{ + QSet attributes; + QgsSymbolLayerV2List::const_iterator sIt = mLayers.constBegin(); + for(; sIt != mLayers.constEnd(); ++sIt ) + { + if( *sIt ) + { + attributes.unite( (*sIt)->usedAttributes() ); + } + } + return attributes; +} + //////////////////// -QgsSymbolV2RenderContext::QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u, qreal alpha, bool selected, int renderHints ) - : mRenderContext( c ), mOutputUnit( u ), mAlpha( alpha ), mSelected( selected ), mRenderHints( renderHints ) +QgsSymbolV2RenderContext::QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u, qreal alpha, bool selected, int renderHints, const QgsFeature* f ) + : mRenderContext( c ), mOutputUnit( u ), mAlpha( alpha ), mSelected( selected ), mRenderHints( renderHints ), mFeature( f ) { } @@ -402,9 +416,9 @@ double QgsMarkerSymbolV2::size() return maxSize; } -void QgsMarkerSymbolV2::renderPoint( const QPointF& point, QgsRenderContext& context, int layer, bool selected ) +void QgsMarkerSymbolV2::renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected ) { - QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, selected, mRenderHints ); + QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, selected, mRenderHints, f ); if ( layer != -1 ) { if ( layer >= 0 && layer < mLayers.count() ) @@ -471,9 +485,9 @@ double QgsLineSymbolV2::width() return maxWidth; } -void QgsLineSymbolV2::renderPolyline( const QPolygonF& points, QgsRenderContext& context, int layer, bool selected ) +void QgsLineSymbolV2::renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected ) { - QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, selected, mRenderHints ); + QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, selected, mRenderHints, f ); if ( layer != -1 ) { if ( layer >= 0 && layer < mLayers.count() ) @@ -507,9 +521,9 @@ QgsFillSymbolV2::QgsFillSymbolV2( QgsSymbolLayerV2List layers ) mLayers.append( new QgsSimpleFillSymbolLayerV2() ); } -void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList* rings, QgsRenderContext& context, int layer, bool selected ) +void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList* rings, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected ) { - QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, selected, mRenderHints ); + QgsSymbolV2RenderContext symbolContext( context, mOutputUnit, mAlpha, selected, mRenderHints, f ); if ( layer != -1 ) { if ( layer >= 0 && layer < mLayers.count() ) diff --git a/src/core/symbology-ng/qgssymbolv2.h b/src/core/symbology-ng/qgssymbolv2.h index 5a5affdb6d7..cc2c7de3aa9 100644 --- a/src/core/symbology-ng/qgssymbolv2.h +++ b/src/core/symbology-ng/qgssymbolv2.h @@ -14,6 +14,7 @@ class QPointF; class QPolygonF; //class +class QgsFeature; class QgsSymbolLayerV2; class QgsRenderContext; @@ -98,6 +99,8 @@ class CORE_EXPORT QgsSymbolV2 //! @note added in 1.5 int renderHints() { return mRenderHints; } + QSet usedAttributes() const; + protected: QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated @@ -124,7 +127,7 @@ class CORE_EXPORT QgsSymbolV2 class CORE_EXPORT QgsSymbolV2RenderContext { public: - QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u , qreal alpha = 1.0, bool selected = false, int renderHints = 0 ); + QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u , qreal alpha = 1.0, bool selected = false, int renderHints = 0, const QgsFeature* f = 0 ); ~QgsSymbolV2RenderContext(); QgsRenderContext& renderContext() { return mRenderContext; } @@ -144,6 +147,9 @@ class CORE_EXPORT QgsSymbolV2RenderContext //! @note added in 1.5 void setRenderHints( int hints ) { mRenderHints = hints; } + void setFeature( const QgsFeature* f ){ mFeature = f; } + const QgsFeature* feature() const { return mFeature; } + // Color used for selections static QColor selectionColor(); @@ -159,6 +165,7 @@ class CORE_EXPORT QgsSymbolV2RenderContext qreal mAlpha; bool mSelected; int mRenderHints; + const QgsFeature* mFeature; //current feature }; @@ -184,7 +191,7 @@ class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2 void setSize( double size ); double size(); - void renderPoint( const QPointF& point, QgsRenderContext& context, int layer = -1, bool selected = false ); + void renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false ); virtual QgsSymbolV2* clone() const; }; @@ -205,7 +212,7 @@ class CORE_EXPORT QgsLineSymbolV2 : public QgsSymbolV2 void setWidth( double width ); double width(); - void renderPolyline( const QPolygonF& points, QgsRenderContext& context, int layer = -1, bool selected = false ); + void renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false ); virtual QgsSymbolV2* clone() const; }; @@ -223,7 +230,7 @@ class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2 QgsFillSymbolV2( QgsSymbolLayerV2List layers = QgsSymbolLayerV2List() ); void setAngle( double angle ); - void renderPolygon( const QPolygonF& points, QList* rings, QgsRenderContext& context, int layer = -1, bool selected = false ); + void renderPolygon( const QPolygonF& points, QList* rings, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false ); virtual QgsSymbolV2* clone() const; }; diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 01bb476ddfc..fc85f65df17 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -21,6 +21,7 @@ symbology-ng/qgsvectorrandomcolorrampv2dialog.cpp symbology-ng/qgsvectorcolorbrewercolorrampv2dialog.cpp symbology-ng/characterwidget.cpp symbology-ng/qgsstylev2exportimportdialog.cpp +symbology-ng/qgsellipsesymbollayerv2widget.cpp attributetable/qgsattributetablemodel.cpp attributetable/qgsattributetablememorymodel.cpp @@ -93,6 +94,7 @@ symbology-ng/characterwidget.h symbology-ng/qgspenstylecombobox.h symbology-ng/qgsbrushstylecombobox.h symbology-ng/qgsstylev2exportimportdialog.h +symbology-ng/qgsellipsesymbollayerv2widget.h attributetable/qgsattributetableview.h attributetable/qgsattributetablemodel.h diff --git a/src/gui/qgsannotationitem.cpp b/src/gui/qgsannotationitem.cpp index 639370cbb7b..cbeb58a43d1 100644 --- a/src/gui/qgsannotationitem.cpp +++ b/src/gui/qgsannotationitem.cpp @@ -220,7 +220,7 @@ void QgsAnnotationItem::drawMarkerSymbol( QPainter* p ) if ( mMarkerSymbol ) { mMarkerSymbol->startRender( renderContext ); - mMarkerSymbol->renderPoint( QPointF( 0, 0 ), renderContext ); + mMarkerSymbol->renderPoint( QPointF( 0, 0 ), 0, renderContext ); mMarkerSymbol->stopRender( renderContext ); } } diff --git a/src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp b/src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp index 166e7313547..f4a97926538 100644 --- a/src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp +++ b/src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp @@ -122,7 +122,7 @@ QgsFeatureRendererV2* QgsCategorizedSymbolRendererV2Widget::renderer() void QgsCategorizedSymbolRendererV2Widget::changeCategorizedSymbol() { - QgsSymbolV2SelectorDialog dlg( mCategorizedSymbol, mStyle, this ); + QgsSymbolV2SelectorDialog dlg( mCategorizedSymbol, mStyle, mLayer, this ); if ( !dlg.exec() ) return; @@ -207,7 +207,7 @@ void QgsCategorizedSymbolRendererV2Widget::changeCategorySymbol() int catIdx = mRenderer->categoryIndexForValue( k ); QgsSymbolV2* newSymbol = mRenderer->categories()[catIdx].symbol()->clone(); - QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, this ); + QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, mLayer, this ); if ( !dlg.exec() ) { delete newSymbol; diff --git a/src/gui/symbology-ng/qgsellipsesymbollayerv2widget.cpp b/src/gui/symbology-ng/qgsellipsesymbollayerv2widget.cpp new file mode 100644 index 00000000000..f54aa1d75d9 --- /dev/null +++ b/src/gui/symbology-ng/qgsellipsesymbollayerv2widget.cpp @@ -0,0 +1,278 @@ +#include "qgsellipsesymbollayerv2widget.h" +#include "qgsellipsesymbollayerv2.h" +#include "qgsmaplayerregistry.h" +#include "qgsvectorlayer.h" +#include + +QgsEllipseSymbolLayerV2Widget::QgsEllipseSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent ): QgsSymbolLayerV2Widget( parent, vl ) +{ + setupUi( this ); + QStringList names; + names << "circle" << "rectangle" << "cross" << "triangle"; + QSize iconSize = mShapeListWidget->iconSize(); + + QStringList::const_iterator nameIt = names.constBegin(); + for(; nameIt != names.constEnd(); ++nameIt ) + { + QgsEllipseSymbolLayerV2* lyr = new QgsEllipseSymbolLayerV2(); + lyr->setSymbolName( *nameIt ); + lyr->setOutlineColor( QColor( 0, 0, 0 ) ); + lyr->setFillColor( QColor( 200, 200, 200 ) ); + lyr->setSymbolWidth(4); + lyr->setSymbolHeight(2); + QIcon icon = QgsSymbolLayerV2Utils::symbolLayerPreviewIcon( lyr, QgsSymbolV2::MM, iconSize ); + QListWidgetItem* item = new QListWidgetItem( icon, "", mShapeListWidget ); + item->setToolTip( *nameIt ); + item->setData( Qt::UserRole, *nameIt ); + delete lyr; + } + + blockComboSignals( true ); + fillDataDefinedComboBoxes(); + blockComboSignals( false ); +} + +void QgsEllipseSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer ) +{ + if( layer->layerType() != "EllipseMarker" ) + { + return; + } + + mLayer = static_cast( layer ); + mWidthSpinBox->setValue( mLayer->symbolWidth() ); + mHeightSpinBox->setValue( mLayer->symbolHeight() ); + mRotationSpinBox->setValue( mLayer->angle() ); + mOutlineWidthSpinBox->setValue( mLayer->outlineWidth() ); + + QList symbolItemList = mShapeListWidget->findItems( mLayer->symbolName(), Qt::MatchExactly ); + if( symbolItemList.size() > 0 ) + { + mShapeListWidget->setCurrentItem( symbolItemList.at( 0 ) ); + } + + //set combo entries to current values + blockComboSignals( true ); + if( mLayer ) + { + if( mLayer->widthField().first != -1 ) + { + mDDSymbolWidthComboBox->setCurrentIndex( mDDSymbolWidthComboBox->findText( mLayer->widthField().second ) ); + } + if( mLayer->heightField().first != -1 ) + { + mDDSymbolHeightComboBox->setCurrentIndex( mDDSymbolHeightComboBox->findText( mLayer->heightField().second ) ); + } + if( mLayer->rotationField().first != -1 ) + { + mDDRotationComboBox->setCurrentIndex( mDDRotationComboBox->findText( mLayer->rotationField().second ) ); + } + if( mLayer->outlineWidthField().first != -1 ) + { + mDDOutlineWidthComboBox->setCurrentIndex( mDDOutlineWidthComboBox->findText( mLayer->outlineWidthField().second ) ); + } + if( mLayer->fillColorField().first != -1 ) + { + mDDFillColorComboBox->setCurrentIndex( mDDFillColorComboBox->findText( mLayer->fillColorField().second ) ); + } + if( mLayer->outlineColorField().first != -1 ) + { + mDDOutlineColorComboBox->setCurrentIndex( mDDOutlineColorComboBox->findText( mLayer->outlineColorField().second ) ); + } + if( mLayer->symbolNameField().first != -1 ) + { + mDDShapeComboBox->setCurrentIndex( mDDShapeComboBox->findText( mLayer->symbolNameField().second ) ); + } + } + blockComboSignals( false ); +} + +QgsSymbolLayerV2* QgsEllipseSymbolLayerV2Widget::symbolLayer() +{ + return mLayer; +} + +void QgsEllipseSymbolLayerV2Widget::on_mShapeListWidget_itemSelectionChanged() +{ + if( mLayer ) + { + QListWidgetItem* item = mShapeListWidget->currentItem(); + if( item ) + { + mLayer->setSymbolName( item->data( Qt::UserRole ).toString() ); + emit changed(); + } + } +} + +void QgsEllipseSymbolLayerV2Widget::on_mWidthSpinBox_valueChanged( double d ) +{ + if( mLayer ) + { + mLayer->setSymbolWidth( d ); + emit changed(); + } +} + +void QgsEllipseSymbolLayerV2Widget::on_mHeightSpinBox_valueChanged( double d ) +{ + if( mLayer ) + { + mLayer->setSymbolHeight( d ); + emit changed(); + } +} + +void QgsEllipseSymbolLayerV2Widget::on_mRotationSpinBox_valueChanged( double d ) +{ + if( mLayer ) + { + mLayer->setAngle( d ); + emit changed(); + } +} + +void QgsEllipseSymbolLayerV2Widget::on_mOutlineWidthSpinBox_valueChanged( double d ) +{ + if( mLayer ) + { + mLayer->setOutlineWidth( d ); + emit changed(); + } +} + +void QgsEllipseSymbolLayerV2Widget::on_btnChangeColorBorder_clicked() +{ + if( mLayer ) + { + QColor newColor = QColorDialog::getColor( mLayer->outlineColor() ); + if( newColor.isValid() ) + { + mLayer->setOutlineColor( newColor ); + emit changed(); + } + } +} + +void QgsEllipseSymbolLayerV2Widget::on_btnChangeColorFill_clicked() +{ + if( mLayer ) + { + QColor newColor = QColorDialog::getColor( mLayer->fillColor() ); + if( newColor.isValid() ) + { + mLayer->setFillColor( newColor ); + emit changed(); + } + } +} + +void QgsEllipseSymbolLayerV2Widget::fillDataDefinedComboBoxes() +{ + mDDSymbolWidthComboBox->clear(); + mDDSymbolWidthComboBox->addItem( "", -1 ); + mDDSymbolHeightComboBox->clear(); + mDDSymbolHeightComboBox->addItem( "", -1 ); + mDDRotationComboBox->clear(); + mDDRotationComboBox->addItem( "", -1 ); + mDDOutlineWidthComboBox->clear(); + mDDOutlineWidthComboBox->addItem( "", -1 ); + mDDFillColorComboBox->clear(); + mDDFillColorComboBox->addItem( "", -1 ); + mDDOutlineColorComboBox->clear(); + mDDOutlineColorComboBox->addItem( "", -1 ); + mDDShapeComboBox->clear(); + mDDShapeComboBox->addItem( "", -1 ); + + if( mVectorLayer ) + { + const QgsFieldMap& fm =mVectorLayer->pendingFields(); + QgsFieldMap::const_iterator fieldIt = fm.constBegin(); + for(; fieldIt != fm.constEnd(); ++fieldIt ) + { + QString fieldName = fieldIt.value().name(); + int index = fieldIt.key(); + + mDDSymbolWidthComboBox->addItem( fieldName, index ); + mDDSymbolHeightComboBox->addItem( fieldName, index ); + mDDRotationComboBox->addItem( fieldName, index ); + mDDOutlineWidthComboBox->addItem( fieldName, index ); + mDDFillColorComboBox->addItem( fieldName, index ); + mDDOutlineColorComboBox->addItem( fieldName, index ); + mDDShapeComboBox->addItem( fieldName, index ); + } + } +} + +void QgsEllipseSymbolLayerV2Widget::on_mDDSymbolWidthComboBox_currentIndexChanged( int idx ) +{ + if( mLayer ) + { + mLayer->setWidthField( mDDSymbolWidthComboBox->itemData( idx ).toInt(), mDDSymbolWidthComboBox->itemText( idx ) ); + emit changed(); + } +} + +void QgsEllipseSymbolLayerV2Widget::on_mDDSymbolHeightComboBox_currentIndexChanged( int idx ) +{ + if( mLayer ) + { + mLayer->setHeightField( mDDSymbolHeightComboBox->itemData( idx ).toInt(), mDDSymbolHeightComboBox->itemText( idx )); + emit changed(); + } +} + +void QgsEllipseSymbolLayerV2Widget::on_mDDRotationComboBox_currentIndexChanged( int idx ) +{ + if( mLayer ) + { + mLayer->setRotationField( mDDRotationComboBox->itemData( idx ).toInt(), mDDRotationComboBox->itemText( idx ) ); + emit changed(); + } +} + +void QgsEllipseSymbolLayerV2Widget::on_mDDOutlineWidthComboBox_currentIndexChanged( int idx ) +{ + if( mLayer ) + { + mLayer->setOutlineWidthField( mDDOutlineWidthComboBox->itemData( idx ).toInt(), mDDOutlineWidthComboBox->itemText( idx ) ); + emit changed(); + } +} + +void QgsEllipseSymbolLayerV2Widget::on_mDDFillColorComboBox_currentIndexChanged( int idx ) +{ + if( mLayer ) + { + mLayer->setFillColorField( mDDFillColorComboBox->itemData( idx ).toInt(), mDDFillColorComboBox->itemText( idx ) ); + emit changed(); + } +} + +void QgsEllipseSymbolLayerV2Widget::on_mDDOutlineColorComboBox_currentIndexChanged( int idx ) +{ + if( mLayer ) + { + mLayer->setOutlineColorField( mDDOutlineColorComboBox->itemData( idx ).toInt(), mDDOutlineColorComboBox->itemText( idx ) ); + emit changed(); + } +} + +void QgsEllipseSymbolLayerV2Widget::on_mDDShapeComboBox_currentIndexChanged( int idx ) +{ + if( mLayer ) + { + mLayer->setSymbolNameField( mDDShapeComboBox->itemData( idx ).toInt(), mDDShapeComboBox->itemText( idx ) ); + } +} + +void QgsEllipseSymbolLayerV2Widget::blockComboSignals( bool block ) +{ + mDDSymbolWidthComboBox->blockSignals( block ); + mDDSymbolHeightComboBox->blockSignals( block ); + mDDRotationComboBox->blockSignals( block ); + mDDOutlineWidthComboBox->blockSignals( block ); + mDDFillColorComboBox->blockSignals( block ); + mDDOutlineColorComboBox->blockSignals( block); + mDDShapeComboBox->blockSignals( block ); +} diff --git a/src/gui/symbology-ng/qgsellipsesymbollayerv2widget.h b/src/gui/symbology-ng/qgsellipsesymbollayerv2widget.h new file mode 100644 index 00000000000..d302773593c --- /dev/null +++ b/src/gui/symbology-ng/qgsellipsesymbollayerv2widget.h @@ -0,0 +1,48 @@ +#ifndef QGSELLIPSESYMBOLLAYERV2WIDGET_H +#define QGSELLIPSESYMBOLLAYERV2WIDGET_H + +#include "ui_widget_ellipse.h" +#include "qgssymbollayerv2widget.h" + +class QgsEllipseSymbolLayerV2; + +class GUI_EXPORT QgsEllipseSymbolLayerV2Widget: public QgsSymbolLayerV2Widget, private Ui::WidgetEllipseBase +{ + Q_OBJECT + + public: + QgsEllipseSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent = 0 ); + + static QgsSymbolLayerV2Widget* create( const QgsVectorLayer* vl ) { return new QgsEllipseSymbolLayerV2Widget( vl ); } + + // from base class + virtual void setSymbolLayer( QgsSymbolLayerV2* layer ); + virtual QgsSymbolLayerV2* symbolLayer(); + + protected: + QgsEllipseSymbolLayerV2* mLayer; + + private: + void blockComboSignals( bool block ); + //insert available attributes for data defined symbolisation + void fillDataDefinedComboBoxes(); + + private slots: + void on_mShapeListWidget_itemSelectionChanged(); + void on_mWidthSpinBox_valueChanged( double d ); + void on_mHeightSpinBox_valueChanged( double d ); + void on_mRotationSpinBox_valueChanged( double d ); + void on_mOutlineWidthSpinBox_valueChanged( double d ); + void on_btnChangeColorBorder_clicked(); + void on_btnChangeColorFill_clicked(); + + void on_mDDSymbolWidthComboBox_currentIndexChanged( int idx ); + void on_mDDSymbolHeightComboBox_currentIndexChanged( int idx ); + void on_mDDRotationComboBox_currentIndexChanged( int idx ); + void on_mDDOutlineWidthComboBox_currentIndexChanged( int idx ); + void on_mDDFillColorComboBox_currentIndexChanged( int idx ); + void on_mDDOutlineColorComboBox_currentIndexChanged( int idx ); + void on_mDDShapeComboBox_currentIndexChanged( int idx ); +}; + +#endif // QGSELLIPSESYMBOLLAYERV2WIDGET_H diff --git a/src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp b/src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp index 745013acc30..34ad2f7c3b7 100644 --- a/src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp +++ b/src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp @@ -192,7 +192,7 @@ void QgsGraduatedSymbolRendererV2Widget::classifyGraduated() void QgsGraduatedSymbolRendererV2Widget::changeGraduatedSymbol() { - QgsSymbolV2SelectorDialog dlg( mGraduatedSymbol, mStyle, this ); + QgsSymbolV2SelectorDialog dlg( mGraduatedSymbol, mStyle, mLayer, this ); if ( !dlg.exec() ) return; @@ -275,7 +275,7 @@ void QgsGraduatedSymbolRendererV2Widget::changeRangeSymbol( int rangeIdx ) { QgsSymbolV2* newSymbol = mRenderer->ranges()[rangeIdx].symbol()->clone(); - QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, this ); + QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, mLayer, this ); if ( !dlg.exec() ) { delete newSymbol; diff --git a/src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp b/src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp index d1b12c375ca..74cd4fe7d9b 100644 --- a/src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp +++ b/src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp @@ -316,7 +316,7 @@ QgsRendererRulePropsDialog::QgsRendererRulePropsDialog( const QgsRuleBasedRender spinMaxScale->setValue( rule.scaleMaxDenom() ); } - QgsSymbolV2SelectorDialog* symbolSel = new QgsSymbolV2SelectorDialog( mRule.symbol(), style, this, true ); + QgsSymbolV2SelectorDialog* symbolSel = new QgsSymbolV2SelectorDialog( mRule.symbol(), style, mLayer, this, true ); QVBoxLayout* l = new QVBoxLayout; l->addWidget( symbolSel ); groupSymbol->setLayout( l ); diff --git a/src/gui/symbology-ng/qgssinglesymbolrendererv2widget.cpp b/src/gui/symbology-ng/qgssinglesymbolrendererv2widget.cpp index c59bbd92f79..0b536f4bd6b 100644 --- a/src/gui/symbology-ng/qgssinglesymbolrendererv2widget.cpp +++ b/src/gui/symbology-ng/qgssinglesymbolrendererv2widget.cpp @@ -39,7 +39,7 @@ QgsSingleSymbolRendererV2Widget::QgsSingleSymbolRendererV2Widget( QgsVectorLayer mSingleSymbol = mRenderer->symbol()->clone(); // setup ui - mSelector = new QgsSymbolV2SelectorDialog( mSingleSymbol, mStyle, NULL, true ); + mSelector = new QgsSymbolV2SelectorDialog( mSingleSymbol, mStyle, mLayer, NULL, true ); connect( mSelector, SIGNAL( symbolModified() ), this, SLOT( changeSingleSymbol() ) ); QVBoxLayout* layout = new QVBoxLayout; diff --git a/src/gui/symbology-ng/qgsstylev2managerdialog.cpp b/src/gui/symbology-ng/qgsstylev2managerdialog.cpp index 89acbceeaec..39c00fd3315 100644 --- a/src/gui/symbology-ng/qgsstylev2managerdialog.cpp +++ b/src/gui/symbology-ng/qgsstylev2managerdialog.cpp @@ -238,7 +238,7 @@ bool QgsStyleV2ManagerDialog::addSymbol() } // get symbol design - QgsSymbolV2PropertiesDialog dlg( symbol, this ); + QgsSymbolV2PropertiesDialog dlg( symbol, 0, this ); if ( dlg.exec() == 0 ) { delete symbol; @@ -384,7 +384,7 @@ bool QgsStyleV2ManagerDialog::editSymbol() QgsSymbolV2* symbol = mStyle->symbol( symbolName ); // let the user edit the symbol and update list when done - QgsSymbolV2PropertiesDialog dlg( symbol, this ); + QgsSymbolV2PropertiesDialog dlg( symbol, 0, this ); if ( dlg.exec() == 0 ) { delete symbol; diff --git a/src/gui/symbology-ng/qgssymbollayerv2widget.cpp b/src/gui/symbology-ng/qgssymbollayerv2widget.cpp index 742936ac8ec..6376446e6fe 100644 --- a/src/gui/symbology-ng/qgssymbollayerv2widget.cpp +++ b/src/gui/symbology-ng/qgssymbollayerv2widget.cpp @@ -23,8 +23,8 @@ -QgsSimpleLineSymbolLayerV2Widget::QgsSimpleLineSymbolLayerV2Widget( QWidget* parent ) - : QgsSymbolLayerV2Widget( parent ) +QgsSimpleLineSymbolLayerV2Widget::QgsSimpleLineSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent ) + : QgsSymbolLayerV2Widget( parent, vl ) { mLayer = NULL; @@ -161,8 +161,8 @@ void QgsSimpleLineSymbolLayerV2Widget::updatePatternIcon() /////////// -QgsSimpleMarkerSymbolLayerV2Widget::QgsSimpleMarkerSymbolLayerV2Widget( QWidget* parent ) - : QgsSymbolLayerV2Widget( parent ) +QgsSimpleMarkerSymbolLayerV2Widget::QgsSimpleMarkerSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent ) + : QgsSymbolLayerV2Widget( parent, vl ) { mLayer = NULL; @@ -289,8 +289,8 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setOffset() /////////// -QgsSimpleFillSymbolLayerV2Widget::QgsSimpleFillSymbolLayerV2Widget( QWidget* parent ) - : QgsSymbolLayerV2Widget( parent ) +QgsSimpleFillSymbolLayerV2Widget::QgsSimpleFillSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent ) + : QgsSymbolLayerV2Widget( parent, vl ) { mLayer = NULL; @@ -392,8 +392,8 @@ void QgsSimpleFillSymbolLayerV2Widget::offsetChanged() /////////// -QgsMarkerLineSymbolLayerV2Widget::QgsMarkerLineSymbolLayerV2Widget( QWidget* parent ) - : QgsSymbolLayerV2Widget( parent ) +QgsMarkerLineSymbolLayerV2Widget::QgsMarkerLineSymbolLayerV2Widget(const QgsVectorLayer* vl, QWidget* parent ) + : QgsSymbolLayerV2Widget( parent, vl ) { mLayer = NULL; @@ -449,7 +449,7 @@ void QgsMarkerLineSymbolLayerV2Widget::setInterval( double val ) void QgsMarkerLineSymbolLayerV2Widget::setMarker() { - QgsSymbolV2PropertiesDialog dlg( mLayer->subSymbol(), this ); + QgsSymbolV2PropertiesDialog dlg( mLayer->subSymbol(), mVectorLayer, this ); if ( dlg.exec() == 0 ) return; updateMarker(); @@ -498,8 +498,8 @@ void QgsMarkerLineSymbolLayerV2Widget::setPlacement() /////////// -QgsSvgMarkerSymbolLayerV2Widget::QgsSvgMarkerSymbolLayerV2Widget( QWidget* parent ) - : QgsSymbolLayerV2Widget( parent ) +QgsSvgMarkerSymbolLayerV2Widget::QgsSvgMarkerSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent ) + : QgsSymbolLayerV2Widget( parent, vl ) { mLayer = NULL; @@ -738,8 +738,8 @@ void QgsSvgMarkerSymbolLayerV2Widget::on_mBorderWidthSpinBox_valueChanged( doubl /////////////// -QgsLineDecorationSymbolLayerV2Widget::QgsLineDecorationSymbolLayerV2Widget( QWidget* parent ) - : QgsSymbolLayerV2Widget( parent ) +QgsLineDecorationSymbolLayerV2Widget::QgsLineDecorationSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent ) + : QgsSymbolLayerV2Widget( parent, vl ) { mLayer = NULL; @@ -794,7 +794,7 @@ void QgsLineDecorationSymbolLayerV2Widget::penWidthChanged() #include -QgsSVGFillSymbolLayerWidget::QgsSVGFillSymbolLayerWidget( QWidget* parent ): QgsSymbolLayerV2Widget( parent ) +QgsSVGFillSymbolLayerWidget::QgsSVGFillSymbolLayerWidget( const QgsVectorLayer* vl, QWidget* parent ): QgsSymbolLayerV2Widget( parent, vl ) { mLayer = 0; setupUi( this ); @@ -880,7 +880,7 @@ void QgsSVGFillSymbolLayerWidget::insertIcons() void QgsSVGFillSymbolLayerWidget::on_mChangeOutlinePushButton_clicked() { - QgsSymbolV2PropertiesDialog dlg( mLayer->subSymbol(), this ); + QgsSymbolV2PropertiesDialog dlg( mLayer->subSymbol(), mVectorLayer, this ); if ( dlg.exec() == QDialog::Rejected ) { return; @@ -910,8 +910,8 @@ void QgsSVGFillSymbolLayerWidget::updateOutlineIcon() ///////////// -QgsFontMarkerSymbolLayerV2Widget::QgsFontMarkerSymbolLayerV2Widget( QWidget* parent ) - : QgsSymbolLayerV2Widget( parent ) +QgsFontMarkerSymbolLayerV2Widget::QgsFontMarkerSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent ) + : QgsSymbolLayerV2Widget( parent, vl ) { mLayer = NULL; @@ -1011,8 +1011,8 @@ void QgsFontMarkerSymbolLayerV2Widget::setOffset() /////////////// -QgsCentroidFillSymbolLayerV2Widget::QgsCentroidFillSymbolLayerV2Widget( QWidget* parent ) - : QgsSymbolLayerV2Widget( parent ) +QgsCentroidFillSymbolLayerV2Widget::QgsCentroidFillSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent ) + : QgsSymbolLayerV2Widget( parent, vl ) { mLayer = NULL; @@ -1040,7 +1040,7 @@ QgsSymbolLayerV2* QgsCentroidFillSymbolLayerV2Widget::symbolLayer() void QgsCentroidFillSymbolLayerV2Widget::setMarker() { - QgsSymbolV2PropertiesDialog dlg( mLayer->subSymbol(), this ); + QgsSymbolV2PropertiesDialog dlg( mLayer->subSymbol(), mVectorLayer, this ); if ( dlg.exec() == 0 ) return; updateMarker(); diff --git a/src/gui/symbology-ng/qgssymbollayerv2widget.h b/src/gui/symbology-ng/qgssymbollayerv2widget.h index 59fd25a4c60..6c38f979065 100644 --- a/src/gui/symbology-ng/qgssymbollayerv2widget.h +++ b/src/gui/symbology-ng/qgssymbollayerv2widget.h @@ -5,6 +5,7 @@ #include class QgsSymbolLayerV2; +class QgsVectorLayer; class GUI_EXPORT QgsSymbolLayerV2Widget : public QWidget @@ -12,12 +13,15 @@ class GUI_EXPORT QgsSymbolLayerV2Widget : public QWidget Q_OBJECT public: - QgsSymbolLayerV2Widget( QWidget* parent ) : QWidget( parent ) {} + QgsSymbolLayerV2Widget( QWidget* parent, const QgsVectorLayer* vl = 0 ) : QWidget( parent ), mVectorLayer( vl ) {} virtual ~QgsSymbolLayerV2Widget() {} virtual void setSymbolLayer( QgsSymbolLayerV2* layer ) = 0; virtual QgsSymbolLayerV2* symbolLayer() = 0; + protected: + const QgsVectorLayer* mVectorLayer; + signals: void changed(); }; @@ -33,9 +37,9 @@ class GUI_EXPORT QgsSimpleLineSymbolLayerV2Widget : public QgsSymbolLayerV2Widge Q_OBJECT public: - QgsSimpleLineSymbolLayerV2Widget( QWidget* parent = NULL ); + QgsSimpleLineSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent = NULL ); - static QgsSymbolLayerV2Widget* create() { return new QgsSimpleLineSymbolLayerV2Widget(); } + static QgsSymbolLayerV2Widget* create( const QgsVectorLayer* vl ) { return new QgsSimpleLineSymbolLayerV2Widget( vl ); } // from base class virtual void setSymbolLayer( QgsSymbolLayerV2* layer ); @@ -68,9 +72,9 @@ class GUI_EXPORT QgsSimpleMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Wid Q_OBJECT public: - QgsSimpleMarkerSymbolLayerV2Widget( QWidget* parent = NULL ); + QgsSimpleMarkerSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent = NULL ); - static QgsSymbolLayerV2Widget* create() { return new QgsSimpleMarkerSymbolLayerV2Widget(); } + static QgsSymbolLayerV2Widget* create( const QgsVectorLayer* vl ) { return new QgsSimpleMarkerSymbolLayerV2Widget( vl ); } // from base class virtual void setSymbolLayer( QgsSymbolLayerV2* layer ); @@ -99,9 +103,9 @@ class GUI_EXPORT QgsSimpleFillSymbolLayerV2Widget : public QgsSymbolLayerV2Widge Q_OBJECT public: - QgsSimpleFillSymbolLayerV2Widget( QWidget* parent = NULL ); + QgsSimpleFillSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent = NULL ); - static QgsSymbolLayerV2Widget* create() { return new QgsSimpleFillSymbolLayerV2Widget(); } + static QgsSymbolLayerV2Widget* create( const QgsVectorLayer* vl ) { return new QgsSimpleFillSymbolLayerV2Widget( vl ); } // from base class virtual void setSymbolLayer( QgsSymbolLayerV2* layer ); @@ -131,9 +135,9 @@ class GUI_EXPORT QgsMarkerLineSymbolLayerV2Widget : public QgsSymbolLayerV2Widge Q_OBJECT public: - QgsMarkerLineSymbolLayerV2Widget( QWidget* parent = NULL ); + QgsMarkerLineSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent = NULL ); - static QgsSymbolLayerV2Widget* create() { return new QgsMarkerLineSymbolLayerV2Widget(); } + static QgsSymbolLayerV2Widget* create( const QgsVectorLayer* vl ) { return new QgsMarkerLineSymbolLayerV2Widget( vl ); } // from base class virtual void setSymbolLayer( QgsSymbolLayerV2* layer ); @@ -166,9 +170,9 @@ class GUI_EXPORT QgsSvgMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Widget Q_OBJECT public: - QgsSvgMarkerSymbolLayerV2Widget( QWidget* parent = NULL ); + QgsSvgMarkerSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent = NULL ); - static QgsSymbolLayerV2Widget* create() { return new QgsSvgMarkerSymbolLayerV2Widget(); } + static QgsSymbolLayerV2Widget* create( const QgsVectorLayer* vl ) { return new QgsSvgMarkerSymbolLayerV2Widget( vl ); } // from base class virtual void setSymbolLayer( QgsSymbolLayerV2* layer ); @@ -206,9 +210,9 @@ class GUI_EXPORT QgsLineDecorationSymbolLayerV2Widget : public QgsSymbolLayerV2W Q_OBJECT public: - QgsLineDecorationSymbolLayerV2Widget( QWidget* parent = NULL ); + QgsLineDecorationSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent = NULL ); - static QgsSymbolLayerV2Widget* create() { return new QgsLineDecorationSymbolLayerV2Widget(); } + static QgsSymbolLayerV2Widget* create( const QgsVectorLayer* vl ) { return new QgsLineDecorationSymbolLayerV2Widget( vl ); } // from base class virtual void setSymbolLayer( QgsSymbolLayerV2* layer ); @@ -233,9 +237,9 @@ class GUI_EXPORT QgsSVGFillSymbolLayerWidget : public QgsSymbolLayerV2Widget, pr Q_OBJECT public: - QgsSVGFillSymbolLayerWidget( QWidget* parent = NULL ); + QgsSVGFillSymbolLayerWidget( const QgsVectorLayer* vl, QWidget* parent = NULL ); - static QgsSymbolLayerV2Widget* create() { return new QgsSVGFillSymbolLayerWidget(); } + static QgsSymbolLayerV2Widget* create( const QgsVectorLayer* vl ) { return new QgsSVGFillSymbolLayerWidget( vl ); } // from base class virtual void setSymbolLayer( QgsSymbolLayerV2* layer ); @@ -270,9 +274,9 @@ class GUI_EXPORT QgsFontMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Widge Q_OBJECT public: - QgsFontMarkerSymbolLayerV2Widget( QWidget* parent = NULL ); + QgsFontMarkerSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent = NULL ); - static QgsSymbolLayerV2Widget* create() { return new QgsFontMarkerSymbolLayerV2Widget(); } + static QgsSymbolLayerV2Widget* create( const QgsVectorLayer* vl ) { return new QgsFontMarkerSymbolLayerV2Widget( vl ); } // from base class virtual void setSymbolLayer( QgsSymbolLayerV2* layer ); @@ -303,9 +307,9 @@ class GUI_EXPORT QgsCentroidFillSymbolLayerV2Widget : public QgsSymbolLayerV2Wid Q_OBJECT public: - QgsCentroidFillSymbolLayerV2Widget( QWidget* parent = NULL ); + QgsCentroidFillSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent = NULL ); - static QgsSymbolLayerV2Widget* create() { return new QgsCentroidFillSymbolLayerV2Widget(); } + static QgsSymbolLayerV2Widget* create( const QgsVectorLayer* vl ) { return new QgsCentroidFillSymbolLayerV2Widget( vl ); } // from base class virtual void setSymbolLayer( QgsSymbolLayerV2* layer ); diff --git a/src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp b/src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp index 27417245de7..d9e626a452b 100644 --- a/src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp +++ b/src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp @@ -12,6 +12,7 @@ #include "qgslogger.h" #include "qgssymbollayerv2widget.h" +#include "qgsellipsesymbollayerv2widget.h" #include "qgssymbolv2.h" //for the unit @@ -90,6 +91,7 @@ static void _initWidgetFunctions() _initWidgetFunction( "SimpleMarker", QgsSimpleMarkerSymbolLayerV2Widget::create ); _initWidgetFunction( "SvgMarker", QgsSvgMarkerSymbolLayerV2Widget::create ); _initWidgetFunction( "FontMarker", QgsFontMarkerSymbolLayerV2Widget::create ); + _initWidgetFunction( "EllipseMarker", QgsEllipseSymbolLayerV2Widget::create ); _initWidgetFunction( "SimpleFill", QgsSimpleFillSymbolLayerV2Widget::create ); _initWidgetFunction( "SVGFill", QgsSVGFillSymbolLayerWidget::create ); @@ -101,8 +103,8 @@ static void _initWidgetFunctions() ////////// -QgsSymbolV2PropertiesDialog::QgsSymbolV2PropertiesDialog( QgsSymbolV2* symbol, QWidget* parent ) - : QDialog( parent ), mSymbol( symbol ) +QgsSymbolV2PropertiesDialog::QgsSymbolV2PropertiesDialog( QgsSymbolV2* symbol, const QgsVectorLayer* vl, QWidget* parent ) + : QDialog( parent ), mSymbol( symbol ), mVectorLayer( vl ) { setupUi( this ); @@ -247,7 +249,7 @@ void QgsSymbolV2PropertiesDialog::loadPropertyWidgets() if ( am == NULL ) // check whether the metadata is assigned continue; - QgsSymbolLayerV2Widget* w = am->createSymbolLayerWidget(); + QgsSymbolLayerV2Widget* w = am->createSymbolLayerWidget( mVectorLayer ); if ( w == NULL ) // check whether the function returns correct widget continue; diff --git a/src/gui/symbology-ng/qgssymbolv2propertiesdialog.h b/src/gui/symbology-ng/qgssymbolv2propertiesdialog.h index 840f05ee092..2a9480726f3 100644 --- a/src/gui/symbology-ng/qgssymbolv2propertiesdialog.h +++ b/src/gui/symbology-ng/qgssymbolv2propertiesdialog.h @@ -7,6 +7,7 @@ class QgsSymbolV2; class QgsSymbolLayerV2; class QgsSymbolLayerV2Widget; +class QgsVectorLayer; class SymbolLayerItem; @@ -18,7 +19,7 @@ class GUI_EXPORT QgsSymbolV2PropertiesDialog : public QDialog, private Ui::DlgSy Q_OBJECT public: - QgsSymbolV2PropertiesDialog( QgsSymbolV2* symbol, QWidget* parent = NULL ); + QgsSymbolV2PropertiesDialog( QgsSymbolV2* symbol, const QgsVectorLayer* vl, QWidget* parent = NULL ); public slots: @@ -64,6 +65,8 @@ class GUI_EXPORT QgsSymbolV2PropertiesDialog : public QDialog, private Ui::DlgSy QgsSymbolV2* mSymbol; QMap mWidgets; + + const QgsVectorLayer* mVectorLayer; }; #endif diff --git a/src/gui/symbology-ng/qgssymbolv2selectordialog.cpp b/src/gui/symbology-ng/qgssymbolv2selectordialog.cpp index 45c5f677161..8aad0aa7760 100644 --- a/src/gui/symbology-ng/qgssymbolv2selectordialog.cpp +++ b/src/gui/symbology-ng/qgssymbolv2selectordialog.cpp @@ -18,8 +18,8 @@ #include #include -QgsSymbolV2SelectorDialog::QgsSymbolV2SelectorDialog( QgsSymbolV2* symbol, QgsStyleV2* style, QWidget* parent, bool embedded ) - : QDialog( parent ), mAdvancedMenu( NULL ) +QgsSymbolV2SelectorDialog::QgsSymbolV2SelectorDialog( QgsSymbolV2* symbol, QgsStyleV2* style, const QgsVectorLayer* vl, QWidget* parent, bool embedded ) + : QDialog( parent ), mAdvancedMenu( NULL ), mVectorLayer( vl ) { mStyle = style; mSymbol = symbol; @@ -162,7 +162,7 @@ void QgsSymbolV2SelectorDialog::updateSymbolInfo() void QgsSymbolV2SelectorDialog::changeSymbolProperties() { - QgsSymbolV2PropertiesDialog dlg( mSymbol, this ); + QgsSymbolV2PropertiesDialog dlg( mSymbol, mVectorLayer, this ); if ( !dlg.exec() ) return; diff --git a/src/gui/symbology-ng/qgssymbolv2selectordialog.h b/src/gui/symbology-ng/qgssymbolv2selectordialog.h index f130bca95cd..399e671b79d 100644 --- a/src/gui/symbology-ng/qgssymbolv2selectordialog.h +++ b/src/gui/symbology-ng/qgssymbolv2selectordialog.h @@ -8,6 +8,7 @@ class QgsStyleV2; class QgsSymbolV2; +class QgsVectorLayer; class QMenu; @@ -16,7 +17,7 @@ class GUI_EXPORT QgsSymbolV2SelectorDialog : public QDialog, private Ui::QgsSymb Q_OBJECT public: - QgsSymbolV2SelectorDialog( QgsSymbolV2* symbol, QgsStyleV2* style, QWidget* parent = NULL, bool embedded = false ); + QgsSymbolV2SelectorDialog( QgsSymbolV2* symbol, QgsStyleV2* style, const QgsVectorLayer* vl, QWidget* parent = NULL, bool embedded = false ); //! return menu for "advanced" button - create it if doesn't exist and show the advanced button QMenu* advancedMenu(); @@ -54,6 +55,7 @@ class GUI_EXPORT QgsSymbolV2SelectorDialog : public QDialog, private Ui::QgsSymb QgsStyleV2* mStyle; QgsSymbolV2* mSymbol; QMenu* mAdvancedMenu; + const QgsVectorLayer* mVectorLayer; }; #endif diff --git a/src/mapserver/qgswmsserver.cpp b/src/mapserver/qgswmsserver.cpp index 2f033786ad2..e1d81b632b9 100755 --- a/src/mapserver/qgswmsserver.cpp +++ b/src/mapserver/qgswmsserver.cpp @@ -1622,6 +1622,33 @@ QMap QgsWMSServer::applyRequestedLayerFilters( const QStringLi } mMapRenderer->setExtent( filterExtent ); } + + //No BBOX parameter in request. We use the union of the filtered layer + //to provide the functionality of zooming to selected records via (enhanced) WMS. + if( mMapRenderer && mMapRenderer->extent().isEmpty() ) + { + QgsRectangle filterExtent; + QMap::const_iterator filterIt = filterMap.constBegin(); + for(; filterIt != filterMap.constEnd(); ++filterIt ) + { + QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer( filterIt.key() ); + if( !mapLayer ) + { + continue; + } + + QgsRectangle layerExtent = mapLayer->extent(); + if( filterExtent.isEmpty() ) + { + filterExtent = layerExtent; + } + else + { + filterExtent.combineExtentWith( &layerExtent ); + } + } + mMapRenderer->setExtent( filterExtent ); + } } return filterMap; } diff --git a/src/plugins/point_displacement_renderer/qgspointdisplacementrenderer.cpp b/src/plugins/point_displacement_renderer/qgspointdisplacementrenderer.cpp index 91f31fead30..f324ae92a02 100644 --- a/src/plugins/point_displacement_renderer/qgspointdisplacementrenderer.cpp +++ b/src/plugins/point_displacement_renderer/qgspointdisplacementrenderer.cpp @@ -165,7 +165,7 @@ void QgsPointDisplacementRenderer::renderFeature( QgsFeature& feature, QgsRender { if ( mCenterSymbol ) { - mCenterSymbol->renderPoint( pt, context, layer, selected ); + mCenterSymbol->renderPoint( pt, &feature, context, layer, selected ); } else { @@ -174,7 +174,7 @@ void QgsPointDisplacementRenderer::renderFeature( QgsFeature& feature, QgsRender } //draw symbols on the circle - drawSymbols( context, symbolList, symbolPositions, selected ); + drawSymbols( feature, context, symbolList, symbolPositions, selected ); //and also the labels drawLabels( pt, symbolContext, labelPositions, labelAttributeList ); } @@ -511,7 +511,7 @@ void QgsPointDisplacementRenderer::drawCircle( double radiusPainterUnits, QgsSym p->drawArc( QRectF( centerPoint.x() - radiusPainterUnits, centerPoint.y() - radiusPainterUnits, 2 * radiusPainterUnits, 2 * radiusPainterUnits ), 0, 5760 ); } -void QgsPointDisplacementRenderer::drawSymbols( QgsRenderContext& context, const QList& symbolList, const QList& symbolPositions, bool selected ) +void QgsPointDisplacementRenderer::drawSymbols( QgsFeature& f, QgsRenderContext& context, const QList& symbolList, const QList& symbolPositions, bool selected ) { QList::const_iterator symbolPosIt = symbolPositions.constBegin(); QList::const_iterator symbolIt = symbolList.constBegin(); @@ -519,7 +519,7 @@ void QgsPointDisplacementRenderer::drawSymbols( QgsRenderContext& context, const { if ( *symbolIt ) { - ( *symbolIt )->renderPoint( *symbolPosIt, context, -1, selected ); + ( *symbolIt )->renderPoint( *symbolPosIt, &f, context, -1, selected ); } } } diff --git a/src/plugins/point_displacement_renderer/qgspointdisplacementrenderer.h b/src/plugins/point_displacement_renderer/qgspointdisplacementrenderer.h index 43b4198469f..b388723c5fe 100644 --- a/src/plugins/point_displacement_renderer/qgspointdisplacementrenderer.h +++ b/src/plugins/point_displacement_renderer/qgspointdisplacementrenderer.h @@ -143,7 +143,7 @@ class QgsPointDisplacementRenderer: public QgsFeatureRendererV2 //helper functions void calculateSymbolAndLabelPositions( const QPointF& centerPoint, int nPosition, double radius, double symbolDiagonal, QList& symbolPositions, QList& labelShifts ) const; void drawCircle( double radiusPainterUnits, QgsSymbolV2RenderContext& context, const QPointF& centerPoint, int nSymbols ); - void drawSymbols( QgsRenderContext& context, const QList& symbolList, const QList& symbolPositions, bool selected = false ); + void drawSymbols( QgsFeature& f, QgsRenderContext& context, const QList& symbolList, const QList& symbolPositions, bool selected = false ); void drawLabels( const QPointF& centerPoint, QgsSymbolV2RenderContext& context, const QList& labelShifts, const QStringList& labelList ); }; diff --git a/src/plugins/point_displacement_renderer/qgspointdisplacementrendererwidget.cpp b/src/plugins/point_displacement_renderer/qgspointdisplacementrendererwidget.cpp index 9971b09cb3a..cabece5fd6c 100644 --- a/src/plugins/point_displacement_renderer/qgspointdisplacementrendererwidget.cpp +++ b/src/plugins/point_displacement_renderer/qgspointdisplacementrendererwidget.cpp @@ -329,7 +329,7 @@ void QgsPointDisplacementRendererWidget::on_mCenterSymbolPushButton_clicked() return; } QgsMarkerSymbolV2* markerSymbol = dynamic_cast( mRenderer->centerSymbol()->clone() ); - QgsSymbolV2SelectorDialog dlg( markerSymbol, QgsStyleV2::defaultStyle(), this ); + QgsSymbolV2SelectorDialog dlg( markerSymbol, QgsStyleV2::defaultStyle(), mLayer, this ); if ( dlg.exec() == QDialog::Rejected ) { delete markerSymbol; diff --git a/src/ui/symbollayer/widget_ellipse.ui b/src/ui/symbollayer/widget_ellipse.ui new file mode 100644 index 00000000000..fbf33ec8fa0 --- /dev/null +++ b/src/ui/symbollayer/widget_ellipse.ui @@ -0,0 +1,248 @@ + + + WidgetEllipseBase + + + + 0 + 0 + 336 + 326 + + + + Form + + + + + + 0 + + + + Settings + + + + + + Border color + + + + + + + Change + + + + + + + Fill color + + + + + + + Change + + + + + + + Symbol width + + + + + + + 6 + + + 999999999.000000000000000 + + + + + + + Outline width + + + + + + + 6 + + + 999999999.000000000000000 + + + + + + + Symbol height + + + + + + + 6 + + + 999999999.000000000000000 + + + + + + + QAbstractItemView::DropOnly + + + + 20 + 20 + + + + QListView::Static + + + QListView::LeftToRight + + + QListView::Adjust + + + 4 + + + + 30 + 24 + + + + QListView::IconMode + + + true + + + true + + + + + + + + + + Rotation + + + + + + + + Data defined settings + + + + + + Symbol width + + + + + + + + + + Symbol height + + + + + + + + + + Outline width + + + + + + + + + + Fill color + + + + + + + + + + Outline color + + + + + + + + + + Shape + + + + + + + + + + + + + Rotation + + + + + + + + + + + + QgsColorButtonV2 + QPushButton +
qgscolorbutton.h
+
+
+ + +