git-svn-id: svn://db.shs.com.ru/libs@116 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -33,7 +33,7 @@ public:
|
||||
EVENT_HANDLER(void, K_Send);
|
||||
EVENT_HANDLER(void, K_Request);
|
||||
|
||||
mutable CDSection k_;
|
||||
CDSection k_;
|
||||
|
||||
void k_write(PIIODevice * d);
|
||||
void k_read(PIIODevice * d);
|
||||
|
||||
@@ -33,9 +33,9 @@ const CDType KInterface::operator [](int v) const {
|
||||
|
||||
|
||||
CDSection & KInterface::section(int v) {
|
||||
CDSection & ret = core->k_.section(v);
|
||||
piCout << "[get section]" << v << ret.name;
|
||||
return ret;
|
||||
// CDSection & ret = core->k_.section(v);
|
||||
// piCout << "[get section]" << v << ret.name;
|
||||
return core->k_.section(v);
|
||||
}
|
||||
|
||||
const CDSection KInterface::section(int v) const {
|
||||
@@ -43,43 +43,17 @@ const CDSection KInterface::section(int v) const {
|
||||
}
|
||||
|
||||
|
||||
//CDSection & KInterface::section(const PIDeque<int> &path) {
|
||||
// piCout << "error"; return root();
|
||||
// PIDeque<int> spath = path;
|
||||
// CDSection & rs = core->k_;
|
||||
// CDSection trs = rs;
|
||||
// piCout << "[get section from path]" << path << rs.name;
|
||||
// PIString tab;
|
||||
// while (!spath.isEmpty()) {
|
||||
// piCout << "!1" << tab << rs.alias << rs.name;
|
||||
// rs = rs.section(spath.take_front());
|
||||
// tab += " ";
|
||||
//// rs = trs;
|
||||
// }
|
||||
// piCout << "!2" << tab << rs.alias << rs.name;
|
||||
// return rs;
|
||||
//}
|
||||
|
||||
|
||||
const CDSection KInterface::section(const PIDeque<int> &path) const {
|
||||
CDSection & KInterface::section(const PIDeque<int> &path) {
|
||||
PIDeque<int> spath = path;
|
||||
CDSection rs = core->k_;
|
||||
CDSection trs = rs;
|
||||
//piCout << "[get section from path]" << path << rs.name;
|
||||
PIString tab;
|
||||
CDSection * rs = &core->k_;
|
||||
while (!spath.isEmpty()) {
|
||||
//piCout << "!1" << tab << rs.alias << rs.name;
|
||||
trs = rs.section(spath.take_front());
|
||||
tab += " ";
|
||||
rs = trs;
|
||||
rs = &rs->section(spath.take_front());
|
||||
}
|
||||
//piCout << "!2" << tab << rs.alias << rs.name;
|
||||
return rs;
|
||||
return *rs;
|
||||
}
|
||||
|
||||
|
||||
CDSection & KInterface::root() {
|
||||
piCout << "[root]" << core->k_.name;
|
||||
return core->k_;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,7 @@ public:
|
||||
const CDType operator [](int v) const;
|
||||
CDSection & section(int v);
|
||||
const CDSection section(int v) const;
|
||||
// CDSection & section(const PIDeque<int> &path);
|
||||
const CDSection section(const PIDeque<int> &path) const;
|
||||
CDSection & section(const PIDeque<int> &path);
|
||||
CDSection & root();
|
||||
const CDSection root() const;
|
||||
|
||||
|
||||
@@ -36,7 +36,19 @@ CDType::CDType(int i, const PIString & n, const PIString & t, const PIString & v
|
||||
// piCout << comment_.size() << comment_.toUTF8();
|
||||
// debug_cnt = cdtype_debug_cnt;
|
||||
// cdtype_debug_cnt++;
|
||||
// piCout << "[CDType] create" << debug_cnt << index_ << ":" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ << ":" << (cd_type_ == cdK);
|
||||
// piCout << "[CDType] create" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ << ":" << (cd_type_ == cdK);
|
||||
}
|
||||
|
||||
|
||||
PIString CDType::type() const {
|
||||
if (type_.trimmed().isEmpty()) return "f";
|
||||
// piCout << "type =" << type_.trimmed() << ";" << type_ << "#";
|
||||
return type_;
|
||||
}
|
||||
|
||||
|
||||
void CDType::setFormula(const PIString &f) {
|
||||
formula_ = f;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,9 +109,9 @@ int CDSection::sectionsCount() const {
|
||||
|
||||
PIStringList CDSection::index_names() const {
|
||||
PIStringList ret;
|
||||
PIMap<int, CDType>::iterator i;
|
||||
PIMap<int, CDType>::const_iterator i;
|
||||
for (i = k.begin(); i != k.end(); ++i)
|
||||
ret << i.value().name();
|
||||
ret << i->second.name();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -114,6 +126,10 @@ void CDSection::write(PIIODevice * d, const PIString & prefix) {
|
||||
else l = "[" + prefix + ".k]";
|
||||
l += "\n";
|
||||
d->write(l.toUTF8());
|
||||
l = "name = " + name + " \n";
|
||||
d->write(l.toUTF8());
|
||||
l = "alias = " + alias + " \n";
|
||||
d->write(l.toUTF8());
|
||||
PIMap<int, CDType>::iterator i;
|
||||
for (i = k.begin(); i != k.end(); ++i) {
|
||||
CDType & ck(i.value());
|
||||
@@ -146,21 +162,23 @@ void CDSection::read(const void * ep) {
|
||||
k.clear();
|
||||
s.clear();
|
||||
PIConfig::Entry & e(*(PIConfig::Entry*)ep);
|
||||
name = e.getValue("k.name").value();
|
||||
alias = e.getValue("k.alias").value();
|
||||
PIConfig::Entry & kl = e.getValue("k");
|
||||
for (int i = 0; i < kl.childCount(); ++i) {
|
||||
const PIConfig::Entry * ke(kl.child(i));
|
||||
int kid = ke->name().toInt();
|
||||
bool ok = false;
|
||||
int kid = ke->name().toInt(-1, &ok);
|
||||
// piCout << "[read]" << ke->name() << ke->value() << ok;
|
||||
// PIString n = ke->getValue("v").comment();
|
||||
// PIString t = n.takeLeft(1);
|
||||
k[kid] = CDType(kid, ke->getValue("v").comment(), ke->getValue("v").type(), ke->getValue("v").value(), ke->getValue("f").value(), ke->getValue("f").comment(), CDType::cdK);
|
||||
if (ok) k[kid] = CDType(kid, ke->getValue("v").comment(), ke->getValue("v").type(), ke->getValue("v").value(), ke->getValue("f").value(), ke->getValue("f").comment(), CDType::cdK);
|
||||
}
|
||||
PIConfig::Entry & sl = e.getValue("s");
|
||||
for (int i = 0; i < sl.childCount(); ++i) {
|
||||
const PIConfig::Entry * se(sl.child(i));
|
||||
int sid = se->name().toInt();
|
||||
CDSection cs;
|
||||
cs.read(se);
|
||||
s[sid] = cs;
|
||||
s[sid].read(se);
|
||||
}
|
||||
// piCout << "[CDSection] read end";
|
||||
}
|
||||
@@ -181,7 +199,10 @@ void CDSection::update(CDSection & v, bool keep_names) {
|
||||
}
|
||||
}
|
||||
if (v.k.contains(i.key())) {
|
||||
k[i.key()] = v.k[i.key()];
|
||||
PIString f = k[i.key()].formula_;
|
||||
CDType & cdt = v.k[i.key()];
|
||||
cdt.formula_ = f;
|
||||
k[i.key()] = cdt;
|
||||
used << i.key();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class CDSection;
|
||||
class CDType {
|
||||
friend class CDSection;
|
||||
friend class ::CD_Pult;
|
||||
friend class ::CDKItem;
|
||||
//friend class ::CDKItem;
|
||||
public:
|
||||
enum cdT {cdNull, cdK, cdX, cdC};
|
||||
CDType();
|
||||
@@ -26,14 +26,15 @@ public:
|
||||
// ~CDType();
|
||||
int index() const {return index_;}
|
||||
PIString name() const {return name_;}
|
||||
PIString type() const {return type_;}
|
||||
PIString type() const;
|
||||
PIString value() const {return value_s;}
|
||||
PIString formula() const {return formula_;}
|
||||
PIString comment() const {/*piCout << "[CDType] comment" << debug_cnt << name_ << comment_.size() << comment_;*/ return comment_;}
|
||||
PIString comment() const {return comment_;}
|
||||
double toDouble() const {return value_d;}
|
||||
int toInt() const {return value_i;}
|
||||
bool toBool() const {return value_b;}
|
||||
cdT cd_type() const {return cd_type_;}
|
||||
void setFormula(const PIString & formula);
|
||||
|
||||
operator double() const {return value_d;}
|
||||
|
||||
@@ -63,7 +64,7 @@ public:
|
||||
bool test(int v) {return k.value(v).toBool();}
|
||||
CDType & operator [](int v) {return k[v];}
|
||||
const CDType operator [](int v) const {return k[v];}
|
||||
CDSection & section(int v) {piCout << "[CDSection &]"; return s[v];}
|
||||
CDSection & section(int v) {return s[v];}
|
||||
const CDSection section(int v) const {return s[v];}
|
||||
|
||||
bool isEmpty() const {return k.isEmpty() && s.isEmpty();}
|
||||
@@ -85,7 +86,7 @@ protected:
|
||||
void update(CDSection & v, bool keep_names);
|
||||
bool isSameStructure(CDSection & v);
|
||||
|
||||
mutable PIMap<int, CDType> k;
|
||||
PIMap<int, CDType> k;
|
||||
PIMap<int, CDSection> s;
|
||||
|
||||
};
|
||||
|
||||
@@ -62,6 +62,36 @@ private:
|
||||
#include "piscreentiles.h"
|
||||
PIScreen screen(false);
|
||||
int main(int argc, char *argv[]) {
|
||||
PIString s;
|
||||
int i = 0;
|
||||
piCout << i++ << "!" << s << "!";
|
||||
piCout << i << "!" << s.trimmed() << "!";
|
||||
piCout << i << "!" << s.trim() << "!";
|
||||
s = "";
|
||||
piCout << i++ << "!" << s << "!";
|
||||
piCout << i << "!" << s.trimmed() << "!";
|
||||
piCout << i << "!" << s.trim() << "!";
|
||||
s = " ";
|
||||
piCout << i++ << "!" << s << "!";
|
||||
piCout << i << "!" << s.trimmed() << "!";
|
||||
piCout << i << "!" << s.trim() << "!";
|
||||
s = " ";
|
||||
piCout << i++ << "!" << s << "!";
|
||||
piCout << i << "!" << s.trimmed() << "!";
|
||||
piCout << i << "!" << s.trim() << "!";
|
||||
s = " s ";
|
||||
piCout << i++ << "!" << s << "!";
|
||||
piCout << i << "!" << s.trimmed() << "!";
|
||||
piCout << i << "!" << s.trim() << "!";
|
||||
s = "f s ";
|
||||
piCout << i++ << "!" << s << "!";
|
||||
piCout << i << "!" << s.trimmed() << "!";
|
||||
piCout << i << "!" << s.trim() << "!";
|
||||
s = " kjdfsnfv;kjsfd ";
|
||||
piCout << i++ << "!" << s << "!";
|
||||
piCout << i << "!" << s.trimmed() << "!";
|
||||
piCout << i << "!" << s.trim() << "!";
|
||||
return 0;
|
||||
// PIEthernet eth;
|
||||
// eth.send("127.0.0.1:16102", PIByteArray("data\n", 5));
|
||||
// eth.send("127.0.0.1:26102", PIByteArray("data\n", 5));
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "cdutils_k.h"
|
||||
#include "piqt.h"
|
||||
#include <QDebug>
|
||||
#include <QBrush>
|
||||
#include <QColor>
|
||||
|
||||
using namespace CDUtils;
|
||||
|
||||
@@ -19,9 +21,8 @@ CDKItemModel::~CDKItemModel() {
|
||||
|
||||
QVariant CDKItemModel::data(const QModelIndex &index, int role) const {
|
||||
if (!index.isValid()) return QVariant();
|
||||
if (role != Qt::DisplayRole && role != Qt::EditRole) return QVariant();
|
||||
CDKItem *item = getItem(index);
|
||||
return item->data(index.column());
|
||||
return item->data(index.column(), role);
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +95,7 @@ void CDKItemModel::rebuildModel() {
|
||||
}
|
||||
|
||||
|
||||
void CDKItemModel::buildItem(CDKItem *it, CDSection r) {
|
||||
void CDKItemModel::buildItem(CDKItem *it, CDSection & r) {
|
||||
//piCout << "build item" << r.name << r.alias;
|
||||
PIMap<int, CDType>::iterator i;
|
||||
for (i = r.k.begin(); i != r.k.end(); ++i) {
|
||||
@@ -112,7 +113,7 @@ void CDKItemModel::internalRebuild() {
|
||||
qDebug() << "[CDKItemModel]" << "internalRebuild()";
|
||||
if (root) delete root;
|
||||
root = new CDKItem(0, CDKItem::ItemCDSection, 0);
|
||||
CDSection r = K.root();
|
||||
CDSection & r = K.root();
|
||||
buildItem(root, r);
|
||||
}
|
||||
|
||||
@@ -138,15 +139,23 @@ CDKItem::~CDKItem() {
|
||||
}
|
||||
|
||||
|
||||
QVariant CDKItem::data(int column) const {
|
||||
CDSection rs = K.section(buildPath());
|
||||
//piCout << rs.name << rs.alias << rs.count(false) << rs.sectionsCount() << K.root().name << K.root().alias <<K.root().count(false) << K.root().sectionsCount();
|
||||
QVariant CDKItem::data(int column, int role) const {
|
||||
if (role == Qt::BackgroundRole) {
|
||||
switch (type_) {
|
||||
case ItemCDType: return QBrush(QColor(255, 250, 230));
|
||||
case ItemCDSection: return QBrush(QColor(220, 220, 250));
|
||||
}
|
||||
}
|
||||
if (role != Qt::DisplayRole && role != Qt::EditRole) return QVariant();
|
||||
PIDeque<int> path = buildPath();
|
||||
CDSection & rs = K.section(path);
|
||||
CDSection s;
|
||||
switch (type_) {
|
||||
case ItemCDType:
|
||||
switch (column) {
|
||||
case 0: return QString::number(index_);
|
||||
case 1: return PI2QString(rs[index_].name());
|
||||
case 2: return PI2QString(rs[index_].type());
|
||||
case 2: return stringType(rs[index_].type());
|
||||
case 3: return PI2QString(rs[index_].formula());
|
||||
case 4: return PI2QString(rs[index_].value());
|
||||
case 5: return PI2QString(rs[index_].comment());
|
||||
@@ -155,11 +164,12 @@ QVariant CDKItem::data(int column) const {
|
||||
}
|
||||
break;
|
||||
case ItemCDSection:
|
||||
rs = rs.section(index_);
|
||||
s = rs.section(index_);
|
||||
// piCout << rs.name << rs.alias << s.name << s.alias;
|
||||
switch (column) {
|
||||
case 0: return QString("[") + QString::number(index_) + QString("]");
|
||||
case 1: return PI2QString(rs.alias);
|
||||
case 2: return PI2QString(rs.name);
|
||||
case 1: return PI2QString(s.alias);
|
||||
case 2: return PI2QString(s.name);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -171,7 +181,7 @@ QVariant CDKItem::data(int column) const {
|
||||
|
||||
bool CDKItem::setData(int column, const QVariant &value) {
|
||||
if (column == 3 && type_ == ItemCDType) {
|
||||
//K.section(buildPath())[index_].formula_ = Q2PIString(value.toString());
|
||||
K.section(buildPath())[index_].setFormula(Q2PIString(value.toString()));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -186,7 +196,28 @@ PIDeque<int> CDKItem::buildPath() const {
|
||||
p = p->parent_;
|
||||
}
|
||||
path.take_front();
|
||||
//piCout << path;
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
QString CDKItem::stringType(const PIString & t) const {
|
||||
QString n = PI2QString(t);
|
||||
if (n.isEmpty()) return QString("");
|
||||
switch (n[0].toLatin1()) {
|
||||
case 'l': return QString("list"); break;
|
||||
case 'b': return QString("bool"); break;
|
||||
case 'n': return QString("int"); break;
|
||||
case 'f': return QString("double"); break;
|
||||
case 'c': return QString("color"); break;
|
||||
case 'r': return QString("rect"); break;
|
||||
case 'a': return QString("rect"); break;
|
||||
case 'p': return QString("point"); break;
|
||||
case 'v': return QString("vector"); break;
|
||||
case 'i': return QString("IP"); break;
|
||||
case 'e': return QString("enum"); break;
|
||||
case 'F': return QString("file"); break;
|
||||
case 'D': return QString("dir"); break;
|
||||
}
|
||||
return QString("double");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
#ifndef CD_KMODEL_H
|
||||
#define CD_KMODEL_H
|
||||
|
||||
#include "cdutils_k.h"
|
||||
//#include "cdutils_k.h"
|
||||
#include <QAbstractItemModel>
|
||||
#include "pistring.h"
|
||||
|
||||
namespace CDUtils {
|
||||
class CDSection;
|
||||
}
|
||||
class CDKItemModel;
|
||||
|
||||
class CDKItem {
|
||||
@@ -12,11 +16,12 @@ public:
|
||||
enum CDKItemType{ItemCDType, ItemCDSection};
|
||||
CDKItem(int index, CDKItemType type, CDKItem * parent);
|
||||
~CDKItem();
|
||||
QVariant data(int column) const;
|
||||
QVariant data(int column, int role) const;
|
||||
bool setData(int column, const QVariant & value);
|
||||
|
||||
private:
|
||||
PIDeque<int> buildPath() const;
|
||||
QString stringType(const PIString & t) const;
|
||||
|
||||
CDKItem * parent_;
|
||||
int index_;
|
||||
@@ -40,7 +45,7 @@ public:
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
|
||||
void rebuildModel();
|
||||
void buildItem(CDKItem * it, CDUtils::CDSection r);
|
||||
void buildItem(CDKItem * it, CDUtils::CDSection &r);
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
@@ -398,6 +398,7 @@ void CD_Pult::updateKDesc(bool ask_move) {
|
||||
addToList(trUtf8("Update K description file \"%1\"").arg(PI2QString(kdesc_file)), Qt::darkMagenta);
|
||||
PIFile f(kdesc_file, PIIODevice::ReadOnly);
|
||||
//piCout << "call K.update():";
|
||||
K.root() = CDSection();
|
||||
K.update(&f);
|
||||
updateTree(ask_move);
|
||||
}
|
||||
|
||||
@@ -11,9 +11,11 @@
|
||||
#include <QStringList>
|
||||
|
||||
|
||||
inline const QString PI2QString(const PIString & v) {return QString::fromLocal8Bit(v.data());}
|
||||
//inline const QString PI2QString(const PIString & v) {return QString::fromLocal8Bit(v.data());}
|
||||
inline const QString PI2QString(const PIString & v) {return QString::fromUtf8(v.dataUTF8());}
|
||||
|
||||
inline const PIString Q2PIString(const QString & v) {return PIString(v.toLocal8Bit().data());}
|
||||
//inline const PIString Q2PIString(const QString & v) {return PIString(v.toLocal8Bit().data());}
|
||||
inline const PIString Q2PIString(const QString & v) {return PIString::fromUTF8(v.toUtf8().data());}
|
||||
|
||||
|
||||
inline const QStringList PI2QStringList(const PIStringList & v) {QStringList ret; piForeachC (PIString & s, v) ret << PI2QString(s); return ret;}
|
||||
|
||||
Reference in New Issue
Block a user