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 #ifndef KPROPERTY_SET_P_H 23 #define KPROPERTY_SET_P_H 24 25 #include "KPropertySet.h" 26 #include "kproperty_debug.h" 27 28 class KPROPERTYCORE_EXPORT KPropertySetPrivate 29 { 30 public: 31 explicit KPropertySetPrivate(KPropertySet *set, bool isOwnProperty); 32 33 ~KPropertySetPrivate(); 34 35 //! Asccessor within the KProperty* d(KPropertySet * set)36 inline static KPropertySetPrivate* d(KPropertySet *set) { return set->d; } d(const KPropertySet * set)37 inline static const KPropertySetPrivate* d(const KPropertySet *set) { return set->d; } 38 visiblePropertiesCount()39 inline int visiblePropertiesCount() const { return m_visiblePropertiesCount; } 40 property(const QByteArray & name)41 inline KProperty* property(const QByteArray &name) const { 42 return m_hash.value(name.toLower()); 43 } 44 propertyOrNull(const QByteArray & name)45 inline KProperty& propertyOrNull(const QByteArray &name) const 46 { 47 KProperty *p = property(name); 48 if (p) 49 return *p; 50 m_nonConstNull.setName(nullptr); //to ensure returned property is null 51 kprWarning() << "PROPERTY" << name << "NOT FOUND"; 52 return m_nonConstNull; 53 } 54 55 void addProperty(KProperty *property, const QByteArray &group/*, bool updateSortingKey*/); 56 57 void removeProperty(KProperty *property); 58 59 void clear(); 60 count()61 inline int count() const { return m_list.count(); } 62 isEmpty()63 inline bool isEmpty() const { return m_list.isEmpty(); } 64 65 /*! @return @c true if there are groups explicitly defined. 66 In this case groups are displayed by the property editor. 67 If there is only one "common" group, it means that all properties belong to this group, 68 and no groups are displayed. 69 @since 3.1 */ 70 bool hasGroups() const; 71 groupForProperty(const KProperty * property)72 inline QByteArray groupForProperty(const KProperty *property) const { 73 return m_groupForProperties.value(const_cast<KProperty*>(property)); 74 } 75 setGroupCaption(const QByteArray & group,const QString & caption)76 inline void setGroupCaption(const QByteArray &group, const QString &caption) 77 { 78 m_groupCaptions.insert(group.toLower(), caption); 79 } 80 addPropertyToGroup(KProperty * property,const QByteArray & groupLower)81 inline void addPropertyToGroup(KProperty *property, const QByteArray &groupLower) { 82 m_groupForProperties.insert(property, groupLower); 83 } 84 removePropertyFromGroup(KProperty * property)85 inline void removePropertyFromGroup(KProperty *property) { 86 m_groupForProperties.remove(property); 87 } 88 89 //! Copy all attributes except complex ones 90 void copyAttributesFrom(const KPropertySetPrivate &other); 91 92 //! Copy all properties from the other set 93 void copyPropertiesFrom( 94 const QList<KProperty*>::ConstIterator& constBegin, 95 const QList<KProperty*>::ConstIterator& constEnd, const KPropertySet & set); 96 groupNames()97 QList<QByteArray> groupNames() const 98 { 99 return m_groupNames; 100 } 101 102 /*! Add property to a group.*/ 103 void addToGroup(const QByteArray &group, KProperty *property); 104 105 /*! Remove property from a group.*/ 106 void removeFromGroup(KProperty *property); 107 108 /*! Used to declare that \a property wants to be informed 109 that the set has been cleared (all properties are deleted) */ 110 void informAboutClearing(bool* cleared); 111 112 /*! Helper for Private class. */ 113 void addRelatedProperty(KProperty *p1, KProperty *p2) const; 114 listConstIterator()115 inline QList<KProperty*>::ConstIterator listConstIterator() const { 116 return m_list.constBegin(); 117 } 118 listConstEnd()119 inline QList<KProperty*>::ConstIterator listConstEnd() const { 120 return m_list.constEnd(); 121 } 122 123 /*! @return index of property @a property within its parent or group. */ 124 int indexOfProperty(const KProperty *property) const; 125 126 /*! @return index of property @a property within its group. */ 127 int indexOfPropertyInGroup(const KProperty *property) const; 128 129 QString groupCaption(const QByteArray &group) const; 130 setGroupIconName(const QByteArray & group,const QString & iconName)131 inline void setGroupIconName(const QByteArray &group, const QString& iconName) 132 { 133 m_groupIconNames.insert(group.toLower(), iconName); 134 } 135 groupIconName(const QByteArray & group)136 inline QString groupIconName(const QByteArray &group) const 137 { 138 return m_groupIconNames.value(group); 139 } 140 previousSelection()141 inline QByteArray previousSelection() const 142 { 143 return m_prevSelection; 144 } 145 setPreviousSelection(const QByteArray & prevSelection)146 inline void setPreviousSelection(const QByteArray &prevSelection) 147 { 148 m_prevSelection = prevSelection; 149 } 150 propertyNamesForGroup(const QByteArray & group)151 inline QList<QByteArray> *propertyNamesForGroup(const QByteArray &group) 152 { 153 return m_propertiesOfGroup.value(group); 154 } 155 groupName(int index)156 inline QByteArray groupName(int index) const 157 { 158 return m_groupNames.value(index); 159 } 160 indexOfGroup(const QByteArray & group)161 inline int indexOfGroup(const QByteArray &group) const 162 { 163 return m_groupNames.indexOf(group); 164 } 165 166 bool readOnly = false; 167 168 private: 169 KPropertySet *q; 170 171 //groups of properties: 172 // list of group name: (list of property names) 173 QMap<QByteArray, QList<QByteArray>* > m_propertiesOfGroup; 174 QList<QByteArray> m_groupNames; 175 QHash<QByteArray, QString> m_groupCaptions; 176 QHash<QByteArray, QString> m_groupIconNames; 177 // map of property: group 178 179 bool m_ownProperty; 180 QByteArray m_prevSelection; 181 182 mutable KProperty m_nonConstNull; 183 184 //! A list of properties, preserving their order, owner of KProperty objects 185 QList<KProperty*> m_list; 186 //! A hash of properties in form name -> property 187 QHash<QByteArray, KProperty*> m_hash; 188 QHash<KProperty*, QByteArray> m_groupForProperties; 189 int m_visiblePropertiesCount = 0; //!< Cache for optimization, 190 //!< used by @ref bool KPropertySet::hasVisibleProperties() 191 //! Used in KPropertySetPrivate::informAboutClearing(bool&) to declare that the property wants 192 //! to be informed that the set has been cleared (all properties are deleted) 193 bool* m_informAboutClearing = nullptr; 194 }; 195 196 #endif 197