Skip to content

Commit

Permalink
symbology-ng: sort the category items when classifying them #4206
Browse files Browse the repository at this point in the history
  • Loading branch information
lynxlynxlynx authored and timlinux committed Sep 7, 2011
1 parent a30c202 commit ad817fc
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
44 changes: 44 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,3 +764,47 @@ void QgsSymbolLayerV2Utils::multiplyImageOpacity( QImage* image, qreal alpha )
}
}
}

static bool _QVariantLessThan( const QVariant& lhs, const QVariant& rhs )
{
switch( lhs.type() )
{
case QVariant::Int:
return lhs.toInt() < rhs.toInt();
case QVariant::UInt:
return lhs.toUInt() < rhs.toUInt();
case QVariant::LongLong:
return lhs.toLongLong() < rhs.toLongLong();
case QVariant::ULongLong:
return lhs.toULongLong() < rhs.toULongLong();
case QVariant::Double:
return lhs.toDouble() < rhs.toDouble();
case QVariant::Char:
return lhs.toChar() < rhs.toChar();
case QVariant::Date:
return lhs.toDate() < rhs.toDate();
case QVariant::Time:
return lhs.toTime() < rhs.toTime();
case QVariant::DateTime:
return lhs.toDateTime() < rhs.toDateTime();
default:
return QString::localeAwareCompare( lhs.toString(), rhs.toString() ) < 0;
}
}

static bool _QVariantGreaterThan( const QVariant& lhs, const QVariant& rhs )
{
return ! _QVariantLessThan( lhs, rhs);
}

void QgsSymbolLayerV2Utils::sortVariantList( QList<QVariant>& list, Qt::SortOrder order )
{
if (order == Qt::AscendingOrder)
{
qSort( list.begin(), list.end(), _QVariantLessThan );
}
else // Qt::DescendingOrder
{
qSort( list.begin(), list.end(), _QVariantGreaterThan );
}
}
4 changes: 4 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <QMap>
#include <Qt>
#include <QtCore>
#include "qgssymbolv2.h"

class QgsSymbolV2;
Expand Down Expand Up @@ -81,6 +82,9 @@ class CORE_EXPORT QgsSymbolLayerV2Utils

/**Multiplies opacity of image pixel values with a (global) transparency value*/
static void multiplyImageOpacity( QImage* image, qreal alpha );

/**Sorts the passed list in requested order*/
static void sortVariantList( QList<QVariant>& list, Qt::SortOrder order );
};

class QPolygonF;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ void QgsCategorizedSymbolRendererV2Widget::changeCategorySymbol()
static void _createCategories( QgsCategoryList& cats, QList<QVariant>& values, QgsSymbolV2* symbol, QgsVectorColorRampV2* ramp )
{
// sort the categories first
// TODO: sortVariantList(values);
//TODO: make the order configurable?
QgsSymbolLayerV2Utils::sortVariantList( values, Qt::AscendingOrder );

int num = values.count();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef QGSCATEGORIZEDSYMBOLRENDERERV2WIDGET_H
#define QGSCATEGORIZEDSYMBOLRENDERERV2WIDGET_H

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

Expand Down

0 comments on commit ad817fc

Please sign in to comment.