Change QgsComposerItem to use opacity instead of transparency

This commit is contained in:
Nyall Dawson 2017-05-29 15:32:58 +10:00
parent b2ba450d46
commit 39146517d2
15 changed files with 116 additions and 81 deletions

View File

@ -615,6 +615,12 @@ Use the corresponding methods in QgsComposerUtils instead.
instead. instead.
- lockSymbolSize(), imageSizeConsideringRotation(), cornerPointOnRotatedAndScaledRect(), - lockSymbolSize(), imageSizeConsideringRotation(), cornerPointOnRotatedAndScaledRect(),
sizeChangedByRotation() were removed. No replacement is offered for these methods. sizeChangedByRotation() were removed. No replacement is offered for these methods.
- transparency() and setTransparency() were removed. Use itemOpacity() and setItemOpacity() instead.
QgsComposerItemCommand {#qgis_api_break_3_0_QgsComposerItemCommand}
----------------------
- ItemTransparency was removed. Use ItemOpacity instead.
QgsComposerLabel {#qgis_api_break_3_0_QgsComposerLabel} QgsComposerLabel {#qgis_api_break_3_0_QgsComposerLabel}

View File

@ -404,17 +404,8 @@ class QgsComposerItem : QgsComposerObject, QGraphicsRectItem
*/ */
void setBlendMode( const QPainter::CompositionMode blendMode ); void setBlendMode( const QPainter::CompositionMode blendMode );
/** Returns the item's transparency double itemOpacity() const;
* @returns transparency as integer between 0 (transparent) and 255 (opaque) void setItemOpacity( const double opacity );
* @see setTransparency
*/
int transparency() const;
/** Sets the item's transparency
* @param transparency integer between 0 (transparent) and 255 (opaque)
* @see transparency
*/
void setTransparency( const int transparency );
/** Returns whether effects (e.g., blend modes) are enabled for the item /** Returns whether effects (e.g., blend modes) are enabled for the item
* @returns true if effects are enabled * @returns true if effects are enabled

View File

@ -112,7 +112,7 @@ class QgsComposerMergeCommand : QgsComposerItemCommand
ItemBackgroundColor, ItemBackgroundColor,
ItemMove, ItemMove,
ItemRotation, ItemRotation,
ItemTransparency, ItemOpacity,
ItemZoomContent ItemZoomContent
}; };

View File

@ -30,6 +30,7 @@ class QgsComposerObject : QObject, QgsExpressionContextGenerator
ItemHeight, /*!< height of item */ ItemHeight, /*!< height of item */
ItemRotation, /*!< rotation of item */ ItemRotation, /*!< rotation of item */
Transparency, /*!< item transparency */ Transparency, /*!< item transparency */
Opacity,
BlendMode, /*!< item blend mode */ BlendMode, /*!< item blend mode */
ExcludeFromExports, /*!< exclude item from exports */ ExcludeFromExports, /*!< exclude item from exports */
FrameColor, //!< Item frame color FrameColor, //!< Item frame color

View File

@ -170,7 +170,7 @@ QgsComposerItemWidget::QgsComposerItemWidget( QWidget *parent, QgsComposerItem *
connect( mItem, &QgsComposerItem::sizeChanged, this, &QgsComposerItemWidget::setValuesForGuiPositionElements ); connect( mItem, &QgsComposerItem::sizeChanged, this, &QgsComposerItemWidget::setValuesForGuiPositionElements );
connect( mItem, &QgsComposerObject::itemChanged, this, &QgsComposerItemWidget::setValuesForGuiNonPositionElements ); connect( mItem, &QgsComposerObject::itemChanged, this, &QgsComposerItemWidget::setValuesForGuiNonPositionElements );
connect( mTransparencySlider, &QAbstractSlider::valueChanged, mTransparencySpnBx, &QSpinBox::setValue ); connect( mOpacitySlider, &QAbstractSlider::valueChanged, this, [ = ]( int value ) { mOpacitySpnBx->setValue( value / 10.0 ); } );
updateVariables(); updateVariables();
connect( mVariableEditor, &QgsVariableEditorWidget::scopeChanged, this, &QgsComposerItemWidget::variablesChanged ); connect( mVariableEditor, &QgsVariableEditorWidget::scopeChanged, this, &QgsComposerItemWidget::variablesChanged );
@ -504,8 +504,8 @@ void QgsComposerItemWidget::setValuesForGuiNonPositionElements()
mBackgroundGroupBox->blockSignals( true ); mBackgroundGroupBox->blockSignals( true );
mItemIdLineEdit->blockSignals( true ); mItemIdLineEdit->blockSignals( true );
mBlendModeCombo->blockSignals( true ); mBlendModeCombo->blockSignals( true );
mTransparencySlider->blockSignals( true ); mOpacitySlider->blockSignals( true );
mTransparencySpnBx->blockSignals( true ); mOpacitySpnBx->blockSignals( true );
mFrameColorButton->blockSignals( true ); mFrameColorButton->blockSignals( true );
mFrameJoinStyleCombo->blockSignals( true ); mFrameJoinStyleCombo->blockSignals( true );
mBackgroundColorButton->blockSignals( true ); mBackgroundColorButton->blockSignals( true );
@ -520,8 +520,8 @@ void QgsComposerItemWidget::setValuesForGuiNonPositionElements()
mFrameGroupBox->setChecked( mItem->hasFrame() ); mFrameGroupBox->setChecked( mItem->hasFrame() );
mBackgroundGroupBox->setChecked( mItem->hasBackground() ); mBackgroundGroupBox->setChecked( mItem->hasBackground() );
mBlendModeCombo->setBlendMode( mItem->blendMode() ); mBlendModeCombo->setBlendMode( mItem->blendMode() );
mTransparencySlider->setValue( mItem->transparency() ); mOpacitySlider->setValue( mItem->itemOpacity() * 1000.0 );
mTransparencySpnBx->setValue( mItem->transparency() ); mOpacitySpnBx->setValue( mItem->itemOpacity() * 100.0 );
mItemRotationSpinBox->setValue( mItem->itemRotation( QgsComposerObject::OriginalValue ) ); mItemRotationSpinBox->setValue( mItem->itemRotation( QgsComposerObject::OriginalValue ) );
mExcludeFromPrintsCheckBox->setChecked( mItem->excludeFromExports( QgsComposerObject::OriginalValue ) ); mExcludeFromPrintsCheckBox->setChecked( mItem->excludeFromExports( QgsComposerObject::OriginalValue ) );
@ -533,8 +533,8 @@ void QgsComposerItemWidget::setValuesForGuiNonPositionElements()
mBackgroundGroupBox->blockSignals( false ); mBackgroundGroupBox->blockSignals( false );
mItemIdLineEdit->blockSignals( false ); mItemIdLineEdit->blockSignals( false );
mBlendModeCombo->blockSignals( false ); mBlendModeCombo->blockSignals( false );
mTransparencySlider->blockSignals( false ); mOpacitySlider->blockSignals( false );
mTransparencySpnBx->blockSignals( false ); mOpacitySpnBx->blockSignals( false );
mItemRotationSpinBox->blockSignals( false ); mItemRotationSpinBox->blockSignals( false );
mExcludeFromPrintsCheckBox->blockSignals( false ); mExcludeFromPrintsCheckBox->blockSignals( false );
} }
@ -546,7 +546,7 @@ void QgsComposerItemWidget::initializeDataDefinedButtons()
mConfigObject->initializeDataDefinedButton( mWidthDDBtn, QgsComposerObject::ItemWidth ); mConfigObject->initializeDataDefinedButton( mWidthDDBtn, QgsComposerObject::ItemWidth );
mConfigObject->initializeDataDefinedButton( mHeightDDBtn, QgsComposerObject::ItemHeight ); mConfigObject->initializeDataDefinedButton( mHeightDDBtn, QgsComposerObject::ItemHeight );
mConfigObject->initializeDataDefinedButton( mItemRotationDDBtn, QgsComposerObject::ItemRotation ); mConfigObject->initializeDataDefinedButton( mItemRotationDDBtn, QgsComposerObject::ItemRotation );
mConfigObject->initializeDataDefinedButton( mTransparencyDDBtn, QgsComposerObject::Transparency ); mConfigObject->initializeDataDefinedButton( mOpacityDDBtn, QgsComposerObject::Opacity );
mConfigObject->initializeDataDefinedButton( mBlendModeDDBtn, QgsComposerObject::BlendMode ); mConfigObject->initializeDataDefinedButton( mBlendModeDDBtn, QgsComposerObject::BlendMode );
mConfigObject->initializeDataDefinedButton( mExcludePrintsDDBtn, QgsComposerObject::ExcludeFromExports ); mConfigObject->initializeDataDefinedButton( mExcludePrintsDDBtn, QgsComposerObject::ExcludeFromExports );
mConfigObject->initializeDataDefinedButton( mItemFrameColorDDBtn, QgsComposerObject::FrameColor ); mConfigObject->initializeDataDefinedButton( mItemFrameColorDDBtn, QgsComposerObject::FrameColor );
@ -591,15 +591,15 @@ void QgsComposerItemWidget::on_mBlendModeCombo_currentIndexChanged( int index )
} }
} }
void QgsComposerItemWidget::on_mTransparencySpnBx_valueChanged( int value ) void QgsComposerItemWidget::on_mOpacitySpnBx_valueChanged( double value )
{ {
mTransparencySlider->blockSignals( true ); mOpacitySlider->blockSignals( true );
mTransparencySlider->setValue( value ); mOpacitySlider->setValue( value * 10 );
mTransparencySlider->blockSignals( false ); mOpacitySlider->blockSignals( false );
if ( mItem ) if ( mItem )
{ {
mItem->beginCommand( tr( "Item transparency changed" ), QgsComposerMergeCommand::ItemTransparency ); mItem->beginCommand( tr( "Item opacity changed" ), QgsComposerMergeCommand::ItemOpacity );
mItem->setTransparency( value ); mItem->setItemOpacity( value / 100.0 );
mItem->endCommand(); mItem->endCommand();
} }
} }

