Skip to content
Permalink
Browse files

[API] Removed old renderer support from QgsVectorLayer

  • Loading branch information
wonder-sk committed Apr 7, 2013
1 parent 37da713 commit c2f00caedfc545df6d993ec2c7a57ae1adb56a55
@@ -171,7 +171,6 @@

%Include symbology-ng/qgsstylev2.sip
%Include symbology-ng/qgssvgcache.sip
%Include symbology-ng/qgssymbologyv2conversion.sip
%Include symbology-ng/qgssymbolv2.sip
%Include symbology-ng/qgscolorbrewerpalette.sip
%Include symbology-ng/qgscptcityarchive.sip
@@ -242,12 +242,6 @@ class QgsVectorLayer : QgsMapLayer
/** Returns the bounding box of the selected features. If there is no selection, QgsRectangle(0,0,0,0) is returned */
QgsRectangle boundingBoxOfSelected();

/** Returns a pointer to the renderer */
const QgsRenderer* renderer() const;

/** Sets the renderer. If a renderer is already present, it is deleted */
void setRenderer( QgsRenderer * r /Transfer/ );

/** Sets diagram rendering object (takes ownership) */
void setDiagramRenderer( QgsDiagramRendererV2* r /Transfer/ );
const QgsDiagramRendererV2* diagramRenderer() const;
@@ -262,14 +256,6 @@ class QgsVectorLayer : QgsMapLayer
* @note added in 1.4
*/
void setRendererV2( QgsFeatureRendererV2* r /Transfer/ );
/** Return whether using renderer V2.
* @note added in 1.4
*/
bool isUsingRendererV2();
/** set whether to use renderer V2 for drawing.
* @note added in 1.4
*/
void setUsingRendererV2( bool usingRendererV2 );

/** Draw layer with renderer V2.
* @note added in 1.4

This file was deleted.

@@ -137,10 +137,7 @@ void QgsLegendLayer::refreshSymbology( const QString& key, double widthScale )
if ( theMapLayer->type() == QgsMapLayer::VectorLayer ) // VECTOR
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( theMapLayer );
if ( vlayer->isUsingRendererV2() )
vectorLayerSymbologyV2( vlayer );
else
vectorLayerSymbology( vlayer, widthScale ); // get and change symbology
vectorLayerSymbologyV2( vlayer );
}
else if ( theMapLayer->type() == QgsMapLayer::RasterLayer ) // RASTER
{
@@ -187,106 +184,6 @@ void QgsLegendLayer::changeSymbologySettings( const QgsMapLayer* theMapLayer,



void QgsLegendLayer::vectorLayerSymbology( QgsVectorLayer* layer, double widthScale )
{
if ( !layer )
{
return;
}

SymbologyList itemList;
if ( layer->hasGeometryType() )
{
//add the new items
QString lw, uv, label;
const QgsRenderer* renderer = layer->renderer();
const QList<QgsSymbol*> sym = renderer->symbols();

//create an item for each classification field (only one for most renderers)
QSettings settings;
if ( settings.value( "/qgis/showLegendClassifiers", false ).toBool() )
{
if ( renderer->needsAttributes() )
{
QgsAttributeList classfieldlist = renderer->classificationAttributes();
const QgsFields& fields = layer->pendingFields();
for ( QgsAttributeList::iterator it = classfieldlist.begin(); it != classfieldlist.end(); ++it )
{
int idx = *it;
if ( idx < 0 || idx >= fields.count() )
continue;
QString classfieldname = layer->attributeAlias( idx );
if ( classfieldname.isEmpty() )
{
classfieldname = fields[idx].name();
}
itemList.append( qMakePair( classfieldname, QPixmap() ) );
}
}
}

QMap< QgsSymbol*, int > featureCountMap;
if ( mShowFeatureCount )
{
updateItemListCount( layer, sym, featureCountMap );
}

for ( QList<QgsSymbol*>::const_iterator it = sym.begin(); it != sym.end(); ++it )
{
QImage img;
if (( *it )->type() == QGis::Point )
{
img = ( *it )->getPointSymbolAsImage( widthScale );
}
else if (( *it )->type() == QGis::Line )
{
img = ( *it )->getLineSymbolAsImage();
}
else if (( *it )->type() == QGis::Polygon )
{
img = ( *it )->getPolygonSymbolAsImage();
}
else
{
// must be a layer without geometry then
}

QString values;
lw = ( *it )->lowerValue();
if ( !lw.isEmpty() )
{
values += lw;
}
uv = ( *it )->upperValue();
if ( !uv.isEmpty() && lw != uv )
{
values += " - ";
values += uv;
}
label = ( *it )->label();
if ( !label.isEmpty() )
{
values += " ";
values += label;
}

if ( mShowFeatureCount )
{
int fCount = featureCountMap[*it];
if ( fCount >= 0 )
{
values += ( " [" + QString::number( fCount ) + "]" );
}
}

QPixmap pix = QPixmap::fromImage( img ); // convert to pixmap
itemList.append( qMakePair( values, pix ) );
}
}
changeSymbologySettings( layer, itemList );
}


void QgsLegendLayer::vectorLayerSymbologyV2( QgsVectorLayer* layer )
{
QSize iconSize( 16, 16 );
@@ -666,60 +563,6 @@ void QgsLegendLayer::updateItemListCountV2( SymbologyList& itemList, QgsVectorLa
}
}

void QgsLegendLayer::updateItemListCount( QgsVectorLayer* layer, const QList<QgsSymbol*>& sym, QMap< QgsSymbol*, int >& featureCountMap )
{
featureCountMap.clear();
QList<QgsSymbol*>::const_iterator symbolIt = sym.constBegin();
for ( ; symbolIt != sym.constEnd(); ++symbolIt )
{
featureCountMap.insert( *symbolIt, 0 );
}

QgsRenderer* renderer = const_cast<QgsRenderer*>( layer->renderer() );
if ( !renderer )
{
return;
}

//go through all features and count the number of occurrences
int nFeatures = layer->pendingFeatureCount();
QProgressDialog p( tr( "Updating feature count for layer %1" ).arg( layer->name() ), tr( "Abort" ), 0, nFeatures );
p.setWindowModality( Qt::WindowModal );
int featuresCounted = 0;

QgsFeatureIterator fit = layer->getFeatures( QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry ) );
QgsFeature f;
QgsSymbol* currentSymbol = 0;

while ( fit.nextFeature( f ) )
{
currentSymbol = renderer->symbolForFeature( &f );
if ( currentSymbol )
{
featureCountMap[currentSymbol] += 1;
}
++featuresCounted;

if ( featuresCounted % 50 == 0 )
{
if ( featuresCounted > nFeatures ) //sometimes the feature count is not correct
{
p.setMaximum( 0 );
}
p.setValue( featuresCounted );
if ( p.wasCanceled() ) //set all entries to -1 (= invalid)
{
QMap< QgsSymbol*, int >::iterator cIt = featureCountMap.begin();
for ( ; cIt != featureCountMap.end(); ++cIt )
{
cIt.value() = -1;
}
return;
}
}
}
p.setValue( nFeatures );
}

void QgsLegendLayer::setShowFeatureCount( bool show, bool update )
{
@@ -110,8 +110,6 @@ class QgsLegendLayer : public QgsLegendItem
protected:

/** Prepare and change symbology for vector layer */
void vectorLayerSymbology( QgsVectorLayer* mapLayer, double widthScale = 1.0 );

