QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 <QTextStream>
21
23
24QString QgsSaveLogToFileAlgorithm::name() const
25{
26 return QStringLiteral( "savelog" );
27}
28
29Qgis::ProcessingAlgorithmFlags QgsSaveLogToFileAlgorithm::flags() const
30{
32}
33
34QString QgsSaveLogToFileAlgorithm::displayName() const
35{
36 return QObject::tr( "Save log to file" );
37}
38
39QStringList QgsSaveLogToFileAlgorithm::tags() const
40{
41 return QObject::tr( "record,messages,logged" ).split( ',' );
42}
43
44QString QgsSaveLogToFileAlgorithm::group() const
45{
46 return QObject::tr( "Modeler tools" );
47}
48
49QString QgsSaveLogToFileAlgorithm::groupId() const
50{
51 return QStringLiteral( "modelertools" );
52}
53
54QString QgsSaveLogToFileAlgorithm::shortHelpString() const
55{
56 return QObject::tr( "This algorithm saves the model's execution log to a file.\n"
57 "Optionally, the log can be saved in a HTML formatted version." );
58}
59
60QString QgsSaveLogToFileAlgorithm::shortDescription() const
61{
62 return QObject::tr( "Saves the model's log contents to a file." );
63}
64
65QgsSaveLogToFileAlgorithm *QgsSaveLogToFileAlgorithm::createInstance() const
66{
67 return new QgsSaveLogToFileAlgorithm();
68}
69
70void QgsSaveLogToFileAlgorithm::initAlgorithm( const QVariantMap & )
71{
72 addParameter( new QgsProcessingParameterFileDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Log file" ), QObject::tr( "Text files (*.txt);;HTML files (*.html *.HTML)" ) ) );
73 addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "USE_HTML" ), QObject::tr( "Use HTML formatting" ), false ) );
74}
75
76QVariantMap QgsSaveLogToFileAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
77{
78 const QString file = parameterAsFile( parameters, QStringLiteral( "OUTPUT" ), context );
79 const bool useHtml = parameterAsBool( parameters, QStringLiteral( "USE_HTML" ), context );
80 if ( !file.isEmpty() )
81 {
82 QFile exportFile( file );
83 if ( !exportFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
84 {
85 throw QgsProcessingException( QObject::tr( "Could not save log to file %1" ).arg( file ) );
86 }
87 QTextStream fout( &exportFile );
88#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
89 fout.setCodec( "UTF-8" );
90#endif
91 fout << ( useHtml ? feedback->htmlLog() : feedback->textLog() );
92 }
93 QVariantMap res;
94 res.insert( QStringLiteral( "OUTPUT" ), 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:3609
@ HideFromToolbox
Algorithm should be hidden from the toolbox.
Definition qgis.h:3583
@ SkipGenericModelLogging
When running as part of a model, the generic algorithm setup and results logging should be skipped.
Definition qgis.h:3594
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...