git-svn-id: svn://db.shs.com.ru/libs@114 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2016-08-15 09:03:18 +00:00
parent 8052406e54
commit fd3a7435e8
15 changed files with 420 additions and 43 deletions

View File

@@ -80,6 +80,8 @@ CDCore::CDCore(const char * conf) {
connection.configureFromString(&s); connection.configureFromString(&s);
datatr.setPacketSize(960); datatr.setPacketSize(960);
connection.start(); connection.start();
k_.name = "__root__";
k_.alias = "root";
/*k_[1] = KType(1, "123", "120+3", "comment"); /*k_[1] = KType(1, "123", "120+3", "comment");
k_[2] = KType(2, "1", "2", "comm"); k_[2] = KType(2, "1", "2", "comm");
@@ -156,7 +158,7 @@ void CDCore::K_Send() {
//PIByteArray ba = PIByteArray::fromString(s); //PIByteArray ba = PIByteArray::fromString(s);
PIFile pf("k.txt", PIIODevice::ReadWrite); PIFile pf("k.txt", PIIODevice::ReadWrite);
pf.resize(0); pf.resize(0);
pf.write(s.dataAscii(), s.lengthAscii()); pf.write(s.toUTF8());
//k_write(&pf); //k_write(&pf);
//piCout << pf.readLine(); //piCout << pf.readLine();
} }

View File

@@ -33,7 +33,7 @@ public:
EVENT_HANDLER(void, K_Send); EVENT_HANDLER(void, K_Send);
EVENT_HANDLER(void, K_Request); EVENT_HANDLER(void, K_Request);
CDSection k_; mutable CDSection k_;
void k_write(PIIODevice * d); void k_write(PIIODevice * d);
void k_read(PIIODevice * d); void k_read(PIIODevice * d);

View File

@@ -33,16 +33,58 @@ const CDType KInterface::operator [](int v) const {
CDSection & KInterface::section(int v) { CDSection & KInterface::section(int v) {
return core->k_.section(v); CDSection & ret = core->k_.section(v);
piCout << "[get section]" << v << ret.name;
return ret;
} }
const CDSection KInterface::section(int v) const { const CDSection KInterface::section(int v) const {
return core->k_.section(v); return core->k_.section(v);
} }
const CDSection & KInterface::root() 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 {
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;
trs = rs.section(spath.take_front());
tab += " ";
rs = trs;
}
//piCout << "!2" << tab << rs.alias << rs.name;
return rs;
}
CDSection & KInterface::root() {
piCout << "[root]" << core->k_.name;
return core->k_;
}
const CDSection KInterface::root() const {
return core->k_; return core->k_;
} }

View File

@@ -21,7 +21,10 @@ public:
const CDType operator [](int v) const; const CDType operator [](int v) const;
CDSection & section(int v); CDSection & section(int v);
const CDSection section(int v) const; const CDSection section(int v) const;
const CDSection & root() const; // CDSection & section(const PIDeque<int> &path);
const CDSection section(const PIDeque<int> &path) const;
CDSection & root();
const CDSection root() const;
int count(bool recursive = true) const; int count(bool recursive = true) const;
const PIString file() const {return k_file;} const PIString file() const {return k_file;}

View File

@@ -80,6 +80,7 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
CDType::cdT et = (CDType::cdT)cdsection_type; CDType::cdT et = (CDType::cdT)cdsection_type;
if (!d) return CDSection(); if (!d) return CDSection();
if (!d->canRead()) return CDSection(); if (!d->canRead()) return CDSection();
//piCout << "[CDSection] parse start";
CDSection cs; CDSection cs;
CDType ck; CDType ck;
PIMap<PIString, CDSection> sections; PIMap<PIString, CDSection> sections;
@@ -171,10 +172,12 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
// enum_values << cevalues; // enum_values << cevalues;
cind += 4; cind += 4;
} }
// piCout << "[CDSection] parse end";
switch (et) { switch (et) {
case CDType::cdK : return sections.value("KDescription"); case CDType::cdK : return sections.value("KDescription");
case CDType::cdX : return sections.value("XDescription"); case CDType::cdX : return sections.value("XDescription");
case CDType::cdC : return sections.value("CDescription"); case CDType::cdC : return sections.value("CDescription");
default: return CDSection();
} }
return CDSection(); return CDSection();
} }

View File

@@ -4,6 +4,7 @@
using namespace CDUtils; using namespace CDUtils;
//int cdtype_debug_cnt = 1;
CDType::CDType() { CDType::CDType() {
index_ = -1; index_ = -1;
@@ -11,9 +12,14 @@ CDType::CDType() {
value_i = 0; value_i = 0;
value_b = false; value_b = false;
cd_type_ = cdNull; cd_type_ = cdNull;
// debug_cnt = cdtype_debug_cnt;
// cdtype_debug_cnt++;
// piCout << "[CDType]" << "create Null" << debug_cnt;
} }
CDType::CDType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c, cdT cd_t) { CDType::CDType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c, cdT cd_t) {
index_ = i; index_ = i;
name_ = n.trimmed(); name_ = n.trimmed();
@@ -28,11 +34,51 @@ CDType::CDType(int i, const PIString & n, const PIString & t, const PIString & v
// piCout << type_.size() << type_.toUTF8(); // piCout << type_.size() << type_.toUTF8();
// piCout << formula_.size() << formula_.toUTF8(); // piCout << formula_.size() << formula_.toUTF8();
// piCout << comment_.size() << comment_.toUTF8(); // piCout << comment_.size() << comment_.toUTF8();
piCout << "[CDType]" << index_ << ":" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ << ":" << (cd_type_ == cdK); // debug_cnt = cdtype_debug_cnt;
piCout << "[CDType]" << index_ << ":" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment() << ":" << (cd_type_ == cdK); // cdtype_debug_cnt++;
// piCout << "[CDType] create" << debug_cnt << index_ << ":" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ << ":" << (cd_type_ == cdK);
} }
//CDType::CDType(const CDType &cdt) {
// index_ = cdt.index_;
// name_ = cdt.name_;
// type_ = cdt.type_;
// value_s = cdt.value_s;
// formula_ = cdt.formula_;
// comment_ = cdt.comment_;
// value_d = cdt.value_d;
// value_i = cdt.value_i;
// value_b = cdt.value_b;
// cd_type_ = cdt.cd_type_;
// debug_cnt = cdtype_debug_cnt;
// cdtype_debug_cnt++;
// piCout << "[CDType] copy" << debug_cnt << "->" << cdt.debug_cnt << index_ << ":" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ << ":" << (cd_type_ == cdK);
//}
//CDType &CDType::operator =(const CDType &cdt) {
// index_ = cdt.index_;
// name_ = cdt.name_;
// type_ = cdt.type_;
// value_s = cdt.value_s;
// formula_ = cdt.formula_;
// comment_ = cdt.comment_;
// value_d = cdt.value_d;
// value_i = cdt.value_i;
// value_b = cdt.value_b;
// cd_type_ = cdt.cd_type_;
// piCout << "[CDType] assign" << debug_cnt << "=" << cdt.debug_cnt << index_ << ":" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ << ":" << (cd_type_ == cdK);
// //debug_cnt = cdt.debug_cnt;
// return *this;
//}
//CDType::~CDType() {
// piCout << "[CDType] delete" << debug_cnt << index_ << ":" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ << ":" << (cd_type_ == cdK);
//}
int CDSection::count(bool recursive) const { int CDSection::count(bool recursive) const {
int ret = k.size_s(); int ret = k.size_s();
if (recursive) { if (recursive) {
@@ -44,6 +90,11 @@ int CDSection::count(bool recursive) const {
} }
int CDSection::sectionsCount() const {
return s.size();
}
PIStringList CDSection::index_names() const { PIStringList CDSection::index_names() const {
PIStringList ret; PIStringList ret;
PIMap<int, CDType>::iterator i; PIMap<int, CDType>::iterator i;
@@ -56,32 +107,21 @@ PIStringList CDSection::index_names() const {
void CDSection::write(PIIODevice * d, const PIString & prefix) { void CDSection::write(PIIODevice * d, const PIString & prefix) {
if (!d) return; if (!d) return;
if (k.isEmpty() && s.isEmpty()) return; if (k.isEmpty() && s.isEmpty()) return;
// piCout << "[CDSection] write start";
PIString l; PIString l;
if (!k.isEmpty()) { if (!k.isEmpty()) {
if (prefix.isEmpty()) l = "[k]"; if (prefix.isEmpty()) l = "[k]";
else l = "[" + prefix + ".k]"; else l = "[" + prefix + ".k]";
l += "\n"; l += "\n";
// piCout << l;
// piCout << l.dataUTF8();
// piCout << l.dataConsole();
// piCout << l.dataAscii();
d->write(l.toUTF8()); d->write(l.toUTF8());
PIMap<int, CDType>::iterator i; PIMap<int, CDType>::iterator i;
for (i = k.begin(); i != k.end(); ++i) { for (i = k.begin(); i != k.end(); ++i) {
CDType & ck(i.value()); CDType & ck(i.value());
//l.clear(); //l.clear();
l = PIString::fromNumber(ck.index()) + ".f = " + ck.formula() + " #s " + ck.comment() + " \n"; l = PIString::fromNumber(ck.index()) + ".f = " + ck.formula() + " #s " + ck.comment() + " \n";
// piCout << l << ck.comment().size();
// piCout << l.dataUTF8();
// piCout << l.dataConsole();
// piCout << l.dataAscii();
d->write(l.toUTF8()); d->write(l.toUTF8());
l.clear(); l.clear();
l << ck.index() << ".v = " << ck.value() << " #" << ck.type() << " " << ck.name() << " \n"; l << ck.index() << ".v = " << ck.value() << " #" << ck.type() << " " << ck.name() << " \n";
// piCout << l;
// piCout << l.dataUTF8();
// piCout << l.dataConsole();
// piCout << l.dataAscii();
d->write(l.toUTF8()); d->write(l.toUTF8());
} }
} }
@@ -95,16 +135,14 @@ void CDSection::write(PIIODevice * d, const PIString & prefix) {
} }
if (prefix.isEmpty()) { if (prefix.isEmpty()) {
l = "[]\n"; l = "[]\n";
// piCout << l;
// piCout << l.dataUTF8();
// piCout << l.dataConsole();
// piCout << l.dataAscii();
d->write(l.toUTF8()); d->write(l.toUTF8());
} }
// piCout << "[CDSection] write end";
} }
void CDSection::read(const void * ep) { void CDSection::read(const void * ep) {
// piCout << "[CDSection] read start";
k.clear(); k.clear();
s.clear(); s.clear();
PIConfig::Entry & e(*(PIConfig::Entry*)ep); PIConfig::Entry & e(*(PIConfig::Entry*)ep);
@@ -124,24 +162,26 @@ void CDSection::read(const void * ep) {
cs.read(se); cs.read(se);
s[sid] = cs; s[sid] = cs;
} }
// piCout << "[CDSection] read end";
} }
void CDSection::update(CDSection & v, bool keep_names) { void CDSection::update(CDSection & v, bool keep_names) {
PIMap<PIString, PIString> vk_ids; // piCout << "[CDSection] update start";
PIMap<PIString, int> vk_ids;
PISet<int> used; PISet<int> used;
PIMap<int, CDType>::iterator i; PIMap<int, CDType>::iterator i;
for (i = v.k.begin(); i != v.k.end(); ++i) for (i = v.k.begin(); i != v.k.end(); ++i)
vk_ids[i.value().name()] = i.value().formula(); vk_ids[i.value().name_] = i.value().index_;
for (i = k.begin(); i != k.end(); ++i) { for (i = k.begin(); i != k.end(); ++i) {
if (keep_names) { if (keep_names) {
if (vk_ids.contains(i.value().name())) { if (vk_ids.contains(i.value().name_)) {
k[i.key()].formula_ = vk_ids[i.value().name()]; k[i.key()] = v.k[vk_ids[i.value().name_]];
continue; continue;
} }
} }
if (v.k.contains(i.key())) { if (v.k.contains(i.key())) {
k[i.key()].formula_ = v.k[i.key()].formula_; k[i.key()] = v.k[i.key()];
used << i.key(); used << i.key();
} }
} }
@@ -160,6 +200,7 @@ void CDSection::update(CDSection & v, bool keep_names) {
if (!used.contains(j.key())) if (!used.contains(j.key()))
s[j.key()] = j.value(); s[j.key()] = j.value();
} }
// piCout << "[CDSection] update end";
} }

View File

@@ -6,6 +6,8 @@
class PIIODevice; class PIIODevice;
class CD_Pult; class CD_Pult;
class CDKItem;
class CDKItemModel;
namespace CDUtils { namespace CDUtils {
@@ -14,16 +16,20 @@ class CDSection;
class CDType { class CDType {
friend class CDSection; friend class CDSection;
friend class ::CD_Pult; friend class ::CD_Pult;
friend class ::CDKItem;
public: public:
enum cdT {cdNull, cdK, cdX, cdC}; enum cdT {cdNull, cdK, cdX, cdC};
CDType(); CDType();
CDType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c, cdT cd_t); CDType(int i, const PIString & n, const PIString & t, const PIString & v, const PIString & f, const PIString & c, cdT cd_t);
// CDType(const CDType & cdt);
// CDType & operator =(const CDType & cdt);
// ~CDType();
int index() const {return index_;} int index() const {return index_;}
PIString name() const {return name_;} PIString name() const {return name_;}
PIString type() const {return type_;} PIString type() const {return type_;}
PIString value() const {return value_s;} PIString value() const {return value_s;}
PIString formula() const {return formula_;} PIString formula() const {return formula_;}
PIString comment() const {piCout << "[CDType]" << name_ << comment_.size(); return comment_;} PIString comment() const {/*piCout << "[CDType] comment" << debug_cnt << name_ << comment_.size() << comment_;*/ return comment_;}
double toDouble() const {return value_d;} double toDouble() const {return value_d;}
int toInt() const {return value_i;} int toInt() const {return value_i;}
bool toBool() const {return value_b;} bool toBool() const {return value_b;}
@@ -40,6 +46,7 @@ protected:
double value_d; double value_d;
int value_i; int value_i;
bool value_b; bool value_b;
// int debug_cnt;
}; };
@@ -47,6 +54,8 @@ protected:
class CDSection { class CDSection {
friend class CDCore; friend class CDCore;
friend class ::CD_Pult; friend class ::CD_Pult;
friend class ::CDKItem;
friend class ::CDKItemModel;
public: public:
CDSection() {} CDSection() {}
@@ -54,11 +63,12 @@ public:
bool test(int v) {return k.value(v).toBool();} bool test(int v) {return k.value(v).toBool();}
CDType & operator [](int v) {return k[v];} CDType & operator [](int v) {return k[v];}
const CDType operator [](int v) const {return k[v];} const CDType operator [](int v) const {return k[v];}
CDSection & section(int v) {return s[v];} CDSection & section(int v) {piCout << "[CDSection &]"; return s[v];}
const CDSection section(int v) const {return s[v];} const CDSection section(int v) const {return s[v];}
bool isEmpty() const {return k.isEmpty() && s.isEmpty();} bool isEmpty() const {return k.isEmpty() && s.isEmpty();}
int count(bool recursive = true) const; int count(bool recursive = true) const;
int sectionsCount() const;
PIVector<int> indexes() const {return k.keys();} PIVector<int> indexes() const {return k.keys();}
PIStringList index_names() const; PIStringList index_names() const;

View File

@@ -114,7 +114,6 @@ int main(int argc, char *argv[]) {
screen.enableExitCapture('q'); screen.enableExitCapture('q');
//screen.start(); //screen.start();
piCout << "start"; piCout << "start";
PIFile::setDefaultCharset("UTF-8");
Core core; Core core;
core.load(); core.load();
core.test(); core.test();

View File

@@ -8,7 +8,7 @@ if (MINGW)
endif() endif()
find_package(Qt4 REQUIRED) find_package(Qt4 REQUIRED)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${PIP_INCLUDES} ${QT_INCLUDES}) include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${PIP_INCLUDES} ${QT_INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR}/../)
add_definitions(-DCDPULT) add_definitions(-DCDPULT)
file(GLOB CPPS "*.cpp") file(GLOB CPPS "*.cpp")
file(GLOB MOCS "*.h") file(GLOB MOCS "*.h")

192
cd_utils/pult/cd_kmodel.cpp Normal file
View File

@@ -0,0 +1,192 @@
#include "cd_kmodel.h"
#include "cdutils_k.h"
#include "piqt.h"
#include <QDebug>
using namespace CDUtils;
CDKItemModel::CDKItemModel(QObject *parent) : QAbstractItemModel(parent) {
root = 0;
internalRebuild();
}
CDKItemModel::~CDKItemModel() {
delete root;
}
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());
}
QVariant CDKItemModel::headerData(int section, Qt::Orientation orientation, int role) const {
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
switch (section) {
case 0: return trUtf8("Index");
case 1: return trUtf8("Name");
case 2: return trUtf8("Type");
case 3: return trUtf8("Expression");
case 4: return trUtf8("Value");
case 5: return trUtf8("Comment");
}
}
return QVariant();
}
QModelIndex CDKItemModel::index(int row, int column, const QModelIndex &parent) const {
if (parent.isValid() && parent.column() != 0) return QModelIndex();
CDKItem * p = getItem(parent);
CDKItem * c = p->childs.value(row, 0);
if (c) return createIndex(row, column, c);
else return QModelIndex();
}
QModelIndex CDKItemModel::parent(const QModelIndex &index) const {
if (!index.isValid()) return QModelIndex();
CDKItem * c = getItem(index);
CDKItem * p = c->parent_;
if (p == root) return QModelIndex();
return createIndex(p->parent_->childs.indexOf(p), 0, p);
}
int CDKItemModel::rowCount(const QModelIndex &parent) const {
CDKItem *p = getItem(parent);
return p->childs.count();
}
int CDKItemModel::columnCount(const QModelIndex &parent) const {
return 6;
}
Qt::ItemFlags CDKItemModel::flags(const QModelIndex &index) const {
if (!index.isValid()) return 0;
Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
CDKItem * item = getItem(index);
if (index.column() == 3 && item->type_ == CDKItem::ItemCDType) f |= Qt::ItemIsEditable;
return f;
}
bool CDKItemModel::setData(const QModelIndex &index, const QVariant &value, int role) {
if (role != Qt::EditRole) return false;
CDKItem * item = getItem(index);
bool result = item->setData(index.column(), value);
if (result) emit dataChanged(index, index);
return result;
}
void CDKItemModel::rebuildModel() {
beginResetModel();
internalRebuild();
endResetModel();
}
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) {
it->childs << new CDKItem(i.key(), CDKItem::ItemCDType, it);
}
PIMap<int, CDSection>::iterator j;
for (j = r.s.begin(); j != r.s.end(); ++j) {
it->childs << new CDKItem(j.key(), CDKItem::ItemCDSection, it);
buildItem(it->childs.back(), j.value());
}
}
void CDKItemModel::internalRebuild() {
qDebug() << "[CDKItemModel]" << "internalRebuild()";
if (root) delete root;
root = new CDKItem(0, CDKItem::ItemCDSection, 0);
CDSection r = K.root();
buildItem(root, r);
}
CDKItem * CDKItemModel::getItem(const QModelIndex &index) const {
if (index.isValid()) {
CDKItem * item = static_cast<CDKItem*>(index.internalPointer());
if (item) return item;
}
return root;
}
CDKItem::CDKItem(int index, CDKItem::CDKItemType type, CDKItem *parent) {
index_ = index;
parent_ = parent;
type_ = type;
}
CDKItem::~CDKItem() {
qDeleteAll(childs);
}
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();
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 3: return PI2QString(rs[index_].formula());
case 4: return PI2QString(rs[index_].value());
case 5: return PI2QString(rs[index_].comment());
default:
break;
}
break;
case ItemCDSection:
rs = rs.section(index_);
switch (column) {
case 0: return QString("[") + QString::number(index_) + QString("]");
case 1: return PI2QString(rs.alias);
case 2: return PI2QString(rs.name);
default:
break;
}
break;
}
return QVariant();
}
bool CDKItem::setData(int column, const QVariant &value) {
if (column == 3 && type_ == ItemCDType) {
//K.section(buildPath())[index_].formula_ = Q2PIString(value.toString());
return true;
}
return false;
}
PIDeque<int> CDKItem::buildPath() const {
PIDeque<int> path;
CDKItem * p = parent_;
while (p) {
path.push_front(p->index_);
p = p->parent_;
}
path.take_front();
//piCout << path;
return path;
}

