Skip to content

Commit 8f3142e

Browse files
committedAug 10, 2012
add author and license information ; UI tweaks ; add avg preview if available ( see QgsCptCityColorRampV2Dialog::eventFilter() )
1 parent c5b2858 commit 8f3142e

File tree

6 files changed

+732
-286
lines changed

6 files changed

+732
-286
lines changed
 

‎src/core/symbology-ng/qgsvectorcolorrampv2.cpp

Lines changed: 158 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "qgslogger.h"
2222

2323
#include <stdlib.h> // for random()
24+
#include <sys/time.h>
2425

2526
QgsVectorGradientColorRampV2::QgsVectorGradientColorRampV2( QColor color1, QColor color2 )
2627
: mColor1( color1 ), mColor2( color2 )
@@ -256,11 +257,25 @@ QgsStringMap QgsVectorColorBrewerColorRampV2::properties() const
256257

257258
/*
258259
TODO
259-
- return a suitable name (scheme_variant)
260-
- use model/view for the treewidget
261-
- fix ocal file parsing
260+
- return a suitable name (scheme_variant) ??
262261
- re-organize and rename colorramp classes and widgets
263262
*/
263+
264+
/*
265+
TODO load schemes
266+
- don't show empty dirs? (e.g. jjg/hatch)
267+
268+
- better grouping:
269+
- cl/fs2????
270+
- cw
271+
- dca
272+
- dirs with one scheme ( cl/ es/ ma/ occ/ wkp/
273+
jjg/neo10/env/green-crystal jjg/neo10/face/eyes/blue )
274+
275+
- fix rendering:
276+
- ibcao
277+
278+
*/
264279
QString QgsCptCityColorRampV2::mBaseDir;
265280
QStringList QgsCptCityColorRampV2::mCollections;
266281
QMap< QString, QStringList > QgsCptCityColorRampV2::mSchemeMap;
@@ -389,7 +404,7 @@ QgsStringMap QgsCptCityColorRampV2::properties() const
389404