void vectorLayerSymbologyV2( QgsVectorLayer* vlayer );

/** Prepare and change symbology for raster layer */
@@ -122,8 +120,6 @@ class QgsLegendLayer : public QgsLegendItem

/**Adds feature counts to the symbology items (for symbology v2)*/
void updateItemListCountV2( SymbologyList& itemList, QgsVectorLayer* layer );
/**Calculates feature count for the individual symbols (old symbology)*/
void updateItemListCount( QgsVectorLayer* layer, const QList<QgsSymbol*>& sym, QMap< QgsSymbol*, int >& featureCountMap );

QPixmap getOriginalPixmap();

@@ -238,26 +238,6 @@ int QgsMapToolRotatePointSymbols::layerRotationAttributes( QgsVectorLayer* vl, Q
return 1;
}

//old symbology
const QgsRenderer* layerRenderer = vl->renderer();
if ( layerRenderer )
{
//get renderer symbols
const QList<QgsSymbol*> rendererSymbols = layerRenderer->symbols();
int currentRotationAttribute;

QList<QgsSymbol*>::const_iterator symbolIt = rendererSymbols.constBegin();
for ( ; symbolIt != rendererSymbols.constEnd(); ++symbolIt )
{
currentRotationAttribute = ( *symbolIt )->rotationClassificationField();
if ( currentRotationAttribute >= 0 )
{
attList.push_back( currentRotationAttribute );
}
}
return 0;
}

//new symbology
const QgsFeatureRendererV2* symbologyNgRenderer = vl->rendererV2();
if ( symbologyNgRenderer )
@@ -306,27 +286,10 @@ void QgsMapToolRotatePointSymbols::createPixmapItem( QgsFeature& f )

//get the image that is used for that symbol, but without point rotation
QImage pointImage;
QgsRenderer* r = 0;
QgsFeatureRendererV2* rv2 = 0;

