KProperty

KPropertySetBuffer.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3 Copyright (C) 2004 Alexander Dymo <cloudtemple@mskat.net>
4 Copyright (C) 2004-2017 Jarosław Staniek <staniek@kde.org>
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 "KPropertySetBuffer.h"
23#include "KPropertySet_p.h"
24#include "KProperty_p.h"
25
26class Q_DECL_HIDDEN KPropertySetBuffer::Private
27{
28public:
29 Private()
30 {
31 }
32};
33
34KPropertySetBuffer::KPropertySetBuffer()
35 : KPropertySet(false)
36 , d(new Private)
37{
38 connect(this, SIGNAL(propertyChanged(KPropertySet&,KProperty&)),
39 this, SLOT(intersectedChanged(KPropertySet&,KProperty&)));
40
41 connect(this, SIGNAL(propertyReset(KPropertySet&,KProperty&)),
42 this, SLOT(intersectedReset(KPropertySet&,KProperty&)));
43}
44
45KPropertySetBuffer::KPropertySetBuffer(const KPropertySet& set)
46 : KPropertySet(false)
47 , d(new Private)
48{
49 connect(this, SIGNAL(propertyChanged(KPropertySet&,KProperty&)),
50 this, SLOT(intersectedChanged(KPropertySet&,KProperty&)));
51
52 connect(this, SIGNAL(propertyReset(KPropertySet&,KProperty&)),
53 this, SLOT(intersectedReset(KPropertySet&,KProperty&)));
54
55 init(set);
56}
57
58KPropertySetBuffer::~KPropertySetBuffer()
59{
60 delete d;
61}
62
63void KPropertySetBuffer::init(const KPropertySet& set)
64{
65 //deep copy of set
66 const QList<KProperty*>::ConstIterator itEnd(KPropertySetPrivate::d(&set)->listConstEnd());
67 for (QList<KProperty*>::ConstIterator it(KPropertySetPrivate::d(&set)->listConstIterator());
68 it!=itEnd; ++it)
69 {
70 KProperty *prop = new KProperty(*(*it));
71 QByteArray group = KPropertySetPrivate::d(&set)->groupForProperty(*it);
72 const QString groupCaption = set.groupCaption(group);
74 addProperty(prop, group);
75 prop->d->addRelatedProperty(*it);
76 }
77}
78
80{
81 if (isEmpty()) {
82 init(set);
83 return;
84 }
85
86 const QList<KProperty*>::ConstIterator itEnd(KPropertySetPrivate::d(&set)->listConstEnd());
87 for (QList<KProperty*>::ConstIterator it(KPropertySetPrivate::d(&set)->listConstIterator());
88 it!=itEnd; ++it)
89 {
90 const QByteArray key( (*it)->name() );
91 KProperty *property = KPropertySetPrivate::d(&set)->property( key );
92 if (property) {
93 blockSignals(true);
94 (*it)->resetValue();
95 (*it)->d->addRelatedProperty(property);
96 blockSignals(false);
97 } else {
98 removeProperty(key);
99 }
100 }
101}
102
103void KPropertySetBuffer::intersectedChanged(KPropertySet& set, KProperty& prop)
104{
105 Q_UNUSED(set);
106 if (!contains(prop.name()))
107 return;
108
109 const QList<KProperty*> *props = prop.d->relatedProperties;
110 for (QList<KProperty*>::ConstIterator it = props->constBegin(); it != props->constEnd(); ++it) {
111 (*it)->setValue(prop.value(), KProperty::ValueOption::IgnoreOld);
112 }
113}
114
115void KPropertySetBuffer::intersectedReset(KPropertySet& set, KProperty& prop)
116{
117 Q_UNUSED(set);
118 if (!contains(prop.name()))
119 return;
120
121 const QList<KProperty*> *props = prop.d->relatedProperties;
122 for (QList<KProperty*>::ConstIterator it = props->constBegin(); it != props->constEnd(); ++it) {
123 (*it)->setValue(prop.value(), KProperty::ValueOption::IgnoreOld);
124 }
125}
A property set's buffer.
virtual void intersect(const KPropertySet &set)
Set of properties.
void addProperty(KProperty *property, const QByteArray &group="common")
bool isEmpty() const
KProperty & property(const QByteArray &name) const
QString groupCaption(const QByteArray &group) const
void setGroupCaption(const QByteArray &group, const QString &caption)
void removeProperty(KProperty *property)
bool contains(const QByteArray &name) const
The base class representing a single property.
Definition KProperty.h:96
QVariant value() const
QByteArray name() const
@ IgnoreOld
Do not remember the old value before setting a new one.
QCA_EXPORT void init()
const_iterator constBegin() const const
const_iterator constEnd() const const
bool blockSignals(bool block)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:09 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.