Skip to content

Commit bcd1a70

Browse files
committed
use selections from .xml files
1 parent bae03b7 commit bcd1a70

File tree

3 files changed

+72
-22
lines changed

3 files changed

+72
-22
lines changed

src/core/symbology-ng/qgscolorrampv2data.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ const char* brewerString =
353353
"PuBuGn-8-255,247,251 236,226,240 208,209,230 166,189,219 103,169,207 54,144,192 2,129,138 1,100,80\n"
354354
"PuBuGn-9-255,247,251 236,226,240 208,209,230 166,189,219 103,169,207 54,144,192 2,129,138 1,108,89 1,70,54";
355355

356+
#if 0
357+
// not used anymore
358+
356359
/*
357360
The following tables were taken from the cpt-city website http://soliton.vm.bytemark.co.uk/pub/cpt-city/
358361
*/
@@ -382,7 +385,6 @@ If the author has not specified a licence then you do not have permission to dis
382385
/* name mappings - by author*/
383386
static const char* cptCityNames [] =
384387
{
385-
#if 0
386388
// these defs are now in DESC.xml files
387389
"bhw", "Art gradients by Blackheartedwolf",
388390
"cb", "Colour schemes by Cynthia Brewer",
@@ -445,8 +447,8 @@ static const char* cptCityNames [] =
445447
"vh", "Victor Huerfano's Caribbean DEM palette",
446448
"wkp", "Wikipedia schemes",
447449
"xkcd", "Bathymetry from XKCD 1040",
448-
#endif
449450
//views
451+
// these defs are now in selection .xml files
450452
"bath", "Palettes for bathymetry",
451453
"blues", "A selection of blues",
452454
"topo", "Palettes for topography",
@@ -459,12 +461,10 @@ static const char* cptCityNames [] =
459461
"transparency", "Palettes with transparency",
460462
"discord", "Gradients of discordance",
461463
"popular", "The most popular palettes",
462-
#if 0
463464
//views/div
464465
"jjg/cbcont/div", "continuous",
465466
"jjg/cbac/div", "almost continuous",
466467
"jjg/polarity", "polarity",
467-
#endif
468468
NULL, NULL
469469
};
470470

@@ -800,5 +800,6 @@ static const char* cptCitySelections [] =
800800
"km/blue-yellow-d13",
801801
NULL, NULL
802802
};
803+
#endif
803804

804805
#endif // QGSCOLORBREWERPALETTE_H

src/core/symbology-ng/qgscptcitybrowsermodel.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ void QgsCptCityBrowserModel::addRootItems( )
495495
QString info = mCollection->dirNamesMap().value( path );
496496
QgsDebugMsg( "path= " + path + " info= " + info );
497497
item = new QgsCptCityCategoryItem( NULL, path, path, info );
498+
//TODO remove item if there are no children (e.g. esri in qgis-sel)
498499
if ( item->isValid() )
499500
mRootItems << item;
500501
else

src/core/symbology-ng/qgsvectorcolorrampv2.cpp

+66-18
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,9 @@ bool QgsCptCityCollection::loadSchemes( QString rootDir, bool reset )
10031003
foreach ( QString path, mDirNames )
10041004
{
10051005
// TODO parse DESC.xml and COPYING.xml here, and add to CptCityCollection member
1006+
// skip "selections" dir which contains selections
1007+
if ( path == "selections" )
1008+
continue;
10061009
QString filename = baseDir() + QDir::separator() + path + QDir::separator() + "DESC.xml";
10071010
QFile f( filename );
10081011
if ( ! f.open( QFile::ReadOnly ) )
@@ -1040,29 +1043,74 @@ bool QgsCptCityCollection::loadSchemes( QString rootDir, bool reset )
10401043
// add info to mapping
10411044
mDirNamesMap[ path ] = nameElement.text();
10421045
}
1043-
// add any elements that are missing from DESC.xml (views)
1044-
for ( int i = 0; cptCityNames[i] != NULL; i = i + 2 )
1045-
{
1046-
mDirNamesMap[ cptCityNames[i] ] = cptCityNames[i+1];
1047-
}
10481046

