code format
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "qpiconfig.h"
|
||||
#include <QFileInfo>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
|
||||
int QString2int(const QString & string) {
|
||||
@@ -14,17 +15,17 @@ int QString2int(const QString & string) {
|
||||
QRect QString2QRect(const QString & string) {
|
||||
int sl, st, sw, sh;
|
||||
int s = 0, e;
|
||||
e = string.indexOf(";");
|
||||
sl = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
st = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
sw = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sh = string.mid(s, e - s).toInt();
|
||||
e = string.indexOf(";");
|
||||
sl = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
st = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
sw = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sh = string.mid(s, e - s).toInt();
|
||||
return QRect(sl, st, sw, sh);
|
||||
}
|
||||
|
||||
@@ -32,17 +33,17 @@ QRect QString2QRect(const QString & string) {
|
||||
QRectF QString2QRectF(const QString & string) {
|
||||
double sl, st, sw, sh;
|
||||
int s = 0, e;
|
||||
e = string.indexOf(";");
|
||||
sl = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
st = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
sw = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sh = string.mid(s, e - s).toDouble();
|
||||
e = string.indexOf(";");
|
||||
sl = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
st = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.indexOf(";", s);
|
||||
sw = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sh = string.mid(s, e - s).toDouble();
|
||||
return QRectF(sl, st, sw, sh);
|
||||
}
|
||||
|
||||
@@ -50,11 +51,11 @@ QRectF QString2QRectF(const QString & string) {
|
||||
QPoint QString2QPoint(const QString & string) {
|
||||
int sx, sy;
|
||||
int s = 0, e;
|
||||
e = string.indexOf(";");
|
||||
sx = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sy = string.mid(s, e - s).toInt();
|
||||
e = string.indexOf(";");
|
||||
sx = string.mid(s, e - s).toInt();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sy = string.mid(s, e - s).toInt();
|
||||
return QPoint(sx, sy);
|
||||
}
|
||||
|
||||
@@ -62,28 +63,24 @@ QPoint QString2QPoint(const QString & string) {
|
||||
QPointF QString2QPointF(const QString & string) {
|
||||
double sx, sy;
|
||||
int s = 0, e;
|
||||
e = string.indexOf(";");
|
||||
sx = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sy = string.mid(s, e - s).toDouble();
|
||||
e = string.indexOf(";");
|
||||
sx = string.mid(s, e - s).toDouble();
|
||||
s = e + 1;
|
||||
e = string.length();
|
||||
sy = string.mid(s, e - s).toDouble();
|
||||
return QPointF(sx, sy);
|
||||
}
|
||||
|
||||
|
||||
QString QRect2QString(const QRect & rect) {
|
||||
return QString::number(rect.left()) + ";" +
|
||||
QString::number(rect.top()) + ";" +
|
||||
QString::number(rect.width()) + ";" +
|
||||
QString::number(rect.height());
|
||||
return QString::number(rect.left()) + ";" + QString::number(rect.top()) + ";" + QString::number(rect.width()) + ";" +
|
||||
QString::number(rect.height());
|
||||
}
|
||||
|
||||
|
||||
QString QRectF2QString(const QRectF & rect) {
|
||||
return QString::number(rect.left()) + ";" +
|
||||
QString::number(rect.top()) + ";" +
|
||||
QString::number(rect.width()) + ";" +
|
||||
QString::number(rect.height());
|
||||
return QString::number(rect.left()) + ";" + QString::number(rect.top()) + ";" + QString::number(rect.width()) + ";" +
|
||||
QString::number(rect.height());
|
||||
}
|
||||
|
||||
|
||||
@@ -94,9 +91,11 @@ QPIConfig::Entry QPIConfig::Entry::_empty;
|
||||
QPIConfig::Branch QPIConfig::Branch::allLeaves() {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
foreach (Entry * i, *this) {
|
||||
if (i->isLeaf()) b << i;
|
||||
else allLeaves(b, i);
|
||||
foreach(Entry * i, *this) {
|
||||
if (i->isLeaf())
|
||||
b << i;
|
||||
else
|
||||
allLeaves(b, i);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
@@ -110,27 +109,27 @@ QPIConfig::Entry & QPIConfig::Branch::getValue(const QString & vname, const QStr
|
||||
return _empty;
|
||||
}
|
||||
QStringList tree = vname.split(delim);
|
||||
QString name = tree.front();
|
||||
QString name = tree.front();
|
||||
tree.pop_front();
|
||||
Entry * ce = 0;
|
||||
foreach (Entry * i, *this)
|
||||
foreach(Entry * i, *this)
|
||||
if (i->_name == name) {
|
||||
ce = i;
|
||||
break;
|
||||
}
|
||||
if (ce == 0) {
|
||||
_empty._name = vname;
|
||||
_empty._name = vname;
|
||||
_empty._value = def;
|
||||
_empty.delim = delim;
|
||||
_empty.delim = delim;
|
||||
if (exist != 0) *exist = false;
|
||||
return _empty;
|
||||
}
|
||||
foreach (QString i, tree) {
|
||||
foreach(QString i, tree) {
|
||||
ce = ce->findChild(i);
|
||||
if (ce == 0) {
|
||||
_empty._name = vname;
|
||||
_empty._name = vname;
|
||||
_empty._value = def;
|
||||
_empty.delim = delim;
|
||||
_empty.delim = delim;
|
||||
if (exist != 0) *exist = false;
|
||||
return _empty;
|
||||
}
|
||||
@@ -143,14 +142,12 @@ QPIConfig::Entry & QPIConfig::Branch::getValue(const QString & vname, const QStr
|
||||
QPIConfig::Branch QPIConfig::Branch::getValues(const QString & name) {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
foreach (Entry * i, *this) {
|
||||
foreach(Entry * i, *this) {
|
||||
if (i->isLeaf()) {
|
||||
if (i->_name.indexOf(name) >= 0)
|
||||
b << i;
|
||||
if (i->_name.indexOf(name) >= 0) b << i;
|
||||
} else {
|
||||
foreach (Entry * j, i->_children)
|
||||
if (j->_name.indexOf(name) >= 0)
|
||||
b << j;
|
||||
foreach(Entry * j, i->_children)
|
||||
if (j->_name.indexOf(name) >= 0) b << j;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
@@ -160,9 +157,8 @@ QPIConfig::Branch QPIConfig::Branch::getValues(const QString & name) {
|
||||
QPIConfig::Branch QPIConfig::Branch::getLeaves() {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
foreach (Entry * i, *this)
|
||||
if (i->isLeaf())
|
||||
b << i;
|
||||
foreach(Entry * i, *this)
|
||||
if (i->isLeaf()) b << i;
|
||||
return b;
|
||||
}
|
||||
|
||||
@@ -170,9 +166,8 @@ QPIConfig::Branch QPIConfig::Branch::getLeaves() {
|
||||
QPIConfig::Branch QPIConfig::Branch::getBranches() {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
foreach (Entry * i, *this)
|
||||
if (!i->isLeaf())
|
||||
b << i;
|
||||
foreach(Entry * i, *this)
|
||||
if (!i->isLeaf()) b << i;
|
||||
return b;
|
||||
}
|
||||
|
||||
@@ -190,10 +185,12 @@ QPIConfig::Branch & QPIConfig::Branch::filter(const QString & f) {
|
||||
|
||||
bool QPIConfig::Branch::entryExists(const Entry * e, const QString & name) const {
|
||||
if (e->_children.isEmpty()) {
|
||||
if (e->_name == name) return true;
|
||||
else return false;
|
||||
if (e->_name == name)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
foreach (Entry * i, e->_children)
|
||||
foreach(Entry * i, e->_children)
|
||||
if (entryExists(i, name)) return true;
|
||||
return false;
|
||||
}
|
||||
@@ -201,13 +198,13 @@ bool QPIConfig::Branch::entryExists(const Entry * e, const QString & name) const
|
||||
|
||||
QPIConfig::Entry & QPIConfig::Entry::getValue(const QString & vname, const QString & def, bool * exist) {
|
||||
QStringList tree = vname.split(delim);
|
||||
Entry * ce = this;
|
||||
foreach (QString i, tree) {
|
||||
Entry * ce = this;
|
||||
foreach(QString i, tree) {
|
||||
ce = ce->findChild(i);
|
||||
if (ce == 0) {
|
||||
_empty._name = vname;
|
||||
_empty._name = vname;
|
||||
_empty._value = def;
|
||||
_empty.delim = delim;
|
||||
_empty.delim = delim;
|
||||
if (exist != 0) *exist = false;
|
||||
return _empty;
|
||||
}
|
||||
@@ -220,19 +217,20 @@ QPIConfig::Entry & QPIConfig::Entry::getValue(const QString & vname, const QStri
|
||||
QPIConfig::Branch QPIConfig::Entry::getValues(const QString & vname) {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
foreach (Entry * i, _children)
|
||||
if (i->_name.indexOf(vname) >= 0)
|
||||
b << i;
|
||||
foreach(Entry * i, _children)
|
||||
if (i->_name.indexOf(vname) >= 0) b << i;
|
||||
return b;
|
||||
};
|
||||
|
||||
|
||||
bool QPIConfig::Entry::entryExists(const Entry * e, const QString & name) const {
|
||||
if (e->_children.isEmpty()) {
|
||||
if (e->_name == name) return true;
|
||||
else return false;
|
||||
if (e->_name == name)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
foreach (Entry * i, e->_children)
|
||||
foreach(Entry * i, e->_children)
|
||||
if (entryExists(i, name)) return true;
|
||||
return false;
|
||||
}
|
||||
@@ -273,7 +271,7 @@ QPIConfig::QPIConfig(const QString & path, QPIConfig::FileType type_): QFile(pat
|
||||
|
||||
QPIConfig::QPIConfig(QString * str, QPIConfig::FileType type_) {
|
||||
init();
|
||||
type = type_;
|
||||
type = type_;
|
||||
buffer = str;
|
||||
parse();
|
||||
}
|
||||
@@ -281,9 +279,9 @@ QPIConfig::QPIConfig(QString * str, QPIConfig::FileType type_) {
|
||||
|
||||
QPIConfig::QPIConfig(const QString & path, QStringList dirs) {
|
||||
init();
|
||||
type = Config;
|
||||
type = Config;
|
||||
internal = true;
|
||||
dev = new QFile(path);
|
||||
dev = new QFile(path);
|
||||
dev->open(QIODevice::ReadOnly);
|
||||
incdirs = dirs;
|
||||
incdirs << QFileInfo(path).absoluteDir().path();
|
||||
@@ -313,7 +311,7 @@ QPIConfig::QPIConfig(const QString & path, QStringList dirs) {
|
||||
QPIConfig::~QPIConfig() {
|
||||
stream.setDevice(0);
|
||||
root.deleteBranch();
|
||||
foreach (QPIConfig * c, inc_devs)
|
||||
foreach(QPIConfig * c, inc_devs)
|
||||
delete c;
|
||||
inc_devs.clear();
|
||||
includes.clear();
|
||||
@@ -321,13 +319,13 @@ QPIConfig::~QPIConfig() {
|
||||
|
||||
|
||||
void QPIConfig::init() {
|
||||
internal = false;
|
||||
buffer = 0;
|
||||
dev = 0;
|
||||
delim = ".";
|
||||
root._name = "root";
|
||||
root.delim = delim;
|
||||
empty.delim = delim;
|
||||
internal = false;
|
||||
buffer = 0;
|
||||
dev = 0;
|
||||
delim = ".";
|
||||
root._name = "root";
|
||||
root.delim = delim;
|
||||
empty.delim = delim;
|
||||
empty._parent = 0;
|
||||
}
|
||||
|
||||
@@ -335,8 +333,7 @@ void QPIConfig::init() {
|
||||
void QPIConfig::setFile(const QString & path, QIODevice::OpenMode mode) {
|
||||
buffer = 0;
|
||||
setFileName(path);
|
||||
if (open(mode))
|
||||
parse();
|
||||
if (open(mode)) parse();
|
||||
}
|
||||
|
||||
|
||||
@@ -357,26 +354,27 @@ void QPIConfig::setupCodec() {
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
stream.setCodec(codec.toLatin1().data());
|
||||
#else
|
||||
QString cn = codec.toLower().remove(' ').remove('-').trimmed();
|
||||
QString cn = codec.toLower().remove(' ').remove('-').trimmed();
|
||||
QStringConverter::Encoding sc = QStringConverter::System;
|
||||
if (cn == "utf8" ) sc = QStringConverter::Utf8 ;
|
||||
else if (cn == "utf16") sc = QStringConverter::Utf16;
|
||||
if (cn == "utf8")
|
||||
sc = QStringConverter::Utf8;
|
||||
else if (cn == "utf16")
|
||||
sc = QStringConverter::Utf16;
|
||||
stream.setEncoding(sc);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::Entry & QPIConfig::getValue(const QString & vname, const QString & def, bool * exist) {
|
||||
QStringList tree = vname.split(delim);
|
||||
Entry * ce = &root;
|
||||
foreach (QString i, tree) {
|
||||
Entry * ce = &root;
|
||||
foreach(QString i, tree) {
|
||||
ce = ce->findChild(i);
|
||||
if (ce == 0) {
|
||||
if (exist != 0) *exist = false;
|
||||
empty._name = vname;
|
||||
empty._name = vname;
|
||||
empty._value = def;
|
||||
empty.delim = delim;
|
||||
empty.delim = delim;
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
@@ -388,82 +386,85 @@ QPIConfig::Entry & QPIConfig::getValue(const QString & vname, const QString & de
|
||||
QPIConfig::Branch QPIConfig::getValues(const QString & vname) {
|
||||
Branch b;
|
||||
b.delim = delim;
|
||||
foreach (Entry * i, root._children)
|
||||
if (i->_name.indexOf(vname) >= 0)
|
||||
b << i;
|
||||
foreach(Entry * i, root._children)
|
||||
if (i->_name.indexOf(vname) >= 0) b << i;
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::Entry & QPIConfig::addEntry(const QString & name, const QString & value, const QString & type, bool write, bool node) {
|
||||
if (getValue(name)._parent != 0)
|
||||
return empty;
|
||||
QString sn = name, tn;
|
||||
if (getValue(name)._parent != 0) return empty;
|
||||
QString sn = name, tn;
|
||||
bool toRoot = false;
|
||||
while (sn.indexOf(delim) == 0) sn.remove(0, delim.length());
|
||||
while (sn.indexOf(delim) == 0)
|
||||
sn.remove(0, delim.length());
|
||||
QStringList tree = sn.split(delim);
|
||||
QString ename = tree.back();
|
||||
tn = tree.front();
|
||||
QString ename = tree.back();
|
||||
tn = tree.front();
|
||||
tree.pop_back();
|
||||
Entry * te, * ce, * entry = &root;
|
||||
Entry *te, *ce, *entry = &root;
|
||||
if (tree.isEmpty()) toRoot = true;
|
||||
foreach (QString i, tree) {
|
||||
foreach(QString i, tree) {
|
||||
te = entry->findChild(i);
|
||||
if (te == 0) {
|
||||
ce = new Entry();
|
||||
ce->delim = delim;
|
||||
ce->_tab = entry->_tab;
|
||||
ce->_line = entry->_line;
|
||||
ce->_name = i;
|
||||
ce->_parent = entry;
|
||||
//qDebug() << " [QPIC] add " + tn;
|
||||
ce = new Entry();
|
||||
ce->delim = delim;
|
||||
ce->_tab = entry->_tab;
|
||||
ce->_line = entry->_line;
|
||||
ce->_name = i;
|
||||
ce->_parent = entry;
|
||||
// qDebug() << " [QPIC] add " + tn;
|
||||
ce->_full_name = tn;
|
||||
entry->_children << ce;
|
||||
entry = ce;
|
||||
} else entry = te;
|
||||
} else
|
||||
entry = te;
|
||||
tn += delim + i;
|
||||
}
|
||||
QPIConfig::Branch ch = entry->_children;
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,13,0)
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
|
||||
qSort
|
||||
#else
|
||||
std::sort
|
||||
#endif
|
||||
(ch.begin(), ch.end(), QPIConfig::Entry::compare);
|
||||
te = (entry->isLeaf() ? 0 : ch.back());
|
||||
ce = new Entry();
|
||||
(ch.begin(), ch.end(), QPIConfig::Entry::compare);
|
||||
te = (entry->isLeaf() ? 0 : ch.back());
|
||||
ce = new Entry();
|
||||
ce->delim = delim;
|
||||
ce->_name = ename;
|
||||
if (!node) ce->_value = value;
|
||||
ce->_type = type;
|
||||
if (te == 0) {
|
||||
//qDebug() << "[QPIC] te == 0";
|
||||
// qDebug() << "[QPIC] te == 0";
|
||||
ce->_tab = entry->_tab;
|
||||
if (toRoot) ce->_line = other.size();
|
||||
if (toRoot)
|
||||
ce->_line = other.size();
|
||||
else {
|
||||
ch = entry->_parent->_children;
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,13,0)
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
|
||||
qSort
|
||||
#else
|
||||
std::sort
|
||||
#endif
|
||||
(ch.begin(), ch.end(), QPIConfig::Entry::compare);
|
||||
(ch.begin(), ch.end(), QPIConfig::Entry::compare);
|
||||
ce->_line = ch.back()->_line + 1;
|
||||
}
|
||||
} else {
|
||||
ce->_tab = te->_tab;
|
||||
if (toRoot) ce->_line = other.size();
|
||||
else ce->_line = te->_line + 1;
|
||||
if (toRoot)
|
||||
ce->_line = other.size();
|
||||
else
|
||||
ce->_line = te->_line + 1;
|
||||
}
|
||||
//qDebug() << "[QPIC] add " + sn + " at line " << ce->_line << ", parent " << entry->_name;
|
||||
// qDebug() << "[QPIC] add " + sn + " at line " << ce->_line << ", parent " << entry->_name;
|
||||
ce->_full_name = sn;
|
||||
ce->_parent = entry;
|
||||
ce->_parent = entry;
|
||||
entry->_children << ce;
|
||||
//qDebug() << "[QPIC] children " << entry->childCount();
|
||||
// qDebug() << "[QPIC] children " << entry->childCount();
|
||||
if (!node) {
|
||||
other.insert(ce->_line, "");
|
||||
Branch b = allLeaves();
|
||||
//qDebug() << "[QPIC] allLeaves " << b.size();
|
||||
Branch b = allLeaves();
|
||||
// qDebug() << "[QPIC] allLeaves " << b.size();
|
||||
bool found = false;
|
||||
for (int i = 0; i < b.size(); ++i) {
|
||||
if (found) {
|
||||
@@ -473,13 +474,12 @@ QPIConfig::Entry & QPIConfig::addEntry(const QString & name, const QString & val
|
||||
if (b[i] == ce) {
|
||||
found = true;
|
||||
if (i > 0)
|
||||
if (b[i - 1]->_line == b[i]->_line)
|
||||
b[i - 1]->_line++;
|
||||
if (b[i - 1]->_line == b[i]->_line) b[i - 1]->_line++;
|
||||
}
|
||||
//qDebug() << b[i]->_line;
|
||||
// qDebug() << b[i]->_line;
|
||||
}
|
||||
}
|
||||
//qDebug() << "[QPIC] add " + sn + " at line " << ce->_line << ", parent " + entry->_name;
|
||||
// qDebug() << "[QPIC] add " + sn + " at line " << ce->_line << ", parent " + entry->_name;
|
||||
if (write) writeAll();
|
||||
return *ce;
|
||||
}
|
||||
@@ -492,7 +492,7 @@ void QPIConfig::setValue(const QString & name, const QString & value, const QStr
|
||||
return;
|
||||
}
|
||||
e._value = value;
|
||||
e._type = type;
|
||||
e._type = type;
|
||||
if (write) writeAll();
|
||||
}
|
||||
|
||||
@@ -500,23 +500,22 @@ void QPIConfig::setValue(const QString & name, const QString & value, const QStr
|
||||
QPIConfig::Branch QPIConfig::allLeaves() {
|
||||
Branch b;
|
||||
allLeaves(b, &root);
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,13,0)
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
|
||||
qSort
|
||||
#else
|
||||
std::sort
|
||||
#endif
|
||||
(b.begin(), b.end(), Entry::compare);
|
||||
(b.begin(), b.end(), Entry::compare);
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
int QPIConfig::entryIndex(const QString & name) {
|
||||
QStringList tree = name.split(delim);
|
||||
Entry * ce = &root;
|
||||
foreach (QString i, tree) {
|
||||
Entry * ce = &root;
|
||||
foreach(QString i, tree) {
|
||||
ce = ce->findChild(i);
|
||||
if (ce == 0)
|
||||
return -1;
|
||||
if (ce == 0) return -1;
|
||||
}
|
||||
Branch b = allLeaves();
|
||||
return allLeaves().indexOf(ce);
|
||||
@@ -575,7 +574,7 @@ void QPIConfig::removeEntry(uint number, bool write) {
|
||||
|
||||
void QPIConfig::removeEntry(Branch & b, QPIConfig::Entry * e) {
|
||||
bool leaf = true;
|
||||
//qDebug() << " before " << b.size();
|
||||
// qDebug() << " before " << b.size();
|
||||
if (e->isLeaf()) other.removeAt(e->_line);
|
||||
if (!e->isLeaf() && !e->_value.isEmpty()) {
|
||||
e->_value.clear();
|
||||
@@ -597,7 +596,7 @@ void QPIConfig::removeEntry(Branch & b, QPIConfig::Entry * e) {
|
||||
if (ti >= 0) e->_parent->_children.remove(ti);
|
||||
ti = b.indexOf(e);
|
||||
if (ti >= 0) b.remove(ti);
|
||||
//qDebug() << " after " << b.size();
|
||||
// qDebug() << " after " << b.size();
|
||||
delete e;
|
||||
}
|
||||
|
||||
@@ -628,8 +627,7 @@ void QPIConfig::writeAll() {
|
||||
tprefix = getPrefixFromLine(other[i], &isPrefix);
|
||||
if (isPrefix) {
|
||||
prefix = tprefix;
|
||||
if (!prefix.isEmpty())
|
||||
prefix += delim;
|
||||
if (!prefix.isEmpty()) prefix += delim;
|
||||
}
|
||||
if (i < other.size() - 1) stream << '\n';
|
||||
}
|
||||
@@ -638,24 +636,28 @@ void QPIConfig::writeAll() {
|
||||
tprefix = getPrefixFromLine(other[i], &isPrefix);
|
||||
if (isPrefix) {
|
||||
prefix = tprefix;
|
||||
if (!prefix.isEmpty())
|
||||
prefix += delim;
|
||||
if (!prefix.isEmpty()) prefix += delim;
|
||||
}
|
||||
if (i < other.size() - 1) stream << '\n';
|
||||
}
|
||||
}
|
||||
if (buffer == 0)
|
||||
flush();
|
||||
if (buffer == 0) flush();
|
||||
readAll();
|
||||
}
|
||||
|
||||
|
||||
QString QPIConfig::getPrefixFromLine(QString line, bool * exists) {
|
||||
line = line.trimmed();
|
||||
if (line.left(1) == "#") {if (exists) *exists = false; return QString();}
|
||||
if (line.left(1) == "#") {
|
||||
if (exists) *exists = false;
|
||||
return QString();
|
||||
}
|
||||
int ci = line.indexOf("#");
|
||||
if (ci >= 0) line = line.left(ci).trimmed();
|
||||
if (line.indexOf("=") >= 0) {if (exists) *exists = false; return QString();}
|
||||
if (line.indexOf("=") >= 0) {
|
||||
if (exists) *exists = false;
|
||||
return QString();
|
||||
}
|
||||
if (line.indexOf("[") >= 0 && line.indexOf("]") >= 0) {
|
||||
if (exists) *exists = true;
|
||||
line.remove(0, 1);
|
||||
@@ -671,7 +673,7 @@ QString QPIConfig::writeAllToString() {
|
||||
QTextStream s(&str);
|
||||
buildFullNames(&root);
|
||||
Branch b = allLeaves();
|
||||
int j = 0;
|
||||
int j = 0;
|
||||
for (int i = 0; i < other.size(); ++i) {
|
||||
if (j >= 0 && j < b.size()) {
|
||||
if (b[j]->_line == i) {
|
||||
@@ -709,18 +711,19 @@ void QPIConfig::clear() {
|
||||
|
||||
|
||||
void QPIConfig::readAll() {
|
||||
if (buffer == 0)
|
||||
flush();
|
||||
if (buffer == 0) flush();
|
||||
parse();
|
||||
}
|
||||
|
||||
|
||||
bool QPIConfig::entryExists(const Entry * e, const QString & name) const {
|
||||
if (e->_children.isEmpty()) {
|
||||
if (e->_name == name) return true;
|
||||
else return false;
|
||||
if (e->_name == name)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
foreach (Entry * i, e->_children)
|
||||
foreach(Entry * i, e->_children)
|
||||
if (entryExists(i, name)) return true;
|
||||
return false;
|
||||
}
|
||||
@@ -729,7 +732,7 @@ bool QPIConfig::entryExists(const Entry * e, const QString & name) const {
|
||||
void QPIConfig::updateIncludes() {
|
||||
if (internal) return;
|
||||
all_includes.clear();
|
||||
foreach (QPIConfig * c, includes)
|
||||
foreach(QPIConfig * c, includes)
|
||||
all_includes << c->allLeaves();
|
||||
}
|
||||
|
||||
@@ -739,17 +742,17 @@ QString QPIConfig::parseLine(QString v) {
|
||||
while (1) {
|
||||
i = v.indexOf("${");
|
||||
if (i < 0) break;
|
||||
l = v.indexOf("}", i + 1);
|
||||
QString w = v.mid(i + 2, l - i - 2), r;
|
||||
l = w.length() + 3;
|
||||
w = parseLine(w);
|
||||
w = w.trimmed();
|
||||
bool ex = false;
|
||||
l = v.indexOf("}", i + 1);
|
||||
QString w = v.mid(i + 2, l - i - 2), r;
|
||||
l = w.length() + 3;
|
||||
w = parseLine(w);
|
||||
w = w.trimmed();
|
||||
bool ex = false;
|
||||
QPIConfig::Entry & me = getValue(w, "", &ex);
|
||||
if (ex) {
|
||||
r = me._value;
|
||||
} else {
|
||||
foreach (QPIConfig::Entry * e, all_includes) {
|
||||
foreach(QPIConfig::Entry * e, all_includes) {
|
||||
if (e->_full_name == w) {
|
||||
r = e->_value;
|
||||
break;
|
||||
@@ -767,10 +770,10 @@ void QPIConfig::parse(QString content) {
|
||||
root.clear();
|
||||
QString src, str, tab, comm, all, name, type, prefix, tprefix;
|
||||
QStringList tree;
|
||||
Entry * entry = 0, * te = 0, * ce = 0;
|
||||
Entry *entry = 0, *te = 0, *ce = 0;
|
||||
int ind, sind;
|
||||
bool isNew = false, isPrefix = false, wasMultiline = false, isMultiline = false;
|
||||
foreach (QPIConfig * c, inc_devs)
|
||||
foreach(QPIConfig * c, inc_devs)
|
||||
delete c;
|
||||
inc_devs.clear();
|
||||
includes.clear();
|
||||
@@ -790,15 +793,14 @@ void QPIConfig::parse(QString content) {
|
||||
while (!stream.atEnd()) {
|
||||
other.push_back(QString());
|
||||
src = str = parseLine(stream.readLine());
|
||||
tprefix = getPrefixFromLine(src, &isPrefix);
|
||||
tprefix = getPrefixFromLine(src, &isPrefix);
|
||||
if (isPrefix) {
|
||||
prefix = tprefix;
|
||||
if (!prefix.isEmpty())
|
||||
prefix += delim;
|
||||
if (!prefix.isEmpty()) prefix += delim;
|
||||
}
|
||||
tab = str.left(str.indexOf(str.trimmed().left(1)));
|
||||
str = str.trimmed();
|
||||
all = str;
|
||||
tab = str.left(str.indexOf(str.trimmed().left(1)));
|
||||
str = str.trimmed();
|
||||
all = str;
|
||||
|
||||
sind = str.indexOf('#');
|
||||
if (sind > 0) {
|
||||
@@ -806,7 +808,8 @@ void QPIConfig::parse(QString content) {
|
||||
if (comm.length() > 0) {
|
||||
type = comm[0];
|
||||
comm = comm.mid(1).trimmed();
|
||||
} else type = "s";
|
||||
} else
|
||||
type = "s";
|
||||
str = str.left(sind).trimmed();
|
||||
} else {
|
||||
type = "s";
|
||||
@@ -831,11 +834,11 @@ void QPIConfig::parse(QString content) {
|
||||
ce = 0;
|
||||
wasMultiline = isMultiline;
|
||||
|
||||
ind = str.indexOf('=');
|
||||
ind = str.indexOf('=');
|
||||
if ((ind > 0) && !(str[0] == '#')) {
|
||||
tree = (prefix + str.left(ind).trimmed()).split(delim);
|
||||
if (tree.front() == "include") {
|
||||
name = str.mid(ind + 1).trimmed();
|
||||
name = str.mid(ind + 1).trimmed();
|
||||
QPIConfig * iconf = new QPIConfig(name, incdirs);
|
||||
if (!iconf->dev) {
|
||||
delete iconf;
|
||||
@@ -849,39 +852,41 @@ void QPIConfig::parse(QString content) {
|
||||
name = tree.back();
|
||||
tree.pop_back();
|
||||
entry = &root;
|
||||
foreach (QString i, tree) {
|
||||
foreach(QString i, tree) {
|
||||
te = entry->findChild(i);
|
||||
if (te == 0) {
|
||||
ce = new Entry();
|
||||
ce->delim = delim;
|
||||
ce->_tab = tab;
|
||||
ce->_line = lines;
|
||||
ce->_name = i;
|
||||
ce = new Entry();
|
||||
ce->delim = delim;
|
||||
ce->_tab = tab;
|
||||
ce->_line = lines;
|
||||
ce->_name = i;
|
||||
ce->_parent = entry;
|
||||
entry->_children << ce;
|
||||
entry = ce;
|
||||
} else entry = te;
|
||||
} else
|
||||
entry = te;
|
||||
}
|
||||
isNew = false;
|
||||
ce = entry->findChild(name);
|
||||
ce = entry->findChild(name);
|
||||
if (ce == 0) {
|
||||
ce = new Entry();
|
||||
ce = new Entry();
|
||||
isNew = true;
|
||||
}
|
||||
ce->delim = delim;
|
||||
ce->_tab = tab;
|
||||
ce->_name = name;
|
||||
ce->_value = str.mid(ind + 1).trimmed();
|
||||
ce->_type = type;
|
||||
ce->delim = delim;
|
||||
ce->_tab = tab;
|
||||
ce->_name = name;
|
||||
ce->_value = str.mid(ind + 1).trimmed();
|
||||
ce->_type = type;
|
||||
ce->_comment = comm;
|
||||
ce->_line = lines;
|
||||
ce->_all = all;
|
||||
ce->_line = lines;
|
||||
ce->_all = all;
|
||||
if (isNew) {
|
||||
ce->_parent = entry;
|
||||
entry->_children << ce;
|
||||
}
|
||||
}
|
||||
} else other.back() = src;
|
||||
} else
|
||||
other.back() = src;
|
||||
lines++;
|
||||
}
|
||||
setEntryDelim(&root, delim);
|
||||
|
||||
Reference in New Issue
Block a user