Skip to content
Permalink
Browse files

[FEATURE][composer] Allow more control over appearance of composer ar…

…rows:

- Line can be styled using line symbol style dialog
- Arrow head fill and outline colors can be specified
- Arrow head outline width can be specified
  • Loading branch information
nyalldawson committed Aug 6, 2014
1 parent 3459413 commit fec27111ee30d97a63d9a203a0f2609cbd30fc20
@@ -12,45 +12,174 @@ class QgsComposerArrow: QgsComposerItem
SVGMarker
};

/**Constructor
* @param c parent composition
*/
QgsComposerArrow( QgsComposition* c );

/**Constructor
* @param startPoint start point for line
* @param stopPoint end point for line
* @param c parent composition
*/
QgsComposerArrow( const QPointF& startPoint, const QPointF& stopPoint, QgsComposition* c );

~QgsComposerArrow();

/** return correct graphics item type. Added in v1.7 */
/**Return composer item type.
* @note added in QGIS 1.7
*/
virtual int type() const;

/** \brief Reimplementation of QCanvasItem::paint - draw on canvas */
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );

/**Modifies position of start and endpoint and calls QgsComposerItem::setSceneRect*/
/**Modifies position of start and endpoint and calls QgsComposerItem::setSceneRect
*/
void setSceneRect( const QRectF& rectangle );

/**Sets the width of the arrow head in mm*/
/**Sets the width of the arrow head in mm
* @param width width of arrow head
* @see arrowHeadWidth
*/
void setArrowHeadWidth( double width );

/**Returns the width of the arrow head in mm
* @returns width of arrow head
* @see setArrowHeadWidth
*/
double arrowHeadWidth() const;

void setOutlineWidth( double width );
double outlineWidth() const;
/**Sets the pen width for drawing the line and arrow head
* @deprecated use setArrowHeadOutlineWidth or setLineSymbol instead
*/
void setOutlineWidth( double width ) /Deprecated/;

/**Returns the pen width for drawing the line and arrow head
* @deprecated use arrowHeadOutlineWidth or lineSymbol instead
*/
double outlineWidth() const /Deprecated/;

/**Sets the marker to draw at the start of the line
* @param svgPath file path for svg marker graphic to draw
* @see startMarker
* @see setEndMarker
*/
void setStartMarker( const QString& svgPath );

/**Returns the marker drawn at the start of the line
* @returns file path for svg marker graphic
* @see setStartMarker
* @see endMarker
*/
QString startMarker() const;

/**Sets the marker to draw at the end of the line
* @param svgPath file path for svg marker graphic to draw
* @see endMarker
* @see setStartMarker
*/
void setEndMarker( const QString& svgPath );

/**Returns the marker drawn at the end of the line
* @returns file path for svg marker graphic
* @see setEndMarker
* @see startMarker
*/
QString endMarker() const;

QColor arrowColor() const;
void setArrowColor( const QColor& c );
/**Returns the color for the line and arrow head
* @deprecated use arrowHeadOutlineColor, arrowHeadFillColor or lineStyle instead
*/
QColor arrowColor() const /Deprecated/;

/**Sets the color for the line and arrow head
* @deprecated use setArrowHeadOutlineColor, setArrowHeadFillColor or setLineStyle instead
*/
void setArrowColor( const QColor& c ) /Deprecated/;

/**Sets the color used to draw the outline around the arrow head.
* @param color arrow head outline color
* @see setArrowHeadFillColor
* @see arrowHeadFillColor
* @note added in 2.5
*/
QColor arrowHeadOutlineColor() const;

/**Returns the color used to draw outline around the the arrow head.
* @returns arrow head outline color
* @see arrowHeadFillColor
* @see setArrowHeadFillColor
* @note added in 2.5
*/
void setArrowHeadOutlineColor( const QColor& color );

/**Sets the color used to draw the arrow head.
* @param color arrow head color
* @see setArrowHeadFillColor
* @see arrowHeadOutlineColor
* @note added in 2.5
*/
QColor arrowHeadFillColor() const;

