[FEATURE][composer] Data defined svg colors and outline width for

composer picture items

Especially useful when the picture is showing a north arrow!
This commit is contained in:
Nyall Dawson 2017-01-17 13:26:02 +10:00
parent d6c7569dda
commit 934c7c9173
7 changed files with 108 additions and 61 deletions

View File

@ -46,6 +46,9 @@ class QgsComposerObject : QObject, QgsExpressionContextGenerator
MapStylePreset, /*!< layer and style visibility preset */
//composer picture
PictureSource, /*!< picture source url */
PictureSvgBackgroundColor, //!< SVG background color
PictureSvgOutlineColor, //!< SVG outline color
PictureSvgOutlineWidth, //!< SVG outline width
//html item
SourceUrl /*!< html source url */
};

View File

@ -77,7 +77,7 @@ QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture
connect( mPicture, SIGNAL( pictureRotationChanged( double ) ), this, SLOT( setPicRotationSpinValue( double ) ) );
//connections for data defined buttons
connect( mSourceDDBtn, SIGNAL( dataDefinedActivated( bool ) ), mPictureLineEdit, SLOT( setDisabled( bool ) ) );
connect( mSourceDDBtn, &QgsDataDefinedButtonV2::activated, mPictureLineEdit, &QLineEdit::setDisabled );
}
QgsComposerPictureWidget::~QgsComposerPictureWidget()
@ -702,6 +702,18 @@ void QgsComposerPictureWidget::populateDataDefinedButtons()
{
registerDataDefinedButton( mSourceDDBtn, QgsComposerObject::PictureSource,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::anyStringDesc() );
mFillColorDDBtn->blockSignals( true );
registerDataDefinedButton( mFillColorDDBtn, QgsComposerObject::PictureSvgBackgroundColor,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() );
mFillColorDDBtn->blockSignals( false );
mOutlineColorDDBtn->blockSignals( true );
registerDataDefinedButton( mOutlineColorDDBtn, QgsComposerObject::PictureSvgOutlineColor,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() );
mOutlineColorDDBtn->blockSignals( false );
mOutlineWidthDDBtn->blockSignals( true );
registerDataDefinedButton( mOutlineWidthDDBtn, QgsComposerObject::PictureSvgOutlineWidth,
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doublePosDesc() );
mOutlineWidthDDBtn->blockSignals( false );
//initial state of controls - disable related controls when dd buttons are active
mPictureLineEdit->setEnabled( !mSourceDDBtn->isActive() );

View File

@ -58,6 +58,9 @@ const QgsPropertyDefinition QgsComposerObject::sPropertyNameMap
{ QgsComposerObject::PaperHeight, "dataDefinedPaperHeight" },
{ QgsComposerObject::NumPages, "dataDefinedNumPages" },
{ QgsComposerObject::PaperOrientation, "dataDefinedPaperOrientation" },
{ QgsComposerObject::PictureSvgBackgroundColor, "dataDefinedSvgBackgroundColor" },
{ QgsComposerObject::PictureSvgOutlineColor, "dataDefinedSvgOutlineColor" },
{ QgsComposerObject::PictureSvgOutlineWidth, "dataDefinedSvgOutlineWidth" },
};

View File

@ -73,8 +73,11 @@ class CORE_EXPORT QgsComposerObject: public QObject, public QgsExpressionContext
MapStylePreset, //!< Layer and style map theme
//composer picture
PictureSource, //!< Picture source url
PictureSvgBackgroundColor, //!< SVG background color
PictureSvgOutlineColor, //!< SVG outline color
PictureSvgOutlineWidth, //!< SVG outline width
//html item
SourceUrl //!< Html source url
SourceUrl, //!< Html source url
};
static const QgsPropertyDefinition sPropertyNameMap;

View File

