37 changes: 18 additions & 19 deletions python/core/symbology-ng/qgsvectorcolorrampv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,25 @@ class QgsVectorColorRampV2

};

struct QgsGradientStop
{
double offset;
QColor color;
QgsGradientStop( double o, const QColor& c );
};

typedef QList<QgsGradientStop> QgsGradientStopsList;

class QgsVectorGradientColorRampV2 : QgsVectorColorRampV2
{
%TypeHeaderCode
#include <qgsvectorcolorrampv2.h>
%End
public:
QgsVectorGradientColorRampV2( QColor color1 = DEFAULT_GRADIENT_COLOR1,
QColor color2 = DEFAULT_GRADIENT_COLOR2 );
QColor color2 = QColor(0,255,0),
bool discrete = false,
QgsGradientStopsList stops = QgsGradientStopsList() );

static QgsVectorColorRampV2* create( const QgsStringMap& properties = QgsStringMap() ) /Factory/;

Expand All @@ -51,10 +62,11 @@ class QgsVectorGradientColorRampV2 : QgsVectorColorRampV2
void setColor1( QColor color );
void setColor2( QColor color );

typedef QMap<double, QColor> StopsMap;
bool isDiscrete() const;
void setDiscrete( bool discrete );

void setStops( const StopsMap& stops );
const StopsMap& stops() const;
void setStops( const QgsGradientStopsList& stops );
const QgsGradientStopsList& stops() const;
};

class QgsVectorRandomColorRampV2 : QgsVectorColorRampV2
Expand Down Expand Up @@ -144,29 +156,15 @@ class QgsCptCityColorRampV2
QgsCptCityColorRampV2( QString schemeName, QStringList variantList,
QString variantName = QString(), bool doLoadFile = true );


enum GradientType
{
Discrete, //discrete stops, e.g. Color Brewer
Continuous, //continuous, e.g. QgsVectorColorRampV2
ContinuousMulti //continuous with 2 values in intermediate stops
};
typedef QList< QPair < double, QColor > > GradientList;


static QgsVectorColorRampV2* create( const QgsStringMap& properties = QgsStringMap() ) /Factory/;

virtual QColor color( double value ) const;

virtual QString type() const;

virtual QgsVectorColorRampV2* clone() const /Factory/;
void copy( const QgsCptCityColorRampV2* other );

virtual QgsStringMap properties() const;

int count() const;

QString schemeName() const;
QString variantName() const;
QStringList variantList() const;
Expand All @@ -178,7 +176,8 @@ class QgsCptCityColorRampV2
void setName( QString schemeName, QString variantName = "", QStringList variantList = QStringList() );

void loadPalette();
GradientType gradientType() const;
bool hasMultiStops() const;
int count() const;

QString fileName() const;
bool loadFile();
Expand Down
116 changes: 86 additions & 30 deletions src/core/symbology-ng/qgscptcityarchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ QgsCptCityArchive::QgsCptCityArchive( QString archiveName, QString baseDir )
: mArchiveName( archiveName ), mBaseDir( baseDir )
{
QgsDebugMsg( "archiveName = " + archiveName + " baseDir = " + baseDir );
// make root items

// make Author items
QgsCptCityDirectoryItem* dirItem = 0;
foreach ( QString path, QDir( mBaseDir ).entryList( QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name ) )
{
Expand All @@ -61,21 +62,29 @@ QgsCptCityArchive::QgsCptCityArchive( QString archiveName, QString baseDir )
}

// make selection items
QgsCptCitySelectionItem* item = 0;
QgsCptCitySelectionItem* selItem = 0;
QDir seldir( mBaseDir + QDir::separator() + "selections" );
QgsDebugMsg( "populating selection from " + seldir.path() );
foreach ( QString selfile, seldir.entryList( QStringList( "*.xml" ), QDir::Files ) )
{
QgsDebugMsg( "file= " + seldir.path() + "/" + selfile );
item = new QgsCptCitySelectionItem( NULL, QFileInfo( selfile ).baseName(),
seldir.dirName() + QDir::separator() + selfile );
selItem = new QgsCptCitySelectionItem( NULL, QFileInfo( selfile ).baseName(),
seldir.dirName() + QDir::separator() + selfile );
//TODO remove item if there are no children (e.g. esri in qgis-sel)
if ( item->isValid() )
mSelectionItems << item;
if ( selItem->isValid() )
mSelectionItems << selItem;
else
delete item;
delete selItem;
}

// make "All Ramps items" (which will contain all ramps without hierarchy)
QgsCptCityAllRampsItem* allRampsItem;
allRampsItem = new QgsCptCityAllRampsItem( NULL, QObject::tr( "All Ramps" ),
mRootItems );
mRootItems.prepend( allRampsItem );
allRampsItem = new QgsCptCityAllRampsItem( NULL, QObject::tr( "All Ramps" ),
mSelectionItems );
mSelectionItems.prepend( allRampsItem );
}

