22 #include <QFileInfoList>
28 qDeleteAll( mColorSchemeList );
29 mColorSchemeList.clear();
38 QList< QgsColorScheme * >::iterator it = schemeList.begin();
39 for ( ; it != schemeList.end(); ++it )
57 if ( QFileInfo::exists( stylePalette ) )
70 if ( !localDir.mkpath( palettesDir ) )
75 QFileInfoList fileInfoList = QDir( palettesDir ).entryInfoList( QStringList( QStringLiteral(
"*.gpl" ) ), QDir::Files );
76 QFileInfoList::const_iterator infoIt = fileInfoList.constBegin();
77 for ( ; infoIt != fileInfoList.constEnd(); ++infoIt )
85 mColorSchemeList.append( scheme );
90 QList< QgsColorScheme * > allSchemes;
91 QList<QgsColorScheme *>::const_iterator schemeIt;
92 for ( schemeIt = mColorSchemeList.constBegin(); schemeIt != mColorSchemeList.constEnd(); ++schemeIt )
94 allSchemes.append( ( *schemeIt ) );
101 QList< QgsColorScheme * > matchingSchemes;
102 QList<QgsColorScheme *>::const_iterator schemeIt;
103 for ( schemeIt = mColorSchemeList.constBegin(); schemeIt != mColorSchemeList.constEnd(); ++schemeIt )
105 if ( ( *schemeIt )->flags().testFlag( flag ) )
107 matchingSchemes.append( ( *schemeIt ) );
110 return matchingSchemes;
115 mRandomStyleColorScheme = scheme;
120 if ( mRandomStyleColors.count() > 0 )
122 std::random_device rd;
123 std::mt19937 mt( rd() );
124 std::uniform_int_distribution<int> colorDist( 0, mRandomStyleColors.count() - 1 );
125 mNextRandomStyleColorIndex = colorDist( mt );
126 std::uniform_int_distribution<int> colorDir( 0, 1 );
127 mNextRandomStyleColorDirection = colorDir( mt ) == 0 ? -1 : 1;
132 mRandomStyleColors.clear();
138 return mRandomStyleColorScheme;
143 if ( mRandomStyleColors.empty() )
148 std::random_device rd;
149 std::mt19937 mt( rd() );
150 std::uniform_int_distribution<int> hueDist( 0, 359 );
151 std::uniform_int_distribution<int> satDist( 64, 255 );
152 std::uniform_int_distribution<int> valueDist( 128, 255 );
153 return QColor::fromHsv( hueDist( mt ), satDist( mt ), valueDist( mt ) );
157 static QMutex sMutex;
158 QMutexLocker locker( &sMutex );
159 QColor res = mRandomStyleColors.at( mNextRandomStyleColorIndex ).first;
160 mNextRandomStyleColorIndex += mNextRandomStyleColorDirection;
161 if ( mNextRandomStyleColorIndex < 0 )
162 mNextRandomStyleColorIndex = mRandomStyleColors.count() - 1;
163 if ( mNextRandomStyleColorIndex >= mRandomStyleColors.count() )
164 mNextRandomStyleColorIndex = 0;
171 if ( mRandomStyleColorScheme == scheme )
173 mRandomStyleColorScheme =
nullptr;
174 mRandomStyleColors.clear();
177 if ( mColorSchemeList.indexOf( scheme ) != -1 )
179 mColorSchemeList.removeAll( scheme );