From 7d057898199c1b08d4cebfde899c79f7299292c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Thu, 12 Sep 2019 09:43:57 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/libs@588 a8b55f48-bf90-11e4-a774-851b48703e85 --- qad/utils/qpiconfig.cpp | 34 ++++++++++++++++++++++++---------- qad/utils/qpiconfig.h | 6 ++++-- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/qad/utils/qpiconfig.cpp b/qad/utils/qpiconfig.cpp index bbd1cd2..1c655c2 100644 --- a/qad/utils/qpiconfig.cpp +++ b/qad/utils/qpiconfig.cpp @@ -241,27 +241,33 @@ bool QPIConfig::Entry::entryExists(const Entry * e, const QString & name) const QPIConfig::QPIConfig(const QString & path, QIODevice::OpenMode mode, QPIConfig::FileType type_): QFile(path) { init(); type = type_; - open(mode); - //stream.setDevice(this); - parse(); + if (!path.isEmpty()) { + open(mode); + //stream.setDevice(this); + parse(); + } } QPIConfig::QPIConfig(const QString & path, QIODevice::OpenMode mode): QFile(path) { init(); type = Config; - open(mode); - //stream.setDevice(this); - parse(); + if (!path.isEmpty()) { + open(mode); + //stream.setDevice(this); + parse(); + } } QPIConfig::QPIConfig(const QString & path, QPIConfig::FileType type_): QFile(path) { init(); type = type_; - open(QIODevice::ReadWrite); - //stream.setDevice(this); - parse(); + if (!path.isEmpty()) { + open(QIODevice::ReadWrite); + //stream.setDevice(this); + parse(); + } } @@ -340,6 +346,13 @@ void QPIConfig::setString(QString * str) { } +void QPIConfig::setCodec(const char * codecName) { + codec = codecName; + stream.setCodec(codecName); + parse(); +} + + QPIConfig::Entry & QPIConfig::getValue(const QString & vname, const QString & def, bool * exist) { QStringList tree = vname.split(delim); Entry * ce = &root; @@ -740,6 +753,8 @@ void QPIConfig::parse(QString content) { stream.seek(0); other.clear(); lines = centry = 0; + if (!codec.isEmpty()) + stream.setCodec(codec.toLatin1().data()); while (!stream.atEnd()) { other.push_back(QString()); src = str = parseLine(stream.readLine()); @@ -749,7 +764,6 @@ void QPIConfig::parse(QString content) { if (!prefix.isEmpty()) prefix += delim; } - //cout << str << endl; tab = str.left(str.indexOf(str.trimmed().left(1))); str = str.trimmed(); all = str; diff --git a/qad/utils/qpiconfig.h b/qad/utils/qpiconfig.h index 1c8a267..f15a94d 100644 --- a/qad/utils/qpiconfig.h +++ b/qad/utils/qpiconfig.h @@ -66,6 +66,8 @@ public: void setFile(const QString & path, QIODevice::OpenMode mode = QIODevice::ReadWrite); void setString(QString * str); + void setCodec(const char * codecName); + class Entry; class Branch: public QVector { @@ -102,7 +104,7 @@ public: friend class QPIConfigWidget; friend class ConfigValueWidget; public: - Entry() {_parent = 0; _line = -1;} + Entry() {_parent = 0; _line = -1;} Entry * parent() const {return _parent;} int childCount() {return _children.size();} @@ -269,7 +271,7 @@ private: Branch all_includes; QFile * dev; QStringList incdirs; - QString delim, * buffer; + QString delim, * buffer, codec; Entry root, empty; uint lines; QStringList other;