Skip to content
Permalink
Browse files

started rotation / data defined rotation

  • Loading branch information
mhugent committed Jun 10, 2011
1 parent 45fcb78 commit 51ca548fa09f1445ca7c0b4d0772f61704846843
@@ -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<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/;
};
@@ -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/;
};

//////////
@@ -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:
@@ -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();
@@ -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;
@@ -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 );
@@ -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;
@@ -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() );
@@ -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"] );
@@ -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
@@ -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;
@@ -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;
@@ -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; }

@@ -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;
@@ -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 );
@@ -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 ) );
@@ -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 )
@@ -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();
@@ -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 );
@@ -187,6 +204,7 @@ void QgsEllipseSymbolLayerV2Widget::on_mDDSymbolWidthComboBox_currentIndexChange
if( mLayer )
{
mLayer->setWidthField( mDDSymbolWidthComboBox->itemData( idx ).toInt(), mDDSymbolWidthComboBox->itemText( idx ) );
emit changed();
}
}

@@ -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();
}
}

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

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

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

@@ -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);
@@ -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 );

0 comments on commit 51ca548

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