Skip to content
Permalink
Browse files

Vector layer properties dialog can convert layer to new/old symbology.

(there's no transfer of settings between old/new symbology)


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12191 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Nov 19, 2009
1 parent 412fa54 commit eb949f9a3ffaee1224afbc0b5bf6c50eee5ded06
@@ -56,6 +56,8 @@

#include "qgsrendererv2propertiesdialog.h"
#include "qgsstylev2.h"
#include "qgssinglesymbolrenderer.h"
#include "qgssinglesymbolrendererv2.h"

#if QT_VERSION < 0x040300
#define toPlainText() text()
@@ -95,6 +97,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
mToggleEditingButton->setIcon( QgisApp::getThemeIcon( "/mActionToggleEditing.png" ) );
mCalculateFieldButton->setIcon( QgisApp::getThemeIcon( "/mActionCalculateField.png" ) );

connect( btnUseNewSymbology, SIGNAL( clicked() ), this, SLOT( useNewSymbology() ) );

// Create the Label dialog tab
QVBoxLayout *layout = new QVBoxLayout( labelOptionsFrame );
@@ -479,55 +482,8 @@ void QgsVectorLayerProperties::reset( void )
}
}

//find out the type of renderer in the vectorlayer, create a dialog with these settings and add it to the form
delete mRendererDialog;
mRendererDialog = 0;

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

// hide unused widgets
legendtypecombobox->hide();
legendtypelabel->hide();
lblTransparencyPercent->hide();
sliderTransparency->hide();
}
else
{

QString rtype = layer->renderer()->name();
if ( rtype == "Single Symbol" )
{
mRendererDialog = new QgsSingleSymbolDialog( layer );
legendtypecombobox->setCurrentIndex( 0 );
}
else if ( rtype == "Graduated Symbol" )
{
mRendererDialog = new QgsGraduatedSymbolDialog( layer );
legendtypecombobox->setCurrentIndex( 1 );
}
else if ( rtype == "Continuous Color" )
{
mRendererDialog = new QgsContinuousColorDialog( layer );
legendtypecombobox->setCurrentIndex( 2 );
}
else if ( rtype == "Unique Value" )
{
mRendererDialog = new QgsUniqueValueDialog( layer );
legendtypecombobox->setCurrentIndex( 3 );
}

QObject::connect( legendtypecombobox, SIGNAL( activated( const QString & ) ), this,
SLOT( alterLayerDialog( const QString & ) ) );

}

if ( mRendererDialog )
{
widgetStackRenderers->addWidget( mRendererDialog );
widgetStackRenderers->setCurrentWidget( mRendererDialog );
}
// load appropriate symbology page (V1 or V2)
updateSymbologyPage();

// reset fields in label dialog
layer->label()->setFields( layer->pendingFields() );
@@ -1136,3 +1092,96 @@ QList<QgsVectorOverlayPlugin*> QgsVectorLayerProperties::overlayPlugins() const

return pluginList;
}

void QgsVectorLayerProperties::setUsingNewSymbology( bool useNewSymbology )
{
if ( useNewSymbology )
{
layer->setUsingRendererV2( true );
layer->setRendererV2( QgsFeatureRendererV2::defaultRenderer( layer->geometryType() ) );
layer->setRenderer( NULL );
}
else
{
layer->setUsingRendererV2( false );
layer->setRendererV2( NULL );
layer->setRenderer( new QgsSingleSymbolRenderer( layer->geometryType() ) );
}

// update GUI!
updateSymbologyPage();
}

void QgsVectorLayerProperties::useNewSymbology()
{
int res = QMessageBox::question( this, tr( "Symbology" ),
tr( "Do you wish to use original symbology implementation for this layer?" ),
QMessageBox::Yes | QMessageBox::No );

if ( res != QMessageBox::Yes )
return;

setUsingNewSymbology( true );
}

