Skip to content
Permalink
Browse files

- various changes and bugfixes to QgsCptCityArchive and QgsCptCityCol…

…orRampV2

UI changes:
 - view color ramps in separate list widgets, with qsplitter
 - draw stippled (check-board) background for ramps with transparency
 - save / restore geometry and layout
 - separate preview and info with tab widget
  • Loading branch information
etiennesky committed Sep 16, 2012
1 parent 567a4d4 commit e67ac05380953707d2f6b005194d9b807ec48703

Large diffs are not rendered by default.

@@ -93,7 +93,7 @@ class CORE_EXPORT QgsCptCityDataItem : public QObject
};

QgsCptCityDataItem( QgsCptCityDataItem::Type type, QgsCptCityDataItem* parent,
QString name, QString path, QString info );
QString name, QString path );
virtual ~QgsCptCityDataItem();

bool hasChildren();
@@ -139,18 +139,20 @@ class CORE_EXPORT QgsCptCityDataItem : public QObject

// Find child index in vector of items using '==' operator
static int findItem( QVector<QgsCptCityDataItem*> items, QgsCptCityDataItem * item );
static QgsCptCityDataItem* dataItem( QString path );
/* static QgsCptCityDataItem* dataItem( QString path ); */

// members

Type type() const { return mType; }
QgsCptCityDataItem* parent() const { return mParent; }
void setParent( QgsCptCityDataItem* parent ) { mParent = parent; }
QVector<QgsCptCityDataItem*> children() const { return mChildren; }
QIcon icon() const { return mIcon; }
virtual QIcon icon() { return mIcon; }
virtual QIcon icon( const QSize& size ) { Q_UNUSED( size ) ; return icon(); }
QString name() const { return mName; }
QString path() const { return mPath; }
QString info() const { return mInfo; }
QString shortInfo() const { return mShortInfo; }

void setIcon( QIcon icon ) { mIcon = icon; }

@@ -168,6 +170,7 @@ class CORE_EXPORT QgsCptCityDataItem : public QObject
QString mName;
QString mPath; // it is also used to identify item in tree
QString mInfo;
QString mShortInfo;
QString mToolTip;
QIcon mIcon;
bool mValid;
@@ -192,25 +195,28 @@ class CORE_EXPORT QgsCptCityColorRampItem : public QgsCptCityDataItem
public:

QgsCptCityColorRampItem( QgsCptCityDataItem* parent,
QString name, QString path, QString info = QString(),
QString name, QString path,
QString variantName = QString() );

QgsCptCityColorRampItem( QgsCptCityDataItem* parent,
QString name, QString path, QString info,
QString name, QString path,
QStringList variantList );
~QgsCptCityColorRampItem() {}

// --- reimplemented from QgsCptCityDataItem ---

virtual bool equal( const QgsCptCityDataItem *other );

// --- New virtual methods for layer item derived classes ---
const QgsCptCityColorRampV2& ramp() const { return mRamp; }
QIcon icon();
QIcon icon( const QSize& size );
void init();

protected:

void init();
bool mInitialised;
QgsCptCityColorRampV2 mRamp;
QIcon mIcon;
QList< QIcon > mIcons;
};


@@ -220,12 +226,15 @@ class CORE_EXPORT QgsCptCityCollectionItem : public QgsCptCityDataItem
Q_OBJECT
public:
QgsCptCityCollectionItem( QgsCptCityDataItem* parent,
QString name, QString path, QString info );
QString name, QString path );
~QgsCptCityCollectionItem();

void setPopulated() { mPopulated = true; }
void addChild( QgsCptCityDataItem *item ) { mChildren.append( item ); }
QVector<QgsCptCityDataItem*> childrenRamps( bool recursive );

protected:
bool mPopulatedRamps;
};

/** A directory: contains subdirectories and color ramps */
@@ -234,23 +243,28 @@ class CORE_EXPORT QgsCptCityDirectoryItem : public QgsCptCityCollectionItem
Q_OBJECT
public:
QgsCptCityDirectoryItem( QgsCptCityDataItem* parent,
QString name, QString path, QString info = QString() );
QString name, QString path );
~QgsCptCityDirectoryItem();

QVector<QgsCptCityDataItem*> createChildren();

virtual bool equal( const QgsCptCityDataItem *other );

static QgsCptCityDataItem* dataItem( QgsCptCityDataItem* parent,
QString name, QString path );