57
cd_utils/pult/cd_kmodel.h Normal file
View File

@@ -0,0 +1,57 @@
#ifndef CD_KMODEL_H
#define CD_KMODEL_H
#include "cdutils_k.h"
#include <QAbstractItemModel>
class CDKItemModel;
class CDKItem {
friend class CDKItemModel;
public:
enum CDKItemType{ItemCDType, ItemCDSection};
CDKItem(int index, CDKItemType type, CDKItem * parent);
~CDKItem();
QVariant data(int column) const;
bool setData(int column, const QVariant & value);
private:
PIDeque<int> buildPath() const;
CDKItem * parent_;
int index_;
CDKItemType type_;
QList<CDKItem *> childs;
};
class CDKItemModel : public QAbstractItemModel {
Q_OBJECT
public:
explicit CDKItemModel(QObject *parent = 0);
~CDKItemModel();
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
void rebuildModel();
void buildItem(CDKItem * it, CDUtils::CDSection r);
public slots:
private:
void internalRebuild();
CDKItem * getItem(const QModelIndex & index) const;
CDKItem * root;
signals:
};
#endif // CD_KMODEL_H

View File

@@ -6,6 +6,8 @@
#include "piqt.h" #include "piqt.h"
#include "qpiconfig.h" #include "qpiconfig.h"
using namespace CDUtils;
CD_Pult::CD_Pult(): QMainWindow(), config_("cd_pult.conf"), CD_Pult::CD_Pult(): QMainWindow(), config_("cd_pult.conf"),
config(piqt(config_), QIODevice::ReadWrite) { config(piqt(config_), QIODevice::ReadWrite) {
@@ -49,6 +51,8 @@ config(piqt(config_), QIODevice::ReadWrite) {
CONNECT(void, &coeffs, sendSucceed, this, pip_sendSucceed); CONNECT(void, &coeffs, sendSucceed, this, pip_sendSucceed);
CONNECT(void, &coeffs, receiveFailed, this, pip_receiveFailed); CONNECT(void, &coeffs, receiveFailed, this, pip_receiveFailed);
CONNECT(void, &coeffs, receiveSucceed, this, pip_receiveSucceed);*/ CONNECT(void, &coeffs, receiveSucceed, this, pip_receiveSucceed);*/
kmodel = new CDKItemModel();
ui->treeCDK->setModel(kmodel);
connect(this, SIGNAL(q_k_sendFailed()), this, SLOT(k_sendFailed()), Qt::QueuedConnection); connect(this, SIGNAL(q_k_sendFailed()), this, SLOT(k_sendFailed()), Qt::QueuedConnection);
connect(this, SIGNAL(q_k_sendSucceed()), this, SLOT(k_sendSucceed()), Qt::QueuedConnection); connect(this, SIGNAL(q_k_sendSucceed()), this, SLOT(k_sendSucceed()), Qt::QueuedConnection);
connect(this, SIGNAL(q_k_receiveFailed()), this, SLOT(k_receiveFailed()), Qt::QueuedConnection); connect(this, SIGNAL(q_k_receiveFailed()), this, SLOT(k_receiveFailed()), Qt::QueuedConnection);
@@ -170,7 +174,7 @@ void CD_Pult::clearSelected() {
ui->treeK->setUpdatesEnabled(false); ui->treeK->setUpdatesEnabled(false);
ui->treeK->blockSignals(true); ui->treeK->blockSignals(true);
foreach (QTreeWidgetItem * i, si) { foreach (QTreeWidgetItem * i, si) {
int ki = i->text(0).toInt(); // int ki = i->text(0).toInt();
i->setText(2, ""); i->setText(2, "");
//coeffs.setFormula(ki, ""); //coeffs.setFormula(ki, "");
} }
@@ -218,11 +222,11 @@ void CD_Pult::makeTreeSection(CDSection & ks, QTreeWidgetItem * pi) {
PIMap<int, CDSection>::iterator si; PIMap<int, CDSection>::iterator si;
for (si = ks.s.begin(); si != ks.s.end(); ++si) { for (si = ks.s.begin(); si != ks.s.end(); ++si) {
QTreeWidgetItem * ti = new QTreeWidgetItem(pi); QTreeWidgetItem * ti = new QTreeWidgetItem(pi);
const CDSection & cs(si.value()); CDSection & cs(si.value());
ti->setText(0, QString("[%1]").arg(si.key())); ti->setText(0, QString("[%1]").arg(si.key()));
ti->setText(1, PI2QString(cs.alias)); ti->setText(1, PI2QString(cs.alias));
ti->setText(2, PI2QString(cs.name)); ti->setText(2, PI2QString(cs.name));
makeTreeSection(const_cast<CDSection&>(cs), ti); makeTreeSection(cs, ti);
} }
} }
@@ -241,7 +245,7 @@ void CD_Pult::on_treeK_itemClicked(QTreeWidgetItem * item, int column) {
void CD_Pult::on_treeK_itemChanged(QTreeWidgetItem * item, int column) { void CD_Pult::on_treeK_itemChanged(QTreeWidgetItem * item, int column) {
if (column != 2) return; if (column != 2) return;
int ki = item->text(0).toInt(); // int ki = item->text(0).toInt();
//coeffs.setFormula(ki, piqt(item->text(column))); //coeffs.setFormula(ki, piqt(item->text(column)));
if (ui->checkKAutoCalculate->isChecked()) if (ui->checkKAutoCalculate->isChecked())
;//calculate(); ;//calculate();
@@ -419,7 +423,8 @@ void CD_Pult::updateTree(bool move) {
ui->treeK->clear(); ui->treeK->clear();
ui->treeK->setUpdatesEnabled(false); ui->treeK->setUpdatesEnabled(false);
eval.clearCustomVariables(); eval.clearCustomVariables();
makeTreeSection(const_cast<CDSection&>(K.root()), ui->treeK->invisibleRootItem()); CDSection r = K.root();
makeTreeSection(r, ui->treeK->invisibleRootItem());
/*for (int i = 0; i < K.size_s(); ++i) { /*for (int i = 0; i < K.size_s(); ++i) {
QTreeWidgetItem * ti = new QTreeWidgetItem(); QTreeWidgetItem * ti = new QTreeWidgetItem();
KDesc kd = kdesc[i]; KDesc kd = kdesc[i];
@@ -456,6 +461,7 @@ void CD_Pult::updateTree(bool move) {
ui->treeK->verticalScrollBar()->setValue(sp); ui->treeK->verticalScrollBar()->setValue(sp);
//calculate(); //calculate();
filterTree(); filterTree();
kmodel->rebuildModel();
} }

View File

@@ -23,8 +23,8 @@
#include "session_manager.h" #include "session_manager.h"
#include "qpievaluator.h" #include "qpievaluator.h"
#include "cdutils_k.h" #include "cdutils_k.h"
#include "cd_kmodel.h"
using namespace CDUtils;
namespace Ui { namespace Ui {
class CD_Pult; class CD_Pult;
@@ -50,7 +50,7 @@ private:
void progress(int val, int max); void progress(int val, int max);
void clearSelected(); void clearSelected();
QString typeName(const QString & n) const; QString typeName(const QString & n) const;
void makeTreeSection(CDSection & ks, QTreeWidgetItem * pi); void makeTreeSection(CDUtils::CDSection & ks, QTreeWidgetItem * pi);
EVENT_HANDLER1(void, received, bool, ok); EVENT_HANDLER1(void, received, bool, ok);
EVENT_HANDLER(void, pip_sendFailed) {emit q_k_sendFailed();} EVENT_HANDLER(void, pip_sendFailed) {emit q_k_sendFailed();}
@@ -70,6 +70,7 @@ private:
QPIEvaluator eval; QPIEvaluator eval;
SessionManager session; SessionManager session;
QPIConfig config; QPIConfig config;
CDKItemModel * kmodel;
//QVector<float> k, x; //QVector<float> k, x;
int clear_target, timer; int clear_target, timer;
bool needWrite, isPause, need_update, show_x; bool needWrite, isPause, need_update, show_x;

View File

@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1034</width> <width>1035</width>
<height>559</height> <height>728</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -343,6 +343,28 @@
</column> </column>
</widget> </widget>
</item> </item>
<item>
<widget class="QTreeView" name="treeCDK">
<property name="editTriggers">
<set>QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed</set>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="horizontalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<attribute name="headerMinimumSectionSize">
<number>20</number>
</attribute>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tab_4"> <widget class="QWidget" name="tab_4">

View File

@@ -3,7 +3,6 @@
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
PIFile::setDefaultCharset("UTF-8");
QApplication a(argc, argv); QApplication a(argc, argv);
CD_Pult w; CD_Pult w;
w.show(); w.show();