Trade equipment common library.  1.0.0
teinifile.h
1 /****************************************************************************
2 ** $Id: teinifile.h,v 1.10 2006/07/07 08:55:50 red75 Exp $
3 **
4 ** Trade equipment common portable library project
5 **
6 ** Copyright (C) 1999-2006 Leader InfoTech. All rights reserved.
7 **
8 ** This file is part of the Library of the Ananas
9 ** automation accounting system.
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 as published by the Free Software
13 ** Foundation and appearing in the file LICENSE.GPL included in the
14 ** packaging of this file.
15 **
16 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
17 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 **
19 ** See http://www.leaderit.ru/ or email sales@leaderit.ru
20 **
21 ** Contact org@leaderit.ru if any conditions of this licensing are
22 ** not clear to you.
23 **
24 **********************************************************************/
25 
26 // TEIniFile 1.1
27 //
28 // Supports storing/reading parameters in text configuration files (like .ini)
29 //
30 // (c) Racheengel 2004-2005
31 #ifndef TEINIFILE_H
32 #define TEINIFILE_H
33 
34 #include <qvariant.h>
35 #include <qwidget.h>
36 #include <qfile.h>
37 #include <qstring.h>
38 #include <qstringlist.h>
39 #include <qtextstream.h>
40 #include <qmap.h>
41 #include <qcolor.h>
42 #include <qrect.h>
43 #include "teglobal.h"
44 
45 typedef QMap<QString, QString> type_ValueList;
46 typedef QMapIterator<QString, QString> type_ValueListIterator;
47 
48 #include "templexports.h"
49 
50 class LIB_EXPORT TEIniFile
51 {
52 public:
53  TEIniFile(const QString &name = QString::null);
54  ~TEIniFile();
55 
56  void setFileName(const QString &name);
57  QString fileName() const {return f.name();}
58  bool openWrite();
59  bool openRead();
60  void close();
61 
62  void writeBreak();
63  void writeSection(const QString &section);
64  void writeComment(const QString &comment);
65  void writeString(const QString &name, const QString &value);
66  void writeData(const QString &name, const QString &value);
67  void writeNumber(const QString &name, const int value, const int base = 10);
68  void writeStringList(const QString &name, const QStringList &value);
69  void writeDataList(const QString &name, const QStringList &value);
70  void writeBool(const QString &name, const bool value);
71  void writeColor(const QString &name, const QColor& color);
72  void writeRect(const QString &name, const QRect& rect);
73 
74  bool sectionExists(const QString &section)
75  { return SectionList.contains(section); }
76  bool useSection(const QString &section);
77  const QString& readString(const QString &name, const QString &def = QString::null);
78  int readNumber(const QString &name, const int def = 0, const int base = 10);
79  bool readBool(const QString &name, const bool def = false);
80  const QColor& readColor(const QString &name, const QColor& def = QColor());
81  const QRect& readRect(const QString &name, const QRect& def = QRect());
82 
83  void setString(const QString &name, const QString &value);
84  void setData(const QString &name, const QString &value);
85  void setNumber(const QString &name, const int value, const int base = 10);
86  void setStringList(const QString &name, const QStringList &value);
87  void setDataList(const QString &name, const QStringList &value);
88  void setBool(const QString &name, const bool value);
89  void setColor(const QString &name, const QColor& color);
90  void setRect(const QString &name, const QRect& rect);
91 
93  void deleteName(const QString &name);
94 
95  bool isNameExists(const QString &name);
96  // These functions return true if readXXX function was called with the same /name/ value already.
97  bool getString(const QString & name, QString & value);
98 // bool getData(const QString & name, QString & value);
99  bool getNumber(const QString & name, int & value, const int base=10);
100  bool getBool(const QString & name, bool & value);
101 
102  bool update();
103 
104  QStringList usedValues();
105 protected:
106  QTextStream ts;
107  QFile f;
108  QMap<QString, type_ValueList> SectionList;
109  QMap<QString, type_ValueList> SectionListDef;
110  QMapIterator<QString, type_ValueList> mi;
111  QString m_sCurSection;
112  bool m_break;
113 };
114 
115 #endif
Supports storing/reading parameters in text configuration files (like .ini).
Definition: teinifile.h:50