KProperty

KPropertyComposedUrl.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2018 Jarosław Staniek <staniek@kde.org>
3 Copyright (C) 2018 Dmitry Baryshev <dmitrymq@gmail.com>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "KPropertyComposedUrl.h"
22
23#include <tuple> // std::tie
24
25class Q_DECL_HIDDEN KPropertyComposedUrl::Private
26{
27public:
28 Private() {}
29 Private(const Private &other) { copy(other); }
30 Private(const QUrl &_baseUrl, const QUrl &_url)
31 : baseUrl(_baseUrl)
32 , url(_url)
33 {
34 }
35
36#define KPropertyComposedUrlPrivateArgs(o) std::tie(o.baseUrl, o.url)
37 void copy(const Private &other)
38 {
39 KPropertyComposedUrlPrivateArgs((*this)) = KPropertyComposedUrlPrivateArgs(other);
40 }
41
42 bool operator==(const Private &other) const
43 {
44 return KPropertyComposedUrlPrivateArgs((*this)) == KPropertyComposedUrlPrivateArgs(other);
45 }
46#undef KPropertyComposedUrlPrivateArgs
47
48 //! Base URL for relative URLs, not used if 'url' is absolute but still stored
49 //! as it will be needed as soon as 'url' is changed to relative
50 QUrl baseUrl;
51 //! contains an absolute URL, or just a path for relative URLs
52 QUrl url;
53};
54
56 : d(new Private)
57{
58}
59
66
73
75 : d(new Private(*other.d))
76{
77}
78
79KPropertyComposedUrl::~KPropertyComposedUrl()
80{
81 delete d;
82}
83
85{
86 if (this != &other) {
87 d->copy(*other.d);
88 }
89 return *this;
90}
91
93{
94 return *d == *other.d;
95}
96
98{
99 if (!isValid()) {
100 return QUrl();
101 }
102
103 if (d->url.isRelative()) {
104 QUrl baseUrl = d->baseUrl;
105
106 //! append necessary '/'
107 if (!baseUrl.path().endsWith(QLatin1String("/"))) {
109 }
110
111 return baseUrl.resolved(d->url);
112 } else {
113 return d->url;
114 }
115}
116
118{
119 return d->baseUrl;
120}
121
123{
124 if (!url.isValid() || url.isRelative()) {
125 d->baseUrl.clear();
126 return;
127 }
128
129 d->baseUrl = url;
130}
131
133{
134 return d->url.isRelative() ? QUrl() : d->url;
135}
136
138{
139 d->url.clear();
140
142 d->url = absoluteUrl;
143 }
144}
145
147{
148 return d->url.isRelative() ? d->url.path() : QString();
149}
150
152{
153 d->url.clear();
154
155 if (!relativePath.isEmpty()) {
156 d->url.setPath(relativePath);
157 }
158}
159
161{
162 // we should have both URLs anyways
163 return d->baseUrl.isValid() && d->url.isValid();
164}
165
166QDebug operator<<(QDebug dbg, const KPropertyComposedUrl &p)
167{
168 dbg.nospace() << "KPropertyComposedUrl("
169 << "baseUrl=" << p.baseUrl() << " relativePath=" << p.relativePath()
170 << " absoluteUrl=" << p.absoluteUrl() << ")";
171 return dbg.space();
172}
A data structure that composes absolute and relative URLs.
QUrl absoluteUrl() const
Returns absolute URL that has been set for this object.
QUrl baseUrl() const
Returns the base URL (absolute) or empty URL if there is no absolute base URL specified.
KPropertyComposedUrl & operator=(const KPropertyComposedUrl &other)
Assigns other to this KPropertyComposedUrl.
QString relativePath() const
Returns relative path that has been set for this object.
QUrl value() const
Returns URL value computed from base URL, absolute URL and relative path, whichever is defined.
bool operator==(const KPropertyComposedUrl &other) const
Return true if this KPropertyComposedUrl equals to other.
void setRelativePath(const QString &relativePath)
Sets a new relative path for this object.
void setAbsoluteUrl(const QUrl &absoluteUrl)
Sets a new absolute URL.
bool isValid() const
Return true if the URL value that can be computed (from base URL, absolute URL and relative path) is ...
KPropertyComposedUrl()
Constructs empty and invalid composed URL.
void setBaseUrl(const QUrl &url)
Sets base URL (absolute)
const QList< QKeySequence > & copy()
bool operator==(const StyleDelim &l, const StyleDelim &r)
QDebug & nospace()
QDebug & space()
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
void clear()
bool isRelative() const const
bool isValid() const const
QString path(ComponentFormattingOptions options) const const
QUrl resolved(const QUrl &relative) const const
void setPath(const QString &path, ParsingMode mode)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:09 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.