1// Copyright (C) 2020 The Qt Company Ltd.
2// Copyright (C) 2016 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QURLQUERY_H
6#define QURLQUERY_H
7
8#include <QtCore/qshareddata.h>
9#include <QtCore/qurl.h>
10
11#include <initializer_list>
12
13QT_BEGIN_NAMESPACE
14
15Q_CORE_EXPORT size_t qHash(const QUrlQuery &key, size_t seed = 0) noexcept;
16
17class QUrlQueryPrivate;
18class Q_CORE_EXPORT QUrlQuery
19{
20public:
21 QUrlQuery();
22 explicit QUrlQuery(const QUrl &url);
23 explicit QUrlQuery(const QString &queryString);
24 QUrlQuery(std::initializer_list<std::pair<QString, QString>> list)
25 : QUrlQuery()
26 {
27 for (const std::pair<QString, QString> &item : list)
28 addQueryItem(key: item.first, value: item.second);
29 }
30
31 QUrlQuery(const QUrlQuery &other);
32 QUrlQuery(QUrlQuery &&other) noexcept;
33 QUrlQuery &operator=(const QUrlQuery &other);
34 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QUrlQuery)
35 ~QUrlQuery();
36
37 bool operator==(const QUrlQuery &other) const;
38 bool operator!=(const QUrlQuery &other) const
39 { return !(*this == other); }
40
41 void swap(QUrlQuery &other) noexcept { d.swap(other&: other.d); }
42
43 bool isEmpty() const;
44 bool isDetached() const;
45 void clear();
46
47 QString query(QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const;
48 void setQuery(const QString &queryString);
49 QString toString(QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const
50 { return query(encoding); }
51
52 void setQueryDelimiters(QChar valueDelimiter, QChar pairDelimiter);
53 QChar queryValueDelimiter() const;
54 QChar queryPairDelimiter() const;
55
56 void setQueryItems(const QList<std::pair<QString, QString> > &query);
57 QList<std::pair<QString, QString> > queryItems(QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const;
58
59 bool hasQueryItem(const QString &key) const;
60 void addQueryItem(const QString &key, const QString &value);
61 void removeQueryItem(const QString &key);
62 QString queryItemValue(const QString &key, QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const;
63 QStringList allQueryItemValues(const QString &key, QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const;
64 void removeAllQueryItems(const QString &key);
65
66 static constexpr char16_t defaultQueryValueDelimiter() noexcept { return u'='; }
67 static constexpr char16_t defaultQueryPairDelimiter() noexcept { return u'&'; }
68
69private:
70 friend class QUrl;
71 friend Q_CORE_EXPORT size_t qHash(const QUrlQuery &key, size_t seed) noexcept;
72 QSharedDataPointer<QUrlQueryPrivate> d;
73
74public:
75 typedef QSharedDataPointer<QUrlQueryPrivate> DataPtr;
76 inline DataPtr &data_ptr() { return d; }
77};
78
79Q_DECLARE_SHARED(QUrlQuery)
80
81QT_END_NAMESPACE
82
83#endif // QURLQUERY_H
84