32 QFile inputFile( path );
33 if ( !inputFile.open( QFile::ReadOnly ) )
35 errors.append( QObject::tr(
"Read access denied. Adjust the file permissions and try again.\n\n" ) );
41 QTextStream inputStream( &inputFile );
43 const thread_local QRegularExpression itemRegex( QStringLiteral(
"^(.+?),(.+?),(.+?),(.+?),(.+?),(.+)$" ) );
46 while ( !inputStream.atEnd() )
49 const QString inputLine = inputStream.readLine();
50 if ( !inputLine.isEmpty() )
52 if ( !inputLine.simplified().startsWith(
'#' ) )
54 if ( inputLine.contains( QLatin1String(
"INTERPOLATION" ), Qt::CaseInsensitive ) )
56 QStringList inputStringComponents = inputLine.split(
':' );
57 if ( inputStringComponents.size() == 2 )
59 if ( inputStringComponents[1].trimmed().toUpper().compare( QLatin1String(
"INTERPOLATED" ), Qt::CaseInsensitive ) == 0 )
63 else if ( inputStringComponents[1].trimmed().toUpper().compare( QLatin1String(
"DISCRETE" ), Qt::CaseInsensitive ) == 0 )
75 errors << QObject::tr(
"Unknown interpolation type at line %1: %2" ).arg( lineCounter ).arg( inputLine );
80 const QRegularExpressionMatch match = itemRegex.match( inputLine );
81 if ( match.hasMatch() )
84 QColor::fromRgb( match.captured( 2 ).toInt(), match.captured( 3 ).toInt(), match.captured( 4 ).toInt(), match.captured( 5 ).toInt() ),
85 match.captured( 6 ) );
86 items.push_back( currentItem );
91 errors << QObject::tr(
"Invalid entry at line %1: %2" ).arg( lineCounter ).arg( inputLine );
104 QFile outputFile( path );
105 if ( outputFile.open( QFile::WriteOnly | QIODevice::Truncate ) )
107 QTextStream outputStream( &outputFile );
108 outputStream <<
"# " << QObject::tr(
"QGIS Generated Color Map Export File" ) <<
'\n';
109 outputStream <<
"INTERPOLATION:";
113 outputStream <<
"INTERPOLATED\n";
116 outputStream <<
"DISCRETE\n";
119 outputStream <<
"EXACT\n";
127 outputStream << item.color.red() <<
',' << item.color.green() <<
',' << item.color.blue() <<
',' << item.color.alpha() <<
',';
128 if ( item.label.isEmpty() )
130 outputStream <<
"Color entry " << i + 1 <<
'\n';
134 outputStream << item.label <<
'\n';
138 outputStream.flush();
static bool saveColorMapFile(const QString &path, const QList< QgsColorRampShader::ColorRampItem > &items, Qgis::ShaderInterpolationMethod type)
Exports a list of color ramp items and ramp shader type to a color map file at the specified path.
static bool parseColorMapFile(const QString &path, QList< QgsColorRampShader::ColorRampItem > &items, Qgis::ShaderInterpolationMethod &type, QStringList &errors)
Parses an exported color map file at the specified path and extracts the stored color ramp items and ...