Skip to content
Permalink
Browse files

Merge branch 'master' of github.com:qgis/Quantum-GIS

  • Loading branch information
pcav committed Sep 5, 2011
2 parents cc8deb9 + c2cf5cb commit 67dfd2e67420ee4d55eac24e89705b488f8b9412
@@ -60,6 +60,7 @@ QgsCategorizedSymbolRendererV2Widget::QgsCategorizedSymbolRendererV2Widget( QgsV
connect( cboCategorizedColumn, SIGNAL( currentIndexChanged( int ) ), this, SLOT( categoryColumnChanged() ) );

connect( viewCategories, SIGNAL( doubleClicked( const QModelIndex & ) ), this, SLOT( categoriesDoubleClicked( const QModelIndex & ) ) );
connect( viewCategories, SIGNAL( customContextMenuRequested( const QPoint& ) ), this, SLOT( contextMenuViewCategories( const QPoint& ) ) );

connect( btnChangeCategorizedSymbol, SIGNAL( clicked() ), this, SLOT( changeCategorizedSymbol() ) );
connect( btnAddCategories, SIGNAL( clicked() ), this, SLOT( addCategories() ) );
@@ -401,3 +402,30 @@ void QgsCategorizedSymbolRendererV2Widget::sizeScaleFieldChanged( QString fldNam
{
mRenderer->setSizeScaleField( fldName );
}

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

QItemSelectionModel* m = viewCategories->selectionModel();
QModelIndexList selectedIndexes = m->selectedRows( 1 );

if ( m && selectedIndexes.size() > 0 )
{
const QgsCategoryList& categories = mRenderer->categories();
QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
{
QStandardItem* currentItem = qobject_cast<const QStandardItemModel*>( m->model() )->itemFromIndex( *indexIt );
if ( currentItem )
{
QgsSymbolV2* s = categories[mRenderer->categoryIndexForValue( currentItem->data() )].symbol();
if ( s )
{
selectedSymbols.append( s );
}
}
}
}
return selectedSymbols;
}
@@ -35,9 +35,6 @@ class GUI_EXPORT QgsCategorizedSymbolRendererV2Widget : public QgsRendererV2Widg
void rotationFieldChanged( QString fldName );
void sizeScaleFieldChanged( QString fldName );

protected slots:
void addCategory();

protected:

void updateUiFromRenderer();
@@ -62,6 +59,12 @@ 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"
@@ -60,6 +58,7 @@ QgsGraduatedSymbolRendererV2Widget::QgsGraduatedSymbolRendererV2Widget( QgsVecto
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 +338,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:
@@ -1,11 +1,142 @@
#include "qgsrendererv2widget.h"
#include "qgssymbolv2.h"
#include "qgsvectorlayer.h"
#include <QColorDialog>
#include <QInputDialog>
#include <QMenu>


QgsRendererV2Widget::QgsRendererV2Widget( QgsVectorLayer* layer, QgsStyleV2* style )
: QWidget(), mLayer( layer ), mStyle( style )
{
}

void QgsRendererV2Widget::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( QCursor::pos() );
}

void QgsRendererV2Widget::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 );
}
refreshSymbolView();
}
}

void QgsRendererV2Widget::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 );
}
refreshSymbolView();
}
}

void QgsRendererV2Widget::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 );
}
refreshSymbolView();
}
}

void QgsRendererV2Widget::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 );
}
refreshSymbolView();
}
}

void QgsRendererV2Widget::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 );
}
refreshSymbolView();
}
}



////////////
@@ -22,6 +22,7 @@ class QgsSymbolV2SelectorDialog;
*/
class GUI_EXPORT QgsRendererV2Widget : public QWidget
{
Q_OBJECT
public:
QgsRendererV2Widget( QgsVectorLayer* layer, QgsStyleV2* style );

@@ -33,6 +34,24 @@ class GUI_EXPORT QgsRendererV2Widget : public QWidget
protected:
QgsVectorLayer* mLayer;
QgsStyleV2* mStyle;

/**Subclasses may provide the capability of changing multiple symbols at once by implementing the following two methods
and by connecting the slot contextMenuViewCategories(const QPoint&)*/
virtual QList<QgsSymbolV2*> selectedSymbols() { return QList<QgsSymbolV2*>(); }
virtual void refreshSymbolView() {}

protected slots:
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();
};


0 comments on commit 67dfd2e

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