Skip to content

Commit

Permalink
Added a checkbox to options dialog to enable/disable symbology-ng
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11157 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jul 23, 2009
1 parent b075404 commit f808b53
Show file tree
Hide file tree
Showing 10 changed files with 482 additions and 434 deletions.
6 changes: 6 additions & 0 deletions python/core/symbology-ng-core.sip
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public:
// TODO: user type?
};

//! return a new renderer - used by default in vector layers
static QgsFeatureRendererV2* defaultRenderer(QGis::GeometryType geomType) /Factory/;

RendererType type() const;

virtual QgsSymbolV2* symbolForFeature(QgsFeature& feature)=0;
Expand Down Expand Up @@ -397,6 +400,9 @@ public:

virtual ~QgsSymbolV2();

//! return new default symbol for specified geometry type
static QgsSymbolV2* defaultSymbol(QGis::GeometryType geomType) /Factory/;

SymbolType type() const;

// symbol layers handling
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
//set the state of the checkboxes
chkAntiAliasing->setChecked( settings.value( "/qgis/enable_anti_aliasing", false ).toBool() );

chkUseSymbologyNG->setChecked( settings.value( "/qgis/use_symbology_ng", false ).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() ) );
Expand Down Expand Up @@ -342,6 +344,7 @@ void QgsOptions::saveOptions()
settings.setValue( "/qgis/new_layers_visible", chkAddedVisibility->isChecked() );
settings.setValue( "/qgis/enable_anti_aliasing", chkAntiAliasing->isChecked() );
settings.setValue( "/qgis/use_qimage_to_render", !( chkUseQPixmap->isChecked() ) );
settings.setValue( "/qgis/use_symbology_ng", chkUseSymbologyNG->isChecked() );
settings.setValue( "qgis/capitaliseLayerName", capitaliseCheckBox->isChecked() );
settings.setValue( "qgis/askToSaveProjectChanges", chbAskToSaveProjectChanges->isChecked() );
settings.setValue( "qgis/warnOldProjectVersion", chbWarnOldProjectVersion->isChecked() );
Expand Down
16 changes: 13 additions & 3 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,31 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
}
if ( mValid )
{
setCoordinateSystem();

// check if there is a default style / propertysheet defined
// for this layer and if so apply it
//
if ( loadDefaultStyleFlag )
QSettings settings;
if ( settings.value( "/qgis/use_symbology_ng", false ).toBool() )
{
// using symbology-ng!
setUsingRendererV2(true);
setRendererV2( QgsFeatureRendererV2::defaultRenderer( geometryType() ) );
}
else if ( loadDefaultStyleFlag )
{
bool defaultLoadedFlag = false;
loadDefaultStyle( defaultLoadedFlag );
if ( !defaultLoadedFlag )
{
setCoordinateSystem();
// add single symbol renderer as default
QgsSingleSymbolRenderer *renderer = new QgsSingleSymbolRenderer( geometryType() );
setRenderer( renderer );
}
}
else // Otherwise use some very basic defaults
{
setCoordinateSystem();
// add single symbol renderer as default
QgsSingleSymbolRenderer *renderer = new QgsSingleSymbolRenderer( geometryType() );
setRenderer( renderer );
Expand Down Expand Up @@ -2468,6 +2475,9 @@ bool QgsVectorLayer::writeXml( QDomNode & layer_node,

bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage )
{
// TODO: load symbology-ng renderers
setUsingRendererV2(false);

// process the attribute actions
mActions->readXML( node );

Expand Down
5 changes: 5 additions & 0 deletions src/core/symbology-ng/qgsrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ QgsFeatureRendererV2::QgsFeatureRendererV2(RendererType type)
{
}

QgsFeatureRendererV2* QgsFeatureRendererV2::defaultRenderer(QGis::GeometryType geomType)
{
return new QgsSingleSymbolRendererV2( QgsSymbolV2::defaultSymbol(geomType) );
}


void QgsFeatureRendererV2::renderFeature(QgsFeature& feature, QgsRenderContext& context, int layer)
{
Expand Down
5 changes: 5 additions & 0 deletions src/core/symbology-ng/qgsrendererv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#ifndef QGSRENDERERV2_H
#define QGSRENDERERV2_H

#include "qgis.h"

#include <QList>
#include <QHash>
#include <QString>
Expand Down Expand Up @@ -49,6 +51,9 @@ class QgsFeatureRendererV2
RendererGraduatedSymbol
// TODO: user type?
};

//! return a new renderer - used by default in vector layers
static QgsFeatureRendererV2* defaultRenderer(QGis::GeometryType geomType);

RendererType type() const { return mType; }

Expand Down
12 changes: 12 additions & 0 deletions src/core/symbology-ng/qgssymbolv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "qgsmarkersymbollayerv2.h"
#include "qgsfillsymbollayerv2.h"

#include "qgslogger.h"
#include "qgsrendercontext.h" // for bigSymbolPreview

#include <QColor>
Expand Down Expand Up @@ -40,6 +41,17 @@ QgsSymbolV2::~QgsSymbolV2()
delete *it;
}

QgsSymbolV2* QgsSymbolV2::defaultSymbol(QGis::GeometryType geomType)
{
switch (geomType)
{
case QGis::Point: return new QgsMarkerSymbolV2();
case QGis::Line: return new QgsLineSymbolV2();
case QGis::Polygon: return new QgsFillSymbolV2();
default: QgsDebugMsg("unknown layer's geometry type"); return NULL;
}
}


QgsSymbolLayerV2* QgsSymbolV2::symbolLayer(int layer)
{
Expand Down
4 changes: 4 additions & 0 deletions src/core/symbology-ng/qgssymbolv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#ifndef QGSSYMBOLV2_H
#define QGSSYMBOLV2_H

#include "qgis.h"
#include <QList>

class QColor;
Expand Down Expand Up @@ -30,6 +31,9 @@ class QgsSymbolV2

virtual ~QgsSymbolV2();

//! return new default symbol for specified geometry type
static QgsSymbolV2* defaultSymbol(QGis::GeometryType geomType);

SymbolType type() const { return mType; }

// symbol layers handling
Expand Down
19 changes: 4 additions & 15 deletions src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog(QgsVectorLayer* lay
// if the layer doesn't use renderer V2, let's start using it!
if (!mLayer->isUsingRendererV2())
{
mLayer->setRendererV2(new QgsSingleSymbolRendererV2( createDefaultSymbol() ));
mLayer->setRendererV2( QgsFeatureRendererV2::defaultRenderer(mLayer->geometryType()) );
mLayer->setUsingRendererV2(true);
}

Expand Down Expand Up @@ -61,7 +61,7 @@ QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog(QgsVectorLayer* lay
m->setHorizontalHeaderLabels(labels);
viewCategories->setModel(m);

mCategorizedSymbol = createDefaultSymbol();
mCategorizedSymbol = QgsSymbolV2::defaultSymbol(mLayer->geometryType());

connect(cboCategorizedColumn, SIGNAL(currentIndexChanged(int)), this, SLOT(categoryColumnChanged()));

Expand All @@ -80,7 +80,7 @@ QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog(QgsVectorLayer* lay
mg->setHorizontalHeaderLabels(labels);
viewGraduated->setModel(mg);

mGraduatedSymbol = createDefaultSymbol();
mGraduatedSymbol = QgsSymbolV2::defaultSymbol(mLayer->geometryType());

connect(viewGraduated, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(rangesDoubleClicked(const QModelIndex &)));

Expand Down Expand Up @@ -148,7 +148,7 @@ void QgsRendererV2PropertiesDialog::updateRenderer()
delete mRenderer;

if (radSingleSymbol->isChecked())
mRenderer = new QgsSingleSymbolRendererV2( createDefaultSymbol() );
mRenderer = new QgsSingleSymbolRendererV2( QgsSymbolV2::defaultSymbol(mLayer->geometryType()) );
else if (radCategorized->isChecked())
mRenderer = new QgsCategorizedSymbolRendererV2(-1, QgsCategoryList());
else if (radGraduated->isChecked())
Expand Down Expand Up @@ -221,17 +221,6 @@ void QgsRendererV2PropertiesDialog::updateUiFromRenderer()
}


QgsSymbolV2* QgsRendererV2PropertiesDialog::createDefaultSymbol()
{
switch (mLayer->geometryType())
{
case QGis::Point: return new QgsMarkerSymbolV2();
case QGis::Line: return new QgsLineSymbolV2();
case QGis::Polygon: return new QgsFillSymbolV2();
default: QgsDebugMsg("unknown layer's geometry type"); return NULL;
}
}

void QgsRendererV2PropertiesDialog::changeCategorizedSymbol()
{
QgsSymbolV2SelectorDialog dlg(mCategorizedSymbol, mStyle, this);
Expand Down
3 changes: 0 additions & 3 deletions src/gui/symbology-ng/qgsrendererv2propertiesdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ public slots:
void updateCategorizedSymbolIcon();
void updateGraduatedSymbolIcon();

//! create default symbol for the layer's geometry type (point/line/polygon)
QgsSymbolV2* createDefaultSymbol();

//! populate categories view
void populateCategories();

Expand Down
Loading

0 comments on commit f808b53

Please sign in to comment.