/**Returns the color used to draw the arrow head.
* @returns arrow head color
* @see arrowHeadColor
* @see setArrowHeadOutlineColor
* @note added in 2.5
*/
void setArrowHeadFillColor( const QColor& color );

/**Sets the pen width for the outline of the arrow head
* @param width pen width for arrow head outline
* @see arrowHeadOutlineWidth
* @see setArrowHeadOutlineColor
* @note added in 2.5
*/
void setArrowHeadOutlineWidth( const double width );

/**Returns the pen width for the outline of the arrow head
* @returns pen width for arrow head outline
* @see setArrowHeadOutlineWidth
* @see arrowHeadOutlineColor
* @note added in 2.5
*/
double arrowHeadOutlineWidth() const;

/**Sets the line symbol used for drawing the line portion of the arrow
* @param symbol line symbol
* @see lineSymbol
* @note added in 2.5
*/
void setLineSymbol( QgsLineSymbolV2* symbol );

/**Returns the line symbol used for drawing the line portion of the arrow
* @returns line symbol
* @see setLineSymbol
* @note added in 2.5
*/
QgsLineSymbolV2* lineSymbol();

/**Returns marker mode, which controls how the arrow endpoints are drawn
* @returns marker mode
* @see setMarkerMode
*/
MarkerMode markerMode() const;

/**Sets the marker mode, which controls how the arrow endpoints are drawn
* @param mode marker mode
* @see setMarkerMode
*/
void setMarkerMode( MarkerMode mode );

/** stores state in Dom element
* @param elem is Dom element corresponding to 'Composer' tag
/**Stores state in DOM element
* @param elem is DOM element corresponding to 'Composer' tag
* @param doc document
*/
bool writeXML( QDomElement& elem, QDomDocument & doc ) const;

/** sets state from Dom document
* @param itemElem is Dom node corresponding to item tag
/**Sets state from DOM document
* @param itemElem is DOM node corresponding to item tag
* @param doc is the document to read
*/
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
@@ -18,6 +18,9 @@
#include "qgscomposerarrowwidget.h"
#include "qgscomposerarrow.h"
#include "qgscomposeritemwidget.h"
#include "qgssymbolv2selectordialog.h"
#include "qgsstylev2.h"
#include "qgssymbolv2.h"
#include <QColorDialog>
#include <QFileDialog>
#include <QFileInfo>
@@ -58,8 +61,8 @@ void QgsComposerArrowWidget::on_mOutlineWidthSpinBox_valueChanged( double d )
return;
}

mArrow->beginCommand( tr( "Arrow outline width" ), QgsComposerMergeCommand::ArrowOutlineWidth );
mArrow->setOutlineWidth( d );
mArrow->beginCommand( tr( "Arrow head outline width" ), QgsComposerMergeCommand::ArrowOutlineWidth );
mArrow->setArrowHeadOutlineWidth( d );
mArrow->update();
mArrow->endCommand();
}
@@ -77,22 +80,37 @@ void QgsComposerArrowWidget::on_mArrowHeadWidthSpinBox_valueChanged( double d )
mArrow->endCommand();
}

void QgsComposerArrowWidget::on_mArrowColorButton_colorChanged( const QColor& newColor )
void QgsComposerArrowWidget::on_mArrowHeadFillColorButton_colorChanged( const QColor& newColor )
{
if ( !mArrow )
{
return;
}

mArrow->beginCommand( tr( "Arrow color changed" ) );
mArrow->setArrowColor( newColor );
mArrow->beginCommand( tr( "Arrow head fill color" ) );
mArrow->setArrowHeadFillColor( newColor );
mArrow->update();
mArrow->endCommand();
}

void QgsComposerArrowWidget::on_mArrowHeadOutlineColorButton_colorChanged( const QColor &newColor )
{
if ( !mArrow )
{
return;
}

mArrow->beginCommand( tr( "Arrow head outline color" ) );
mArrow->setArrowHeadOutlineColor( newColor );
mArrow->update();
mArrow->endCommand();
}

