code format

This commit is contained in:
2022-12-14 14:14:33 +03:00
parent 09e5342956
commit cdb02fc9be
278 changed files with 15371 additions and 12176 deletions

View File

@@ -1,9 +1,11 @@
#include "ui_piqt_connection_edit.h"
#include "piqt_connection_edit.h"
#include "picodeinfo.h"
#include "piqt.h"
#include "piqt_connection_view.h"
#include "piqt_highlighter.h"
#include "piqt.h"
#include "picodeinfo.h"
#include "ui_piqt_connection_edit.h"
#include <QCheckBox>
#include <QMessageBox>
@@ -13,14 +15,15 @@ ConnectionEdit::ConnectionEdit(QWidget * parent): QDialog(parent) {
ui->setupUi(this);
new ConfigHighlighter(ui->codeEdit->document());
loading = false;
connect(ui->blockView, SIGNAL(schemeAction(BlockItemBase::Action,QList<QGraphicsItem*>)), this, SLOT(recreateRequest()));
connect(ui->blockView, SIGNAL(schemeAction(BlockItemBase::Action, QList<QGraphicsItem *>)), this, SLOT(recreateRequest()));
connect(ui->blockView->scene(), SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
conn = 0;
conn = 0;
PICodeInfo::EnumInfo * ei = PICodeInfo::enumsInfo->value("PIIODevice::DeviceMode");
if (ei) {
piForeachC (PICodeInfo::EnumeratorInfo & e, ei->members)
#if PIP_VERSION >= PIP_MAKE_VERSION(2,39,0)
ui->comboMode->addItem(PI2QString(e.name.toString() + " (" + PIString::fromNumber(e.value) + ")"), QVariant::fromValue<int>(e.value));
piForeachC(PICodeInfo::EnumeratorInfo & e, ei->members)
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 39, 0)
ui->comboMode->addItem(PI2QString(e.name.toString() + " (" + PIString::fromNumber(e.value) + ")"),
QVariant::fromValue<int>(e.value));
#else
ui->comboMode->addItem(PI2QString(e.name + " (" + PIString::fromNumber(e.value) + ")"), QVariant::fromValue<int>(e.value));
#endif
@@ -28,9 +31,9 @@ ConnectionEdit::ConnectionEdit(QWidget * parent): QDialog(parent) {
ui->comboMode->setCurrentIndex(ui->comboMode->count() - 1);
ei = PICodeInfo::enumsInfo->value("PIIODevice::DeviceOption");
if (ei) {
piForeachC (PICodeInfo::EnumeratorInfo & e, ei->members) {
piForeachC(PICodeInfo::EnumeratorInfo & e, ei->members) {
QCheckBox * cb = new QCheckBox();
#if PIP_VERSION >= PIP_MAKE_VERSION(2,39,0)
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 39, 0)
cb->setText(PI2QString(e.name.toString() + " (" + PIString::fromNumber(e.value) + ")"));
#else
cb->setText(PI2QString(e.name + " (" + PIString::fromNumber(e.value) + ")"));
@@ -41,9 +44,10 @@ ConnectionEdit::ConnectionEdit(QWidget * parent): QDialog(parent) {
}
ei = PICodeInfo::enumsInfo->value("PIPacketExtractor::SplitMode");
if (ei) {
piForeachC (PICodeInfo::EnumeratorInfo & e, ei->members)
#if PIP_VERSION >= PIP_MAKE_VERSION(2,39,0)
ui->comboSplit->addItem(PI2QString(e.name.toString() + " (" + PIString::fromNumber(e.value) + ")"), QVariant::fromValue<int>(e.value));
piForeachC(PICodeInfo::EnumeratorInfo & e, ei->members)
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 39, 0)
ui->comboSplit->addItem(PI2QString(e.name.toString() + " (" + PIString::fromNumber(e.value) + ")"),
QVariant::fromValue<int>(e.value));
#else
ui->comboSplit->addItem(PI2QString(e.name + " (" + PIString::fromNumber(e.value) + ")"), QVariant::fromValue<int>(e.value));
#endif
@@ -61,13 +65,15 @@ ConnectionEdit::~ConnectionEdit() {
void ConnectionEdit::accept() {
//bool ok = false;
QList<BlockItem * > bl = ui->blockView->allDevices();
foreach (BlockItem * i, bl)
foreach (BlockItem * j, bl)
// bool ok = false;
QList<BlockItem *> bl = ui->blockView->allDevices();
foreach(BlockItem * i, bl)
foreach(BlockItem * j, bl)
if (i != j)
if (((DeviceItem*)i)->name() == ((DeviceItem*)j)->name()) {
QMessageBox::critical(this, windowTitle() + " - " + tr("error") + "!", tr("Equal devices names: \"%1\"!").arg(((DeviceItem*)i)->name()));
if (((DeviceItem *)i)->name() == ((DeviceItem *)j)->name()) {
QMessageBox::critical(this,
windowTitle() + " - " + tr("error") + "!",
tr("Equal devices names: \"%1\"!").arg(((DeviceItem *)i)->name()));
return;
}
QDialog::accept();
@@ -85,21 +91,19 @@ QByteArray ConnectionEdit::model() const {
QDataStream s(&ret, QIODevice::ReadWrite);
QString cn = PI2QString(conn ? conn->name() : PIString());
s << cn;
QList<BlockBusItem*> busl = ui->blockView->buses();
QList<BlockBusItem *> busl = ui->blockView->buses();
s << busl.size();
foreach (BlockBusItem * b, busl)
foreach(BlockBusItem * b, busl)
s << b->save();
QList<BlockItem*> blockl = ui->blockView->blocks();
QList<BlockItem *> blockl = ui->blockView->blocks();
s << blockl.size();
foreach (BlockItem * b, blockl) {
foreach(BlockItem * b, blockl) {
int type = b->propertyByName("__type").value.toInt();
s << type;
switch (type) {
case __CV_Device:
case __CV_Filter:
case __CV_Sender:
s << b->save();
break;
case __CV_Sender: s << b->save(); break;
}
}
return ret;
@@ -136,7 +140,9 @@ void ConnectionEdit::setModel(const QByteArray & m) {
s >> sz;
for (int i = 0; i < sz; ++i) {
BlockBusItem * b = new BlockBusItem();
QByteArray ba; s >> ba; b->load(ba);
QByteArray ba;
s >> ba;
b->load(ba);
ui->blockView->addItem(b);
}
s >> sz;
@@ -148,26 +154,26 @@ void ConnectionEdit::setModel(const QByteArray & m) {
switch (type) {
case __CV_Device:
b = new DeviceItem();
s >> ba; b->load(ba);
if (!b->isPropertyExists("bufferSize"))
((DeviceItem*)b)->setBufferSize(4096);
((DeviceItem*)b)->rename();
s >> ba;
b->load(ba);
if (!b->isPropertyExists("bufferSize")) ((DeviceItem *)b)->setBufferSize(4096);
((DeviceItem *)b)->rename();
break;
case __CV_Filter:
b = new FilterItem();
s >> ba; b->load(ba);
if (!b->isPropertyExists("bufferSize"))
((FilterItem*)b)->setBufferSize(65536);
((FilterItem*)b)->rename();
s >> ba;
b->load(ba);
if (!b->isPropertyExists("bufferSize")) ((FilterItem *)b)->setBufferSize(65536);
((FilterItem *)b)->rename();
break;
case __CV_Sender:
b = new SenderItem();
s >> ba; b->load(ba);
((SenderItem*)b)->rename();
s >> ba;
b->load(ba);
((SenderItem *)b)->rename();
break;
}
if (b)
ui->blockView->addItem(b);
if (b) ui->blockView->addItem(b);
}
ui->blockView->reconnectAll();
loading = false;
@@ -176,18 +182,18 @@ void ConnectionEdit::setModel(const QByteArray & m) {
void ConnectionEdit::selectionChanged() {
QList<QGraphicsItem*> si = ui->blockView->scene()->selectedItems();
QList<QGraphicsItem *> si = ui->blockView->scene()->selectedItems();
ui->buttonRemove->setEnabled(!si.isEmpty());
ui->buttonDeviceModify->setEnabled(false);
ui->buttonFilterModify->setEnabled(false);
ui->buttonSenderModify->setEnabled(false);
if (si.size() != 1) return;
BlockItem * b = qgraphicsitem_cast<BlockItem*>(si[0]);
BlockItem * b = qgraphicsitem_cast<BlockItem *>(si[0]);
if (!b) return;
int type = b->propertyByName("__type").value.toInt();
if (type == __CV_Device) {
ui->tabWidget->setCurrentIndex(0);
DeviceItem * di = (DeviceItem*)b;
DeviceItem * di = (DeviceItem *)b;
ui->buttonDeviceModify->setEnabled(true);
for (int i = 0; i < ui->comboMode->count(); ++i)
if (ui->comboMode->itemData(i).toInt() == di->mode()) {
@@ -202,7 +208,7 @@ void ConnectionEdit::selectionChanged() {
}
if (type == __CV_Filter) {
ui->tabWidget->setCurrentIndex(1);
FilterItem * fi = (FilterItem*)b;
FilterItem * fi = (FilterItem *)b;
ui->buttonFilterModify->setEnabled(true);
for (int i = 0; i < ui->comboSplit->count(); ++i)
if (ui->comboSplit->itemData(i).toInt() == fi->mode()) {
@@ -219,13 +225,12 @@ void ConnectionEdit::selectionChanged() {
}
if (type == __CV_Sender) {
ui->tabWidget->setCurrentIndex(2);
SenderItem * si = (SenderItem*)b;
SenderItem * si = (SenderItem *)b;
ui->buttonSenderModify->setEnabled(true);
ui->lineSender->setText(si->name());
ui->lineData->setText(si->data());
ui->spinFrequency->setValue(si->frequency());
}
}
@@ -268,10 +273,9 @@ void ConnectionEdit::applySender(SenderItem * b) {
int ConnectionEdit::getOptions() const {
int ret(0);
for (int i = 0; i < ui->layoutOptions->count(); ++i) {
QCheckBox * cb = qobject_cast<QCheckBox*>(ui->layoutOptions->itemAt(i)->widget());
QCheckBox * cb = qobject_cast<QCheckBox *>(ui->layoutOptions->itemAt(i)->widget());
if (!cb) continue;
if (cb->isChecked())
ret |= cb->property("__value").toInt();
if (cb->isChecked()) ret |= cb->property("__value").toInt();
}
return ret;
}
@@ -279,27 +283,29 @@ int ConnectionEdit::getOptions() const {
void ConnectionEdit::setOptions(int o) {
for (int i = 0; i < ui->layoutOptions->count(); ++i) {
QCheckBox * cb = qobject_cast<QCheckBox*>(ui->layoutOptions->itemAt(i)->widget());
QCheckBox * cb = qobject_cast<QCheckBox *>(ui->layoutOptions->itemAt(i)->widget());
if (!cb) continue;
int cbf = cb->property("__value").toInt();
//qDebug() << cbf;
// qDebug() << cbf;
cb->setChecked((o & cbf) == cbf);
}
}
void ConnectionEdit::recreateConnection() {
//qDebug() << "recreate";
// qDebug() << "recreate";
if (loading) return;
ui->blockView->reconnectAll();
if (conn) delete conn;
PIString cn = Q2PIString(ui->lineName->text());
if (cn.isEmpty()) conn = new PIConnection();
else conn = new PIConnection(cn);
QList<BlockItem*> devs = ui->blockView->allDevices();
foreach (BlockItem * b, devs) {
DeviceItem * di = (DeviceItem*)b;
//qDebug() << di->path();
if (cn.isEmpty())
conn = new PIConnection();
else
conn = new PIConnection(cn);
QList<BlockItem *> devs = ui->blockView->allDevices();
foreach(BlockItem * b, devs) {
DeviceItem * di = (DeviceItem *)b;
// qDebug() << di->path();
PIIODevice * dev = conn->addDevice(Q2PIString(di->path()), di->mode());
if (!dev) continue;
dev->setOptions(di->options());
@@ -308,35 +314,35 @@ void ConnectionEdit::recreateConnection() {
PIDiagnostics * diag = conn->diagnostic(dev);
if (diag) diag->setDisconnectTimeout(di->disconnectTimeout());
}
foreach (BlockItem * b, devs) {
DeviceItem * di = (DeviceItem*)b;
foreach(BlockItem * b, devs) {
DeviceItem * di = (DeviceItem *)b;
PIIODevice * dev = conn->deviceByName(Q2PIString(di->name()));
if (!dev) continue;
BlockItemPin * p = b->pinByText("read");
if (!p) continue;
QList<BlockBusItem*> buses = p->connectedBuses(), nbuses;
QSet<BlockBusItem*> pbuses;
QList<BlockBusItem *> buses = p->connectedBuses(), nbuses;
QSet<BlockBusItem *> pbuses;
while (!buses.isEmpty()) {
nbuses.clear();
foreach (BlockBusItem * bus, buses) {
QList<BlockItem*> cb = bus->connectedBlocks();
foreach(BlockBusItem * bus, buses) {
QList<BlockItem *> cb = bus->connectedBlocks();
if (cb.size() != 2) continue;
FilterItem * fi_t(0);
BlockItem * bi_f(0);
if (cb[0]->pinAtBus(bus)->text() == "in") {
fi_t = (FilterItem*)(cb[0]);
fi_t = (FilterItem *)(cb[0]);
bi_f = (cb[1]);
} else if (cb[1]->pinAtBus(bus)->text() == "in") {
fi_t = (FilterItem*)(cb[1]);
fi_t = (FilterItem *)(cb[1]);
bi_f = (cb[0]);
}
if (!fi_t || !bi_f) continue;
PIString name_from;
int type = bi_f->propertyByName("__type").value.toInt();
if (type == __CV_Device) name_from = Q2PIString(((DeviceItem*)bi_f)->name());
if (type == __CV_Filter) name_from = Q2PIString(((FilterItem*)bi_f)->name());
if (type == __CV_Device) name_from = Q2PIString(((DeviceItem *)bi_f)->name());
if (type == __CV_Filter) name_from = Q2PIString(((FilterItem *)bi_f)->name());
if (name_from.isEmpty()) continue;
PIPacketExtractor * pe = conn->addFilter(Q2PIString(fi_t->name()),conn->deviceByName(name_from), fi_t->mode());
PIPacketExtractor * pe = conn->addFilter(Q2PIString(fi_t->name()), conn->deviceByName(name_from), fi_t->mode());
if (!pe) continue;
pe->setHeader(PIByteArray::fromUserInput(Q2PIString(fi_t->header())));
pe->setFooter(PIByteArray::fromUserInput(Q2PIString(fi_t->footer())));
@@ -345,8 +351,8 @@ void ConnectionEdit::recreateConnection() {
pe->setThreadedReadBufferSize(fi_t->bufferSize());
PIDiagnostics * diag = conn->diagnostic(pe);
if (diag) diag->setDisconnectTimeout(fi_t->disconnectTimeout());
QList<BlockBusItem*> nb = fi_t->pinByText("out")->connectedBuses();
foreach (BlockBusItem * b_, nb)
QList<BlockBusItem *> nb = fi_t->pinByText("out")->connectedBuses();
foreach(BlockBusItem * b_, nb)
if (!pbuses.contains(b_)) {
pbuses << b_;
nbuses << b_;
@@ -355,34 +361,34 @@ void ConnectionEdit::recreateConnection() {
buses = nbuses;
}
}
foreach (BlockItem * b, devs) {
foreach(BlockItem * b, devs) {
BlockItemPin * p = b->pinByText("write");
if (!p) continue;
QList<BlockBusItem*> buses = p->connectedBuses();
foreach (BlockBusItem * bus, buses) {
QList<BlockItem*> cb = bus->connectedBlocks();
QList<BlockBusItem *> buses = p->connectedBuses();
foreach(BlockBusItem * bus, buses) {
QList<BlockItem *> cb = bus->connectedBlocks();
if (cb.size() != 2) continue;
BlockItem * bi_f(0);
DeviceItem * di_t(0);
if (cb[0]->pinAtBus(bus)->text() == "write") {
di_t = (DeviceItem*)(cb[0]);
di_t = (DeviceItem *)(cb[0]);
bi_f = (cb[1]);
} else if (cb[1]->pinAtBus(bus)->text() == "write") {
di_t = (DeviceItem*)(cb[1]);
di_t = (DeviceItem *)(cb[1]);
bi_f = (cb[0]);
}
if (!bi_f || !di_t) continue;
QString name_from;
int type = bi_f->propertyByName("__type").value.toInt();
if (type == __CV_Sender) {
SenderItem * si = ((SenderItem*)bi_f);
SenderItem * si = ((SenderItem *)bi_f);
si->name();
conn->addSender(Q2PIString(si->name()), Q2PIString(di_t->path()), si->frequency());
if (!si->data().isEmpty())
conn->setSenderFixedData(Q2PIString(si->name()), PIByteArray::fromUserInput(Q2PIString(si->data())));
} else {
if (type == __CV_Device) name_from = ((DeviceItem*)bi_f)->name();
if (type == __CV_Filter) name_from = ((FilterItem*)bi_f)->name();
if (type == __CV_Device) name_from = ((DeviceItem *)bi_f)->name();
if (type == __CV_Filter) name_from = ((FilterItem *)bi_f)->name();
if (name_from.isEmpty()) continue;
conn->addChannel(Q2PIString(name_from), Q2PIString(di_t->name()));
}
@@ -411,12 +417,11 @@ void ConnectionEdit::on_buttonFilterAdd_clicked() {
void ConnectionEdit::on_buttonFilterModify_clicked() {
QList<QGraphicsItem*> si = ui->blockView->scene()->selectedItems();
QList<QGraphicsItem *> si = ui->blockView->scene()->selectedItems();
if (si.isEmpty()) return;
if (!qgraphicsitem_cast<BlockItem*>(si[0])) return;
if (qgraphicsitem_cast<BlockItem*>(si[0])->propertyByName("__type").value.toInt() != __CV_Filter)
return;
applyFilter(qgraphicsitem_cast<FilterItem*>(si[0]));
if (!qgraphicsitem_cast<BlockItem *>(si[0])) return;
if (qgraphicsitem_cast<BlockItem *>(si[0])->propertyByName("__type").value.toInt() != __CV_Filter) return;
applyFilter(qgraphicsitem_cast<FilterItem *>(si[0]));
}
@@ -435,12 +440,11 @@ void ConnectionEdit::on_buttonDeviceAdd_clicked() {
void ConnectionEdit::on_buttonDeviceModify_clicked() {
QList<QGraphicsItem*> si = ui->blockView->scene()->selectedItems();
QList<QGraphicsItem *> si = ui->blockView->scene()->selectedItems();
if (si.isEmpty()) return;
if (!qgraphicsitem_cast<BlockItem*>(si[0])) return;
if (qgraphicsitem_cast<BlockItem*>(si[0])->propertyByName("__type").value.toInt() != __CV_Device)
return;
applyDevice(qgraphicsitem_cast<DeviceItem*>(si[0]));
if (!qgraphicsitem_cast<BlockItem *>(si[0])) return;
if (qgraphicsitem_cast<BlockItem *>(si[0])->propertyByName("__type").value.toInt() != __CV_Device) return;
applyDevice(qgraphicsitem_cast<DeviceItem *>(si[0]));
}
@@ -451,12 +455,11 @@ void ConnectionEdit::on_buttonSenderAdd_clicked() {
void ConnectionEdit::on_buttonSenderModify_clicked() {
QList<QGraphicsItem*> si = ui->blockView->scene()->selectedItems();
QList<QGraphicsItem *> si = ui->blockView->scene()->selectedItems();
if (si.isEmpty()) return;
if (!qgraphicsitem_cast<BlockItem*>(si[0])) return;
if (qgraphicsitem_cast<BlockItem*>(si[0])->propertyByName("__type").value.toInt() != __CV_Sender)
return;
applySender(qgraphicsitem_cast<SenderItem*>(si[0]));
if (!qgraphicsitem_cast<BlockItem *>(si[0])) return;
if (qgraphicsitem_cast<BlockItem *>(si[0])->propertyByName("__type").value.toInt() != __CV_Sender) return;
applySender(qgraphicsitem_cast<SenderItem *>(si[0]));
}

View File

@@ -1,32 +1,33 @@
/*
PIQt Utils - Qt utilites for PIP
PIQt Utils - Qt utilites for PIP
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CONNECTION_EDIT_H
#define CONNECTION_EDIT_H
#include <QDialog>
#include "piconnection.h"
#include "qad_piqt_utils_export.h"
#include <QDialog>
namespace Ui {
class ConnectionEdit;
class ConnectionEdit;
}
class FilterItem;
@@ -35,18 +36,19 @@ class SenderItem;
class QAD_PIQT_UTILS_EXPORT ConnectionEdit: public QDialog {
Q_OBJECT
public:
explicit ConnectionEdit(QWidget * parent = 0);
~ConnectionEdit();
QString configuration() const;
QByteArray model() const;
QString name() const;
void setName(const QString & name);
void addDevice(const QString & name, const QString & path);
void setModel(const QByteArray & m);
private:
void accept();
void keyPressEvent(QKeyEvent *) {}
@@ -55,14 +57,16 @@ private:
void applySender(SenderItem * b);
int getOptions() const;
void setOptions(int o);
Ui::ConnectionEdit * ui;
PIConnection * conn;
bool loading;
int udevicenum;
private slots:
void recreateRequest() {if (!loading) QMetaObject::invokeMethod(this, "recreateConnection", Qt::QueuedConnection);}
void recreateRequest() {
if (!loading) QMetaObject::invokeMethod(this, "recreateConnection", Qt::QueuedConnection);
}
void on_buttonRemove_clicked();
void on_buttonClear_clicked();
void on_buttonFilterAdd_clicked();
@@ -73,10 +77,9 @@ private slots:
void on_buttonSenderModify_clicked();
void on_comboSplit_currentIndexChanged(int index);
void selectionChanged();
public slots:
void recreateConnection();
};
#endif // CONNECTION_EDIT_H

View File

@@ -1,6 +1,8 @@
#include "piqt_connection_view.h"
#include "picodeinfo.h"
#include "piqt.h"
#include <alignedtextitem.h>
@@ -11,7 +13,8 @@ DeviceItem::DeviceItem(): BlockItem() {
setColor(QColor(192, 192, 255));
text_name = new AlignedTextItem();
text_path = new AlignedTextItem();
QFont fnt(text_name->font()); fnt.setBold(true);
QFont fnt(text_name->font());
fnt.setBold(true);
text_name->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
text_name->setFont(fnt);
text_name->setPos(0., -size().height() / 2.);
@@ -29,19 +32,29 @@ DeviceItem::DeviceItem(): BlockItem() {
void DeviceItem::rename() {
QString ms;
BlockItemPin * pr = pinByText("read"), * pw = pinByText("write");
BlockItemPin *pr = pinByText("read"), *pw = pinByText("write");
switch (mode()) {
case PIIODevice::ReadOnly: ms = "ro"; pr->show(); pw->hide(); break;
case PIIODevice::WriteOnly: ms = "wo"; pr->hide(); pw->show(); break;
case PIIODevice::ReadWrite: ms = "rw"; pr->show(); pw->show(); break;
case PIIODevice::ReadOnly:
ms = "ro";
pr->show();
pw->hide();
break;
case PIIODevice::WriteOnly:
ms = "wo";
pr->hide();
pw->show();
break;
case PIIODevice::ReadWrite:
ms = "rw";
pr->show();
pw->show();
break;
}
text_name->setText(name() + " (" + ms + ")");
text_path->setText(path());
}
FilterItem::FilterItem(): BlockItem() {
addProperty(BlockItem::Property("__type", "", __CV_Filter));
addProperty(BlockItem::Property("bufferSize", "", 65536));
@@ -50,7 +63,8 @@ FilterItem::FilterItem(): BlockItem() {
setColor(QColor(192, 255, 192));
text_name = new AlignedTextItem();
text_mode = new AlignedTextItem();
QFont fnt(text_name->font()); fnt.setBold(true);
QFont fnt(text_name->font());
fnt.setBold(true);
text_name->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
text_name->setFont(fnt);
text_name->setPos(0., -size().height() / 2.);
@@ -71,9 +85,9 @@ void FilterItem::rename() {
QString ms;
PICodeInfo::EnumInfo * ei = PICodeInfo::enumsInfo->value("PIPacketExtractor::SplitMode", 0);
if (ei) {
piForeachC (PICodeInfo::EnumeratorInfo & i, ei->members)
piForeachC(PICodeInfo::EnumeratorInfo & i, ei->members)
if (i.value == mode()) {
#if PIP_VERSION >= PIP_MAKE_VERSION(2,39,0)
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 39, 0)
ms = PI2QString(i.name.toString());
#else
ms = PI2QString(i.name);
@@ -82,20 +96,18 @@ void FilterItem::rename() {
}
}
text_mode->setText(ms);
}
SenderItem::SenderItem(): BlockItem() {
addProperty(BlockItem::Property("__type", "", __CV_Sender));
setSize(140, 80);
setPos(-200, 0);
setColor(QColor(255, 192, 192));
text_name = new AlignedTextItem();
text_name = new AlignedTextItem();
text_frequency = new AlignedTextItem();
QFont fnt(text_name->font()); fnt.setBold(true);
QFont fnt(text_name->font());
fnt.setBold(true);
text_name->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
text_name->setFont(fnt);
text_name->setPos(0., -size().height() / 2.);
@@ -116,14 +128,10 @@ void SenderItem::rename() {
}
ConnectionView::ConnectionView(QWidget * parent): BlockView(parent) {}
ConnectionView::ConnectionView(QWidget * parent): BlockView(parent) {
}
ConnectionView::~ConnectionView() {
}
ConnectionView::~ConnectionView() {}
DeviceItem * ConnectionView::addDevice(const QString & name, const QString & path) {
@@ -166,10 +174,9 @@ SenderItem * ConnectionView::addSender(const QString & name) {
DeviceItem * ConnectionView::findDevice(const QString & name) const {
QList<BlockItem*> blockl = blocks();
foreach (BlockItem * b, blockl)
if ((b->propertyByName("name").value == name) && (b->propertyByName("__type").value.toInt() == __CV_Device))
return (DeviceItem*)b;
QList<BlockItem *> blockl = blocks();
foreach(BlockItem * b, blockl)
if ((b->propertyByName("name").value == name) && (b->propertyByName("__type").value.toInt() == __CV_Device)) return (DeviceItem *)b;
return 0;
}
@@ -179,14 +186,14 @@ void ConnectionView::loadBus(BlockBusItem * bus) {
}
void ConnectionView::placeBlock(BlockItem * b, QList<BlockItem * > coll) {
void ConnectionView::placeBlock(BlockItem * b, QList<BlockItem *> coll) {
if (coll.isEmpty()) return;
QList<QRectF> collr;
foreach (BlockItem * i, coll)
foreach(BlockItem * i, coll)
collr << i->sceneBoundingRect();
while (true) {
QRectF br = b->sceneBoundingRect();
bool ok = true;
bool ok = true;
for (int i = 0; i < collr.size(); ++i)
if (br.intersects(collr[i])) {
ok = false;
@@ -199,10 +206,9 @@ void ConnectionView::placeBlock(BlockItem * b, QList<BlockItem * > coll) {
}
QList<BlockItem * > ConnectionView::allByType(int type_) const {
QList<BlockItem*> blockl = blocks(), ret;
foreach (BlockItem * b, blockl)
if (b->propertyByName("__type").value.toInt() == type_)
ret << b;
QList<BlockItem *> ConnectionView::allByType(int type_) const {
QList<BlockItem *> blockl = blocks(), ret;
foreach(BlockItem * b, blockl)
if (b->propertyByName("__type").value.toInt() == type_) ret << b;
return ret;
}

View File

@@ -1,20 +1,20 @@
/*
PIQt Utils - Qt utilites for PIP
PIQt Utils - Qt utilites for PIP
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CONNECTION_VIEW_H
@@ -32,102 +32,150 @@ const int __CV_Sender = 3;
class QAD_PIQT_UTILS_EXPORT DeviceItem: public BlockItem {
public:
DeviceItem();
void setName(const QString & n) {addProperty(BlockItem::Property("name", "", n)); rename();}
void setPath(const QString & p) {addProperty(BlockItem::Property("device", "", p)); rename();}
void setMode(PIIODevice::DeviceMode m) {addProperty(BlockItem::Property("mode", "", int(m))); rename();}
void setOptions(PIIODevice::DeviceOptions o) {addProperty(BlockItem::Property("options", "", int(o))); rename();}
void setDisconnectTimeout(double v) {addProperty(BlockItem::Property("disconnectTimeout", "", v)); rename();}
void setBufferSize(int v) {addProperty(BlockItem::Property("bufferSize", "", v)); rename();}
QString name() const {return propertyByName("name").value.toString();}
QString path() const {return propertyByName("device").value.toString();}
PIIODevice::DeviceMode mode() const {return PIIODevice::DeviceMode(propertyByName("mode").value.toInt());}
PIIODevice::DeviceOptions options() const {return PIIODevice::DeviceOptions(propertyByName("options").value.toInt());}
double disconnectTimeout() const {return propertyByName("disconnectTimeout").value.toDouble();}
int bufferSize() const {return propertyByName("bufferSize").value.toInt();}
void setName(const QString & n) {
addProperty(BlockItem::Property("name", "", n));
rename();
}
void setPath(const QString & p) {
addProperty(BlockItem::Property("device", "", p));
rename();
}
void setMode(PIIODevice::DeviceMode m) {
addProperty(BlockItem::Property("mode", "", int(m)));
rename();
}
void setOptions(PIIODevice::DeviceOptions o) {
addProperty(BlockItem::Property("options", "", int(o)));
rename();
}
void setDisconnectTimeout(double v) {
addProperty(BlockItem::Property("disconnectTimeout", "", v));
rename();
}
void setBufferSize(int v) {
addProperty(BlockItem::Property("bufferSize", "", v));
rename();
}
QString name() const { return propertyByName("name").value.toString(); }
QString path() const { return propertyByName("device").value.toString(); }
PIIODevice::DeviceMode mode() const { return PIIODevice::DeviceMode(propertyByName("mode").value.toInt()); }
PIIODevice::DeviceOptions options() const { return PIIODevice::DeviceOptions(propertyByName("options").value.toInt()); }
double disconnectTimeout() const { return propertyByName("disconnectTimeout").value.toDouble(); }
int bufferSize() const { return propertyByName("bufferSize").value.toInt(); }
void rename();
protected:
AlignedTextItem * text_name, * text_path;
AlignedTextItem *text_name, *text_path;
};
class QAD_PIQT_UTILS_EXPORT FilterItem: public BlockItem {
public:
FilterItem();
void setName(const QString & n) {addProperty(BlockItem::Property("name", "", n)); rename();}
void setMode(PIPacketExtractor::SplitMode m) {addProperty(BlockItem::Property("mode", "", int(m))); rename();}
void setHeader(const QString & v) {addProperty(BlockItem::Property("header", "", v)); rename();}
void setFooter(const QString & v) {addProperty(BlockItem::Property("footer", "", v)); rename();}
void setTimeout(double v) {addProperty(BlockItem::Property("timeout", "", v)); rename();}
void setPacketSize(int v) {addProperty(BlockItem::Property("size", "", v)); rename();}
void setDisconnectTimeout(double v) {addProperty(BlockItem::Property("disconnectTimeout", "", v)); rename();}
void setBufferSize(int v) {addProperty(BlockItem::Property("bufferSize", "", v)); rename();}
QString name() const {return propertyByName("name").value.toString();}
PIPacketExtractor::SplitMode mode() const {return PIPacketExtractor::SplitMode(propertyByName("mode").value.toInt());}
QString header() const {return propertyByName("header").value.toString();}
QString footer() const {return propertyByName("footer").value.toString();}
double timeout() const {return propertyByName("timeout").value.toDouble();}
int packetSize() const {return propertyByName("size").value.toInt();}
double disconnectTimeout() const {return propertyByName("disconnectTimeout").value.toDouble();}
int bufferSize() const {return propertyByName("bufferSize").value.toInt();}
void setName(const QString & n) {
addProperty(BlockItem::Property("name", "", n));
rename();
}
void setMode(PIPacketExtractor::SplitMode m) {
addProperty(BlockItem::Property("mode", "", int(m)));
rename();
}
void setHeader(const QString & v) {
addProperty(BlockItem::Property("header", "", v));
rename();
}
void setFooter(const QString & v) {
addProperty(BlockItem::Property("footer", "", v));
rename();
}
void setTimeout(double v) {
addProperty(BlockItem::Property("timeout", "", v));
rename();
}
void setPacketSize(int v) {
addProperty(BlockItem::Property("size", "", v));
rename();
}
void setDisconnectTimeout(double v) {
addProperty(BlockItem::Property("disconnectTimeout", "", v));
rename();
}
void setBufferSize(int v) {
addProperty(BlockItem::Property("bufferSize", "", v));
rename();
}
QString name() const { return propertyByName("name").value.toString(); }
PIPacketExtractor::SplitMode mode() const { return PIPacketExtractor::SplitMode(propertyByName("mode").value.toInt()); }
QString header() const { return propertyByName("header").value.toString(); }
QString footer() const { return propertyByName("footer").value.toString(); }
double timeout() const { return propertyByName("timeout").value.toDouble(); }
int packetSize() const { return propertyByName("size").value.toInt(); }
double disconnectTimeout() const { return propertyByName("disconnectTimeout").value.toDouble(); }
int bufferSize() const { return propertyByName("bufferSize").value.toInt(); }
void rename();
protected:
AlignedTextItem * text_name, * text_mode;
AlignedTextItem *text_name, *text_mode;
};
class QAD_PIQT_UTILS_EXPORT SenderItem: public BlockItem {
public:
SenderItem();
void setName(const QString & n) {addProperty(BlockItem::Property("name", "", n)); rename();}
void setData(const QString & p) {addProperty(BlockItem::Property("data", "", p)); rename();}
void setFrequency(double m) {addProperty(BlockItem::Property("frequency", "", m)); rename();}
QString name() const {return propertyByName("name").value.toString();}
QString data() const {return propertyByName("data").value.toString();}
double frequency() const {return propertyByName("frequency").value.toDouble();}
void setName(const QString & n) {
addProperty(BlockItem::Property("name", "", n));
rename();
}
void setData(const QString & p) {
addProperty(BlockItem::Property("data", "", p));
rename();
}
void setFrequency(double m) {
addProperty(BlockItem::Property("frequency", "", m));
rename();
}
QString name() const { return propertyByName("name").value.toString(); }
QString data() const { return propertyByName("data").value.toString(); }
double frequency() const { return propertyByName("frequency").value.toDouble(); }
void rename();
protected:
AlignedTextItem * text_name, * text_frequency;
AlignedTextItem *text_name, *text_frequency;
};
class QAD_PIQT_UTILS_EXPORT ConnectionView: public BlockView {
Q_OBJECT
public:
explicit ConnectionView(QWidget * parent = 0);
~ConnectionView();
DeviceItem * addDevice(const QString & name, const QString & path);
FilterItem * addFilter(const QString & name);
SenderItem * addSender(const QString & name);
DeviceItem * findDevice(const QString & name) const;
QList<BlockItem * > allDevices() const {return allByType(__CV_Device);}
QList<BlockItem * > allFilters() const {return allByType(__CV_Filter);}
QList<BlockItem * > allSenders() const {return allByType(__CV_Sender);}
QList<BlockItem *> allDevices() const { return allByType(__CV_Device); }
QList<BlockItem *> allFilters() const { return allByType(__CV_Filter); }
QList<BlockItem *> allSenders() const { return allByType(__CV_Sender); }
private:
QSize sizeHint() const {return QSize(800, 600);}
QSize sizeHint() const { return QSize(800, 600); }
void loadBus(BlockBusItem * bus);
void placeBlock(BlockItem * b, QList<BlockItem*> coll);
QList<BlockItem * > allByType(int type_) const;
void placeBlock(BlockItem * b, QList<BlockItem *> coll);
QList<BlockItem *> allByType(int type_) const;
private slots:
};
#endif // CONNECTION_VIEW_H

View File

@@ -6,30 +6,30 @@ ConfigHighlighter::ConfigHighlighter(QTextDocument * parent): QSyntaxHighlighter
valueNameFormat.setForeground(QColor(0, 64, 154));
rule.pattern = QRegularExpression("[^=]"); //"\\b[A-Za-z0-9_]+(?=\\()");
rule.format = valueNameFormat;
rule.format = valueNameFormat;
highlightingRules.append(rule);
valueFormat.setForeground(QColor(192, 0, 0));
rule.pattern = QRegularExpression("=[^\n]*");
rule.format = valueFormat;
rule.format = valueFormat;
highlightingRules.append(rule);
equalFormat.setFontWeight(QFont::Bold);
equalFormat.setForeground(QColor(96, 126, 0));
rule.pattern = QRegularExpression("=");
rule.format = equalFormat;
rule.format = equalFormat;
highlightingRules.append(rule);
sectionFormat.setFontWeight(QFont::Bold);
sectionFormat.setForeground(QColor(0, 32, 64));
rule.pattern = QRegularExpression("\\[.*\\]");
rule.format = sectionFormat;
rule.format = sectionFormat;
highlightingRules.append(rule);
substFormat.setForeground(QColor(192, 0, 192));
rule.pattern = QRegularExpression("\\$\\{.*\\}+");
//rule.pattern.setMinimal(true);
rule.format = substFormat;
// rule.pattern.setMinimal(true);
rule.format = substFormat;
highlightingRules.append(rule);
rule.pattern = QRegularExpression("\\$\\{[^\\{]*\\}+");
highlightingRules.append(rule);
@@ -37,18 +37,18 @@ ConfigHighlighter::ConfigHighlighter(QTextDocument * parent): QSyntaxHighlighter
singleLineCommentFormat.setFontItalic(true);
singleLineCommentFormat.setForeground(QColor(128, 128, 128));
rule.pattern = QRegularExpression("#[^\n]*");
rule.format = singleLineCommentFormat;
rule.format = singleLineCommentFormat;
highlightingRules.append(rule);
spaceFormat.setForeground(QColor(210, 210, 210));
//commentStartExpression = QRegExp("/\\*");
//commentEndExpression = QRegExp("\\*/");
// commentStartExpression = QRegExp("/\\*");
// commentEndExpression = QRegExp("\\*/");
}
void ConfigHighlighter::highlightBlock(const QString & text) {
foreach (const HighlightingRule &rule, highlightingRules) {
foreach(const HighlightingRule & rule, highlightingRules) {
QRegularExpression expression(rule.pattern);
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QRegularExpressionMatchIterator i = expression.globalMatch(text);
@@ -66,7 +66,7 @@ void ConfigHighlighter::highlightBlock(const QString & text) {
#endif
}
setCurrentBlockState(0);
QRegularExpression expression("[ |\t]");
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QRegularExpressionMatchIterator i = expression.globalMatch(text);

View File

@@ -1,49 +1,49 @@
/*
PIQt Utils - Qt utilites for PIP
PIQt Utils - Qt utilites for PIP
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CONF_HIGHLIGHTER_H
#define CONF_HIGHLIGHTER_H
#include <QSyntaxHighlighter>
#include <QTextCursor>
#include <QTextCharFormat>
#include <QTextCursor>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
# include <QRegularExpression>
#else
# include <QRegExp>
typedef QRegExp QRegularExpression;
typedef QRegExp QRegularExpression;
#endif
#include "qad_piqt_utils_export.h"
class QTextDocument;
class QAD_PIQT_UTILS_EXPORT ConfigHighlighter : public QSyntaxHighlighter
{
class QAD_PIQT_UTILS_EXPORT ConfigHighlighter: public QSyntaxHighlighter {
Q_OBJECT
public:
ConfigHighlighter(QTextDocument *parent = 0);
ConfigHighlighter(QTextDocument * parent = 0);
QTextCursor cursor;
private:
void highlightBlock(const QString &text);
void highlightBlock(const QString & text);
struct QAD_PIQT_UTILS_EXPORT HighlightingRule {
QRegularExpression pattern;
QTextCharFormat format;

View File

@@ -1,17 +1,19 @@
#include "piqt_iodevice_edit.h"
#include "piqt_iodevice_edit_dialog.h"
#include "qvariantedit_custom.h"
#include <QBoxLayout>
#include <QLineEdit>
#include <QToolButton>
#include <QBoxLayout>
#include <piqt.h>
#include <piiodevice.h>
#include <piqt.h>
IODeviceEdit::IODeviceEdit(QWidget * parent): QWidget(parent) {
dlg = new IODeviceEditDialog();
dlg = new IODeviceEditDialog();
line = new QLineEdit();
btn = new QToolButton();
btn = new QToolButton();
setLayout(new QBoxLayout(QBoxLayout::LeftToRight));
layout()->setContentsMargins(0, 0, 0, 0);
layout()->addWidget(line);
@@ -65,11 +67,10 @@ void IODeviceEdit::buttonDlg_clicked() {
}
class Factory: public QVariantEditorFactoryBase {
public:
Factory() {}
virtual QWidget * createEditor() {return new IODeviceEdit();}
virtual QWidget * createEditor() { return new IODeviceEdit(); }
};
@@ -81,11 +82,11 @@ __IODeviceEditRegistrator__::__IODeviceEditRegistrator__() {
void QAD_IODevice_toString(const QVariant & v, QString & r) {
PIVariantTypes::IODevice sd = Q2PIVariant(v).toIODevice();
// piCout << sd;
PIIODevice * rd = PIIODevice::createFromVariant(sd);
// piCout << sd;
PIIODevice * rd = PIIODevice::createFromVariant(sd);
if (rd) {
PIString ps = rd->constructFullPath();
r = PI2QString(ps);
r = PI2QString(ps);
} else {
piCout << "error in " << sd;
}

View File

@@ -1,28 +1,29 @@
/*
PIQt Utils - Qt utilites for PIP
PIQt Utils - Qt utilites for PIP
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIQT_IODEVICE_EDIT_H
#define PIQT_IODEVICE_EDIT_H
#include <QWidget>
#include "qad_types.h"
#include "qad_piqt_utils_export.h"
#include "qad_types.h"
#include <QWidget>
class QLineEdit;
class QToolButton;
@@ -33,13 +34,14 @@ class QAD_PIQT_UTILS_EXPORT IODeviceEdit: public QWidget {
Q_OBJECT
Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
public:
explicit IODeviceEdit(QWidget * parent = 0);
~IODeviceEdit();
QVariant value() const;
bool isReadOnly() const;
private:
void setDevice(const QAD::IODevice & d);
@@ -47,7 +49,7 @@ private:
QToolButton * btn;
IODeviceEditDialog * dlg;
QAD::IODevice dev;
public slots:
void setValue(const QVariant & v);
void setReadOnly(bool yes);
@@ -57,7 +59,6 @@ private slots:
signals:
void valueChanged();
};

View File

@@ -1,8 +1,10 @@
#include "ui_piqt_iodevice_edit_dialog.h"
#include "piqt_iodevice_edit_dialog.h"
#include "piqt.h"
#include "picodeinfo.h"
#include "piiodevice.h"
#include "piqt.h"
#include "ui_piqt_iodevice_edit_dialog.h"
#include <QCheckBox>
@@ -11,9 +13,10 @@ IODeviceEditDialog::IODeviceEditDialog(QWidget * parent): QDialog(parent) {
ui->setupUi(this);
PICodeInfo::EnumInfo * ei = PICodeInfo::enumsInfo->value("PIIODevice::DeviceMode");
if (ei) {
piForeachC (PICodeInfo::EnumeratorInfo & e, ei->members)
#if PIP_VERSION >= PIP_MAKE_VERSION(2,39,0)
ui->comboMode->addItem(PI2QString(e.name.toString() + " (" + PIString::fromNumber(e.value) + ")"), QVariant::fromValue<int>(e.value));
piForeachC(PICodeInfo::EnumeratorInfo & e, ei->members)
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 39, 0)
ui->comboMode->addItem(PI2QString(e.name.toString() + " (" + PIString::fromNumber(e.value) + ")"),
QVariant::fromValue<int>(e.value));
#else
ui->comboMode->addItem(PI2QString(e.name + " (" + PIString::fromNumber(e.value) + ")"), QVariant::fromValue<int>(e.value));
#endif
@@ -21,9 +24,9 @@ IODeviceEditDialog::IODeviceEditDialog(QWidget * parent): QDialog(parent) {
ui->comboMode->setCurrentIndex(ui->comboMode->count() - 1);
ei = PICodeInfo::enumsInfo->value("PIIODevice::DeviceOption");
if (ei) {
piForeachC (PICodeInfo::EnumeratorInfo & e, ei->members) {
piForeachC(PICodeInfo::EnumeratorInfo & e, ei->members) {
QCheckBox * cb = new QCheckBox();
#if PIP_VERSION >= PIP_MAKE_VERSION(2,39,0)
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 39, 0)
cb->setText(PI2QString(e.name.toString() + " (" + PIString::fromNumber(e.value) + ")"));
#else
cb->setText(PI2QString(e.name + " (" + PIString::fromNumber(e.value) + ")"));
@@ -33,23 +36,21 @@ IODeviceEditDialog::IODeviceEditDialog(QWidget * parent): QDialog(parent) {
}
}
PIStringList pl = PIIODevice::availablePrefixes();
piForeachC (PIString & p, pl) {
piForeachC(PIString & p, pl) {
ui->comboType->addItem(PI2QString(p));
}
}
IODeviceEditDialog::~IODeviceEditDialog() {
}
IODeviceEditDialog::~IODeviceEditDialog() {}
int IODeviceEditDialog::getOptions() const {
int ret = 0;
for (int i = 0; i < ui->layoutOptions->count(); ++i) {
QCheckBox * cb = qobject_cast<QCheckBox*>(ui->layoutOptions->itemAt(i)->widget());
QCheckBox * cb = qobject_cast<QCheckBox *>(ui->layoutOptions->itemAt(i)->widget());
if (!cb) continue;
if (cb->isChecked())
ret |= cb->property("__value").toInt();
if (cb->isChecked()) ret |= cb->property("__value").toInt();
}
return ret;
}
@@ -57,7 +58,7 @@ int IODeviceEditDialog::getOptions() const {
void IODeviceEditDialog::setOptions(int o) {
for (int i = 0; i < ui->layoutOptions->count(); ++i) {
QCheckBox * cb = qobject_cast<QCheckBox*>(ui->layoutOptions->itemAt(i)->widget());
QCheckBox * cb = qobject_cast<QCheckBox *>(ui->layoutOptions->itemAt(i)->widget());
if (!cb) continue;
int cbf = cb->property("__value").toInt();
cb->setChecked((o & cbf) == cbf);
@@ -67,7 +68,7 @@ void IODeviceEditDialog::setOptions(int o) {
void IODeviceEditDialog::on_comboType_currentIndexChanged(int index) {
PIString prefix = Q2PIString(ui->comboType->currentText());
auto * d = PIIODevice::createFromFullPath(prefix + "://");
auto * d = PIIODevice::createFromFullPath(prefix + "://");
if (d) {
ps = PI2QPropertyStorage(d->constructVariant().get());
ui->widgetProperties->setStorage(&ps);
@@ -78,8 +79,7 @@ void IODeviceEditDialog::on_comboType_currentIndexChanged(int index) {
QAD::IODevice IODeviceEditDialog::getIODevice(const QAD::IODevice & d) {
setValue(d);
if (QDialog::exec() != QDialog::Accepted)
return QAD::IODevice();
if (QDialog::exec() != QDialog::Accepted) return QAD::IODevice();
return value();
}
@@ -87,10 +87,10 @@ QAD::IODevice IODeviceEditDialog::getIODevice(const QAD::IODevice & d) {
QAD::IODevice IODeviceEditDialog::value() const {
QAD::IODevice d;
ui->widgetProperties->applyProperties();
d.prefix = ui->comboType->currentText();
d.mode = ui->comboMode->itemData(ui->comboMode->currentIndex()).toInt();
d.prefix = ui->comboType->currentText();
d.mode = ui->comboMode->itemData(ui->comboMode->currentIndex()).toInt();
d.options = getOptions();
d.props = ps;
d.props = ps;
return d;
}

View File

@@ -1,40 +1,42 @@
/*
PIQt Utils - Qt utilites for PIP
PIQt Utils - Qt utilites for PIP
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIQT_IODEVICE_EDIT_DIALOG_H
#define PIQT_IODEVICE_EDIT_DIALOG_H
#include <QDialog>
#include "qad_types.h"
#include "propertystorage.h"
#include "qad_piqt_utils_export.h"
#include "qad_types.h"
#include <QDialog>
namespace Ui {
class IODeviceEditDialog;
class IODeviceEditDialog;
}
class QAD_PIQT_UTILS_EXPORT IODeviceEditDialog: public QDialog {
Q_OBJECT
public:
explicit IODeviceEditDialog(QWidget * parent = 0);
~IODeviceEditDialog();
QAD::IODevice getIODevice(const QAD::IODevice & d);
private:
@@ -45,10 +47,9 @@ private:
PropertyStorage ps;
Ui::IODeviceEditDialog * ui;
private slots:
void on_comboType_currentIndexChanged(int index);
};
#endif // PIQT_IODEVICE_EDIT_DIALOG_H

View File

@@ -104,7 +104,7 @@ void PIValueTreeEdit::build() {
widget_array = new QWidget();
ui_array->setupUi(widget_array);
ui_array->spinCount->setRange(source.attribute(PIValueTree::attributeArrayMinCount, 0).toInt(),
source.attribute(PIValueTree::attributeArrayMaxCount, 65536).toInt());
source.attribute(PIValueTree::attributeArrayMaxCount, 65536).toInt());
ui_array->spinCount->setValue(source.children().size_s());
ui_array->widgetEdit->setVisible(source.attribute(PIValueTree::attributeArrayResize, false).toBool());
ui_array->layoutArray->addWidget(grid);

View File

@@ -1,20 +1,20 @@
/*
PIQt Utils - Qt utilites for PIP
PIQt Utils - Qt utilites for PIP
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef pivaluetree_edit_H

View File

@@ -1,20 +1,20 @@
/*
PIQt Utils - Qt utilites for PIP
PIQt Utils - Qt utilites for PIP
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef pivariant_edit_H

View File

@@ -36,7 +36,7 @@ PIVariantMap PIVariantEditors::Int::defaultAttributes() const {
void PIVariantEditors::Int::applyAttributes(const PIVariantMap & a) {
widget->setRange(a.value(PIValueTree::attributeMinimum, widget->minimum()).toInt(),
a.value(PIValueTree::attributeMaximum, widget->maximum()).toInt());
a.value(PIValueTree::attributeMaximum, widget->maximum()).toInt());
widget->setSingleStep(a.value(PIValueTree::attributeSingleStep, widget->singleStep()).toInt());
widget->setPrefix(PI2QString(a.value(PIValueTree::attributePrefix, Q2PIString(widget->prefix())).toString()));
widget->setSuffix(PI2QString(a.value(PIValueTree::attributeSuffix, Q2PIString(widget->suffix())).toString()));
@@ -60,7 +60,7 @@ PIVariantMap PIVariantEditors::Double::defaultAttributes() const {
void PIVariantEditors::Double::applyAttributes(const PIVariantMap & a) {
widget->setRange(a.value(PIValueTree::attributeMinimum, widget->minimum()).toDouble(),
a.value(PIValueTree::attributeMaximum, widget->maximum()).toDouble());
a.value(PIValueTree::attributeMaximum, widget->maximum()).toDouble());
widget->setSingleStep(a.value(PIValueTree::attributeSingleStep, widget->singleStep()).toDouble());
widget->setDecimals(a.value(PIValueTree::attributeDecimals, widget->decimals()).toInt());
widget->setPrefix(PI2QString(a.value(PIValueTree::attributePrefix, Q2PIString(widget->prefix())).toString()));

View File

@@ -1,20 +1,20 @@
/*
PIQt Utils - Qt utilites for PIP
PIQt Utils - Qt utilites for PIP
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef pivariant_edit_widgets_H