Skip to content
Permalink
Browse files

[FEATURE][composer] Allow setting line join and cap style for scalebars

  • Loading branch information
nyalldawson committed Apr 14, 2014
1 parent 80b7021 commit 103b3b4e9aff828cb4b640dced4e079f43c139c4
@@ -91,6 +91,34 @@ class QgsComposerScaleBar: QgsComposerItem

/**@note: this method was added in version 1.9*/
void setUnits( ScaleBarUnits u );

/** Returns the join style used for drawing lines in the scalebar
* @returns Join style for lines
* @note introduced in 2.3
* @see setLineJoinStyle
*/
Qt::PenJoinStyle lineJoinStyle() const;
/** Sets join style used when drawing the lines in the scalebar
* @param style Join style for lines
* @returns nothing
* @note introduced in 2.3
* @see lineJoinStyle
*/
void setLineJoinStyle( Qt::PenJoinStyle style );

/** Returns the cap style used for drawing lines in the scalebar
* @returns Cap style for lines
* @note introduced in 2.3
* @see setLineCapStyle
*/
Qt::PenCapStyle lineCapStyle() const;
/** Sets cap style used when drawing the lines in the scalebar
* @param style Cap style for lines
* @returns nothing
* @note introduced in 2.3
* @see lineCapStyle
*/
void setLineCapStyle( Qt::PenCapStyle style );

/**Apply default settings*/
void applyDefaultSettings();
@@ -169,6 +169,8 @@ void QgsComposerScaleBarWidget::setGuiElements()
mLabelBarSpaceSpinBox->setValue( mComposerScaleBar->labelBarSpace() );
mBoxSizeSpinBox->setValue( mComposerScaleBar->boxContentSpace() );
mUnitLabelLineEdit->setText( mComposerScaleBar->unitLabeling() );
mLineJoinStyleCombo->setPenJoinStyle( mComposerScaleBar->lineJoinStyle() );
mLineCapStyleCombo->setPenCapStyle( mComposerScaleBar->lineCapStyle() );

//map combo box
if ( mComposerScaleBar->composerMap() )
@@ -462,16 +464,29 @@ void QgsComposerScaleBarWidget::toggleStyleSpecificControls( const QString& styl
mLineWidthSpinBox->setEnabled( false );
mColorPushButton->setEnabled( false );
mStrokeColorPushButton->setEnabled( false );
mLineJoinStyleCombo->setEnabled( false );
mLineCapStyleCombo->setEnabled( false );
}
else
{
//Enable all controls
//Enable controls
mGroupBoxUnits->setEnabled( true );
mGroupBoxSegments->setEnabled( true );
mLabelBarSpaceSpinBox->setEnabled( true );
mLineWidthSpinBox->setEnabled( true );
mColorPushButton->setEnabled( true );
mStrokeColorPushButton->setEnabled( true );
if ( style == "Single Box" || style == "Double Box" )
{
mLineJoinStyleCombo->setEnabled( true );
mLineCapStyleCombo->setEnabled( false );
}
else
{
mLineJoinStyleCombo->setEnabled( false );
mLineCapStyleCombo->setEnabled( true );
}

}
}

@@ -583,6 +598,8 @@ void QgsComposerScaleBarWidget::blockMemberSignals( bool block )
mBoxSizeSpinBox->blockSignals( block );
mAlignmentComboBox->blockSignals( block );
mUnitsComboBox->blockSignals( block );
mLineJoinStyleCombo->blockSignals( block );
mLineCapStyleCombo->blockSignals( block );
}

void QgsComposerScaleBarWidget::connectUpdateSignal()
@@ -600,3 +617,29 @@ void QgsComposerScaleBarWidget::disconnectUpdateSignal()
QObject::disconnect( mComposerScaleBar, SIGNAL( itemChanged() ), this, SLOT( setGuiElements() ) );
}
}

