Skip to content

Commit

Permalink
Be a bit more forgiving when reading gpl files which don't exactly fo…
Browse files Browse the repository at this point in the history
…llow the specifications
  • Loading branch information
nyalldawson committed Sep 17, 2014
1 parent 35e3eac commit 66e6820
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Expand Up @@ -37,6 +37,7 @@
#include <QIcon>
#include <QPainter>
#include <QSettings>
#include <QRegExp>

QString QgsSymbolLayerV2Utils::encodeColor( QColor color )
{
Expand Down Expand Up @@ -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 = rx.cap( 4 ).simplified();
}
else
{
label = parts.at( parts.length() - 1 );
label = colorToName( color );
}

importedColors << qMakePair( color, label );
Expand Down

0 comments on commit 66e6820

Please sign in to comment.