void QgsVectorLayerProperties::updateSymbologyPage()
{

//find out the type of renderer in the vectorlayer, create a dialog with these settings and add it to the form
delete mRendererDialog;
mRendererDialog = 0;

bool v2 = layer->isUsingRendererV2();

// hide unused widgets
legendtypecombobox->setVisible( !v2 );
legendtypelabel->setVisible( !v2 );
lblTransparencyPercent->setVisible( !v2 );
sliderTransparency->setVisible( !v2 );
btnUseNewSymbology->setVisible( !v2 );

if ( v2 )
{
mRendererDialog = new QgsRendererV2PropertiesDialog( layer, QgsStyleV2::defaultStyle(), true );

connect( mRendererDialog, SIGNAL( useNewSymbology( bool ) ), this, SLOT( setUsingNewSymbology( bool ) ) );

}
else
{

QString rtype = layer->renderer()->name();
if ( rtype == "Single Symbol" )
{
mRendererDialog = new QgsSingleSymbolDialog( layer );
legendtypecombobox->setCurrentIndex( 0 );
}
else if ( rtype == "Graduated Symbol" )
{
mRendererDialog = new QgsGraduatedSymbolDialog( layer );
legendtypecombobox->setCurrentIndex( 1 );
}
else if ( rtype == "Continuous Color" )
{
mRendererDialog = new QgsContinuousColorDialog( layer );
legendtypecombobox->setCurrentIndex( 2 );
}
else if ( rtype == "Unique Value" )
{
mRendererDialog = new QgsUniqueValueDialog( layer );
legendtypecombobox->setCurrentIndex( 3 );
}

QObject::connect( legendtypecombobox, SIGNAL( activated( const QString & ) ), this,
SLOT( alterLayerDialog( const QString & ) ) );

}

if ( mRendererDialog )
{
widgetStackRenderers->addWidget( mRendererDialog );
widgetStackRenderers->setCurrentWidget( mRendererDialog );
}


}
@@ -112,6 +112,9 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope
void attributeAdded( int idx );
void attributeDeleted( int idx );

void useNewSymbology();
void setUsingNewSymbology( bool useNewSymbology );

signals:

/** emitted when changes to layer were saved to update legend */
@@ -120,6 +123,9 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope
void toggleEditing( QgsMapLayer * );

protected:

void updateSymbologyPage();

