KProperty

KPropertyListData.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2004 Cedric Pasteur <[email protected]>
3  Copyright (C) 2004 Alexander Dymo <[email protected]>
4  Copyright (C) 2004-2017 Jarosław Staniek <[email protected]>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20 */
21 
22 #include "KPropertyListData.h"
23 
24 class Q_DECL_HIDDEN KPropertyListData::Private
25 {
26 public:
27  Private() {
28  }
29  Private(const Private &other) {
30  copy(other);
31  }
32 #define KPropertyListDataPrivateArgs(o) std::tie(o.keys, o.names)
33  void copy(const Private &other) {
34  KPropertyListDataPrivateArgs((*this)) = KPropertyListDataPrivateArgs(other);
35  }
36  bool operator==(const Private &other) const {
37  return KPropertyListDataPrivateArgs((*this)) == KPropertyListDataPrivateArgs(other);
38  }
39  QVariantList keys;
40  QVariantList names;
41 };
42 
43 KPropertyListData::KPropertyListData()
44  : d(new Private)
45 {
46 }
47 
48 KPropertyListData::KPropertyListData(const KPropertyListData &other)
49  : d(new Private(*other.d))
50 {
51 }
52 
53 KPropertyListData::KPropertyListData(const QStringList &keys, const QStringList &names)
54  : d(new Private)
55 {
56  setKeysAsStringList(keys);
57  setNamesAsStringList(names);
58 }
59 
60 KPropertyListData::KPropertyListData(const QVariantList &keys, const QVariantList &names)
61  : d(new Private)
62 {
63  setKeys(keys);
64  setNames(names);
65 }
66 
67 KPropertyListData::KPropertyListData(const QVariantList &keys, const QStringList &names)
68  : d(new Private)
69 {
70  setKeys(keys);
71  setNamesAsStringList(names);
72 }
73 
74 KPropertyListData::~KPropertyListData()
75 {
76  delete d;
77 }
78 
80 {
81  if (this != &other) {
82  d->copy(*other.d);
83  }
84  return *this;
85 }
86 
88 {
89  return *d == *other.d;
90 }
91 
93 {
94  d->keys.clear();
95  for (const QString &key : keys) {
96  d->keys.append(key);
97  }
98 }
99 
100 void KPropertyListData::setKeys(const QVariantList &keys)
101 {
102  d->keys = keys;
103 }
104 
105 QVariantList KPropertyListData::keys() const
106 {
107  return d->keys;
108 }
109 
111 {
112  QStringList result;
113  for (const QVariant &key : d->keys) {
114  result.append(key.toString());
115  }
116  return result;
117 }
118 
119 QVariantList KPropertyListData::names() const
120 {
121  return d->names;
122 }
123 
125 {
126  QStringList result;
127  for (const QVariant &name : d->names) {
128  result.append(name.toString());
129  }
130  return result;
131 }
132 
134 {
135  d->names.clear();
136  for (const QString &name : names) {
137  d->names.append(name);
138  }
139 }
140 
141 void KPropertyListData::setNames(const QVariantList &names)
142 {
143  d->names = names;
144 }
void setNamesAsStringList(const QStringList &names)
Sets a list containing all possible keys for a property as strings.
QVariantList names() const
The list of user-visible translated name elements.
void setKeysAsStringList(const QStringList &keys)
Sets a list containing all possible keys for a property as strings.
void setNames(const QVariantList &names)
Sets a list containing all possible keys for a property.
bool operator==(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
KIOCORE_EXPORT CopyJob * copy(const QUrl &src, const QUrl &dest, JobFlags flags=DefaultFlags)
bool operator==(const KPropertyListData &other) const
QStringList namesAsStringList() const
The list of user-visible translated name elements as strings.
void append(const T &value)
KPropertyListData & operator=(const KPropertyListData &other)
Assigns other to this KPropertyListData.
void setKeys(const QVariantList &keys)
Sets a list containing all possible keys for a property.
QVariantList keys() const
A list containing all possible keys for a property.
QStringList keysAsStringList() const
A list containing all possible keys for a property converted to strings.
QString toString() const const
A data container for properties of list type.
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.