Skip to content
Permalink
Browse files

Move symbol change slots to render widget parent class

  • Loading branch information
mhugent committed Sep 5, 2011
1 parent 1490f58 commit ca6a225100357d546f801d55c4be2a5c173fa1b8
@@ -10,8 +10,6 @@
#include "qgssymbolv2selectordialog.h"

#include "qgsvectorlayer.h"
#include <QColorDialog>
#include <QInputDialog>
#include <QMenu>
#include <QMessageBox>
#include <QStandardItemModel>
@@ -406,131 +404,6 @@ void QgsCategorizedSymbolRendererV2Widget::sizeScaleFieldChanged( QString fldNam
mRenderer->setSizeScaleField( fldName );
}

void QgsCategorizedSymbolRendererV2Widget::contextMenuViewCategories( const QPoint& p )
{
QMenu contextMenu;
contextMenu.addAction( tr( "Change color" ), this, SLOT( changeSymbolColor( ) ) );
contextMenu.addAction( tr( "Change transparency" ), this, SLOT( changeSymbolTransparency() ) );
contextMenu.addAction( tr( "Change output unit" ), this, SLOT( changeSymbolUnit() ) );

if ( mLayer && mLayer->geometryType() == QGis::Line )
{
contextMenu.addAction( tr( "Change width" ), this, SLOT( changeSymbolWidth() ) );
}
else if ( mLayer && mLayer->geometryType() == QGis::Point )
{
contextMenu.addAction( tr( "Change size" ), this, SLOT( changeSymbolSize() ) );
}
contextMenu.exec( viewCategories->mapToGlobal( p ) );
}

void QgsCategorizedSymbolRendererV2Widget::changeSymbolColor()
{
QList<QgsSymbolV2*> symbolList = selectedSymbols();
if ( symbolList.size() < 1 )
{
return;
}

QColor color = QColorDialog::getColor( symbolList.at( 0 )->color(), this );
if ( color.isValid() )
{
QList<QgsSymbolV2*>::iterator symbolIt = symbolList.begin();
for ( ; symbolIt != symbolList.end(); ++symbolIt )
{
( *symbolIt )->setColor( color );
}
populateCategories();
}
}

void QgsCategorizedSymbolRendererV2Widget::changeSymbolTransparency()
{
QList<QgsSymbolV2*> symbolList = selectedSymbols();
if ( symbolList.size() < 1 )
{
return;
}

bool ok;
double transparency = QInputDialog::getDouble( this, tr( "Transparency" ), tr( "Change symbol transparency" ), 1 - symbolList.at( 0 )->alpha(), 0.0, 1.0, 1, &ok );
if ( ok )
{
QList<QgsSymbolV2*>::iterator symbolIt = symbolList.begin();
for ( ; symbolIt != symbolList.end(); ++symbolIt )
{
( *symbolIt )->setAlpha( 1 - transparency );
}
populateCategories();
}
}

void QgsCategorizedSymbolRendererV2Widget::changeSymbolUnit()
{
QList<QgsSymbolV2*> symbolList = selectedSymbols();
if ( symbolList.size() < 1 )
{
return;
}

bool ok;
int currentUnit = ( symbolList.at( 0 )->outputUnit() == QgsSymbolV2::MM ) ? 0 : 1;
QString item = QInputDialog::getItem( this, tr( "Symbol unit" ), tr( "Select symbol unit" ), QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), currentUnit, false, &ok );
if ( ok )
{
QgsSymbolV2::OutputUnit unit = ( item.compare( tr( "Millimeter" ) ) == 0 ) ? QgsSymbolV2::MM : QgsSymbolV2::MapUnit;

QList<QgsSymbolV2*>::iterator symbolIt = symbolList.begin();
for ( ; symbolIt != symbolList.end(); ++symbolIt )
{
( *symbolIt )->setOutputUnit( unit );
}
populateCategories();
}
}

void QgsCategorizedSymbolRendererV2Widget::changeSymbolWidth()
{
QList<QgsSymbolV2*> symbolList = selectedSymbols();
if ( symbolList.size() < 1 )
{
return;
}

bool ok;
double width = QInputDialog::getDouble( this, tr( "Width" ), tr( "Change symbol width" ), dynamic_cast<QgsLineSymbolV2*>( symbolList.at( 0 ) )->width(), 0.0, 999999, 1, &ok );
if ( ok )
{
QList<QgsSymbolV2*>::iterator symbolIt = symbolList.begin();
for ( ; symbolIt != symbolList.end(); ++symbolIt )
{
dynamic_cast<QgsLineSymbolV2*>( *symbolIt )->setWidth( width );
}
populateCategories();
}
}

void QgsCategorizedSymbolRendererV2Widget::changeSymbolSize()
{
QList<QgsSymbolV2*> symbolList = selectedSymbols();
if ( symbolList.size() < 1 )
{
return;
}

bool ok;
double size = QInputDialog::getDouble( this, tr( "Size" ), tr( "Change symbol size" ), dynamic_cast<QgsMarkerSymbolV2*>( symbolList.at( 0 ) )->size(), 0.0, 999999, 1, &ok );
if ( ok )
{
QList<QgsSymbolV2*>::iterator symbolIt = symbolList.begin();
for ( ; symbolIt != symbolList.end(); ++symbolIt )
{
dynamic_cast<QgsMarkerSymbolV2*>( *symbolIt )->setSize( size );
}
populateCategories();
}
}

