24 #ifndef KCONFIGGROUP_H
25 #define KCONFIGGROUP_H
31 #include <QtCore/QExplicitlySharedDataPointer>
32 #include <QtCore/QVariant>
33 #include <QtCore/QStringList>
36 class KConfigGroupPrivate;
109 bool isValid()
const;
152 #ifndef KDE_NO_DEPRECATED
153 KDE_DEPRECATED
void changeGroup(
const QString &group);
161 #ifndef KDE_NO_DEPRECATED
162 KDE_DEPRECATED
void changeGroup(
const char *group);
176 void copyTo(
KConfigBase *other, WriteConfigFlags pFlags = Normal)
const;
193 void reparent(
KConfigBase *parent, WriteConfigFlags pFlags = Normal);
222 void deleteGroup(WriteConfigFlags pFlags = Normal);
247 template <
typename T>
251 template <
typename T>
253 {
return readCheck(key, aDefault); }
296 QVariantList
readEntry(
const QString &key,
const QVariantList &aDefault)
const;
298 QVariantList
readEntry(
const char *key,
const QVariantList &aDefault)
const;
328 {
return readListCheck(key, aDefault); }
357 QString readPathEntry(
const char *key,
const QString &aDefault)
const;
386 QString readEntryUntranslated(
const char *key,
399 WriteConfigFlags pFlags = Normal);
401 void writeEntry(
const char *key,
const QVariant &value,
402 WriteConfigFlags pFlags = Normal);
406 WriteConfigFlags pFlags = Normal);
408 void writeEntry(
const char *key,
const QString &value,
409 WriteConfigFlags pFlags = Normal);
413 WriteConfigFlags pFlags = Normal);
415 void writeEntry(
const char *key,
const QByteArray &value,
416 WriteConfigFlags pFlags = Normal);
419 void writeEntry(
const QString &key,
const char *value, WriteConfigFlags pFlags = Normal);
421 void writeEntry(
const char *key,
const char *value, WriteConfigFlags pFlags = Normal);
424 template <
typename T>
425 inline void writeEntry(
const char *key,
const T &value, WriteConfigFlags pFlags = Normal)
426 { writeCheck( key, value, pFlags ); }
428 template <
typename T>
434 WriteConfigFlags pFlags = Normal);
436 void writeEntry(
const char *key,
const QStringList &value,
437 WriteConfigFlags pFlags = Normal);
440 void writeEntry(
const QString &key,
const QVariantList &value,
441 WriteConfigFlags pFlags = Normal);
443 void writeEntry(
const char *key,
const QVariantList &value,
444 WriteConfigFlags pFlags = Normal);
447 template <
typename T>
451 template <
typename T>
453 { writeListCheck( key, value, pFlags ); }
466 WriteConfigFlags pFlags = Normal);
468 void writeXdgListEntry(
const char *pKey,
const QStringList &value,
469 WriteConfigFlags pFlags = Normal);
485 WriteConfigFlags pFlags = Normal);
487 void writePathEntry(
const char *pKey,
const QString &path,
488 WriteConfigFlags pFlags = Normal);
504 WriteConfigFlags pFlags = Normal);
506 void writePathEntry(
const char *pKey,
const QStringList &value,
507 WriteConfigFlags pFlags = Normal);
519 void deleteEntry(
const QString &pKey, WriteConfigFlags pFlags = Normal);
521 void deleteEntry(
const char *pKey, WriteConfigFlags pFlags = Normal);
538 bool hasKey(
const QString &key)
const;
540 bool hasKey(
const char *key)
const;
559 bool isEntryImmutable(
const QString &key)
const;
561 bool isEntryImmutable(
const char *key)
const;
579 void revertToDefault(
const QString &key);
581 void revertToDefault(
const char* key);
610 bool hasDefault(
const QString &key)
const;
612 bool hasDefault(
const char *key)
const;
641 inline void writeCheck(
const char *key,
const T &value, WriteConfigFlags pFlags);
644 inline void writeListCheck(
const char *key,
const QList<T> &value, WriteConfigFlags pFlags);
646 friend class KConfigGroupPrivate;
661 #define KCONFIGGROUP_ENUMERATOR_ERROR(ENUM) \
662 "The Qt MetaObject system does not seem to know about \"" ENUM \
663 "\" please use Q_ENUMS or Q_FLAGS to register it."
676 #define KCONFIGGROUP_DECLARE_ENUM_QOBJECT(Class, Enum) \
677 inline Class::Enum readEntry(const KConfigGroup& group, const char* key, const Class::Enum& def) \
679 const QMetaObject* M_obj = &Class::staticMetaObject; \
680 const int M_index = M_obj->indexOfEnumerator(#Enum); \
681 kFatal(M_index == -1) << KCONFIGGROUP_ENUMERATOR_ERROR(#Enum) << endl; \
682 const QMetaEnum M_enum = M_obj->enumerator(M_index); \
683 const QByteArray M_data = group.readEntry(key, QByteArray(M_enum.valueToKey(def)));\
684 return static_cast<Class::Enum>(M_enum.keyToValue(M_data.constData())); \
686 inline void writeEntry(KConfigGroup& group, const char* key, const Class::Enum& value, KConfigBase::WriteConfigFlags flags = KConfigBase::Normal)\
688 const QMetaObject* M_obj = &Class::staticMetaObject; \
689 const int M_index = M_obj->indexOfEnumerator(#Enum); \
690 kFatal(M_index == -1) << KCONFIGGROUP_ENUMERATOR_ERROR(#Enum) << endl; \
691 const QMetaEnum M_enum = M_obj->enumerator(M_index); \
692 group.writeEntry(key, QByteArray(M_enum.valueToKey(value)), flags); \
699 #define KCONFIGGROUP_DECLARE_FLAGS_QOBJECT(Class, Flags) \
700 inline Class::Flags readEntry(const KConfigGroup& group, const char* key, const Class::Flags& def) \
702 const QMetaObject* M_obj = &Class::staticMetaObject; \
703 const int M_index = M_obj->indexOfEnumerator(#Flags); \
704 kFatal(M_index == -1) << KCONFIGGROUP_ENUMERATOR_ERROR(#Flags) << endl; \
705 const QMetaEnum M_enum = M_obj->enumerator(M_index); \
706 const QByteArray M_data = group.readEntry(key, QByteArray(M_enum.valueToKeys(def)));\
707 return static_cast<Class::Flags>(M_enum.keysToValue(M_data.constData())); \
709 inline void writeEntry(KConfigGroup& group, const char* key, const Class::Flags& value, KConfigBase::WriteConfigFlags flags = KConfigBase::Normal)\
711 const QMetaObject* M_obj = &Class::staticMetaObject; \
712 const int M_index = M_obj->indexOfEnumerator(#Flags); \
713 kFatal(M_index == -1) << KCONFIGGROUP_ENUMERATOR_ERROR(#Flags) << endl; \
714 const QMetaEnum M_enum = M_obj->enumerator(M_index); \
715 group.writeEntry(key, QByteArray(M_enum.valueToKeys(value)), flags); \
720 template <
typename T>
721 T KConfigGroup::readCheck(
const char *key,
const T &
defaultValue)
const
723 ConversionCheck::to_QVariant<T>();
724 return qvariant_cast<
T>(
readEntry(key, qVariantFromValue(defaultValue)));
727 template <
typename T>
730 ConversionCheck::to_QVariant<T>();
731 ConversionCheck::to_QString<T>();
735 Q_FOREACH(
const T& value, defaultValue)
736 data.append(qVariantFromValue(value));
740 Q_ASSERT(qVariantCanConvert<T>(value));
741 list.append(qvariant_cast<T>(value));
747 template <
typename T>
748 void KConfigGroup::writeCheck(
const char *key,
const T &value,
749 WriteConfigFlags pFlags)
751 ConversionCheck::to_QVariant<T>();
752 writeEntry(key, qVariantFromValue(value), pFlags);
755 template <
typename T>
756 void KConfigGroup::writeListCheck(
const char *key,
const QList<T> &list,
757 WriteConfigFlags pFlags)
759 ConversionCheck::to_QVariant<T>();
760 ConversionCheck::to_QString<T>();
762 Q_FOREACH(
const T &value, list) {
763 data.append(qVariantFromValue(value));
769 #endif // KCONFIGGROUP_H
Can be used to control the lifetime of an object that has derived QSharedData.
KAutostart::StartPhase readEntry(const KConfigGroup &group, const char *key, const KAutostart::StartPhase &aDefault)
KConfig variant using shared memory.
KSharedPtr< KSharedConfig > KSharedConfigPtr
void deleteGroup(const QByteArray &group, WriteConfigFlags flags=Normal)
Delete aGroup.
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
Writes a value to the configuration object.
KSharedConfigPtr config()
Returns the general config object.
virtual bool isGroupImmutableImpl(const QByteArray &aGroup) const =0
virtual AccessMode accessMode() const =0
Returns the access mode of the app-config object.
const char * constData() const
virtual KConfigGroup groupImpl(const QByteArray &b)=0
void writeEntry(const char *key, const T &value, WriteConfigFlags pFlags=Normal)
Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags)
virtual void deleteGroupImpl(const QByteArray &group, WriteConfigFlags flags=Normal)=0
void writeEntry(const QString &key, const QList< T > &value, WriteConfigFlags pFlags=Normal)
Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags)
QList< T > readEntry(const char *key, const QList< T > &aDefault) const
Overload for readEntry(const QString&, const QList&)
A class for one specific group in a KConfig object.
The central class of the KDE configuration data system.
void writeEntry(const char *key, const QList< T > &value, WriteConfigFlags pFlags=Normal)
Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags)
QList< T > readEntry(const QString &key, const QList< T > &aDefault) const
Reads a list of values from the config object.
virtual void sync()=0
Syncs the configuration object that this group belongs to.
AccessMode
Possible return values for accessMode().
virtual bool hasGroupImpl(const QByteArray &group) const =0
void writeEntry(const QString &key, const T &value, WriteConfigFlags pFlags=Normal)
Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags)
virtual bool isImmutable() const =0
Checks whether this configuration object can be modified.
virtual void markAsClean()=0
Reset the dirty flags of all entries in the entry map, so the values will not be written to disk on a...
T readEntry(const QString &key, const T &aDefault) const
Reads the value of an entry specified by pKey in the current group.
virtual QStringList groupList() const =0
Returns a list of groups that are known about.
T readEntry(const char *key, const T &aDefault) const
Overload for readEntry(const QString&, const T&) const.
QString defaultValue(const QString &t)
QByteArray toUtf8() const