Skip to content

Commit

Permalink
remove unused layer transparency (and fix some warnings)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Apr 8, 2013
1 parent 2cd4c1a commit 6b2af9a
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 38 deletions.
4 changes: 2 additions & 2 deletions python/core/qgsmaplayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ class QgsMapLayer : QObject
void removeCustomProperty( const QString& key );

/** Accessor for transparency level. */
unsigned int getTransparency();
// unsigned int getTransparency();

/** Mutator for transparency level. Should be between 0 and 255 */
virtual void setTransparency( unsigned int );
// virtual void setTransparency( unsigned int );

/**
* If an operation returns 0 (e.g. draw()), this function
Expand Down
10 changes: 6 additions & 4 deletions src/core/composer/qgscomposerlegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,10 @@ QgsComposerLegend::Nucleon QgsComposerLegend::drawSymbolItem( QgsComposerLegendI
//real symbol height. Can be different from standard height in case of point symbols
double realSymbolHeight;

int opacity = 255;
QgsComposerLayerItem* layerItem = dynamic_cast<QgsComposerLayerItem*>( symbolItem->parent() );

#if 0
int opacity = 255;
if ( layerItem )
{
QgsMapLayer* currentLayer = QgsMapLayerRegistry::instance()->mapLayer( layerItem->layerID() );
Expand All @@ -324,6 +326,7 @@ QgsComposerLegend::Nucleon QgsComposerLegend::drawSymbolItem( QgsComposerLegendI
opacity = currentLayer->getTransparency();
}
}
#endif

QString text = symbolItem->text();
if ( text.isEmpty() )
Expand All @@ -346,7 +349,7 @@ QgsComposerLegend::Nucleon QgsComposerLegend::drawSymbolItem( QgsComposerLegendI
if ( symbolNg ) //item with symbol NG?
{
// must be called also with painter=0 to get real size
drawSymbolV2( painter, symbolNg, point.y() + ( itemHeight - mSymbolHeight ) / 2, x, realSymbolHeight, opacity );
drawSymbolV2( painter, symbolNg, point.y() + ( itemHeight - mSymbolHeight ) / 2, x, realSymbolHeight );
symbolSize.rwidth() = qMax( x - point.x(), mSymbolWidth );
symbolSize.rheight() = qMax( realSymbolHeight, mSymbolHeight );
}
Expand Down Expand Up @@ -414,9 +417,8 @@ QgsComposerLegend::Nucleon QgsComposerLegend::drawSymbolItem( QgsComposerLegendI
}


void QgsComposerLegend::drawSymbolV2( QPainter* p, QgsSymbolV2* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int layerOpacity ) const
void QgsComposerLegend::drawSymbolV2( QPainter* p, QgsSymbolV2* s, double currentYCoord, double& currentXPosition, double& symbolHeight ) const
{
Q_UNUSED( layerOpacity );
if ( !s )
{
return;
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposerlegend.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem

/**Draws a symbol at the current y position and returns the new x position. Returns real symbol height, because for points,
it is possible that it differs from mSymbolHeight*/
void drawSymbolV2( QPainter* p, QgsSymbolV2* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int layerOpacity = 255 ) const;
void drawSymbolV2( QPainter* p, QgsSymbolV2* s, double currentYCoord, double& currentXPosition, double& symbolHeight ) const;

/** Draw atom and return its actual size */
QSizeF drawAtom( Atom atom, QPainter* painter = 0, QPointF point = QPointF() );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgscrscache.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CORE_EXPORT QgsCRSCache
~QgsCRSCache();
/**Returns the CRS for authid, e.g. 'EPSG:4326' (or an invalid CRS in case of error)*/
const QgsCoordinateReferenceSystem& crsByAuthId( const QString& authid );
const QgsCoordinateReferenceSystem& crsByEpsgId( long epgs );
const QgsCoordinateReferenceSystem& crsByEpsgId( long epsg );

protected:
QgsCRSCache();
Expand Down
11 changes: 11 additions & 0 deletions src/core/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ bool QgsMapLayer::readXML( const QDomNode& layer_node )
mAbstract = abstractElem.text();
}

