QGIS API Documentation 3.99.0-Master (09f76ad7019)
Loading...
Searching...
No Matches
qgsalgorithmsavelog.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmsavelog.cpp
3 ---------------------
4 begin : March 2020
5 copyright : (C) 2020 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include "qgsalgorithmsavelog.h"
19
20#include <QString>
21#include <QTextStream>
22
23using namespace Qt::StringLiterals;
24
26
27QString QgsSaveLogToFileAlgorithm::name() const
28{
29 return u"savelog"_s;
30}
31
32Qgis::ProcessingAlgorithmFlags QgsSaveLogToFileAlgorithm::flags() const
33{
35}
36
37QString QgsSaveLogToFileAlgorithm::displayName() const
38{
39 return QObject::tr( "Save log to file" );
40}
41
42QStringList QgsSaveLogToFileAlgorithm::tags() const
43{
44 return QObject::tr( "record,messages,logged" ).split( ',' );
45}
46
47QString QgsSaveLogToFileAlgorithm::group() const
48{
49 return QObject::tr( "Modeler tools" );
50}
51
52QString QgsSaveLogToFileAlgorithm::groupId() const
53{
54 return u"modelertools"_s;
55}
56
57QString QgsSaveLogToFileAlgorithm::shortHelpString() const
58{
59 return QObject::tr( "This algorithm saves the model's execution log to a file.\n"
60 "Optionally, the log can be saved in a HTML formatted version." );
61}
62
63QString QgsSaveLogToFileAlgorithm::shortDescription() const
64{
65 return QObject::tr( "Saves the model's log contents to a file." );
66}
67
68QgsSaveLogToFileAlgorithm *QgsSaveLogToFileAlgorithm::createInstance() const
69{
70 return new QgsSaveLogToFileAlgorithm();
71}
72
73void QgsSaveLogToFileAlgorithm::initAlgorithm( const QVariantMap & )
74{
75 addParameter( new QgsProcessingParameterFileDestination( u"OUTPUT"_s, QObject::tr( "Log file" ), QObject::tr( "Text files (*.txt);;HTML files (*.html *.HTML)" ) ) );
76 addParameter( new QgsProcessingParameterBoolean( u"USE_HTML"_s, QObject::tr( "Use HTML formatting" ), false ) );
77}
78
79QVariantMap QgsSaveLogToFileAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
80{
81 const QString file = parameterAsFile( parameters, u"OUTPUT"_s, context );
82 const bool useHtml = parameterAsBool( parameters, u"USE_HTML"_s, context );
83 if ( !file.isEmpty() )
84 {
85 QFile exportFile( file );
86 if ( !exportFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
87 {
88 throw QgsProcessingException( QObject::tr( "Could not save log to file %1" ).arg( file ) );
89 }
90 QTextStream fout( &exportFile );
91 fout << ( useHtml ? feedback->htmlLog() : feedback->textLog() );
92 }
93 QVariantMap res;
94 res.insert( u"OUTPUT"_s, file );
95 return res;
96}
97
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
Definition qgis.h:3680
@ HideFromToolbox
Algorithm should be hidden from the toolbox.
Definition qgis.h:3654
@ SkipGenericModelLogging
When running as part of a model, the generic algorithm setup and results logging should be skipped.
Definition qgis.h:3665
virtual Qgis::ProcessingAlgorithmFlags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
virtual QString textLog() const
Returns the plain text contents of the log, which contains all messages pushed to the feedback object...
virtual QString htmlLog() const
Returns the HTML formatted contents of the log, which contains all messages pushed to the feedback ob...
A boolean parameter for processing algorithms.
A generic file based destination parameter, for specifying the destination path for a file (non-map l...