as_pref.h

Thu, 06 Aug 2009 13:21:30 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 06 Aug 2009 13:21:30 +0200
changeset 15
0e0eb7c91312
permissions
-rw-r--r--

Remove seemingly declarations unnecessary according to Qt 4.5.2 headers.

michael@1 1 /***************************************************************************
michael@1 2 preferences.h
michael@1 3 -------------------
michael@1 4 A class to access persistant preferences for an application. Utilizes XML/DOM.
michael@1 5 Basic format is:
michael@1 6 <!DOCTYPE preferences>
michael@1 7 <preferences version="0.1" application="MyApp" >
michael@1 8 <group name="Default" >
michael@1 9 <option key="alpha" value="true" />
michael@1 10 <option key="beta" value="99" />
michael@1 11 <option key="gamma" value="test" />
michael@1 12 </group>
michael@1 13 </preferences>
michael@1 14 -------------------
michael@1 15 begin Tue Sep 12 2000
michael@1 16 author David Johnson, david@usermode.org
michael@1 17 -------------------
michael@1 18 Copyright 2000, David Johnson
michael@1 19 All rights reserved.
michael@1 20
michael@1 21 Redistribution and use in source and binary forms, with or without
michael@1 22 modification, are permitted provided that the following conditions are met:
michael@1 23
michael@1 24 1. Redistributions of source code must retain the above copyright notice, this
michael@1 25 list of conditions and the following disclaimer.
michael@1 26
michael@1 27 2. Redistributions in binary form must reproduce the above copyright notice,
michael@1 28 this list of conditions and the following disclaimer in the documentation
michael@1 29 and/or other materials provided with the distribution.
michael@1 30
michael@1 31 3. Neither name of the copyright holders nor the names of its contributors may
michael@1 32 be used to endorse or promote products derived from this software without
michael@1 33 specific prior written permission.
michael@1 34
michael@1 35 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
michael@1 36 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
michael@1 37 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
michael@1 38 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
michael@1 39 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
michael@1 40 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
michael@1 41 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
michael@1 42 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
michael@1 43 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
michael@1 44 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@1 45 ***************************************************************************/
michael@1 46
michael@1 47 // version 2
michael@1 48
michael@1 49 #ifndef PREFERENCES_H
michael@1 50 #define PREFERENCES_H
michael@1 51
michael@1 52 #include <qapplication.h>
michael@1 53 #include <qstring.h>
michael@1 54 #include <qmap.h>
michael@1 55
michael@1 56 class QDomElement;
michael@1 57
michael@1 58 class Preferences {
michael@1 59 public:
michael@1 60 // constructor
michael@1 61 Preferences(const QString& filename, const QString& format, const QString& version);
michael@1 62 // destructor
michael@1 63 virtual ~Preferences(void);
michael@1 64
michael@1 65 // preference file information
michael@1 66 const QString& file();
michael@1 67 const QString& format();
michael@1 68 const QString& version();
michael@1 69 // did file open successfully?
michael@1 70 bool fileState();
michael@1 71 // is this a proper preferences file for format?
michael@1 72 bool formatState();
michael@1 73
michael@1 74 // group settings
michael@1 75 const QString& getGroup();
michael@1 76 void setGroup(const QString& group);
michael@1 77
michael@1 78 // boolean data storage
michael@1 79 bool getBool(const QString& key, bool def = false);
michael@1 80 void setBool(const QString& key, bool value);
michael@1 81 // integer data storage
michael@1 82 long getNumber(const QString& key, long def = 0);
michael@1 83 void setNumber(const QString& key, long value);
michael@1 84 // double data storage
michael@1 85 double getDouble(const QString& key, double def = 0.0);
michael@1 86 void setDouble(const QString& key, double value);
michael@1 87 // string data storage
michael@1 88 QString getString(const QString& key, const QString& def = "NULL");
michael@1 89 void setString(const QString& key, const QString& value);
michael@1 90
michael@1 91 // remove a key/value from the preferences
michael@1 92 void removeKey(const QString& key);
michael@1 93 // remove the current group from the preferences
michael@1 94 void removeGroup();
michael@1 95
michael@1 96 // flush the preferences out to file
michael@1 97 void flush();
michael@1 98
michael@1 99 protected:
michael@1 100 // serialization
michael@1 101 void readData();
michael@1 102 void writeData();
michael@1 103 void processGroup(QDomElement group);
michael@1 104
michael@1 105 private:
michael@1 106 bool dirty_;
michael@1 107 QString currentgroup_;
michael@1 108 QString file_;
michael@1 109 QString format_;
michael@1 110 QString version_;
michael@1 111 QString buffer_;
michael@1 112 bool filestate_;
michael@1 113 bool formatstate_;
michael@1 114
michael@1 115 typedef QMap<QString, QString> PrefMap;
michael@1 116 QMap<QString, PrefMap> groups_;
michael@1 117 };
michael@1 118
michael@1 119 //////////////////////////////////////////////////////////////////////////////
michael@1 120 // Inline methods
michael@1 121
michael@1 122 inline const QString& Preferences::file() { return file_; };
michael@1 123
michael@1 124 inline const QString& Preferences::format() { return format_; }
michael@1 125
michael@1 126 inline bool Preferences::fileState() { return filestate_; }
michael@1 127
michael@1 128 inline bool Preferences::formatState() { return formatstate_; }
michael@1 129
michael@1 130 inline void Preferences::setGroup(const QString& group) { currentgroup_ = group; }
michael@1 131
michael@1 132 inline const QString& Preferences::getGroup() { return currentgroup_; }
michael@1 133
michael@1 134 #endif // PREFERENCES

mercurial