From 66e6820ba15aeae43eed9cc0edbc2f1d3f4bdacb Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 17 Sep 2014 21:09:49 +1000 Subject: [PATCH] Be a bit more forgiving when reading gpl files which don't exactly follow the specifications --- .../symbology-ng/qgssymbollayerv2utils.cpp | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/core/symbology-ng/qgssymbollayerv2utils.cpp b/src/core/symbology-ng/qgssymbollayerv2utils.cpp index 2878dff363b..8b89cd12a84 100644 --- a/src/core/symbology-ng/qgssymbollayerv2utils.cpp +++ b/src/core/symbology-ng/qgssymbollayerv2utils.cpp @@ -37,6 +37,7 @@ #include #include #include +#include QString QgsSymbolLayerV2Utils::encodeColor( QColor color ) { @@ -3066,22 +3067,29 @@ QgsNamedColorList QgsSymbolLayerV2Utils::importColorsFromGpl( QFile &file, bool while ( !in.atEnd() ) { line = in.readLine(); - QStringList parts = line.simplified().split( " " ); - if ( parts.length() < 3 ) + QRegExp rx( "^\\s*(\\d+)\\s+(\\d+)\\s+(\\d+)(\\s.*)?$" ); + if ( rx.indexIn( line ) == -1 ) { continue; } - int red = parts.at( 0 ).toInt(); - int green = parts.at( 1 ).toInt(); - int blue = parts.at( 2 ).toInt(); + int red = rx.cap( 1 ).toInt(); + int green = rx.cap( 2 ).toInt(); + int blue = rx.cap( 3 ).toInt(); QColor color = QColor( red, green, blue ); + if ( !color.isValid() ) + { + continue; + } //try to read color name QString label; - parts = line.split( "\t" ); - if ( parts.length() > 1 ) + if ( rx.captureCount() > 3 ) { - label = parts.at( parts.length() - 1 ); + label = rx.cap( 4 ).simplified(); + } + else + { + label = colorToName( color ); } importedColors << qMakePair( color, label );