@@ -1003,6 +1003,9 @@ bool QgsCptCityCollection::loadSchemes( QString rootDir, bool reset )
1003
1003
foreach ( QString path, mDirNames )
1004
1004
{
1005
1005
// 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 ;
1006
1009
QString filename = baseDir () + QDir::separator () + path + QDir::separator () + " DESC.xml" ;
1007
1010
QFile f ( filename );
1008
1011
if ( ! f.open ( QFile::ReadOnly ) )
@@ -1040,29 +1043,74 @@ bool QgsCptCityCollection::loadSchemes( QString rootDir, bool reset )
1040
1043
// add info to mapping
1041
1044
mDirNamesMap [ path ] = nameElement.text ();
1042
1045
}
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
- }
1048
1046
1049
1047
// 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 ) )
1057
1051
{
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 ) )
1060
1057
{
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 ();
1064
1113
}
1065
- mSelectionsMap [ viewName ] << curName;
1066
1114
}
1067
1115
1068
1116
QgsDebugMsg ( QString ( " done in %1 seconds" ).arg ( time .elapsed () / 1000.0 ) );
0 commit comments