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 * @class KIO::MetaData metadata.h <KIO/MetaData>
19 *
20 * MetaData is a simple map of key/value strings.
21 */
22class MetaData : public QMap<QString, QString>
23{
24public:
25 /**
26 * Creates an empty meta data map.
27 */
28 MetaData()
29 : QMap<QString, QString>()
30 {
31 }
32 /**
33 * Copy constructor.
34 */
35 MetaData(const QMap<QString, QString> &metaData)
36 : QMap<QString, QString>(metaData)
37 {
38 }
39
40 /**
41 * Creates a meta data map from a QVaraint map.
42 * @since 4.3.1
43 */
44 MetaData(const QMap<QString, QVariant> &);
45
46 /**
47 * Adds the given meta data map to this map.
48 * @param metaData the map to add
49 * @return this map
50 */
51 MetaData &operator+=(const QMap<QString, QString> &metaData)
52 {
53 QMap<QString, QString>::ConstIterator it;
54 for (it = metaData.constBegin(); it != metaData.constEnd(); ++it) {
55 insert(key: it.key(), value: it.value());
56 }
57 return *this;
58 }
59
60 /**
61 * Same as above except the value in the map is a QVariant.
62 *
63 * This convenience function allows you to easily assign the values
64 * of a QVariant to this meta data class.
65 *
66 * @param metaData the map to add
67 * @return this map
68 * @since 4.3.1
69 */
70 MetaData &operator+=(const QMap<QString, QVariant> &metaData);
71
72 /**
73 * Sets the given meta data map to this map.
74 * @param metaData the map to add
75 * @return this map
76 * @since 4.3.1
77 */
78 MetaData &operator=(const QMap<QString, QVariant> &metaData);
79
80 /**
81 * Returns the contents of the map as a QVariant.
82 *
83 * @return a QVariant representation of the meta data map.
84 * @since 4.3.1
85 */
86 QVariant toVariant() const;
87};
88
89inline KIO::MetaData::MetaData(const QMap<QString, QVariant> &map)
90{
91 *this = map;
92}
93
94inline KIO::MetaData &KIO::MetaData::operator+=(const QMap<QString, QVariant> &metaData)
95{
96 QMapIterator<QString, QVariant> it(metaData);
97
98 while (it.hasNext()) {
99 it.next();
100 insert(key: it.key(), value: it.value().toString());
101 }
102
103 return *this;
104}
105
106inline KIO::MetaData &KIO::MetaData::operator=(const QMap<QString, QVariant> &metaData)
107{
108 clear();
109 return (*this += metaData);
110}
111
112inline QVariant KIO::MetaData::toVariant() const
113{
114 QMap<QString, QVariant> map;
115 QMapIterator<QString, QString> it(*this);
116
117 while (it.hasNext()) {
118 it.next();
119 map.insert(key: it.key(), value: it.value());
120 }
121
122 return QVariant(map);
123}
124
125} // namespace KIO
126
127#endif /* KIO_METADATA_H */
128

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