Skip to content

Commit

Permalink
Merge pull request #476 from nyalldawson/blend_modes
Browse files Browse the repository at this point in the history
Blend modes pt 2
  • Loading branch information
NathanW2 committed Mar 24, 2013
2 parents 176a08c + 08fba25 commit dac35e1
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 124 deletions.
6 changes: 0 additions & 6 deletions src/app/qgsvectorlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,6 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
mLayerAbstractTextEdit->setPlainText( layer->abstract() );
}

// Blend mode
mBlendModeComboBox->setBlendMode( layer->blendMode() );

QSettings settings;
restoreGeometry( settings.value( "/Windows/VectorLayerProperties/geometry" ).toByteArray() );
int tabIndex = settings.value( "/Windows/VectorLayerProperties/row", 0 ).toInt();
Expand Down Expand Up @@ -531,9 +528,6 @@ void QgsVectorLayerProperties::apply()
layer->setTitle( mLayerTitleLineEdit->text() );
layer->setAbstract( mLayerAbstractTextEdit->toPlainText() );

// set the blend mode for the layer
layer->setBlendMode(( QgsMapLayer::BlendMode ) mBlendModeComboBox->blendMode() );

// update symbology
emit refreshLegend( layer->id(), QgsLegendItem::DontChange );

Expand Down
15 changes: 0 additions & 15 deletions src/core/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,15 +411,6 @@ bool QgsMapLayer::readXML( const QDomNode& layer_node )
setTransparency( myElement.text().toInt() );
}

//read blend mode
QDomNode blendModeNode = layer_node.namedItem( "blendMode" );
if ( ! blendModeNode.isNull() )
{
// set blend mode if it's specified in project
QDomElement myElement = blendModeNode.toElement();
setBlendMode(( QgsMapLayer::BlendMode )myElement.text().toInt() );
}

readCustomProperties( layer_node );

return true;
Expand Down Expand Up @@ -536,12 +527,6 @@ bool QgsMapLayer::writeXML( QDomNode & layer_node, QDomDocument & document )
transparencyLevelIntElement.appendChild( transparencyLevelIntText );
maplayer.appendChild( transparencyLevelIntElement );

// <blendMode>
QDomElement blendModeElement = document.createElement( "blendMode" );
QDomText blendModeText = document.createTextNode( QString::number( blendMode() ) );
blendModeElement.appendChild( blendModeText );
maplayer.appendChild( blendModeElement );

// now append layer node to map layer node

layer_node.appendChild( maplayer );
Expand Down
7 changes: 5 additions & 2 deletions src/core/qgsmaprenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,10 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
.arg( ml->extent().toString() )
.arg( ml->blendMode() )
);

// Set the QPainter composition mode so that this layer is rendered using
// the desired blending mode
mypContextPainter->setCompositionMode(ml->getCompositionMode());
mypContextPainter->setCompositionMode( ml->getCompositionMode() );

if ( !ml->hasScaleBasedVisibility() || ( ml->minimumScale() <= mScale && mScale < ml->maximumScale() ) || mOverview )
{
Expand Down Expand Up @@ -559,6 +559,9 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )

QgsDebugMsg( "Done rendering map layers" );

// Reset the composition mode before rendering the labels
mRenderContext.painter()->setCompositionMode( QPainter::CompositionMode_SourceOver );

if ( !mOverview )
{
// render all labels for vector layers in the stack, starting at the base
Expand Down
14 changes: 14 additions & 0 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2260,6 +2260,14 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
setDisplayField( e.text() );
}

// get and set the blend mode if it exists
QDomNode blendModeNode = node.namedItem( "blendMode" );
if ( !blendModeNode.isNull() )
{
QDomElement e = blendModeNode.toElement();
setBlendMode(( QgsMapLayer::BlendMode ) e.text().toInt() );
}

// use scale dependent visibility flag
QDomElement e = node.toElement();
mLabel->setScaleBasedVisibility( e.attribute( "scaleBasedLabelVisibilityFlag", "0" ) == "1" );
Expand Down Expand Up @@ -2605,6 +2613,12 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
//save customproperties (for labeling ng)
writeCustomProperties( node, doc );

// add the blend mode field
QDomElement blendModeElem = doc.createElement( "blendMode" );
QDomText blendModeText = doc.createTextNode( QString::number( blendMode() ) );
blendModeElem.appendChild( blendModeText );
node.appendChild( blendModeElem );

// add the display field
QDomElement dField = doc.createElement( "displayfield" );
QDomText dFieldText = doc.createTextNode( displayField() );
Expand Down
14 changes: 14 additions & 0 deletions src/core/raster/qgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2312,6 +2312,14 @@ bool QgsRasterLayer::readSymbology( const QDomNode& layer_node, QString& errorMe
resampleFilter->readXML( resampleElem );
}

// get and set the blend mode if it exists
QDomNode blendModeNode = layer_node.namedItem( "blendMode" );
if ( !blendModeNode.isNull() )
{
QDomElement e = blendModeNode.toElement();
setBlendMode(( QgsMapLayer::BlendMode ) e.text().toInt() );
}

