File indexing completed on 2024-04-21 05:41:36
0001 /* 0002 This file is part of KCachegrind. 0003 0004 SPDX-FileCopyrightText: 2008-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> 0005 0006 SPDX-License-Identifier: GPL-2.0-only 0007 */ 0008 0009 #ifndef CONFIG_H 0010 #define CONFIG_H 0011 0012 #include <QString> 0013 #include <QVariant> 0014 0015 class ConfigStorage; 0016 0017 // helper functions for storing specific values 0018 QList<int> toIntList(QStringList l); 0019 QStringList toStringList(QList<int> l); 0020 0021 /** 0022 * A group of configuration settings. 0023 * Actual implementation for the backends is done in derived classes. 0024 */ 0025 class ConfigGroup 0026 { 0027 friend class ConfigStorage; 0028 0029 public: 0030 virtual ~ConfigGroup(); 0031 0032 // when value is defaultValue, any previous stored value is removed 0033 virtual void setValue(const QString& key, const QVariant& value, 0034 const QVariant& defaultValue = QVariant()); 0035 virtual QVariant value(const QString & key, 0036 const QVariant& defaultValue) const; 0037 0038 // the template version is needed for GUI Qt types 0039 template<typename T> 0040 inline T value(const QString & key, 0041 const QVariant & defaultValue = QVariant()) const 0042 { return qvariant_cast<T>( value(key, defaultValue) ); } 0043 0044 protected: 0045 ConfigGroup(); 0046 }; 0047 0048 /** 0049 * This is an adapter class for different configuration backends. 0050 * A singleton. 0051 */ 0052 0053 class ConfigStorage 0054 { 0055 public: 0056 ConfigStorage(); 0057 virtual ~ConfigStorage(); 0058 0059 // if second parameter is not-empty, first search for an existing 0060 // group using the optional suffix, and then without. 0061 // the group gets readonly. 0062 static ConfigGroup* group(const QString& group, 0063 const QString& optSuffix = QString()); 0064 static void setStorage(ConfigStorage*); 0065 static void cleanup(); 0066 0067 protected: 0068 virtual ConfigGroup* getGroup(const QString& group, 0069 const QString& optSuffix); 0070 0071 static ConfigStorage* _storage; 0072 }; 0073 0074 0075 #endif // CONFIG_H