KProperty

KPropertySetBuffer.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 "KPropertySetBuffer.h"
23 #include "KPropertySet_p.h"
24 #include "KProperty_p.h"
25 
26 class Q_DECL_HIDDEN KPropertySetBuffer::Private
27 {
28 public:
29  Private()
30  {
31  }
32 };
33 
34 KPropertySetBuffer::KPropertySetBuffer()
35  : KPropertySet(false)
36  , d(new Private)
37 {
39  this, SLOT(intersectedChanged(KPropertySet&,KProperty&)));
40 
42  this, SLOT(intersectedReset(KPropertySet&,KProperty&)));
43 }
44 
45 KPropertySetBuffer::KPropertySetBuffer(const KPropertySet& set)
46  : KPropertySet(false)
47  , d(new Private)
48 {
50  this, SLOT(intersectedChanged(KPropertySet&,KProperty&)));
51 
53  this, SLOT(intersectedReset(KPropertySet&,KProperty&)));
54 
55  init(set);
56 }
57 
58 KPropertySetBuffer::~KPropertySetBuffer()
59 {
60  delete d;
61 }
62 
63 void 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);
73  setGroupCaption(group, groupCaption);
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 
103 void 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 
115 void 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 }
QString groupCaption(const QByteArray &group) const
virtual void intersect(const KPropertySet &set)
Do not remember the old value before setting a new one.
bool isEmpty() const
bool contains(const QByteArray &name) const
void addProperty(KProperty *property, const QByteArray &group="common")
void removeProperty(KProperty *property)
void propertyChanged(KPropertySet &set, KProperty &property)
A property set&#39;s buffer.
Set of properties.
Definition: KPropertySet.h:119
QByteArray name() const
Definition: KProperty.cpp:324
bool blockSignals(bool block)
QCA_EXPORT void init()
void setGroupCaption(const QByteArray &group, const QString &caption)
The base class representing a single property.
Definition: KProperty.h:95
QVariant value() const
Definition: KProperty.cpp:394
KProperty & property(const QByteArray &name) const
QList::const_iterator constEnd() const const
QList::const_iterator constBegin() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void propertyReset(KPropertySet &set, KProperty &property)
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.