Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When classifying the categorized view does not sort the values (symbology-ng) #4206 #39

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,3 +765,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::DescendingOrder );

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