#if 0
//read transparency level
QDomNode transparencyNode = layer_node.namedItem( "transparencyLevelInt" );
if ( ! transparencyNode.isNull() )
Expand All @@ -369,6 +370,7 @@ bool QgsMapLayer::readXML( const QDomNode& layer_node )
QDomElement myElement = transparencyNode.toElement();
setTransparency( myElement.text().toInt() );
}
#endif

readCustomProperties( layer_node );

Expand Down Expand Up @@ -480,11 +482,13 @@ bool QgsMapLayer::writeXML( QDomNode & layer_node, QDomDocument & document )
mCRS->writeXML( mySrsElement, document );
maplayer.appendChild( mySrsElement );

#if 0
// <transparencyLevelInt>
QDomElement transparencyLevelIntElement = document.createElement( "transparencyLevelInt" );
QDomText transparencyLevelIntText = document.createTextNode( QString::number( getTransparency() ) );
transparencyLevelIntElement.appendChild( transparencyLevelIntText );
maplayer.appendChild( transparencyLevelIntElement );
#endif

// now append layer node to map layer node

Expand Down Expand Up @@ -610,6 +614,7 @@ void QgsMapLayer::setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSign
emit layerCrsChanged();
}

#if 0
unsigned int QgsMapLayer::getTransparency()
{
return mTransparencyLevel;
Expand All @@ -619,6 +624,7 @@ void QgsMapLayer::setTransparency( unsigned int theInt )
{
mTransparencyLevel = theInt;
}
#endif

QString QgsMapLayer::capitaliseLayerName( const QString& name )
{
Expand Down Expand Up @@ -818,6 +824,7 @@ QString QgsMapLayer::loadNamedStyle( const QString theURI, bool &theResultFlag )
setMinimumScale( myRoot.attribute( "minimumScale" ).toFloat() );
setMaximumScale( myRoot.attribute( "maximumScale" ).toFloat() );

#if 0
//read transparency level
QDomNode transparencyNode = myRoot.namedItem( "transparencyLevelInt" );
if ( ! transparencyNode.isNull() )
Expand All @@ -827,6 +834,7 @@ QString QgsMapLayer::loadNamedStyle( const QString theURI, bool &theResultFlag )
QDomElement myElement = transparencyNode.toElement();
setTransparency( myElement.text().toInt() );
}
#endif

QString errorMsg;
theResultFlag = readSymbology( myRoot, errorMsg );
Expand Down Expand Up @@ -862,11 +870,14 @@ QString QgsMapLayer::saveNamedStyle( const QString theURI, bool & theResultFlag
myRootNode.setAttribute( "minimumScale", QString::number( minimumScale() ) );
myRootNode.setAttribute( "maximumScale", QString::number( maximumScale() ) );

#if 0
// <transparencyLevelInt>
QDomElement transparencyLevelIntElement = myDocument.createElement( "transparencyLevelInt" );
QDomText transparencyLevelIntText = myDocument.createTextNode( QString::number( getTransparency() ) );
transparencyLevelIntElement.appendChild( transparencyLevelIntText );
myRootNode.appendChild( transparencyLevelIntElement );
#endif

// now append layer node to map layer node

QString errorMsg;
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsmaplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,13 @@ class CORE_EXPORT QgsMapLayer : public QObject
* @note Added in v1.4 */
void removeCustomProperty( const QString& key );

#if 0
/** Accessor for transparency level. */
unsigned int getTransparency();

/** Mutator for transparency level. Should be between 0 and 255 */
virtual void setTransparency( unsigned int );
#endif

/**
* If an operation returns 0 (e.g. draw()), this function
Expand Down
8 changes: 4 additions & 4 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ void QgsVectorLayer::drawLabels( QgsRenderContext& rendererContext )
QgsDebugMsg( "Starting draw of labels: " + id() );

if ( mRendererV2 && mLabelOn &&
( !mLabel->scaleBasedVisibility() ||
( mLabel->minScale() <= rendererContext.rendererScale() &&
rendererContext.rendererScale() <= mLabel->maxScale() ) ) )
( !mLabel->scaleBasedVisibility() ||
( mLabel->minScale() <= rendererContext.rendererScale() &&
rendererContext.rendererScale() <= mLabel->maxScale() ) ) )
{
QgsAttributeList attributes;
foreach ( QString attrName, mRendererV2->usedAttributes() )
Expand Down Expand Up @@ -1513,7 +1513,7 @@ bool QgsVectorLayer::readXml( const QDomNode& layer_node )

QDomNode prevExpNode = layer_node.namedItem( "previewExpression" );

if( prevExpNode.isNull() )
if ( prevExpNode.isNull() )
{
mDisplayExpression = "";
}
Expand Down
4 changes: 2 additions & 2 deletions src/gui/attributetable/qgsdualview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ QgsDualView::QgsDualView( QWidget* parent )
// Connect layer list preview signals
connect( mActionExpressionPreview, SIGNAL( triggered() ), SLOT( previewExpressionBuilder() ) );
connect( mPreviewActionMapper, SIGNAL( mapped( QObject* ) ), SLOT( previewColumnChanged( QObject* ) ) );
connect( mFeatureList, SIGNAL( displayExpressionChanged(QString) ), this, SLOT( previewExpressionChanged(QString) ) );
connect( mFeatureList, SIGNAL( displayExpressionChanged( QString ) ), this, SLOT( previewExpressionChanged( QString ) ) );
}

QgsDualView::~QgsDualView()
Expand Down Expand Up @@ -213,7 +213,7 @@ void QgsDualView::initModels( QgsMapCanvas* mapCanvas )
mFilterModel = new QgsAttributeTableFilterModel( mapCanvas, mMasterModel, mMasterModel );

connect( mFilterModel, SIGNAL( filterInvalidated() ), this, SIGNAL( filterChanged() ) );
connect( mFeatureList, SIGNAL( displayExpressionChanged(QString) ), this, SIGNAL( displayExpressionChanged(QString) ) );
connect( mFeatureList, SIGNAL( displayExpressionChanged( QString ) ), this, SIGNAL( displayExpressionChanged( QString ) ) );

mFeatureListModel = new QgsFeatureListModel( mFilterModel, mFilterModel );
}
Expand Down
12 changes: 12 additions & 0 deletions src/mapserver/qgssldparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ QList<QgsMapLayer*> QgsSLDParser::mapLayerFromStyle( const QString& layerName, c
#ifdef DIAGRAMSERVER
overlaysFromUserStyle( userStyleElement, v );
#endif //DIAGRAMSERVER
#if 0
setOpacityForLayer( namedLayerElemList[i], v );
#endif

resultList.push_back( v );
return resultList;
Expand All @@ -293,7 +295,9 @@ QList<QgsMapLayer*> QgsSLDParser::mapLayerFromStyle( const QString& layerName, c
{
rasterSymbologyFromUserStyle( userStyleElement, r );

#if 0
setOpacityForLayer( namedLayerElemList[i], r );
#endif

//Using a contour symbolizer, there may be a raster and a vector layer
QgsVectorLayer* v = contourLayerFromRaster( userStyleElement, r );
Expand All @@ -320,11 +324,13 @@ QList<QgsMapLayer*> QgsSLDParser::mapLayerFromStyle( const QString& layerName, c
resultList = mFallbackParser->mapLayerFromStyle( layerName, styleName, useCache );
}

#if 0
QList<QgsMapLayer*>::iterator it = resultList.begin();
for ( ; it != resultList.end(); ++it )
{
setOpacityForLayer( userLayerElement, *it );
}
#endif

return resultList;
}
Expand Down Expand Up @@ -361,7 +367,9 @@ QList<QgsMapLayer*> QgsSLDParser::mapLayerFromStyle( const QString& layerName, c
mLayersToRemove.push_back( v );
}
}
#if 0
setOpacityForLayer( userLayerElement, theMapLayer );
#endif
resultList.push_back( theMapLayer );

return resultList;
Expand Down Expand Up @@ -394,7 +402,9 @@ QList<QgsMapLayer*> QgsSLDParser::mapLayerFromStyle( const QString& layerName, c
}
theVectorLayer->setRendererV2( theRenderer );
QgsDebugMsg( "Returning the vectorlayer" );
#if 0
setOpacityForLayer( userLayerElement, theVectorLayer );
#endif
resultList.push_back( theVectorLayer );
return resultList;
}
Expand Down Expand Up @@ -1449,6 +1459,7 @@ QString QgsSLDParser::layerNameFromUri( const QString& uri ) const
return "";
}

#if 0
void QgsSLDParser::setOpacityForLayer( const QDomElement& layerElem, QgsMapLayer* layer ) const
{
QDomNode opacityNode = layerElem.namedItem( "Opacity" );
Expand Down Expand Up @@ -1477,6 +1488,7 @@ void QgsSLDParser::setOpacityForLayer( const QDomElement& layerElem, QgsMapLayer
QgsDebugMsg( "Setting opacity value: " + QString::number( opacityValue ) );
layer->setTransparency( opacityValue );
}
#endif

void QgsSLDParser::clearRasterSymbology( QgsRasterLayer* rl ) const
{
Expand Down
2 changes: 2 additions & 0 deletions src/mapserver/qgssldparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ class QgsSLDParser: public QgsConfigParser
QgsVectorLayer* contourLayerFromRaster( const QDomElement& userStyleElem, QgsRasterLayer* rasterLayer ) const;
/**Creates a suitable layer name from a URL. */
QString layerNameFromUri( const QString& uri ) const;
#if 0
/**Sets the opacity on layer level if the <Opacity> tag is present*/
void setOpacityForLayer( const QDomElement& layerElem, QgsMapLayer* layer ) const;
#endif
/**Resets the former symbology of a raster layer. This is important for single band layers (e.g. dems)
coming from the cash*/
void clearRasterSymbology( QgsRasterLayer* rl ) const;
Expand Down
27 changes: 5 additions & 22 deletions src/mapserver/qgswmsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,10 @@ QByteArray* QgsWMSServer::getPrint( const QString& formatString )

QList< QPair< QgsVectorLayer*, QgsFeatureRendererV2*> > bkVectorRenderers;
QList< QPair< QgsRasterLayer*, QgsRasterRenderer* > > bkRasterRenderers;
QList< QPair< QgsVectorLayer*, unsigned int> > bkVectorOld;
QList< QPair< QgsVectorLayer*, double > > labelTransparencies;
QList< QPair< QgsVectorLayer*, double > > labelBufferTransparencies;

applyOpacities( layersList, bkVectorRenderers, bkVectorOld, bkRasterRenderers, labelTransparencies, labelBufferTransparencies );
applyOpacities( layersList, bkVectorRenderers, bkRasterRenderers, labelTransparencies, labelBufferTransparencies );


QgsComposition* c = mConfigParser->createPrintComposition( mParameterMap[ "TEMPLATE" ], mMapRenderer, QMap<QString, QString>( mParameterMap ) );
Expand Down Expand Up @@ -591,7 +590,7 @@ QByteArray* QgsWMSServer::getPrint( const QString& formatString )
throw QgsMapServiceException( "InvalidFormat", "Output format '" + formatString + "' is not supported in the GetPrint request" );
}

restoreOpacities( bkVectorRenderers, bkVectorOld, bkRasterRenderers, labelTransparencies, labelBufferTransparencies );
restoreOpacities( bkVectorRenderers, bkRasterRenderers, labelTransparencies, labelBufferTransparencies );
restoreLayerFilters( originalLayerFilters );
clearFeatureSelections( selectedLayerIdList );

Expand Down Expand Up @@ -632,11 +631,10 @@ QImage* QgsWMSServer::getMap()

QList< QPair< QgsVectorLayer*, QgsFeatureRendererV2*> > bkVectorRenderers;
QList< QPair< QgsRasterLayer*, QgsRasterRenderer* > > bkRasterRenderers;
QList< QPair< QgsVectorLayer*, unsigned int> > bkVectorOld;
QList< QPair< QgsVectorLayer*, double > > labelTransparencies;
QList< QPair< QgsVectorLayer*, double > > labelBufferTransparencies;

applyOpacities( layersList, bkVectorRenderers, bkVectorOld, bkRasterRenderers, labelTransparencies, labelBufferTransparencies );
applyOpacities( layersList, bkVectorRenderers, bkRasterRenderers, labelTransparencies, labelBufferTransparencies );

mMapRenderer->render( &thePainter );
if ( mConfigParser )
Expand All @@ -645,7 +643,7 @@ QImage* QgsWMSServer::getMap()
mConfigParser->drawOverlays( &thePainter, theImage->dotsPerMeterX() / 1000.0 * 25.4, theImage->width(), theImage->height() );
}

