From fd3a7435e8dc43cdbaf901a28c8a81cbd7b16b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=8B=D1=87=D0=BA=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9?= Date: Mon, 15 Aug 2016 09:03:18 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/libs@114 a8b55f48-bf90-11e4-a774-851b48703e85 --- cd_utils/cdutils_core.cpp | 4 +- cd_utils/cdutils_core.h | 2 +- cd_utils/cdutils_k.cpp | 48 ++++++++- cd_utils/cdutils_k.h | 5 +- cd_utils/cdutils_parser.cpp | 3 + cd_utils/cdutils_types.cpp | 87 +++++++++++----- cd_utils/cdutils_types.h | 14 ++- cd_utils/cdutilstest.cpp | 1 - cd_utils/pult/CMakeLists.txt | 2 +- cd_utils/pult/cd_kmodel.cpp | 192 +++++++++++++++++++++++++++++++++++ cd_utils/pult/cd_kmodel.h | 57 +++++++++++ cd_utils/pult/cd_pult.cpp | 16 ++- cd_utils/pult/cd_pult.h | 5 +- cd_utils/pult/cd_pult.ui | 26 ++++- cd_utils/pult/main.cpp | 1 - 15 files changed, 420 insertions(+), 43 deletions(-) create mode 100644 cd_utils/pult/cd_kmodel.cpp create mode 100644 cd_utils/pult/cd_kmodel.h diff --git a/cd_utils/cdutils_core.cpp b/cd_utils/cdutils_core.cpp index 6c1922f..b618c67 100644 --- a/cd_utils/cdutils_core.cpp +++ b/cd_utils/cdutils_core.cpp @@ -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(); } diff --git a/cd_utils/cdutils_core.h b/cd_utils/cdutils_core.h index 5086188..e0ad692 100644 --- a/cd_utils/cdutils_core.h +++ b/cd_utils/cdutils_core.h @@ -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); diff --git a/cd_utils/cdutils_k.cpp b/cd_utils/cdutils_k.cpp index 5ee9aab..2e5e2dd 100644 --- a/cd_utils/cdutils_k.cpp +++ b/cd_utils/cdutils_k.cpp @@ -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 &path) { +// piCout << "error"; return root(); +// PIDeque 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 &path) const { + PIDeque 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_; } diff --git a/cd_utils/cdutils_k.h b/cd_utils/cdutils_k.h index 3094345..61e7bbe 100644 --- a/cd_utils/cdutils_k.h +++ b/cd_utils/cdutils_k.h @@ -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 &path); + const CDSection section(const PIDeque &path) const; + CDSection & root(); + const CDSection root() const; int count(bool recursive = true) const; const PIString file() const {return k_file;} diff --git a/cd_utils/cdutils_parser.cpp b/cd_utils/cdutils_parser.cpp index 0f7da64..4c42b2e 100644 --- a/cd_utils/cdutils_parser.cpp +++ b/cd_utils/cdutils_parser.cpp @@ -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 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(); } diff --git a/cd_utils/cdutils_types.cpp b/cd_utils/cdutils_types.cpp index a13b754..8866554 100644 --- a/cd_utils/cdutils_types.cpp +++ b/cd_utils/cdutils_types.cpp @@ -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::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::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 vk_ids; +// piCout << "[CDSection] update start"; + PIMap vk_ids; PISet used; PIMap::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"; } diff --git a/cd_utils/cdutils_types.h b/cd_utils/cdutils_types.h index 6081e13..2150547 100644 --- a/cd_utils/cdutils_types.h +++ b/cd_utils/cdutils_types.h @@ -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 indexes() const {return k.keys();} PIStringList index_names() const; diff --git a/cd_utils/cdutilstest.cpp b/cd_utils/cdutilstest.cpp index 405117e..38b718e 100644 --- a/cd_utils/cdutilstest.cpp +++ b/cd_utils/cdutilstest.cpp @@ -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(); diff --git a/cd_utils/pult/CMakeLists.txt b/cd_utils/pult/CMakeLists.txt index 3a05de5..8320c73 100644 --- a/cd_utils/pult/CMakeLists.txt +++ b/cd_utils/pult/CMakeLists.txt @@ -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") diff --git a/cd_utils/pult/cd_kmodel.cpp b/cd_utils/pult/cd_kmodel.cpp new file mode 100644 index 0000000..a89ba6b --- /dev/null +++ b/cd_utils/pult/cd_kmodel.cpp @@ -0,0 +1,192 @@ +#include "cd_kmodel.h" +#include "cdutils_k.h" +#include "piqt.h" +#include + +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::iterator i; + for (i = r.k.begin(); i != r.k.end(); ++i) { + it->childs << new CDKItem(i.key(), CDKItem::ItemCDType, it); + } + PIMap::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(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 < CDKItem::buildPath() const { + PIDeque path; + CDKItem * p = parent_; + while (p) { + path.push_front(p->index_); + p = p->parent_; + } + path.take_front(); + //piCout << path; + return path; +} + diff --git a/cd_utils/pult/cd_kmodel.h b/cd_utils/pult/cd_kmodel.h new file mode 100644 index 0000000..b1b26ce --- /dev/null +++ b/cd_utils/pult/cd_kmodel.h @@ -0,0 +1,57 @@ +#ifndef CD_KMODEL_H +#define CD_KMODEL_H + +#include "cdutils_k.h" +#include + +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 buildPath() const; + + CDKItem * parent_; + int index_; + CDKItemType type_; + QList 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 diff --git a/cd_utils/pult/cd_pult.cpp b/cd_utils/pult/cd_pult.cpp index 1b8fc13..22e8f34 100644 --- a/cd_utils/pult/cd_pult.cpp +++ b/cd_utils/pult/cd_pult.cpp @@ -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::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(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(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(); } diff --git a/cd_utils/pult/cd_pult.h b/cd_utils/pult/cd_pult.h index 53303a6..934f08b 100644 --- a/cd_utils/pult/cd_pult.h +++ b/cd_utils/pult/cd_pult.h @@ -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 k, x; int clear_target, timer; bool needWrite, isPause, need_update, show_x; diff --git a/cd_utils/pult/cd_pult.ui b/cd_utils/pult/cd_pult.ui index a04f3cf..3ac47b1 100644 --- a/cd_utils/pult/cd_pult.ui +++ b/cd_utils/pult/cd_pult.ui @@ -6,8 +6,8 @@ 0 0 - 1034 - 559 + 1035 + 728 @@ -343,6 +343,28 @@ + + + + QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed + + + true + + + QAbstractItemView::ExtendedSelection + + + QAbstractItemView::ScrollPerPixel + + + QAbstractItemView::ScrollPerPixel + + + 20 + + + diff --git a/cd_utils/pult/main.cpp b/cd_utils/pult/main.cpp index 38f08ba..4f8e616 100644 --- a/cd_utils/pult/main.cpp +++ b/cd_utils/pult/main.cpp @@ -3,7 +3,6 @@ int main(int argc, char *argv[]) { - PIFile::setDefaultCharset("UTF-8"); QApplication a(argc, argv); CD_Pult w; w.show();