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

source code of qtbase/src/corelib/io/qurlquery.h