Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged the symbol editing with the symbol selector dialog
- Loading branch information
Arunmozhi
committed
Jul 9, 2012
1 parent
82dfbac
commit 4c3afbb
Showing
10 changed files
with
366 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
/*************************************************************************** | ||
qgslayerpropertieswidget.cpp | ||
---------------------------- | ||
begin : June 2012 | ||
copyright : (C) 2012 by Arunmozhi | ||
email : aruntheguy at gmail.com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgslayerpropertieswidget.h" | ||
|
||
#include <QFile> | ||
#include <QStandardItem> | ||
#include <QKeyEvent> | ||
#include <QMessageBox> | ||
|
||
#include "qgssymbollayerv2.h" | ||
#include "qgssymbollayerv2registry.h" | ||
|
||
#include "qgsapplication.h" | ||
#include "qgslogger.h" | ||
|
||
#include "qgssymbollayerv2widget.h" | ||
#include "qgsellipsesymbollayerv2widget.h" | ||
#include "qgsvectorfieldsymbollayerwidget.h" | ||
#include "qgssymbolv2.h" //for the unit | ||
|
||
static bool _initWidgetFunction( QString name, QgsSymbolLayerV2WidgetFunc f ) | ||
{ | ||
QgsSymbolLayerV2Registry* reg = QgsSymbolLayerV2Registry::instance(); | ||
|
||
QgsSymbolLayerV2AbstractMetadata* abstractMetadata = reg->symbolLayerMetadata( name ); | ||
if ( abstractMetadata == NULL ) | ||
{ | ||
QgsDebugMsg( "Failed to find symbol layer's entry in registry: " + name ); | ||
return false; | ||
} | ||
QgsSymbolLayerV2Metadata* metadata = dynamic_cast<QgsSymbolLayerV2Metadata*>( abstractMetadata ); | ||
if ( metadata == NULL ) | ||
{ | ||
QgsDebugMsg( "Failed to cast symbol layer's metadata: " + name ); | ||
return false; | ||
} | ||
metadata->setWidgetFunction( f ); | ||
return true; | ||
} | ||
|
||
static void _initWidgetFunctions() | ||
{ | ||
static bool initialized = false; | ||
if ( initialized ) | ||
return; | ||
|
||
_initWidgetFunction( "SimpleLine", QgsSimpleLineSymbolLayerV2Widget::create ); | ||
_initWidgetFunction( "MarkerLine", QgsMarkerLineSymbolLayerV2Widget::create ); | ||
_initWidgetFunction( "LineDecoration", QgsLineDecorationSymbolLayerV2Widget::create ); | ||
|
||
_initWidgetFunction( "SimpleMarker", QgsSimpleMarkerSymbolLayerV2Widget::create ); | ||
_initWidgetFunction( "SvgMarker", QgsSvgMarkerSymbolLayerV2Widget::create ); | ||
_initWidgetFunction( "FontMarker", QgsFontMarkerSymbolLayerV2Widget::create ); | ||
_initWidgetFunction( "EllipseMarker", QgsEllipseSymbolLayerV2Widget::create ); | ||
_initWidgetFunction( "VectorField", QgsVectorFieldSymbolLayerWidget::create ); | ||
|
||
_initWidgetFunction( "SimpleFill", QgsSimpleFillSymbolLayerV2Widget::create ); | ||
_initWidgetFunction( "SVGFill", QgsSVGFillSymbolLayerWidget::create ); | ||
_initWidgetFunction( "CentroidFill", QgsCentroidFillSymbolLayerV2Widget::create ); | ||
_initWidgetFunction( "LinePatternFill", QgsLinePatternFillSymbolLayerWidget::create ); | ||
_initWidgetFunction( "PointPatternFill", QgsPointPatternFillSymbolLayerWidget::create ); | ||
|
||
initialized = true; | ||
} | ||
|
||
|
||
QgsLayerPropertiesWidget::QgsLayerPropertiesWidget( QgsSymbolLayerV2* layer, const QgsSymbolV2* symbol, const QgsVectorLayer* vl, QWidget* parent ) | ||
: QWidget( parent ) | ||
{ | ||
|
||
mLayer = layer; | ||
mSymbol = symbol; | ||
mVectorLayer = vl; | ||
|
||
setupUi( this ); | ||
// initalize the sub-widgets | ||
// XXX Should this thing be here this way? Initalize all th widgets just for the sake of one layer? | ||
// TODO Make this on demand creation | ||
_initWidgetFunctions(); | ||
|
||
// TODO Algorithm | ||
// | ||
// 3. populate the combo box with the supported layer type | ||
// 4. set the present layer type | ||
// 5. create the widget for the present layer type and set inn stacked widget | ||
// 6. connect comboBox type changed to two things | ||
// 1. emit signal that type has beed changed | ||
// 2. remove the widget and place the new widget corresponding to the changed layer type | ||
// | ||
populateLayerTypes(); | ||
// update layer type combo box | ||
int idx = cboLayerType->findData( mLayer->layerType() ); | ||
cboLayerType->setCurrentIndex( idx ); | ||
// set the corresponding widget | ||
updateSymbolLayerWidget( layer ); | ||
connect( cboLayerType, SIGNAL( currentIndexChanged( int ) ), this, SLOT( layerTypeChanged() ) ); | ||
} | ||
|
||
void QgsLayerPropertiesWidget::populateLayerTypes() | ||
{ | ||
QStringList types = QgsSymbolLayerV2Registry::instance()->symbolLayersForType( mSymbol->type() ); | ||
|
||
for ( int i = 0; i < types.count(); i++ ) | ||
cboLayerType->addItem( QgsSymbolLayerV2Registry::instance()->symbolLayerMetadata( types[i] )->visibleName(), types[i] ); | ||
|
||
if ( mSymbol->type() == QgsSymbolV2::Fill ) | ||
{ | ||
QStringList typesLine = QgsSymbolLayerV2Registry::instance()->symbolLayersForType( QgsSymbolV2::Line ); | ||
for ( int i = 0; i < typesLine.count(); i++ ) | ||
{ | ||
QString visibleName = QgsSymbolLayerV2Registry::instance()->symbolLayerMetadata( typesLine[i] )->visibleName(); | ||
QString name = QString( tr( "Outline: %1" ) ).arg( visibleName ); | ||
cboLayerType->addItem( name, typesLine[i] ); | ||
} | ||
} | ||
|
||
} | ||
|
||
void QgsLayerPropertiesWidget::updateSymbolLayerWidget( QgsSymbolLayerV2* layer ) | ||
{ | ||
if ( stackedWidget->currentWidget() != pageDummy ) | ||
{ | ||
// stop updating from the original widget | ||
disconnect( stackedWidget->currentWidget(), SIGNAL( changed() ), this, SLOT( emitSignalChanged() ) ); | ||
stackedWidget->removeWidget( stackedWidget->currentWidget() ); | ||
} | ||
|
||
QgsSymbolLayerV2Registry* pReg = QgsSymbolLayerV2Registry::instance(); | ||
|
||
QString layerType = layer->layerType(); | ||
QgsSymbolLayerV2AbstractMetadata* am = pReg->symbolLayerMetadata( layerType ); | ||
if ( am ) | ||
{ | ||
QgsSymbolLayerV2Widget* w = am->createSymbolLayerWidget( mVectorLayer ); | ||
if ( w ) | ||
{ | ||
w->setSymbolLayer( layer ); | ||
stackedWidget->addWidget( w ); | ||
stackedWidget->setCurrentWidget( w ); | ||
// start recieving updates from widget | ||
connect( w , SIGNAL( changed() ), this, SLOT( emitSignalChanged() ) ); | ||
return; | ||
} | ||
} | ||
// When anything is not right | ||
stackedWidget->setCurrentWidget( pageDummy ); | ||
} | ||
|
||
void QgsLayerPropertiesWidget::layerTypeChanged() | ||
{ | ||
QgsSymbolLayerV2* layer = mLayer; | ||
if ( !layer ) | ||
return; | ||
QString newLayerType = cboLayerType->itemData( cboLayerType->currentIndex() ).toString(); | ||
if ( layer->layerType() == newLayerType ) | ||
return; | ||
|
||
// get creation function for new layer from registry | ||
QgsSymbolLayerV2Registry* pReg = QgsSymbolLayerV2Registry::instance(); | ||
QgsSymbolLayerV2AbstractMetadata* am = pReg->symbolLayerMetadata( newLayerType ); | ||
if ( am == NULL ) // check whether the metadata is assigned | ||
return; | ||
|
||
// change layer to a new (with different type) | ||
QgsSymbolLayerV2* newLayer = am->createSymbolLayer( QgsStringMap() ); | ||
if ( newLayer == NULL ) | ||
return; | ||
|
||
updateSymbolLayerWidget( newLayer ); | ||
emit changeLayer( newLayer ); | ||
} | ||
|
||
void QgsLayerPropertiesWidget::emitSignalChanged() | ||
{ | ||
emit changed(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/*************************************************************************** | ||
qgslayerpropertieswidget.h | ||
--------------------- | ||
begin : June 2012 | ||
copyright : (C) 2012 by Martin Dobias | ||
email : aruntheguy at gmail.com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSLAYERPROPERTIESWIDGET_H | ||
#define QGSLAYERPROPERTIESWIDGET_H | ||
|
||
#include "ui_widget_layerproperties.h" | ||
|
||
class QgsSymbolV2; | ||
class QgsSymbolLayerV2; | ||
class QgsSymbolLayerV2Widget; | ||
class QgsVectorLayer; | ||
|
||
class SymbolLayerItem; | ||
|
||
#include <QMap> | ||
#include <QStandardItemModel> | ||
|
||
|
||
class GUI_EXPORT QgsLayerPropertiesWidget : public QWidget, private Ui::LayerPropertiesWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
QgsLayerPropertiesWidget( QgsSymbolLayerV2* layer, const QgsSymbolV2* symbol, const QgsVectorLayer* vl, QWidget* parent = NULL ); | ||
|
||
|
||
public slots: | ||
void layerTypeChanged(); | ||
void emitSignalChanged(); | ||
|
||
signals: | ||
void changed(); | ||
void changeLayer( QgsSymbolLayerV2* ); | ||
|
||
protected: | ||
void populateLayerTypes(); | ||
void updateSymbolLayerWidget( QgsSymbolLayerV2* layer ); | ||
|
||
protected: // data | ||
QgsSymbolLayerV2* mLayer; | ||
|
||
const QgsSymbolV2* mSymbol; | ||
const QgsVectorLayer* mVectorLayer; | ||
}; | ||
|
||
#endif //QGSLAYERPROPERTIESWIDGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.