Skip to content
Permalink
Browse files

remove unused layer transparency (and fix some warnings)

  • Loading branch information
jef-n committed Apr 8, 2013
1 parent 2cd4c1a commit 6b2af9a2092cc890188cbd1ec0f3bdc72994da6e
@@ -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
@@ -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() );
@@ -324,6 +326,7 @@ QgsComposerLegend::Nucleon QgsComposerLegend::drawSymbolItem( QgsComposerLegendI
opacity = currentLayer->getTransparency();
}
}
#endif

QString text = symbolItem->text();
if ( text.isEmpty() )
@@ -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 );
}
@@ -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;
@@ -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() );
@@ -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();
@@ -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() )
@@ -369,6 +370,7 @@ bool QgsMapLayer::readXML( const QDomNode& layer_node )
QDomElement myElement = transparencyNode.toElement();
setTransparency( myElement.text().toInt() );
}
#endif

readCustomProperties( layer_node );

@@ -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

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

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

QString QgsMapLayer::capitaliseLayerName( const QString& name )
{
@@ -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() )
@@ -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 );
@@ -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;
@@ -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
@@ -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() )
@@ -1513,7 +1513,7 @@ bool QgsVectorLayer::readXml( const QDomNode& layer_node )

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

if( prevExpNode.isNull() )
if ( prevExpNode.isNull() )
{
mDisplayExpression = "";
}
@@ -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()
@@ -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 );
}
@@ -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;
@@ -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 );
@@ -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;
}
@@ -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;
@@ -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;
}
@@ -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" );
@@ -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
{
@@ -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;
@@ -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 ) );
@@ -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 );

@@ -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 )
@@ -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 );

@@ -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 );

@@ -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 )
@@ -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;
}
@@ -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 )
{
@@ -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 );

0 comments on commit 6b2af9a

Please sign in to comment.
You can’t perform that action at this time.