Skip to content

Commit

Permalink
Add and wire in ellipse symbol layer widget
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jun 9, 2011
1 parent 3dc9659 commit 5a5f10c
Show file tree
Hide file tree
Showing 7 changed files with 475 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend

QString QgsEllipseSymbolLayerV2::layerType() const
{
return "Ellipse";
return "EllipseMarker";
}

void QgsEllipseSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
Expand Down
3 changes: 3 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2registry.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#include "qgssymbollayerv2registry.h"

#include "qgsellipsesymbollayerv2.h"
#include "qgsmarkersymbollayerv2.h"
#include "qgslinesymbollayerv2.h"
#include "qgsfillsymbollayerv2.h"
Expand All @@ -23,6 +24,8 @@ QgsSymbolLayerV2Registry::QgsSymbolLayerV2Registry()
QgsSvgMarkerSymbolLayerV2::create ) );
addSymbolLayerType( new QgsSymbolLayerV2Metadata( "FontMarker", QObject::tr( "Font marker" ), QgsSymbolV2::Marker,
QgsFontMarkerSymbolLayerV2::create ) );
addSymbolLayerType( new QgsSymbolLayerV2Metadata( "EllipseMarker", QObject::tr("Ellipse marker"), QgsSymbolV2::Marker,
QgsEllipseSymbolLayerV2::create ) );

addSymbolLayerType( new QgsSymbolLayerV2Metadata( "SimpleFill", QObject::tr( "Simple fill" ), QgsSymbolV2::Fill,
QgsSimpleFillSymbolLayerV2::create ) );
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ symbology-ng/qgsvectorrandomcolorrampv2dialog.cpp
symbology-ng/qgsvectorcolorbrewercolorrampv2dialog.cpp
symbology-ng/characterwidget.cpp
symbology-ng/qgsstylev2exportimportdialog.cpp
symbology-ng/qgsellipsesymbollayerv2widget.cpp

attributetable/qgsattributetablemodel.cpp
attributetable/qgsattributetablememorymodel.cpp
Expand Down Expand Up @@ -93,6 +94,7 @@ symbology-ng/characterwidget.h
symbology-ng/qgspenstylecombobox.h
symbology-ng/qgsbrushstylecombobox.h
symbology-ng/qgsstylev2exportimportdialog.h
symbology-ng/qgsellipsesymbollayerv2widget.h

attributetable/qgsattributetableview.h
attributetable/qgsattributetablemodel.h
Expand Down
211 changes: 211 additions & 0 deletions src/gui/symbology-ng/qgsellipsesymbollayerv2widget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
#include "qgsellipsesymbollayerv2widget.h"
#include "qgsellipsesymbollayerv2.h"
#include "qgsmaplayerregistry.h"
#include "qgsvectorlayer.h"
#include <QColorDialog>

QgsEllipseSymbolLayerV2Widget::QgsEllipseSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent ): QgsSymbolLayerV2Widget( parent, vl )
{
setupUi( this );
QStringList names;
names << "circle" << "rectangle" << "cross" << "triangle";
QSize iconSize = mShapeListWidget->iconSize();

QStringList::const_iterator nameIt = names.constBegin();
for(; nameIt != names.constEnd(); ++nameIt )
{
QgsEllipseSymbolLayerV2* lyr = new QgsEllipseSymbolLayerV2();
lyr->setSymbolName( *nameIt );
lyr->setOutlineColor( QColor( 0, 0, 0 ) );
lyr->setFillColor( QColor( 200, 200, 200 ) );
lyr->setSymbolWidth(4);
lyr->setSymbolHeight(2);
QIcon icon = QgsSymbolLayerV2Utils::symbolLayerPreviewIcon( lyr, QgsSymbolV2::MM, iconSize );
QListWidgetItem* item = new QListWidgetItem( icon, QString(), mShapeListWidget );
item->setData( Qt::UserRole, *nameIt );
delete lyr;
}

blockComboSignals( true );
fillDataDefinedComboBoxes();
blockComboSignals( false );
}

void QgsEllipseSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
{
if( layer->layerType() != "EllipseMarker" )
{
return;
}

mLayer = static_cast<QgsEllipseSymbolLayerV2*>( layer );
mWidthSpinBox->setValue( mLayer->symbolWidth() );
mHeightSpinBox->setValue( mLayer->symbolHeight() );
mOutlineWidthSpinBox->setValue( mLayer->outlineWidth() );

QList<QListWidgetItem *> symbolItemList = mShapeListWidget->findItems( mLayer->symbolName(), Qt::MatchExactly );
if( symbolItemList.size() > 0 )
{
mShapeListWidget->setCurrentItem( symbolItemList.at( 0 ) );
}
}

QgsSymbolLayerV2* QgsEllipseSymbolLayerV2Widget::symbolLayer()
{
return mLayer;
}

void QgsEllipseSymbolLayerV2Widget::on_mShapeListWidget_itemSelectionChanged()
{
if( mLayer )
{
QListWidgetItem* item = mShapeListWidget->currentItem();
if( item )
{
mLayer->setSymbolName( item->data( Qt::UserRole ).toString() );
emit changed();
}
}
}

void QgsEllipseSymbolLayerV2Widget::on_mWidthSpinBox_valueChanged( double d )
{
if( mLayer )
{
mLayer->setSymbolWidth( d );
emit changed();
}
}

void QgsEllipseSymbolLayerV2Widget::on_mHeightSpinBox_valueChanged( double d )
{
if( mLayer )
{
mLayer->setSymbolHeight( d );
emit changed();
}
}

void QgsEllipseSymbolLayerV2Widget::on_mOutlineWidthSpinBox_valueChanged( double d )
{
if( mLayer )
{
mLayer->setOutlineWidth( d );
emit changed();
}
}

void QgsEllipseSymbolLayerV2Widget::on_btnChangeColorBorder_clicked()
{
if( mLayer )
{
QColor newColor = QColorDialog::getColor( mLayer->outlineColor() );
if( newColor.isValid() )
{
mLayer->setOutlineColor( newColor );
emit changed();
}
}
}

void QgsEllipseSymbolLayerV2Widget::on_btnChangeColorFill_clicked()
{
if( mLayer )
{
QColor newColor = QColorDialog::getColor( mLayer->fillColor() );
if( newColor.isValid() )
{
mLayer->setFillColor( newColor );
emit changed();
}
}
}

void QgsEllipseSymbolLayerV2Widget::fillDataDefinedComboBoxes()
{
mDDSymbolWidthComboBox->clear();
mDDSymbolWidthComboBox->addItem( "", -1 );
mDDSymbolHeightComboBox->clear();
mDDSymbolHeightComboBox->addItem( "", -1 );
mDDOutlineWidthComboBox->clear();
mDDOutlineWidthComboBox->addItem( "", -1 );
mDDFillColorComboBox->clear();
mDDFillColorComboBox->addItem( "", -1 );
mDDOutlineColorComboBox->clear();
mDDOutlineColorComboBox->addItem( "", -1 );
mDDShapeComboBox->clear();
mDDShapeComboBox->addItem( "", -1 );

if( mVectorLayer )
{
const QgsFieldMap& fm =mVectorLayer->pendingFields();
QgsFieldMap::const_iterator fieldIt = fm.constBegin();
for(; fieldIt != fm.constEnd(); ++fieldIt )
{
QString fieldName = fieldIt.value().name();
int index = fieldIt.key();

mDDSymbolWidthComboBox->addItem( fieldName, index );
mDDSymbolHeightComboBox->addItem( fieldName, index );
mDDOutlineWidthComboBox->addItem( fieldName, index );
mDDFillColorComboBox->addItem( fieldName, index );
mDDOutlineColorComboBox->addItem( fieldName, index );
mDDShapeComboBox->addItem( fieldName, index );
}
}
}

void QgsEllipseSymbolLayerV2Widget::on_mDDSymbolWidthComboBox_currentIndexChanged( int idx )
{
if( mLayer )
{
mLayer->setDataDefinedWidth( mDDSymbolWidthComboBox->itemData( idx ).toInt() );
}
}

void QgsEllipseSymbolLayerV2Widget::on_mDDSymbolHeightComboBox_currentIndexChanged( int idx )
{
if( mLayer )
{
mLayer->setDataDefinedHeight( mDDSymbolHeightComboBox->itemData( idx ).toInt() );
}
}

void QgsEllipseSymbolLayerV2Widget::on_mDDOutlineWidthComboBox_currentIndexChanged( int idx )
{
if( mLayer )
{
mLayer->setDataDefinedOutlineWidth( mDDOutlineWidthComboBox->itemData( idx ).toInt() );
}
}

