git-svn-id: svn://db.shs.com.ru/libs@160 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -153,6 +153,7 @@ void CDCore::initPult() {
|
||||
|
||||
void CDCore::init(const PIString & configuration) {
|
||||
PIString c = configuration;
|
||||
//piCoutObj << "init" << c;
|
||||
connection.stop();
|
||||
connection.removeAllDevices();
|
||||
connection.configureFromString(&c);
|
||||
|
||||
@@ -10,7 +10,7 @@ using namespace CDUtils;
|
||||
|
||||
|
||||
Form::Form(QWidget *parent) : QWidget(parent), ui(new Ui::Form) {
|
||||
CDCore::instance()->initPult();
|
||||
//CDCore::instance()->initPult();
|
||||
ui->setupUi(this);
|
||||
ui->treeView->setKFile("");
|
||||
ui->treeView->refresh();
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <QLineEdit>
|
||||
#include <spinslider.h>
|
||||
#include <clineedit.h>
|
||||
#include <qcd_kview.h>
|
||||
|
||||
using namespace CDUtils;
|
||||
|
||||
@@ -60,6 +61,7 @@ void QCDCore::slotBool(bool v) {
|
||||
if (!w || updating) return;
|
||||
PIDeque<int> path = binded_widgets.value(w);
|
||||
CDCore::instance()->k()[path].setValue(PIString::fromBool(v));
|
||||
emit updateViewRequest();
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +70,7 @@ void QCDCore::slotInt(int v) {
|
||||
if (!w || updating) return;
|
||||
PIDeque<int> path = binded_widgets.value(w);
|
||||
CDCore::instance()->k()[path].setValue(PIString::fromNumber(v));
|
||||
emit updateViewRequest();
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +79,7 @@ void QCDCore::slotDouble(double v) {
|
||||
if (!w || updating) return;
|
||||
PIDeque<int> path = binded_widgets.value(w);
|
||||
CDCore::instance()->k()[path].setValue(PIString::fromNumber(v));
|
||||
emit updateViewRequest();
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +88,7 @@ void QCDCore::slotText(QString v) {
|
||||
if (!w || updating) return;
|
||||
PIDeque<int> path = binded_widgets.value(w);
|
||||
CDCore::instance()->k()[path].setValue(Q2PIString(v));
|
||||
emit updateViewRequest();
|
||||
}
|
||||
|
||||
|
||||
@@ -105,35 +110,49 @@ int QCDCore::bindWidgets(QList<QWidget * > wl) {
|
||||
bool QCDCore::bindWidget(QWidget * w) {
|
||||
if (!w) return false;
|
||||
QString on = w->objectName();
|
||||
QString cn = w->metaObject()->className();
|
||||
if (cn == "CDKView") {
|
||||
bindView(w);
|
||||
return false;
|
||||
}
|
||||
PIVector<CDType * > ak = CDCore::instance()->k().children();
|
||||
piForeachC (CDType * k, ak) {
|
||||
if (!on.endsWith(PI2QString(k->name()))) continue;
|
||||
QString cn = w->metaObject()->className();
|
||||
bool ok = false;
|
||||
if (cn == "QCheckBox" || cn == "QGroupBox") {
|
||||
connect(w, SIGNAL(toggled(bool)), this, SLOT(slotBool(bool)), Qt::UniqueConnection);
|
||||
ok = true;
|
||||
}
|
||||
if (cn == "QSpinBox" || cn == "QSlider" || cn == "QScrollBar") {
|
||||
connect(w, SIGNAL(valueChanged(int)), this, SLOT(slotInt(int)), Qt::UniqueConnection);
|
||||
ok = true;
|
||||
}
|
||||
if (cn == "QDoubleSpinBox" || cn == "SpinSlider") {
|
||||
connect(w, SIGNAL(valueChanged(double)), this, SLOT(slotDouble(double)), Qt::UniqueConnection);
|
||||
ok = true;
|
||||
}
|
||||
if (cn == "QLineEdit" || cn == "CLineEdit") {
|
||||
connect(w, SIGNAL(textChanged(QString)), this, SLOT(slotText(QString)), Qt::UniqueConnection);
|
||||
ok = true;
|
||||
}
|
||||
if (!ok) continue;
|
||||
binded_widgets[w] = k->path();
|
||||
return true;
|
||||
if (bindWidget(w, *k)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool QCDCore::bindWidget(QWidget * w, const CDType & k) {
|
||||
if (!w) return false;
|
||||
QString cn = w->metaObject()->className();
|
||||
bool ok = false;
|
||||
if (cn == "QCheckBox" || cn == "QGroupBox") {
|
||||
connect(w, SIGNAL(toggled(bool)), this, SLOT(slotBool(bool)), Qt::UniqueConnection);
|
||||
ok = true;
|
||||
}
|
||||
if (cn == "QSpinBox" || cn == "QSlider" || cn == "QScrollBar") {
|
||||
connect(w, SIGNAL(valueChanged(int)), this, SLOT(slotInt(int)), Qt::UniqueConnection);
|
||||
ok = true;
|
||||
}
|
||||
if (cn == "QDoubleSpinBox" || cn == "SpinSlider") {
|
||||
connect(w, SIGNAL(valueChanged(double)), this, SLOT(slotDouble(double)), Qt::UniqueConnection);
|
||||
ok = true;
|
||||
}
|
||||
if (cn == "QLineEdit" || cn == "CLineEdit") {
|
||||
connect(w, SIGNAL(textChanged(QString)), this, SLOT(slotText(QString)), Qt::UniqueConnection);
|
||||
ok = true;
|
||||
}
|
||||
if (cn == "CDKView") {
|
||||
bindView(w);
|
||||
}
|
||||
if (!ok) return false;
|
||||
binded_widgets[w] = k.path();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void QCDCore::updateBindedWidgets() {
|
||||
QMapIterator<QWidget * , PIDeque<int> > it(binded_widgets);
|
||||
updating = true;
|
||||
@@ -155,6 +174,13 @@ void QCDCore::updateBindedWidgets() {
|
||||
}
|
||||
|
||||
|
||||
void QCDCore::bindView(QWidget * v) {
|
||||
CDKView * w = qobject_cast<CDKView * >(v);
|
||||
if (!w) return;
|
||||
connect(this, SIGNAL(updateViewRequest()), w->model(), SLOT(updateModel()), Qt::UniqueConnection);
|
||||
}
|
||||
|
||||
|
||||
int QCDCore::unbindWindow(QWidget * wnd) {
|
||||
if (!wnd) return 0;
|
||||
return unbindWidgets(wnd->findChildren<QWidget * >());
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
#include "piobject.h"
|
||||
#include "cdutils_types.h"
|
||||
|
||||
|
||||
class QCDCore;
|
||||
@@ -29,7 +30,8 @@ public:
|
||||
int bindWindow(QWidget * wnd);
|
||||
int bindWidgets(QList<QWidget * > wl);
|
||||
bool bindWidget(QWidget * w);
|
||||
void updateBindedWidgets();
|
||||
bool bindWidget(QWidget * w, const CDUtils::CDType & k);
|
||||
|
||||
int unbindWindow(QWidget * wnd);
|
||||
int unbindWidgets(QList<QWidget * > wl);
|
||||
bool unbindWidget(QWidget * w);
|
||||
@@ -39,6 +41,7 @@ private:
|
||||
QCDCore();
|
||||
~QCDCore();
|
||||
|
||||
void bindView(QWidget * v);
|
||||
EVENT_HANDLER(void, K_ChangedGlobal);
|
||||
|
||||
QMap<QWidget * , PIDeque<int> > binded_widgets;
|
||||
@@ -51,10 +54,11 @@ private slots:
|
||||
void slotText(QString v);
|
||||
|
||||
public slots:
|
||||
void updateBindedWidgets();
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
void updateViewRequest();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -127,6 +127,12 @@ void CDKItemModel::buildItem(CDKItem *it, CDSection & r) {
|
||||
}
|
||||
|
||||
|
||||
void CDKItemModel::updateModel() {
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
|
||||
void CDKItemModel::internalRebuild() {
|
||||
//qDebug() << "[CDKItemModel]" << "internalRebuild()";
|
||||
if (root) delete root;
|
||||
|
||||
@@ -62,10 +62,11 @@ public:
|
||||
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:
|
||||
void rebuildModel();
|
||||
void updateModel();
|
||||
|
||||
private:
|
||||
void internalRebuild();
|
||||
|
||||
@@ -29,7 +29,7 @@ CDKView::~CDKView() {
|
||||
|
||||
void CDKView::refresh() {
|
||||
if (!kmodel) {
|
||||
K.reinitConnection(K.pultConfig());
|
||||
//K.reinitConnection(K.pultConfig());
|
||||
kmodel = new CDKItemModel();
|
||||
setModel(kmodel);
|
||||
setItemDelegateForColumn(4, new CDKDelegate());
|
||||
|
||||
Reference in New Issue
Block a user