restoreOpacities( bkVectorRenderers, bkVectorOld, bkRasterRenderers, labelTransparencies, labelBufferTransparencies );
restoreOpacities( bkVectorRenderers, bkRasterRenderers, labelTransparencies, labelBufferTransparencies );
restoreLayerFilters( originalLayerFilters );
clearFeatureSelections( selectedLayerIdList );

Expand Down Expand Up @@ -1499,13 +1497,6 @@ void QgsWMSServer::drawLegendLayerItem( QgsComposerLayerItem* item, QPainter* p,

currentY += layerTitleSpace;

int opacity = 0;
QgsMapLayer* layerInstance = QgsMapLayerRegistry::instance()->mapLayer( item->layerID() );
if ( layerInstance )
{
opacity = layerInstance->getTransparency(); //maplayer says transparency but means opacity
}

//then draw all the children
QFontMetricsF itemFontMetrics( itemFont );

Expand Down Expand Up @@ -1947,7 +1938,6 @@ void QgsWMSServer::clearFeatureSelections( const QStringList& layerIds ) const
}

void QgsWMSServer::applyOpacities( const QStringList& layerList, QList< QPair< QgsVectorLayer*, QgsFeatureRendererV2*> >& vectorRenderers,
QList< QPair< QgsVectorLayer*, unsigned int> >& vectorOld,
QList< QPair< QgsRasterLayer*, QgsRasterRenderer* > >& rasterRenderers,
QList< QPair< QgsVectorLayer*, double > >& labelTransparencies,
QList< QPair< QgsVectorLayer*, double > >& labelBufferTransparencies )
Expand Down Expand Up @@ -2036,12 +2026,11 @@ void QgsWMSServer::applyOpacities( const QStringList& layerList, QList< QPair< Q
}