void QgsComposerScaleBarWidget::on_mLineJoinStyleCombo_currentIndexChanged( int index )
{
Q_UNUSED( index );
if ( !mComposerScaleBar )
{
return;
}

mComposerScaleBar->beginCommand( tr( "Scalebar line join style" ) );
mComposerScaleBar->setLineJoinStyle( mLineJoinStyleCombo->penJoinStyle() );
mComposerScaleBar->endCommand();
}

void QgsComposerScaleBarWidget::on_mLineCapStyleCombo_currentIndexChanged( int index )
{
Q_UNUSED( index );
if ( !mComposerScaleBar )
{
return;
}

mComposerScaleBar->beginCommand( tr( "Scalebar line cap style" ) );
mComposerScaleBar->setLineCapStyle( mLineCapStyleCombo->penCapStyle() );
mComposerScaleBar->endCommand();
}
@@ -50,6 +50,8 @@ class QgsComposerScaleBarWidget: public QWidget, private Ui::QgsComposerScaleBar
void on_mBoxSizeSpinBox_valueChanged( double d );
void on_mAlignmentComboBox_currentIndexChanged( int index );
void on_mUnitsComboBox_currentIndexChanged( int index );
void on_mLineJoinStyleCombo_currentIndexChanged( int index );
void on_mLineCapStyleCombo_currentIndexChanged( int index );

private slots:
void setGuiElements();
@@ -26,6 +26,7 @@
#include "qgsticksscalebarstyle.h"
#include "qgsrectangle.h"
#include "qgsproject.h"
#include "qgssymbollayerv2utils.h"
#include <QDomDocument>
#include <QDomElement>
#include <QFontMetricsF>
@@ -42,6 +43,8 @@ QgsComposerScaleBar::QgsComposerScaleBar( QgsComposition* composition )
, mSegmentMillimeters( 0.0 )
, mAlignment( Left )
, mUnits( MapUnits )
, mLineJoinStyle( Qt::MiterJoin )
, mLineCapStyle( Qt::SquareCap )
{
applyDefaultSettings();
applyDefaultSize();
@@ -228,6 +231,32 @@ void QgsComposerScaleBar::setUnits( ScaleBarUnits u )
emit itemChanged();
}

void QgsComposerScaleBar::setLineJoinStyle( Qt::PenJoinStyle style )
{
if ( mLineJoinStyle == style )
{
//no change
return;
}
mLineJoinStyle = style;
mPen.setJoinStyle( mLineJoinStyle );
update();
emit itemChanged();
}

void QgsComposerScaleBar::setLineCapStyle( Qt::PenCapStyle style )
{
if ( mLineCapStyle == style )
{
//no change
return;
}
mLineCapStyle = style;
mPen.setCapStyle( mLineCapStyle );
update();
emit itemChanged();
}

