QGIS API Documentation 3.99.0-Master (357b655ed83)
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 <QString>
21
22#include "moc_qgsprocessingrecentalgorithmlog.cpp"
23
24using namespace Qt::StringLiterals;
25
27
28const int MAX_LOG_LENGTH = 5;
29
30QgsProcessingRecentAlgorithmLog::QgsProcessingRecentAlgorithmLog( QObject *parent )
31 : QObject( parent )
32{
33 const QgsSettings settings;
34 mRecentAlgorithmIds = settings.value( u"processing/recentAlgorithms"_s, QVariant(), QgsSettings::Gui ).toStringList();
35}
36
37QStringList QgsProcessingRecentAlgorithmLog::recentAlgorithmIds() const
38{
39 return mRecentAlgorithmIds;
40}
41
42void QgsProcessingRecentAlgorithmLog::push( const QString &id )
43{
44 const QStringList previous = mRecentAlgorithmIds;
45 mRecentAlgorithmIds.removeAll( id );
46 mRecentAlgorithmIds.insert( 0, id );
47 if ( mRecentAlgorithmIds.length() > MAX_LOG_LENGTH )
48 mRecentAlgorithmIds = mRecentAlgorithmIds.mid( 0, MAX_LOG_LENGTH );
49
50 QgsSettings settings;
51 settings.setValue( u"processing/recentAlgorithms"_s, mRecentAlgorithmIds, QgsSettings::Gui );
52
53 if ( previous != mRecentAlgorithmIds )
54 emit changed();
55}
56
Stores settings for use within QGIS.
Definition qgssettings.h:68
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.