QgsCptCityArchive::~QgsCptCityArchive( )
Expand Down Expand Up @@ -157,9 +166,9 @@ QString QgsCptCityArchive::descFileName( const QString& path ) const
baseDir() + QDir::separator() + path, baseDir() );
}

QMap< QString, QString > QgsCptCityArchive::copyingInfo( const QString& fileName )
QgsStringMap QgsCptCityArchive::copyingInfo( const QString& fileName )
{
QMap< QString, QString > copyingMap;
QgsStringMap copyingMap;

if ( fileName.isNull() )
return copyingMap;
Expand Down Expand Up @@ -258,9 +267,9 @@ QMap< QString, QString > QgsCptCityArchive::copyingInfo( const QString& fileName
return copyingMap;
}

QMap< QString, QString > QgsCptCityArchive::description( const QString& fileName )
QgsStringMap QgsCptCityArchive::description( const QString& fileName )
{
QMap< QString, QString > descMap;
QgsStringMap descMap;

QgsDebugMsg( "description fileName = " + fileName );

Expand Down Expand Up @@ -435,7 +444,7 @@ void QgsCptCityArchive::initDefaultArchive()

void QgsCptCityArchive::initArchives( bool loadAll )
{
QMap< QString, QString > archivesMap;
QgsStringMap archivesMap;
QString baseDir, defArchiveName;
QSettings settings;

Expand All @@ -460,7 +469,7 @@ void QgsCptCityArchive::initArchives( bool loadAll )
archivesMap[ defArchiveName ] = baseDir + QDir::separator() + defArchiveName;
}

for ( QMap< QString, QString >::iterator it = archivesMap.begin();
for ( QgsStringMap::iterator it = archivesMap.begin();
it != archivesMap.end(); ++it )
{
if ( QDir( it.value() ).exists() )
Expand Down Expand Up @@ -730,16 +739,18 @@ void QgsCptCityColorRampItem::init( )
if ( variantList.isEmpty() )
{
int count = mRamp.count();
QgsCptCityColorRampV2::GradientType type = mRamp.gradientType();
if ( type == QgsCptCityColorRampV2::Discrete )
if ( mRamp.isDiscrete() )
count--;
mInfo = QString::number( count ) + " " + tr( "colors" ) + " - ";
if ( type == QgsCptCityColorRampV2::Continuous )
mInfo += tr( "continuous" );
else if ( type == QgsCptCityColorRampV2::ContinuousMulti )
mInfo += tr( "continuous (multi)" );
else if ( type == QgsCptCityColorRampV2::Discrete )
if ( mRamp.isDiscrete() )
mInfo += tr( "discrete" );
else
{
if ( !mRamp.hasMultiStops() )
mInfo += tr( "continuous" );
else
mInfo += tr( "continuous (multi)" );
}
mShortInfo = QFileInfo( mName ).fileName();
}
else
Expand Down Expand Up @@ -858,7 +869,7 @@ QgsCptCityDirectoryItem::QgsCptCityDirectoryItem( QgsCptCityDataItem* parent,
: QgsCptCityCollectionItem( parent, name, path )
{
mType = Directory;
mValid = QDir( QgsCptCityArchive::defaultBaseDir() ).exists();
mValid = QDir( QgsCptCityArchive::defaultBaseDir() + QDir::separator() + mPath ).exists();
if ( ! mValid )
{
QgsDebugMsg( "created invalid dir item, path = " + QgsCptCityArchive::defaultBaseDir()
Expand All @@ -869,7 +880,7 @@ QgsCptCityDirectoryItem::QgsCptCityDirectoryItem( QgsCptCityDataItem* parent,
mInfo = "";
QString fileName = QgsCptCityArchive::defaultBaseDir() + QDir::separator() + \
mPath + QDir::separator() + "DESC.xml";
QMap< QString, QString > descMap = QgsCptCityArchive::description( fileName );
QgsStringMap descMap = QgsCptCityArchive::description( fileName );
if ( descMap.contains( "name" ) )
mInfo = descMap.value( "name" );

Expand Down Expand Up @@ -1138,7 +1149,9 @@ QgsCptCitySelectionItem::QgsCptCitySelectionItem( QgsCptCityDataItem* parent,
: QgsCptCityCollectionItem( parent, name, path )
{
mType = Selection;
parseXML();
mValid = ! path.isNull();
if ( mValid )
parseXML();
}

QgsCptCitySelectionItem::~QgsCptCitySelectionItem()
Expand Down Expand Up @@ -1255,6 +1268,38 @@ bool QgsCptCitySelectionItem::equal( const QgsCptCityDataItem *other )
return ( path() == other->path() );
}

//-----------------------------------------------------------------------
QgsCptCityAllRampsItem::QgsCptCityAllRampsItem( QgsCptCityDataItem* parent,
QString name, QVector<QgsCptCityDataItem*> items )
: QgsCptCityCollectionItem( parent, name, QString() ), mItems( items )
{
mType = AllRamps;
mValid = true;
// populate();
}

QgsCptCityAllRampsItem::~QgsCptCityAllRampsItem()
{
}

QVector<QgsCptCityDataItem*> QgsCptCityAllRampsItem::createChildren()
{
if ( ! mValid )
return QVector<QgsCptCityDataItem*>();

QVector<QgsCptCityDataItem*> children;

// add children ramps of each item
foreach ( QgsCptCityDataItem* item, mItems )
{
QgsCptCityCollectionItem* colItem = dynamic_cast< QgsCptCityCollectionItem* >( item );
if ( colItem )
children += colItem->childrenRamps( true );
}

return children;
}

//-----------------------------------------------------------------------

QgsCptCityBrowserModel::QgsCptCityBrowserModel( QObject *parent,
Expand Down Expand Up @@ -1341,12 +1386,11 @@ QVariant QgsCptCityBrowserModel::data( const QModelIndex &index, int role ) cons
return item->icon( mIconSize );
}
else if ( role == Qt::FontRole &&
( item->type() == QgsCptCityDataItem::Directory ||
item->type() == QgsCptCityDataItem::Selection ) )
( dynamic_cast< QgsCptCityCollectionItem* >( item ) != 0 ) )
{
// collectionitems are larger and bold
QFont font;
// font.setPointSize( font.pointSize() + 1 );
font.setPointSize( 11 ); //FIXME why is the font so small?
font.setBold( true );
return font;
}
Expand Down Expand Up @@ -1416,7 +1460,11 @@ QModelIndex QgsCptCityBrowserModel::findPath( QString path )
{
foundChild = false; // assume that the next child item will not be found

for ( int i = 0; i < rowCount( theIndex ); i++ )
int i = 0;
// if root skip first item "All Ramps"
if ( itemPath.isEmpty() )
i = 1;
for ( ; i < rowCount( theIndex ); i++ )
{
QModelIndex idx = index( i, 0, theIndex );
QgsCptCityDataItem *item = dataItem( idx );
Expand Down Expand Up @@ -1585,9 +1633,17 @@ bool QgsCptCityBrowserModel::canFetchMore( const QModelIndex & parent ) const
QgsCptCityDataItem* item = dataItem( parent );
// fetch all items initially so we know which items have children
// (nicer looking and less confusing)
if ( item )
item->populate();
return ( item && ! item->isPopulated() );

if ( ! item )
return false;

// except for "All Ramps" - this is populated when clicked on
if ( item->type() == QgsCptCityDataItem::AllRamps )
return false;

item->populate();

return ( ! item->isPopulated() );
}

void QgsCptCityBrowserModel::fetchMore( const QModelIndex & parent )
Expand Down
17 changes: 16 additions & 1 deletion src/core/symbology-ng/qgscptcityarchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class CORE_EXPORT QgsCptCityDataItem : public QObject
ColorRamp,
Collection,
Directory,
Selection
Selection,
AllRamps
};

QgsCptCityDataItem( QgsCptCityDataItem::Type type, QgsCptCityDataItem* parent,
Expand Down Expand Up @@ -277,6 +278,20 @@ class CORE_EXPORT QgsCptCitySelectionItem : public QgsCptCityCollectionItem
QStringList mSelectionsList;
};

/** An "All ramps item", which contains all items in a flat hierarchy */
class CORE_EXPORT QgsCptCityAllRampsItem : public QgsCptCityCollectionItem
{
Q_OBJECT
public:
QgsCptCityAllRampsItem( QgsCptCityDataItem* parent, QString name,
QVector<QgsCptCityDataItem*> items );
~QgsCptCityAllRampsItem();

QVector<QgsCptCityDataItem*> createChildren();

protected:
QVector<QgsCptCityDataItem*> mItems;
};


class CORE_EXPORT QgsCptCityBrowserModel : public QAbstractItemModel
Expand Down
Loading