View File

@ -172,7 +172,7 @@ class QgsComposerItemWidget: public QWidget, private Ui::QgsComposerItemWidgetBa
void on_mLowerRightCheckBox_stateChanged( int state ); void on_mLowerRightCheckBox_stateChanged( int state );
void on_mBlendModeCombo_currentIndexChanged( int index ); void on_mBlendModeCombo_currentIndexChanged( int index );
void on_mTransparencySpnBx_valueChanged( int value ); void on_mOpacitySpnBx_valueChanged( double value );
void on_mItemRotationSpinBox_valueChanged( double val ); void on_mItemRotationSpinBox_valueChanged( double val );
void on_mExcludeFromPrintsCheckBox_toggled( bool checked ); void on_mExcludeFromPrintsCheckBox_toggled( bool checked );

View File

@ -60,7 +60,6 @@ QgsComposerItem::QgsComposerItem( QgsComposition *composition, bool manageZValue
, mEvaluatedItemRotation( 0 ) , mEvaluatedItemRotation( 0 )
, mBlendMode( QPainter::CompositionMode_SourceOver ) , mBlendMode( QPainter::CompositionMode_SourceOver )
, mEffectsEnabled( true ) , mEffectsEnabled( true )
, mTransparency( 0 )
, mExcludeFromExports( false ) , mExcludeFromExports( false )
, mEvaluatedExcludeFromExports( false ) , mEvaluatedExcludeFromExports( false )
, mLastUsedPositionMode( UpperLeft ) , mLastUsedPositionMode( UpperLeft )
@ -89,7 +88,6 @@ QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, Q
, mEvaluatedItemRotation( 0 ) , mEvaluatedItemRotation( 0 )
, mBlendMode( QPainter::CompositionMode_SourceOver ) , mBlendMode( QPainter::CompositionMode_SourceOver )
, mEffectsEnabled( true ) , mEffectsEnabled( true )
, mTransparency( 0 )
, mExcludeFromExports( false ) , mExcludeFromExports( false )
, mEvaluatedExcludeFromExports( false ) , mEvaluatedExcludeFromExports( false )
, mLastUsedPositionMode( UpperLeft ) , mLastUsedPositionMode( UpperLeft )
@ -228,8 +226,8 @@ bool QgsComposerItem::_writeXml( QDomElement &itemElem, QDomDocument &doc ) cons
//blend mode //blend mode
composerItemElem.setAttribute( QStringLiteral( "blendMode" ), QgsPainting::getBlendModeEnum( mBlendMode ) ); composerItemElem.setAttribute( QStringLiteral( "blendMode" ), QgsPainting::getBlendModeEnum( mBlendMode ) );
//transparency //opacity
composerItemElem.setAttribute( QStringLiteral( "transparency" ), QString::number( mTransparency ) ); composerItemElem.setAttribute( QStringLiteral( "opacity" ), QString::number( mOpacity ) );
composerItemElem.setAttribute( QStringLiteral( "excludeFromExports" ), mExcludeFromExports ); composerItemElem.setAttribute( QStringLiteral( "excludeFromExports" ), mExcludeFromExports );
@ -386,8 +384,15 @@ bool QgsComposerItem::_readXml( const QDomElement &itemElem, const QDomDocument
//blend mode //blend mode
setBlendMode( QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( itemElem.attribute( QStringLiteral( "blendMode" ), QStringLiteral( "0" ) ).toUInt() ) ) ); setBlendMode( QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( itemElem.attribute( QStringLiteral( "blendMode" ), QStringLiteral( "0" ) ).toUInt() ) ) );
//transparency //opacity
setTransparency( itemElem.attribute( QStringLiteral( "transparency" ), QStringLiteral( "0" ) ).toInt() ); if ( itemElem.hasAttribute( QStringLiteral( "opacity" ) ) )
{
setItemOpacity( itemElem.attribute( QStringLiteral( "opacity" ), QStringLiteral( "1" ) ).toDouble() );
}
else
{
setItemOpacity( 1.0 - itemElem.attribute( QStringLiteral( "transparency" ), QStringLiteral( "0" ) ).toInt() / 100.0 );
}
mExcludeFromExports = itemElem.attribute( QStringLiteral( "excludeFromExports" ), QStringLiteral( "0" ) ).toInt(); mExcludeFromExports = itemElem.attribute( QStringLiteral( "excludeFromExports" ), QStringLiteral( "0" ) ).toInt();
mEvaluatedExcludeFromExports = mExcludeFromExports; mEvaluatedExcludeFromExports = mExcludeFromExports;
@ -895,20 +900,20 @@ void QgsComposerItem::refreshBlendMode( const QgsExpressionContext &context )
mEffect->setCompositionMode( blendMode ); mEffect->setCompositionMode( blendMode );
} }
void QgsComposerItem::setTransparency( const int transparency ) void QgsComposerItem::setItemOpacity( const double opacity )
{ {
mTransparency = transparency; mOpacity = opacity;
QgsExpressionContext context = createExpressionContext(); QgsExpressionContext context = createExpressionContext();
refreshTransparency( true, context ); refreshOpacity( true, context );
} }
void QgsComposerItem::refreshTransparency( const bool updateItem, const QgsExpressionContext &context ) void QgsComposerItem::refreshOpacity( const bool updateItem, const QgsExpressionContext &context )
{ {
//data defined transparency set? //data defined opacity set?
int transparency = mDataDefinedProperties.valueAsInt( QgsComposerObject::Transparency, context, mTransparency ); double opacity = mDataDefinedProperties.valueAsDouble( QgsComposerObject::Opacity, context, mOpacity * 100.0 );
// Set the QGraphicItem's opacity // Set the QGraphicItem's opacity
setOpacity( 1. - ( transparency / 100. ) ); setOpacity( opacity / 100.0 );
if ( updateItem ) if ( updateItem )
{ {
@ -1140,9 +1145,9 @@ void QgsComposerItem::refreshDataDefinedProperty( const QgsComposerObject::DataD
{ {
refreshRotation( false, true, *evalContext ); refreshRotation( false, true, *evalContext );
} }
if ( property == QgsComposerObject::Transparency || property == QgsComposerObject::AllProperties ) if ( property == QgsComposerObject::Opacity || property == QgsComposerObject::AllProperties )
{ {
refreshTransparency( false, *evalContext ); refreshOpacity( false, *evalContext );
} }
if ( property == QgsComposerObject::BlendMode || property == QgsComposerObject::AllProperties ) if ( property == QgsComposerObject::BlendMode || property == QgsComposerObject::AllProperties )
{ {

View File

@ -364,22 +364,26 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
*/ */
void setBlendMode( const QPainter::CompositionMode blendMode ); void setBlendMode( const QPainter::CompositionMode blendMode );
/** Returns the item's transparency /** Returns the item's opacity. This method should be used instead of
* \returns transparency as integer between 0 (transparent) and 255 (opaque) * QGraphicsItem::opacity() as any data defined overrides will be
* \see setTransparency * respected.
* \returns opacity as double between 1.0 (opaque) and 0 (transparent).
* \see setItemOpacity()
*/ */
int transparency() const { return mTransparency; } double itemOpacity() const { return mOpacity; }
/** Sets the item's transparency /** Sets the item's \a opacity. This method should be used instead of
* \param transparency integer between 0 (transparent) and 255 (opaque) * QGraphicsItem::setOpacity() as any data defined overrides will be
* \see transparency * respected.
* \param opacity double between 1.0 (opaque) and 0 (transparent).
* \see itemOpacity()
*/ */
void setTransparency( const int transparency ); void setItemOpacity( const double itemOpacity );
/** Returns whether effects (e.g., blend modes) are enabled for the item /** Returns whether effects (e.g., blend modes) are enabled for the item
* \returns true if effects are enabled * \returns true if effects are enabled
* \see setEffectsEnabled * \see setEffectsEnabled
* \see transparency * \see itemOpacity()
* \see blendMode * \see blendMode
*/ */
bool effectsEnabled() const { return mEffectsEnabled; } bool effectsEnabled() const { return mEffectsEnabled; }
@ -387,7 +391,7 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
/** Sets whether effects (e.g., blend modes) are enabled for the item /** Sets whether effects (e.g., blend modes) are enabled for the item
* \param effectsEnabled set to true to enable effects * \param effectsEnabled set to true to enable effects
* \see effectsEnabled * \see effectsEnabled
* \see setTransparency * \see setItemOpacity()
* \see setBlendMode * \see setBlendMode
*/ */
void setEffectsEnabled( const bool effectsEnabled ); void setEffectsEnabled( const bool effectsEnabled );
@ -621,8 +625,8 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
bool mEffectsEnabled; bool mEffectsEnabled;
QgsComposerEffect *mEffect = nullptr; QgsComposerEffect *mEffect = nullptr;
//! Item transparency //! Item opacity, between 0 and 1
int mTransparency; double mOpacity = 1.0;
//! Whether item should be excluded in exports //! Whether item should be excluded in exports
bool mExcludeFromExports; bool mExcludeFromExports;
@ -734,25 +738,25 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec
*/ */
void refreshRotation( const bool updateItem = true, const bool rotateAroundCenter = false, const QgsExpressionContext &context = QgsExpressionContext() ); void refreshRotation( const bool updateItem = true, const bool rotateAroundCenter = false, const QgsExpressionContext &context = QgsExpressionContext() );
/** Refresh item's transparency, considering data defined transparency /** Refresh item's opacity, considering data defined opacity
* \param updateItem set to false to prevent the item being automatically updated * \param updateItem set to false to prevent the item being automatically updated
* after the transparency is set * after the opacity is set
* \param context expression context for evaulating data defined transparency * \param context expression context for evaulating data defined opacity
* \since QGIS 2.5 * \since QGIS 2.5
*/ */
void refreshTransparency( const bool updateItem = true, const QgsExpressionContext &context = QgsExpressionContext() ); void refreshOpacity( const bool updateItem = true, const QgsExpressionContext &context = QgsExpressionContext() );
/** Refresh item's frame color, considering data defined transparency /** Refresh item's frame color, considering data defined colors
* \param updateItem set to false to prevent the item being automatically updated * \param updateItem set to false to prevent the item being automatically updated
* after the frame color is set * after the frame color is set
* \param context expression context for evaulating data defined transparency * \param context expression context for evaulating data defined color
*/ */
void refreshFrameColor( const bool updateItem = true, const QgsExpressionContext &context = QgsExpressionContext() ); void refreshFrameColor( const bool updateItem = true, const QgsExpressionContext &context = QgsExpressionContext() );
/** Refresh item's transparency, considering data defined transparency /** Refresh item's background color, considering data defined colors
* \param updateItem set to false to prevent the item being automatically updated * \param updateItem set to false to prevent the item being automatically updated
* after the background color is set * after the background color is set
* \param context expression context for evaulating data defined transparency * \param context expression context for evaulating data defined color
*/ */
void refreshBackgroundColor( const bool updateItem = true, const QgsExpressionContext &context = QgsExpressionContext() ); void refreshBackgroundColor( const bool updateItem = true, const QgsExpressionContext &context = QgsExpressionContext() );

View File

@ -154,7 +154,7 @@ class CORE_EXPORT QgsComposerMergeCommand: public QgsComposerItemCommand
ItemBackgroundColor, ItemBackgroundColor,
ItemMove, ItemMove,
ItemRotation, ItemRotation,
ItemTransparency, ItemOpacity, //!< Item opacity
ItemZoomContent ItemZoomContent
}; };

View File

@ -213,7 +213,7 @@ QgsComposerFrame *QgsComposerMultiFrame::createNewFrame( QgsComposerFrame *curre
newFrame->setFrameStrokeColor( currentFrame->frameStrokeColor() ); newFrame->setFrameStrokeColor( currentFrame->frameStrokeColor() );
newFrame->setFrameJoinStyle( currentFrame->frameJoinStyle() ); newFrame->setFrameJoinStyle( currentFrame->frameJoinStyle() );
newFrame->setFrameStrokeWidth( currentFrame->frameStrokeWidth() ); newFrame->setFrameStrokeWidth( currentFrame->frameStrokeWidth() );
newFrame->setTransparency( currentFrame->transparency() ); newFrame->setItemOpacity( currentFrame->itemOpacity() );
newFrame->setHideBackgroundIfEmpty( currentFrame->hideBackgroundIfEmpty() ); newFrame->setHideBackgroundIfEmpty( currentFrame->hideBackgroundIfEmpty() );
addFrame( newFrame, false ); addFrame( newFrame, false );

View File

@ -51,6 +51,7 @@ void QgsComposerObject::initPropertyDefinitions()
{ QgsComposerObject::ItemHeight, QgsPropertyDefinition( "dataDefinedHeight", QObject::tr( "Height" ), QgsPropertyDefinition::DoublePositive ) }, { QgsComposerObject::ItemHeight, QgsPropertyDefinition( "dataDefinedHeight", QObject::tr( "Height" ), QgsPropertyDefinition::DoublePositive ) },
{ QgsComposerObject::ItemRotation, QgsPropertyDefinition( "dataDefinedRotation", QObject::tr( "Rotation angle" ), QgsPropertyDefinition::Rotation ) }, { QgsComposerObject::ItemRotation, QgsPropertyDefinition( "dataDefinedRotation", QObject::tr( "Rotation angle" ), QgsPropertyDefinition::Rotation ) },
{ QgsComposerObject::Transparency, QgsPropertyDefinition( "dataDefinedTransparency", QObject::tr( "Transparency" ), QgsPropertyDefinition::Transparency ) }, { QgsComposerObject::Transparency, QgsPropertyDefinition( "dataDefinedTransparency", QObject::tr( "Transparency" ), QgsPropertyDefinition::Transparency ) },
{ QgsComposerObject::Opacity, QgsPropertyDefinition( "dataDefinedOpacity", QObject::tr( "Opacity" ), QgsPropertyDefinition::Transparency ) },
{ QgsComposerObject::BlendMode, QgsPropertyDefinition( "dataDefinedBlendMode", QObject::tr( "Blend mode" ), QgsPropertyDefinition::BlendMode ) }, { QgsComposerObject::BlendMode, QgsPropertyDefinition( "dataDefinedBlendMode", QObject::tr( "Blend mode" ), QgsPropertyDefinition::BlendMode ) },
{ QgsComposerObject::ExcludeFromExports, QgsPropertyDefinition( "dataDefinedExcludeExports", QObject::tr( "Exclude item from exports" ), QgsPropertyDefinition::Boolean ) }, { QgsComposerObject::ExcludeFromExports, QgsPropertyDefinition( "dataDefinedExcludeExports", QObject::tr( "Exclude item from exports" ), QgsPropertyDefinition::Boolean ) },
{ QgsComposerObject::FrameColor, QgsPropertyDefinition( "dataDefinedFrameColor", QObject::tr( "Frame color" ), QgsPropertyDefinition::ColorWithAlpha ) }, { QgsComposerObject::FrameColor, QgsPropertyDefinition( "dataDefinedFrameColor", QObject::tr( "Frame color" ), QgsPropertyDefinition::ColorWithAlpha ) },
@ -142,6 +143,14 @@ bool QgsComposerObject::readXml( const QDomElement &itemElem, const QDomDocument
{ {
mDataDefinedProperties.readXml( propsNode.toElement(), sPropertyDefinitions ); mDataDefinedProperties.readXml( propsNode.toElement(), sPropertyDefinitions );
} }
if ( mDataDefinedProperties.isActive( QgsComposerObject::Transparency ) )
{
// upgrade transparency -> opacity
QString exp = mDataDefinedProperties.property( QgsComposerObject::Transparency ).asExpression();
exp = QStringLiteral( "100.0 - (%1)" ).arg( exp );
mDataDefinedProperties.setProperty( QgsComposerObject::Opacity, QgsProperty::fromExpression( exp ) );
mDataDefinedProperties.setProperty( QgsComposerObject::Transparency, QgsProperty() );
}
//custom properties //custom properties
mCustomProperties.readXml( itemElem ); mCustomProperties.readXml( itemElem );

View File

@ -57,7 +57,8 @@ class CORE_EXPORT QgsComposerObject: public QObject, public QgsExpressionContext
ItemWidth, //!< Width of item ItemWidth, //!< Width of item
ItemHeight, //!< Height of item ItemHeight, //!< Height of item
ItemRotation, //!< Rotation of item ItemRotation, //!< Rotation of item
Transparency, //!< Item transparency Transparency, //!< Item transparency (deprecated)
Opacity, //!< Item opacity
BlendMode, //!< Item blend mode BlendMode, //!< Item blend mode
ExcludeFromExports, //!< Exclude item from exports ExcludeFromExports, //!< Exclude item from exports
FrameColor, //!< Item frame color FrameColor, //!< Item frame color

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>290</width> <width>309</width>
<height>1017</height> <height>1135</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -658,37 +658,55 @@
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="labelTransparency"> <widget class="QLabel" name="labelTransparency">
<property name="text"> <property name="text">
<string>Transparency</string> <string>Opacity</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<widget class="QSlider" name="mTransparencySlider"> <widget class="QSlider" name="mOpacitySlider">
<property name="maximum"> <property name="maximum">
<number>1000</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
<property name="pageStep">
<number>100</number> <number>100</number>
</property> </property>
<property name="value">
<number>1000</number>
</property>
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QgsSpinBox" name="mTransparencySpnBx"> <widget class="QgsDoubleSpinBox" name="mOpacitySpnBx">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>80</width> <width>100</width>
<height>25</height> <height>25</height>
</size> </size>
</property> </property>
<property name="suffix">
<string> %</string>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="maximum"> <property name="maximum">
<number>100</number> <double>100.000000000000000</double>
</property>
<property name="value">
<double>100.000000000000000</double>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QgsPropertyOverrideButton" name="mTransparencyDDBtn"> <widget class="QgsPropertyOverrideButton" name="mOpacityDDBtn">
<property name="text"> <property name="text">
<string>...</string> <string>...</string>
</property> </property>
@ -841,9 +859,9 @@
<tabstop>groupRendering</tabstop> <tabstop>groupRendering</tabstop>
<tabstop>mBlendModeCombo</tabstop> <tabstop>mBlendModeCombo</tabstop>
<tabstop>mBlendModeDDBtn</tabstop> <tabstop>mBlendModeDDBtn</tabstop>
<tabstop>mTransparencySlider</tabstop> <tabstop>mOpacitySlider</tabstop>
<tabstop>mTransparencySpnBx</tabstop> <tabstop>mOpacitySpnBx</tabstop>
<tabstop>mTransparencyDDBtn</tabstop> <tabstop>mOpacityDDBtn</tabstop>
<tabstop>mExcludeFromPrintsCheckBox</tabstop> <tabstop>mExcludeFromPrintsCheckBox</tabstop>
<tabstop>mExcludePrintsDDBtn</tabstop> <tabstop>mExcludePrintsDDBtn</tabstop>
</tabstops> </tabstops>

View File

@ -111,7 +111,7 @@ void TestQgsComposerEffects::blend_modes()
void TestQgsComposerEffects::transparency() void TestQgsComposerEffects::transparency()
{ {
mComposerRect2->setTransparency( 50 ); mComposerRect2->setItemOpacity( 0.5 );
QgsCompositionChecker checker( QStringLiteral( "composereffects_transparency" ), mComposition ); QgsCompositionChecker checker( QStringLiteral( "composereffects_transparency" ), mComposition );
checker.setControlPathPrefix( QStringLiteral( "composer_effects" ) ); checker.setControlPathPrefix( QStringLiteral( "composer_effects" ) );

View File

@ -109,7 +109,7 @@ void TestQgsComposerMultiFrame::addFrame()
frame1->setBackgroundEnabled( true ); frame1->setBackgroundEnabled( true );
frame1->setBackgroundColor( QColor( Qt::green ) ); frame1->setBackgroundColor( QColor( Qt::green ) );
frame1->setBlendMode( QPainter::CompositionMode_ColorBurn ); frame1->setBlendMode( QPainter::CompositionMode_ColorBurn );
frame1->setTransparency( 50 ); frame1->setItemOpacity( 0.5 );
QgsComposerFrame *frame2 = htmlItem->createNewFrame( frame1, QPointF( 50, 55 ), QSizeF( 70, 120 ) ); QgsComposerFrame *frame2 = htmlItem->createNewFrame( frame1, QPointF( 50, 55 ), QSizeF( 70, 120 ) );
@ -126,7 +126,7 @@ void TestQgsComposerMultiFrame::addFrame()
QCOMPARE( frame2->hasBackground(), frame1->hasBackground() ); QCOMPARE( frame2->hasBackground(), frame1->hasBackground() );
QCOMPARE( frame2->backgroundColor(), frame1->backgroundColor() ); QCOMPARE( frame2->backgroundColor(), frame1->backgroundColor() );
QCOMPARE( frame2->blendMode(), frame1->blendMode() ); QCOMPARE( frame2->blendMode(), frame1->blendMode() );
QCOMPARE( frame2->transparency(), frame1->transparency() ); QCOMPARE( frame2->itemOpacity(), frame1->itemOpacity() );
//check non-inherited properties //check non-inherited properties
QVERIFY( !frame2->hidePageIfEmpty() ); QVERIFY( !frame2->hidePageIfEmpty() );
@ -252,10 +252,10 @@ void TestQgsComposerMultiFrame::undoRedo()
mComposition->endMultiFrameCommand(); mComposition->endMultiFrameCommand();
//another frame command //another frame command
frame1->beginCommand( QStringLiteral( "bgcolor" ), QgsComposerMergeCommand::ItemTransparency ); frame1->beginCommand( QStringLiteral( "bgcolor" ), QgsComposerMergeCommand::ItemOpacity );
frame1->setBackgroundColor( QColor( 255, 255, 0 ) ); frame1->setBackgroundColor( QColor( 255, 255, 0 ) );
frame1->endCommand(); frame1->endCommand();
frame1->beginCommand( QStringLiteral( "bgcolor" ), QgsComposerMergeCommand::ItemTransparency ); frame1->beginCommand( QStringLiteral( "bgcolor" ), QgsComposerMergeCommand::ItemOpacity );
frame1->setBackgroundColor( QColor( 255, 0, 0 ) ); frame1->setBackgroundColor( QColor( 255, 0, 0 ) );
frame1->endCommand(); frame1->endCommand();