Skip to content

Commit

Permalink
started rotation / data defined rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jun 10, 2011
1 parent 45fcb78 commit 51ca548
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 27 deletions.
11 changes: 7 additions & 4 deletions python/core/symbology-ng-core.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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/;
};
Expand All @@ -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/;
};
Expand All @@ -807,7 +810,7 @@ public:
QgsFillSymbolV2(QgsSymbolLayerV2List layers /Transfer/ = QgsSymbolLayerV2List());

void setAngle( double angle );
void renderPolygon(const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context, int layer = -1, bool selected = false );
void renderPolygon(const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );

virtual QgsSymbolV2* clone() const /Factory/;
};
Expand Down Expand Up @@ -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/;
};

//////////
Expand Down
6 changes: 3 additions & 3 deletions python/gui/symbology-ng-gui.sip
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class QgsSymbolV2PropertiesDialog : QDialog //, private Ui::DlgSymbolV2Propertie
%End

public:
QgsSymbolV2PropertiesDialog(QgsSymbolV2* symbol, QWidget* parent = NULL);
QgsSymbolV2PropertiesDialog(QgsSymbolV2* symbol, const QgsVectorLayer*, QWidget* parent = NULL);


public slots:
Expand Down Expand Up @@ -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*, QWidget* parent = NULL, bool embedded = false);

protected:
void populateSymbolView();
Expand Down Expand Up @@ -106,7 +106,7 @@ class QgsSymbolLayerV2Widget : QWidget
%End

public:
QgsSymbolLayerV2Widget( QWidget* parent );
QgsSymbolLayerV2Widget( const QgsVectorLayer* vl, Widget* parent );
virtual ~QgsSymbolLayerV2Widget();

virtual void setSymbolLayer( QgsSymbolLayerV2* layer ) = 0;
Expand Down
34 changes: 29 additions & 5 deletions src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <QPainter>
#include <QSet>

QgsEllipseSymbolLayerV2::QgsEllipseSymbolLayerV2(): mSymbolName("circle"), mSymbolWidth(4), mSymbolHeight(3), mFillColor( Qt::black ), mOutlineColor( Qt::white )
QgsEllipseSymbolLayerV2::QgsEllipseSymbolLayerV2(): mSymbolName("circle"), mSymbolWidth(4), mSymbolHeight(3), mRotation(0), mFillColor( Qt::black ), mOutlineColor( Qt::white )
{
mPen.setColor( mOutlineColor );
mPen.setWidth( 1.0 );
Expand All @@ -14,6 +14,7 @@ QgsEllipseSymbolLayerV2::QgsEllipseSymbolLayerV2(): mSymbolName("circle"), mSymb

mWidthField.first = -1;
mHeightField.first = -1;
mRotationField.first = -1;
mOutlineWidthField.first = -1;
mFillColorField.first = -1;
mOutlineColorField.first = -1;
Expand All @@ -38,6 +39,10 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& propertie
{
layer->setSymbolHeight( properties["symbol_height"].toDouble() );
}
if( properties.contains("rotation") )
{
layer->setRotation( properties["rotation"].toDouble() );
}
if( properties.contains( "outline_width" ) )
{
layer->setOutlineWidth( properties["outline_width"].toDouble() );
Expand All @@ -60,6 +65,10 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& propertie
{
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"] );
Expand Down Expand Up @@ -113,9 +122,15 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend
QMatrix transform;
transform.translate( point.x() + off.x(), point.y() + off.y() );

p->save();
if( !doubleNear( mRotation, 0.0 ) )
{
p->rotate( mRotation );
}
p->setPen( mPen );
p->setBrush( mBrush );
p->drawPath( transform.map( mPainterPath ) );
p->restore();
}

QString QgsEllipseSymbolLayerV2::layerType() const
Expand Down Expand Up @@ -146,13 +161,16 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::clone() const
QgsStringMap QgsEllipseSymbolLayerV2::properties() const
{
QgsStringMap map;
map["symbol_name"] = mSymbolName;
map["symbol_name"] = mSymbolName;
map["symbol_width"] = QString::number( mSymbolWidth );
map["height_index"] = QString::number( mHeightField.first );
map["height_field"] = mHeightField.second;
map["symbol_height"] = QString::number( mSymbolHeight );
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["rotation"] = QString::number( mRotation );
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;
Expand Down Expand Up @@ -257,6 +275,12 @@ void QgsEllipseSymbolLayerV2::setHeightField( int index, const QString& field )
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;
Expand Down
20 changes: 16 additions & 4 deletions src/core/symbology-ng/qgsellipsesymbollayerv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ class QgsEllipseSymbolLayerV2: public QgsMarkerSymbolLayerV2
void setHeightField( int index, const QString& field );
const QPair<int, QString>& heightField() const { return mHeightField; }

void setRotation( double r ){ mRotation = r; }
double rotation() const { return mRotation; }

void setRotationField( int index, const QString& field );
const QPair<int, QString>& rotationField() const { return mRotationField; }

void setOutlineWidth( double w ){ mOutlineWidth = w; }
double outlineWidth() const { return mOutlineWidth; }

Expand All @@ -58,18 +64,24 @@ class QgsEllipseSymbolLayerV2: public QgsMarkerSymbolLayerV2
private:
QString mSymbolName;
double mSymbolWidth;
double mSymbolHeight;
double mRotation;
QColor mFillColor;
QColor mOutlineColor;
double mOutlineWidth;

/**Take width from attribute (-1 if fixed width)*/
QPair<int, QString> mWidthField;
double mSymbolHeight;
/**Take height from attribute (-1 if fixed height)*/
QPair<int, QString> mHeightField;
double mOutlineWidth;
/**Take symbol rotation from attribute (-1 if fixed rotation)*/
QPair<int, QString> mRotationField;
/**Take outline width from attribute (-1 if fixed outline width)*/
QPair<int, QString> mOutlineWidthField;
QColor mFillColor;

/**Take fill color from attribute (-1 if fixed fill color)*/
QPair<int, QString> mFillColorField;
QColor mOutlineColor;

/**Take outline color from attribute (-1 if fixed outline color)*/
QPair<int, QString> mOutlineColorField;
QPainterPath mPainterPath;
Expand Down
32 changes: 32 additions & 0 deletions src/gui/symbology-ng/qgsellipsesymbollayerv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void QgsEllipseSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
mLayer = static_cast<QgsEllipseSymbolLayerV2*>( layer );
mWidthSpinBox->setValue( mLayer->symbolWidth() );
mHeightSpinBox->setValue( mLayer->symbolHeight() );
mRotationSpinBox->setValue( mLayer->rotation() );
mOutlineWidthSpinBox->setValue( mLayer->outlineWidth() );

QList<QListWidgetItem *> symbolItemList = mShapeListWidget->findItems( mLayer->symbolName(), Qt::MatchExactly );
Expand All @@ -61,6 +62,10 @@ void QgsEllipseSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
{
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 ) );
Expand Down Expand Up @@ -113,6 +118,15 @@ void QgsEllipseSymbolLayerV2Widget::on_mHeightSpinBox_valueChanged( double d )
}
}

