From dfb021c2288bffb543e8b1a8135134ff8712a72a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Mon, 23 Jan 2017 07:36:07 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/libs@160 a8b55f48-bf90-11e4-a774-851b48703e85 --- cd_utils/cdutils_core.cpp | 1 + qcd_utils/pult/form.cpp | 2 +- qcd_utils/qcd_core.cpp | 68 +++++++++++++++++++++++++++------------ qcd_utils/qcd_core.h | 8 +++-- qcd_utils/qcd_kmodel.cpp | 6 ++++ qcd_utils/qcd_kmodel.h | 3 +- qcd_utils/qcd_kview.cpp | 2 +- 7 files changed, 64 insertions(+), 26 deletions(-) diff --git a/cd_utils/cdutils_core.cpp b/cd_utils/cdutils_core.cpp index 54b96fb..186a315 100644 --- a/cd_utils/cdutils_core.cpp +++ b/cd_utils/cdutils_core.cpp @@ -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); diff --git a/qcd_utils/pult/form.cpp b/qcd_utils/pult/form.cpp index 3a67da9..a56186b 100644 --- a/qcd_utils/pult/form.cpp +++ b/qcd_utils/pult/form.cpp @@ -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(); diff --git a/qcd_utils/qcd_core.cpp b/qcd_utils/qcd_core.cpp index 175a691..4cb76c4 100644 --- a/qcd_utils/qcd_core.cpp +++ b/qcd_utils/qcd_core.cpp @@ -11,6 +11,7 @@ #include #include #include +#include using namespace CDUtils; @@ -60,6 +61,7 @@ void QCDCore::slotBool(bool v) { if (!w || updating) return; PIDeque 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 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 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 path = binded_widgets.value(w); CDCore::instance()->k()[path].setValue(Q2PIString(v)); + emit updateViewRequest(); } @@ -105,35 +110,49 @@ int QCDCore::bindWidgets(QList 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 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 > it(binded_widgets); updating = true; @@ -155,6 +174,13 @@ void QCDCore::updateBindedWidgets() { } +void QCDCore::bindView(QWidget * v) { + CDKView * w = qobject_cast(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()); diff --git a/qcd_utils/qcd_core.h b/qcd_utils/qcd_core.h index a870ce7..c5dfa42 100644 --- a/qcd_utils/qcd_core.h +++ b/qcd_utils/qcd_core.h @@ -4,6 +4,7 @@ #include #include #include "piobject.h" +#include "cdutils_types.h" class QCDCore; @@ -29,7 +30,8 @@ public: int bindWindow(QWidget * wnd); int bindWidgets(QList wl); bool bindWidget(QWidget * w); - void updateBindedWidgets(); + bool bindWidget(QWidget * w, const CDUtils::CDType & k); + int unbindWindow(QWidget * wnd); int unbindWidgets(QList wl); bool unbindWidget(QWidget * w); @@ -39,6 +41,7 @@ private: QCDCore(); ~QCDCore(); + void bindView(QWidget * v); EVENT_HANDLER(void, K_ChangedGlobal); QMap > binded_widgets; @@ -51,10 +54,11 @@ private slots: void slotText(QString v); public slots: + void updateBindedWidgets(); signals: - + void updateViewRequest(); }; diff --git a/qcd_utils/qcd_kmodel.cpp b/qcd_utils/qcd_kmodel.cpp index b513fdc..0bb8c22 100644 --- a/qcd_utils/qcd_kmodel.cpp +++ b/qcd_utils/qcd_kmodel.cpp @@ -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; diff --git a/qcd_utils/qcd_kmodel.h b/qcd_utils/qcd_kmodel.h index db496e5..9323340 100644 --- a/qcd_utils/qcd_kmodel.h +++ b/qcd_utils/qcd_kmodel.h @@ -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(); diff --git a/qcd_utils/qcd_kview.cpp b/qcd_utils/qcd_kview.cpp index ac6c57a..03bb984 100644 --- a/qcd_utils/qcd_kview.cpp +++ b/qcd_utils/qcd_kview.cpp @@ -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());