Skip to content
Permalink
Browse files

Add and wire in ellipse symbol layer widget

  • Loading branch information
mhugent committed Jun 9, 2011
1 parent 3dc9659 commit 5a5f10c0c03f3d483e88403e17ee381bb67138fe
@@ -112,7 +112,7 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend

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

void QgsEllipseSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
@@ -1,6 +1,7 @@

#include "qgssymbollayerv2registry.h"

#include "qgsellipsesymbollayerv2.h"
#include "qgsmarkersymbollayerv2.h"
#include "qgslinesymbollayerv2.h"
#include "qgsfillsymbollayerv2.h"
@@ -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 ) );
@@ -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
@@ -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
@@ -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 );
}
@@ -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
@@ -12,6 +12,7 @@
#include "qgslogger.h"

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


@@ -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 );

0 comments on commit 5a5f10c

Please sign in to comment.
You can’t perform that action at this time.