QGIS API Documentation  3.21.0-Master (5b68dc587e)
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 
21 const int MAX_LOG_LENGTH = 5;
22 
23 QgsProcessingRecentAlgorithmLog::QgsProcessingRecentAlgorithmLog( QObject *parent )
24  : QObject( parent )
25 {
26  const QgsSettings settings;
27  mRecentAlgorithmIds = settings.value( QStringLiteral( "processing/recentAlgorithms" ), QVariant(), QgsSettings::Gui ).toStringList();
28 }
29 
30 QStringList QgsProcessingRecentAlgorithmLog::recentAlgorithmIds() const
31 {
32  return mRecentAlgorithmIds;
33 }
34 
35 void 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