diff --git a/cd_utils/cdutils_core.cpp b/cd_utils/cdutils_core.cpp index ba74c02..ea05474 100644 --- a/cd_utils/cdutils_core.cpp +++ b/cd_utils/cdutils_core.cpp @@ -109,7 +109,7 @@ void CDCore::cd_read(CDSection * cd, PIIODevice * d) { if (cd->cd_type_ == CDType::cdX) x_selected = cd->collectX(); initRoot(cd); - K_ChangedGlobal(); + raiseChangedGlobal(cd->cd_type_); /*PIVector ds = connection.allDevices(); piForeach(PIIODevice * d, ds) { if (d) @@ -121,7 +121,7 @@ void CDCore::cd_read(CDSection * cd, PIIODevice * d) { void CDCore::cd_parse(CDSection * cd, PIIODevice * d) { *cd = CDParser::parse(d, cd->cd_type_); initRoot(cd); - K_ChangedGlobal(); + raiseChangedGlobal(cd->cd_type_); } @@ -138,13 +138,13 @@ void CDCore::cd_update(CDSection * cd, PIIODevice * d, UpdateModeFlags mode) { //piCout << k_.count() << ucd.count(); *cd = ucd; initRoot(cd); - K_ChangedGlobal(); + raiseChangedGlobal(cd->cd_type_); } void CDCore::cd_calculate(CDSection * cd) { cd->calculate(); - K_ChangedGlobal(); + raiseChangedGlobal(cd->cd_type_); } @@ -475,6 +475,16 @@ void CDCore::procReceivedPacket(PIByteArray & ba) { } +void CDCore::raiseChangedGlobal(CDType::cdT cdt) { + switch (cdt) { + case CDType::cdK: K_ChangedGlobal(); break; + case CDType::cdX: X_ChangedGlobal(); break; + case CDType::cdC: C_ChangedGlobal(); break; + default: break; + } +} + + PIString CDCore::pathToString(const PIDeque & p) { PIString ret; for (int i = 0; i < p.size_s(); ++i) { diff --git a/cd_utils/cdutils_core.h b/cd_utils/cdutils_core.h index cf5040a..b6ef02f 100644 --- a/cd_utils/cdutils_core.h +++ b/cd_utils/cdutils_core.h @@ -92,6 +92,7 @@ private: void sendDirect(PIByteArray & ba); void sendThreaded(PIByteArray & ba); void procReceivedPacket(PIByteArray & ba); + void raiseChangedGlobal(CDType::cdT cdt); typedef PIPair OHPair; diff --git a/cd_utils/cdutils_interface.cpp b/cd_utils/cdutils_interface.cpp index e5c90ba..4a9aff3 100644 --- a/cd_utils/cdutils_interface.cpp +++ b/cd_utils/cdutils_interface.cpp @@ -19,18 +19,21 @@ Interface::Interface(CDType::cdT type_) { CONNECTU(core, K_SendFail, this, sendFailed); CONNECTU(core, K_Received, this, received); CONNECTU(core, K_ReceiveFail, this, receiveFailed); + CONNECTU(core, K_ChangedGlobal, this, changedGlobal); break; case CDType::cdX: CONNECTU(core, X_Sended, this, sended); CONNECTU(core, X_SendFail, this, sendFailed); CONNECTU(core, X_Received, this, received); CONNECTU(core, X_ReceiveFail, this, receiveFailed); + CONNECTU(core, X_ChangedGlobal, this, changedGlobal); break; case CDType::cdC: CONNECTU(core, C_Sended, this, sended); CONNECTU(core, C_SendFail, this, sendFailed); CONNECTU(core, C_Received, this, received); CONNECTU(core, C_ReceiveFail, this, receiveFailed); + CONNECTU(core, C_ChangedGlobal, this, changedGlobal); break; default: break; } diff --git a/cd_utils/cdutils_k.cpp b/cd_utils/cdutils_k.cpp index 76038d0..6ee850a 100644 --- a/cd_utils/cdutils_k.cpp +++ b/cd_utils/cdutils_k.cpp @@ -10,6 +10,11 @@ KInterface::KInterface(): Interface(CDType::cdK) { } +void KInterface::directChange(const CDType & k) { + core->K_DirectChange(k.path(), k.value()); +} + + void KInterface::directChange(const CDType & k, double v) { core->K_DirectChange(k.path(), PIString::fromNumber(v)); } diff --git a/cd_utils/cdutils_k.h b/cd_utils/cdutils_k.h index 5374a41..b49e697 100644 --- a/cd_utils/cdutils_k.h +++ b/cd_utils/cdutils_k.h @@ -15,6 +15,7 @@ public: EVENT1(keepNamesRequest, bool*, kn) + void directChange(const CDType & k); void directChange(const CDType & k, double v); }; diff --git a/cd_utils/cdutils_types.cpp b/cd_utils/cdutils_types.cpp index b491881..308ed24 100644 --- a/cd_utils/cdutils_types.cpp +++ b/cd_utils/cdutils_types.cpp @@ -88,6 +88,25 @@ PIString CDType::value() const { } +PIVariant CDType::variantValue() const { + if (type_.isEmpty()) return PIVariant(value()); + switch (type_[0].toAscii()) { + case 'b': return PIVariant(toBool()); break; + case 'n': return PIVariant(toInt()); break; + case 'f': return PIVariant(toDouble()); break; + case 'c': return PIVariant(PIVariantTypes::Color(toInt())); break; + case 'e': { + PIVariantTypes::Enum e = enum_values; + e.selectValue(toInt()); + return PIVariant(e); + break; + } + default: break; + } + return PIVariant(value()); +} + + void CDType::setValue(const PIString & value_) { formula_ = value_; value_d = formula_.toDouble(); @@ -96,6 +115,11 @@ void CDType::setValue(const PIString & value_) { } +void CDType::setVariantValue(const PIVariant & value_) { + setValue(PIString::fromNumber(value_.toDouble())); +} + + void CDType::setFormula(const PIString & f) { formula_ = f; calculated = false; diff --git a/cd_utils/cdutils_types.h b/cd_utils/cdutils_types.h index cc37044..0a0a11c 100644 --- a/cd_utils/cdutils_types.h +++ b/cd_utils/cdutils_types.h @@ -3,7 +3,7 @@ #include "pistring.h" #include "pimap.h" -#include "pivarianttypes.h" +#include "pivariant.h" class PIIODevice; class PIEvaluator; @@ -40,6 +40,7 @@ public: PIString name() const {return name_;} PIString type() const; PIString value() const; + PIVariant variantValue() const; PIString formula() const {return formula_;} PIString comment() const {return comment_;} double toDouble() const {return value_d;} @@ -47,6 +48,7 @@ public: bool toBool() const {return value_b;} cdT cd_type() const {return cd_type_;} void setValue(const PIString & value_); + void setVariantValue(const PIVariant & value_); void setFormula(const PIString & formula); void setComment(const PIString & comment) {comment_ = comment;} operator double() const {return value_d;} diff --git a/qcd_utils/pult/cddirectk.cpp b/qcd_utils/pult/cddirectk.cpp new file mode 100644 index 0000000..a9ada88 --- /dev/null +++ b/qcd_utils/pult/cddirectk.cpp @@ -0,0 +1,265 @@ +#include "cddirectk.h" +#include "ui_cddirectk_type_dialog.h" +#include "cdutils_core.h" +#include "cdutils_k.h" +#include "qcd_core.h" +#include "qcd_model.h" +#include "graphic.h" +#include "piqt.h" +#include "qvariantedit.h" +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace CDUtils; + + +KDockWidget::KDockWidget(QString title, QMainWindow * p): QDockWidget(title, p) { + da = p; + menu = new QMenu(this); + QAction * a = new QAction(QIcon(":/icons/document-edit.png"), "Rename ...", this); + connect(a, SIGNAL(triggered(bool)), this, SLOT(rename())); + dactions << a; + a = new QAction(QIcon(":/icons/edit-delete.png"), "Remove", this); + connect(a, SIGNAL(triggered(bool)), this, SIGNAL(removeRequest())); + dactions << a; + menu_k = new QMenu(this); + menu_k->setTitle(trUtf8("Remove K")); + lay = new QFormLayout(); + lay->setContentsMargins(0, qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin), 0, 0); + lay->setLabelAlignment(Qt::AlignRight | Qt::AlignVCenter); + QWidget * w = new QWidget(); + w->setAcceptDrops(true); + w->installEventFilter(this); + w->setLayout(lay); + setWidget(w); + type_dialog = new CDDirectKTypeDialog(); +} + + +void KDockWidget::addK(const CDType & t, CDDirectKTypeDialog::TypeInfo ti) { + if (t.cd_type() != CDType::cdK) return; + PIDeque xp = t.path(); + if (k_list.contains(xp)) return; + k_list << xp; + info_list << ti; + QWidget * ve = ti.create(); + lay->addRow(PI2QString(t.pathString().join(".")) + ":", ve); + QCDCore::instance()->bindWidget(ve, t); + //ve->setValue(); +} + + +QByteArray KDockWidget::save() const { + ChunkStream cs; + cs.add(1, windowTitle()) + .add(2, getList(k_list)) + .add(3, info_list); + return cs.data(); +} + + +void KDockWidget::load(QByteArray ba) { + clear(); + if (ba.isEmpty()) return; + ChunkStream cs(ba); + PIVector > list; + QVector ilist; + while (!cs.atEnd()) { + switch (cs.read()) { + case 1: setWindowTitle(cs.getData()); break; + case 2: list = setList(cs.getData()); break; + case 3: ilist = cs.getData >(); break; + default: break; + } + } + ilist.resize(list.size()); + for (int i = 0; i < list.size_s(); ++i) { + addK(K[list[i]], ilist[i]); + } +} + + +void KDockWidget::clear() { + while (lay->rowCount() > 0) + removeRow(0); + k_list.clear(); + info_list.clear(); +} + + +bool KDockWidget::eventFilter(QObject * o, QEvent * e) { + //if (o == graphic->viewport()) { + switch (e->type()) { + case QEvent::DragEnter: { + QDragEnterEvent * de = (QDragEnterEvent*)e; + const QMimeData * mime = de->mimeData(); + if (!mime) break; + if (!mime->text().startsWith("k")) break; + de->setDropAction(Qt::CopyAction); + de->accept(); + return true; + } break; + case QEvent::Drop: { + QDropEvent * de = (QDropEvent*)e; + const QMimeData * mime = de->mimeData(); + if (!mime) break; + //qDebug() << "drop" << mime->text(); + if (!mime->text().startsWith("k")) break; + CDDirectKTypeDialog::TypeInfo ti; + CDType & k(K[CDCore::stringToPath(Q2PIString(mime->text().mid(1)))]); + if (k.type().left(1) == "n" || k.type().left(1) == "f") { + if (type_dialog->exec() == QDialog::Accepted) + ti = type_dialog->getType(); + } + addK(k, ti); + de->accept(); + return true; + } break; + default: break; + } + //} + return QWidget::eventFilter(o, e); +} + + +void KDockWidget::contextMenuEvent(QContextMenuEvent * e) { + qDeleteAll(menu_k->actions()); + menu_k->clear(); + for (int i = 0; i < k_list.size_s(); ++i) { + QAction * a = new QAction(PI2QString(K[k_list[i]].pathString().join(".")), this); + a->setData(i); + connect(a, SIGNAL(triggered(bool)), this, SLOT(removeK())); + menu_k->addAction(a); + } + QMenu * mwm = da->createPopupMenu(); + menu->clear(); + menu->addActions(dactions); + menu->addMenu(menu_k); + menu->addSeparator(); + menu->addActions(mwm->actions()); + menu->popup(e->globalPos()); + mwm->deleteLater(); +} + + +void KDockWidget::removeRow(int r) { + if (r < 0 || r >= lay->rowCount()) return; + QLayoutItem * i = lay->takeAt(r+r); + if (i) {delete i->widget(); delete i;} + i = lay->takeAt(r+r); + if (i) {delete i->widget(); delete i;} +} + + +void KDockWidget::rename() { + QString nn = QInputDialog::getText(this, trUtf8("Rename area"), trUtf8("New area name:"), + QLineEdit::Normal, windowTitle()); + if (nn.isEmpty()) return; + setWindowTitle(nn); +} + + +void KDockWidget::removeK() { + QAction * a = qobject_cast(sender()); + if (!a) return; + int ind = a->data().toInt(); + if (ind < 0 || ind >= k_list.size_s()) return; + k_list.remove(ind); + if (ind >= 0 && ind < info_list.size()) + info_list.remove(ind); + removeRow(ind); +} + + + + +CDDirectK::CDDirectK(QWidget * parent) : QWidget(parent), Ui::CDDirectK() { + setupUi(this); + da = new QMainWindow(); + da->setWindowFlags(frame->windowFlags()); + da->setDockNestingEnabled(true); + layoutMain->addWidget(da); +} + + +CDDirectK::~CDDirectK() { +} + + +void CDDirectK::reset() { + qDeleteAll(docks); + docks.clear(); +} + + +QByteArray CDDirectK::save() const { + ChunkStream cs; + QVector dstates; + foreach (KDockWidget * d, docks) { + dstates << d->save(); + } + cs.add(1, docks.size()) + .add(2, dstates) + .add(3, da->saveState()); + return cs.data(); +} + + +void CDDirectK::load(QByteArray ba) { + reset(); + if (ba.isEmpty()) return; + ChunkStream cs(ba); + while (!cs.atEnd()) { + switch (cs.read()) { + case 1: { + int s = cs.getData(); + piForTimes (s) + addArea(); + } break; + case 2: { + QVector dstates = cs.getData >(); + for (int i = 0; i < piMini(dstates.size(), docks.size()); ++i) + docks[i]->load(dstates[i]); + } break; + case 3: da->restoreState(cs.getData()); break; + default: break; + } + } +} + + +void CDDirectK::addArea() { + KDockWidget * dw = new KDockWidget(QString("area %1").arg(docks.size()), da); + connect(dw, SIGNAL(removeRequest()), this, SLOT(removeArea())); + da->addDockWidget(Qt::RightDockWidgetArea, dw); + docks << dw; + for (int i = 0; i < docks.size(); ++i) + docks[i]->setObjectName(QString("dock_%1").arg(i)); +} + + +void CDDirectK::removeArea() { + KDockWidget * d = qobject_cast(sender()); + if (!d) return; + docks.removeAll(d); + d->deleteLater(); + for (int i = 0; i < docks.size(); ++i) + docks[i]->setObjectName(QString("dock_%1").arg(i)); +} + + +void CDDirectK::on_buttonAdd_clicked() { + addArea(); +} + + +void CDDirectK::on_buttonRemoveAll_clicked() { + qDeleteAll(docks); + docks.clear(); +} diff --git a/qcd_utils/pult/cddirectk.h b/qcd_utils/pult/cddirectk.h new file mode 100644 index 0000000..453e909 --- /dev/null +++ b/qcd_utils/pult/cddirectk.h @@ -0,0 +1,75 @@ +#ifndef CDDIRECTK_H +#define CDDIRECTK_H + +#include "cdgraphics.h" +#include "ui_cddirectk.h" +#include "cddirectk_type_dialog.h" + +class QFormLayout; + + +class KDockWidget: public QDockWidget { + Q_OBJECT +public: + KDockWidget(QString title = QString(), QMainWindow * p = 0); + + void addK(const CDUtils::CDType & t, CDDirectKTypeDialog::TypeInfo ti); + QByteArray save() const; + void load(QByteArray ba); + void clear(); + + QFormLayout * lay; + +private: + bool eventFilter(QObject * o, QEvent * e); + void contextMenuEvent(QContextMenuEvent * e); + void removeRow(int r); + + QMenu * menu, * menu_k; + QList dactions; + QMainWindow * da; + CDDirectKTypeDialog * type_dialog; + PIVector > k_list; + QVector info_list; + +private slots: + void rename(); + void removeK(); + +signals: + void removeRequest(); + +}; + + + + +class CDDirectK: public QWidget, public Ui::CDDirectK +{ + Q_OBJECT +public: + explicit CDDirectK(QWidget *parent = 0); + ~CDDirectK(); + + void reset(); + QByteArray save() const; + void load(QByteArray ba); + +private: + void addArea(); + + QList docks; + QMainWindow * da; + +public slots: + +private slots: + void removeArea(); + void on_buttonAdd_clicked(); + void on_buttonRemoveAll_clicked(); + +signals: + +}; + +#endif // CDDIRECTK_H diff --git a/qcd_utils/pult/cddirectk.ui b/qcd_utils/pult/cddirectk.ui new file mode 100644 index 0000000..a14e715 --- /dev/null +++ b/qcd_utils/pult/cddirectk.ui @@ -0,0 +1,85 @@ + + + CDDirectK + + + + 0 + 0 + 624 + 411 + + + + CD Pult + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + + 0 + + + 0 + + + + + Add new + + + + :/icons/list-add.png:/icons/list-add.png + + + + + + + Remove all + + + + :/icons/edit-delete.png:/icons/edit-delete.png + + + + + + + Qt::Horizontal + + + + 1 + 20 + + + + + + + + + + + + + + diff --git a/qcd_utils/pult/cddirectk_type_dialog.cpp b/qcd_utils/pult/cddirectk_type_dialog.cpp new file mode 100644 index 0000000..ba95141 --- /dev/null +++ b/qcd_utils/pult/cddirectk_type_dialog.cpp @@ -0,0 +1,76 @@ +#include "cddirectk_type_dialog.h" +#include "cdutils_core.h" +#include "qcd_core.h" +#include "qcd_model.h" +#include "piqt.h" +#include "spinslider.h" +#include "qvariantedit.h" + + +CDDirectKTypeDialog::CDDirectKTypeDialog(QWidget * parent) : QDialog(parent), Ui::CDDirectKTypeDialog() { + setupUi(this); +} + + +CDDirectKTypeDialog::~CDDirectKTypeDialog() { +} + + +CDDirectKTypeDialog::TypeInfo CDDirectKTypeDialog::getType() const { + if (!groupBox->isChecked()) return TypeInfo(); + TypeInfo ret; + ret.type = comboType->currentIndex(); + ret.params_d[0] = evalMin->value(); + ret.params_d[1] = evalMax->value(); + ret.params_d[2] = spinDecimals->value(); + ret.params_d[3] = evalStep->value(); + ret.params_s[0] = linePrefix->text(); + ret.params_s[1] = lineSuffix->text(); + return ret; +} + + + + +CDDirectKTypeDialog::TypeInfo::TypeInfo(int type_) { + type = type_; + params_d.resize(4); + params_s.resize(2); +} + + +QWidget * CDDirectKTypeDialog::TypeInfo::create() { + params_d.resize(4); + params_s.resize(2); + switch (type) { + case 0: { + QDoubleSpinBox * ret = new QDoubleSpinBox(); + ret->setMinimum(params_d[0]); + ret->setMaximum(params_d[1]); + ret->setDecimals(params_d[2]); + ret->setSingleStep(params_d[3]); + ret->setPrefix(params_s[0]); + ret->setSuffix(params_s[1]); + return ret; + } break; + case 1: { + QSlider * ret = new QSlider(Qt::Horizontal); + ret->setMinimum(params_d[0]); + ret->setMaximum(params_d[1]); + ret->setSingleStep(params_d[3]); + return ret; + } break; + case 2: { + SpinSlider * ret = new SpinSlider(); + ret->setMinimum(params_d[0]); + ret->setMaximum(params_d[1]); + ret->setDecimals(params_d[2]); + ret->setSingleStep(params_d[3]); + ret->setPrefix(params_s[0]); + ret->setSuffix(params_s[1]); + return ret; + } break; + default: break; + } + return new QVariantEdit(); +} diff --git a/qcd_utils/pult/cddirectk_type_dialog.h b/qcd_utils/pult/cddirectk_type_dialog.h new file mode 100644 index 0000000..c3ee06a --- /dev/null +++ b/qcd_utils/pult/cddirectk_type_dialog.h @@ -0,0 +1,44 @@ +#ifndef CDDIRECTK_TYPE_DIALOG_H +#define CDDIRECTK_TYPE_DIALOG_H + +#include +#include "ui_cddirectk_type_dialog.h" + + +class CDDirectKTypeDialog: public QDialog, public Ui::CDDirectKTypeDialog +{ + Q_OBJECT +public: + explicit CDDirectKTypeDialog(QWidget * parent = 0); + ~CDDirectKTypeDialog(); + + struct TypeInfo { + TypeInfo(int type_ = -1); + QWidget * create(); + int type; + QVector params_d; + QVector params_s; + }; + + TypeInfo getType() const; + +private: + +public slots: + +private slots: + +signals: + +}; + +inline QDataStream & operator <<(QDataStream & s, const CDDirectKTypeDialog::TypeInfo & v) { + s << v.type << v.params_d << v.params_s; + return s; +} +inline QDataStream & operator >>(QDataStream & s, CDDirectKTypeDialog::TypeInfo & v) { + s >> v.type >> v.params_d >> v.params_s; + return s; +} + +#endif // CDDIRECTK_TYPE_DIALOG_H diff --git a/qcd_utils/pult/cddirectk_type_dialog.ui b/qcd_utils/pult/cddirectk_type_dialog.ui new file mode 100644 index 0000000..3c4ac3a --- /dev/null +++ b/qcd_utils/pult/cddirectk_type_dialog.ui @@ -0,0 +1,232 @@ + + + CDDirectKTypeDialog + + + + 0 + 0 + 275 + 310 + + + + CD Pult + + + + + + Custom + + + true + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Type: + + + + + + + + Spin + + + + + Slider + + + + + SpinSlider + + + + + + + + Min: + + + + + + + + + + Max: + + + + + + + 100.000000000000000 + + + + + + + Decimals: + + + + + + + + + + Single step: + + + + + + + 1.000000000000000 + + + + + + + Prefix: + + + + + + + + + + Suffix: + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 1 + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + CLineEdit + QLineEdit +
clineedit.h
+
+ + EvalSpinBox + QWidget +
evalspinbox.h
+
+
+ + + + groupBox + toggled(bool) + widget + setEnabled(bool) + + + 86 + 49 + + + 94 + 91 + + + + + buttonBox + accepted() + CDDirectKTypeDialog + accept() + + + 297 + 285 + + + 315 + 280 + + + + + buttonBox + rejected() + CDDirectKTypeDialog + reject() + + + 281 + 290 + + + 283 + 307 + + + + +
diff --git a/qcd_utils/pult/cdgraphics.cpp b/qcd_utils/pult/cdgraphics.cpp index e205868..49ac8b5 100644 --- a/qcd_utils/pult/cdgraphics.cpp +++ b/qcd_utils/pult/cdgraphics.cpp @@ -110,7 +110,7 @@ bool GDockWidget::eventFilter(QObject * o, QEvent * e) { const QMimeData * mime = de->mimeData(); //qDebug() << "enter" << mime; if (!mime) break; - if (mime->text().isEmpty()) break; + if (!mime->text().startsWith("x")) break; de->setDropAction(Qt::CopyAction); de->accept(); return true; @@ -120,8 +120,8 @@ bool GDockWidget::eventFilter(QObject * o, QEvent * e) { const QMimeData * mime = de->mimeData(); if (!mime) break; //qDebug() << "drop" << mime->text(); - if (mime->text().isEmpty()) break; - addX(X[CDCore::stringToPath(Q2PIString(mime->text()))]); + if (!mime->text().startsWith("x")) break; + addX(X[CDCore::stringToPath(Q2PIString(mime->text().mid(1)))]); de->accept(); return true; } break; diff --git a/qcd_utils/pult/cdpultwindow.cpp b/qcd_utils/pult/cdpultwindow.cpp index 640d633..97738a5 100644 --- a/qcd_utils/pult/cdpultwindow.cpp +++ b/qcd_utils/pult/cdpultwindow.cpp @@ -47,6 +47,9 @@ CDPultWindow::CDPultWindow(QWidget *parent) : EMainWindow(parent), Ui::CDPultWin connect(widgetX, SIGNAL(addToLog(CDViewWidget::LogIcon,QString)), this, SLOT(addToLog(CDViewWidget::LogIcon,QString))); connect(widgetC, SIGNAL(addToLog(CDViewWidget::LogIcon,QString)), this, SLOT(addToLog(CDViewWidget::LogIcon,QString))); connect(widgetX->view, SIGNAL(receivedX()), widgetGraphics, SLOT(receivedX())); + QCDCore::instance()->bindWidget(widgetK->view); + QCDCore::instance()->setDirectKEnabled(true); + X.start(); if (windowState() == Qt::WindowMinimized) setWindowState(Qt::WindowNoState); } @@ -73,6 +76,7 @@ void CDPultWindow::apply(bool sessions) { widgetX->view->startX(); if (sessions) { widgetGraphics->load(session_gr); + widgetDirectK->load(session_dk); if (!session_mw.isEmpty()) restoreState(session_mw); X.lock(); @@ -127,6 +131,7 @@ bool CDPultWindow::load(const QString & path) { if (codeConfig->text().isEmpty()) codeConfig->setText(def_config); session_gr = conf.getValue("session_gr", QByteArray()); + session_dk = conf.getValue("session_dk", QByteArray()); session_mw = conf.getValue("session_mw", QByteArray()); setChanged(false); file_name = path; @@ -138,6 +143,7 @@ bool CDPultWindow::load(const QString & path) { bool CDPultWindow::save(const QString & path) { session_gr = widgetGraphics->save(); + session_dk = widgetDirectK->save(); session_mw = saveState(); QPIConfig conf(path, QIODevice::ReadWrite); conf.clear(); @@ -155,6 +161,7 @@ bool CDPultWindow::save(const QString & path) { conf.setValue("default_config", checkDefaultConfig->isChecked()); conf.setValue("config", QString2QByteArray(codeConfig->text())); conf.setValue("session_gr", session_gr); + conf.setValue("session_dk", session_dk); conf.setValue("session_mw", session_mw); file_name = path; return true; diff --git a/qcd_utils/pult/cdpultwindow.h b/qcd_utils/pult/cdpultwindow.h index bf95b08..92e027e 100644 --- a/qcd_utils/pult/cdpultwindow.h +++ b/qcd_utils/pult/cdpultwindow.h @@ -35,7 +35,7 @@ private: Ribbon * ribbon; QMap log_icons; - QByteArray session_gr, session_mw; + QByteArray session_gr, session_dk, session_mw; QString def_config, last_icon; QImage icon; diff --git a/qcd_utils/pult/cdpultwindow.ui b/qcd_utils/pult/cdpultwindow.ui index baa5f5e..f8c7e2d 100644 --- a/qcd_utils/pult/cdpultwindow.ui +++ b/qcd_utils/pult/cdpultwindow.ui @@ -323,6 +323,25 @@ device.cd = eth://udp:${ip.pult}:27002:${ip.app}:27001 #s + + + + :/icons/tools-wizard.png:/icons/tools-wizard.png + + + Direct K + + + 8 + + + + + + + + + @@ -427,6 +446,12 @@ device.cd = eth://udp:${ip.pult}:27002:${ip.app}:27001 #s
cdgraphics.h
1 + + CDDirectK + QWidget +
cddirectk.h
+ 1 +
diff --git a/qcd_utils/qcd_core.cpp b/qcd_utils/qcd_core.cpp index b8fdfb8..5cbac20 100644 --- a/qcd_utils/qcd_core.cpp +++ b/qcd_utils/qcd_core.cpp @@ -1,4 +1,5 @@ #include "qcd_core.h" +#include "cdutils_k.h" #include "cdutils_core.h" #include "piqt.h" #include @@ -11,6 +12,8 @@ #include #include #include +#include +#include #include 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 > pathes = binded_widgets.values(w); foreach (const PIDeque & 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 > pathes = binded_widgets.values(w); foreach (const PIDeque & 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 > pathes = binded_widgets.values(w); foreach (const PIDeque & 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 > pathes = binded_widgets.values(w); foreach (const PIDeque & 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 > pathes = binded_widgets.values(w); + foreach (const PIDeque & 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()); } @@ -119,16 +140,16 @@ bool QCDCore::bindWidget(QWidget * w) { bindView(w); return false; } - PIVector ak = CDCore::instance()->k().children(); + PIVector 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(w)->setChecked(k.toBool()); - if (cn == "QGroupBox") qobject_cast(w)->setChecked(k.toBool()); - if (cn == "QSpinBox") qobject_cast(w)->setValue(k.toInt()); - if (cn == "QSlider") qobject_cast(w)->setValue(k.toInt()); - if (cn == "QScrollBar") qobject_cast(w)->setValue(k.toInt()); - if (cn == "QDoubleSpinBox") qobject_cast(w)->setValue(k.toDouble()); - if (cn == "SpinSlider") qobject_cast(w)->setValue(k.toDouble()); - if (cn == "QLineEdit") qobject_cast(w)->setText(PI2QString(k.value())); - if (cn == "CLineEdit") qobject_cast(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(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(w)->setChecked(k.toBool()); + if (cn == "QGroupBox") qobject_cast(w)->setChecked(k.toBool()); + if (cn == "QSpinBox") qobject_cast(w)->setValue(k.toInt()); + if (cn == "QSlider") qobject_cast(w)->setValue(k.toInt()); + if (cn == "QScrollBar") qobject_cast(w)->setValue(k.toInt()); + if (cn == "QDoubleSpinBox") qobject_cast(w)->setValue(k.toDouble()); + if (cn == "SpinSlider") qobject_cast(w)->setValue(k.toDouble()); + if (cn == "QLineEdit") qobject_cast(w)->setText(PI2QString(k.value())); + if (cn == "CLineEdit") qobject_cast(w)->setText(PI2QString(k.value())); + if (cn == "EvalSpinBox") qobject_cast(w)->setValue(k.toDouble()); + if (cn == "QVariantEdit") qobject_cast(w)->setValue(PI2QVariant(k.variantValue())); +} + + +void QCDCore::finishEdit(const QList > & pathes) { + K.calculate(); + if (direct_on) { + foreach (const PIDeque & 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 > 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; +} diff --git a/qcd_utils/qcd_core.h b/qcd_utils/qcd_core.h index 984f64b..84d38bb 100644 --- a/qcd_utils/qcd_core.h +++ b/qcd_utils/qcd_core.h @@ -3,6 +3,7 @@ #include #include +#include #include "piobject.h" #include "cdutils_types.h" @@ -30,33 +31,40 @@ public: int bindWindow(QWidget * wnd); int bindWidgets(QList wl); bool bindWidget(QWidget * w); - bool bindWidget(QWidget * w, const CDUtils::CDType k); + bool bindWidget(QWidget * w, const CDUtils::CDType & k); int unbindWindow(QWidget * wnd); int unbindWidgets(QList wl); bool unbindWidget(QWidget * w); void unbindAllWidgets(); + void updateBindedWidget(const CDUtils::CDType & k_); + void setDirectKEnabled(bool yes) {direct_on = yes;} + bool isDirectKEnabled() const {return direct_on;} + private: QCDCore(); ~QCDCore(); void bindView(QWidget * v); + void setWidgetValue(QWidget * w, const CDUtils::CDType & k); + void finishEdit(const QList > & pathes); EVENT_HANDLER(void, K_ChangedGlobal); QMultiMap > binded_widgets; - bool updating; + bool updating, direct_on; private slots: void slotBool(bool v); void slotInt(int v); void slotDouble(double v); void slotText(QString v); + void slotVariant(QVariant v); + void slotDestroyed(QObject * ); public slots: void updateBindedWidgets(); - signals: void updateViewRequest(); diff --git a/qcd_utils/qcd_model.cpp b/qcd_utils/qcd_model.cpp index dca3ae4..f9264d1 100644 --- a/qcd_utils/qcd_model.cpp +++ b/qcd_utils/qcd_model.cpp @@ -21,6 +21,7 @@ CDItem::CDItem(CDUtils::Interface * i, int _index, CDItem::CDItemType type, CDIt parent_ = parent; type_ = type; item_count = 0; + expanded = true; } @@ -319,6 +320,8 @@ Qt::ItemFlags CDItemModel::flags(const QModelIndex & index) const { f |= Qt::ItemIsEditable; if (index.column() == cValue && t.type() == "b") f |= Qt::ItemIsUserCheckable; + if (index.column() == cName_Cmd) + f |= Qt::ItemIsDragEnabled; } if (t.cd_type() == CDType::cdX) { if (index.column() == cXMode || index.column() == cXAvg) @@ -367,12 +370,13 @@ bool CDItemModel::setData(const QModelIndex & index, const QVariant & value, int QMimeData * CDItemModel::mimeData(const QModelIndexList & indexes) const { if (indexes.size() == 1) { QModelIndex index = indexes[0]; - if (index.isValid() && interface->cdType() == CDType::cdX) { + if (index.isValid()/* && interface->cdType() == CDType::cdX*/) { CDItem * item = getItem(index); if (item) { CDType & t(interface->section(item->buildPath())[item->index_]); QMimeData * mime = new QMimeData(); - mime->setText(PI2QString(CDCore::pathToString(t.path()))); + mime->setText(PI2QString(CDCore::instance()->typeLetter(interface->cdType()) + + CDCore::pathToString(t.path()))); return mime; } } diff --git a/qcd_utils/qcd_model.h b/qcd_utils/qcd_model.h index 9325df8..4021015 100644 --- a/qcd_utils/qcd_model.h +++ b/qcd_utils/qcd_model.h @@ -46,6 +46,7 @@ public: int index() const {return index_;} CDUtils::Interface * interface; + bool expanded; private: QString stringType(const PIString & t) const; diff --git a/qcd_utils/qcd_view.cpp b/qcd_utils/qcd_view.cpp index b24ef70..aa78760 100644 --- a/qcd_utils/qcd_view.cpp +++ b/qcd_utils/qcd_view.cpp @@ -121,6 +121,12 @@ void CDView::refresh() { } +void CDView::refreshValues() { + if (!model_) return; + model_->dataChanged(model_->index(0, 0), model_->index(model_->columnCount() - 1, model_->rowCount() - 1)); +} + + void CDView::setFile(const QString & filename) { switch ((CDType::cdT)type_) { case CDType::cdK: K.setFileName(Q2PIString(filename)); break; diff --git a/qcd_utils/qcd_view.h b/qcd_utils/qcd_view.h index 76634b9..22cc7ae 100644 --- a/qcd_utils/qcd_view.h +++ b/qcd_utils/qcd_view.h @@ -35,6 +35,7 @@ protected: public slots: void refresh(); + void refreshValues(); void send(); void receive(); void save();