Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qgeouriprovider.cpp
Go to the documentation of this file.
1// Copyright (C) 2015 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#include "qgeouriprovider.h"
4
5#include <QMap>
6#include <QVariant>
7#include <QRandomGenerator>
8#include <QSet>
9#include <QString>
10
12
14 QObject *parent,
15 const QVariantMap &parameters,
16 const QString &hostParameterName,
17 const QString &internationalHost,
18 const QString &localizedHost)
19 : QObject(parent)
20 , m_internationalHost(parameters.value(hostParameterName, internationalHost).toString())
21 , m_localizedHost(localizedHost)
22 , m_firstSubdomain(QChar::Null)
23 , m_maxSubdomains(0)
24{
25 setCurrentHost(isInternationalNetwork() || m_localizedHost.isEmpty() ? m_internationalHost : m_localizedHost);
26}
27
29{
30 if (m_maxSubdomains) {
31 auto result = QString("%1").arg(static_cast<char>(m_firstSubdomain.toLatin1() + QRandomGenerator::global()->bounded(m_maxSubdomains)));
32 result += '.' + m_currentHost;
33 return result;
34 }
35 return m_currentHost;
36}
37
38void QGeoUriProvider::setCurrentHost(const QString &host)
39{
40 if (host.length() > 4 && host.at(1) == QChar('-') && host.at(3) == QChar('.')) {
41 QString realHost = host.right(host.length() - 4);
42 m_firstSubdomain = host.at(0);
43 m_maxSubdomains = host.at(2).toLatin1() - host.at(0).toLatin1() + 1;
44 m_currentHost = realHost;
45 } else {
46 m_currentHost = host;
47 m_firstSubdomain = QChar::Null;
48 m_maxSubdomains = 0;
49 }
50}
51
52void QGeoUriProvider::mobileCountryCodeChanged(int interfaceId, const QString& mcc)
53{
54 Q_UNUSED(interfaceId);
55 Q_UNUSED(mcc);
56
57 setCurrentHost(isInternationalNetwork() || m_localizedHost.isEmpty() ? m_internationalHost : m_localizedHost);
58}
59
60bool QGeoUriProvider::isInternationalNetwork() const
61{
62 return true;
63}
64
\inmodule QtCore
QString getCurrentHost() const
QGeoUriProvider(QObject *parent, const QVariantMap &parameters, const QString &hostParameterName, const QString &internationalHost, const QString &localizedHost=QString())
\inmodule QtCore
Definition qobject.h:103
static Q_DECL_CONST_FUNCTION QRandomGenerator * global()
\threadsafe
Definition qrandom.h:275
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
Definition qstring.cpp:8870
QString right(qsizetype n) const &
Definition qstring.h:375
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1226
qsizetype length() const noexcept
Returns the number of characters in this string.
Definition qstring.h:191
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLuint64EXT * result
[6]
#define Q_UNUSED(x)
char * toString(const MyType &t)
[31]