Skip to content
Permalink
Browse files

graduated renderer GUI DnD and sort; categorized symbol GUI better dr…

…op indicator
  • Loading branch information
blazek committed Nov 18, 2012
1 parent ba0cd0c commit a1a1fb7be7c0672f745007918f5e020c9eb22f98
@@ -22,8 +22,8 @@ class QgsGraduatedSymbolRendererV2Widget : QgsRendererV2Widget

/**Adds a class manually to the classification*/
void addClass();
/**Removes a class from the classification*/
void deleteCurrentClass();
/**Removes selected classes*/
void deleteClasses();

void rotationFieldChanged( QString fldName );
void sizeScaleFieldChanged( QString fldName );
@@ -39,9 +39,6 @@ class QgsGraduatedSymbolRendererV2Widget : QgsRendererV2Widget
//! populate column combos in categorized and graduated page
void populateColumns();

//! populate ranges of graduated symbol renderer
void populateRanges();

void changeRangeSymbol( int rangeIdx );
void changeRange( int rangeIdx );

@@ -30,6 +30,11 @@
#include <cmath> // for pretty classification
#include <ctime>

QgsRendererRangeV2::QgsRendererRangeV2()
: mLowerValue( 0 ), mUpperValue( 0 ), mSymbol( 0 ), mLabel()
{
}

QgsRendererRangeV2::QgsRendererRangeV2( double lowerValue, double upperValue, QgsSymbolV2* symbol, QString label )
: mLowerValue( lowerValue )
, mUpperValue( upperValue )
@@ -51,6 +56,19 @@ QgsRendererRangeV2::~QgsRendererRangeV2()
delete mSymbol;
}

QgsRendererRangeV2& QgsRendererRangeV2::operator=( const QgsRendererRangeV2 & range )
{
mLowerValue = range.mLowerValue;
mUpperValue = range.mUpperValue;
mLabel = range.mLabel;
mSymbol = 0;
if ( range.mSymbol )
{
mSymbol = range.mSymbol->clone();
}
return *this;
}