protected:
QMap< QString, QStringList > gradientsMap();
QMap< QString, QStringList > rampsMap();
QStringList dirEntries() const;
QMap< QString, QStringList > mRampsMap;
};

/** A selection: contains subdirectories and color ramps */
class CORE_EXPORT QgsCptCitySelectionItem : public QgsCptCityCollectionItem
{
Q_OBJECT
public:
QgsCptCitySelectionItem( QgsCptCityDataItem* parent, QString name, QString path, QString info );
QgsCptCitySelectionItem( QgsCptCityDataItem* parent, QString name, QString path );
~QgsCptCitySelectionItem();

QVector<QgsCptCityDataItem*> createChildren();
@@ -271,9 +285,20 @@ class CORE_EXPORT QgsCptCityBrowserModel : public QAbstractItemModel
Q_OBJECT

public:
explicit QgsCptCityBrowserModel( QObject *parent = 0,
QgsCptCityArchive* archive = QgsCptCityArchive::defaultArchive(),
QString viewName = "authors" );

enum ViewType
{
Authors = 0,
Selections = 1,
List = 2
};

QgsCptCityBrowserModel( QObject* parent = 0,
QgsCptCityArchive* archive = QgsCptCityArchive::defaultArchive(),
ViewType Type = Authors );
QgsCptCityBrowserModel( QObject* parent = 0,
QgsCptCityArchive* archive = QgsCptCityArchive::defaultArchive(),
QVector< QgsCptCityDataItem* > rootItems = 0 );
~QgsCptCityBrowserModel();

// implemented methods from QAbstractItemModel for read-only access
@@ -359,7 +384,8 @@ class CORE_EXPORT QgsCptCityBrowserModel : public QAbstractItemModel

QVector<QgsCptCityDataItem*> mRootItems;
QgsCptCityArchive* mArchive;
QString mViewName;
ViewType mViewType;
QSize mIconSize;
};

#endif
@@ -526,6 +526,10 @@ QPixmap QgsSymbolLayerV2Utils::colorRampPreviewPixmap( QgsVectorColorRampV2* ram
// pixmap.fill( Qt::white ); // this makes the background white instead of transparent
QPainter painter;
painter.begin( &pixmap );

//draw stippled background, for transparent images
drawStippledBackround( &painter, QRect( 0, 0, size.width(), size.height() ) );

// antialising makes the colors duller, and no point in antialiasing a color ramp
// painter.setRenderHint( QPainter::Antialiasing );
for ( int i = 0; i < size.width(); i++ )
@@ -538,6 +542,24 @@ QPixmap QgsSymbolLayerV2Utils::colorRampPreviewPixmap( QgsVectorColorRampV2* ram
return pixmap;
}

void QgsSymbolLayerV2Utils::drawStippledBackround( QPainter* painter, QRect rect )
{
// create a 2x2 checker-board image
uchar pixDataRGB[] = { 255, 255, 255, 255,
127, 127, 127, 255,
127, 127, 127, 255,
255, 255, 255, 255
};
QImage img( pixDataRGB, 2, 2, 8, QImage::Format_ARGB32 );
// scale it to rect so at least 5 patterns are shown
int width = ( rect.width() < rect.height() ) ?
rect.width() / 2.5 : rect.height() / 2.5;
QPixmap pix = QPixmap::fromImage( img.scaled( width, width ) );
// fill rect with texture
QBrush brush;
brush.setTexture( pix );
painter->fillRect( rect, brush );
}

#include <QPolygonF>

@@ -97,6 +97,8 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
static QIcon symbolLayerPreviewIcon( QgsSymbolLayerV2* layer, QgsSymbolV2::OutputUnit u, QSize size );
static QIcon colorRampPreviewIcon( QgsVectorColorRampV2* ramp, QSize size );

static void drawStippledBackround( QPainter* painter, QRect rect );

static QPixmap symbolPreviewPixmap( QgsSymbolV2* symbol, QSize size );
static QPixmap colorRampPreviewPixmap( QgsVectorColorRampV2* ramp, QSize size );

@@ -278,26 +278,29 @@ TODO load schemes
*/

QgsCptCityColorRampV2::QgsCptCityColorRampV2( QString schemeName, QString variantName )
QgsCptCityColorRampV2::QgsCptCityColorRampV2( QString schemeName, QString variantName,
bool doLoadFile )
: mSchemeName( schemeName ), mVariantName( variantName ),
mGradientType( Continuous ), mFileLoaded( false )
mVariantList( QStringList() ), mFileLoaded( false ),
mGradientType( Continuous )
{
// TODO replace this with hard-coded data in the default case
// don't load file if variant is missing
if ( variantName != QString() || mVariantList.isEmpty() )
if ( doLoadFile && ( variantName != QString() || mVariantList.isEmpty() ) )
loadFile();
}

QgsCptCityColorRampV2::QgsCptCityColorRampV2( QString schemeName, QStringList variantList,
QString variantName )
QString variantName, bool doLoadFile )
: mSchemeName( schemeName ), mVariantName( variantName ),
mGradientType( Continuous ), mFileLoaded( false )
mVariantList( variantList ), mFileLoaded( false ),
mGradientType( Continuous )
{
mVariantList = variantList;

// TODO replace this with hard-coded data in the default case
// don't load file if variant is missing
if ( variantName != QString() || mVariantList.isEmpty() )
if ( doLoadFile && ( variantName != QString() || mVariantList.isEmpty() ) )
loadFile();
}

