Skip to content

Commit

Permalink
use selections from .xml files
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennesky committed Aug 24, 2012
1 parent bae03b7 commit bcd1a70
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 22 deletions.
9 changes: 5 additions & 4 deletions src/core/symbology-ng/qgscolorrampv2data.h
Expand Up @@ -353,6 +353,9 @@ const char* brewerString =
"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"
"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";

#if 0
// not used anymore

/*
The following tables were taken from the cpt-city website http://soliton.vm.bytemark.co.uk/pub/cpt-city/
*/
Expand Down Expand Up @@ -382,7 +385,6 @@ If the author has not specified a licence then you do not have permission to dis
/* name mappings - by author*/
static const char* cptCityNames [] =
{
#if 0
// these defs are now in DESC.xml files
"bhw", "Art gradients by Blackheartedwolf",
"cb", "Colour schemes by Cynthia Brewer",
Expand Down Expand Up @@ -445,8 +447,8 @@ static const char* cptCityNames [] =
"vh", "Victor Huerfano's Caribbean DEM palette",
"wkp", "Wikipedia schemes",
"xkcd", "Bathymetry from XKCD 1040",
#endif
//views
// these defs are now in selection .xml files
"bath", "Palettes for bathymetry",
"blues", "A selection of blues",
"topo", "Palettes for topography",
Expand All @@ -459,12 +461,10 @@ static const char* cptCityNames [] =
"transparency", "Palettes with transparency",
"discord", "Gradients of discordance",
"popular", "The most popular palettes",
#if 0
//views/div
"jjg/cbcont/div", "continuous",
"jjg/cbac/div", "almost continuous",
"jjg/polarity", "polarity",
#endif
NULL, NULL
};

Expand Down Expand Up @@ -800,5 +800,6 @@ static const char* cptCitySelections [] =
"km/blue-yellow-d13",
NULL, NULL
};
#endif

#endif // QGSCOLORBREWERPALETTE_H
1 change: 1 addition & 0 deletions src/core/symbology-ng/qgscptcitybrowsermodel.cpp
Expand Up @@ -495,6 +495,7 @@ void QgsCptCityBrowserModel::addRootItems( )
QString info = mCollection->dirNamesMap().value( path );
QgsDebugMsg( "path= " + path + " info= " + info );
item = new QgsCptCityCategoryItem( NULL, path, path, info );
//TODO remove item if there are no children (e.g. esri in qgis-sel)
if ( item->isValid() )
mRootItems << item;
else
Expand Down
84 changes: 66 additions & 18 deletions src/core/symbology-ng/qgsvectorcolorrampv2.cpp
Expand Up @@ -1003,6 +1003,9 @@ bool QgsCptCityCollection::loadSchemes( QString rootDir, bool reset )
foreach ( QString path, mDirNames )
{
// TODO parse DESC.xml and COPYING.xml here, and add to CptCityCollection member
// skip "selections" dir which contains selections
if ( path == "selections" )
continue;
QString filename = baseDir() + QDir::separator() + path + QDir::separator() + "DESC.xml";
QFile f( filename );
if ( ! f.open( QFile::ReadOnly ) )
Expand Down Expand Up @@ -1040,29 +1043,74 @@ bool QgsCptCityCollection::loadSchemes( QString rootDir, bool reset )
// add info to mapping
mDirNamesMap[ path ] = nameElement.text();
}
// add any elements that are missing from DESC.xml (views)
for ( int i = 0; cptCityNames[i] != NULL; i = i + 2 )
{
mDirNamesMap[ cptCityNames[i] ] = cptCityNames[i+1];
}

// populate mSelections
QString viewName;
const char** selections;
if ( mCollectionName == DEFAULT_CPTCITY_COLLECTION )
selections = cptCitySelectionsMin;
else
selections = cptCitySelections;
for ( int i = 0; selections[i] != NULL; i++ )
QDir seldir( baseDir() + QDir::separator() + rootDir + QDir::separator() + "selections" );
QgsDebugMsg( "populating selection from " + seldir.path() );
foreach ( QString selfile, seldir.entryList( QStringList( "*.xml" ), QDir::Files ) )
{
curName = QString( selections[i] );
if ( curName == "" )
QString filename = seldir.path() + QDir::separator() + selfile;
QgsDebugMsg( "reading file " + filename );

QFile f( filename );
if ( ! f.open( QFile::ReadOnly ) )
{
viewName = QString( selections[i+1] );
curName = QString( selections[i+2] );
i = i + 2;
QgsDebugMsg( filename + " does not exist" );
continue;
}

// parse the document
QString errMsg;
QDomDocument doc( "selection" );
if ( !doc.setContent( &f, &errMsg ) )
{
f.close();
QgsDebugMsg( "Couldn't parse file " + filename + " : " + errMsg );
continue;
}
f.close();

// read description
QDomElement docElem = doc.documentElement();
if ( docElem.tagName() != "selection" )
{
QgsDebugMsg( "Incorrect root tag: " + docElem.tagName() );
continue;
}
QDomElement e = docElem.firstChildElement( "name" );
// QString selname = QFileInfo( selfile ).baseName();
QString selname = ( e.isNull() || e.text().isNull() ) ? QFileInfo( selfile ).baseName() : e.text();
QString description = docElem.firstChildElement( "description" ).text().simplified();
if ( description.endsWith( "." ) )
description.chop( 1 );
mDirNamesMap[ selname ] = description;

// get collections
QDomElement collectsElem = docElem.firstChildElement( "seealsocollects" );
e = collectsElem.firstChildElement( "collect" );
while ( ! e.isNull() )
{
if ( ! e.attribute( "dir" ).isNull() )
{
QgsDebugMsg( "add " + e.attribute( "dir" ) + "/ to " + selname );
// TODO parse description and use that, instead of default collection name
mSelectionsMap[ selname ] << e.attribute( "dir" ) + "/";
}
e = e.nextSiblingElement();
}
// get individual gradients
QDomElement gradientsElem = docElem.firstChildElement( "gradients" );
e = gradientsElem.firstChildElement( "gradient" );
while ( ! e.isNull() )
{
if ( ! e.attribute( "dir" ).isNull() )
{
QgsDebugMsg( "add " + e.attribute( "dir" ) + "/" + e.attribute( "file" ) + " to " + selname );
// TODO parse description and save elsewhere
mSelectionsMap[ selname ] << e.attribute( "dir" ) + "/" + e.attribute( "file" );
}
e = e.nextSiblingElement();
}
mSelectionsMap[ viewName ] << curName;
}

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

0 comments on commit bcd1a70

Please sign in to comment.