void QgsComposerScaleBar::applyDefaultSettings()
{
mNumSegments = 2;
@@ -242,7 +271,8 @@ void QgsComposerScaleBar::applyDefaultSettings()
mHeight = 3;

mPen = QPen( QColor( 0, 0, 0 ) );
mPen.setJoinStyle( Qt::MiterJoin );
mPen.setJoinStyle( mLineJoinStyle );
mPen.setCapStyle( mLineCapStyle );
mPen.setWidthF( 1.0 );

mBrush.setColor( QColor( 0, 0, 0 ) );
@@ -487,6 +517,8 @@ bool QgsComposerScaleBar::writeXML( QDomElement& elem, QDomDocument & doc ) cons
composerScaleBarElem.setAttribute( "outlineWidth", QString::number( mPen.widthF() ) );
composerScaleBarElem.setAttribute( "unitLabel", mUnitLabeling );
composerScaleBarElem.setAttribute( "units", mUnits );
composerScaleBarElem.setAttribute( "lineJoinStyle", QgsSymbolLayerV2Utils::encodePenJoinStyle( mLineJoinStyle ) );
composerScaleBarElem.setAttribute( "lineCapStyle", QgsSymbolLayerV2Utils::encodePenCapStyle( mLineCapStyle ) );

//style
if ( mStyle )
@@ -529,6 +561,10 @@ bool QgsComposerScaleBar::readXML( const QDomElement& itemElem, const QDomDocume
mNumMapUnitsPerScaleBarUnit = itemElem.attribute( "numMapUnitsPerScaleBarUnit", "1.0" ).toDouble();
mPen.setWidthF( itemElem.attribute( "outlineWidth", "1.0" ).toDouble() );
mUnitLabeling = itemElem.attribute( "unitLabel" );
mLineJoinStyle = QgsSymbolLayerV2Utils::decodePenJoinStyle( itemElem.attribute( "lineJoinStyle", "miter" ) );
mPen.setJoinStyle( mLineJoinStyle );
mLineCapStyle = QgsSymbolLayerV2Utils::decodePenCapStyle( itemElem.attribute( "lineCapStyle", "square" ) );
mPen.setCapStyle( mLineCapStyle );
QString fontString = itemElem.attribute( "font", "" );
if ( !fontString.isEmpty() )
{
@@ -594,4 +630,3 @@ void QgsComposerScaleBar::correctXPositionAlignment( double width, double widthA
}
}


@@ -115,6 +115,34 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem
/**@note: this method was added in version 1.9*/
void setUnits( ScaleBarUnits u );

/** Returns the join style used for drawing lines in the scalebar
* @returns Join style for lines
* @note introduced in 2.3
* @see setLineJoinStyle
*/
Qt::PenJoinStyle lineJoinStyle() const { return mLineJoinStyle; }
/** Sets join style used when drawing the lines in the scalebar
* @param style Join style for lines
* @returns nothing
* @note introduced in 2.3
* @see lineJoinStyle
*/
void setLineJoinStyle( Qt::PenJoinStyle style );

/** Returns the cap style used for drawing lines in the scalebar
* @returns Cap style for lines
* @note introduced in 2.3
* @see setLineCapStyle
*/
Qt::PenCapStyle lineCapStyle() const { return mLineCapStyle; }
/** Sets cap style used when drawing the lines in the scalebar
* @param style Cap style for lines
* @returns nothing
* @note introduced in 2.3
* @see lineCapStyle
*/
void setLineCapStyle( Qt::PenCapStyle style );

/**Apply default settings*/
void applyDefaultSettings();
/**Apply default size (scale bar 1/5 of map item width)
@@ -203,6 +231,9 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem

ScaleBarUnits mUnits;

Qt::PenJoinStyle mLineJoinStyle;
Qt::PenCapStyle mLineCapStyle;

/**Calculates with of a segment in mm and stores it in mSegmentMillimeters*/
void refreshSegmentMillimeters();

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>337</width>
<height>757</height>
<width>358</width>
<height>429</height>
</rect>
</property>
<property name="sizePolicy">
@@ -51,9 +51,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>320</width>
<height>792</height>
<y>-406</y>
<width>340</width>
<height>888</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
@@ -290,12 +290,6 @@
<bool>true</bool>
</property>
<layout class="QFormLayout" name="formLayout_4">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
@@ -313,14 +307,14 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Labels margin</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="mLabelBarSpaceSpinBox">
<property name="prefix">
<string/>
@@ -330,14 +324,14 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Line width</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="mLineWidthSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@@ -362,14 +356,34 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="8" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Join style</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QgsPenJoinStyleComboBox" name="mLineJoinStyleCombo"/>
</item>
<item row="10" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Cap style</string>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QgsPenCapStyleComboBox" name="mLineCapStyleCombo"/>
</item>
<item row="11" column="0">
<widget class="QLabel" name="mAlignmentLabel">
<property name="text">
<string>Alignment</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="11" column="1">
<widget class="QComboBox" name="mAlignmentComboBox"/>
</item>
</layout>
@@ -432,12 +446,22 @@
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QgsPenJoinStyleComboBox</class>
<extends>QComboBox</extends>
<header>qgspenstylecombobox.h</header>
</customwidget>
<customwidget>
<class>QgsCollapsibleGroupBoxBasic</class>
<extends>QGroupBox</extends>
<header location="global">qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsPenCapStyleComboBox</class>
<extends>QComboBox</extends>
<header>qgspenstylecombobox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>

0 comments on commit 103b3b4

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