QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsprocessingrecentalgorithmlog.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprocessingrecentalgorithmlog.cpp
3 ------------------------------------
4 Date : July 2018
5 Copyright : (C) 2018 Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17
18#include "qgssettings.h"
19
20#include "moc_qgsprocessingrecentalgorithmlog.cpp"
21
23
24const int MAX_LOG_LENGTH = 5;
25
26QgsProcessingRecentAlgorithmLog::QgsProcessingRecentAlgorithmLog( QObject *parent )
27 : QObject( parent )
28{
29 const QgsSettings settings;
30 mRecentAlgorithmIds = settings.value( QStringLiteral( "processing/recentAlgorithms" ), QVariant(), QgsSettings::Gui ).toStringList();
31}
32
33QStringList QgsProcessingRecentAlgorithmLog::recentAlgorithmIds() const
34{
35 return mRecentAlgorithmIds;
36}
37
38void QgsProcessingRecentAlgorithmLog::push( const QString &id )
39{
40 const QStringList previous = mRecentAlgorithmIds;
41 mRecentAlgorithmIds.removeAll( id );
42 mRecentAlgorithmIds.insert( 0, id );
43 if ( mRecentAlgorithmIds.length() > MAX_LOG_LENGTH )
44 mRecentAlgorithmIds = mRecentAlgorithmIds.mid( 0, MAX_LOG_LENGTH );
45
46 QgsSettings settings;
47 settings.setValue( QStringLiteral( "processing/recentAlgorithms" ), mRecentAlgorithmIds, QgsSettings::Gui );
48
49 if ( previous != mRecentAlgorithmIds )
50 emit changed();
51}
52
Stores settings for use within QGIS.
Definition qgssettings.h:65
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.