QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 }
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
static QgsHistoryProviderRegistry * historyProviderRegistry()
Returns the global history provider registry, used for tracking history providers.
Definition: qgsgui.cpp:169
Encapsulates a history entry.
bool addEntries(const QList< QgsHistoryEntry > &entries, QgsHistoryProviderRegistry::HistoryEntryOptions options=QgsHistoryProviderRegistry::HistoryEntryOptions())
Adds a list of entries to the history logs.
QString id() const override
Returns the provider's unique id, which is used to associate existing history entries with the provid...
void portOldLog()
Ports the old text log to the history framework.