390405
QStringList QgsCptCityColorRampV2::listSchemeCollections( QString collectionName, bool recursive )
391406
{
392-
QDir dir = QDir( QgsCptCityColorRampV2::getBaseDir() + "/" + collectionName );
407+
QDir dir = QDir( QgsCptCityColorRampV2::baseDir() + "/" + collectionName );
393408
if ( ! dir.exists() )
394409
return QStringList();
395410

@@ -417,7 +432,7 @@ QStringList QgsCptCityColorRampV2::listSchemeCollections( QString collectionName
417432

418433
QStringList QgsCptCityColorRampV2::listSchemeNames( QString collectionName )
419434
{
420-
QDir dir = QDir( QgsCptCityColorRampV2::getBaseDir() + "/" + collectionName );
435+
QDir dir = QDir( QgsCptCityColorRampV2::baseDir() + "/" + collectionName );
421436
if ( ! dir.exists() )
422437
{
423438
QgsDebugMsg( "dir " + dir.dirName() + " does not exist" );
@@ -430,7 +445,7 @@ QStringList QgsCptCityColorRampV2::listSchemeNames( QString collectionName )
430445
return entries;
431446
}
432447

433-
QString QgsCptCityColorRampV2::getBaseDir()
448+
QString QgsCptCityColorRampV2::baseDir()
434449
{
435450
// if was set with setBaseDir, return that value
436451
QString baseDir = mBaseDir;
@@ -451,19 +466,137 @@ QString QgsCptCityColorRampV2::getBaseDir()
451466
return baseDir;
452467
}
453468

454-
QString QgsCptCityColorRampV2::getFilename() const
469+
QString QgsCptCityColorRampV2::fileName() const
455470
{
456471
if ( mSchemeName == "" )
457472
return QString();
458473
else
459-
return QgsCptCityColorRampV2::getBaseDir() + "/" + mSchemeName + mVariantName + ".svg";
474+
return QgsCptCityColorRampV2::baseDir() + "/" + mSchemeName + mVariantName + ".svg";
475+
}
476+
477+
QString findFileName( const QString & target, const QString & startDir, const QString & baseDir )
478+
{
479+
if ( startDir == "" || ! startDir.startsWith( baseDir ) )
480+
return QString();
481+
482+
QDir dir = QDir( startDir );
483+
//todo test when
484+
while ( ! dir.exists( target ) && dir.path() != baseDir )
485+
{
486+
dir.cdUp();
487+
}
488+
if ( ! dir.exists( target ) )
489+
return QString();
490+
else
491+
return dir.path() + QDir::separator() + target;
492+
}
493+
494+
QString QgsCptCityColorRampV2::copyingFileName() const
495+
{
496+
return findFileName( "COPYING.xml", QFileInfo( fileName() ).dir().path(), baseDir() );
497+
}
498+
499+
QString QgsCptCityColorRampV2::descFileName() const
500+
{
501+
return findFileName( "DESC.xml", QFileInfo( fileName() ).dir().path(), baseDir() );
502+
}
503+
504+
QMap< QString, QString > QgsCptCityColorRampV2::copyingInfo()
505+
{
506+
QMap< QString, QString > copyingMap;
507+
508+
// import xml file
509+
QString licenseFileName = copyingFileName();
510+
if ( licenseFileName.isNull() )
511+
return copyingMap;
512+
QFile f( licenseFileName );
513+
if ( !f.open( QFile::ReadOnly ) )
514+
{
515+
QgsDebugMsg( "Couldn't open xml file: " + licenseFileName );
516+
return copyingMap;
517+
}
518+
519+
// parse the document
520+
QDomDocument doc( "license" );
521+
if ( !doc.setContent( &f ) )
522+
{
523+
f.close();
524+
QgsDebugMsg( "Couldn't parse xml file: " + licenseFileName );
525+
return copyingMap;
526+
}
527+
f.close();
528+
529+
// get root element
530+
QDomElement docElem = doc.documentElement();
531+
if ( docElem.tagName() != "copying" )
532+
{
533+
QgsDebugMsg( "Incorrect root tag: " + docElem.tagName() );
534+
return copyingMap;
535+
}
536+
537+
// load author information
538+
QDomElement authorsElement = docElem.firstChildElement( "authors" );
539+
if ( authorsElement.isNull() )
540+
{
541+
QgsDebugMsg( "authors tag missing" );
542+
}
543+
else
544+
{
545+
QDomElement e = authorsElement.firstChildElement();
546+
QStringList authors;
547+
while ( ! e.isNull() )
548+
{
549+
if ( e.tagName() == "author" )
550+
{
551+
if ( ! e.firstChildElement( "name" ).isNull() )
552+
authors << e.firstChildElement( "name" ).text().simplified();
553+
// org???
554+
}
555+
e = e.nextSiblingElement();
556+
}
557+
copyingMap[ "authors" ] = authors.join( ", " );
558+
}
559+
560+
// load license information
561+
QDomElement licenseElement = docElem.firstChildElement( "license" );
562+
if ( licenseElement.isNull() )
563+
{
564+
QgsDebugMsg( "license tag missing" );
565+
}
566+
else
567+
{
568+
QDomElement e = licenseElement.firstChildElement( "informal" );
569+
if ( ! e.isNull() )
570+
copyingMap[ "license/informal" ] = e.text().simplified();
571+
e = licenseElement.firstChildElement( "year" );
572+
if ( ! e.isNull() )
573+
copyingMap[ "license/year" ] = e.text().simplified();
574+
e = licenseElement.firstChildElement( "text" );
575+
if ( ! e.isNull() && e.attribute( "href" ) != QString() )
576+
copyingMap[ "license/url" ] = e.attribute( "href" );
577+
}
578+
579+
// load src information
580+
QDomElement element = docElem.firstChildElement( "src" );
581+
if ( element.isNull() )
582+
{
583+
QgsDebugMsg( "src tag missing" );
584+
}
585+
else
586+
{
587+
QDomElement e = element.firstChildElement( "link" );
588+
if ( ! e.isNull() && e.attribute( "href" ) != QString() )
589+
copyingMap[ "src/link" ] = e.attribute( "href" );
590+
}
591+
592+
return copyingMap;
460593
}
461594

462595
bool QgsCptCityColorRampV2::loadFile( QString filename )
463596
{
464597
if ( filename == "" )
465598
{
466-
filename = getFilename();
599+
filename = fileName();
467600
if ( filename.isNull() )
468601
return false;
469602
}
@@ -503,9 +636,15 @@ bool QgsCptCityColorRampV2::loadFile( QString filename )
503636
return false;
504637
}
505638

506-
// load color ramp
639+
// load color ramp from first linearGradient node
507640
QDomElement rampsElement = docElem.firstChildElement( "linearGradient" );
508641
if ( rampsElement.isNull() )
642+
{
643+
QDomNodeList nodeList = docElem.elementsByTagName( "linearGradient" );
644+
if ( ! nodeList.isEmpty() )
645+
rampsElement = nodeList.at( 0 ).toElement();
646+
}
647+
if ( rampsElement.isNull() )
509648
{
510649
mErrorString = "linearGradient tag missing";
511650
QgsDebugMsg( mErrorString );
@@ -621,9 +760,12 @@ bool QgsCptCityColorRampV2::hasAllSchemes()
621760
return true;
622761
}
623762

624-
// currently this methos takes some time, so it must be explicitly requested
763+
// currently this method takes some time, so it must be explicitly requested
625764
bool QgsCptCityColorRampV2::loadSchemes( QString rootDir, bool reset )
626765
{
766+
struct timeval tv1, tv2;
767+
gettimeofday( &tv1, 0 );
768+
627769
// TODO should keep the name of the previously loaded, or see if the first element is inside rootDir
628770
if ( ! reset && ! mCollections.isEmpty() )
629771
{
@@ -787,7 +929,8 @@ bool QgsCptCityColorRampV2::loadSchemes( QString rootDir, bool reset )
787929
// populate mCollectionNames
788930
foreach ( QString path, mCollections )
789931
{
790-
QString filename = QgsCptCityColorRampV2::getBaseDir() + "/" + path + "/" + "DESC.xml";
932+
// TODO parse DESC.xml and COPYING.xml here, and add to CptCityCollection member
933+
QString filename = QgsCptCityColorRampV2::baseDir() + "/" + path + "/" + "DESC.xml";
791934
QFile f( filename );
792935
if ( ! f.open( QFile::ReadOnly ) )
793936
{
@@ -844,6 +987,9 @@ bool QgsCptCityColorRampV2::loadSchemes( QString rootDir, bool reset )
844987
mCollectionSelections[ viewName ] << curName;
845988
}
846989

990+
gettimeofday( &tv2, 0 );
991+
QgsDebugMsg( QString( "done in %1.%2 seconds" ).arg( tv2.tv_sec - tv1.tv_sec
992+
).arg(( double )( tv2.tv_usec - tv2.tv_usec ) / 1000000.0 ) );
847993
return ( ! mCollections.isEmpty() );
848994
}
849995

‎src/core/symbology-ng/qgsvectorcolorrampv2.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,14 @@ class CORE_EXPORT QgsCptCityColorRampV2 : public QgsVectorColorRampV2
203203
/* bool isContinuous() const { return mContinuous; } */
204204
GradientType gradientType() const { return mGradientType; }
205205

206-
QString getFilename() const;
206+
QString fileName() const;
207207
bool loadFile( QString filename = "" );
208208

209-
static QString getBaseDir();
209+
QString copyingFileName() const;
210+
QMap< QString, QString > copyingInfo();
211+
QString descFileName() const;
212+
213+
static QString baseDir();
210214
static void setBaseDir( QString dirName ) { mBaseDir = dirName; }
211215
static bool loadSchemes( QString rootDir = "", bool reset = false );
212216
/** Is the minimal (free to distribute) set of schemes available?

‎src/gui/symbology-ng/qgscptcitycolorrampv2dialog.cpp

Lines changed: 251 additions & 79 deletions
Large diffs are not rendered by default.

‎src/gui/symbology-ng/qgscptcitycolorrampv2dialog.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,20 @@ class GUI_EXPORT QgsCptCityColorRampV2Dialog : public QDialog, private Ui::QgsCp
3737

3838
void on_treeWidget_currentItemChanged( QTreeWidgetItem * current, QTreeWidgetItem * previous );
3939
void on_treeWidget_itemExpanded( QTreeWidgetItem * item );
40-
void on_buttonGroupView_buttonClicked( QAbstractButton * button );
40+
/* void on_buttonGroupView_buttonClicked( QAbstractButton * button ); */
41+
void on_tabBar_currentChanged( int index );
42+
void on_pbtnLicenseDetails_pressed();
4143

4244
protected:
4345

4446
void updatePreview();
4547
QTreeWidgetItem* findPath( QString path );
4648
QTreeWidgetItem * makeCollectionItem( const QString& path );
4749
void makeSchemeItem( QTreeWidgetItem *item, const QString& path, const QString& schemeName );
50+
bool eventFilter( QObject *obj, QEvent *event );
4851

4952
QgsCptCityColorRampV2* mRamp;
53+
QString mCollection;
5054
};
5155

5256
#endif

‎src/gui/symbology-ng/qgsstylev2managerdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ QString QgsStyleV2ManagerDialog::addColorRampStatic( QWidget* parent, QgsStyleV2
346346
}
347347
else if ( rampType == tr( "cpt-city" ) )
348348
{
349-
QgsCptCityColorRampV2* cptCityRamp = new QgsCptCityColorRampV2();
349+
QgsCptCityColorRampV2* cptCityRamp = new QgsCptCityColorRampV2( "", "" );
350350
QgsCptCityColorRampV2Dialog dlg( cptCityRamp, parent );
351351
if ( !dlg.exec() )
352352
{

‎src/ui/qgscptcitycolorrampv2dialogbase.ui

Lines changed: 311 additions & 191 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.