QGIS API Documentation
4.3.0-Master (52aa6503bed)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
analysis
processing
qgsalgorithmurlopener.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsalgorithmurlopener.cpp
3
---------------------
4
begin : August 2024
5
copyright : (C) 2024 by Dave Signer
6
email : david at opengis dot ch
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 "
qgsalgorithmurlopener.h
"
19
20
#include "
qgis.h
"
21
#include "
qgsprocessingparameters.h
"
22
23
#include <QDesktopServices>
24
#include <QString>
25
#include <QUrl>
26
27
#include "moc_qgsalgorithmurlopener.cpp"
28
29
using namespace
Qt::StringLiterals;
30
32
33
QString QgsOpenUrlAlgorithm::name()
const
34
{
35
return
u
"openurl"
_s;
36
}
37
38
QString QgsOpenUrlAlgorithm::displayName()
const
39
{
40
return
tr(
"Open file or URL"
);
41
}
42
43
QString QgsOpenUrlAlgorithm::shortDescription()
const
44
{
45
return
tr(
"Opens files in their default associated application, or URLs in the user's default web browser."
);
46
}
47
48
QStringList QgsOpenUrlAlgorithm::tags()
const
49
{
50
return
tr(
"open,url,internet,url,fetch,get,request,https,pdf,file"
).split(
','
);
51
}
52
53
QString QgsOpenUrlAlgorithm::group()
const
54
{
55
return
tr(
"File tools"
);
56
}
57
58
QString QgsOpenUrlAlgorithm::groupId()
const
59
{
60
return
u
"filetools"
_s;
61
}
62
63
QString QgsOpenUrlAlgorithm::shortHelpString()
const
64
{
65
return
tr(
"This algorithm opens files in their default associated application, or URLs in the user's default web browser."
);
66
}
67
68
QgsOpenUrlAlgorithm *QgsOpenUrlAlgorithm::createInstance()
const
69
{
70
return
new
QgsOpenUrlAlgorithm();
71
}
72
73
void
QgsOpenUrlAlgorithm::initAlgorithm(
const
QVariantMap & )
74
{
75
addParameter(
new
QgsProcessingParameterString
( u
"URL"
_s, tr(
"URL or file path"
), QVariant(),
false
,
false
) );
76
addOutput(
new
QgsProcessingOutputBoolean
( u
"SUCCESS"
_s, QObject::tr(
"Successfully performed opening file or URL"
) ) );
77
}
78
79
QVariantMap QgsOpenUrlAlgorithm::processAlgorithm(
const
QVariantMap ¶meters,
QgsProcessingContext
&context,
QgsProcessingFeedback
*feedback )
80
{
81
QGS_MARK_ALGORITHM_SOURCE
82
83
const
QString url = parameterAsString( parameters, u
"URL"
_s, context );
84
if
( url.isEmpty() )
85
throw
QgsProcessingException
( tr(
"No URL or file path specified"
) );
86
const
QUrl qurl = QUrl::fromUserInput( url );
87
88
const
bool
result = QDesktopServices::openUrl( qurl );
89
90
if
( result )
91
feedback->
pushInfo
( QObject::tr(
"Successfully opened %1"
).arg( url ) );
92
else
93
feedback->
reportError
( QObject::tr(
"Failed opening %1"
).arg( url ) );
94
95
QVariantMap outputs;
96
outputs.insert( u
"SUCCESS"
_s, result );
97
return
outputs;
98
}
99
QgsProcessingContext
Contains information about the context in which a processing algorithm is executed.
Definition
qgsprocessingcontext.h:45
QgsProcessingException
Custom exception class for processing related exceptions.
Definition
qgsexception.h:76
QgsProcessingFeedback
Base class for providing feedback from a processing algorithm.
Definition
qgsprocessingfeedback.h:40
QgsProcessingFeedback::pushInfo
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
Definition
qgsprocessingfeedback.cpp:97
QgsProcessingFeedback::reportError
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
Definition
qgsprocessingfeedback.cpp:77
QgsProcessingOutputBoolean
A boolean output for processing algorithms.
Definition
qgsprocessingoutputs.h:453
QgsProcessingParameterString
A string parameter for processing algorithms.
Definition
qgsprocessingparameters.h:3087
qgis.h
qgsalgorithmurlopener.h
qgsprocessingparameters.h
Generated on
for QGIS API Documentation by
1.17.0