22#include "KPropertySet.h"
23#include "KPropertySet_p.h"
24#include "KProperty_p.h"
28KPropertySetPrivate::KPropertySetPrivate(
KPropertySet *set,
bool isOwnProperty)
29 : q(set), m_ownProperty(isOwnProperty)
31 m_groupCaptions.insert(
"common",
QObject::tr(
"General",
"General properties"));
34KPropertySetPrivate::~KPropertySetPrivate()
41 kprWarning() <<
"property == 0";
45 kprWarning() <<
"COULD NOT ADD NULL PROPERTY";
51 addRelatedProperty(p, property);
54 m_list.append(property);
55 m_hash.insert(property->
name().
toLower(), property);
57 m_visiblePropertiesCount++;
59 addToGroup(realGroup, property);
62 property->d->addSet(q);
65 property->setSortingKey(count());
69void KPropertySetPrivate::removeProperty(
KProperty *property)
74 if (!m_list.removeOne(property)) {
75 kprDebug() <<
"The property set does not contain property" << property;
82 m_visiblePropertiesCount--;
85 emit q->aboutToDeleteProperty(*q, *p);
91void KPropertySetPrivate::clear()
93 if (m_informAboutClearing) {
94 *m_informAboutClearing =
true;
96 m_informAboutClearing =
nullptr;
97 emit q->aboutToBeCleared();
98 m_visiblePropertiesCount = 0;
99 qDeleteAll(m_propertiesOfGroup);
100 m_propertiesOfGroup.clear();
101 m_groupNames.clear();
102 m_groupForProperties.clear();
103 m_groupCaptions.clear();
104 m_groupIconNames.clear();
110void KPropertySetPrivate::copyAttributesFrom(
const KPropertySetPrivate &other)
118 m_propertiesOfGroup.clear();
119 m_groupForProperties.clear();
120 m_visiblePropertiesCount = 0;
121 m_informAboutClearing =
nullptr;
124void KPropertySetPrivate::copyPropertiesFrom(
130 addProperty(prop, set.d->groupForProperty( *it )
142 if (!property || group.
isEmpty()) {
147 if (groupForProperty(property) == groupLower) {
148 kprWarning() <<
"Group" << group <<
"already contains property" <<
property->name();
152 if (!propertiesOfGroup) {
154 m_propertiesOfGroup.insert(groupLower, propertiesOfGroup);
155 m_groupNames.append(groupLower);
158 addPropertyToGroup(property, groupLower);
161void KPropertySetPrivate::removeFromGroup(
KProperty *property)
166 const QByteArray group(groupForProperty(property));
171 if (propertiesOfGroup) {
173 if (propertiesOfGroup->
isEmpty()) {
175 m_propertiesOfGroup.take(group);
176 delete propertiesOfGroup;
177 const int i = m_groupNames.
indexOf(group);
179 m_groupNames.removeAt(i);
183 removePropertyFromGroup(property);
186bool KPropertySetPrivate::hasGroups()
const
188 return m_groupNames.count() > 1 || (m_groupNames.count() == 1 && m_groupNames.first() !=
"common");
191void KPropertySetPrivate::informAboutClearing(
bool* cleared)
195 m_informAboutClearing = cleared;
200 p1->d->addRelatedProperty(p2);
203int KPropertySetPrivate::indexOfProperty(
const KProperty *property)
const
206 if (parentProperty) {
209 const int index = children->
indexOf(parentProperty);
210 Q_ASSERT(index != -1);
213 return indexOfPropertyInGroup(property);
216int KPropertySetPrivate::indexOfPropertyInGroup(
const KProperty *property)
const
220 if (!propertiesOfGroup) {
223 return propertiesOfGroup->
indexOf(property->
name());
229 if (!result.isEmpty())
236KPropertySelector::KPropertySelector()
240KPropertySelector::~KPropertySelector()
246typedef QPair<KProperty*, QString> Iterator_PropertyAndString;
248static inline bool Iterator_propertyAndStringLessThan(
249 const Iterator_PropertyAndString &n1,
const Iterator_PropertyAndString &n2)
272#define KPropertySetIteratorPrivateArgs(o) std::tie(o.set, o.iterator, o.end, o.selector, o.order, o.sorted)
273 void copy(
const Private &other) {
274 KPropertySetIteratorPrivateArgs((*
this)) = KPropertySetIteratorPrivateArgs(other);
277 return KPropertySetIteratorPrivateArgs((*
this)) == KPropertySetIteratorPrivateArgs(other);
280 void skipNotAcceptable()
285 if (q->current() && !(*selector)( *q->current() )) {
304 : d(new Private(this))
307 d->iterator = KPropertySetPrivate::d(&set)->listConstIterator();
308 d->end = KPropertySetPrivate::d(&set)->listConstEnd();
309 d->selector =
nullptr;
315 : d(new Private(this))
318 d->iterator = KPropertySetPrivate::d(&set)->listConstIterator();
319 d->end = KPropertySetPrivate::d(&set)->listConstEnd();
320 d->selector = selector.
clone();
322 d->skipNotAcceptable();
326 : d(new Private(this, *set.d))
332 if (
this != &other) {
340 return *d == *other.d;
343KPropertySetIterator::~KPropertySetIterator()
350 if (d->order ==
order)
358 d->iterator = KPropertySetPrivate::d(d->set)->listConstIterator();
359 d->end = KPropertySetPrivate::d(d->set)->listConstEnd();
360 for (; d->iterator!=d->end; ++d->iterator) {
364 captionOrName = prop->
caption();
369 propertiesAndStrings.
append( qMakePair(prop, captionOrName) );
371 std::sort(propertiesAndStrings.
begin(), propertiesAndStrings.
end(),
372 Iterator_propertyAndStringLessThan);
374 foreach (
const Iterator_PropertyAndString& propertyAndString, propertiesAndStrings) {
375 d->sorted.
append(propertyAndString.first);
385 d->iterator = KPropertySetPrivate::d(d->set)->listConstIterator();
386 d->end = KPropertySetPrivate::d(d->set)->listConstEnd();
388 d->skipNotAcceptable();
396KProperty* KPropertySetIterator::current()
const
398 return d->iterator == d->end ? nullptr : *d->iterator;
401void KPropertySetIterator::operator ++()
410 if ((*d->selector)( *current() ))
419 , d(new KPropertySetPrivate(this, true))
426 , d(new KPropertySetPrivate(this, true))
434 , d(new KPropertySetPrivate(this, propertyOwner))
438KPropertySet::~KPropertySet()
477 const KProperty *
property = d->property(propertyName);
483 return d->groupForProperty(&
property);
488 return d->groupNames();
499 d->setGroupCaption(group, caption);
504 return d->groupCaption(group);
509 d->setGroupIconName(group, iconName);
514 return d->groupIconName(group);
540 return d->visiblePropertiesCount() > 0;
558 if (d->readOnly != readOnly) {
559 d->readOnly = readOnly;
567 return d->property(name);
573 return d->propertyOrNull(name);
586 return d->propertyOrNull(name);
596 d->copyAttributesFrom(*set.d);
597 d->copyPropertiesFrom(set.d->listConstIterator(), set.d->listConstEnd(), set);
604 return p ? p->
value() : defaultValue;
622 dbg.
nospace() <<
"KPropertySet(";
624 dbg.
space() <<
"<EMPTY>)";
627 dbg.
nospace() <<
" PROPERTIES(" << set.
count() <<
"):\n";
632 for ( ; it.current(); ++it) {
639 dbg.
nospace() << *it.current();
647 return d->previousSelection();
652 d->setPreviousSelection(prevSelection);
659 result.
insert(it.current()->name(), it.current()->value());
667 it.current()->clearModifiedFlag();
674 if (it.current()->isModified()) {
An interface for functor selecting properties.
virtual KPropertySelector * clone() const =0
Creates a deep copy of the selector.
A class to iterate over a KPropertySet.
KPropertySetIterator(const KPropertySet &set)
Creates iterator for set set of properties.
void setOrder(Order order)
Sets order for properties. Restarts the iterator.
KPropertySetIterator & operator=(const KPropertySetIterator &other)
Assigns other to this KPropertySetIterator.
Order
Ordering options for properties.
@ AlphabeticalByName
alphabetical order (case-insensitively by name)
@ Insertion
insertion order
@ Alphabetical
alphabetical order (case-insensitively by captions)
bool operator==(const KPropertySetIterator &other) const
QVariant propertyValue(const QByteArray &name, const QVariant &defaultValue=QVariant()) const
KPropertySet & operator=(const KPropertySet &set)
void addProperty(KProperty *property, const QByteArray &group="common")
bool hasProperties(const KPropertySelector &selector) const
KProperty & property(const QByteArray &name) const
void changeProperty(const QByteArray &property, const QVariant &value)
KPropertySet(QObject *parent=nullptr)
Constructs a new property set object.
void changePropertyIfExists(const QByteArray &property, const QVariant &value)
QByteArray previousSelection() const
QString groupCaption(const QByteArray &group) const
QString groupIconName(const QByteArray &group) const
QByteArray groupNameForProperty(const QByteArray &propertyName) const
QMap< QByteArray, QVariant > propertyValues() const
void readOnlyFlagChanged()
void setGroupCaption(const QByteArray &group, const QString &caption)
bool hasVisibleProperties() const
QList< QByteArray > propertyNamesForGroup(const QByteArray &group) const
void setGroupIconName(const QByteArray &group, const QString &iconName)
bool isModified() const
Returns true if at least one property in this set is modified, i.e.
QList< QByteArray > groupNames() const
void removeProperty(KProperty *property)
void clearModifiedFlags()
Clears "modified" flag of all properties in this set, i.e.
KProperty & operator[](const QByteArray &name) const
void setReadOnly(bool readOnly)
bool contains(const QByteArray &name) const
void setPreviousSelection(const QByteArray &prevSelection)
Sets previous section.
The base class representing a single property.
bool setValue(const QVariant &value, ValueOptions options=ValueOptions())
Sets value of the property.
const QList< KProperty * > * children() const
KProperty * parent() const
QAction * end(const QObject *recvr, const char *slot, QObject *parent)
KIOCORE_EXPORT CopyJob * copy(const QList< QUrl > &src, const QUrl &dest, JobFlags flags=DefaultFlags)
bool operator==(const StyleDelim &l, const StyleDelim &r)
bool isEmpty() const const
QByteArray toLower() const const
void append(QList< T > &&value)
const_iterator constBegin() const const
const_iterator constEnd() const const
qsizetype indexOf(const AT &value, qsizetype from) const const
bool isEmpty() const const
void removeAt(qsizetype i)
T value(qsizetype i) const const
iterator insert(const Key &key, const T &value)
void setObjectName(QAnyStringView name)
QString tr(const char *sourceText, const char *disambiguation, int n)
int compare(QLatin1StringView s1, const QString &s2, Qt::CaseSensitivity cs)
bool isEmpty() const const