Skip to content
Permalink
Browse files

symbology-ng: sort the category items when classifying them #4206

  • Loading branch information
lynxlynxlynx authored and timlinux committed Sep 7, 2011
1 parent a30c202 commit ad817fc275434e4dc6efd36855174522edd5f8de
@@ -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 );
}
}
@@ -5,6 +5,7 @@

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

class QgsSymbolV2;
@@ -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;
@@ -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();

@@ -1,6 +1,7 @@
#ifndef QGSCATEGORIZEDSYMBOLRENDERERV2WIDGET_H
#define QGSCATEGORIZEDSYMBOLRENDERERV2WIDGET_H

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

0 comments on commit ad817fc

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