Skip to content

Commit

Permalink
When using new symbology, embed renderer properties into vector layer…
Browse files Browse the repository at this point in the history
… properties, symbology tab.

git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11156 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jul 23, 2009
1 parent da2894a commit b075404
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 56 deletions.
3 changes: 3 additions & 0 deletions python/core/symbology-ng-core.sip
Expand Up @@ -573,6 +573,9 @@ public:
QgsStyleV2();
~QgsStyleV2();

//! return default application-wide style
static QgsStyleV2* defaultStyle();

//! remove all contents of the style
void clear();

Expand Down
2 changes: 1 addition & 1 deletion python/gui/symbology-ng-gui.sip
Expand Up @@ -34,7 +34,7 @@ class QgsRendererV2PropertiesDialog : QDialog //, private Ui::QgsRendererV2Props
%End

public:
QgsRendererV2PropertiesDialog(QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent = NULL);
QgsRendererV2PropertiesDialog(QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent = NULL, bool embedded = false);

public slots:
void changeSingleSymbol();
Expand Down
25 changes: 2 additions & 23 deletions src/app/qgisapp.cpp
Expand Up @@ -1038,24 +1038,7 @@ void QgisApp::createActions()
#include "qgsrendererv2propertiesdialog.h"
#include "qgsstylev2managerdialog.h"

static QgsStyleV2* gStyleV2 = NULL;

static void _initStyle()
{
if (gStyleV2 == NULL)
{
QString styleFilename = QgsApplication::userStyleV2Path();

// copy default style if user style doesn't exist
if ( !QFile::exists( styleFilename ) )
{
QFile::copy( QgsApplication::defaultStyleV2Path(), styleFilename );
}

gStyleV2 = new QgsStyleV2;
gStyleV2->load( styleFilename );
}
}

void QgisApp::toggleRendererV2()
{
Expand All @@ -1067,9 +1050,7 @@ void QgisApp::toggleRendererV2()
}
QgsVectorLayer* vlayer = static_cast<QgsVectorLayer*>(layer);

_initStyle();

QgsRendererV2PropertiesDialog dlg(vlayer, gStyleV2, this);
QgsRendererV2PropertiesDialog dlg(vlayer, QgsStyleV2::defaultStyle(), this);
if (!dlg.exec())
return;

Expand All @@ -1080,9 +1061,7 @@ void QgisApp::toggleRendererV2()

void QgisApp::showStyleManagerV2()
{
_initStyle();

QgsStyleV2ManagerDialog dlg(gStyleV2, QgsApplication::userStyleV2Path(), this);
QgsStyleV2ManagerDialog dlg(QgsStyleV2::defaultStyle(), QgsApplication::userStyleV2Path(), this);
dlg.exec();
}

Expand Down
83 changes: 56 additions & 27 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -56,6 +56,9 @@
#include <QComboBox>
#include <QCheckBox>

#include "qgsrendererv2propertiesdialog.h"
#include "qgsstylev2.h"

#if QT_VERSION < 0x040300
#define toPlainText() text()
#endif
Expand Down Expand Up @@ -439,10 +442,24 @@ void QgsVectorLayerProperties::reset( void )
legendtypecombobox->addItem( tr( "Unique Value" ) );
}
}

//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(), NULL, true);

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

QString rtype = layer->renderer()->name();
if ( rtype == "Single Symbol" )
{
Expand All @@ -465,16 +482,17 @@ void QgsVectorLayerProperties::reset( void )
legendtypecombobox->setCurrentIndex( 3 );
}

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

}

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


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

// reset fields in label dialog
layer->label()->setFields( layer->pendingFields() );

Expand Down Expand Up @@ -611,32 +629,43 @@ void QgsVectorLayerProperties::apply()
}
}

QgsSingleSymbolDialog *sdialog =
dynamic_cast < QgsSingleSymbolDialog * >( widgetStackRenderers->currentWidget() );
QgsGraduatedSymbolDialog *gdialog =
dynamic_cast < QgsGraduatedSymbolDialog * >( widgetStackRenderers->currentWidget() );
QgsContinuousColorDialog *cdialog =
dynamic_cast < QgsContinuousColorDialog * >( widgetStackRenderers->currentWidget() );
QgsUniqueValueDialog* udialog =
dynamic_cast< QgsUniqueValueDialog * >( widgetStackRenderers->currentWidget() );

