24 changes: 23 additions & 1 deletion src/core/composer/qgscomposershape.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <QBrush>
#include <QPen>

class QgsFillSymbolV2;

/**A composer items that draws common shapes (ellipse, triangle, rectangle)*/
class CORE_EXPORT QgsComposerShape: public QgsComposerItem
{
Expand Down Expand Up @@ -66,22 +68,42 @@ class CORE_EXPORT QgsComposerShape: public QgsComposerItem
/**Returns the radius for rounded rectangle corners*/
double cornerRadius() const { return mCornerRadius; };

/**Sets the QgsFillSymbolV2 used to draw the shape. Must also call setUseSymbolV2( true ) to
* enable drawing with a symbol.
* Note: added in version 2.1*/
void setShapeStyleSymbol( QgsFillSymbolV2* symbol );
/**Returns the QgsFillSymbolV2 used to draw the shape.
* Note: added in version 2.1*/
QgsFillSymbolV2* shapeStyleSymbol() { return mShapeStyleSymbol; }

/**Controls whether the shape should be drawn using a QgsFillSymbolV2.
* Note: Added in v2.1 */
void setUseSymbolV2( bool useSymbolV2 );

protected:
/* reimplement drawFrame, since it's not a rect, but a custom shape */
virtual void drawFrame( QPainter* p );
/* reimplement drawBackground, since it's not a rect, but a custom shape */
virtual void drawBackground( QPainter* p );


private:
/**Ellipse, rectangle or triangle*/
Shape mShape;

double mCornerRadius;

bool mUseSymbolV2;

QgsFillSymbolV2* mShapeStyleSymbol;

/* draws the custom shape */
void drawShape( QPainter* p );

/* draws the custom shape using symbol v2*/
void drawShapeUsingSymbol( QPainter* p );

/* creates the default shape symbol */
void createDefaultShapeStyleSymbol();

/**Returns a point on the line from startPoint to directionPoint that is a certain distance away from the starting point*/
QPointF pointOnLineWithDistance( const QPointF& startPoint, const QPointF& directionPoint, double distance ) const;
Expand Down
2 changes: 2 additions & 0 deletions src/core/composer/qgscomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,8 @@ void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocumen
QDomElement currentComposerShapeElem = composerShapeList.at( i ).toElement();
QgsComposerShape* newShape = new QgsComposerShape( this );
newShape->readXML( currentComposerShapeElem, doc );
//new shapes should default to symbol v2
newShape->setUseSymbolV2( true );
if ( pos )
{
if ( pasteInPlace )
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgscomposerview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ void QgsComposerView::addShape( Tool currentTool )
{
QgsComposerShape* composerShape = new QgsComposerShape( mRubberBandItem->transform().dx(), mRubberBandItem->transform().dy(), mRubberBandItem->rect().width(), mRubberBandItem->rect().height(), composition() );
composerShape->setShapeType( shape );
//new shapes use symbol v2 by default
composerShape->setUseSymbolV2( true );
composition()->addComposerShape( composerShape );
removeRubberBand();
emit actionFinished();
Expand Down
73 changes: 43 additions & 30 deletions src/ui/qgscomposershapewidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand Down Expand Up @@ -63,35 +72,39 @@
<bool>false</bool>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<item row="2" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Corner radius</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="mCornerRadiusSpinBox">
<property name="suffix">
<string> mm</string>
</property>
<property name="maximum">
<double>999.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QComboBox" name="mShapeComboBox"/>
</item>
</layout>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Corner radius</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="mCornerRadiusSpinBox">
<property name="suffix">
<string> mm</string>
</property>
<property name="maximum">
<double>999.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Style</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="mShapeStyleButton">
<property name="text">
<string>Change...</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QComboBox" name="mShapeComboBox"/>
</item>
</layout>
</widget>
Expand Down
26 changes: 26 additions & 0 deletions tests/src/core/testqgscomposershapes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include "qgscomposition.h"
#include "qgscompositionchecker.h"
#include "qgscomposershape.h"
#include "qgssymbolv2.h"
#include "qgssinglesymbolrendererv2.h"
#include "qgsfillsymbollayerv2.h"
#include <QObject>
#include <QtTest>
#include <QColor>
Expand All @@ -36,10 +39,13 @@ class TestQgsComposerShapes: public QObject
void triangle(); //test if triange shape is functioning
void ellipse(); //test if ellipse shape is functioning
void roundedRectangle(); //test if rounded rectangle shape is functioning
void symbolV2(); //test is styling shapes via symbolv2 is working

private:
QgsComposition* mComposition;
QgsComposerShape* mComposerShape;
QgsSimpleFillSymbolLayerV2* mSimpleFill;
QgsFillSymbolV2* mFillSymbol;
QString mReport;
};

Expand All @@ -55,6 +61,11 @@ void TestQgsComposerShapes::initTestCase()
mComposerShape->setBackgroundColor( QColor::fromRgb( 255, 150, 0 ) );
mComposition->addComposerShape( mComposerShape );

//setup simple fill
mSimpleFill = new QgsSimpleFillSymbolLayerV2();
mFillSymbol = new QgsFillSymbolV2();
mFillSymbol->changeSymbolLayer( 0, mSimpleFill );

mReport = "<h1>Composer Shape Tests</h1>\n";
}

Expand Down Expand Up @@ -116,5 +127,20 @@ void TestQgsComposerShapes::roundedRectangle()
mComposerShape->setCornerRadius( 0 );
}

void TestQgsComposerShapes::symbolV2()
{
mComposerShape->setShapeType( QgsComposerShape::Rectangle );

mSimpleFill->setColor( Qt::green );
mSimpleFill->setBorderColor( Qt::yellow );
mSimpleFill->setBorderWidth( 6 );

mComposerShape->setShapeStyleSymbol( mFillSymbol );
mComposerShape->setUseSymbolV2( true );

QgsCompositionChecker checker( "composershapes_symbolv2", mComposition );
QVERIFY( checker.testComposition( mReport ) );
}

QTEST_MAIN( TestQgsComposerShapes )
#include "moc_testqgscomposershapes.cxx"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.