mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
[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:
parent
d6c7569dda
commit
934c7c9173
@ -46,6 +46,9 @@ class QgsComposerObject : QObject, QgsExpressionContextGenerator
|
|||||||
MapStylePreset, /*!< layer and style visibility preset */
|
MapStylePreset, /*!< layer and style visibility preset */
|
||||||
//composer picture
|
//composer picture
|
||||||
PictureSource, /*!< picture source url */
|
PictureSource, /*!< picture source url */
|
||||||
|
PictureSvgBackgroundColor, //!< SVG background color
|
||||||
|
PictureSvgOutlineColor, //!< SVG outline color
|
||||||
|
PictureSvgOutlineWidth, //!< SVG outline width
|
||||||
//html item
|
//html item
|
||||||
SourceUrl /*!< html source url */
|
SourceUrl /*!< html source url */
|
||||||
};
|
};
|
||||||
|
@ -77,7 +77,7 @@ QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture
|
|||||||
connect( mPicture, SIGNAL( pictureRotationChanged( double ) ), this, SLOT( setPicRotationSpinValue( double ) ) );
|
connect( mPicture, SIGNAL( pictureRotationChanged( double ) ), this, SLOT( setPicRotationSpinValue( double ) ) );
|
||||||
|
|
||||||
//connections for data defined buttons
|
//connections for data defined buttons
|
||||||
connect( mSourceDDBtn, SIGNAL( dataDefinedActivated( bool ) ), mPictureLineEdit, SLOT( setDisabled( bool ) ) );
|
connect( mSourceDDBtn, &QgsDataDefinedButtonV2::activated, mPictureLineEdit, &QLineEdit::setDisabled );
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsComposerPictureWidget::~QgsComposerPictureWidget()
|
QgsComposerPictureWidget::~QgsComposerPictureWidget()
|
||||||
@ -702,6 +702,18 @@ void QgsComposerPictureWidget::populateDataDefinedButtons()
|
|||||||
{
|
{
|
||||||
registerDataDefinedButton( mSourceDDBtn, QgsComposerObject::PictureSource,
|
registerDataDefinedButton( mSourceDDBtn, QgsComposerObject::PictureSource,
|
||||||
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::anyStringDesc() );
|
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
|
//initial state of controls - disable related controls when dd buttons are active
|
||||||
mPictureLineEdit->setEnabled( !mSourceDDBtn->isActive() );
|
mPictureLineEdit->setEnabled( !mSourceDDBtn->isActive() );
|
||||||
|
@ -58,6 +58,9 @@ const QgsPropertyDefinition QgsComposerObject::sPropertyNameMap
|
|||||||
{ QgsComposerObject::PaperHeight, "dataDefinedPaperHeight" },
|
{ QgsComposerObject::PaperHeight, "dataDefinedPaperHeight" },
|
||||||
{ QgsComposerObject::NumPages, "dataDefinedNumPages" },
|
{ QgsComposerObject::NumPages, "dataDefinedNumPages" },
|
||||||
{ QgsComposerObject::PaperOrientation, "dataDefinedPaperOrientation" },
|
{ QgsComposerObject::PaperOrientation, "dataDefinedPaperOrientation" },
|
||||||
|
{ QgsComposerObject::PictureSvgBackgroundColor, "dataDefinedSvgBackgroundColor" },
|
||||||
|
{ QgsComposerObject::PictureSvgOutlineColor, "dataDefinedSvgOutlineColor" },
|
||||||
|
{ QgsComposerObject::PictureSvgOutlineWidth, "dataDefinedSvgOutlineWidth" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,8 +73,11 @@ class CORE_EXPORT QgsComposerObject: public QObject, public QgsExpressionContext
|
|||||||
MapStylePreset, //!< Layer and style map theme
|
MapStylePreset, //!< Layer and style map theme
|
||||||
//composer picture
|
//composer picture
|
||||||
PictureSource, //!< Picture source url
|
PictureSource, //!< Picture source url
|
||||||
|
PictureSvgBackgroundColor, //!< SVG background color
|
||||||
|
PictureSvgOutlineColor, //!< SVG outline color
|
||||||
|
PictureSvgOutlineWidth, //!< SVG outline width
|
||||||
//html item
|
//html item
|
||||||
SourceUrl //!< Html source url
|
SourceUrl, //!< Html source url
|
||||||
};
|
};
|
||||||
|
|
||||||
static const QgsPropertyDefinition sPropertyNameMap;
|
static const QgsPropertyDefinition sPropertyNameMap;
|
||||||
|
@ -52,9 +52,6 @@ QgsComposerPicture::QgsComposerPicture( QgsComposition *composition )
|
|||||||
, mNorthOffset( 0.0 )
|
, mNorthOffset( 0.0 )
|
||||||
, mResizeMode( QgsComposerPicture::Zoom )
|
, mResizeMode( QgsComposerPicture::Zoom )
|
||||||
, mPictureAnchor( UpperLeft )
|
, mPictureAnchor( UpperLeft )
|
||||||
, mSvgFillColor( QColor( 255, 255, 255 ) )
|
|
||||||
, mSvgBorderColor( QColor( 0, 0, 0 ) )
|
|
||||||
, mSvgBorderWidth( 0.2 )
|
|
||||||
, mHasExpressionError( false )
|
, mHasExpressionError( false )
|
||||||
, mLoadingSvg( false )
|
, mLoadingSvg( false )
|
||||||
{
|
{
|
||||||
@ -71,9 +68,6 @@ QgsComposerPicture::QgsComposerPicture()
|
|||||||
, mNorthOffset( 0.0 )
|
, mNorthOffset( 0.0 )
|
||||||
, mResizeMode( QgsComposerPicture::Zoom )
|
, mResizeMode( QgsComposerPicture::Zoom )
|
||||||
, mPictureAnchor( UpperLeft )
|
, mPictureAnchor( UpperLeft )
|
||||||
, mSvgFillColor( QColor( 255, 255, 255 ) )
|
|
||||||
, mSvgBorderColor( QColor( 0, 0, 0 ) )
|
|
||||||
, mSvgBorderWidth( 0.2 )
|
|
||||||
, mHasExpressionError( false )
|
, mHasExpressionError( false )
|
||||||
, mLoadingSvg( false )
|
, mLoadingSvg( false )
|
||||||
{
|
{
|
||||||
@ -369,7 +363,11 @@ void QgsComposerPicture::loadLocalPicture( const QString &path )
|
|||||||
if ( sourceFileSuffix.compare( QLatin1String( "svg" ), Qt::CaseInsensitive ) == 0 )
|
if ( sourceFileSuffix.compare( QLatin1String( "svg" ), Qt::CaseInsensitive ) == 0 )
|
||||||
{
|
{
|
||||||
//try to open svg
|
//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 );
|
1.0 );
|
||||||
mSVG.load( svgContent );
|
mSVG.load( svgContent );
|
||||||
if ( mSVG.isValid() )
|
if ( mSVG.isValid() )
|
||||||
@ -715,7 +713,9 @@ void QgsComposerPicture::refreshDataDefinedProperty( const QgsComposerObject::Da
|
|||||||
QgsExpressionContext scopedContext = createExpressionContext();
|
QgsExpressionContext scopedContext = createExpressionContext();
|
||||||
const QgsExpressionContext* evalContext = context ? context : &scopedContext;
|
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 );
|
refreshPicture( evalContext );
|
||||||
}
|
}
|
||||||
|
@ -324,9 +324,9 @@ class CORE_EXPORT QgsComposerPicture: public QgsComposerItem
|
|||||||
ResizeMode mResizeMode;
|
ResizeMode mResizeMode;
|
||||||
QgsComposerItem::ItemPositionMode mPictureAnchor;
|
QgsComposerItem::ItemPositionMode mPictureAnchor;
|
||||||
|
|
||||||
QColor mSvgFillColor;
|
QColor mSvgFillColor = QColor( 255, 255, 255 );
|
||||||
QColor mSvgBorderColor;
|
QColor mSvgBorderColor = QColor( 0, 0, 0 );
|
||||||
double mSvgBorderWidth;
|
double mSvgBorderWidth = 0.2;
|
||||||
|
|
||||||
bool mHasExpressionError;
|
bool mHasExpressionError;
|
||||||
bool mLoaded;
|
bool mLoaded;
|
||||||
|
@ -60,9 +60,9 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>-312</y>
|
<y>-275</y>
|
||||||
<width>314</width>
|
<width>316</width>
|
||||||
<height>871</height>
|
<height>827</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="mainLayout">
|
<layout class="QVBoxLayout" name="mainLayout">
|
||||||
@ -333,6 +333,19 @@
|
|||||||
<string>SVG Parameters</string>
|
<string>SVG Parameters</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_3">
|
<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">
|
<item row="2" column="1">
|
||||||
<widget class="QgsDoubleSpinBox" name="mOutlineWidthSpinBox">
|
<widget class="QgsDoubleSpinBox" name="mOutlineWidthSpinBox">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@ -361,22 +374,23 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="0" column="3">
|
||||||
<widget class="QgsColorButton" name="mOutlineColorButton">
|
<widget class="QgsDataDefinedButtonV2" name="mFillColorDDBtn">
|
||||||
<property name="minimumSize">
|
<property name="text">
|
||||||
<size>
|
<string>...</string>
|
||||||
<width>120</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
</property>
|
||||||
<property name="maximumSize">
|
</widget>
|
||||||
<size>
|
</item>
|
||||||
<width>120</width>
|
<item row="1" column="0">
|
||||||
<height>16777215</height>
|
<widget class="QLabel" name="mBorderColorLabel">
|
||||||
</size>
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string>Outline color</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -399,19 +413,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="mBorderWidthLabel">
|
<widget class="QLabel" name="mBorderWidthLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -419,6 +420,25 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label_6">
|
<widget class="QLabel" name="label_6">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@ -432,18 +452,19 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="2">
|
<item row="1" column="3">
|
||||||
<spacer name="horizontalSpacer">
|
<widget class="QgsDataDefinedButtonV2" name="mOutlineColorDDBtn">
|
||||||
<property name="orientation">
|
<property name="text">
|
||||||
<enum>Qt::Horizontal</enum>
|
<string>...</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
</widget>
|
||||||
<size>
|
</item>
|
||||||
<width>40</width>
|
<item row="2" column="3">
|
||||||
<height>20</height>
|
<widget class="QgsDataDefinedButtonV2" name="mOutlineWidthDDBtn">
|
||||||
</size>
|
<property name="text">
|
||||||
|
<string>...</string>
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
@ -527,27 +548,27 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
|
||||||
<class>QgsCollapsibleGroupBoxBasic</class>
|
|
||||||
<extends>QGroupBox</extends>
|
|
||||||
<header location="global">qgscollapsiblegroupbox.h</header>
|
|
||||||
<container>1</container>
|
|
||||||
</customwidget>
|
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>QgsColorButton</class>
|
<class>QgsColorButton</class>
|
||||||
<extends>QToolButton</extends>
|
<extends>QToolButton</extends>
|
||||||
<header>qgscolorbutton.h</header>
|
<header>qgscolorbutton.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>QgsDataDefinedButtonV2</class>
|
||||||
|
<extends>QToolButton</extends>
|
||||||
|
<header>qgsdatadefinedbuttonv2.h</header>
|
||||||
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>QgsDoubleSpinBox</class>
|
<class>QgsDoubleSpinBox</class>
|
||||||
<extends>QDoubleSpinBox</extends>
|
<extends>QDoubleSpinBox</extends>
|
||||||
<header>qgsdoublespinbox.h</header>
|
<header>qgsdoublespinbox.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>QgsDataDefinedButtonV2</class>
|
<class>QgsCollapsibleGroupBoxBasic</class>
|
||||||
<extends>QToolButton</extends>
|
<extends>QGroupBox</extends>
|
||||||
<header>qgsdatadefinedbuttonv2.h</header>
|
<header location="global">qgscollapsiblegroupbox.h</header>
|
||||||
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>QgsComposerItemComboBox</class>
|
<class>QgsComposerItemComboBox</class>
|
||||||
@ -569,12 +590,17 @@
|
|||||||
<tabstop>mRemoveDirectoryButton</tabstop>
|
<tabstop>mRemoveDirectoryButton</tabstop>
|
||||||
<tabstop>mAddDirectoryButton</tabstop>
|
<tabstop>mAddDirectoryButton</tabstop>
|
||||||
<tabstop>mFillColorButton</tabstop>
|
<tabstop>mFillColorButton</tabstop>
|
||||||
|
<tabstop>mFillColorDDBtn</tabstop>
|
||||||
<tabstop>mOutlineColorButton</tabstop>
|
<tabstop>mOutlineColorButton</tabstop>
|
||||||
|
<tabstop>mOutlineColorDDBtn</tabstop>
|
||||||
<tabstop>mOutlineWidthSpinBox</tabstop>
|
<tabstop>mOutlineWidthSpinBox</tabstop>
|
||||||
|
<tabstop>mOutlineWidthDDBtn</tabstop>
|
||||||
<tabstop>mRotationGroupBox</tabstop>
|
<tabstop>mRotationGroupBox</tabstop>
|
||||||
<tabstop>mPictureRotationSpinBox</tabstop>
|
<tabstop>mPictureRotationSpinBox</tabstop>
|
||||||
<tabstop>mRotationFromComposerMapCheckBox</tabstop>
|
<tabstop>mRotationFromComposerMapCheckBox</tabstop>
|
||||||
<tabstop>mComposerMapComboBox</tabstop>
|
<tabstop>mComposerMapComboBox</tabstop>
|
||||||
|
<tabstop>mNorthTypeComboBox</tabstop>
|
||||||
|
<tabstop>mPictureRotationOffsetSpinBox</tabstop>
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user