Skip to content

Commit 66e6820

Browse files
committed
Be a bit more forgiving when reading gpl files which don't exactly follow the specifications
1 parent 35e3eac commit 66e6820

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/core/symbology-ng/qgssymbollayerv2utils.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <QIcon>
3838
#include <QPainter>
3939
#include <QSettings>
40+
#include <QRegExp>
4041

4142
QString QgsSymbolLayerV2Utils::encodeColor( QColor color )
4243
{
@@ -3066,22 +3067,29 @@ QgsNamedColorList QgsSymbolLayerV2Utils::importColorsFromGpl( QFile &file, bool
30663067
while ( !in.atEnd() )
30673068
{
30683069
line = in.readLine();
3069-
QStringList parts = line.simplified().split( " " );
3070-
if ( parts.length() < 3 )
3070+
QRegExp rx( "^\\s*(\\d+)\\s+(\\d+)\\s+(\\d+)(\\s.*)?$" );
3071+
if ( rx.indexIn( line ) == -1 )
30713072
{
30723073
continue;
30733074
}
3074-
int red = parts.at( 0 ).toInt();
3075-
int green = parts.at( 1 ).toInt();
3076-
int blue = parts.at( 2 ).toInt();
3075+
int red = rx.cap( 1 ).toInt();
3076+
int green = rx.cap( 2 ).toInt();
3077+
int blue = rx.cap( 3 ).toInt();
30773078
QColor color = QColor( red, green, blue );
3079+
if ( !color.isValid() )
3080+
{
3081+
continue;
3082+
}
30783083

30793084
//try to read color name
30803085
QString label;
3081-
parts = line.split( "\t" );
3082-
if ( parts.length() > 1 )
3086+
if ( rx.captureCount() > 3 )
3087+
{
3088+
label = rx.cap( 4 ).simplified();
3089+
}
3090+
else
30833091
{
3084-
label = parts.at( parts.length() - 1 );
3092+
label = colorToName( color );
30853093
}
30863094

30873095
importedColors << qMakePair( color, label );

0 commit comments

Comments
 (0)