49 QList< QVariant > recentColorVariants = settings.
value( QStringLiteral(
"colors/recent" ) ).toList();
53 const auto constRecentColorVariants = recentColorVariants;
54 for (
const QVariant &color : constRecentColorVariants )
68 if ( !color.isValid() )
74 QColor opaqueColor = color;
75 opaqueColor.setAlpha( 255 );
78 QList< QVariant > recentColorVariants = settings.
value( QStringLiteral(
"colors/recent" ) ).toList();
81 for (
int colorIdx = recentColorVariants.length() - 1; colorIdx >= 0; --colorIdx )
83 if ( ( recentColorVariants.at( colorIdx ).value<QColor>() ).name() == opaqueColor.name() )
85 recentColorVariants.removeAt( colorIdx );
90 QVariant colorVariant = QVariant( opaqueColor );
91 recentColorVariants.prepend( colorVariant );
94 while ( recentColorVariants.count() > 20 )
96 recentColorVariants.pop_back();
99 settings.
setValue( QStringLiteral(
"colors/recent" ), recentColorVariants );
106 QList< QVariant > recentColorVariants = settings.
value( QStringLiteral(
"colors/recent" ) ).toList();
108 if ( recentColorVariants.isEmpty() )
111 return recentColorVariants.at( 0 ).value<QColor>();
117 Q_UNUSED( baseColor )
124 if ( !settings.
contains( QStringLiteral(
"/colors/palettecolors" ) ) )
127 colorList.append( qMakePair( QColor( 0, 0, 0 ), QString() ) );
128 colorList.append( qMakePair( QColor( 255, 255, 255 ), QString() ) );
129 colorList.append( qMakePair( QColor( 166, 206, 227 ), QString() ) );
130 colorList.append( qMakePair( QColor( 31, 120, 180 ), QString() ) );
131 colorList.append( qMakePair( QColor( 178, 223, 138 ), QString() ) );
132 colorList.append( qMakePair( QColor( 51, 160, 44 ), QString() ) );
133 colorList.append( qMakePair( QColor( 251, 154, 153 ), QString() ) );
134 colorList.append( qMakePair( QColor( 227, 26, 28 ), QString() ) );
135 colorList.append( qMakePair( QColor( 253, 191, 111 ), QString() ) );
136 colorList.append( qMakePair( QColor( 255, 127, 0 ), QString() ) );
141 QList< QVariant > customColorVariants = settings.
value( QStringLiteral(
"colors/palettecolors" ) ).toList();
142 QList< QVariant > customColorLabels = settings.
value( QStringLiteral(
"colors/palettelabels" ) ).toList();
146 for ( QList< QVariant >::iterator it = customColorVariants.begin();
147 it != customColorVariants.end(); ++it )
149 QColor color = ( *it ).value<QColor>();
151 if ( customColorLabels.length() > colorIndex )
153 label = customColorLabels.at( colorIndex ).toString();
156 colorList.append( qMakePair( color, label ) );
166 Q_UNUSED( baseColor )
170 QList< QVariant > customColors;
171 QList< QVariant > customColorLabels;
173 QgsNamedColorList::const_iterator colorIt = colors.constBegin();
174 for ( ; colorIt != colors.constEnd(); ++colorIt )
176 QVariant color = ( *colorIt ).first;
177 QVariant label = ( *colorIt ).second;
178 customColors.append( color );
179 customColorLabels.append( label );
181 settings.
setValue( QStringLiteral(
"colors/palettecolors" ), customColors );
182 settings.
setValue( QStringLiteral(
"colors/palettelabels" ), customColorLabels );
195 Q_UNUSED( baseColor )
204 for ( QStringList::iterator it = colorStrings.begin();
205 it != colorStrings.end(); ++it )
209 if ( colorLabels.length() > colorIndex )
211 label = colorLabels.at( colorIndex );
214 colorList.append( qMakePair( color, label ) );
224 Q_UNUSED( baseColor )
242 Q_UNUSED( baseColor )
245 if ( sourceFilePath.isEmpty() )
253 QFile sourceFile( sourceFilePath );
260 Q_UNUSED( baseColor )
263 if ( destFilePath.isEmpty() )
268 QFile destFile( destFilePath );
290 : mFilename( filename )
295 if ( sourceFile.open( QIODevice::ReadOnly ) )
297 QTextStream in( &sourceFile );
301 while ( !in.atEnd() && !line.startsWith( QLatin1String(
"Name:" ) ) )
303 line = in.readLine();
307 QRegExp rx(
"Name:\\s*(\\S.*)$" );
308 if ( rx.indexIn( line ) != -1 )
314 if (
mName.isEmpty() )
323 mEditable = !sourceFileInfo.exists() || sourceFileInfo.isWritable();
341 QStringList showInMenuSchemes = s.
value( QStringLiteral(
"/colors/showInMenuList" ) ).toStringList();
343 if ( showInMenuSchemes.contains(
mName ) )
354 if ( filePath.isEmpty() )
360 if ( ! QFile::exists( filePath ) )
366 return QFile::remove( filePath );
372 QStringList showInMenuSchemes = s.
value( QStringLiteral(
"/colors/showInMenuList" ) ).toStringList();
374 if ( show && !showInMenuSchemes.contains(
mName ) )
376 showInMenuSchemes <<
mName;
378 else if ( !show && showInMenuSchemes.contains(
mName ) )
380 showInMenuSchemes.removeAll(
mName );
383 s.
setValue( QStringLiteral(
"/colors/showInMenuList" ), showInMenuSchemes );
391 if ( !localDir.mkpath( palettesDir ) )
396 return QDir( palettesDir ).filePath(
mFilename );