QList<QgsSymbolV2*> QgsCategorizedSymbolRendererV2Widget::selectedSymbols()
{
QList<QgsSymbolV2*> selectedSymbols;
@@ -35,20 +35,6 @@ class GUI_EXPORT QgsCategorizedSymbolRendererV2Widget : public QgsRendererV2Widg
void rotationFieldChanged( QString fldName );
void sizeScaleFieldChanged( QString fldName );

protected slots:
void addCategory();
void contextMenuViewCategories( const QPoint& p );
/**Change color of selected symbols*/
void changeSymbolColor();
/**Change opacity of selected symbols*/
void changeSymbolTransparency();
/**Change units mm/map units of selected symbols*/
void changeSymbolUnit();
/**Change line widths of selected symbols*/
void changeSymbolWidth();
/**Change marker sizes of selected symbols*/
void changeSymbolSize();

protected:

void updateUiFromRenderer();
@@ -74,6 +60,10 @@ class GUI_EXPORT QgsCategorizedSymbolRendererV2Widget : public QgsRendererV2Widg
void changeCategorySymbol();

QList<QgsSymbolV2*> selectedSymbols();
void refreshSymbolView() { populateCategories(); }

protected slots:
void addCategory();

protected:
QgsCategorizedSymbolRendererV2* mRenderer;
@@ -7,8 +7,6 @@

#include "qgsvectorlayer.h"

#include "qgsgraduatedsymbolrendererv2.h"

#include "qgssymbolv2selectordialog.h"

#include "qgsludialog.h"
@@ -54,12 +52,14 @@ QgsGraduatedSymbolRendererV2Widget::QgsGraduatedSymbolRendererV2Widget( QgsVecto
labels << tr( "Range" ) << tr( "Label" );
mg->setHorizontalHeaderLabels( labels );
viewGraduated->setModel( mg );
viewGraduated->setSelectionMode( QAbstractItemView::ExtendedSelection );

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

connect( cboGraduatedColumn, SIGNAL( currentIndexChanged( int ) ), this, SLOT( graduatedColumnChanged() ) );
connect( viewGraduated, SIGNAL( doubleClicked( const QModelIndex & ) ), this, SLOT( rangesDoubleClicked( const QModelIndex & ) ) );
connect( viewGraduated, SIGNAL( clicked( const QModelIndex & ) ), this, SLOT( rangesClicked( const QModelIndex & ) ) );
connect( viewGraduated, SIGNAL( customContextMenuRequested( const QPoint& ) ), this, SLOT( contextMenuViewCategories( const QPoint& ) ) );
connect( mg, SIGNAL( itemChanged( QStandardItem * ) ), this, SLOT( changeCurrentValue( QStandardItem * ) ) );
connect( btnGraduatedClassify, SIGNAL( clicked() ), this, SLOT( classifyGraduated() ) );
connect( btnChangeGraduatedSymbol, SIGNAL( clicked() ), this, SLOT( changeGraduatedSymbol() ) );
@@ -339,3 +339,57 @@ void QgsGraduatedSymbolRendererV2Widget::sizeScaleFieldChanged( QString fldName
{
mRenderer->setSizeScaleField( fldName );
}

QList<QgsSymbolV2*> QgsGraduatedSymbolRendererV2Widget::selectedSymbols()
{
QList<QgsSymbolV2*> selectedSymbols;

QItemSelectionModel* m = viewGraduated->selectionModel();
QModelIndexList selectedIndexes = m->selectedRows( 1 );
if ( m && selectedIndexes.size() > 0 )
{
const QgsRangeList& ranges = mRenderer->ranges();
QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
{
QStandardItem* currentItem = qobject_cast<const QStandardItemModel*>( m->model() )->itemFromIndex( *indexIt );
if ( currentItem )
{
QStringList list = currentItem->data( 0 ).toString().split( " " );
if ( list.size() < 3 )
{
continue;
}

double lowerBound = list.at( 0 ).toDouble();
double upperBound = list.at( 2 ).toDouble();
QgsSymbolV2* s = findSymbolForRange( lowerBound, upperBound, ranges );
if ( s )
{
selectedSymbols.append( s );
}
}
}
}
return selectedSymbols;
}

QgsSymbolV2* QgsGraduatedSymbolRendererV2Widget::findSymbolForRange( double lowerBound, double upperBound, const QgsRangeList& ranges ) const
{
for ( QgsRangeList::const_iterator it = ranges.begin(); it != ranges.end(); ++it )
{
//range string has been created with option 'f',4
if ( doubleNear( lowerBound, it->lowerValue(), 0.0001 ) && doubleNear( upperBound, it->upperValue(), 0.0001 ) )
{
return it->symbol();
}
}
return 0;
}

void QgsGraduatedSymbolRendererV2Widget::refreshSymbolView()
{
populateRanges();
}


@@ -1,11 +1,10 @@
#ifndef QGSGRADUATEDSYMBOLRENDERERV2WIDGET_H
#define QGSGRADUATEDSYMBOLRENDERERV2WIDGET_H

#include "qgsgraduatedsymbolrendererv2.h"
#include "qgsrendererv2widget.h"
#include <QStandardItem>

class QgsGraduatedSymbolRendererV2;

#include "ui_qgsgraduatedsymbolrendererv2widget.h"

class GUI_EXPORT QgsGraduatedSymbolRendererV2Widget : public QgsRendererV2Widget, private Ui::QgsGraduatedSymbolRendererV2Widget
@@ -53,7 +52,9 @@ class GUI_EXPORT QgsGraduatedSymbolRendererV2Widget : public QgsRendererV2Widget
void changeRangeSymbol( int rangeIdx );
void changeRange( int rangeIdx );


QList<QgsSymbolV2*> selectedSymbols();
QgsSymbolV2* findSymbolForRange( double lowerBound, double upperBound, const QgsRangeList& ranges ) const;
void refreshSymbolView();


protected:

0 comments on commit ca6a225

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