git-svn-id: svn://db.shs.com.ru/libs@160 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2017-01-23 07:36:07 +00:00
parent 9f9b624124
commit dfb021c228
7 changed files with 64 additions and 26 deletions

View File

@@ -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 * >());