KProperty

KPropertyComposedUrl.h
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#ifndef KPROPERTYCOMPOSEDURL_H
22#define KPROPERTYCOMPOSEDURL_H
23
24#include "kpropertycore_export.h"
25
26#include <QDebug>
27#include <QMetaType>
28#include <QUrl>
29
30/**
31 * @brief A data structure that composes absolute and relative URLs.
32 *
33 * @since 3.2
34 */
35class KPROPERTYCORE_EXPORT KPropertyComposedUrl
36{
37public:
38 /**
39 * Constructs empty and invalid composed URL
40 */
42
43 /**
44 * Constructs composed URL with specified base URL and path relative to the base URL
45 *
46 * @a baseUrl must be a valid absolute URL, otherwise the entire composed URL is invalid.
47 * @a relativePath must be proper relative path. It is not important if it points to existing
48 * filesystem object.
49 */
50 KPropertyComposedUrl(const QUrl &baseUrl, const QString &relativePath = QString());
51
52 /**
53 * Constructs composed URL with specified base URL and independent absolute URL
54 *
55 * @a baseUrl must be absolute or empty URL, otherwise the entire composed URL is invalid.
56 * @a absoluteUrl must be absolute URL. It is not important if it points to existing filesystem
57 * object.
58 *
59 * Because @a absoluteUrl carries all needed information, @a baseUrl is ignored in this variant
60 * of constructor. However @a baseUrl is still remembered and will be used if this object's
61 * value will be changed to relative path using setRelativePath().
62 */
63 KPropertyComposedUrl(const QUrl &baseUrl, const QUrl &absoluteUrl);
64
65 /**
66 * Constructs a copy of @a other
67 */
69
71
72 /**
73 * Assigns @a other to this KPropertyComposedUrl
74 */
75 KPropertyComposedUrl &operator=(const KPropertyComposedUrl &other);
76
77 /**
78 * Return @c true if this KPropertyComposedUrl equals to @a other
79 *
80 * Two KPropertyComposedUrl objects are equal if they have the same values.
81 * @see value()
82 */
83 bool operator==(const KPropertyComposedUrl &other) const;
84
85 /**
86 * Return @c true if this KPropertyComposedUrl does not equal to @a other
87 */
88 bool operator!=(const KPropertyComposedUrl &other) const { return !operator==(other); }
89
90 /**
91 * Returns URL value computed from base URL, absolute URL and relative path, whichever is
92 * defined.
93 *
94 * - If the KPropertyComposedUrl is invalid, empty QUrl is returned
95 * - If absolute path is present, it is returned
96 * - If base URL and relative path are present, URL with added relative path is returned
97 */
98 QUrl value() const;
99
100 /**
101 * Returns the base URL (absolute) or empty URL if there is no absolute base URL specified
102 */
103 QUrl baseUrl() const;
104
105 /**
106 * Sets base URL (absolute)
107 *
108 * If @a baseUrl is not valid and absolute, base URL is cleared.
109 * In any case relative path (relativePath()) and absolute URL (absoluteUrl()) are not modified.
110 */
111 void setBaseUrl(const QUrl &url);
112
113 /**
114 * Returns absolute URL that has been set for this object
115 *
116 * Empty URL is returned if absolute URL is not specified. In this case relative path can still
117 * be present. If absolute URL is present, relative path is empty.
118 */
119 QUrl absoluteUrl() const;
120
121 /**
122 * Sets a new absolute URL
123 *
124 * If @a absoluteUrl is not valid and absolute, it is cleared.
125 * If @a absoluteUrl is absolute, relative path (relativePath()) is cleared.
126 */
127 void setAbsoluteUrl(const QUrl &absoluteUrl);
128
129 /**
130 * Returns relative path that has been set for this object
131 *
132 * Empty string is returned if there is no path assigned. Non-empty path can be used to
133 * calculate value by concatenating it with the base URL. If relativePath() is present
134 * absoluteUrl() is empty .
135 */
136 QString relativePath() const;
137
138 /**
139 * Sets a new relative path for this object
140 *
141 * If @a relativePath is not a valid or empty path, it is cleared.
142 * If @a relativePath is empty or valid, absolute URL is cleared.
143 */
144 void setRelativePath(const QString &relativePath);
145
146 /**
147 * Return @c true if the URL value that can be computed (from base URL, absolute URL and
148 * relative path) is valid
149 *
150 * @see value() for description of how value is computed.
151 */
152 bool isValid() const;
153
154private:
155 class Private;
156 Private *const d;
157};
158
159Q_DECLARE_METATYPE(KPropertyComposedUrl)
160
161//! qDebug() stream operator. Writes KPropertyComposedUrl to the debug output.
162KPROPERTYCORE_EXPORT QDebug operator<<(QDebug dbg, const KPropertyComposedUrl &p);
163
164#endif // KPROPERTYCOMPOSEDURL_H
A data structure that composes absolute and relative URLs.
bool operator!=(const KPropertyComposedUrl &other) const
Return true if this KPropertyComposedUrl does not equal to other.
QDebug operator<<(QDebug dbg, const PerceptualColor::MultiSpinBoxSection &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:11:18 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.