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

This commit is contained in:
2018-06-07 11:50:15 +00:00
parent 771011128a
commit 6967dcc747
23 changed files with 975 additions and 41 deletions

View File

@@ -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<PIIODevice * > 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<int> & p) {
PIString ret;
for (int i = 0; i < p.size_s(); ++i) {

View File

@@ -92,6 +92,7 @@ private:
void sendDirect(PIByteArray & ba);
void sendThreaded(PIByteArray & ba);
void procReceivedPacket(PIByteArray & ba);
void raiseChangedGlobal(CDType::cdT cdt);
typedef PIPair<PIObject * , Handler> OHPair;

View File

@@ -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;
}

View File

@@ -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));
}

View File

@@ -15,6 +15,7 @@ public:
EVENT1(keepNamesRequest, bool*, kn)
void directChange(const CDType & k);
void directChange(const CDType & k, double v);
};

View File

@@ -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;

View File

@@ -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;}

View File

@@ -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 <QFormLayout>
#include <QMimeData>
#include <QDragEnterEvent>
#include <QDragMoveEvent>
#include <QDropEvent>
#include <QMainWindow>
#include <QDockWidget>
#include <QInputDialog>
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<int> 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<PIDeque<int> > list;
QVector<CDDirectKTypeDialog::TypeInfo> ilist;
while (!cs.atEnd()) {
switch (cs.read()) {
case 1: setWindowTitle(cs.getData<QString>()); break;
case 2: list = setList(cs.getData<QStringList>()); break;
case 3: ilist = cs.getData<QVector<CDDirectKTypeDialog::TypeInfo> >(); 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<QAction * >(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<QByteArray> 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<int>();
piForTimes (s)
addArea();
} break;
case 2: {
QVector<QByteArray> dstates = cs.getData<QVector<QByteArray> >();
for (int i = 0; i < piMini(dstates.size(), docks.size()); ++i)
docks[i]->load(dstates[i]);
} break;
case 3: da->restoreState(cs.getData<QByteArray>()); 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<KDockWidget * >(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();
}

View File

@@ -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<QAction*> dactions;
QMainWindow * da;
CDDirectKTypeDialog * type_dialog;
PIVector<PIDeque<int> > k_list;
QVector<CDDirectKTypeDialog::TypeInfo> 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<KDockWidget * > docks;
QMainWindow * da;
public slots:
private slots:
void removeArea();
void on_buttonAdd_clicked();
void on_buttonRemoveAll_clicked();
signals:
};
#endif // CDDIRECTK_H

View File

@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CDDirectK</class>
<widget class="QWidget" name="CDDirectK">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>624</width>
<height>411</height>
</rect>
</property>
<property name="windowTitle">
<string>CD Pult</string>
</property>
<layout class="QVBoxLayout" name="layoutMain" stretch="0">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="topMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="buttonAdd">
<property name="toolTip">
<string>Add new</string>
</property>
<property name="icon">
<iconset resource="../../qad/application/qad_application.qrc">
<normaloff>:/icons/list-add.png</normaloff>:/icons/list-add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonRemoveAll">
<property name="toolTip">
<string>Remove all</string>
</property>
<property name="icon">
<iconset resource="../../qad/application/qad_application.qrc">
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>1</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../qad/application/qad_application.qrc"/>
</resources>
<connections/>
</ui>

View File

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

View File

@@ -0,0 +1,44 @@
#ifndef CDDIRECTK_TYPE_DIALOG_H
#define CDDIRECTK_TYPE_DIALOG_H
#include <QDialog>
#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<double> params_d;
QVector<QString> 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

View File

@@ -0,0 +1,232 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CDDirectKTypeDialog</class>
<widget class="QDialog" name="CDDirectKTypeDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>275</width>
<height>310</height>
</rect>
</property>
<property name="windowTitle">
<string>CD Pult</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Custom</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Type:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboType">
<item>
<property name="text">
<string>Spin</string>
</property>
</item>
<item>
<property name="text">
<string>Slider</string>
</property>
</item>
<item>
<property name="text">
<string>SpinSlider</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Min:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="EvalSpinBox" name="evalMin"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Max:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="EvalSpinBox" name="evalMax">
<property name="value">
<double>100.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Decimals:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="spinDecimals"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Single step:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="EvalSpinBox" name="evalStep">
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Prefix:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="CLineEdit" name="linePrefix"/>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Suffix:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="CLineEdit" name="lineSuffix"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>CLineEdit</class>
<extends>QLineEdit</extends>
<header>clineedit.h</header>
</customwidget>
<customwidget>
<class>EvalSpinBox</class>
<extends>QWidget</extends>
<header>evalspinbox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>groupBox</sender>
<signal>toggled(bool)</signal>
<receiver>widget</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>86</x>
<y>49</y>
</hint>
<hint type="destinationlabel">
<x>94</x>
<y>91</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>CDDirectKTypeDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>297</x>
<y>285</y>
</hint>
<hint type="destinationlabel">
<x>315</x>
<y>280</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>CDDirectKTypeDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>281</x>
<y>290</y>
</hint>
<hint type="destinationlabel">
<x>283</x>
<y>307</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -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;

View File

@@ -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;

View File

@@ -35,7 +35,7 @@ private:
Ribbon * ribbon;
QMap<CDViewWidget::LogIcon, QIcon> log_icons;
QByteArray session_gr, session_mw;
QByteArray session_gr, session_dk, session_mw;
QString def_config, last_icon;
QImage icon;

View File

@@ -323,6 +323,25 @@ device.cd = eth://udp:${ip.pult}:27002:${ip.app}:27001 #s
</layout>
</widget>
</widget>
<widget class="EDockWidget" name="dockDirectK">
<property name="windowIcon">
<iconset resource="../../qad/widgets/qad_widgets.qrc">
<normaloff>:/icons/tools-wizard.png</normaloff>:/icons/tools-wizard.png</iconset>
</property>
<property name="windowTitle">
<string>Direct K</string>
</property>
<attribute name="dockWidgetArea">
<number>8</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents_7">
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="CDDirectK" name="widgetDirectK" native="true"/>
</item>
</layout>
</widget>
</widget>
<action name="actionOpen">
<property name="icon">
<iconset resource="../../qad/application/qad_application.qrc">
@@ -427,6 +446,12 @@ device.cd = eth://udp:${ip.pult}:27002:${ip.app}:27001 #s
<header>cdgraphics.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>CDDirectK</class>
<extends>QWidget</extends>
<header>cddirectk.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../../qad/application/qad_application.qrc"/>

View File

@@ -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;
}

View File

@@ -3,6 +3,7 @@
#include <QObject>
#include <QMultiMap>
#include <QVariant>
#include "piobject.h"
#include "cdutils_types.h"
@@ -30,33 +31,40 @@ public:
int bindWindow(QWidget * wnd);
int bindWidgets(QList<QWidget * > 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<QWidget * > 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<PIDeque<int> > & pathes);
EVENT_HANDLER(void, K_ChangedGlobal);
QMultiMap<QWidget * , PIDeque<int> > 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();

View File

@@ -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;
}
}

View File

@@ -46,6 +46,7 @@ public:
int index() const {return index_;}
CDUtils::Interface * interface;
bool expanded;
private:
QString stringType(const PIString & t) const;

View File

@@ -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;

View File

@@ -35,6 +35,7 @@ protected:
public slots:
void refresh();
void refreshValues();
void send();
void receive();
void save();