if ( mActiveLayer && mActiveLayer->renderer() ) //old symbology
{
//copy renderer
QgsRenderer* r = mActiveLayer->renderer()->clone();

//set all symbol fields of the cloned renderer to -1. Very ugly but necessary
QList<QgsSymbol*> symbolList( r->symbols() );
QList<QgsSymbol*>::iterator it = symbolList.begin();
for ( ; it != symbolList.end(); ++it )
{
( *it )->setRotationClassificationField( -1 );
}

r->renderFeature( *renderContext, f, &pointImage, false );
}
else if ( mActiveLayer && mActiveLayer->rendererV2() ) //symbology-ng
if ( mActiveLayer && mActiveLayer->rendererV2() ) //symbology-ng
{
rv2 = mActiveLayer->rendererV2()->clone();
QgsFeatureRendererV2* rv2 = mActiveLayer->rendererV2()->clone();
rv2->setRotationField( "" );
rv2->startRender( *renderContext, mActiveLayer );

@@ -336,12 +299,11 @@ void QgsMapToolRotatePointSymbols::createPixmapItem( QgsFeature& f )
pointImage = symbolV2->bigSymbolPreviewImage();
}
rv2->stopRender( *renderContext );
delete rv2;
}

mRotationItem = new QgsPointRotationItem( mCanvas );
mRotationItem->setSymbol( pointImage );
delete r;
delete rv2;
}

void QgsMapToolRotatePointSymbols::setPixmapItemRotation( double rotation )
@@ -500,15 +500,6 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
chkAntiAliasing->setChecked( settings.value( "/qgis/enable_anti_aliasing", true ).toBool() );
chkUseRenderCaching->setChecked( settings.value( "/qgis/enable_render_caching", false ).toBool() );

//Changed to default to true as of QGIS 1.7
//TODO: remove hack when http://hub.qgis.org/issues/5170 is fixed
#ifdef ANDROID
bool use_symbology_ng_default = false;
#else
bool use_symbology_ng_default = true;
#endif
chkUseSymbologyNG->setChecked( settings.value( "/qgis/use_symbology_ng", use_symbology_ng_default ).toBool() );

// Slightly awkard here at the settings value is true to use QImage,
// but the checkbox is true to use QPixmap
chkUseQPixmap->setChecked( !( settings.value( "/qgis/use_qimage_to_render", true ).toBool() ) );
@@ -1031,7 +1022,6 @@ void QgsOptions::saveOptions()
settings.setValue( "/qgis/enable_anti_aliasing", chkAntiAliasing->isChecked() );
settings.setValue( "/qgis/enable_render_caching", chkUseRenderCaching->isChecked() );
settings.setValue( "/qgis/use_qimage_to_render", !( chkUseQPixmap->isChecked() ) );
settings.setValue( "/qgis/use_symbology_ng", chkUseSymbologyNG->isChecked() );
settings.setValue( "/qgis/legendDoubleClickAction", cmbLegendDoubleClickAction->currentIndex() );
bool legendLayersCapitalise = settings.value( "/qgis/capitaliseLayerName", false ).toBool();
settings.setValue( "/qgis/capitaliseLayerName", capitaliseCheckBox->isChecked() );
@@ -413,12 +413,8 @@ void QgsVectorLayerProperties::apply()
// Apply fields settings
mFieldsPropertiesDialog->apply();

if ( layer->isUsingRendererV2() )
{
QgsRendererV2PropertiesDialog* dlg =
static_cast<QgsRendererV2PropertiesDialog*>( widgetStackRenderers->currentWidget() );
dlg->apply();
}
QgsRendererV2PropertiesDialog* dlg = static_cast<QgsRendererV2PropertiesDialog*>( widgetStackRenderers->currentWidget() );
dlg->apply();

//apply diagram settings
diagramPropertiesDialog->apply();
@@ -778,19 +774,12 @@ void QgsVectorLayerProperties::updateSymbologyPage()
delete mRendererDialog;
mRendererDialog = 0;

if ( layer->isUsingRendererV2() )
{
mRendererDialog = new QgsRendererV2PropertiesDialog( layer, QgsStyleV2::defaultStyle(), true );
mRendererDialog = new QgsRendererV2PropertiesDialog( layer, QgsStyleV2::defaultStyle(), true );

// display the menu to choose the output format (fix #5136)
pbnSaveStyleAs->setText( tr( "Save Style" ) );
pbnSaveStyleAs->setMenu( mSaveAsMenu );
QObject::disconnect( pbnSaveStyleAs, SIGNAL( clicked() ), this, SLOT( on_pbnSaveStyleAs_clicked() ) );
}
else
{
tabWidget->setTabEnabled( 0, false ); // hide symbology item
}
// display the menu to choose the output format (fix #5136)
pbnSaveStyleAs->setText( tr( "Save Style" ) );
pbnSaveStyleAs->setMenu( mSaveAsMenu );
QObject::disconnect( pbnSaveStyleAs, SIGNAL( clicked() ), this, SLOT( on_pbnSaveStyleAs_clicked() ) );

if ( mRendererDialog )
{

0 comments on commit c2f00ca

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