double QgsRendererRangeV2::lowerValue() const
{
return mLowerValue;
@@ -1117,3 +1135,60 @@ void QgsGraduatedSymbolRendererV2::deleteClass( int idx )
{
mRanges.removeAt( idx );
}

void QgsGraduatedSymbolRendererV2::deleteAllClasses()
{
mRanges.clear();
}

void QgsGraduatedSymbolRendererV2::moveClass( int from, int to )
{
if ( from < 0 || from >= mRanges.size() || to < 0 || to >= mRanges.size() ) return;
mRanges.move( from, to );
}

bool valueLessThan( const QgsRendererRangeV2 &r1, const QgsRendererRangeV2 &r2 )
{
return r1.lowerValue() < r2.lowerValue();
}

bool valueGreaterThan( const QgsRendererRangeV2 &r1, const QgsRendererRangeV2 &r2 )
{
return !valueLessThan( r1, r2 );
}

void QgsGraduatedSymbolRendererV2::sortByValue( Qt::SortOrder order )
{
QgsDebugMsg( "Entered" );
if ( order == Qt::AscendingOrder )
{
qSort( mRanges.begin(), mRanges.end(), valueLessThan );
}
else
{
qSort( mRanges.begin(), mRanges.end(), valueGreaterThan );
}
}

bool labelLessThan( const QgsRendererRangeV2 &r1, const QgsRendererRangeV2 &r2 )
{
return QString::localeAwareCompare( r1.label(), r2.label() ) < 0;
}

bool labelGreaterThan( const QgsRendererRangeV2 &r1, const QgsRendererRangeV2 &r2 )
{
return !labelLessThan( r1, r2 );
}

void QgsGraduatedSymbolRendererV2::sortByLabel( Qt::SortOrder order )
{
if ( order == Qt::AscendingOrder )
{
qSort( mRanges.begin(), mRanges.end(), labelLessThan );
}
else
{
qSort( mRanges.begin(), mRanges.end(), labelGreaterThan );
}
}

@@ -21,11 +21,14 @@
class CORE_EXPORT QgsRendererRangeV2
{
public:
QgsRendererRangeV2();
QgsRendererRangeV2( double lowerValue, double upperValue, QgsSymbolV2* symbol, QString label );
QgsRendererRangeV2( const QgsRendererRangeV2& range );

~QgsRendererRangeV2();

QgsRendererRangeV2& operator=( const QgsRendererRangeV2& range );

double lowerValue() const;
double upperValue() const;

@@ -92,6 +95,13 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2

void addClass( QgsSymbolV2* symbol );
void deleteClass( int idx );
void deleteAllClasses();

//! Moves the category at index position from to index position to.
void moveClass( int from, int to );

void sortByValue( Qt::SortOrder order = Qt::AscendingOrder );
void sortByLabel( Qt::SortOrder order = Qt::AscendingOrder );

enum Mode
{
@@ -32,6 +32,8 @@
#include <QMessageBox>
#include <QStandardItemModel>
#include <QStandardItem>
#include <QPen>
#include <QPainter>

QgsCategorizedSymbolRendererV2Model::QgsCategorizedSymbolRendererV2Model( QObject * parent ) : QAbstractItemModel( parent )
, mRenderer( 0 )
@@ -236,6 +238,9 @@ bool QgsCategorizedSymbolRendererV2Model::dropMimeData( const QMimeData *data, Q
}

int to = parent.row();
// to is -1 if dragged outside items, i.e. below any item,
// then move to the last position
if ( to == -1 ) to = mRenderer->categories().size(); // out of rang ok, will be decreased
for ( int i = rows.size() - 1; i >= 0; i-- )
{
QgsDebugMsg( QString( "move %1 to %2" ).arg( rows[i] ).arg( to ) );
@@ -292,6 +297,27 @@ void QgsCategorizedSymbolRendererV2Model::sort( int column, Qt::SortOrder order
QgsDebugMsg( "Done" );
}

// ------------------------------ View style --------------------------------
QgsCategorizedSymbolRendererV2ViewStyle::QgsCategorizedSymbolRendererV2ViewStyle( QStyle* style )
: QProxyStyle( style )
{}

void QgsCategorizedSymbolRendererV2ViewStyle::drawPrimitive( PrimitiveElement element, const QStyleOption * option, QPainter * painter, const QWidget * widget ) const
{
if ( element == QStyle::PE_IndicatorItemViewItemDrop && !option->rect.isNull() )
{
QStyleOption opt( *option );
opt.rect.setLeft( 0 );
// draw always as line above, because we move item to that index
opt.rect.setHeight( 0 );
if ( widget ) opt.rect.setRight( widget->width() );
QProxyStyle::drawPrimitive( element, &opt, painter, widget );
return;
}
QProxyStyle::drawPrimitive( element, option, painter, widget );
}

// ------------------------------ Widget ------------------------------------
QgsRendererV2Widget* QgsCategorizedSymbolRendererV2Widget::create( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer )
{
return new QgsCategorizedSymbolRendererV2Widget( layer, style, renderer );
@@ -343,6 +369,8 @@ QgsCategorizedSymbolRendererV2Widget::QgsCategorizedSymbolRendererV2Widget( QgsV
viewCategories->resizeColumnToContents( 1 );
viewCategories->resizeColumnToContents( 2 );

viewCategories->setStyle( new QgsCategorizedSymbolRendererV2ViewStyle( viewCategories->style() ) );

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

connect( mModel, SIGNAL( rowsMoved() ), this, SLOT( rowsMoved() ) );
@@ -18,6 +18,7 @@
#include "qgscategorizedsymbolrendererv2.h"
#include "qgsrendererv2widget.h"
#include <QStandardItem>
#include <QProxyStyle>

class QgsCategorizedSymbolRendererV2;
class QgsRendererCategoryV2;
@@ -57,6 +58,15 @@ class GUI_EXPORT QgsCategorizedSymbolRendererV2Model : public QAbstractItemModel
QString mMimeFormat;
};

// View style which shows drop indicator line between items
class QgsCategorizedSymbolRendererV2ViewStyle: public QProxyStyle
{
public:
QgsCategorizedSymbolRendererV2ViewStyle( QStyle* style = 0 );

void drawPrimitive( PrimitiveElement element, const QStyleOption * option, QPainter * painter, const QWidget * widget = 0 ) const;
};

class GUI_EXPORT QgsCategorizedSymbolRendererV2Widget : public QgsRendererV2Widget, private Ui::QgsCategorizedSymbolRendererV2Widget
{
Q_OBJECT

0 comments on commit a1a1fb7

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