if ( sdialog )
if (layer->isUsingRendererV2())
{
sdialog->apply();
QgsRendererV2PropertiesDialog* dlg =
static_cast<QgsRendererV2PropertiesDialog*>(widgetStackRenderers->currentWidget());
dlg->apply();
}
else if ( gdialog )
{
gdialog->apply();
}
else if ( cdialog )
{
cdialog->apply();
}
else if ( udialog )
else
{
udialog->apply();

QgsSingleSymbolDialog *sdialog =
dynamic_cast < QgsSingleSymbolDialog * >( widgetStackRenderers->currentWidget() );
QgsGraduatedSymbolDialog *gdialog =
dynamic_cast < QgsGraduatedSymbolDialog * >( widgetStackRenderers->currentWidget() );
QgsContinuousColorDialog *cdialog =
dynamic_cast < QgsContinuousColorDialog * >( widgetStackRenderers->currentWidget() );
QgsUniqueValueDialog* udialog =
dynamic_cast< QgsUniqueValueDialog * >( widgetStackRenderers->currentWidget() );

if ( sdialog )
{
sdialog->apply();
}
else if ( gdialog )
{
gdialog->apply();
}
else if ( cdialog )
{
cdialog->apply();
}
else if ( udialog )
{
udialog->apply();
}
layer->setTransparency( static_cast < unsigned int >( 255 - sliderTransparency->value() ) );

}
layer->setTransparency( static_cast < unsigned int >( 255 - sliderTransparency->value() ) );

//apply overlay dialogs
for ( QList<QgsApplyDialog*>::iterator it = mOverlayDialogs.begin(); it != mOverlayDialogs.end(); ++it )
Expand Down
22 changes: 22 additions & 0 deletions src/core/symbology-ng/qgsstylev2.cpp
Expand Up @@ -6,6 +6,7 @@

#include "qgssymbollayerv2registry.h"

#include "qgsapplication.h"
#include "qgslogger.h"

#include <QDomDocument>
Expand All @@ -15,6 +16,8 @@

#define STYLE_CURRENT_VERSION "0"

QgsStyleV2* QgsStyleV2::mDefaultStyle = NULL;


QgsStyleV2::QgsStyleV2()
{
Expand All @@ -25,6 +28,25 @@ QgsStyleV2::~QgsStyleV2()
clear();
}

QgsStyleV2* QgsStyleV2::defaultStyle() // static
{
if (mDefaultStyle == NULL)
{
QString styleFilename = QgsApplication::userStyleV2Path();

// copy default style if user style doesn't exist
if ( !QFile::exists( styleFilename ) )
{
QFile::copy( QgsApplication::defaultStyleV2Path(), styleFilename );
}

mDefaultStyle = new QgsStyleV2;
mDefaultStyle->load( styleFilename );
}
return mDefaultStyle;
}


void QgsStyleV2::clear()
{
for (QMap<QString, QgsSymbolV2*>::iterator its = mSymbols.begin(); its != mSymbols.end(); ++its)
Expand Down
5 changes: 5 additions & 0 deletions src/core/symbology-ng/qgsstylev2.h
Expand Up @@ -23,6 +23,9 @@ class QgsStyleV2

QgsStyleV2();
~QgsStyleV2();

//! return default application-wide style
static QgsStyleV2* defaultStyle();

//! remove all contents of the style
void clear();
Expand Down Expand Up @@ -90,6 +93,8 @@ class QgsStyleV2
QgsVectorColorRampV2Map mColorRamps;

QString mErrorString;

static QgsStyleV2* mDefaultStyle;
};


Expand Down
14 changes: 12 additions & 2 deletions src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp
Expand Up @@ -17,7 +17,7 @@
#include <QStandardItemModel>
#include <QStandardItem>

QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog(QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent)
QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog(QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent, bool embedded)
: QDialog(parent), mStyle(style)
{
mLayer = layer;
Expand All @@ -33,6 +33,12 @@ QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog(QgsVectorLayer* lay

setupUi(this);

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

connect(buttonBox, SIGNAL(accepted()), this, SLOT(onOK()));

connect(btnSymbolLevels, SIGNAL(clicked()), this, SLOT(symbolLevels()));
Expand Down Expand Up @@ -91,11 +97,15 @@ QgsRendererV2PropertiesDialog::~QgsRendererV2PropertiesDialog()
delete mRenderer;
}

void QgsRendererV2PropertiesDialog::onOK()
void QgsRendererV2PropertiesDialog::apply()
{
mLayer->setRendererV2(mRenderer);
mRenderer = NULL;
}

void QgsRendererV2PropertiesDialog::onOK()
{
apply();
accept();
}

Expand Down
3 changes: 2 additions & 1 deletion src/gui/symbology-ng/qgsrendererv2propertiesdialog.h
Expand Up @@ -18,7 +18,7 @@ class QgsRendererV2PropertiesDialog : public QDialog, private Ui::QgsRendererV2P
Q_OBJECT

public:
QgsRendererV2PropertiesDialog(QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent = NULL);
QgsRendererV2PropertiesDialog(QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent = NULL, bool embedded = false);
~QgsRendererV2PropertiesDialog();

public slots:
Expand All @@ -39,6 +39,7 @@ public slots:
void symbolLevels();

void onOK();
void apply();

protected:

Expand Down
4 changes: 2 additions & 2 deletions src/ui/qgsvectorlayerpropertiesbase.ui
Expand Up @@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>839</width>
<height>675</height>
<width>500</width>
<height>600</height>
</rect>
</property>
<property name="minimumSize" >
Expand Down

0 comments on commit b075404

Please sign in to comment.