QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
qgsabstractcontentcache.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
QgsAbstractContentCache.cpp
3
-----------------
4
begin : December 2018
5
copyright : (C) 2018 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 "
qgsabstractcontentcache.h
"
19
20
#include "
qgssetrequestinitiator_p.h
"
21
22
#include <QRegularExpression>
23
#include <QString>
24
25
#include "moc_qgsabstractcontentcache.cpp"
26
27
using namespace
Qt::StringLiterals;
28
29
//
30
// QgsAbstractContentCacheEntry
31
//
32
33
QgsAbstractContentCacheEntry::QgsAbstractContentCacheEntry
(
const
QString &
path
)
34
:
path
(
path
)
35
{}
36
37
//
38
// QgsAbstractContentCacheBase
39
//
40
41
QgsAbstractContentCacheBase::QgsAbstractContentCacheBase
( QObject *parent )
42
: QObject( parent )
43
{}
44
45
bool
QgsAbstractContentCacheBase::invalidateCacheEntry
(
const
QString &path )
46
{
47
Q_UNUSED( path );
48
return
false
;
49
}
50
51
void
QgsAbstractContentCacheBase::onRemoteContentFetched
(
const
QString &,
bool
)
52
{}
53
54
bool
QgsAbstractContentCacheBase::parseBase64DataUrl
(
const
QString &path, QString *mimeType, QString *data )
55
{
56
const
thread_local
QRegularExpression sRx( u
"^data:([a-zA-Z0-9+\\-]*\\/[a-zA-Z0-9+\\-]*?)(?:;(base64|utf8))?,(.*)$"
_s );
57
const
QRegularExpressionMatch base64Match = sRx.match( path );
58
if
( !base64Match.hasMatch() )
59
return
false
;
60
61
const
QString typeMatch = base64Match.captured( 2 );
62
const
QString mimeMatch = base64Match.captured( 1 );
63
64
if
( mimeType )
65
*mimeType = mimeMatch;
66
if
( data )
67
*data = base64Match.captured( 3 );
68
69
if
( typeMatch ==
"base64"
_L1 )
70
return
true
;
// definitely base 64
71
else
if
( typeMatch ==
"utf8"
_L1 )
72
return
false
;
// definitely NOT base 64
73
74
// if we aren't certain it's base 64, and it has an xml mime type, assume it's not.
75
// see https://github.com/qgis/QGIS/issues/59575
76
if
( mimeMatch.endsWith(
"xml"
_L1 ) || mimeMatch.endsWith(
"svg"
_L1 ) )
77
return
false
;
78
79
return
true
;
80
}
81
82
bool
QgsAbstractContentCacheBase::parseEmbeddedStringData
(
const
QString &path, QString *mimeType, QString *data )
83
{
84
const
thread_local
QRegularExpression sRx( u
"^data:([a-zA-Z0-9+\\-]*\\/[a-zA-Z0-9+\\-]*?)\\;utf8,(.*)$"
_s, QRegularExpression::DotMatchesEverythingOption );
85
const
QRegularExpressionMatch stringMatch = sRx.match( path );
86
87
if
( !stringMatch.hasMatch() )
88
return
false
;
89
90
if
( mimeType )
91
*mimeType = stringMatch.captured( 1 );
92
if
( data )
93
*data = stringMatch.captured( 2 );
94
95
return
true
;
96
}
97
98
bool
QgsAbstractContentCacheBase::isBase64Data
(
const
QString &path )
99
{
100
return
path.startsWith(
"base64:"
_L1 ) ||
parseBase64DataUrl
( path );
101
}
QgsAbstractContentCacheBase::parseEmbeddedStringData
static bool parseEmbeddedStringData(const QString &path, QString *mimeType=nullptr, QString *data=nullptr)
Parses a path to determine if it represents a embedded string data, and if so, extracts the component...
Definition
qgsabstractcontentcache.cpp:82
QgsAbstractContentCacheBase::onRemoteContentFetched
virtual void onRemoteContentFetched(const QString &url, bool success)
Triggered after remote content (i.e.
Definition
qgsabstractcontentcache.cpp:51
QgsAbstractContentCacheBase::parseBase64DataUrl
static bool parseBase64DataUrl(const QString &path, QString *mimeType=nullptr, QString *data=nullptr)
Parses a path to determine if it represents a base 64 encoded HTML data URL, and if so,...
Definition
qgsabstractcontentcache.cpp:54
QgsAbstractContentCacheBase::QgsAbstractContentCacheBase
QgsAbstractContentCacheBase(QObject *parent)
Constructor for QgsAbstractContentCacheBase, with the specified parent object.
Definition
qgsabstractcontentcache.cpp:41
QgsAbstractContentCacheBase::invalidateCacheEntry
virtual bool invalidateCacheEntry(const QString &path)
Invalidates a cache entry for the specified path.
Definition
qgsabstractcontentcache.cpp:45
QgsAbstractContentCacheBase::isBase64Data
static bool isBase64Data(const QString &path)
Returns true if path represents base64 encoded data.
Definition
qgsabstractcontentcache.cpp:98
QgsAbstractContentCacheEntry::QgsAbstractContentCacheEntry
QgsAbstractContentCacheEntry(const QString &path)
Constructor for QgsAbstractContentCacheEntry for an entry relating to the specified path.
Definition
qgsabstractcontentcache.cpp:33
QgsAbstractContentCacheEntry::path
QString path
Represents the absolute path to a file, a remote URL, or a base64 encoded string.
Definition
qgsabstractcontentcache.h:70
qgsabstractcontentcache.h
qgssetrequestinitiator_p.h
Generated on
for QGIS API Documentation by
1.17.0