git-svn-id: svn://db.shs.com.ru/libs@114 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -80,6 +80,8 @@ CDCore::CDCore(const char * conf) {
|
||||
connection.configureFromString(&s);
|
||||
datatr.setPacketSize(960);
|
||||
connection.start();
|
||||
k_.name = "__root__";
|
||||
k_.alias = "root";
|
||||
|
||||
/*k_[1] = KType(1, "123", "120+3", "comment");
|
||||
k_[2] = KType(2, "1", "2", "comm");
|
||||
@@ -156,7 +158,7 @@ void CDCore::K_Send() {
|
||||
//PIByteArray ba = PIByteArray::fromString(s);
|
||||
PIFile pf("k.txt", PIIODevice::ReadWrite);
|
||||
pf.resize(0);
|
||||
pf.write(s.dataAscii(), s.lengthAscii());
|
||||
pf.write(s.toUTF8());
|
||||
//k_write(&pf);
|
||||
//piCout << pf.readLine();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
EVENT_HANDLER(void, K_Send);
|
||||
EVENT_HANDLER(void, K_Request);
|
||||
|
||||
CDSection k_;
|
||||
mutable CDSection k_;
|
||||
|
||||
void k_write(PIIODevice * d);
|
||||
void k_read(PIIODevice * d);
|
||||
|
||||
@@ -33,16 +33,58 @@ const CDType KInterface::operator [](int v) const {
|
||||
|
||||
|
||||
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 {
|
||||
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_;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,10 @@ public:
|
||||
const CDType operator [](int v) const;
|
||||
CDSection & section(int v);
|
||||
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;
|
||||
const PIString file() const {return k_file;}
|
||||
|
||||
@@ -80,6 +80,7 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
|
||||
CDType::cdT et = (CDType::cdT)cdsection_type;
|
||||
if (!d) return CDSection();
|
||||
if (!d->canRead()) return CDSection();
|
||||
//piCout << "[CDSection] parse start";
|
||||
CDSection cs;
|
||||
CDType ck;
|
||||
PIMap<PIString, CDSection> sections;
|
||||
@@ -171,10 +172,12 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
|
||||
// enum_values << cevalues;
|
||||
cind += 4;
|
||||
}
|
||||
// piCout << "[CDSection] parse end";
|
||||
switch (et) {
|
||||
case CDType::cdK : return sections.value("KDescription");
|
||||
case CDType::cdX : return sections.value("XDescription");
|
||||
case CDType::cdC : return sections.value("CDescription");
|
||||
default: return CDSection();
|
||||
}
|
||||
return CDSection();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
using namespace CDUtils;
|
||||
|
||||
//int cdtype_debug_cnt = 1;
|
||||
|
||||
CDType::CDType() {
|
||||
index_ = -1;
|
||||
@@ -11,9 +12,14 @@ CDType::CDType() {
|
||||
value_i = 0;
|
||||
value_b = false;
|
||||
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) {
|
||||
index_ = i;
|
||||
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 << formula_.size() << formula_.toUTF8();
|
||||
// piCout << comment_.size() << comment_.toUTF8();
|
||||
piCout << "[CDType]" << index_ << ":" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment_ << ":" << (cd_type_ == cdK);
|
||||
piCout << "[CDType]" << index_ << ":" << name_ << ":" << type_ << ":" << value_s << ":" << value_d << ":" << formula_ << ":" << comment() << ":" << (cd_type_ == cdK);
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
//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 ret = k.size_s();
|
||||
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 ret;
|
||||
PIMap<int, CDType>::iterator i;
|
||||
@@ -56,32 +107,21 @@ PIStringList CDSection::index_names() const {
|
||||
void CDSection::write(PIIODevice * d, const PIString & prefix) {
|
||||
if (!d) return;
|
||||
if (k.isEmpty() && s.isEmpty()) return;
|
||||
// piCout << "[CDSection] write start";
|
||||
PIString l;
|
||||
if (!k.isEmpty()) {
|
||||
if (prefix.isEmpty()) l = "[k]";
|
||||
else l = "[" + prefix + ".k]";
|
||||
l += "\n";
|
||||
// piCout << l;
|
||||
// piCout << l.dataUTF8();
|
||||
// piCout << l.dataConsole();
|
||||
// piCout << l.dataAscii();
|
||||
d->write(l.toUTF8());
|
||||
PIMap<int, CDType>::iterator i;
|
||||
for (i = k.begin(); i != k.end(); ++i) {
|
||||
CDType & ck(i.value());
|
||||
//l.clear();
|
||||
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());
|
||||
l.clear();
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -95,16 +135,14 @@ void CDSection::write(PIIODevice * d, const PIString & prefix) {
|
||||
}
|
||||
if (prefix.isEmpty()) {
|
||||
l = "[]\n";
|
||||
// piCout << l;
|
||||
// piCout << l.dataUTF8();
|
||||
// piCout << l.dataConsole();
|
||||
// piCout << l.dataAscii();
|
||||
d->write(l.toUTF8());
|
||||
}
|
||||
// piCout << "[CDSection] write end";
|
||||
}
|
||||
|
||||
|
||||
void CDSection::read(const void * ep) {
|
||||
// piCout << "[CDSection] read start";
|
||||
k.clear();
|
||||
s.clear();
|
||||
PIConfig::Entry & e(*(PIConfig::Entry*)ep);
|
||||
@@ -124,24 +162,26 @@ void CDSection::read(const void * ep) {
|
||||
cs.read(se);
|
||||
s[sid] = cs;
|
||||
}
|
||||
// piCout << "[CDSection] read end";
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
PIMap<int, CDType>::iterator 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) {
|
||||
if (keep_names) {
|
||||
if (vk_ids.contains(i.value().name())) {
|
||||
k[i.key()].formula_ = vk_ids[i.value().name()];
|
||||
if (vk_ids.contains(i.value().name_)) {
|
||||
k[i.key()] = v.k[vk_ids[i.value().name_]];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -160,6 +200,7 @@ void CDSection::update(CDSection & v, bool keep_names) {
|
||||
if (!used.contains(j.key()))
|
||||
s[j.key()] = j.value();
|
||||
}
|
||||
// piCout << "[CDSection] update end";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
class PIIODevice;
|
||||
class CD_Pult;
|
||||
class CDKItem;
|
||||
class CDKItemModel;
|
||||
|
||||
namespace CDUtils {
|
||||
|
||||
@@ -14,16 +16,20 @@ class CDSection;
|
||||
class CDType {
|
||||
friend class CDSection;
|
||||
friend class ::CD_Pult;
|
||||
friend class ::CDKItem;
|
||||
public:
|
||||
enum cdT {cdNull, cdK, cdX, cdC};
|
||||
CDType();
|
||||
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_;}
|
||||
PIString name() const {return name_;}
|
||||
PIString type() const {return type_;}
|
||||
PIString value() const {return value_s;}
|
||||
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;}
|
||||
int toInt() const {return value_i;}
|
||||
bool toBool() const {return value_b;}
|
||||
@@ -40,6 +46,7 @@ protected:
|
||||
double value_d;
|
||||
int value_i;
|
||||
bool value_b;
|
||||
// int debug_cnt;
|
||||
|
||||
};
|
||||
|
||||
@@ -47,6 +54,8 @@ protected:
|
||||
class CDSection {
|
||||
friend class CDCore;
|
||||
friend class ::CD_Pult;
|
||||
friend class ::CDKItem;
|
||||
friend class ::CDKItemModel;
|
||||
public:
|
||||
|
||||
CDSection() {}
|
||||
@@ -54,11 +63,12 @@ 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) {return s[v];}
|
||||
CDSection & section(int v) {piCout << "[CDSection &]"; return s[v];}
|
||||
const CDSection section(int v) const {return s[v];}
|
||||
|
||||
bool isEmpty() const {return k.isEmpty() && s.isEmpty();}
|
||||
int count(bool recursive = true) const;
|
||||
int sectionsCount() const;
|
||||
PIVector<int> indexes() const {return k.keys();}
|
||||
PIStringList index_names() const;
|
||||
|
||||
|
||||
@@ -114,7 +114,6 @@ int main(int argc, char *argv[]) {
|
||||
screen.enableExitCapture('q');
|
||||
//screen.start();
|
||||
piCout << "start";
|
||||
PIFile::setDefaultCharset("UTF-8");
|
||||
Core core;
|
||||
core.load();
|
||||
core.test();
|
||||
|
||||
@@ -8,7 +8,7 @@ if (MINGW)
|
||||
endif()
|
||||
find_package(Qt4 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)
|
||||
file(GLOB CPPS "*.cpp")
|
||||
file(GLOB MOCS "*.h")
|
||||
|
||||
192
cd_utils/pult/cd_kmodel.cpp
Normal file
192
cd_utils/pult/cd_kmodel.cpp
Normal 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
57
cd_utils/pult/cd_kmodel.h
Normal 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
|
||||
@@ -6,6 +6,8 @@
|
||||
#include "piqt.h"
|
||||
#include "qpiconfig.h"
|
||||
|
||||
using namespace CDUtils;
|
||||
|
||||
|
||||
CD_Pult::CD_Pult(): QMainWindow(), config_("cd_pult.conf"),
|
||||
config(piqt(config_), QIODevice::ReadWrite) {
|
||||
@@ -49,6 +51,8 @@ config(piqt(config_), QIODevice::ReadWrite) {
|
||||
CONNECT(void, &coeffs, sendSucceed, this, pip_sendSucceed);
|
||||
CONNECT(void, &coeffs, receiveFailed, this, pip_receiveFailed);
|
||||
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_sendSucceed()), this, SLOT(k_sendSucceed()), 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->blockSignals(true);
|
||||
foreach (QTreeWidgetItem * i, si) {
|
||||
int ki = i->text(0).toInt();
|
||||
// int ki = i->text(0).toInt();
|
||||
i->setText(2, "");
|
||||
//coeffs.setFormula(ki, "");
|
||||
}
|
||||
@@ -218,11 +222,11 @@ void CD_Pult::makeTreeSection(CDSection & ks, QTreeWidgetItem * pi) {
|
||||
PIMap<int, CDSection>::iterator si;
|
||||
for (si = ks.s.begin(); si != ks.s.end(); ++si) {
|
||||
QTreeWidgetItem * ti = new QTreeWidgetItem(pi);
|
||||
const CDSection & cs(si.value());
|
||||
CDSection & cs(si.value());
|
||||
ti->setText(0, QString("[%1]").arg(si.key()));
|
||||
ti->setText(1, PI2QString(cs.alias));
|
||||
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) {
|
||||
if (column != 2) return;
|
||||
int ki = item->text(0).toInt();
|
||||
// int ki = item->text(0).toInt();
|
||||
//coeffs.setFormula(ki, piqt(item->text(column)));
|
||||
if (ui->checkKAutoCalculate->isChecked())
|
||||
;//calculate();
|
||||
@@ -419,7 +423,8 @@ void CD_Pult::updateTree(bool move) {
|
||||
ui->treeK->clear();
|
||||
ui->treeK->setUpdatesEnabled(false);
|
||||
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) {
|
||||
QTreeWidgetItem * ti = new QTreeWidgetItem();
|
||||
KDesc kd = kdesc[i];
|
||||
@@ -456,6 +461,7 @@ void CD_Pult::updateTree(bool move) {
|
||||
ui->treeK->verticalScrollBar()->setValue(sp);
|
||||
//calculate();
|
||||
filterTree();
|
||||
kmodel->rebuildModel();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
#include "session_manager.h"
|
||||
#include "qpievaluator.h"
|
||||
#include "cdutils_k.h"
|
||||
#include "cd_kmodel.h"
|
||||
|
||||
using namespace CDUtils;
|
||||
|
||||
namespace Ui {
|
||||
class CD_Pult;
|
||||
@@ -50,7 +50,7 @@ private:
|
||||
void progress(int val, int max);
|
||||
void clearSelected();
|
||||
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_HANDLER(void, pip_sendFailed) {emit q_k_sendFailed();}
|
||||
@@ -70,6 +70,7 @@ private:
|
||||
QPIEvaluator eval;
|
||||
SessionManager session;
|
||||
QPIConfig config;
|
||||
CDKItemModel * kmodel;
|
||||
//QVector<float> k, x;
|
||||
int clear_target, timer;
|
||||
bool needWrite, isPause, need_update, show_x;
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1034</width>
|
||||
<height>559</height>
|
||||
<width>1035</width>
|
||||
<height>728</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -343,6 +343,28 @@
|
||||
</column>
|
||||
</widget>
|
||||
</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>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_4">
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
PIFile::setDefaultCharset("UTF-8");
|
||||
QApplication a(argc, argv);
|
||||
CD_Pult w;
|
||||
w.show();
|
||||
|
||||
Reference in New Issue
Block a user