QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsprocessinghistoryprovider.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsprocessinghistoryprovider.cpp
3  -------------------------
4  begin : December 2021
5  copyright : (C) 2021 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
18 #include "qgsapplication.h"
19 #include "qgsgui.h"
21 #include "qgssettings.h"
22 
23 #include <QFile>
24 #include <QTextStream>
25 #include <QRegularExpression>
26 #include <QRegularExpressionMatch>
27 
29 {
30 }
31 
33 {
34  return QStringLiteral( "processing" );
35 }
36 
38 {
39  const QString logPath = oldLogPath();
40  if ( !QFile::exists( logPath ) )
41  return;
42 
43  QFile logFile( logPath );
44  if ( logFile.open( QIODevice::ReadOnly ) )
45  {
46  QTextStream in( &logFile );
47  QList< QgsHistoryEntry > entries;
48  while ( !in.atEnd() )
49  {
50  const QString line = in.readLine().trimmed();
51  QStringList parts = line.split( QStringLiteral( "|~|" ) );
52  if ( parts.size() <= 1 )
53  parts = line.split( '|' );
54 
55  if ( parts.size() == 3 && parts.at( 0 ).startsWith( QLatin1String( "ALGORITHM" ), Qt::CaseInsensitive ) )
56  {
57  QVariantMap details;
58  details.insert( QStringLiteral( "python_command" ), parts.at( 2 ) );
59 
60  const thread_local QRegularExpression algIdRegEx( QStringLiteral( "processing\\.run\\(\"(.*?)\"" ) );
61  const QRegularExpressionMatch match = algIdRegEx.match( parts.at( 2 ) );
62  if ( match.hasMatch() )
63  details.insert( QStringLiteral( "algorithm_id" ), match.captured( 1 ) );
64 
65  entries.append( QgsHistoryEntry( id(),
66  QDateTime::fromString( parts.at( 1 ), QStringLiteral( "yyyy-MM-d hh:mm:ss" ) ),
67  details ) );
68  }
69  }
70 
72  }
73 }
74 
75 QString QgsProcessingHistoryProvider::oldLogPath() const
76 {
77  const QString userDir = QgsApplication::qgisSettingsDirPath() + QStringLiteral( "/processing" );
78  return userDir + QStringLiteral( "/processing.log" );
79 }
QgsProcessingHistoryProvider::QgsProcessingHistoryProvider
QgsProcessingHistoryProvider()
Definition: qgsprocessinghistoryprovider.cpp:28
qgsgui.h
QgsHistoryEntry
Encapsulates a history entry.
Definition: qgshistoryproviderregistry.h:40
QgsProcessingHistoryProvider::id
QString id() const override
Returns the provider's unique id, which is used to associate existing history entries with the provid...
Definition: qgsprocessinghistoryprovider.cpp:32
qgsapplication.h
QgsApplication::qgisSettingsDirPath
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
Definition: qgsapplication.cpp:1099
QgsProcessingHistoryProvider::portOldLog
void portOldLog()
Ports the old text log to the history framework.
Definition: qgsprocessinghistoryprovider.cpp:37
qgssettings.h
qgsprocessinghistoryprovider.h
QgsHistoryProviderRegistry::addEntries
bool addEntries(const QList< QgsHistoryEntry > &entries, QgsHistoryProviderRegistry::HistoryEntryOptions options=QgsHistoryProviderRegistry::HistoryEntryOptions())
Adds a list of entries to the history logs.
Definition: qgshistoryproviderregistry.cpp:144
QgsGui::historyProviderRegistry
static QgsHistoryProviderRegistry * historyProviderRegistry()
Returns the global history provider registry, used for tracking history providers.
Definition: qgsgui.cpp:175
qgshistoryproviderregistry.h