git-svn-id: svn://db.shs.com.ru/libs@397 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "qcd_core.h"
|
||||
#include "cdutils_k.h"
|
||||
#include "cdutils_core.h"
|
||||
#include "piqt.h"
|
||||
#include <QWidget>
|
||||
@@ -11,6 +12,8 @@
|
||||
#include <QLineEdit>
|
||||
#include <spinslider.h>
|
||||
#include <clineedit.h>
|
||||
#include <evalspinbox.h>
|
||||
#include <qvariantedit.h>
|
||||
#include <qcd_view.h>
|
||||
|
||||
using namespace CDUtils;
|
||||
@@ -42,8 +45,8 @@ __QCore_Initializer__::~__QCore_Initializer__() {
|
||||
QCDCore::QCDCore() {
|
||||
setObjectName("QCDCore");
|
||||
setName("QCDCore");
|
||||
CONNECTU(CDCore::instance(), K_ChangedGlobal, this, K_ChangedGlobal);
|
||||
updating = false;
|
||||
CONNECTU(&K, changedGlobal, this, K_ChangedGlobal);
|
||||
updating = direct_on = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +64,8 @@ void QCDCore::slotBool(bool v) {
|
||||
if (!w || updating) return;
|
||||
QList<PIDeque<int> > pathes = binded_widgets.values(w);
|
||||
foreach (const PIDeque<int> & path, pathes)
|
||||
CDCore::instance()->k()[path].setValue(PIString::fromBool(v));
|
||||
K[path].setValue(PIString::fromBool(v));
|
||||
K.calculate();
|
||||
emit updateViewRequest();
|
||||
}
|
||||
|
||||
@@ -71,8 +75,8 @@ void QCDCore::slotInt(int v) {
|
||||
if (!w || updating) return;
|
||||
QList<PIDeque<int> > pathes = binded_widgets.values(w);
|
||||
foreach (const PIDeque<int> & path, pathes)
|
||||
CDCore::instance()->k()[path].setValue(PIString::fromNumber(v));
|
||||
emit updateViewRequest();
|
||||
K[path].setValue(PIString::fromNumber(v));
|
||||
finishEdit(pathes);
|
||||
}
|
||||
|
||||
|
||||
@@ -81,8 +85,8 @@ void QCDCore::slotDouble(double v) {
|
||||
if (!w || updating) return;
|
||||
QList<PIDeque<int> > pathes = binded_widgets.values(w);
|
||||
foreach (const PIDeque<int> & path, pathes)
|
||||
CDCore::instance()->k()[path].setValue(PIString::fromNumber(v));
|
||||
emit updateViewRequest();
|
||||
K[path].setValue(PIString::fromNumber(v));
|
||||
finishEdit(pathes);
|
||||
}
|
||||
|
||||
|
||||
@@ -91,14 +95,31 @@ void QCDCore::slotText(QString v) {
|
||||
if (!w || updating) return;
|
||||
QList<PIDeque<int> > pathes = binded_widgets.values(w);
|
||||
foreach (const PIDeque<int> & path, pathes)
|
||||
CDCore::instance()->k()[path].setValue(Q2PIString(v));
|
||||
emit updateViewRequest();
|
||||
K[path].setValue(Q2PIString(v));
|
||||
finishEdit(pathes);
|
||||
}
|
||||
|
||||
|
||||
void QCDCore::slotVariant(QVariant v) {
|
||||
QWidget * w = (QWidget*)sender();
|
||||
if (!w || updating) return;
|
||||
QList<PIDeque<int> > pathes = binded_widgets.values(w);
|
||||
foreach (const PIDeque<int> & path, pathes)
|
||||
K[path].setVariantValue(Q2PIVariant(v));
|
||||
finishEdit(pathes);
|
||||
}
|
||||
|
||||
|
||||
void QCDCore::slotDestroyed(QObject * o) {
|
||||
if (!o) return;
|
||||
if (!binded_widgets.contains((QWidget*)o)) return;
|
||||
binded_widgets.remove((QWidget*)o);
|
||||
}
|
||||
|
||||
|
||||
int QCDCore::bindWindow(QWidget * wnd) {
|
||||
if (!wnd) return 0;
|
||||
CDCore::instance()->k().makePath();
|
||||
//K.root().makePath();
|
||||
return bindWidgets(wnd->findChildren<QWidget * >());
|
||||
}
|
||||
|
||||
@@ -119,16 +140,16 @@ bool QCDCore::bindWidget(QWidget * w) {
|
||||
bindView(w);
|
||||
return false;
|
||||
}
|
||||
PIVector<CDType * > ak = CDCore::instance()->k().children();
|
||||
PIVector<CDType * > ak = K.root().children();
|
||||
piForeachC (CDType * k, ak) {
|
||||
if (!on.endsWith(PI2QString(k->name()))) continue;
|
||||
if (!on.endsWith(PI2QString(k->pathString().join("_")))) continue;
|
||||
if (bindWidget(w, *k)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool QCDCore::bindWidget(QWidget * w, const CDType k) {
|
||||
bool QCDCore::bindWidget(QWidget * w, const CDType & k) {
|
||||
if (!w) return false;
|
||||
QString cn = w->metaObject()->className();
|
||||
bool ok = false;
|
||||
@@ -140,7 +161,7 @@ bool QCDCore::bindWidget(QWidget * w, const CDType k) {
|
||||
connect(w, SIGNAL(valueChanged(int)), this, SLOT(slotInt(int)), Qt::UniqueConnection);
|
||||
ok = true;
|
||||
}
|
||||
if (cn == "QDoubleSpinBox" || cn == "SpinSlider") {
|
||||
if (cn == "QDoubleSpinBox" || cn == "SpinSlider" || cn == "EvalSpinBox") {
|
||||
connect(w, SIGNAL(valueChanged(double)), this, SLOT(slotDouble(double)), Qt::UniqueConnection);
|
||||
ok = true;
|
||||
}
|
||||
@@ -148,9 +169,15 @@ bool QCDCore::bindWidget(QWidget * w, const CDType k) {
|
||||
connect(w, SIGNAL(textChanged(QString)), this, SLOT(slotText(QString)), Qt::UniqueConnection);
|
||||
ok = true;
|
||||
}
|
||||
if (cn == "QVariantEdit") {
|
||||
connect(w, SIGNAL(valueChanged(QVariant)), this, SLOT(slotVariant(QVariant)), Qt::UniqueConnection);
|
||||
ok = true;
|
||||
}
|
||||
if (cn == "CDView") {
|
||||
bindView(w);
|
||||
}
|
||||
connect(w, SIGNAL(destroyed(QObject*)), this, SLOT(slotDestroyed(QObject*)), Qt::UniqueConnection);
|
||||
setWidgetValue(w, k);
|
||||
if (!ok) return false;
|
||||
piCout << k.name() << k.path();
|
||||
binded_widgets.insert(w, k.path());
|
||||
@@ -163,17 +190,7 @@ void QCDCore::updateBindedWidgets() {
|
||||
updating = true;
|
||||
while (it.hasNext()) {
|
||||
QWidget * w = it.next().key();
|
||||
QString cn = w->metaObject()->className();
|
||||
const CDType k(CDCore::instance()->k()[it.value()]);
|
||||
if (cn == "QCheckBox") qobject_cast<QCheckBox*>(w)->setChecked(k.toBool());
|
||||
if (cn == "QGroupBox") qobject_cast<QGroupBox*>(w)->setChecked(k.toBool());
|
||||
if (cn == "QSpinBox") qobject_cast<QSpinBox*>(w)->setValue(k.toInt());
|
||||
if (cn == "QSlider") qobject_cast<QSlider*>(w)->setValue(k.toInt());
|
||||
if (cn == "QScrollBar") qobject_cast<QScrollBar*>(w)->setValue(k.toInt());
|
||||
if (cn == "QDoubleSpinBox") qobject_cast<QDoubleSpinBox*>(w)->setValue(k.toDouble());
|
||||
if (cn == "SpinSlider") qobject_cast<SpinSlider*>(w)->setValue(k.toDouble());
|
||||
if (cn == "QLineEdit") qobject_cast<QLineEdit*>(w)->setText(PI2QString(k.value()));
|
||||
if (cn == "CLineEdit") qobject_cast<CLineEdit*>(w)->setText(PI2QString(k.value()));
|
||||
setWidgetValue(w, K[it.value()]);
|
||||
}
|
||||
updating = false;
|
||||
}
|
||||
@@ -182,7 +199,34 @@ void QCDCore::updateBindedWidgets() {
|
||||
void QCDCore::bindView(QWidget * v) {
|
||||
CDView * w = qobject_cast<CDView * >(v);
|
||||
if (!w) return;
|
||||
connect(this, SIGNAL(updateViewRequest()), w->model(), SLOT(updateModel()), Qt::UniqueConnection);
|
||||
connect(this, SIGNAL(updateViewRequest()), w, SLOT(refreshValues()), Qt::UniqueConnection);
|
||||
}
|
||||
|
||||
|
||||
void QCDCore::setWidgetValue(QWidget * w, const CDType & k) {
|
||||
if (!w) return;
|
||||
QString cn = w->metaObject()->className();
|
||||
if (cn == "QCheckBox") qobject_cast<QCheckBox*>(w)->setChecked(k.toBool());
|
||||
if (cn == "QGroupBox") qobject_cast<QGroupBox*>(w)->setChecked(k.toBool());
|
||||
if (cn == "QSpinBox") qobject_cast<QSpinBox*>(w)->setValue(k.toInt());
|
||||
if (cn == "QSlider") qobject_cast<QSlider*>(w)->setValue(k.toInt());
|
||||
if (cn == "QScrollBar") qobject_cast<QScrollBar*>(w)->setValue(k.toInt());
|
||||
if (cn == "QDoubleSpinBox") qobject_cast<QDoubleSpinBox*>(w)->setValue(k.toDouble());
|
||||
if (cn == "SpinSlider") qobject_cast<SpinSlider*>(w)->setValue(k.toDouble());
|
||||
if (cn == "QLineEdit") qobject_cast<QLineEdit*>(w)->setText(PI2QString(k.value()));
|
||||
if (cn == "CLineEdit") qobject_cast<CLineEdit*>(w)->setText(PI2QString(k.value()));
|
||||
if (cn == "EvalSpinBox") qobject_cast<EvalSpinBox*>(w)->setValue(k.toDouble());
|
||||
if (cn == "QVariantEdit") qobject_cast<QVariantEdit*>(w)->setValue(PI2QVariant(k.variantValue()));
|
||||
}
|
||||
|
||||
|
||||
void QCDCore::finishEdit(const QList<PIDeque<int> > & pathes) {
|
||||
K.calculate();
|
||||
if (direct_on) {
|
||||
foreach (const PIDeque<int> & path, pathes)
|
||||
K.directChange(K[path]);
|
||||
}
|
||||
emit updateViewRequest();
|
||||
}
|
||||
|
||||
|
||||
@@ -208,10 +252,12 @@ bool QCDCore::unbindWidget(QWidget * w) {
|
||||
disconnect(w, SIGNAL(toggled(bool)), this, SLOT(slotBool(bool)));
|
||||
if (cn == "QSpinBox" || cn == "QSlider" || cn == "QScrollBar")
|
||||
disconnect(w, SIGNAL(valueChanged(int)), this, SLOT(slotInt(int)));
|
||||
if (cn == "QDoubleSpinBox" || cn == "SpinSlider")
|
||||
if (cn == "QDoubleSpinBox" || cn == "SpinSlider" || cn == "EvalSpinBox")
|
||||
disconnect(w, SIGNAL(valueChanged(double)), this, SLOT(slotDouble(double)));
|
||||
if (cn == "QLineEdit" || cn == "CLineEdit")
|
||||
disconnect(w, SIGNAL(textChanged(QString)), this, SLOT(slotText(QString)));
|
||||
if (cn == "QVariantEdit")
|
||||
disconnect(w, SIGNAL(valueChanged(QVariant)), this, SLOT(slotVariant(QVariant)));
|
||||
binded_widgets.remove(w);
|
||||
return true;
|
||||
}
|
||||
@@ -225,3 +271,16 @@ void QCDCore::unbindAllWidgets() {
|
||||
}
|
||||
binded_widgets.clear();
|
||||
}
|
||||
|
||||
|
||||
void QCDCore::updateBindedWidget(const CDType & k_) {
|
||||
QMapIterator<QWidget * , PIDeque<int> > it(binded_widgets);
|
||||
updating = true;
|
||||
while (it.hasNext()) {
|
||||
QWidget * w = it.next().key();
|
||||
const CDType & k(K[it.value()]);
|
||||
if (k.path() != k_.path()) continue;
|
||||
setWidgetValue(w, k);
|
||||
}
|
||||
updating = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user