void QgsWMSServer::restoreOpacities( QList< QPair< QgsVectorLayer*, QgsFeatureRendererV2*> >& vectorRenderers,
QList< QPair< QgsVectorLayer*, unsigned int> >& vectorOld,
QList < QPair< QgsRasterLayer*, QgsRasterRenderer* > >& rasterRenderers,
QList< QPair< QgsVectorLayer*, double > >& labelOpacities,
QList< QPair< QgsVectorLayer*, double > >& labelBufferOpacities )
{
if ( vectorRenderers.isEmpty() && vectorOld.isEmpty() && rasterRenderers.isEmpty() )
if ( vectorRenderers.isEmpty() && rasterRenderers.isEmpty() )
{
return;
}
Expand All @@ -2058,12 +2047,6 @@ void QgsWMSServer::restoreOpacities( QList< QPair< QgsVectorLayer*, QgsFeatureRe
( *rIt ).first->setRenderer(( *rIt ).second );
}

QList< QPair< QgsVectorLayer*, unsigned int> >::iterator oIt = vectorOld.begin();
for ( ; oIt != vectorOld.end(); ++oIt )
{
( *oIt ).first->setTransparency(( *oIt ).second );
}

QList< QPair< QgsVectorLayer*, double > >::iterator loIt = labelOpacities.begin();
for ( ; loIt != labelOpacities.end(); ++loIt )
{
Expand Down
2 changes: 0 additions & 2 deletions src/mapserver/qgswmsserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,13 @@ class QgsWMSServer

/**Applies opacity on layer/group level*/
void applyOpacities( const QStringList& layerList, QList< QPair< QgsVectorLayer*, QgsFeatureRendererV2*> >& vectorRenderers,
QList< QPair< QgsVectorLayer*, unsigned int> >& vectorOld,
QList< QPair< QgsRasterLayer*, QgsRasterRenderer* > >& rasterRenderers,
QList< QPair< QgsVectorLayer*, double > >& labelTransparencies,
QList< QPair< QgsVectorLayer*, double > >& labelBufferTransparencies
);

/**Restore original opacities*/
void restoreOpacities( QList< QPair <QgsVectorLayer*, QgsFeatureRendererV2*> >& vectorRenderers,
QList< QPair <QgsVectorLayer*, unsigned int> >& vectorOld,
QList< QPair < QgsRasterLayer*, QgsRasterRenderer* > >& rasterRenderers,
QList< QPair< QgsVectorLayer*, double > >& labelTransparencies,
QList< QPair< QgsVectorLayer*, double > >& labelBufferTransparencies );
Expand Down

0 comments on commit 6b2af9a

Please sign in to comment.