@@ -351,7 +354,24 @@ QColor QgsCptCityColorRampV2::color( double value ) const

QgsVectorColorRampV2* QgsCptCityColorRampV2::clone() const
{
return new QgsCptCityColorRampV2( mSchemeName, mVariantName );
QgsCptCityColorRampV2* ramp = new QgsCptCityColorRampV2( "", "", false );
ramp->copy( this );
return ramp;
}

void QgsCptCityColorRampV2::copy( const QgsCptCityColorRampV2* other )
{
if ( ! other )
return;
mSchemeName = other->mSchemeName;
mVariantName = other->mVariantName;
mVariantList = other->mVariantList;
mFileLoaded = other->mFileLoaded;
if ( other->mFileLoaded )
{
mGradientType = other->mGradientType;
mPalette = other->mPalette;
}
}

QgsStringMap QgsCptCityColorRampV2::properties() const
@@ -167,8 +167,10 @@ class CORE_EXPORT QgsCptCityColorRampV2 : public QgsVectorColorRampV2
{
public:
QgsCptCityColorRampV2( QString schemeName = DEFAULT_CPTCITY_SCHEMENAME,
QString variantName = DEFAULT_CPTCITY_VARIANTNAME );
QgsCptCityColorRampV2( QString schemeName, QStringList variantList, QString variantName = QString() );
QString variantName = DEFAULT_CPTCITY_VARIANTNAME,
bool doLoadFile = true );
QgsCptCityColorRampV2( QString schemeName, QStringList variantList,
QString variantName = QString(), bool doLoadFile = true );


enum GradientType
@@ -187,6 +189,7 @@ class CORE_EXPORT QgsCptCityColorRampV2 : public QgsVectorColorRampV2
virtual QString type() const { return "cpt-city"; }

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

virtual QgsStringMap properties() const;

@@ -203,6 +206,7 @@ class CORE_EXPORT QgsCptCityColorRampV2 : public QgsVectorColorRampV2
/* lazy loading - have to call loadPalette() explicitly */
void setSchemeName( QString schemeName ) { mSchemeName = schemeName; mFileLoaded = false; }
void setVariantName( QString variantName ) { mVariantName = variantName; mFileLoaded = false; }
void setVariantList( QStringList variantList ) { mVariantList = variantList; }
void setName( QString schemeName, QString variantName = "", QStringList variantList = QStringList() )
{ mSchemeName = schemeName; mVariantName = variantName; mVariantList = variantList; mFileLoaded = false; }

@@ -212,6 +216,7 @@ class CORE_EXPORT QgsCptCityColorRampV2 : public QgsVectorColorRampV2

QString fileName() const;
bool loadFile();
bool fileLoaded() const { return mFileLoaded; }

QString copyingFileName() const;
QString descFileName() const;
@@ -221,12 +226,10 @@ class CORE_EXPORT QgsCptCityColorRampV2 : public QgsVectorColorRampV2

QString mSchemeName;
QString mVariantName;
/* QString mCollectionName; */
/* QgsCptCityCollection* mCollection; */
GradientType mGradientType;
GradientList mPalette;
QStringList mVariantList;
bool mFileLoaded;
GradientType mGradientType;
GradientList mPalette;
};


0 comments on commit e67ac05

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