void QgsEllipseSymbolLayerV2Widget::on_mRotationSpinBox_valueChanged( double d )
{
if( mLayer )
{
mLayer->setRotation( d );
emit changed();
}
}

void QgsEllipseSymbolLayerV2Widget::on_mOutlineWidthSpinBox_valueChanged( double d )
{
if( mLayer )
Expand Down Expand Up @@ -154,6 +168,8 @@ void QgsEllipseSymbolLayerV2Widget::fillDataDefinedComboBoxes()
mDDSymbolWidthComboBox->addItem( "", -1 );
mDDSymbolHeightComboBox->clear();
mDDSymbolHeightComboBox->addItem( "", -1 );
mDDRotationComboBox->clear();
mDDRotationComboBox->addItem( "", -1 );
mDDOutlineWidthComboBox->clear();
mDDOutlineWidthComboBox->addItem( "", -1 );
mDDFillColorComboBox->clear();
Expand All @@ -174,6 +190,7 @@ void QgsEllipseSymbolLayerV2Widget::fillDataDefinedComboBoxes()

mDDSymbolWidthComboBox->addItem( fieldName, index );
mDDSymbolHeightComboBox->addItem( fieldName, index );
mDDRotationComboBox->addItem( fieldName, index );
mDDOutlineWidthComboBox->addItem( fieldName, index );
mDDFillColorComboBox->addItem( fieldName, index );
mDDOutlineColorComboBox->addItem( fieldName, index );
Expand All @@ -187,6 +204,7 @@ void QgsEllipseSymbolLayerV2Widget::on_mDDSymbolWidthComboBox_currentIndexChange
if( mLayer )
{
mLayer->setWidthField( mDDSymbolWidthComboBox->itemData( idx ).toInt(), mDDSymbolWidthComboBox->itemText( idx ) );
emit changed();
}
}

Expand All @@ -195,6 +213,16 @@ void QgsEllipseSymbolLayerV2Widget::on_mDDSymbolHeightComboBox_currentIndexChang
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();
}
}

Expand All @@ -203,6 +231,7 @@ void QgsEllipseSymbolLayerV2Widget::on_mDDOutlineWidthComboBox_currentIndexChang
if( mLayer )
{
mLayer->setOutlineWidthField( mDDOutlineWidthComboBox->itemData( idx ).toInt(), mDDOutlineWidthComboBox->itemText( idx ) );
emit changed();
}
}

Expand All @@ -211,6 +240,7 @@ void QgsEllipseSymbolLayerV2Widget::on_mDDFillColorComboBox_currentIndexChanged(
if( mLayer )
{
mLayer->setFillColorField( mDDFillColorComboBox->itemData( idx ).toInt(), mDDFillColorComboBox->itemText( idx ) );
emit changed();
}
}

Expand All @@ -219,6 +249,7 @@ void QgsEllipseSymbolLayerV2Widget::on_mDDOutlineColorComboBox_currentIndexChang
if( mLayer )
{
mLayer->setOutlineColorField( mDDOutlineColorComboBox->itemData( idx ).toInt(), mDDOutlineColorComboBox->itemText( idx ) );
emit changed();
}
}

Expand All @@ -231,6 +262,7 @@ void QgsEllipseSymbolLayerV2Widget::blockComboSignals( bool block )
{
mDDSymbolWidthComboBox->blockSignals( block );
mDDSymbolHeightComboBox->blockSignals( block );
mDDRotationComboBox->blockSignals( block );
mDDOutlineWidthComboBox->blockSignals( block );
mDDFillColorComboBox->blockSignals( block );
mDDOutlineColorComboBox->blockSignals( block);
Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology-ng/qgsellipsesymbollayerv2widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ class GUI_EXPORT QgsEllipseSymbolLayerV2Widget: public QgsSymbolLayerV2Widget, p
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 );
Expand Down
Loading

0 comments on commit 51ca548

Please sign in to comment.