131 changes: 131 additions & 0 deletions src/gui/symbology-ng/qgsrendererv2widget.cpp
Original file line number Diff line number Diff line change
@@ -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 );
}
//populateCategories();
}
}

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



////////////
Expand Down
19 changes: 19 additions & 0 deletions src/gui/symbology-ng/qgsrendererv2widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class QgsSymbolV2SelectorDialog;
*/
class GUI_EXPORT QgsRendererV2Widget : public QWidget
{
Q_OBJECT
public:
QgsRendererV2Widget( QgsVectorLayer* layer, QgsStyleV2* style );

Expand All @@ -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();
};


Expand Down
3 changes: 3 additions & 0 deletions src/ui/qgsgraduatedsymbolrendererv2widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@
</item>
<item>
<widget class="QTreeView" name="viewGraduated">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
Expand Down