void QgsComposerArrowWidget::blockAllSignals( bool block )
{
mArrowColorButton->blockSignals( block );
mLineStyleButton->blockSignals( block );
mArrowHeadFillColorButton->blockSignals( block );
mArrowHeadOutlineColorButton->blockSignals( block );
mOutlineWidthSpinBox->blockSignals( block );
mArrowHeadWidthSpinBox->blockSignals( block );
mDefaultMarkerRadioButton->blockSignals( block );
@@ -112,10 +130,13 @@ void QgsComposerArrowWidget::setGuiElementValues()
}

blockAllSignals( true );
mArrowColorButton->setColor( mArrow->arrowColor() );
mArrowColorButton->setColorDialogTitle( tr( "Select arrow color" ) );
mArrowColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
mOutlineWidthSpinBox->setValue( mArrow->outlineWidth() );
mArrowHeadFillColorButton->setColor( mArrow->arrowHeadFillColor() );
mArrowHeadFillColorButton->setColorDialogTitle( tr( "Select arrow head fill color" ) );
mArrowHeadFillColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
mArrowHeadOutlineColorButton->setColor( mArrow->arrowHeadOutlineColor() );
mArrowHeadOutlineColorButton->setColorDialogTitle( tr( "Select arrow head outlnie color" ) );
mArrowHeadOutlineColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
mOutlineWidthSpinBox->setValue( mArrow->arrowHeadOutlineWidth() );
mArrowHeadWidthSpinBox->setValue( mArrow->arrowHeadWidth() );

QgsComposerArrow::MarkerMode mode = mArrow->markerMode();
@@ -134,6 +155,9 @@ void QgsComposerArrowWidget::setGuiElementValues()
}
mStartMarkerLineEdit->setText( mArrow->startMarker() );
mEndMarkerLineEdit->setText( mArrow->endMarker() );

updateLineSymbolMarker();

blockAllSignals( false );
}

@@ -270,3 +294,38 @@ void QgsComposerArrowWidget::on_mEndMarkerToolButton_clicked()
mArrow->endCommand();
}
}

void QgsComposerArrowWidget::on_mLineStyleButton_clicked()
{
if ( !mArrow )
{
return;
}

QgsLineSymbolV2* newSymbol = dynamic_cast<QgsLineSymbolV2*>( mArrow->lineSymbol()->clone() );
QgsSymbolV2SelectorDialog d( newSymbol, QgsStyleV2::defaultStyle(), 0 );

if ( d.exec() == QDialog::Accepted )
{
mArrow->beginCommand( tr( "Arrow line style changed" ) );
mArrow->setLineSymbol( newSymbol );
updateLineSymbolMarker();
mArrow->endCommand();
mArrow->update();
}
else
{
delete newSymbol;
}
}

void QgsComposerArrowWidget::updateLineSymbolMarker()
{
if ( !mArrow )
{
return;
}

QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( mArrow->lineSymbol(), mLineStyleButton->iconSize() );
mLineStyleButton->setIcon( icon );
}
@@ -40,17 +40,21 @@ class QgsComposerArrowWidget: public QgsComposerItemBaseWidget, private Ui::QgsC
/**Enables / disables the SVG line inputs*/
void enableSvgInputElements( bool enable );

void updateLineSymbolMarker();

private slots:
void on_mOutlineWidthSpinBox_valueChanged( double d );
void on_mArrowHeadWidthSpinBox_valueChanged( double d );
void on_mArrowColorButton_colorChanged( const QColor& newColor );
void on_mArrowHeadFillColorButton_colorChanged( const QColor& newColor );
void on_mArrowHeadOutlineColorButton_colorChanged( const QColor& newColor );
void on_mDefaultMarkerRadioButton_toggled( bool toggled );
void on_mNoMarkerRadioButton_toggled( bool toggled );
void on_mSvgMarkerRadioButton_toggled( bool toggled );
void on_mStartMarkerLineEdit_textChanged( const QString & text );
void on_mEndMarkerLineEdit_textChanged( const QString & text );
void on_mStartMarkerToolButton_clicked();
void on_mEndMarkerToolButton_clicked();
void on_mLineStyleButton_clicked();

void setGuiElementValues();
};

0 comments on commit fec2711

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