return true;
} //readSymbology

Expand Down Expand Up @@ -2499,6 +2507,12 @@ bool QgsRasterLayer::writeSymbology( QDomNode & layer_node, QDomDocument & docum
resampleFilter->writeXML( document, layerElem );
}

// add blend mode node
QDomElement blendModeElement = document.createElement( "blendMode" );
QDomText blendModeText = document.createTextNode( QString::number( blendMode() ) );
blendModeElement.appendChild( blendModeText );
layer_node.appendChild( blendModeElement );

return true;
} // bool QgsRasterLayer::writeSymbology

Expand Down
6 changes: 6 additions & 0 deletions src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog( QgsVectorLayer* la
// initialize registry's widget functions
_initRendererWidgetFunctions();

// Blend mode
mBlendModeComboBox->setBlendMode( mLayer->blendMode() );

QPixmap pix;
QgsRendererV2Registry* reg = QgsRendererV2Registry::instance();
QStringList renderers = reg->renderersList();
Expand Down Expand Up @@ -177,6 +180,9 @@ void QgsRendererV2PropertiesDialog::apply()
{
mLayer->setRendererV2( renderer->clone() );
}

// set the blend mode for the layer
mLayer->setBlendMode(( QgsMapLayer::BlendMode ) mBlendModeComboBox->blendMode() );
}

void QgsRendererV2PropertiesDialog::onOK()
Expand Down
73 changes: 25 additions & 48 deletions src/ui/qgsrasterlayerpropertiesbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,23 @@
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="mBlendTypeLabel">
<property name="text">
<string>Blending mode</string>
</property>
</widget>
</item>
<item>
<widget class="QgsBlendModeComboBox" name="mBlendModeComboBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand All @@ -158,13 +175,19 @@
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mResamplingGroupBox"><property name="collapsed" stdset="0"><bool>false</bool></property><property name="saveCollapsedState" stdset="0"><bool>true</bool></property>
<widget class="QgsCollapsibleGroupBox" name="mResamplingGroupBox">
<property name="title">
<string>Resampling</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="collapsed" stdset="0">
<bool>false</bool>
</property>
<property name="saveCollapsedState" stdset="0">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="mZoomedInResamplingLabel">
Expand Down Expand Up @@ -869,52 +892,6 @@ p, li { white-space: pre-wrap; }
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<property name="leftMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="mBlendTypeLabel">
<property name="text">
<string>Composition blending mode</string>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="QgsBlendModeComboBox" name="mBlendModeComboBox" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="grpSRS">
<property name="title">
Expand Down Expand Up @@ -1326,7 +1303,7 @@ p, li { white-space: pre-wrap; }
</customwidget>
<customwidget>
<class>QgsBlendModeComboBox</class>
<extends>QWidget</extends>
<extends>QComboBox</extends>
<header>qgsblendmodecombobox.h</header>
</customwidget>
</customwidgets>
Expand Down
17 changes: 17 additions & 0 deletions src/ui/qgsrendererv2propsdialogbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Blending mode</string>
</property>
</widget>
</item>
<item>
<widget class="QgsBlendModeComboBox" name="mBlendModeComboBox"/>
</item>
<item>
<widget class="QPushButton" name="btnOldSymbology">
<property name="text">
Expand Down Expand Up @@ -77,6 +87,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsBlendModeComboBox</class>
<extends>QComboBox</extends>
<header>qgsblendmodecombobox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>cboRenderers</tabstop>
<tabstop>buttonBox</tabstop>
Expand Down
55 changes: 2 additions & 53 deletions src/ui/qgsvectorlayerpropertiesbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ p, li { white-space: pre-wrap; }
</layout>
</widget>
</item>
<item row="4" column="0">
<item row="3" column="0">
<widget class="QGroupBox" name="grpSubset">
<property name="title">
<string>Subset</string>
Expand Down Expand Up @@ -578,7 +578,7 @@ p, li { white-space: pre-wrap; }
</layout>
</widget>
</item>
<item row="3" column="0">
<item row="2" column="0">
<widget class="QGroupBox" name="grpProviderOptions">
<property name="title">
<string>Provider-specific options</string>
Expand All @@ -600,52 +600,6 @@ p, li { white-space: pre-wrap; }
</layout>
</widget>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<property name="leftMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="mBlendTypeLabel">
<property name="text">
<string>Composition blending mode</string>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="QgsBlendModeComboBox" name="mBlendModeComboBox" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
Expand Down Expand Up @@ -1054,11 +1008,6 @@ p, li { white-space: pre-wrap; }
<extends>QWidget</extends>
<header>qgsscalecombobox.h</header>
</customwidget>
<customwidget>
<class>QgsBlendModeComboBox</class>
<extends>QWidget</extends>
<header>qgsblendmodecombobox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>cbMinimumScale</tabstop>
Expand Down

0 comments on commit dac35e1

Please sign in to comment.