QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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#include "qgssettings.h"
18
20
21const int MAX_LOG_LENGTH = 5;
22
23QgsProcessingRecentAlgorithmLog::QgsProcessingRecentAlgorithmLog( QObject *parent )
24 : QObject( parent )
25{
26 const QgsSettings settings;
27 mRecentAlgorithmIds = settings.value( QStringLiteral( "processing/recentAlgorithms" ), QVariant(), QgsSettings::Gui ).toStringList();
28}
29
30QStringList QgsProcessingRecentAlgorithmLog::recentAlgorithmIds() const
31{
32 return mRecentAlgorithmIds;
33}
34
35void QgsProcessingRecentAlgorithmLog::push( const QString &id )
36{
37 const QStringList previous = mRecentAlgorithmIds;
38 mRecentAlgorithmIds.removeAll( id );
39 mRecentAlgorithmIds.insert( 0, id );
40 if ( mRecentAlgorithmIds.length() > MAX_LOG_LENGTH )
41 mRecentAlgorithmIds = mRecentAlgorithmIds.mid( 0, MAX_LOG_LENGTH );
42
43 QgsSettings settings;
44 settings.setValue( QStringLiteral( "processing/recentAlgorithms" ), mRecentAlgorithmIds, QgsSettings::Gui );
45
46 if ( previous != mRecentAlgorithmIds )
47 emit changed();
48}
49
This class is a composition of two QSettings instances:
Definition: qgssettings.h:64
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.