1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2000-2005 David Faure <faure@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-only
6*/
7#ifndef KIO_METADATA_H
8#define KIO_METADATA_H
9
10#include "kiocore_export.h"
11#include <QMap>
12#include <QString>
13#include <QVariant>
14
15namespace KIO
16{
17/*!
18 * MetaData is a simple map of key/value strings.
19 * \internal
20 */
21class MetaData : public QMap<QString, QString>
22{
23public:
24 /*!
25 * Creates an empty meta data map.
26 */
27 MetaData()
28 : QMap<QString, QString>()
29 {
30 }
31 /*!
32 * Copy constructor.
33 */
34 MetaData(const QMap<QString, QString> &metaData)
35 : QMap<QString, QString>(metaData)
36 {
37 }
38
39 /*!
40 * Creates a meta data map from a QVaraint map.
41 * \since 4.3.1
42 */
43 MetaData(const QMap<QString, QVariant> &);
44
45 /*!
46 * Adds the given meta data map to this map.
47 *
48 * \a metaData the map to add
49 *
50 * Returns this map
51 */
52 MetaData &operator+=(const QMap<QString, QString> &metaData)
53 {
54 QMap<QString, QString>::ConstIterator it;
55 for (it = metaData.constBegin(); it != metaData.constEnd(); ++it) {
56 insert(key: it.key(), value: it.value());
57 }
58 return *this;
59 }
60
61 /*!
62 * Same as above except the value in the map is a QVariant.
63 *
64 * This convenience function allows you to easily assign the values
65 * of a QVariant to this meta data class.
66 *
67 * \a metaData the map to add
68 *
69 * Returns this map
70 *
71 * \since 4.3.1
72 */
73 MetaData &operator+=(const QMap<QString, QVariant> &metaData);
74
75 /*!
76 * Sets the given meta data map to this map.
77 *
78 * \a metaData the map to add
79 *
80 * Returns this map
81 *
82 * \since 4.3.1
83 */
84 MetaData &operator=(const QMap<QString, QVariant> &metaData);
85
86 /*!
87 * Returns the contents of the map as a QVariant.
88 *
89 * Returns a QVariant representation of the meta data map.
90 *
91 * \since 4.3.1
92 */
93 QVariant toVariant() const;
94};
95
96inline KIO::MetaData::MetaData(const QMap<QString, QVariant> &map)
97{
98 *this = map;
99}
100
101inline KIO::MetaData &KIO::MetaData::operator+=(const QMap<QString, QVariant> &metaData)
102{
103 QMapIterator<QString, QVariant> it(metaData);
104
105 while (it.hasNext()) {
106 it.next();
107 insert(key: it.key(), value: it.value().toString());
108 }
109
110 return *this;
111}
112
113inline KIO::MetaData &KIO::MetaData::operator=(const QMap<QString, QVariant> &metaData)
114{
115 clear();
116 return (*this += metaData);
117}
118
119inline QVariant KIO::MetaData::toVariant() const
120{
121 QMap<QString, QVariant> map;
122 QMapIterator<QString, QString> it(*this);
123
124 while (it.hasNext()) {
125 it.next();
126 map.insert(key: it.key(), value: it.value());
127 }
128
129 return QVariant(map);
130}
131
132} // namespace KIO
133
134#endif /* KIO_METADATA_H */
135

source code of kio/src/core/metadata.h