@ -52,9 +52,6 @@ QgsComposerPicture::QgsComposerPicture( QgsComposition *composition )
, mNorthOffset( 0.0 )
, mResizeMode( QgsComposerPicture::Zoom )
, mPictureAnchor( UpperLeft )
, mSvgFillColor( QColor( 255, 255, 255 ) )
, mSvgBorderColor( QColor( 0, 0, 0 ) )
, mSvgBorderWidth( 0.2 )
, mHasExpressionError( false )
, mLoadingSvg( false )
{
@ -71,9 +68,6 @@ QgsComposerPicture::QgsComposerPicture()
, mNorthOffset( 0.0 )
, mResizeMode( QgsComposerPicture::Zoom )
, mPictureAnchor( UpperLeft )
, mSvgFillColor( QColor( 255, 255, 255 ) )
, mSvgBorderColor( QColor( 0, 0, 0 ) )
, mSvgBorderWidth( 0.2 )
, mHasExpressionError( false )
, mLoadingSvg( false )
{
@ -369,7 +363,11 @@ void QgsComposerPicture::loadLocalPicture( const QString &path )
if ( sourceFileSuffix.compare( QLatin1String( "svg" ), Qt::CaseInsensitive ) == 0 )
{
//try to open svg
const QByteArray &svgContent = QgsApplication::svgCache()->svgContent( pic.fileName(), rect().width(), mSvgFillColor, mSvgBorderColor, mSvgBorderWidth,
QgsExpressionContext context = createExpressionContext();
QColor fillColor = mProperties.valueAsColor( QgsComposerObject::PictureSvgBackgroundColor, context, mSvgFillColor );
QColor outlineColor = mProperties.valueAsColor( QgsComposerObject::PictureSvgOutlineColor, context, mSvgBorderColor );
double outlineWidth = mProperties.valueAsDouble( QgsComposerObject::PictureSvgOutlineWidth, context, mSvgBorderWidth );
const QByteArray &svgContent = QgsApplication::svgCache()->svgContent( pic.fileName(), rect().width(), fillColor, outlineColor, outlineWidth,
1.0 );
mSVG.load( svgContent );
if ( mSVG.isValid() )
@ -715,7 +713,9 @@ void QgsComposerPicture::refreshDataDefinedProperty( const QgsComposerObject::Da
QgsExpressionContext scopedContext = createExpressionContext();
const QgsExpressionContext* evalContext = context ? context : &scopedContext;
if ( property == QgsComposerObject::PictureSource || property == QgsComposerObject::AllProperties )
if ( property == QgsComposerObject::PictureSource || property == QgsComposerObject::PictureSvgBackgroundColor
|| property == QgsComposerObject::PictureSvgOutlineColor || property == QgsComposerObject::PictureSvgOutlineWidth
|| property == QgsComposerObject::AllProperties )
{
refreshPicture( evalContext );
}

View File

@ -324,9 +324,9 @@ class CORE_EXPORT QgsComposerPicture: public QgsComposerItem
ResizeMode mResizeMode;
QgsComposerItem::ItemPositionMode mPictureAnchor;
QColor mSvgFillColor;
QColor mSvgBorderColor;
double mSvgBorderWidth;
QColor mSvgFillColor = QColor( 255, 255, 255 );
QColor mSvgBorderColor = QColor( 0, 0, 0 );
double mSvgBorderWidth = 0.2;
bool mHasExpressionError;
bool mLoaded;

View File

@ -60,9 +60,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-312</y>
<width>314</width>
<height>871</height>
<y>-275</y>
<width>316</width>
<height>827</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
@ -333,6 +333,19 @@
<string>SVG Parameters</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<widget class="QgsDoubleSpinBox" name="mOutlineWidthSpinBox">
<property name="sizePolicy">
@ -361,22 +374,23 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsColorButton" name="mOutlineColorButton">
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
<item row="0" column="3">
<widget class="QgsDataDefinedButtonV2" name="mFillColorDDBtn">
<property name="text">
<string>...</string>
</property>
<property name="maximumSize">
<size>
<width>120</width>
<height>16777215</height>
</size>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mBorderColorLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
<string>Outline color</string>
</property>
</widget>
</item>
@ -399,19 +413,6 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mBorderColorLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Outline color</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mBorderWidthLabel">
<property name="text">
@ -419,6 +420,25 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsColorButton" name="mOutlineColorButton">
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>120</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
@ -432,18 +452,19 @@
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item row="1" column="3">
<widget class="QgsDataDefinedButtonV2" name="mOutlineColorDDBtn">
<property name="text">
<string>...</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</widget>
</item>
<item row="2" column="3">
<widget class="QgsDataDefinedButtonV2" name="mOutlineWidthDDBtn">
<property name="text">
<string>...</string>
</property>
</spacer>
</widget>
</item>
</layout>
</widget>
@ -527,27 +548,27 @@
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QgsCollapsibleGroupBoxBasic</class>
<extends>QGroupBox</extends>
<header location="global">qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsDataDefinedButtonV2</class>
<extends>QToolButton</extends>
<header>qgsdatadefinedbuttonv2.h</header>
</customwidget>
<customwidget>
<class>QgsDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>qgsdoublespinbox.h</header>
</customwidget>
<customwidget>
<class>QgsDataDefinedButtonV2</class>
<extends>QToolButton</extends>
<header>qgsdatadefinedbuttonv2.h</header>
<class>QgsCollapsibleGroupBoxBasic</class>
<extends>QGroupBox</extends>
<header location="global">qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsComposerItemComboBox</class>
@ -569,12 +590,17 @@
<tabstop>mRemoveDirectoryButton</tabstop>
<tabstop>mAddDirectoryButton</tabstop>
<tabstop>mFillColorButton</tabstop>
<tabstop>mFillColorDDBtn</tabstop>
<tabstop>mOutlineColorButton</tabstop>
<tabstop>mOutlineColorDDBtn</tabstop>
<tabstop>mOutlineWidthSpinBox</tabstop>
<tabstop>mOutlineWidthDDBtn</tabstop>
<tabstop>mRotationGroupBox</tabstop>
<tabstop>mPictureRotationSpinBox</tabstop>
<tabstop>mRotationFromComposerMapCheckBox</tabstop>
<tabstop>mComposerMapComboBox</tabstop>
<tabstop>mNorthTypeComboBox</tabstop>
<tabstop>mPictureRotationOffsetSpinBox</tabstop>
</tabstops>
<resources/>
<connections/>