git-svn-id: svn://db.shs.com.ru/libs@114 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -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