enum attrColumns
{
attrIdCol = 0,
@@ -16,64 +16,65 @@
#include "qgsvectorlayer.h"

#include <QKeyEvent>
#include <QMessageBox>


QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog(QgsVectorLayer* layer, QgsStyleV2* style, bool embedded)
: mLayer(layer), mStyle(style), mActiveWidget(NULL)
QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog( QgsVectorLayer* layer, QgsStyleV2* style, bool embedded )
: mLayer( layer ), mStyle( style ), mActiveWidget( NULL )
{
setupUi(this);
setupUi( this );

// can be embedded in vector layer properties
if (embedded)
if ( embedded )
{
buttonBox->hide();
layout()->setContentsMargins(0,0,0,0);
layout()->setContentsMargins( 0, 0, 0, 0 );
}

connect(buttonBox, SIGNAL(accepted()), this, SLOT(onOK()));
connect(btnSymbolLevels, SIGNAL(clicked()), this, SLOT(showSymbolLevels()));
connect( buttonBox, SIGNAL( accepted() ), this, SLOT( onOK() ) );
connect( btnSymbolLevels, SIGNAL( clicked() ), this, SLOT( showSymbolLevels() ) );
connect( btnOldSymbology, SIGNAL( clicked() ), this, SLOT( useOldSymbology() ) );

// initialize registry's widget functions
QgsRendererV2Registry* reg = QgsRendererV2Registry::instance();
if (reg->rendererMetadata("singleSymbol").widgetFunction() == NULL)
if ( reg->rendererMetadata( "singleSymbol" ).widgetFunction() == NULL )
{
reg->setRendererWidgetFunction("singleSymbol", QgsSingleSymbolRendererV2Widget::create);
reg->setRendererWidgetFunction("categorizedSymbol", QgsCategorizedSymbolRendererV2Widget::create);
reg->setRendererWidgetFunction("graduatedSymbol", QgsGraduatedSymbolRendererV2Widget::create);
reg->setRendererWidgetFunction( "singleSymbol", QgsSingleSymbolRendererV2Widget::create );
reg->setRendererWidgetFunction( "categorizedSymbol", QgsCategorizedSymbolRendererV2Widget::create );
reg->setRendererWidgetFunction( "graduatedSymbol", QgsGraduatedSymbolRendererV2Widget::create );
}

QPixmap pix;
QStringList renderers = reg->renderersList();
foreach (QString name, renderers)
foreach( QString name, renderers )
{
QgsRendererV2Metadata m = reg->rendererMetadata(name);
QgsRendererV2Metadata m = reg->rendererMetadata( name );

QString iconPath = QgsApplication::defaultThemePath() + m.iconName();
if (!pix.load(iconPath, "png"))
if ( !pix.load( iconPath, "png" ) )
pix = QPixmap();

cboRenderers->addItem(QIcon(pix), m.visibleName(), name);
cboRenderers->addItem( QIcon( pix ), m.visibleName(), name );
}

cboRenderers->setCurrentIndex(-1); // set no current renderer
cboRenderers->setCurrentIndex( -1 ); // set no current renderer

// if the layer doesn't use renderer V2, let's start using it!
if (!mLayer->isUsingRendererV2())
if ( !mLayer->isUsingRendererV2() )
{
mLayer->setRendererV2( QgsFeatureRendererV2::defaultRenderer(mLayer->geometryType()) );
mLayer->setUsingRendererV2(true);
mLayer->setRendererV2( QgsFeatureRendererV2::defaultRenderer( mLayer->geometryType() ) );
mLayer->setUsingRendererV2( true );
}

// setup slot rendererChanged()
connect(cboRenderers, SIGNAL(currentIndexChanged(int)), this, SLOT(rendererChanged()));
connect( cboRenderers, SIGNAL( currentIndexChanged( int ) ), this, SLOT( rendererChanged() ) );

// set current renderer from layer
QString rendererName = mLayer->rendererV2()->type();
for (int i = 0; i < cboRenderers->count(); i++)
for ( int i = 0; i < cboRenderers->count(); i++ )
{
if (cboRenderers->itemData(i).toString() == rendererName)
if ( cboRenderers->itemData( i ).toString() == rendererName )
{
cboRenderers->setCurrentIndex(i);
cboRenderers->setCurrentIndex( i );
return;
}
}
@@ -87,47 +88,47 @@ QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog(QgsVectorLayer* lay
void QgsRendererV2PropertiesDialog::rendererChanged()
{

if (cboRenderers->currentIndex() == -1)
if ( cboRenderers->currentIndex() == -1 )
{
QgsDebugMsg("No current item -- this should never happen!");
QgsDebugMsg( "No current item -- this should never happen!" );
return;
}

QString rendererName = cboRenderers->itemData( cboRenderers->currentIndex() ).toString();

// get rid of old active widget (if any)
if (mActiveWidget)
if ( mActiveWidget )
{
stackedWidget->removeWidget( mActiveWidget );

delete mActiveWidget;
mActiveWidget = NULL;
}

QgsRendererV2Metadata m = QgsRendererV2Registry::instance()->rendererMetadata(rendererName);
QgsRendererV2Metadata m = QgsRendererV2Registry::instance()->rendererMetadata( rendererName );
QgsRendererV2WidgetFunc fWidget = m.widgetFunction();
if (fWidget != NULL)
if ( fWidget != NULL )
{
// instantiate the widget and set as active
mActiveWidget = fWidget(mLayer, mStyle, mLayer->rendererV2()->clone());
stackedWidget->addWidget(mActiveWidget);
stackedWidget->setCurrentWidget(mActiveWidget);
mActiveWidget = fWidget( mLayer, mStyle, mLayer->rendererV2()->clone() );
stackedWidget->addWidget( mActiveWidget );
stackedWidget->setCurrentWidget( mActiveWidget );

btnSymbolLevels->setEnabled(true);
btnSymbolLevels->setEnabled( true );
}
else
{
// set default "no edit widget available" page
stackedWidget->setCurrentWidget(pageNoWidget);
stackedWidget->setCurrentWidget( pageNoWidget );

btnSymbolLevels->setEnabled(false);
btnSymbolLevels->setEnabled( false );
}

}

void QgsRendererV2PropertiesDialog::apply()
{
if (mActiveWidget != NULL)
if ( mActiveWidget != NULL )
{
mLayer->setRendererV2( mActiveWidget->renderer()->clone() );
}
@@ -149,22 +150,34 @@ void QgsRendererV2PropertiesDialog::keyPressEvent( QKeyEvent * e )
}
else
{
QDialog::keyPressEvent(e);
QDialog::keyPressEvent( e );
}
}


void QgsRendererV2PropertiesDialog::showSymbolLevels()
{
if (!mActiveWidget)
if ( !mActiveWidget )
return;

QgsFeatureRendererV2* r = mActiveWidget->renderer();
QgsSymbolV2List symbols = r->symbols();

QgsSymbolLevelsV2Dialog dlg(symbols, r->usingSymbolLevels(), this);
if (dlg.exec())
QgsSymbolLevelsV2Dialog dlg( symbols, r->usingSymbolLevels(), this );
if ( dlg.exec() )
{
r->setUsingSymbolLevels( dlg.usingLevels() );
}
}

void QgsRendererV2PropertiesDialog::useOldSymbology()
{
int res = QMessageBox::question( this, tr( "Symbology" ),
tr( "Do you wish to use original symbology implementation for this layer?" ),
QMessageBox::Yes | QMessageBox::No );

if ( res != QMessageBox::Yes )
return;

emit useNewSymbology( false );
}
@@ -30,6 +30,11 @@ class GUI_EXPORT QgsRendererV2PropertiesDialog : public QDialog, private Ui::Qgs

void showSymbolLevels();

void useOldSymbology();

signals:
void useNewSymbology( bool );

protected:

//! Reimplements dialog keyPress event so we can ignore it

0 comments on commit eb949f9

Please sign in to comment.