void QgsEllipseSymbolLayerV2Widget::on_mDDFillColorComboBox_currentIndexChanged( int idx )
{
if( mLayer )
{
mLayer->setDataDefinedFillColor( mDDFillColorComboBox->itemData( idx ).toInt() );
}
}

void QgsEllipseSymbolLayerV2Widget::on_mDDOutlineColorComboBox_currentIndexChanged( int idx )
{
if( mLayer )
{
mLayer->setDataDefinedOutlineColor( mDDOutlineColorComboBox->itemData( idx ).toInt() );
}
}

void QgsEllipseSymbolLayerV2Widget::on_mDDShapeComboBox_currentIndexChanged( int idx )
{
//todo...
}

void QgsEllipseSymbolLayerV2Widget::blockComboSignals( bool block )
{
mDDSymbolWidthComboBox->blockSignals( block );
mDDSymbolHeightComboBox->blockSignals( block );
mDDOutlineWidthComboBox->blockSignals( block );
mDDFillColorComboBox->blockSignals( block );
mDDOutlineColorComboBox->blockSignals( block);
mDDShapeComboBox->blockSignals( block );
}
46 changes: 46 additions & 0 deletions src/gui/symbology-ng/qgsellipsesymbollayerv2widget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#ifndef QGSELLIPSESYMBOLLAYERV2WIDGET_H
#define QGSELLIPSESYMBOLLAYERV2WIDGET_H

#include "ui_widget_ellipse.h"
#include "qgssymbollayerv2widget.h"

class QgsEllipseSymbolLayerV2;

class GUI_EXPORT QgsEllipseSymbolLayerV2Widget: public QgsSymbolLayerV2Widget, private Ui::WidgetEllipseBase
{
Q_OBJECT

public:
QgsEllipseSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent = 0 );

static QgsSymbolLayerV2Widget* create( const QgsVectorLayer* vl ) { return new QgsEllipseSymbolLayerV2Widget( vl ); }

// from base class
virtual void setSymbolLayer( QgsSymbolLayerV2* layer );
virtual QgsSymbolLayerV2* symbolLayer();

protected:
QgsEllipseSymbolLayerV2* mLayer;

private:
void blockComboSignals( bool block );
//insert available attributes for data defined symbolisation
void fillDataDefinedComboBoxes();

private slots:
void on_mShapeListWidget_itemSelectionChanged();
void on_mWidthSpinBox_valueChanged( double d );
void on_mHeightSpinBox_valueChanged( double d );
void on_mOutlineWidthSpinBox_valueChanged( double d );
void on_btnChangeColorBorder_clicked();
void on_btnChangeColorFill_clicked();

void on_mDDSymbolWidthComboBox_currentIndexChanged( int idx );
void on_mDDSymbolHeightComboBox_currentIndexChanged( int idx );
void on_mDDOutlineWidthComboBox_currentIndexChanged( int idx );
void on_mDDFillColorComboBox_currentIndexChanged( int idx );
void on_mDDOutlineColorComboBox_currentIndexChanged( int idx );
void on_mDDShapeComboBox_currentIndexChanged( int idx );
};

#endif // QGSELLIPSESYMBOLLAYERV2WIDGET_H
2 changes: 2 additions & 0 deletions src/gui/symbology-ng/qgssymbolv2propertiesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "qgslogger.h"

#include "qgssymbollayerv2widget.h"
#include "qgsellipsesymbollayerv2widget.h"
#include "qgssymbolv2.h" //for the unit


Expand Down Expand Up @@ -90,6 +91,7 @@ static void _initWidgetFunctions()
_initWidgetFunction( "SimpleMarker", QgsSimpleMarkerSymbolLayerV2Widget::create );
_initWidgetFunction( "SvgMarker", QgsSvgMarkerSymbolLayerV2Widget::create );
_initWidgetFunction( "FontMarker", QgsFontMarkerSymbolLayerV2Widget::create );
_initWidgetFunction( "EllipseMarker", QgsEllipseSymbolLayerV2Widget::create );

_initWidgetFunction( "SimpleFill", QgsSimpleFillSymbolLayerV2Widget::create );
_initWidgetFunction( "SVGFill", QgsSVGFillSymbolLayerWidget::create );
Expand Down
Loading

0 comments on commit 5a5f10c

Please sign in to comment.