27 #include <QRegularExpression>
28 #include <QTextStream>
51 const QList< QVariant > recentColorVariants = settings.
value( QStringLiteral(
"colors/recent" ) ).toList();
55 const auto constRecentColorVariants = recentColorVariants;
56 for (
const QVariant &color : constRecentColorVariants )
70 if ( !color.isValid() )
76 QColor opaqueColor = color;
77 opaqueColor.setAlpha( 255 );
80 QList< QVariant > recentColorVariants = settings.
value( QStringLiteral(
"colors/recent" ) ).toList();
83 for (
int colorIdx = recentColorVariants.length() - 1; colorIdx >= 0; --colorIdx )
85 if ( ( recentColorVariants.at( colorIdx ).value<QColor>() ).name() == opaqueColor.name() )
87 recentColorVariants.removeAt( colorIdx );
92 const QVariant colorVariant = QVariant( opaqueColor );
93 recentColorVariants.prepend( colorVariant );
96 while ( recentColorVariants.count() > 20 )
98 recentColorVariants.pop_back();
101 settings.
setValue( QStringLiteral(
"colors/recent" ), recentColorVariants );
108 const QList< QVariant > recentColorVariants = settings.
value( QStringLiteral(
"colors/recent" ) ).toList();
110 if ( recentColorVariants.isEmpty() )
113 return recentColorVariants.at( 0 ).value<QColor>();
119 Q_UNUSED( baseColor )
126 if ( !settings.
contains( QStringLiteral(
"/colors/palettecolors" ) ) )
129 colorList.append( qMakePair( QColor( 0, 0, 0 ), QString() ) );
130 colorList.append( qMakePair( QColor( 255, 255, 255 ), QString() ) );
131 colorList.append( qMakePair( QColor( 166, 206, 227 ), QString() ) );
132 colorList.append( qMakePair( QColor( 31, 120, 180 ), QString() ) );
133 colorList.append( qMakePair( QColor( 178, 223, 138 ), QString() ) );
134 colorList.append( qMakePair( QColor( 51, 160, 44 ), QString() ) );
135 colorList.append( qMakePair( QColor( 251, 154, 153 ), QString() ) );
136 colorList.append( qMakePair( QColor( 227, 26, 28 ), QString() ) );
137 colorList.append( qMakePair( QColor( 253, 191, 111 ), QString() ) );
138 colorList.append( qMakePair( QColor( 255, 127, 0 ), QString() ) );
143 QList< QVariant > customColorVariants = settings.
value( QStringLiteral(
"colors/palettecolors" ) ).toList();
144 const QList< QVariant > customColorLabels = settings.
value( QStringLiteral(
"colors/palettelabels" ) ).toList();
148 for ( QList< QVariant >::iterator it = customColorVariants.begin();
149 it != customColorVariants.end(); ++it )
151 const QColor color = ( *it ).value<QColor>();
153 if ( customColorLabels.length() > colorIndex )
155 label = customColorLabels.at( colorIndex ).toString();
158 colorList.append( qMakePair( color, label ) );
168 Q_UNUSED( baseColor )
172 QList< QVariant > customColors;
173 QList< QVariant > customColorLabels;
175 QgsNamedColorList::const_iterator colorIt = colors.constBegin();
176 for ( ; colorIt != colors.constEnd(); ++colorIt )
178 const QVariant color = ( *colorIt ).first;
179 const QVariant label = ( *colorIt ).second;
180 customColors.append( color );
181 customColorLabels.append( label );
183 settings.
setValue( QStringLiteral(
"colors/palettecolors" ), customColors );
184 settings.
setValue( QStringLiteral(
"colors/palettelabels" ), customColorLabels );
197 Q_UNUSED( baseColor )
206 for ( QStringList::iterator it = colorStrings.begin();
207 it != colorStrings.end(); ++it )
211 if ( colorLabels.length() > colorIndex )
213 label = colorLabels.at( colorIndex );
216 colorList.append( qMakePair( color, label ) );
226 Q_UNUSED( baseColor )
244 Q_UNUSED( baseColor )
247 if ( sourceFilePath.isEmpty() )
255 QFile sourceFile( sourceFilePath );
262 Q_UNUSED( baseColor )
265 if ( destFilePath.isEmpty() )
270 QFile destFile( destFilePath );
292 : mFilename( filename )
297 if ( sourceFile.open( QIODevice::ReadOnly ) )
299 QTextStream in( &sourceFile );
303 while ( !in.atEnd() && !line.startsWith( QLatin1String(
"Name:" ) ) )
305 line = in.readLine();
309 const QRegularExpression rx(
"Name:\\s*(\\S.*)$" );
310 const QRegularExpressionMatch match = rx.match( line );
311 if ( match.hasMatch() )
313 mName = match.captured( 1 );
317 if (
mName.isEmpty() )
326 mEditable = !sourceFileInfo.exists() || sourceFileInfo.isWritable();
344 const QStringList showInMenuSchemes = s.
value( QStringLiteral(
"/colors/showInMenuList" ) ).toStringList();
346 if ( showInMenuSchemes.contains(
mName ) )
357 if ( filePath.isEmpty() )
363 if ( ! QFile::exists( filePath ) )
369 return QFile::remove( filePath );
375 QStringList showInMenuSchemes = s.
value( QStringLiteral(
"/colors/showInMenuList" ) ).toStringList();
377 if ( show && !showInMenuSchemes.contains(
mName ) )
379 showInMenuSchemes <<
mName;
381 else if ( !show && showInMenuSchemes.contains(
mName ) )
383 showInMenuSchemes.removeAll(
mName );
386 s.
setValue( QStringLiteral(
"/colors/showInMenuList" ), showInMenuSchemes );
394 if ( !localDir.mkpath( palettesDir ) )
399 return QDir( palettesDir ).filePath(
mFilename );