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