KProperty

KPropertyComposedUrl.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2018 Jarosław Staniek <[email protected]>
3  Copyright (C) 2018 Dmitry Baryshev <[email protected]>
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 
25 class Q_DECL_HIDDEN KPropertyComposedUrl::Private
26 {
27 public:
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 
50  QUrl baseUrl;
52  QUrl url;
53 };
54 
56  : d(new Private)
57 {
58 }
59 
62 {
63  setBaseUrl(baseUrl);
64  setRelativePath(relativePath);
65 }
66 
69 {
70  setBaseUrl(baseUrl);
71  setAbsoluteUrl(absoluteUrl);
72 }
73 
75  : d(new Private(*other.d))
76 {
77 }
78 
79 KPropertyComposedUrl::~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 
107  if (!baseUrl.path().endsWith(QLatin1String("/"))) {
108  baseUrl.setPath(baseUrl.path() + 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 
141  if (absoluteUrl.isValid() && !absoluteUrl.isRelative()) {
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 
167 {
168  dbg.nospace() << "KPropertyComposedUrl("
169  << "baseUrl=" << p.baseUrl() << " relativePath=" << p.relativePath()
170  << " absoluteUrl=" << p.absoluteUrl() << ")";
171  return dbg.space();
172 }
QDebug & nospace()
QUrl baseUrl() const
Returns the base URL (absolute) or empty URL if there is no absolute base URL specified.
KPropertyComposedUrl()
Constructs empty and invalid composed URL.
QString relativePath() const
Returns relative path that has been set for this object.
bool operator==(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
void setPath(const QString &path, QUrl::ParsingMode mode)
KIOCORE_EXPORT CopyJob * copy(const QUrl &src, const QUrl &dest, JobFlags flags=DefaultFlags)
KPropertyComposedUrl & operator=(const KPropertyComposedUrl &other)
Assigns other to this KPropertyComposedUrl.
void setRelativePath(const QString &relativePath)
Sets a new relative path for this object.
QUrl value() const
Returns URL value computed from base URL, absolute URL and relative path, whichever is defined...
bool isEmpty() const const
QString path(QUrl::ComponentFormattingOptions options) const const
QUrl absoluteUrl() const
Returns absolute URL that has been set for this object.
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const const
void setAbsoluteUrl(const QUrl &absoluteUrl)
Sets a new absolute URL.
QDebug & space()
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
bool isValid() const const
bool isRelative() const const
QUrl resolved(const QUrl &relative) const const
bool isValid() const
Return true if the URL value that can be computed (from base URL, absolute URL and relative path) is ...
bool operator==(const KPropertyComposedUrl &other) const
Return true if this KPropertyComposedUrl equals to other.
void setBaseUrl(const QUrl &url)
Sets base URL (absolute)
A data structure that composes absolute and relative URLs.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Aug 9 2020 23:10:57 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.