10491047
// populate mSelections
1050-
QString viewName;
1051-
const char** selections;
1052-
if ( mCollectionName == DEFAULT_CPTCITY_COLLECTION )
1053-
selections = cptCitySelectionsMin;
1054-
else
1055-
selections = cptCitySelections;
1056-
for ( int i = 0; selections[i] != NULL; i++ )
1048+
QDir seldir( baseDir() + QDir::separator() + rootDir + QDir::separator() + "selections" );
1049+
QgsDebugMsg( "populating selection from " + seldir.path() );
1050+
foreach ( QString selfile, seldir.entryList( QStringList( "*.xml" ), QDir::Files ) )
10571051
{
1058-
curName = QString( selections[i] );
1059-
if ( curName == "" )
1052+
QString filename = seldir.path() + QDir::separator() + selfile;
1053+
QgsDebugMsg( "reading file " + filename );
1054+
1055+
QFile f( filename );
1056+
if ( ! f.open( QFile::ReadOnly ) )
10601057
{
1061-
viewName = QString( selections[i+1] );
1062-
curName = QString( selections[i+2] );
1063-
i = i + 2;
1058+
QgsDebugMsg( filename + " does not exist" );
1059+
continue;
1060+
}
1061+
1062+
// parse the document
1063+
QString errMsg;
1064+
QDomDocument doc( "selection" );
1065+
if ( !doc.setContent( &f, &errMsg ) )
1066+
{
1067+
f.close();
1068+
QgsDebugMsg( "Couldn't parse file " + filename + " : " + errMsg );
1069+
continue;
1070+
}
1071+
f.close();
1072+
1073+
// read description
1074+
QDomElement docElem = doc.documentElement();
1075+
if ( docElem.tagName() != "selection" )
1076+
{
1077+
QgsDebugMsg( "Incorrect root tag: " + docElem.tagName() );
1078+
continue;
1079+
}
1080+
QDomElement e = docElem.firstChildElement( "name" );
1081+
// QString selname = QFileInfo( selfile ).baseName();
1082+
QString selname = ( e.isNull() || e.text().isNull() ) ? QFileInfo( selfile ).baseName() : e.text();
1083+
QString description = docElem.firstChildElement( "description" ).text().simplified();
1084+
if ( description.endsWith( "." ) )
1085+
description.chop( 1 );
1086+
mDirNamesMap[ selname ] = description;
1087+
1088+
// get collections
1089+
QDomElement collectsElem = docElem.firstChildElement( "seealsocollects" );
1090+
e = collectsElem.firstChildElement( "collect" );
1091+
while ( ! e.isNull() )
1092+
{
1093+
if ( ! e.attribute( "dir" ).isNull() )
1094+
{
1095+
QgsDebugMsg( "add " + e.attribute( "dir" ) + "/ to " + selname );
1096+
// TODO parse description and use that, instead of default collection name
1097+
mSelectionsMap[ selname ] << e.attribute( "dir" ) + "/";
1098+
}
1099+
e = e.nextSiblingElement();
1100+
}
1101+
// get individual gradients
1102+
QDomElement gradientsElem = docElem.firstChildElement( "gradients" );
1103+
e = gradientsElem.firstChildElement( "gradient" );
1104+
while ( ! e.isNull() )
1105+
{
1106+
if ( ! e.attribute( "dir" ).isNull() )
1107+
{
1108+
QgsDebugMsg( "add " + e.attribute( "dir" ) + "/" + e.attribute( "file" ) + " to " + selname );
1109+
// TODO parse description and save elsewhere
1110+
mSelectionsMap[ selname ] << e.attribute( "dir" ) + "/" + e.attribute( "file" );
1111+
}
1112+
e = e.nextSiblingElement();
10641113
}
1065-
mSelectionsMap[ viewName ] << curName;
10661114
}
10671115

10681116
QgsDebugMsg( QString( "done in %1 seconds" ).arg( time.elapsed() / 1000.0 ) );

0 commit comments

Comments
 (0)