rename libs/piqt_widgtes to libs/piqt_utils

add PIVariantEdit for PIGeoPosition
This commit is contained in:
2023-01-29 20:29:15 +03:00
parent ef0963c878
commit 993a9219d5
42 changed files with 386 additions and 4 deletions

View File

@@ -0,0 +1,14 @@
find_package(PIP)
if (PIP_FOUND AND BUILDING_PIP)
project(piqt_utils)
pip_code_model(CCM "${PIP_ROOT_SRC}/libs/main/io_devices/piiodevice.h" "${PIP_ROOT_SRC}/libs/main/io_utils/pipacketextractor.h" OPTIONS "-DPIP_EXPORT" "-Es" ABSOLUTE)
qad_library(piqt_utils "Gui" "qad_blockview;qad_piqt" ${CCM})
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v})
add_dependencies(qad_piqt_utils${_v} pip_cmg)
endif()
endforeach()
endif()

View File

@@ -0,0 +1,507 @@
#include "piqt_connection_edit.h"
#include "picodeinfo.h"
#include "piqt.h"
#include "piqt_connection_view.h"
#include "piqt_highlighter.h"
#include "ui_piqt_connection_edit.h"
#include <QCheckBox>
#include <QMessageBox>
ConnectionEdit::ConnectionEdit(QWidget * parent): QDialog(parent) {
ui = new Ui::ConnectionEdit();
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->scene(), SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
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));
#else
ui->comboMode->addItem(PI2QString(e.name + " (" + PIString::fromNumber(e.value) + ")"), QVariant::fromValue<int>(e.value));
#endif
}
ui->comboMode->setCurrentIndex(ui->comboMode->count() - 1);
ei = PICodeInfo::enumsInfo->value("PIIODevice::DeviceOption");
if (ei) {
piForeachC(PICodeInfo::EnumeratorInfo & e, ei->members) {
QCheckBox * cb = new QCheckBox();
#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) + ")"));
#endif
cb->setProperty("__value", e.value);
ui->layoutOptions->addWidget(cb);
}
}
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));
#else
ui->comboSplit->addItem(PI2QString(e.name + " (" + PIString::fromNumber(e.value) + ")"), QVariant::fromValue<int>(e.value));
#endif
}
udevicenum = 0;
}
ConnectionEdit::~ConnectionEdit() {
if (conn) {
conn->stop();
delete conn;
}
}
void ConnectionEdit::accept() {
// 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()));
return;
}
QDialog::accept();
}
QString ConnectionEdit::configuration() const {
if (!conn) return QString();
return PI2QString(conn->makeConfig());
}
QByteArray ConnectionEdit::model() const {
QByteArray ret;
QDataStream s(&ret, QIODevice::ReadWrite);
QString cn = PI2QString(conn ? conn->name() : PIString());
s << cn;
QList<BlockBusItem *> busl = ui->blockView->buses();
s << busl.size();
foreach(BlockBusItem * b, busl)
s << b->save();
QList<BlockItem *> blockl = ui->blockView->blocks();
s << blockl.size();
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;
}
}
return ret;
}
QString ConnectionEdit::name() const {
if (!conn) return QString();
return PI2QString(conn->name());
}
void ConnectionEdit::setName(const QString & name) {
ui->lineName->setText(name);
recreateConnection();
}
void ConnectionEdit::addDevice(const QString & name, const QString & path) {
ui->blockView->addDevice(name, path);
}
void ConnectionEdit::setModel(const QByteArray & m) {
loading = true;
ui->blockView->removeAll();
QDataStream s(m);
QString cn;
s >> cn;
if (conn) delete conn;
conn = new PIConnection(Q2PIString(cn));
ui->lineName->setText(cn);
int sz;
s >> sz;
for (int i = 0; i < sz; ++i) {
BlockBusItem * b = new BlockBusItem();
QByteArray ba;
s >> ba;
b->load(ba);
ui->blockView->addItem(b);
}
s >> sz;
for (int i = 0; i < sz; ++i) {
int type(0);
BlockItem * b(0);
QByteArray ba;
s >> type;
switch (type) {
case __CV_Device:
b = new DeviceItem();
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();
break;
case __CV_Sender:
b = new SenderItem();
s >> ba;
b->load(ba);
((SenderItem *)b)->rename();
break;
}
if (b) ui->blockView->addItem(b);
}
ui->blockView->reconnectAll();
loading = false;
recreateConnection();
}
void ConnectionEdit::selectionChanged() {
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]);
if (!b) return;
int type = b->propertyByName("__type").value.toInt();
if (type == __CV_Device) {
ui->tabWidget->setCurrentIndex(0);
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()) {
ui->comboMode->setCurrentIndex(i);
break;
}
ui->lineDevice->setText(di->name());
ui->linePath->setEditText(di->path());
ui->spinDeviceDT->setValue(di->disconnectTimeout());
ui->spinDeviceBS->setValue(di->bufferSize());
setOptions(di->options());
}
if (type == __CV_Filter) {
ui->tabWidget->setCurrentIndex(1);
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()) {
ui->comboSplit->setCurrentIndex(i);
break;
}
ui->lineFilter->setText(fi->name());
ui->lineHeader->setText(fi->header());
ui->lineFooter->setText(fi->footer());
ui->spinTimeout->setValue(fi->timeout());
ui->spinSize->setValue(fi->packetSize());
ui->spinFilterDT->setValue(fi->disconnectTimeout());
ui->spinFilterBS->setValue(fi->bufferSize());
}
if (type == __CV_Sender) {
ui->tabWidget->setCurrentIndex(2);
SenderItem * si = (SenderItem *)b;
ui->buttonSenderModify->setEnabled(true);
ui->lineSender->setText(si->name());
ui->lineData->setText(si->data());
ui->spinFrequency->setValue(si->frequency());
}
}
void ConnectionEdit::applyFilter(FilterItem * b) {
b->setName(ui->lineFilter->text());
b->setMode(PIPacketExtractor::SplitMode(ui->comboSplit->itemData(ui->comboSplit->currentIndex()).toInt()));
b->setHeader(ui->lineHeader->text());
b->setFooter(ui->lineFooter->text());
b->setTimeout(ui->spinTimeout->value());
b->setPacketSize(ui->spinSize->value());
b->setDisconnectTimeout(ui->spinFilterDT->value());
b->setBufferSize(ui->spinFilterBS->value());
recreateConnection();
}
void ConnectionEdit::applyDevice(DeviceItem * b) {
QString n = ui->lineDevice->text();
if (n.isEmpty()) {
n = "device" + QString::number(udevicenum);
}
b->setName(n);
b->setMode(PIIODevice::DeviceMode(ui->comboMode->itemData(ui->comboMode->currentIndex()).toInt()));
b->setOptions(PIIODevice::DeviceOptions(getOptions()));
b->setPath(ui->linePath->currentText());
b->setDisconnectTimeout(ui->spinDeviceDT->value());
b->setBufferSize(ui->spinDeviceBS->value());
recreateConnection();
}
void ConnectionEdit::applySender(SenderItem * b) {
b->setName(ui->lineSender->text());
b->setData(ui->lineData->text());
b->setFrequency(ui->spinFrequency->value());
recreateConnection();
}
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());
if (!cb) continue;
if (cb->isChecked()) ret |= cb->property("__value").toInt();
}
return ret;
}
void ConnectionEdit::setOptions(int o) {
for (int i = 0; i < ui->layoutOptions->count(); ++i) {
QCheckBox * cb = qobject_cast<QCheckBox *>(ui->layoutOptions->itemAt(i)->widget());
if (!cb) continue;
int cbf = cb->property("__value").toInt();
// qDebug() << cbf;
cb->setChecked((o & cbf) == cbf);
}
}
void ConnectionEdit::recreateConnection() {
// 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();
PIIODevice * dev = conn->addDevice(Q2PIString(di->path()), di->mode());
if (!dev) continue;
dev->setOptions(di->options());
dev->setThreadedReadBufferSize(di->bufferSize());
conn->setDeviceName(dev, Q2PIString(di->name()));
PIDiagnostics * diag = conn->diagnostic(dev);
if (diag) diag->setDisconnectTimeout(di->disconnectTimeout());
}
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;
while (!buses.isEmpty()) {
nbuses.clear();
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]);
bi_f = (cb[1]);
} else if (cb[1]->pinAtBus(bus)->text() == "in") {
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 (name_from.isEmpty()) continue;
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())));
pe->setTimeout(fi_t->timeout());
pe->setPayloadSize(fi_t->packetSize());
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)
if (!pbuses.contains(b_)) {
pbuses << b_;
nbuses << b_;
}
}
buses = nbuses;
}
}
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();
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]);
bi_f = (cb[1]);
} else if (cb[1]->pinAtBus(bus)->text() == "write") {
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);
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 (name_from.isEmpty()) continue;
conn->addChannel(Q2PIString(name_from), Q2PIString(di_t->name()));
}
}
}
ui->codeEdit->setText(PI2QString(conn->makeConfig()));
}
void ConnectionEdit::on_buttonRemove_clicked() {
ui->blockView->removeSelected();
recreateConnection();
}
void ConnectionEdit::on_buttonClear_clicked() {
ui->blockView->removeAll();
recreateConnection();
}
void ConnectionEdit::on_buttonFilterAdd_clicked() {
if (!conn) return;
applyFilter(ui->blockView->addFilter(ui->lineFilter->text()));
}
void ConnectionEdit::on_buttonFilterModify_clicked() {
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]));
}
void ConnectionEdit::on_buttonDeviceAdd_clicked() {
if (!conn) return;
QString n = ui->lineDevice->text();
if (n.isEmpty()) {
udevicenum++;
n = "device" + QString::number(udevicenum);
}
QString p = ui->linePath->currentText();
if (ui->linePath->findText(p) < 0) ui->linePath->addItem(p);
qDebug() << "add:" << n;
applyDevice(ui->blockView->addDevice(n, ui->linePath->currentText()));
}
void ConnectionEdit::on_buttonDeviceModify_clicked() {
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]));
}
void ConnectionEdit::on_buttonSenderAdd_clicked() {
if (!conn) return;
applySender(ui->blockView->addSender(ui->lineSender->text()));
}
void ConnectionEdit::on_buttonSenderModify_clicked() {
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]));
}
void ConnectionEdit::on_comboSplit_currentIndexChanged(int index) {
int mode = ui->comboSplit->itemData(index).toInt();
switch (mode) {
case PIPacketExtractor::None:
ui->widgetHeader->setEnabled(false);
ui->widgetFooter->setEnabled(false);
ui->widgetTimeout->setEnabled(false);
ui->widgetSize->setEnabled(false);
break;
case PIPacketExtractor::Header:
ui->widgetHeader->setEnabled(true);
ui->widgetFooter->setEnabled(false);
ui->widgetTimeout->setEnabled(false);
ui->widgetSize->setEnabled(true);
break;
case PIPacketExtractor::Footer:
ui->widgetHeader->setEnabled(false);
ui->widgetFooter->setEnabled(true);
ui->widgetTimeout->setEnabled(false);
ui->widgetSize->setEnabled(true);
break;
case PIPacketExtractor::HeaderAndFooter:
ui->widgetHeader->setEnabled(true);
ui->widgetFooter->setEnabled(true);
ui->widgetTimeout->setEnabled(false);
ui->widgetSize->setEnabled(false);
break;
case PIPacketExtractor::Timeout:
ui->widgetHeader->setEnabled(false);
ui->widgetFooter->setEnabled(false);
ui->widgetTimeout->setEnabled(true);
ui->widgetSize->setEnabled(false);
break;
case PIPacketExtractor::Size:
ui->widgetHeader->setEnabled(false);
ui->widgetFooter->setEnabled(false);
ui->widgetTimeout->setEnabled(false);
ui->widgetSize->setEnabled(true);
break;
default: break;
}
}

View File

@@ -0,0 +1,85 @@
/*
PIQt Utils - Qt utilites for PIP
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 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/>.
*/
#ifndef CONNECTION_EDIT_H
#define CONNECTION_EDIT_H
#include "piconnection.h"
#include "qad_piqt_utils_export.h"
#include <QDialog>
namespace Ui {
class ConnectionEdit;
}
class FilterItem;
class DeviceItem;
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 *) {}
void applyFilter(FilterItem * b);
void applyDevice(DeviceItem * b);
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 on_buttonRemove_clicked();
void on_buttonClear_clicked();
void on_buttonFilterAdd_clicked();
void on_buttonFilterModify_clicked();
void on_buttonDeviceAdd_clicked();
void on_buttonDeviceModify_clicked();
void on_buttonSenderAdd_clicked();
void on_buttonSenderModify_clicked();
void on_comboSplit_currentIndexChanged(int index);
void selectionChanged();
public slots:
void recreateConnection();
};
#endif // CONNECTION_EDIT_H

View File

@@ -0,0 +1,942 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConnectionEdit</class>
<widget class="QDialog" name="ConnectionEdit">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>794</width>
<height>799</height>
</rect>
</property>
<property name="windowTitle">
<string>Connection editor</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QSplitter" name="splitter_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_4">
<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>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineName"/>
</item>
</layout>
</item>
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Device</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<item row="0" column="0">
<widget class="QLabel" name="labelFilter_4">
<property name="text">
<string>Name:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="CLineEdit" name="lineDevice"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelFilter_11">
<property name="text">
<string>Path:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="EComboBox" name="linePath">
<property name="editable">
<bool>true</bool>
</property>
<property name="currentIndex">
<number>-1</number>
</property>
<item>
<property name="text">
<string>eth://UDP:127.0.0.1:12345:127.0.0.1:12346</string>
</property>
</item>
<item>
<property name="text">
<string>eth://TCP:127.0.0.1:16666</string>
</property>
</item>
<item>
<property name="text">
<string>eth://UDP:192.168.0.5:16666:192.168.0.6:16667:mcast:234.0.2.1:mcast:234.0.2.2</string>
</property>
</item>
<item>
<property name="text">
<string>file://./text.txt</string>
</property>
</item>
<item>
<property name="text">
<string>binlog://./logs/:mylog_:1</string>
</property>
</item>
<item>
<property name="text">
<string>ser:///dev/ttyUSB0:9600:8:N:1</string>
</property>
</item>
<item>
<property name="text">
<string>ser://COM32:115200:8:N:1</string>
</property>
</item>
<item>
<property name="text">
<string>usb://0bb4:0c86:1:1:2</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelFilter_12">
<property name="text">
<string>Mode:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="comboMode"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelFilter_14">
<property name="text">
<string>Options:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="1">
<layout class="QVBoxLayout" name="layoutOptions">
<property name="spacing">
<number>2</number>
</property>
</layout>
</item>
<item row="4" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_14">
<item>
<widget class="QLabel" name="labelFilter_13">
<property name="text">
<string>Disconnect timeout:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="spinDeviceDT">
<property name="suffix">
<string> ms</string>
</property>
<property name="maximum">
<double>9999.000000000000000</double>
</property>
<property name="value">
<double>3.000000000000000</double>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labelFilter_15">
<property name="text">
<string>Buffer size:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinDeviceBS">
<property name="suffix">
<string> b</string>
</property>
<property name="maximum">
<number>999999999</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<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>
</item>
</layout>
</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>
<layout class="QHBoxLayout" name="horizontalLayout_18">
<item>
<widget class="QPushButton" name="buttonDeviceAdd">
<property name="text">
<string>Add</string>
</property>
<property name="icon">
<iconset resource="../../../qad/libs/application/qad_application.qrc">
<normaloff>:/icons/list-add.png</normaloff>:/icons/list-add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonDeviceModify">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Modify</string>
</property>
<property name="icon">
<iconset resource="../../../qad/libs/application/qad_application.qrc">
<normaloff>:/icons/document-save.png</normaloff>:/icons/document-save.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Filter</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="labelFilter">
<property name="text">
<string>Name:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="CLineEdit" name="lineFilter"/>
</item>
<item>
<widget class="QComboBox" name="comboSplit"/>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Parameters</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QWidget" name="widgetHeader" native="true">
<property name="enabled">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<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="QLabel" name="labelFilter_2">
<property name="text">
<string>Header:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="CLineEdit" name="lineHeader"/>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QWidget" name="widgetFooter" native="true">
<property name="enabled">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<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="QLabel" name="labelFilter_3">
<property name="text">
<string>Footer:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="CLineEdit" name="lineFooter"/>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QWidget" name="widgetTimeout" native="true">
<property name="enabled">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<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="QLabel" name="labelFilter_7">
<property name="text">
<string>Timeout:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="spinTimeout">
<property name="suffix">
<string> ms</string>
</property>
<property name="maximum">
<double>99999.000000000000000</double>
</property>
<property name="value">
<double>10.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QWidget" name="widgetSize" native="true">
<property name="enabled">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<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="QLabel" name="labelFilter_8">
<property name="text">
<string>Size:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinSize">
<property name="maximum">
<number>999999999</number>
</property>
<property name="value">
<number>8</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>1</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QWidget" name="widgetDT" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_12">
<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="QLabel" name="labelFilter_9">
<property name="text">
<string>Disconnect timeout:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="spinFilterDT">
<property name="suffix">
<string> ms</string>
</property>
<property name="maximum">
<double>9999.000000000000000</double>
</property>
<property name="value">
<double>3.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widgetSize_2" native="true">
<property name="enabled">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_13">
<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>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>17</width>
<height>17</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labelFilter_17">
<property name="text">
<string>Buffer size:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinFilterBS">
<property name="suffix">
<string> b</string>
</property>
<property name="maximum">
<number>999999999</number>
</property>
<property name="value">
<number>65536</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>1</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<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>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="buttonFilterAdd">
<property name="text">
<string>Add</string>
</property>
<property name="icon">
<iconset resource="../../../qad/libs/application/qad_application.qrc">
<normaloff>:/icons/list-add.png</normaloff>:/icons/list-add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonFilterModify">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Modify</string>
</property>
<property name="icon">
<iconset>
<normaloff>:/icons/document-save-.png</normaloff>:/icons/document-save-.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>Sender</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QFormLayout" name="formLayout_3">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="labelFilter_5">
<property name="text">
<string>Name:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="CLineEdit" name="lineSender"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelFilter_16">
<property name="text">
<string>Frequency:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="spinFrequency">
<property name="suffix">
<string> Hz</string>
</property>
<property name="maximum">
<double>9999.000000000000000</double>
</property>
<property name="value">
<double>10.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelFilter_6">
<property name="text">
<string>Data:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="CLineEdit" name="lineData"/>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>77</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_19">
<item>
<widget class="QPushButton" name="buttonSenderAdd">
<property name="text">
<string>Add</string>
</property>
<property name="icon">
<iconset resource="../../../qad/libs/application/qad_application.qrc">
<normaloff>:/icons/list-add.png</normaloff>:/icons/list-add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonSenderModify">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Modify</string>
</property>
<property name="icon">
<iconset>
<normaloff>:/icons/document-save-.png</normaloff>:/icons/document-save-.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="buttonRemove">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Remove</string>
</property>
<property name="icon">
<iconset resource="../../../qad/libs/application/qad_application.qrc">
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonClear">
<property name="text">
<string>Clear</string>
</property>
<property name="icon">
<iconset resource="../../../qad/libs/application/qad_application.qrc">
<normaloff>:/icons/edit-clear.png</normaloff>:/icons/edit-clear.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="ConnectionView" name="blockView">
<property name="traceConsiderBuses">
<bool>false</bool>
</property>
<property name="pinMulticonnect" stdset="0">
<bool>true</bool>
</property>
<property name="miniMap" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QCodeEdit" name="codeEdit"/>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BlockView</class>
<extends>QGraphicsView</extends>
<header>blockview.h</header>
</customwidget>
<customwidget>
<class>CLineEdit</class>
<extends>QLineEdit</extends>
<header>clineedit.h</header>
</customwidget>
<customwidget>
<class>EComboBox</class>
<extends>QComboBox</extends>
<header>ecombobox.h</header>
</customwidget>
<customwidget>
<class>QCodeEdit</class>
<extends>QWidget</extends>
<header>qcodeedit.h</header>
</customwidget>
<customwidget>
<class>ConnectionView</class>
<extends>BlockView</extends>
<header>piqt_connection_view.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../../../qad/libs/application/qad_application.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ConnectionEdit</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>442</x>
<y>738</y>
</hint>
<hint type="destinationlabel">
<x>413</x>
<y>426</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ConnectionEdit</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>669</x>
<y>738</y>
</hint>
<hint type="destinationlabel">
<x>643</x>
<y>428</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>recreateConnection()</slot>
</slots>
</ui>

View File

@@ -0,0 +1,214 @@
#include "piqt_connection_view.h"
#include "picodeinfo.h"
#include "piqt.h"
#include <alignedtextitem.h>
DeviceItem::DeviceItem(): BlockItem() {
addProperty(BlockItem::Property("__type", "", __CV_Device));
addProperty(BlockItem::Property("bufferSize", "", 4096));
setSize(200, 80);
setColor(QColor(192, 192, 255));
text_name = new AlignedTextItem();
text_path = new AlignedTextItem();
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.);
addDecor(text_name);
fnt.setBold(false);
fnt.setPointSizeF(fnt.pointSizeF() - 2.);
text_path->setFont(fnt);
text_path->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
text_path->setPos(0., -size().height() / 2. + 20);
addDecor(text_path);
addPin(Qt::AlignLeft, 0, "write", "");
addPin(Qt::AlignRight, 0, "read", "");
}
void DeviceItem::rename() {
QString ms;
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;
}
text_name->setText(name() + " (" + ms + ")");
text_path->setText(path());
}
FilterItem::FilterItem(): BlockItem() {
addProperty(BlockItem::Property("__type", "", __CV_Filter));
addProperty(BlockItem::Property("bufferSize", "", 65536));
setSize(140, 80);
setPos(200, 0);
setColor(QColor(192, 255, 192));
text_name = new AlignedTextItem();
text_mode = new AlignedTextItem();
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.);
addDecor(text_name);
fnt.setBold(false);
fnt.setPointSizeF(fnt.pointSizeF() - 2.);
text_mode->setFont(fnt);
text_mode->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
text_mode->setPos(0., -size().height() / 2. + 20);
addDecor(text_mode);
addPin(Qt::AlignLeft, 0, "in", "");
addPin(Qt::AlignRight, 0, "out", "");
}
void FilterItem::rename() {
text_name->setText(name());
QString ms;
PICodeInfo::EnumInfo * ei = PICodeInfo::enumsInfo->value("PIPacketExtractor::SplitMode", 0);
if (ei) {
piForeachC(PICodeInfo::EnumeratorInfo & i, ei->members)
if (i.value == mode()) {
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 39, 0)
ms = PI2QString(i.name.toString());
#else
ms = PI2QString(i.name);
#endif
break;
}
}
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_frequency = new AlignedTextItem();
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.);
addDecor(text_name);
fnt.setBold(false);
fnt.setPointSizeF(fnt.pointSizeF() - 2.);
text_frequency->setFont(fnt);
text_frequency->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
text_frequency->setPos(0., -size().height() / 2. + 20);
addDecor(text_frequency);
addPin(Qt::AlignRight, 0, "out", "");
}
void SenderItem::rename() {
text_name->setText(name());
text_frequency->setText(QString::number(frequency()) + " Hz");
}
ConnectionView::ConnectionView(QWidget * parent): BlockView(parent) {}
ConnectionView::~ConnectionView() {}
DeviceItem * ConnectionView::addDevice(const QString & name, const QString & path) {
DeviceItem * ret = findDevice(name);
if (ret) return ret;
ret = new DeviceItem();
PIString dp;
PIIODevice::DeviceMode dm;
PIIODevice::splitFullPath(Q2PIString(path), &dp, &dm);
ret->setPos(0, 0);
ret->setName(name);
ret->setPath(PI2QString(dp));
ret->setMode(dm);
ret->setDisconnectTimeout(3.);
ret->setBufferSize(4096);
placeBlock(ret, allDevices());
addItem(ret);
return ret;
}
FilterItem * ConnectionView::addFilter(const QString & name) {
FilterItem * ret = new FilterItem();
ret->setDisconnectTimeout(3.);
ret->setBufferSize(65536);
ret->setName(name);
placeBlock(ret, allFilters());
addItem(ret);
return ret;
}
SenderItem * ConnectionView::addSender(const QString & name) {
SenderItem * ret = new SenderItem();
ret->setName(name);
placeBlock(ret, allSenders());
addItem(ret);
return ret;
}
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;
return 0;
}
void ConnectionView::loadBus(BlockBusItem * bus) {
bus->setEndpointsNumber(2);
}
void ConnectionView::placeBlock(BlockItem * b, QList<BlockItem *> coll) {
if (coll.isEmpty()) return;
QList<QRectF> collr;
foreach(BlockItem * i, coll)
collr << i->sceneBoundingRect();
while (true) {
QRectF br = b->sceneBoundingRect();
bool ok = true;
for (int i = 0; i < collr.size(); ++i)
if (br.intersects(collr[i])) {
ok = false;
break;
}
if (ok) break;
b->moveBy(0., grid_step);
}
b->moveBy(0., grid_step * 2.);
}
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

@@ -0,0 +1,181 @@
/*
PIQt Utils - Qt utilites for PIP
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 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/>.
*/
#ifndef CONNECTION_VIEW_H
#define CONNECTION_VIEW_H
#include "blockview.h"
#include "piconnection.h"
#include "qad_piqt_utils_export.h"
const int __CV_Device = 1;
const int __CV_Filter = 2;
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 rename();
protected:
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 rename();
protected:
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 rename();
protected:
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); }
private:
QSize sizeHint() const { return QSize(800, 600); }
void loadBus(BlockBusItem * bus);
void placeBlock(BlockItem * b, QList<BlockItem *> coll);
QList<BlockItem *> allByType(int type_) const;
private slots:
};
#endif // CONNECTION_VIEW_H

View File

@@ -0,0 +1,85 @@
#include "piqt_highlighter.h"
ConfigHighlighter::ConfigHighlighter(QTextDocument * parent): QSyntaxHighlighter(parent) {
HighlightingRule rule;
valueNameFormat.setForeground(QColor(0, 64, 154));
rule.pattern = QRegularExpression("[^=]"); //"\\b[A-Za-z0-9_]+(?=\\()");
rule.format = valueNameFormat;
highlightingRules.append(rule);
valueFormat.setForeground(QColor(192, 0, 0));
rule.pattern = QRegularExpression("=[^\n]*");
rule.format = valueFormat;
highlightingRules.append(rule);
equalFormat.setFontWeight(QFont::Bold);
equalFormat.setForeground(QColor(96, 126, 0));
rule.pattern = QRegularExpression("=");
rule.format = equalFormat;
highlightingRules.append(rule);
sectionFormat.setFontWeight(QFont::Bold);
sectionFormat.setForeground(QColor(0, 32, 64));
rule.pattern = QRegularExpression("\\[.*\\]");
rule.format = sectionFormat;
highlightingRules.append(rule);
substFormat.setForeground(QColor(192, 0, 192));
rule.pattern = QRegularExpression("\\$\\{.*\\}+");
// rule.pattern.setMinimal(true);
rule.format = substFormat;
highlightingRules.append(rule);
rule.pattern = QRegularExpression("\\$\\{[^\\{]*\\}+");
highlightingRules.append(rule);
singleLineCommentFormat.setFontItalic(true);
singleLineCommentFormat.setForeground(QColor(128, 128, 128));
rule.pattern = QRegularExpression("#[^\n]*");
rule.format = singleLineCommentFormat;
highlightingRules.append(rule);
spaceFormat.setForeground(QColor(210, 210, 210));
// commentStartExpression = QRegExp("/\\*");
// commentEndExpression = QRegExp("\\*/");
}
void ConfigHighlighter::highlightBlock(const QString & text) {
foreach(const HighlightingRule & rule, highlightingRules) {
QRegularExpression expression(rule.pattern);
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QRegularExpressionMatchIterator i = expression.globalMatch(text);
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
setFormat(match.capturedStart(), match.capturedLength(), rule.format);
}
#else
int index = expression.indexIn(text);
while (index >= 0) {
int length = expression.matchedLength();
setFormat(index, length, rule.format);
index = expression.indexIn(text, index + length);
}
#endif
}
setCurrentBlockState(0);
QRegularExpression expression("[ |\t]");
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QRegularExpressionMatchIterator i = expression.globalMatch(text);
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
setFormat(match.capturedStart(), match.capturedLength(), spaceFormat);
}
#else
int index = expression.indexIn(text);
while (index >= 0) {
int length = expression.matchedLength();
setFormat(index, length, spaceFormat);
index = expression.indexIn(text, index + length);
}
#endif
}

View File

@@ -0,0 +1,57 @@
/*
PIQt Utils - Qt utilites for PIP
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 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/>.
*/
#ifndef CONF_HIGHLIGHTER_H
#define CONF_HIGHLIGHTER_H
#include <QSyntaxHighlighter>
#include <QTextCharFormat>
#include <QTextCursor>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
# include <QRegularExpression>
#else
# include <QRegExp>
typedef QRegExp QRegularExpression;
#endif
#include "qad_piqt_utils_export.h"
class QTextDocument;
class QAD_PIQT_UTILS_EXPORT ConfigHighlighter: public QSyntaxHighlighter {
Q_OBJECT
public:
ConfigHighlighter(QTextDocument * parent = 0);
QTextCursor cursor;
private:
void highlightBlock(const QString & text);
struct QAD_PIQT_UTILS_EXPORT HighlightingRule {
QRegularExpression pattern;
QTextCharFormat format;
};
QVector<HighlightingRule> highlightingRules;
QRegularExpression commentStartExpression, commentEndExpression;
QTextCharFormat singleLineCommentFormat, valueNameFormat, valueFormat, equalFormat, sectionFormat, spaceFormat, substFormat;
};
#endif // CONF_HIGHTLIGHTER_H

View File

@@ -0,0 +1,93 @@
#include "piqt_iodevice_edit.h"
#include "piqt_iodevice_edit_dialog.h"
#include "qvariantedit_custom.h"
#include <QBoxLayout>
#include <QLineEdit>
#include <QToolButton>
#include <piiodevice.h>
#include <piqt.h>
IODeviceEdit::IODeviceEdit(QWidget * parent): QWidget(parent) {
dlg = new IODeviceEditDialog();
line = new QLineEdit();
btn = new QToolButton();
setLayout(new QBoxLayout(QBoxLayout::LeftToRight));
layout()->setContentsMargins(0, 0, 0, 0);
layout()->addWidget(line);
layout()->addWidget(btn);
connect(btn, SIGNAL(clicked(bool)), this, SLOT(buttonDlg_clicked()));
line->setReadOnly(true);
btn->setText(QString());
btn->setIcon(QIcon(":/icons/configure.png"));
btn->setToolTip(tr("Edit ..."));
}
IODeviceEdit::~IODeviceEdit() {
delete dlg;
}
QVariant IODeviceEdit::value() const {
return QVariant::fromValue(dev);
}
bool IODeviceEdit::isReadOnly() const {
return btn->isHidden();
}
void IODeviceEdit::setDevice(const QAD::IODevice & d) {
if (dev.toString() == d.toString()) return;
dev = d;
line->setText(dev.toString());
line->setCursorPosition(0);
emit valueChanged();
}
void IODeviceEdit::setValue(const QVariant & v) {
setDevice(v.value<QAD::IODevice>());
}
void IODeviceEdit::setReadOnly(bool yes) {
btn->setHidden(yes);
}
void IODeviceEdit::buttonDlg_clicked() {
QAD::IODevice d = dlg->getIODevice(dev);
if (!d.isValid()) return;
setDevice(d);
}
class Factory: public QVariantEditorFactoryBase {
public:
Factory() {}
virtual QWidget * createEditor() { return new IODeviceEdit(); }
};
__IODeviceEditRegistrator__::__IODeviceEditRegistrator__() {
QVariantEditorFactories::registerEditorFactory(qMetaTypeId<QAD::IODevice>(), new Factory());
__QADTypesRegistrator__::instance()->toString_funcs.insert(qMetaTypeId<QAD::IODevice>(), &QAD_IODevice_toString);
}
void QAD_IODevice_toString(const QVariant & v, QString & r) {
PIVariantTypes::IODevice sd = Q2PIVariant(v).toIODevice();
// piCout << sd;
PIIODevice * rd = PIIODevice::createFromVariant(sd);
if (rd) {
PIString ps = rd->constructFullPath();
r = PI2QString(ps);
} else {
piCout << "error in " << sd;
}
}

View File

@@ -0,0 +1,75 @@
/*
PIQt Utils - Qt utilites for PIP
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 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/>.
*/
#ifndef PIQT_IODEVICE_EDIT_H
#define PIQT_IODEVICE_EDIT_H
#include "qad_piqt_utils_export.h"
#include "qad_types.h"
#include <QWidget>
class QLineEdit;
class QToolButton;
class IODeviceEditDialog;
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);
QLineEdit * line;
QToolButton * btn;
IODeviceEditDialog * dlg;
QAD::IODevice dev;
public slots:
void setValue(const QVariant & v);
void setReadOnly(bool yes);
private slots:
void buttonDlg_clicked();
signals:
void valueChanged();
};
class QAD_PIQT_UTILS_EXPORT __IODeviceEditRegistrator__ {
public:
__IODeviceEditRegistrator__();
};
static __IODeviceEditRegistrator__ __iodeviceeditregistrator__;
QAD_PIQT_UTILS_EXPORT void QAD_IODevice_toString(const QVariant & v, QString & r);
#endif // PIQT_IODEVICE_EDIT_H

View File

@@ -0,0 +1,117 @@
#include "piqt_iodevice_edit_dialog.h"
#include "picodeinfo.h"
#include "piiodevice.h"
#include "piqt.h"
#include "ui_piqt_iodevice_edit_dialog.h"
#include <QCheckBox>
IODeviceEditDialog::IODeviceEditDialog(QWidget * parent): QDialog(parent) {
ui = new Ui::IODeviceEditDialog();
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));
#else
ui->comboMode->addItem(PI2QString(e.name + " (" + PIString::fromNumber(e.value) + ")"), QVariant::fromValue<int>(e.value));
#endif
}
ui->comboMode->setCurrentIndex(ui->comboMode->count() - 1);
ei = PICodeInfo::enumsInfo->value("PIIODevice::DeviceOption");
if (ei) {
piForeachC(PICodeInfo::EnumeratorInfo & e, ei->members) {
QCheckBox * cb = new QCheckBox();
#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) + ")"));
#endif
cb->setProperty("__value", e.value);
ui->layoutOptions->addWidget(cb);
}
}
PIStringList pl = PIIODevice::availablePrefixes();
piForeachC(PIString & p, pl) {
ui->comboType->addItem(PI2QString(p));
}
}
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());
if (!cb) continue;
if (cb->isChecked()) ret |= cb->property("__value").toInt();
}
return ret;
}
void IODeviceEditDialog::setOptions(int o) {
for (int i = 0; i < ui->layoutOptions->count(); ++i) {
QCheckBox * cb = qobject_cast<QCheckBox *>(ui->layoutOptions->itemAt(i)->widget());
if (!cb) continue;
int cbf = cb->property("__value").toInt();
cb->setChecked((o & cbf) == cbf);
}
}
void IODeviceEditDialog::on_comboType_currentIndexChanged(int index) {
PIString prefix = Q2PIString(ui->comboType->currentText());
auto * d = PIIODevice::createFromFullPath(prefix + "://");
if (d) {
ps = PI2QPropertyStorage(d->constructVariant().get());
ui->widgetProperties->setStorage(&ps);
delete d;
}
}
QAD::IODevice IODeviceEditDialog::getIODevice(const QAD::IODevice & d) {
setValue(d);
if (QDialog::exec() != QDialog::Accepted) return QAD::IODevice();
return value();
}
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.options = getOptions();
d.props = ps;
return d;
}
void IODeviceEditDialog::setValue(const QAD::IODevice & d) {
#if QT_VERSION >= 0x050000
ui->comboType->setCurrentText(d.prefix);
#else
for (int i = 0; i < ui->comboType->count(); ++i) {
if (ui->comboType->itemText(i) == d.prefix) {
ui->comboType->setCurrentIndex(i);
break;
}
}
#endif
for (int i = 0; i < ui->comboMode->count(); ++i)
if (ui->comboMode->itemData(i).toInt() == d.mode) {
ui->comboMode->setCurrentIndex(i);
break;
}
setOptions(d.options);
ps = d.props;
ui->widgetProperties->setStorage(&ps);
}

View File

@@ -0,0 +1,55 @@
/*
PIQt Utils - Qt utilites for PIP
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 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/>.
*/
#ifndef PIQT_IODEVICE_EDIT_DIALOG_H
#define PIQT_IODEVICE_EDIT_DIALOG_H
#include "propertystorage.h"
#include "qad_piqt_utils_export.h"
#include "qad_types.h"
#include <QDialog>
namespace Ui {
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:
QAD::IODevice value() const;
void setValue(const QAD::IODevice & d);
int getOptions() const;
void setOptions(int o);
PropertyStorage ps;
Ui::IODeviceEditDialog * ui;
private slots:
void on_comboType_currentIndexChanged(int index);
};
#endif // PIQT_IODEVICE_EDIT_DIALOG_H

View File

@@ -0,0 +1,138 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>IODeviceEditDialog</class>
<widget class="QDialog" name="IODeviceEditDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>387</width>
<height>345</height>
</rect>
</property>
<property name="windowTitle">
<string>IODevice</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</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>
<item row="1" column="0">
<widget class="QLabel" name="labelFilter_12">
<property name="text">
<string>Mode:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboMode"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelFilter_14">
<property name="text">
<string>Options:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QVBoxLayout" name="layoutOptions">
<property name="spacing">
<number>2</number>
</property>
</layout>
</item>
</layout>
</item>
<item>
<widget class="PropertyStorageEditor" name="widgetProperties" native="true"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</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>PropertyStorageEditor</class>
<extends>QWidget</extends>
<header>propertystorage_editor.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>IODeviceEditDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>227</x>
<y>326</y>
</hint>
<hint type="destinationlabel">
<x>144</x>
<y>302</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>IODeviceEditDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>325</x>
<y>315</y>
</hint>
<hint type="destinationlabel">
<x>304</x>
<y>306</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>recreateConnection()</slot>
</slots>
</ui>

View File

@@ -0,0 +1,769 @@
#include "pivaluetree_edit.h"
#include "piqt.h"
#include "pivaluetree_edit_parameters.h"
#include "pivaluetree_edit_reorder.h"
#include "pivariant_edit.h"
#include "ui_pivaluetree_edit_array.h"
#include <QEvent>
#include <QFormLayout>
#include <QGroupBox>
#include <QInputDialog>
#include <QMessageBox>
#include <QTabWidget>
#include <QToolButton>
using Attribute = PIValueTree::Attribute;
const char property_name[] = "__name__";
class GroupBox: public QGroupBox {
public:
GroupBox(QWidget * content = nullptr): QGroupBox() {
icon_show = QIcon(":/icons/layer-visible-on.png");
icon_hide = QIcon(":/icons/layer-visible-off.png");
setLayout(new QBoxLayout(QBoxLayout::TopToBottom));
layout()->addWidget(content);
setAlignment(Qt::AlignCenter);
btn = new QToolButton(this);
btn->setCheckable(true);
btn->show();
connect(btn, &QToolButton::toggled, this, [this, content](bool on) {
btn->setIcon(on ? icon_show : icon_hide);
content->setVisible(on);
});
btn->setChecked(true);
}
private:
void resizeEvent(QResizeEvent * e) {
QGroupBox::resizeEvent(e);
btn->resize(btn->height(), btn->height());
btn->move(btn->height() / 2, 0);
}
QToolButton * btn = nullptr;
QIcon icon_show, icon_hide;
};
PIValueTreeEdit::PIValueTreeEdit(QWidget * parent): QWidget(parent) {
widget_params = new PIValueTreeEditParameters();
widget_reorder = new PIValueTreeEditReorder();
ui_array = new Ui::PIValueTreeEditArray();
grid = new GridWidgets(this);
auto * lay = new QBoxLayout(QBoxLayout::TopToBottom);
lay->setContentsMargins(0, 0, 0, 0);
setLayout(lay);
}
PIValueTreeEdit::~PIValueTreeEdit() {
delete grid;
delete ui_array;
delete widget_params;
}
void PIValueTreeEdit::setValue(const PIValueTree & v) {
current = source = v;
build();
}
PIValueTree PIValueTreeEdit::value() const {
applyValues();
return current;
}
void PIValueTreeEdit::setGrouping(Grouping g) {
applyValues();
cur_grouping = real_grouping = g;
if (parent_tree && g == Parent) real_grouping = parent_tree->real_grouping;
if (real_grouping == Parent) real_grouping = Indent;
for (auto * a: widget_params->menu_grouping.actions()) {
if (a->data().toInt() == g) {
a->setChecked(true);
break;
}
}
build();
}
void PIValueTreeEdit::setFullEditMode(bool yes) {
applyValues();
is_full_edit = yes;
build();
}
void PIValueTreeEdit::rollback() {
current = source;
build();
}
void PIValueTreeEdit::clear() {
current = PIValueTree();
removeAll();
}
void PIValueTreeEdit::retranslate() {
for (const auto & i: value_edits)
i.second->retranslate();
for (const auto & i: tree_edits)
i.second->retranslate();
for (const auto & i: comm_labels) {
i.second->setText(PIVariantEditorBase::vtTr(current.child(i.first).comment()));
}
for (const auto & i: label_labels) {
i.second->setText(PIVariantEditorBase::vtTr(i.first));
}
if (tab_widget) {
for (int i = 0; i < tab_widget->count(); ++i) {
tab_widget->setTabText(i, PIVariantEditorBase::vtTr(Q2PIString(tab_widget->tabBar()->tabData(i).toString())));
}
}
grid->retranslate();
}
void PIValueTreeEdit::changeEvent(QEvent * e) {
if (e->type() == QEvent::LanguageChange) {
if (widget_array) ui_array->retranslateUi(widget_array);
retranslate();
}
QWidget::changeEvent(e);
}
void PIValueTreeEdit::removeAll() {
array_edits.clear();
value_edits.clear();
tree_edits.clear();
comm_labels.clear();
label_labels.clear();
tab_widget = nullptr;
if (widget_array) {
ui_array->layoutArray->removeWidget(grid);
grid->hide();
grid->setParent(this);
delete widget_array;
widget_array = nullptr;
}
QLayoutItem * child = nullptr;
while ((child = layout()->takeAt(0))) {
delete child;
}
grid->clear();
}
void PIValueTreeEdit::build() {
grid->create_edit_buttons = false;
removeAll();
// piCout << source.attributes().value(Attribute::arrayType) << array_type;
grid->button_add->hide();
if (current.isArray()) {
widget_array = new QWidget();
ui_array->setupUi(widget_array);
applyArrayAttributes();
ui_array->layoutArray->addWidget(grid);
grid->show();
uint array_type = PIVariant::typeIDFromName(current.attribute(Attribute::arrayType).toString());
int index = 0;
for (const auto & i: current.children()) {
auto * ve = new PIVariantEdit();
ve->setAttributes(current.attributes());
ve->setValue(i.value(), array_type);
grid->add(PIValueTree(), PIString::fromNumber(++index), ve, i.comment());
array_edits << ve;
}
connect(ui_array->spinCount, QOverload<int>::of(&QSpinBox::valueChanged), widget_array, [this, array_type](int value) {
value = piMaxi(value, 0);
for (int i = grid->rowCount() - 1; i >= value; --i)
grid->removeRow(i);
array_edits.resize(grid->rowCount());
for (int i = grid->rowCount(); i < value; ++i) {
auto * ve = new PIVariantEdit();
ve->setAttributes(current.attributes());
ve->setValue(PIVariant::fromType(array_type), array_type);
grid->add(PIValueTree(), PIString::fromNumber(i + 1), ve, "");
array_edits << ve;
}
});
layout()->addWidget(widget_array);
} else {
grid->create_edit_buttons = is_full_edit;
layout()->addWidget(grid);
if (!current.hasChildren()) grid->clear();
for (const auto & i: current.children()) {
if (i.attribute(Attribute::hidden, false).toBool() && !is_full_edit) continue;
if (i.attribute(Attribute::isLabel, false).toBool()) {
if (i.name().isEmpty()) continue;
auto * l = newLabel(i);
grid->add(i, l);
continue;
}
if (i.hasChildren() || i.isArray()) {
addTreeEdit(i);
} else {
addValueEdit(i);
}
}
}
}
void PIValueTreeEdit::applyValues() const {
if (current.isArray()) {
if (array_edits.isNotEmpty()) current.mergeAttributes(array_edits[0]->attributes());
current.clearChildren();
for (int i = 0; i < array_edits.size_s(); ++i)
current.addChild({PIString::fromNumber(i), array_edits[i]->value()});
} else {
auto vit = value_edits.makeIterator();
while (vit.next()) {
auto & c(current.child(vit.key()));
c.mergeAttributes(vit.value()->attributes());
c.setValue(vit.value()->value());
}
auto tit = tree_edits.makeIterator();
while (tit.next()) {
auto & c(current.child(tit.key()));
if (!c.isNull()) c = tit.value()->value();
}
if (current.hasChildren()) {
auto ge = PIVariantEditorBase::createGrouping();
ge.selectValue(cur_grouping);
current.setAttribute(Attribute::grouping, ge);
}
}
}
void PIValueTreeEdit::actionTriggered(QToolButton * button, const PIString & vn, QAction * a) {
if (a == widget_params->actionRename) {
PIString nn = Q2PIString(QInputDialog::getText(nullptr, tr("Rename"), tr("Input new name:"), QLineEdit::Normal, PI2QString(vn)));
if (nn.isEmpty() || (nn == vn)) return;
for (const auto & c: current.children()) {
if (c.name() == nn) {
QMessageBox::critical(nullptr, tr("Rename"), tr("This name already exists!"));
return;
}
}
current[vn].setName(nn);
button->setProperty(property_name, PI2QString(nn));
grid->rename(vn, nn);
if (value_edits.contains(vn)) {
value_edits[nn] = value_edits[vn];
value_edits.remove(vn);
}
if (tree_edits.contains(vn)) {
tree_edits[nn] = tree_edits[vn];
tree_edits.remove(vn);
}
if (comm_labels.contains(vn)) {
comm_labels[nn] = comm_labels[vn];
comm_labels.remove(vn);
}
if (label_labels.contains(vn)) {
label_labels[nn] = label_labels[vn];
label_labels[nn]->setText(PIVariantEditorBase::vtTr(nn));
label_labels.remove(vn);
}
if (tab_widget) {
for (int i = 0; i < tab_widget->count(); ++i) {
if (tab_widget->tabBar()->tabData(i).toString() == PI2QString(vn)) {
tab_widget->setTabText(i, PIVariantEditorBase::vtTr(nn));
tab_widget->tabBar()->setTabData(i, PI2QString(nn));
break;
}
}
}
return;
}
if (a == widget_params->actionRemove) {
current.remove(vn);
if (tab_widget) {
QString qvn = PI2QString(vn);
QMetaObject::invokeMethod(
this,
[this, qvn]() {
for (int i = 0; i < tab_widget->count(); ++i) {
if (tab_widget->tabBar()->tabData(i).toString() == qvn) {
tab_widget->removeTab(i);
break;
}
}
if (tab_widget->count() == 0) {
grid->removeRow(grid->getRow(tab_widget));
tab_widget = nullptr;
}
},
Qt::QueuedConnection);
}
grid->removeRow(grid->getRow(button));
value_edits.remove(vn);
tree_edits.remove(vn);
comm_labels.remove(vn);
label_labels.remove(vn);
return;
}
if (a == widget_params->actionChange) {
auto & vt(current[vn]);
if (vt.isArray()) {
auto * ve = tree_edits.value(vn, nullptr);
if (!ve) return;
vt = ve->value();
if (!widget_params->showFor(vt)) return;
ve->setValue(vt);
// ve->applyArrayAttributes();
} else {
bool was_label = vt.attribute(Attribute::isLabel, false).toBool();
auto * ve = value_edits.value(vn, nullptr);
if (ve) {
vt.setValue(ve->value());
vt.mergeAttributes(ve->attributes());
}
if (!widget_params->showFor(vt)) return;
bool now_label = vt.attribute(Attribute::isLabel, false).toBool();
if (was_label ^ now_label) {
if (now_label) {
auto * l = newLabel(vt);
grid->replace(grid->getRow(button), l);
value_edits.remove(vt.name());
comm_labels.remove(vt.name());
} else {
auto * ve = new PIVariantEdit();
applyVariantEdit(ve, vt);
grid->replace(grid->getRow(button), vt.name(), ve, vt.comment());
value_edits[vt.name()] = ve;
}
ve = nullptr;
}
if (ve) {
applyVariantEdit(ve, vt);
}
if (now_label) {
label_labels[vt.name()]->setStyleSheet(PI2QString(vt.attribute(Attribute::style).toString()));
}
}
auto * cl = comm_labels.value(vn, nullptr);
if (cl) cl->setText(PIVariantEditorBase::vtTr(vt.comment()));
return;
}
if (a == widget_params->actionReorder) {
if (!widget_reorder->showFor(current)) return;
grid->reorder(widget_reorder->map);
auto cl = current.children();
current.clearChildren();
for (int i = 0; i < cl.size_s(); ++i) {
int mi = widget_reorder->map.value(i, i);
if (mi < 0 || mi >= cl.size_s()) continue;
current.addChild(cl[mi]);
}
return;
}
setGrouping((Grouping)a->data().toInt());
}
PIValueTreeEdit * PIValueTreeEdit::addTreeEdit(const PIValueTree & vt) {
auto * ve = new PIValueTreeEdit();
PIStringList rp = root_path;
rp << vt.name();
ve->root_path = rp;
ve->parent_tree = this;
ve->setGrouping((Grouping)vt.attribute(Attribute::grouping, Parent).toEnum().selectedValue());
ve->setFullEditMode(is_full_edit);
ve->setValue(vt);
switch (real_grouping) {
case Indent: grid->add(vt, vt.name(), ve, vt.comment(), true); break;
case Groups: {
auto * gb = new GroupBox(ve);
gb->setTitle(PI2QString(vt.name()));
gb->setToolTip(PI2QString(vt.comment()));
gb->setProperty(property_name, PI2QString(vt.name()));
grid->add(vt, gb, true);
} break;
case Tabs: {
createTabWidget();
auto * cw = new QWidget();
cw->setLayout(new QBoxLayout(QBoxLayout::TopToBottom));
cw->layout()->addWidget(ve);
cw->layout()->addItem(new QSpacerItem(0, 0, QSizePolicy::Preferred, QSizePolicy::Expanding));
int tab = tab_widget->addTab(cw, PIVariantEditorBase::vtTr(vt.name()));
tab_widget->tabBar()->setTabData(tab, PI2QString(vt.name()));
if (is_full_edit) {
auto * b = grid->createConfigButton(vt, true);
tab_widget->tabBar()->setTabButton(tab, QTabBar::RightSide, b);
}
} break;
default: break;
}
tree_edits[vt.name()] = ve;
return ve;
}
void PIValueTreeEdit::addValueEdit(const PIValueTree & vt) {
auto * ve = new PIVariantEdit();
applyVariantEdit(ve, vt);
grid->add(vt, vt.name(), ve, vt.comment());
value_edits[vt.name()] = ve;
}
void PIValueTreeEdit::applyArrayAttributes() {
ui_array->spinCount->setRange(current.attribute(Attribute::arrayMinCount, 0).toInt(),
current.attribute(Attribute::arrayMaxCount, 65536).toInt());
ui_array->spinCount->setValue(current.children().size_s());
ui_array->widgetEdit->setVisible(current.attribute(Attribute::arrayResize, false).toBool());
uint array_type = PIVariant::typeIDFromName(current.attribute(Attribute::arrayType).toString());
for (int i = 0; i < array_edits.size_s(); ++i) {
auto * w = array_edits[i];
w->setAttributes(current.attributes());
w->setValue(i < current.children().size_s() ? current.children()[i].value() : PIVariant(), array_type);
}
}
QLabel * PIValueTreeEdit::newLabel(const PIValueTree & vt) {
auto * l = new QLabel();
l->setAlignment(Qt::AlignCenter);
l->setText(PIVariantEditorBase::vtTr(vt.name()));
l->setStyleSheet(PI2QString(vt.attribute(Attribute::style).toString()));
label_labels[vt.name()] = l;
return l;
}
void PIValueTreeEdit::applyVariantEdit(PIVariantEdit * ve, const PIValueTree & vt) {
ve->setAttributes(vt.attributes());
ve->setValue(vt.value());
ve->setFullEditMode(is_full_edit);
}
void PIValueTreeEdit::createTabWidget() {
if (tab_widget) return;
tab_widget = new QTabWidget();
grid->addRow(tab_widget);
}
void PIValueTreeEdit::newRequest(NewType type) {
PIString nn = Q2PIString(QInputDialog::getText(nullptr, tr("New item"), tr("Input new name:")));
if (nn.isEmpty()) return;
for (const auto & c: current.children()) {
if (c.name() == nn) {
QMessageBox::critical(nullptr, tr("New item"), tr("This name already exists!"));
return;
}
}
PIValueTree vt;
vt.setName(nn);
if (type == NewType::Value) {
if (!widget_params->showFor(vt)) return;
}
if (type == NewType::Array) {
vt.setAttribute(Attribute::arrayType, PIVariant::typeName<PIString>());
if (!widget_params->showFor(vt)) return;
}
current.addChild(vt);
switch (type) {
case NewType::Value: addValueEdit(vt); break;
case NewType::Group: addTreeEdit(vt); break;
case NewType::Array: addTreeEdit(vt); break;
}
}
// PIValueTreeEdit::GridWidgets
PIValueTreeEdit::GridWidgets::GridWidgets(PIValueTreeEdit * p) {
parent = p;
icon_conf = QIcon(":/icons/configure.png");
auto newSeparator = []() {
auto * a = new QAction();
a->setSeparator(true);
return a;
};
menu_group.addActions({p->widget_params->actionRename,
p->widget_params->actionReorder,
p->widget_params->menu_grouping.menuAction(),
newSeparator(),
p->widget_params->actionRemove});
menu_conf.addActions({p->widget_params->actionRename,
p->widget_params->actionChange,
p->widget_params->actionReorder,
newSeparator(),
p->widget_params->actionRemove});
menu_new.addActions({p->widget_params->actionValue, p->widget_params->actionGroup, p->widget_params->actionArray});
button_add = new QToolButton();
button_add->setIcon(QIcon(":/icons/list-add.png"));
button_add->setPopupMode(QToolButton::InstantPopup);
button_add->setMenu(&menu_new);
p->widget_params->actionValue->setData((int)NewType::Value);
p->widget_params->actionGroup->setData((int)NewType::Group);
p->widget_params->actionArray->setData((int)NewType::Array);
connect(button_add, &QToolButton::triggered, this, [this](QAction * a) { parent->newRequest((NewType)a->data().toInt()); });
}
PIValueTreeEdit::GridWidgets::~GridWidgets() {
delete button_add;
}
int PIValueTreeEdit::GridWidgets::getRow(QWidget * w) const {
if (!w) return -1;
for (int r = 0; r < lay->rowCount(); ++r) {
for (int c = 0; c < lay->columnCount(); ++c) {
auto * li = lay->itemAtPosition(r, c);
if (!li) continue;
if (li->widget() && (li->widget() == w)) return r;
}
}
return -1;
}
void PIValueTreeEdit::GridWidgets::add(const PIValueTree & vt,
const PIString & label,
QWidget * w,
const PIString & comment,
bool is_group) {
int col = beginRow(vt, is_group);
auto * l = new QLabel();
auto * c = new QLabel(PIVariantEditorBase::vtTr(comment));
l->setProperty(property_name, PI2QString(label));
QString nn = PIVariantEditorBase::vtTr(label);
if (!nn.isEmpty()) nn += ':';
l->setText(nn);
l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
c->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
lay->addWidget(l, row_count, col++, Qt::AlignVCenter | Qt::AlignRight);
lay->addWidget(w, row_count, col++);
lay->addWidget(c, row_count, col++, Qt::AlignVCenter | Qt::AlignLeft);
widgets << l << w << c;
labels << l;
parent->comm_labels[vt.name()] = c;
++row_count;
changed();
}
void PIValueTreeEdit::GridWidgets::add(const PIValueTree & vt, QWidget * w, bool is_group) {
int col = beginRow(vt, is_group);
lay->addWidget(w, row_count, col, 1, -1);
widgets << w;
++row_count;
changed();
}
void PIValueTreeEdit::GridWidgets::addRow(QWidget * w) {
lay->addWidget(w, row_count, 0, 1, -1);
widgets << w;
++row_count;
changed();
}
QToolButton * PIValueTreeEdit::GridWidgets::createConfigButton(const PIValueTree & vt, bool is_group) {
auto * b = new QToolButton();
b->setIcon(icon_conf);
b->setPopupMode(QToolButton::InstantPopup);
b->setMenu((is_group && !vt.isArray()) ? &menu_group : &menu_conf);
b->setProperty(property_name, PI2QString(vt.name()));
b->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
connect(b, &QToolButton::triggered, this, [this, b](QAction * a) {
parent->actionTriggered(b, Q2PIString(b->property(property_name).toString()), a);
});
return b;
}
void PIValueTreeEdit::GridWidgets::replace(int row, QWidget * w) {
int col = removeRowEdits(row);
lay->addWidget(w, row, col, 1, -1);
widgets << w;
}
void PIValueTreeEdit::GridWidgets::replace(int row, const PIString & label, QWidget * w, const PIString & comment) {
int col = removeRowEdits(row);
auto * l = new QLabel();
auto * c = new QLabel(PIVariantEditorBase::vtTr(comment));
l->setProperty(property_name, PI2QString(label));
QString nn = PIVariantEditorBase::vtTr(label);
if (!nn.isEmpty()) nn += ':';
l->setText(nn);
l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
c->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
lay->addWidget(l, row, col++, Qt::AlignVCenter | Qt::AlignRight);
lay->addWidget(w, row, col++);
lay->addWidget(c, row, col++, Qt::AlignVCenter | Qt::AlignLeft);
widgets << l << w << c;
labels << l;
parent->comm_labels[label] = c;
}
int PIValueTreeEdit::GridWidgets::beginRow(const PIValueTree & vt, bool is_group) {
if (!create_edit_buttons) return 0;
auto * b = createConfigButton(vt, is_group);
lay->addWidget(b, row_count, 0);
widgets << b;
return 1;
}
void PIValueTreeEdit::GridWidgets::rename(const PIString & prev_name, const PIString & new_name) {
for (auto * w: widgets) {
auto * gb = qobject_cast<QGroupBox *>(w);
if (!gb) continue;
if (gb->property(property_name).toString() == PI2QString(prev_name)) {
gb->setProperty(property_name, PI2QString(new_name));
gb->setTitle(PIVariantEditorBase::vtTr(new_name));
break;
}
}
for (auto * l: labels)
if (l->property(property_name).toString() == PI2QString(prev_name)) {
l->setProperty(property_name, PI2QString(new_name));
QString nn = PIVariantEditorBase::vtTr(new_name);
if (!nn.isEmpty()) nn += ':';
l->setText(nn);
break;
}
}
void PIValueTreeEdit::GridWidgets::clear() {
piDeleteAllAndClear(widgets);
labels.clear();
if (lay) delete lay;
lay = new QGridLayout();
lay->setContentsMargins(0, 0, 0, 0);
setLayout(lay);
row_count = 0;
changed();
}
void PIValueTreeEdit::GridWidgets::changed() {
if (!create_edit_buttons || !lay) return;
lay->addWidget(button_add, row_count, 0);
button_add->show();
adjustSize();
}
void PIValueTreeEdit::GridWidgets::retranslate() {
for (auto * w: widgets) {
auto * gb = qobject_cast<QGroupBox *>(w);
if (!gb) continue;
gb->setTitle(PIVariantEditorBase::vtTr(Q2PIString(gb->property(property_name).toString())));
}
for (auto * l: labels) {
QString nn = PIVariantEditorBase::vtTr(Q2PIString(l->property(property_name).toString()));
if (!nn.isEmpty()) nn += ':';
l->setText(nn);
}
}
int PIValueTreeEdit::GridWidgets::removeRowEdits(int row) {
int col = create_edit_buttons ? 1 : 0;
for (int c = col; c < lay->columnCount(); ++c) {
auto * li = lay->itemAtPosition(row, c);
if (li) {
QWidget * w = li->widget();
if (w) {
widgets.removeOne(w);
QLabel * lbl = qobject_cast<QLabel *>(w);
if (lbl) labels.removeOne(lbl);
delete w;
}
}
}
return col;
}
void PIValueTreeEdit::GridWidgets::removeRow(int index) {
if (!lay) return;
if ((index < 0) || (index >= row_count) || (index >= lay->rowCount())) return;
for (int c = 0; c < lay->columnCount(); ++c) {
auto * li = lay->itemAtPosition(index, c);
if (li) {
QWidget * w = li->widget();
if (w) {
widgets.removeOne(w);
QLabel * lbl = qobject_cast<QLabel *>(w);
if (lbl) labels.removeOne(lbl);
delete w;
}
}
}
--row_count;
simplify();
changed();
}
void PIValueTreeEdit::GridWidgets::simplify(const PIMap<int, int> & map) {
struct Info {
Qt::Alignment align;
int row_span = 0;
int col_span = 0;
};
if (!lay) return;
QVector<QMap<int, QWidget *>> wg;
QMap<QWidget *, Info> wa;
for (int r = 0; r < lay->rowCount(); ++r) {
QMap<int, QWidget *> row;
for (int c = 0; c < lay->columnCount(); ++c) {
auto * li = lay->itemAtPosition(r, c);
if (!li) continue;
if (li->widget()) {
row[c] = li->widget();
Info info;
info.align = li->alignment();
int pos[4];
lay->getItemPosition(lay->indexOf(li), &(pos[0]), &(pos[1]), &(pos[2]), &(pos[3]));
info.row_span = pos[2];
info.col_span = pos[3];
wa[li->widget()] = info;
c += (pos[3] - 1);
}
}
if (!row.isEmpty()) wg << row;
}
delete lay;
lay = new QGridLayout();
lay->setContentsMargins(0, 0, 0, 0);
int rindex = 0;
for (int i = 0; i < wg.size(); ++i) {
int mi = map.value(i, i);
if (mi < 0 || mi >= wg.size()) continue;
QMapIterator<int, QWidget *> it(wg[mi]);
while (it.hasNext()) {
it.next();
Info info = wa.value(it.value());
lay->addWidget(it.value(), rindex, it.key(), info.row_span, info.col_span, info.align);
}
++rindex;
}
setLayout(lay);
adjustSize();
}

View File

@@ -0,0 +1,143 @@
/*
PIQt Utils - Qt utilites for PIP
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 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/>.
*/
#ifndef pivaluetree_edit_H
#define pivaluetree_edit_H
#include "pivaluetree.h"
#include "qad_piqt_utils_export.h"
#include <QIcon>
#include <QLabel>
#include <QMenu>
#include <QWidget>
class QGridLayout;
class QToolButton;
class QTabWidget;
class PIVariantEdit;
class PIValueTreeEditParameters;
class PIValueTreeEditReorder;
namespace Ui {
class PIValueTreeEditArray;
}
class QAD_PIQT_UTILS_EXPORT PIValueTreeEdit: public QWidget {
Q_OBJECT
Q_ENUMS(Grouping)
public:
PIValueTreeEdit(QWidget * parent = nullptr);
~PIValueTreeEdit();
enum Grouping {
Indent,
Groups,
Tabs,
Parent = 0xFF
};
void setValue(const PIValueTree & v);
PIValueTree value() const;
Grouping grouping() const { return cur_grouping; }
void setGrouping(Grouping g);
bool isFullEditMode() const { return is_full_edit; }
void setFullEditMode(bool yes);
void rollback();
void clear();
void retranslate();
private:
enum class NewType {
Value,
Group,
Array
};
void changeEvent(QEvent * e) override;
void removeAll();
void build();
void applyValues() const;
void actionTriggered(QToolButton * button, const PIString & vn, QAction * a);
void newRequest(NewType type);
PIValueTreeEdit * addTreeEdit(const PIValueTree & vt);
void addValueEdit(const PIValueTree & vt);
void applyArrayAttributes();
QLabel * newLabel(const PIValueTree & vt);
void applyVariantEdit(PIVariantEdit * ve, const PIValueTree & vt);
void createTabWidget();
class GridWidgets: public QWidget {
public:
GridWidgets(PIValueTreeEdit * p);
~GridWidgets();
int rowCount() const { return row_count; }
int getRow(QWidget * w) const;
void removeRow(int index);
void add(const PIValueTree & vt, const PIString & label, QWidget * w, const PIString & comment, bool is_group = false);
void add(const PIValueTree & vt, QWidget * w, bool is_group = false);
void addRow(QWidget * w);
QToolButton * createConfigButton(const PIValueTree & vt, bool is_group);
void replace(int row, QWidget * w);
void replace(int row, const PIString & label, QWidget * w, const PIString & comment);
int beginRow(const PIValueTree & vt, bool is_group);
void rename(const PIString & prev_name, const PIString & new_name);
void reorder(const PIMap<int, int> & map) { simplify(map); }
void simplify(const PIMap<int, int> & map = PIMap<int, int>());
void clear();
void changed();
void retranslate();
bool create_edit_buttons = false;
QToolButton * button_add;
private:
int removeRowEdits(int row);
int row_count = 0;
QGridLayout * lay = nullptr;
PIValueTreeEdit * parent;
QMenu menu_group, menu_conf, menu_new;
QWidgetList widgets;
QList<QLabel *> labels;
QIcon icon_conf;
};
QWidget * widget_array = nullptr;
PIValueTreeEdit * parent_tree = nullptr;
PIValueTreeEditParameters * widget_params;
PIValueTreeEditReorder * widget_reorder;
PIStringList root_path;
PIVector<PIVariantEdit *> array_edits;
PIMap<PIString, PIVariantEdit *> value_edits;
PIMap<PIString, PIValueTreeEdit *> tree_edits;
PIMap<PIString, QLabel *> comm_labels, label_labels;
QTabWidget * tab_widget = nullptr;
Ui::PIValueTreeEditArray * ui_array;
GridWidgets * grid = nullptr;
Grouping cur_grouping = Parent, real_grouping = Indent;
mutable PIValueTree source, current;
bool is_full_edit = false;
};
#endif

View File

@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PIValueTreeEditArray</class>
<widget class="QWidget" name="PIValueTreeEditArray">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>387</width>
<height>345</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</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>
<widget class="QWidget" name="widgetEdit" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Count:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinCount">
<property name="maximum">
<number>65536</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>233</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widgetArray" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="layoutArray">
<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>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
<slots/>
</ui>

View File

@@ -0,0 +1,202 @@
#include "pivaluetree_edit_parameters.h"
#include "piqt.h"
#include "pivaluetree_edit.h"
#include "pivariant_edit.h"
#include <QFormLayout>
#include <QGroupBox>
#include <QMetaEnum>
using Attribute = PIValueTree::Attribute;
const char property_name[] = "__name__";
PIValueTreeEditParameters::PIValueTreeEditParameters(QWidget * parent): QDialog(parent) {
setupUi(this);
auto * ag = new QActionGroup(this);
ag->setExclusive(true);
// connect(ag, &QActionGroup::triggered, [this](QAction * a) { widget->setGrouping((PIValueTreeEdit::Grouping)a->data().toInt()); });
auto mo = PIValueTreeEdit::staticMetaObject;
auto me = mo.enumerator(mo.indexOfEnumerator("Grouping"));
for (int i = 0; i < me.keyCount(); ++i) {
auto * a = ag->addAction(me.key(i));
a->setCheckable(true);
a->setData(me.value(i));
if (me.value(i) == PIValueTreeEdit::Indent) a->setChecked(true);
}
menu_grouping.addActions(ag->actions());
menu_grouping.menuAction()->setText(tr("Grouping"));
}
PIValueTreeEditParameters::~PIValueTreeEditParameters() {}
bool PIValueTreeEditParameters::showFor(PIValueTree & vt) {
setWindowTitle(tr("Change of \"%1\"").arg(PI2QString(vt.name())));
ve_attr.clear();
ve_array.clear();
while (layoutAttributes->rowCount() > 0)
layoutAttributes->removeRow(0);
while (layoutArray->rowCount() > 0)
layoutArray->removeRow(0);
if (last_IDs_count != PIVariant::knownTypeIDsCount()) {
last_IDs_count = PIVariant::knownTypeIDsCount();
comboType->clear();
auto ids = PIVariant::knownTypeIDs();
PIVector<PIPair<uint, QString>> types;
for (auto id: ids) {
if (!PIVariantEditorBase::editorExists(id)) continue;
PIString tn = PIVariant::typeNameFromID(id);
if (tn.startsWith("PI")) tn.remove(0, 2);
if (tn.startsWith("VariantTypes::")) tn.remove(0, 14);
types.append({id, PI2QString(tn)});
}
types.sort([](const PIPair<uint, QString> & a, const PIPair<uint, QString> & b) {
return QString::localeAwareCompare(a.second, b.second) < 0;
});
for (const auto & t: types)
comboType->addItem(t.second, t.first);
}
comboType->blockSignals(true);
comboType->setEnabled(true);
if (vt.isArray()) {
uint array_type = PIVariant::typeIDFromName(vt.attribute(Attribute::arrayType).toString());
comboType->setCurrentIndex(comboType->findData(array_type));
checkAttribute(vt, Attribute::arrayMinCount, 0);
checkAttribute(vt, Attribute::arrayMaxCount, 65536);
checkAttribute(vt, Attribute::arrayReorder, true);
checkAttribute(vt, Attribute::arrayResize, true);
createAttributes(ve_array, layoutArray, vt.attributes(), true);
groupArray->show();
} else {
if (vt.attribute(Attribute::isLabel, false).toBool()) {
comboType->setEnabled(false);
checkAttribute(vt, Attribute::style, "");
}
comboType->setCurrentIndex(comboType->findData(vt.value().typeID()));
groupArray->hide();
}
comboType->blockSignals(false);
checkHidden->setChecked(vt.attribute(Attribute::hidden, false).toBool());
checkReadOnly->setChecked(vt.attribute(Attribute::readOnly, false).toBool());
checkLabel->blockSignals(true);
checkLabel->setChecked(vt.attribute(Attribute::isLabel, false).toBool());
checkLabel->blockSignals(false);
lineComment->setText(PI2QString(vt.comment()));
createAttributes(ve_attr, layoutAttributes, vt.attributes());
if (exec() != QDialog::Accepted) return false;
if (!vt.isArray()) {
PIString vs = vt.value().toString();
PIVariant var = PIVariant::fromType(comboType->currentData().toUInt());
var.setValueFromString(vs);
vt.setValue(var);
}
applyAttributes(vt);
vt.setComment(Q2PIString(lineComment->text()));
return true;
}
void PIValueTreeEditParameters::createAttributes(QList<PIVariantEdit *> & list,
QFormLayout * lay,
const PIVariantMap & attr,
bool inv_filter) {
static PIStringList hidden({"type", Attribute::hidden, Attribute::readOnly, Attribute::isLabel, Attribute::arrayType});
static PIStringList filter({Attribute::arrayMinCount, Attribute::arrayMaxCount, Attribute::arrayReorder, Attribute::arrayResize});
list.clear();
while (lay->rowCount() > 0)
lay->removeRow(0);
PIVariantMap dal;
if (!inv_filter) dal = PIVariantEditorBase::editorDefaultAttributes(comboType->currentData().toUInt());
auto vit = attr.makeIterator();
while (vit.next()) {
if (hidden.contains(vit.key())) continue;
bool cf = filter.contains(vit.key());
if (cf && !inv_filter) continue;
if (!cf && inv_filter) continue;
dal[vit.key()] = vit.value();
}
auto addEdit = [&list, &lay](const QString & name, const PIVariant & value) {
auto * ve = new PIVariantEdit();
ve->setAttributes(PIVariantEditorBase::editorDefaultAttributes(value.typeID()));
ve->setValue(value);
ve->setProperty(property_name, name);
list << ve;
lay->addRow(name + ":", ve);
};
const auto & sal(PIValueTree::standardAttributes());
for (const auto & sn: sal) {
if (!dal.contains(sn)) continue;
addEdit(PI2QString(sn), dal.value(sn));
dal.remove(sn);
}
auto dit = dal.makeIterator();
while (dit.next()) {
addEdit(PI2QString(dit.key()), dit.value());
}
}
void PIValueTreeEditParameters::applyAttributes(PIValueTree & vt) {
bool is_array = vt.isArray();
vt.attributes().clear();
for (auto * w: ve_attr) {
PIString an = Q2PIString(w->property(property_name).toString());
vt.setAttribute(an, w->value());
}
if (is_array) {
vt.setAttribute(Attribute::arrayType, PIVariant::typeNameFromID(comboType->currentData().toUInt()));
for (auto * w: ve_array) {
PIString an = Q2PIString(w->property(property_name).toString());
vt.setAttribute(an, w->value());
}
}
vt.setAttribute(Attribute::hidden, checkHidden->isChecked());
vt.setAttribute(Attribute::readOnly, checkReadOnly->isChecked());
vt.setAttribute(Attribute::isLabel, checkLabel->isChecked());
}
void PIValueTreeEditParameters::checkAttribute(PIValueTree & vt, PIString an, PIVariant def) {
if (vt.attributes().contains(an)) def.setValueFromString(vt.attributes().value(an).toString());
vt.setAttribute(an, def);
}
void PIValueTreeEditParameters::on_comboType_currentIndexChanged(int) {
createAttributes(ve_attr, layoutAttributes);
}
void PIValueTreeEditParameters::on_checkLabel_toggled(bool on) {
if (!on) {
comboType->setEnabled(true);
for (int r = 0; r < layoutAttributes->rowCount(); ++r) {
auto * w = qobject_cast<PIVariantEdit *>(layoutAttributes->itemAt(r, QFormLayout::FieldRole)->widget());
if (!w) continue;
PIString an = Q2PIString(w->property(property_name).toString());
if (an == Attribute::style) {
ve_attr.removeOne(w);
layoutAttributes->removeRow(r);
break;
}
}
} else {
comboType->setEnabled(false);
comboType->setCurrentIndex(comboType->findData(PIVariant::typeID<PIString>()));
ve_attr.clear();
while (layoutAttributes->rowCount() > 0)
layoutAttributes->removeRow(0);
// clang-format off
createAttributes(ve_attr, layoutAttributes, {{Attribute::style, ""}});
// clang-format on
}
}

View File

@@ -0,0 +1,61 @@
/*
PIQt Utils - Qt utilites for PIP
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 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/>.
*/
#ifndef pivaluetree_edit_parameters_H
#define pivaluetree_edit_parameters_H
#include "pivaluetree.h"
#include "ui_pivaluetree_edit_parameters.h"
#include <QDialog>
#include <QFormLayout>
#include <QLabel>
#include <QMenu>
class PIVariantEdit;
class PIValueTreeEditParameters
: public QDialog
, public Ui::PIValueTreeEditParameters {
Q_OBJECT
public:
PIValueTreeEditParameters(QWidget * parent = nullptr);
~PIValueTreeEditParameters();
bool showFor(PIValueTree & vt);
QMenu menu_grouping;
private:
void
createAttributes(QList<PIVariantEdit *> & list, QFormLayout * lay, const PIVariantMap & attr = PIVariantMap(), bool inv_filter = false);
void applyAttributes(PIValueTree & vt);
void checkAttribute(PIValueTree & vt, PIString an, PIVariant def);
int last_IDs_count = -1;
QList<PIVariantEdit *> ve_attr, ve_array;
private slots:
void on_comboType_currentIndexChanged(int);
void on_checkLabel_toggled(bool on);
};
#endif

View File

@@ -0,0 +1,223 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PIValueTreeEditParameters</class>
<widget class="QDialog" name="PIValueTreeEditParameters">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>457</width>
<height>347</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<property name="labelAlignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="checkReadOnly">
<property name="text">
<string>Read-only</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="checkHidden">
<property name="text">
<string>Hidden</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="checkLabel">
<property name="text">
<string>Label</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Type:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="EComboBox" name="comboType"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Comment:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="CLineEdit" name="lineComment"/>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupArray">
<property name="title">
<string>Array</string>
</property>
<layout class="QFormLayout" name="layoutArray">
<property name="labelAlignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupAttributes">
<property name="title">
<string>Attributes</string>
</property>
<layout class="QFormLayout" name="layoutAttributes">
<property name="labelAlignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
<action name="actionRemove">
<property name="icon">
<iconset resource="../blockview/qad_blockview.qrc">
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset>
</property>
<property name="text">
<string>Remove</string>
</property>
</action>
<action name="actionChange">
<property name="icon">
<iconset resource="../application/qad_application.qrc">
<normaloff>:/icons/configure.png</normaloff>:/icons/configure.png</iconset>
</property>
<property name="text">
<string>Change ...</string>
</property>
</action>
<action name="actionRename">
<property name="icon">
<iconset resource="../graphic/qad_graphic.qrc">
<normaloff>:/icons/border-line.png</normaloff>:/icons/border-line.png</iconset>
</property>
<property name="text">
<string>Rename ...</string>
</property>
</action>
<action name="actionValue">
<property name="icon">
<iconset resource="qad_piqt_widgets.qrc">
<normaloff>:/icons/code-variable.png</normaloff>:/icons/code-variable.png</iconset>
</property>
<property name="text">
<string>Value</string>
</property>
</action>
<action name="actionGroup">
<property name="icon">
<iconset resource="qad_piqt_widgets.qrc">
<normaloff>:/icons/code-struct.png</normaloff>:/icons/code-struct.png</iconset>
</property>
<property name="text">
<string>Group</string>
</property>
</action>
<action name="actionArray">
<property name="icon">
<iconset resource="qad_piqt_widgets.qrc">
<normaloff>:/icons/code-union.png</normaloff>:/icons/code-union.png</iconset>
</property>
<property name="text">
<string>Array</string>
</property>
</action>
<action name="actionReorder">
<property name="icon">
<iconset resource="../graphic/qad_graphic.qrc">
<normaloff>:/icons/legend.png</normaloff>:/icons/legend.png</iconset>
</property>
<property name="text">
<string>Reorder ...</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>CLineEdit</class>
<extends>QLineEdit</extends>
<header>clineedit.h</header>
</customwidget>
<customwidget>
<class>EComboBox</class>
<extends>QComboBox</extends>
<header>ecombobox.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../application/qad_application.qrc"/>
<include location="../blockview/qad_blockview.qrc"/>
<include location="../graphic/qad_graphic.qrc"/>
<include location="qad_piqt_widgets.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>PIValueTreeEditParameters</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>247</x>
<y>276</y>
</hint>
<hint type="destinationlabel">
<x>196</x>
<y>221</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>PIValueTreeEditParameters</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>317</x>
<y>269</y>
</hint>
<hint type="destinationlabel">
<x>291</x>
<y>222</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,30 @@
#include "pivaluetree_edit_reorder.h"
#include "piqt.h"
PIValueTreeEditReorder::PIValueTreeEditReorder(QWidget * parent): QDialog(parent) {
setupUi(this);
}
PIValueTreeEditReorder::~PIValueTreeEditReorder() {}
bool PIValueTreeEditReorder::showFor(PIValueTree & vt) {
setWindowTitle(tr("Reorder of \"%1\"").arg(PI2QString(vt.name())));
PIStringList old_list;
for (const auto & c: vt.children())
old_list << c.name();
listWidget->clear();
listWidget->addItems(PI2QStringList(old_list));
if (exec() != QDialog::Accepted) return false;
map.clear();
for (int i = 0; i < listWidget->count(); ++i)
map[i] = old_list.indexOf(Q2PIString(listWidget->item(i)->text()));
return true;
}

View File

@@ -0,0 +1,47 @@
/*
PIQt Utils - Qt utilites for PIP
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 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/>.
*/
#ifndef pivaluetree_edit_reorder_H
#define pivaluetree_edit_reorder_H
#include "pivaluetree.h"
#include "ui_pivaluetree_edit_reorder.h"
#include <QDialog>
class PIValueTreeEditReorder
: public QDialog
, public Ui::PIValueTreeEditReorder {
Q_OBJECT
public:
PIValueTreeEditReorder(QWidget * parent = nullptr);
~PIValueTreeEditReorder();
bool showFor(PIValueTree & vt);
PIMap<int, int> map;
private:
private slots:
};
#endif

View File

@@ -0,0 +1,152 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PIValueTreeEditReorder</class>
<widget class="QDialog" name="PIValueTreeEditReorder">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>457</width>
<height>347</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Change order:</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="listWidget">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
<action name="actionRemove">
<property name="icon">
<iconset resource="../blockview/qad_blockview.qrc">
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset>
</property>
<property name="text">
<string>Remove</string>
</property>
</action>
<action name="actionChange">
<property name="icon">
<iconset resource="../application/qad_application.qrc">
<normaloff>:/icons/configure.png</normaloff>:/icons/configure.png</iconset>
</property>
<property name="text">
<string>Change ...</string>
</property>
</action>
<action name="actionRename">
<property name="icon">
<iconset resource="../graphic/qad_graphic.qrc">
<normaloff>:/icons/border-line.png</normaloff>:/icons/border-line.png</iconset>
</property>
<property name="text">
<string>Rename ...</string>
</property>
</action>
<action name="actionValue">
<property name="icon">
<iconset resource="qad_piqt_widgets.qrc">
<normaloff>:/icons/code-variable.png</normaloff>:/icons/code-variable.png</iconset>
</property>
<property name="text">
<string>Value</string>
</property>
</action>
<action name="actionGroup">
<property name="icon">
<iconset resource="qad_piqt_widgets.qrc">
<normaloff>:/icons/code-struct.png</normaloff>:/icons/code-struct.png</iconset>
</property>
<property name="text">
<string>Group</string>
</property>
</action>
<action name="actionArray">
<property name="icon">
<iconset resource="qad_piqt_widgets.qrc">
<normaloff>:/icons/code-union.png</normaloff>:/icons/code-union.png</iconset>
</property>
<property name="text">
<string>Array</string>
</property>
</action>
<action name="actionReorder">
<property name="icon">
<iconset resource="../graphic/qad_graphic.qrc">
<normaloff>:/icons/legend.png</normaloff>:/icons/legend.png</iconset>
</property>
<property name="text">
<string>Reorder ...</string>
</property>
</action>
</widget>
<resources>
<include location="../application/qad_application.qrc"/>
<include location="../blockview/qad_blockview.qrc"/>
<include location="../graphic/qad_graphic.qrc"/>
<include location="qad_piqt_widgets.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>PIValueTreeEditReorder</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>260</x>
<y>333</y>
</hint>
<hint type="destinationlabel">
<x>196</x>
<y>221</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>PIValueTreeEditReorder</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>330</x>
<y>333</y>
</hint>
<hint type="destinationlabel">
<x>291</x>
<y>222</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,133 @@
#include "pivariant_edit.h"
#include "piqt.h"
#include "pivaluetree_edit.h"
#include <QEvent>
QString PIVariantEditorBase::vtTr(const PIString & txt) {
PIByteArray utf = txt.toUTF8();
utf.append(0);
QString ret = QCoreApplication::translate("QAD::PIValueTreeEdit", reinterpret_cast<const char *>(utf.data()));
ret.detach();
return ret;
}
PIVariantEditorBase * PIVariantEditorBase::createEditor(uint type_id) {
auto f = factories().value(type_id, nullptr);
if (!f) return nullptr;
auto ret = f();
ret->retranslate();
return ret;
}
bool PIVariantEditorBase::editorExists(uint type_id) {
return factories().value(type_id, nullptr);
}
PIVariantMap PIVariantEditorBase::editorDefaultAttributes(uint type_id) {
return default_attributes().value(type_id);
}
PIVariantTypes::Enum PIVariantEditorBase::createGrouping() {
PIVariantTypes::Enum ret;
ret << PIVariantTypes::Enumerator(PIValueTreeEdit::Indent, "indent") << PIVariantTypes::Enumerator(PIValueTreeEdit::Groups, "groups")
<< PIVariantTypes::Enumerator(PIValueTreeEdit::Tabs, "tabs") << PIVariantTypes::Enumerator(PIValueTreeEdit::Parent, "parent");
ret.selectValue(PIValueTreeEdit::Parent);
return ret;
}
void PIVariantEditorBase::createBoxLayout(QBoxLayout::Direction d) {
auto * l = new QBoxLayout(d);
l->setContentsMargins(0, 0, 0, 0);
setLayout(l);
}
void PIVariantEditorBase::changeEvent(QEvent * e) {
if (e->type() == QEvent::LanguageChange) retranslate();
QWidget::changeEvent(e);
}
PIMap<uint, PIVariantEditorBase * (*)()> & PIVariantEditorBase::factories() {
static PIMap<uint, PIVariantEditorBase * (*)()> ret;
return ret;
}
PIMap<uint, PIVariantMap> & PIVariantEditorBase::default_attributes() {
static PIMap<uint, PIVariantMap> ret;
return ret;
}
PIVariantEdit::PIVariantEdit(QWidget * parent): PIVariantEditorBase(parent) {
label = new QLabel();
label->setAlignment(Qt::AlignCenter);
setValue(PIVariant());
}
PIVariantEdit::~PIVariantEdit() {
delete label;
}
void PIVariantEdit::setValue(const PIVariant & v, uint type_id) {
if (type_id == 0) type_id = v.typeID();
if (current_type_id != type_id || !editor) {
if (editor) delete editor;
current_type_id = type_id;
editor = PIVariantEditorBase::createEditor(current_type_id);
if (editor) {
editor->applyAttributes(_attributes);
layout()->removeWidget(label);
layout()->addWidget(editor);
label->hide();
} else {
label->setText(!v.isValid() ? tr("Invalid type") : tr("No editor for %1").arg(PI2QString(PIVariant::typeNameFromID(type_id))));
layout()->addWidget(label);
label->show();
}
}
if (!editor) return;
editor->setValue(v);
}
PIVariant PIVariantEdit::value() const {
if (!editor) return PIVariant();
return editor->value();
}
void PIVariantEdit::setAttributes(const PIVariantMap & a) {
_attributes = a;
if (!editor) return;
editor->applyAttributes(_attributes);
}
PIVariantMap PIVariantEdit::attributes() const {
if (!editor) return PIVariantMap();
return editor->attributes();
}
void PIVariantEdit::setFullEditMode(bool on) {
if (!editor) return;
editor->setFullEditMode(on);
}
void PIVariantEdit::retranslate() {
if (!editor) return;
editor->retranslate();
}

View File

@@ -0,0 +1,111 @@
/*
PIQt Utils - Qt utilites for PIP
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 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/>.
*/
#ifndef pivariant_edit_H
#define pivariant_edit_H
#include "pivariant.h"
#include "qad_piqt_utils_export.h"
#include <QBoxLayout>
#include <QDebug>
#include <QLabel>
#include <QWidget>
#define REGISTER_PIVARIANTEDITOR(type_name, class_name) \
STATIC_INITIALIZER_BEGIN \
PIVariantEditorBase::registerEditor<class_name>(PIVariant::typeIDFromName(PIStringAscii(#type_name))); \
STATIC_INITIALIZER_END
class PIVariantEdit;
class QAD_PIQT_UTILS_EXPORT PIVariantEditorBase: public QWidget {
friend class PIVariantEdit;
public:
PIVariantEditorBase(QWidget * parent = nullptr): QWidget(parent) { createBoxLayout(); }
virtual ~PIVariantEditorBase() {}
virtual void setValue(const PIVariant & v) = 0;
virtual PIVariant value() const = 0;
virtual PIVariantMap attributes() const { return PIVariantMap(); }
static PIVariantMap defaultAttributes() { return PIVariantMap(); }
virtual void retranslate() {}
static QString vtTr(const PIString & txt);
template<typename T>
static void registerEditor(uint type_id) {
if (factories().contains(type_id)) {
piCout << "[PIVariantEditorBase::registerEditor] Editor with typeID" << type_id << "already registered, ignore";
return;
}
factories()[type_id] = []() -> PIVariantEditorBase * { return new T(); };
default_attributes()[type_id] = T::defaultAttributes();
// qDebug() << "register" << T::staticMetaObject.className() << type_id;
}
static PIVariantEditorBase * createEditor(uint type_id);
static bool editorExists(uint type_id);
static PIVariantMap editorDefaultAttributes(uint type_id);
static PIVariantTypes::Enum createGrouping();
protected:
void createBoxLayout(QBoxLayout::Direction d = QBoxLayout::LeftToRight);
virtual void setFullEditMode(bool on) {}
virtual void applyAttributes(const PIVariantMap & a) {}
private:
void changeEvent(QEvent * e) override;
static PIMap<uint, PIVariantEditorBase * (*)()> & factories();
static PIMap<uint, PIVariantMap> & default_attributes();
};
class QAD_PIQT_UTILS_EXPORT PIVariantEdit: public PIVariantEditorBase {
Q_OBJECT
public:
PIVariantEdit(QWidget * parent = nullptr);
~PIVariantEdit();
void setValue(const PIVariant & v, uint type_id);
void setValue(const PIVariant & v) override { setValue(v, v.typeID()); }
PIVariant value() const override;
void setAttributes(const PIVariantMap & a);
PIVariantMap attributes() const override;
void setFullEditMode(bool on) override;
void retranslate() override;
private:
PIVariantEditorBase * editor = nullptr;
PIVariantMap _attributes;
QLabel * label;
uint current_type_id = -1;
};
#endif

View File

@@ -0,0 +1,74 @@
#include "pivariant_edit_enum.h"
#include "piqt.h"
PIValueTreeEditEnum::PIValueTreeEditEnum(QWidget * parent): QDialog(parent) {
setupUi(this);
}
PIValueTreeEditEnum::~PIValueTreeEditEnum() {}
bool PIValueTreeEditEnum::showFor(const PIVariantTypes::Enum & v) {
ret = PIVariantTypes::Enum();
treeWidget->clear();
for (auto e: v.enum_list)
addItem(PI2QString(e.name), e.value);
if (exec() != QDialog::Accepted) return false;
for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) {
auto * ti = treeWidget->topLevelItem(i);
ret << PIVariantTypes::Enumerator(ti->text(1).toInt(), Q2PIString(ti->text(0)));
}
return true;
}
QTreeWidgetItem * PIValueTreeEditEnum::addItem(QString n, int v) {
auto * ti = new QTreeWidgetItem({n, QString::number(v)});
treeWidget->addTopLevelItem(ti);
auto f = ti->flags();
f.setFlag(Qt::ItemIsEditable);
ti->setFlags(f);
return ti;
}
void PIValueTreeEditEnum::on_buttonAdd_clicked() {
bool is_edit = false;
for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) {
auto * ti = treeWidget->topLevelItem(i);
for (int c = 0; c < treeWidget->columnCount(); ++c) {
if (treeWidget->isPersistentEditorOpen(ti, c)) {
is_edit = true;
break;
}
}
if (is_edit) break;
}
if (is_edit) {
buttonAdd->setFocus();
treeWidget->setFocus();
}
int max = -1;
for (int i = 0; i < treeWidget->topLevelItemCount(); ++i)
max = piMaxi(max, treeWidget->topLevelItem(i)->text(1).toInt());
auto * ti = addItem("name", max + 1);
treeWidget->editItem(ti, 0);
}
void PIValueTreeEditEnum::on_buttonRemove_clicked() {
qDeleteAll(treeWidget->selectedItems());
}
void PIValueTreeEditEnum::on_buttonClear_clicked() {
treeWidget->clear();
}

View File

@@ -0,0 +1,52 @@
/*
PIQt Utils - Qt utilites for PIP
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 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/>.
*/
#ifndef pivariant_edit_enum_H
#define pivariant_edit_enum_H
#include "ui_pivariant_edit_enum.h"
#include <QDialog>
#include <pivariant.h>
class PIValueTreeEditEnum
: public QDialog
, public Ui::PIValueTreeEditEnum {
Q_OBJECT
public:
PIValueTreeEditEnum(QWidget * parent = nullptr);
~PIValueTreeEditEnum();
bool showFor(const PIVariantTypes::Enum & v);
PIVariantTypes::Enum ret;
private:
QTreeWidgetItem * addItem(QString n, int v);
private slots:
void on_buttonAdd_clicked();
void on_buttonRemove_clicked();
void on_buttonClear_clicked();
};
#endif

View File

@@ -0,0 +1,223 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PIValueTreeEditEnum</class>
<widget class="QDialog" name="PIValueTreeEditEnum">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>457</width>
<height>347</height>
</rect>
</property>
<property name="windowTitle">
<string>Edit Enum</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<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="QToolButton" name="buttonAdd">
<property name="icon">
<iconset resource="qad_piqt_widgets.qrc">
<normaloff>:/icons/list-add.png</normaloff>:/icons/list-add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonRemove">
<property name="icon">
<iconset resource="../blockview/qad_blockview.qrc">
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="buttonClear">
<property name="icon">
<iconset resource="../application/qad_application.qrc">
<normaloff>:/icons/edit-clear.png</normaloff>:/icons/edit-clear.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTreeWidget" name="treeWidget">
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="itemsExpandable">
<bool>false</bool>
</property>
<property name="expandsOnDoubleClick">
<bool>false</bool>
</property>
<column>
<property name="text">
<string>Name</string>
</property>
</column>
<column>
<property name="text">
<string>Value</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
<action name="actionRemove">
<property name="icon">
<iconset resource="../blockview/qad_blockview.qrc">
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset>
</property>
<property name="text">
<string>Remove</string>
</property>
</action>
<action name="actionChange">
<property name="icon">
<iconset resource="../application/qad_application.qrc">
<normaloff>:/icons/configure.png</normaloff>:/icons/configure.png</iconset>
</property>
<property name="text">
<string>Change ...</string>
</property>
</action>
<action name="actionRename">
<property name="icon">
<iconset resource="../graphic/qad_graphic.qrc">
<normaloff>:/icons/border-line.png</normaloff>:/icons/border-line.png</iconset>
</property>
<property name="text">
<string>Rename ...</string>
</property>
</action>
<action name="actionValue">
<property name="icon">
<iconset resource="qad_piqt_widgets.qrc">
<normaloff>:/icons/code-variable.png</normaloff>:/icons/code-variable.png</iconset>
</property>
<property name="text">
<string>Value</string>
</property>
</action>
<action name="actionGroup">
<property name="icon">
<iconset resource="qad_piqt_widgets.qrc">
<normaloff>:/icons/code-struct.png</normaloff>:/icons/code-struct.png</iconset>
</property>
<property name="text">
<string>Group</string>
</property>
</action>
<action name="actionArray">
<property name="icon">
<iconset resource="qad_piqt_widgets.qrc">
<normaloff>:/icons/code-union.png</normaloff>:/icons/code-union.png</iconset>
</property>
<property name="text">
<string>Array</string>
</property>
</action>
<action name="actionReorder">
<property name="icon">
<iconset resource="../graphic/qad_graphic.qrc">
<normaloff>:/icons/legend.png</normaloff>:/icons/legend.png</iconset>
</property>
<property name="text">
<string>Reorder ...</string>
</property>
</action>
</widget>
<resources>
<include location="../application/qad_application.qrc"/>
<include location="../blockview/qad_blockview.qrc"/>
<include location="../graphic/qad_graphic.qrc"/>
<include location="qad_piqt_widgets.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>PIValueTreeEditEnum</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>260</x>
<y>333</y>
</hint>
<hint type="destinationlabel">
<x>196</x>
<y>221</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>PIValueTreeEditEnum</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>330</x>
<y>333</y>
</hint>
<hint type="destinationlabel">
<x>291</x>
<y>222</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,628 @@
#include "pivariant_edit_widgets.h"
#include "evalspinbox.h"
#include "pivaluetree.h"
#include "pivariant_edit_enum.h"
#include "pivarianttypes.h"
#include "scroll_spin_box.h"
#include "spinslider.h"
#include <QEvent>
#include <QFileDialog>
#include <QInputDialog>
#include <QMessageBox>
#include <QToolButton>
REGISTER_PIVARIANTEDITOR(bool, PIVariantEditors::Bool);
REGISTER_PIVARIANTEDITOR(short, PIVariantEditors::Int);
REGISTER_PIVARIANTEDITOR(ushort, PIVariantEditors::Int);
REGISTER_PIVARIANTEDITOR(int, PIVariantEditors::Int);
REGISTER_PIVARIANTEDITOR(uint, PIVariantEditors::Int);
REGISTER_PIVARIANTEDITOR(float, PIVariantEditors::Double);
REGISTER_PIVARIANTEDITOR(double, PIVariantEditors::Double);
REGISTER_PIVARIANTEDITOR(PIString, PIVariantEditors::String);
REGISTER_PIVARIANTEDITOR(PIStringList, PIVariantEditors::StringList);
REGISTER_PIVARIANTEDITOR(PITime, PIVariantEditors::Time);
REGISTER_PIVARIANTEDITOR(PIDate, PIVariantEditors::Date);
REGISTER_PIVARIANTEDITOR(PIDateTime, PIVariantEditors::DateTime);
REGISTER_PIVARIANTEDITOR(PIVariantTypes::Color, PIVariantEditors::Color);
REGISTER_PIVARIANTEDITOR(PIVariantTypes::Enum, PIVariantEditors::Enum);
REGISTER_PIVARIANTEDITOR(PINetworkAddress, PIVariantEditors::NetworkAddress);
REGISTER_PIVARIANTEDITOR(PIVariantTypes::File, PIVariantEditors::File);
REGISTER_PIVARIANTEDITOR(PIVariantTypes::Dir, PIVariantEditors::Dir);
using Attribute = PIValueTree::Attribute;
// PIVariantEditors::NumberBase
PIVariantEditors::NumberBase::NumberBase() {}
void PIVariantEditors::NumberBase::setValueNumeric(double v) {
switch (type) {
case tSpinBox: {
auto * w = qobject_cast<QDoubleSpinBox *>(widget);
if (w) w->setValue(v);
} break;
case tSlider: {
auto * w = qobject_cast<QSlider *>(widget);
if (w) w->setValue(v);
} break;
case tSpinSlider: {
auto * w = qobject_cast<SpinSlider *>(widget);
if (w) w->setValue(v);
} break;
case tEvalSpinBox: {
auto * w = qobject_cast<EvalSpinBox *>(widget);
if (w) {
PIString vs = PIString::fromNumber(v), es = PIString::fromNumber(w->value());
if (vs != es) w->setValue(v);
}
} break;
case tScrollSpinBox: {
auto * w = qobject_cast<ScrollSpinBox *>(widget);
if (w) w->setValue(v);
} break;
default: break;
}
}
double PIVariantEditors::NumberBase::valueNumeric() const {
switch (type) {
case tSpinBox: {
auto * w = qobject_cast<QDoubleSpinBox *>(widget);
if (w) return w->value();
} break;
case tSlider: {
auto * w = qobject_cast<QSlider *>(widget);
if (w) return w->value();
} break;
case tSpinSlider: {
auto * w = qobject_cast<SpinSlider *>(widget);
if (w) return w->value();
} break;
case tEvalSpinBox: {
auto * w = qobject_cast<EvalSpinBox *>(widget);
if (w) return w->value();
} break;
case tScrollSpinBox: {
auto * w = qobject_cast<ScrollSpinBox *>(widget);
if (w) return w->value();
} break;
default: break;
}
return 0.;
}
PIVariantMap PIVariantEditors::NumberBase::attributes() const {
auto etype = createTypes();
etype.selectValue(type);
PIVariantMap ret = {
{Attribute::widgetType, etype },
{Attribute::prefix, prefix},
{Attribute::suffix, suffix},
};
switch (type) {
case tSpinBox: {
auto * w = qobject_cast<QDoubleSpinBox *>(widget);
if (w) {
ret[Attribute::minimum] = w->minimum();
ret[Attribute::maximum] = w->maximum();
ret[Attribute::singleStep] = w->singleStep();
if (!is_int) ret[Attribute::decimals] = w->decimals();
}
} break;
case tSlider: {
auto * w = qobject_cast<QSlider *>(widget);
if (w) {
ret[Attribute::minimum] = w->minimum();
ret[Attribute::maximum] = w->maximum();
ret[Attribute::singleStep] = w->singleStep();
}
} break;
case tSpinSlider: {
auto * w = qobject_cast<SpinSlider *>(widget);
if (w) {
ret[Attribute::minimum] = w->minimum();
ret[Attribute::maximum] = w->maximum();
ret[Attribute::singleStep] = w->singleStep();
if (!is_int) ret[Attribute::decimals] = w->decimals();
}
} break;
case tEvalSpinBox: {
auto * w = qobject_cast<EvalSpinBox *>(widget);
if (w) {
ret[Attribute::expression] = Q2PIString(w->expression());
}
} break;
default: break;
}
return ret;
}
PIVariantMap PIVariantEditors::NumberBase::defaultAttributes() {
return {
{Attribute::widgetType, createTypes() },
{Attribute::minimum, -std::numeric_limits<int>::max()},
{Attribute::maximum, std::numeric_limits<int>::max() },
{Attribute::singleStep, 1. },
{Attribute::decimals, 3 },
{Attribute::prefix, "" },
{Attribute::suffix, "" },
};
}
PIVariantTypes::Enum PIVariantEditors::NumberBase::createTypes() {
PIVariantTypes::Enum ret;
ret << PIVariantTypes::Enumerator(tSpinBox, "spin box") << PIVariantTypes::Enumerator(tSlider, "slider")
<< PIVariantTypes::Enumerator(tSpinSlider, "spin-slider") << PIVariantTypes::Enumerator(tEvalSpinBox, "eval spin box")
<< PIVariantTypes::Enumerator(tScrollSpinBox, "scroll spin box");
ret.selectValue(tSpinBox);
return ret;
}
void PIVariantEditors::NumberBase::retranslate() {
switch (type) {
case tSpinBox: {
auto * w = qobject_cast<QDoubleSpinBox *>(widget);
if (!w) return;
w->setPrefix(PIVariantEditorBase::vtTr(prefix));
w->setSuffix(PIVariantEditorBase::vtTr(suffix));
} break;
case tSpinSlider: {
auto * w = qobject_cast<SpinSlider *>(widget);
if (!w) return;
w->setPrefix(PIVariantEditorBase::vtTr(prefix));
w->setSuffix(PIVariantEditorBase::vtTr(suffix));
} break;
default: break;
}
}
void PIVariantEditors::NumberBase::applyAttributes(const PIVariantMap & a) {
Type new_type = static_cast<Type>(a.value(Attribute::widgetType).toEnum().selectedValue());
if (type != new_type) {
type = new_type;
if (widget) delete widget;
widget = nullptr;
// clang-format off
switch (type) {
case tSpinBox : widget = new QDoubleSpinBox(); break;
case tSlider : widget = new QSlider (Qt::Horizontal); break;
case tSpinSlider : widget = new SpinSlider (); break;
case tEvalSpinBox : widget = new EvalSpinBox (); break;
case tScrollSpinBox: widget = new ScrollSpinBox (); break;
default: break;
}
// clang-format on
if (!widget) return;
widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
layout()->addWidget(widget);
}
prefix = a.value(Attribute::prefix).toString();
suffix = a.value(Attribute::suffix).toString();
double min = a.value(Attribute::minimum).toDouble();
double max = a.value(Attribute::maximum).toDouble();
double step = a.value(Attribute::singleStep).toDouble();
int dec = is_int ? 0 : a.value(Attribute::decimals).toInt();
switch (type) {
case tSpinBox: {
auto * w = qobject_cast<QDoubleSpinBox *>(widget);
if (!w) return;
w->setPrefix(PIVariantEditorBase::vtTr(prefix));
w->setSuffix(PIVariantEditorBase::vtTr(suffix));
w->setRange(min, max);
w->setSingleStep(step);
w->setDecimals(dec);
} break;
case tSlider: {
auto * w = qobject_cast<QSlider *>(widget);
if (!w) return;
w->setTickInterval(piRoundd(piMaxd(1., (max - min) / 100.)));
w->setRange(min, max);
w->setSingleStep(step);
} break;
case tSpinSlider: {
auto * w = qobject_cast<SpinSlider *>(widget);
if (!w) return;
w->setPrefix(PIVariantEditorBase::vtTr(prefix));
w->setSuffix(PIVariantEditorBase::vtTr(suffix));
w->setMinimum(min);
w->setMaximum(max);
w->setSingleStep(step);
w->setDecimals(dec);
} break;
case tEvalSpinBox: {
auto * w = qobject_cast<EvalSpinBox *>(widget);
if (!w) return;
w->setExpression(PI2QString(a.value(Attribute::expression).toString()));
} break;
case tScrollSpinBox: {
auto * w = qobject_cast<ScrollSpinBox *>(widget);
if (!w) return;
} break;
default: break;
}
}
// PIVariantEditors::Int
// PIVariantEditors::Double
// PIVariantEditors::String
PIVariantMap PIVariantEditors::String::attributes() const {
return {};
}
PIVariantMap PIVariantEditors::String::defaultAttributes() {
return {};
}
void PIVariantEditors::String::applyAttributes(const PIVariantMap & a) {
widget->setReadOnly(a.value(Attribute::readOnly, widget->isReadOnly()).toBool());
}
// PIVariantEditors::StringList
PIVariantEditors::StringList::StringList() {
combo = new EComboBox(this);
combo->setEditable(true);
combo->setLineEdit(new CLineEdit);
combo->setInsertPolicy(QComboBox::NoInsert);
layout()->setContentsMargins(0, 0, 0, 0);
layout()->addWidget(combo);
auto newButton = [this](QString icon, QString tooltip) {
auto * b = new QToolButton(this);
b->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
b->setIcon(QIcon(icon));
b->setToolTip(tooltip);
layout()->addWidget(b);
return b;
};
butt_apply = newButton(":/icons/list-edit-apply.png", tr("Apply"));
butt_add = newButton(":/icons/list-add.png", tr("Add"));
butt_del = newButton(":/icons/list-remove.png", tr("Remove"));
butt_clear = newButton(":/icons/edit-clear.png", tr("Clear"));
connect(combo->lineEdit(), SIGNAL(returnPressed()), butt_apply, SLOT(click()));
connect(butt_apply, &QToolButton::clicked, [this]() {
int ci = combo->currentIndex();
if (ci < 0) return;
combo->setItemText(ci, combo->currentText());
});
connect(butt_add, &QToolButton::clicked, [this]() { combo->addItem(combo->currentText()); });
connect(butt_del, &QToolButton::clicked, [this]() {
if (combo->currentIndex() < 0) return;
combo->removeItem(combo->currentIndex());
});
connect(butt_clear, &QToolButton::clicked, [this]() {
if (QMessageBox::question(nullptr, tr("Clear All"), tr("Clear All?"), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok)
setValue(PIStringList());
});
}
void PIVariantEditors::StringList::setValue(const PIVariant & v) {
int pi = combo->currentIndex();
combo->clear();
combo->addItems(PI2QStringList(v.toStringList()));
if (combo->count() > 0) {
if (pi < combo->count() && pi >= 0) {
combo->setCurrentIndex(pi);
} else {
combo->setCurrentIndex(0);
}
}
}
PIVariant PIVariantEditors::StringList::value() const {
QStringList l;
for (int i = 0; i < combo->count(); ++i)
l << combo->itemText(i);
return Q2PIStringList(l);
}
PIVariantMap PIVariantEditors::StringList::attributes() const {
return {
{Attribute::readOnly, !combo->isEditable()},
};
}
void PIVariantEditors::StringList::applyAttributes(const PIVariantMap & a) {
bool ro = a.value(Attribute::readOnly, !combo->isEditable()).toBool();
combo->setEditable(!ro);
butt_apply->setEnabled(!ro);
butt_add->setEnabled(!ro);
butt_del->setEnabled(!ro);
butt_clear->setEnabled(!ro);
}
void PIVariantEditors::StringList::retranslate() {
butt_apply->setToolTip(tr("Apply"));
butt_add->setToolTip(tr("Add"));
butt_del->setToolTip(tr("Remove"));
butt_clear->setToolTip(tr("Clear"));
}
// PIVariantEditors::Color
PIVariantMap PIVariantEditors::Color::attributes() const {
return {
{"useAlpha", widget->useAlphaChannel()},
};
}
PIVariantMap PIVariantEditors::Color::defaultAttributes() {
return {
{"useAlpha", true},
};
}
void PIVariantEditors::Color::applyAttributes(const PIVariantMap & a) {
widget->setUseAlphaChannel(a.value("useAlpha", widget->useAlphaChannel()).toBool());
widget->setEnabled(!a.value(Attribute::readOnly, !widget->isEnabled()).toBool());
}
// PIVariantEditors::Time
void PIVariantEditors::Time::applyAttributes(const PIVariantMap & a) {
widget->setReadOnly(a.value(Attribute::readOnly, widget->isReadOnly()).toBool());
}
// PIVariantEditors::Date
void PIVariantEditors::Date::applyAttributes(const PIVariantMap & a) {
widget->setReadOnly(a.value(Attribute::readOnly, widget->isReadOnly()).toBool());
}
// PIVariantEditors::DateTime
void PIVariantEditors::DateTime::applyAttributes(const PIVariantMap & a) {
widget->setReadOnly(a.value(Attribute::readOnly, widget->isReadOnly()).toBool());
}
// PIVariantEditors::Enum
PIVariantEditors::Enum::Enum() {
widget = new QComboBox();
layout()->addWidget(widget);
edit_widget = new QWidget();
edit_widget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
edit_widget->setLayout(new QBoxLayout(QBoxLayout::LeftToRight));
QMargins m = edit_widget->layout()->contentsMargins();
edit_widget->layout()->setContentsMargins(m.left(), 0, 0, 0);
auto * b = new QToolButton();
b->setIcon(QIcon(":/icons/document-edit.png"));
connect(b, &QToolButton::clicked, this, [this]() {
PIValueTreeEditEnum dlg;
if (!dlg.showFor(src)) return;
setValue(PIVariant(dlg.ret));
});
edit_widget->layout()->addWidget(b);
layout()->setSpacing(0);
layout()->addWidget(edit_widget);
setFullEditMode(false);
}
void PIVariantEditors::Enum::setValue(const PIVariant & v) {
src = v.toEnum();
int sv = src.selectedValue();
widget->clear();
for (const auto & e: src.enum_list) {
widget->addItem(PI2QString(e.name), e.value);
if (e.value == sv) widget->setCurrentIndex(widget->count() - 1);
}
}
PIVariant PIVariantEditors::Enum::value() const {
src.selectValue(widget->currentData().toInt());
return src;
}
void PIVariantEditors::Enum::applyAttributes(const PIVariantMap & a) {
widget->setEnabled(!a.value(Attribute::readOnly, !widget->isEnabled()).toBool());
}
void PIVariantEditors::Enum::setFullEditMode(bool on) {
edit_widget->setVisible(on);
}
// PIVariantEditors::NetworkAddress
PIVariantEditors::NetworkAddress::NetworkAddress() {
widget = new QLineEdit();
widget->setInputMask("000.000.000.000:00000;_");
layout()->addWidget(widget);
}
void PIVariantEditors::NetworkAddress::setValue(const PIVariant & v) {
if (has_port)
widget->setText(PI2QString(v.toNetworkAddress().toString()));
else
widget->setText(PI2QString(v.toNetworkAddress().ipString()));
}
PIVariant PIVariantEditors::NetworkAddress::value() const {
return PINetworkAddress(Q2PIString(widget->text()));
}
PIVariantMap PIVariantEditors::NetworkAddress::attributes() const {
return {
{"port", has_port}
};
}
PIVariantMap PIVariantEditors::NetworkAddress::defaultAttributes() {
return {
{"port", true}
};
}
void PIVariantEditors::NetworkAddress::applyAttributes(const PIVariantMap & a) {
has_port = a.value("port", true).toBool();
if (has_port)
widget->setInputMask("000.000.000.000:00000;_");
else
widget->setInputMask("000.000.000.000;_");
widget->setReadOnly(a.value(Attribute::readOnly, widget->isReadOnly()).toBool());
}
// PIVariantEditors::FileBase
PIVariantEditors::FileBase::FileBase() {
filter = "All files(*)";
widget = new CLineEdit();
layout()->addWidget(widget);
sel_widget = new QWidget();
sel_widget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
sel_widget->setLayout(new QBoxLayout(QBoxLayout::LeftToRight));
QMargins m = sel_widget->layout()->contentsMargins();
sel_widget->layout()->setContentsMargins(m.left(), 0, 0, 0);
auto * b = new QToolButton();
b->setIcon(QIcon(":/icons/document-open.png"));
b->setToolTip(tr("Choose") + " ...");
connect(b, &QToolButton::clicked, this, [this]() {
QString ret;
if (is_dir)
ret = QFileDialog::getExistingDirectory(this, tr("Select directory"), widget->text());
else {
if (is_save)
ret = QFileDialog::getSaveFileName(this, tr("Select file"), widget->text(), PIVariantEditorBase::vtTr(filter));
else
ret = QFileDialog::getOpenFileName(this, tr("Select file"), widget->text(), PIVariantEditorBase::vtTr(filter));
}
if (ret.isEmpty()) return;
if (!is_abs) ret = QDir::current().relativeFilePath(ret);
widget->setText(ret);
});
sel_widget->layout()->addWidget(b);
layout()->addWidget(sel_widget);
edit_widget = new QWidget();
edit_widget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
edit_widget->setLayout(new QBoxLayout(QBoxLayout::LeftToRight));
m = edit_widget->layout()->contentsMargins();
edit_widget->layout()->setContentsMargins(m.left(), 0, 0, 0);
b = new QToolButton();
b->setIcon(QIcon(":/icons/document-edit.png"));
b->setPopupMode(QToolButton::InstantPopup);
b->setMenu(&edit_menu);
edit_widget->layout()->addWidget(b);
layout()->setSpacing(0);
layout()->addWidget(edit_widget);
setFullEditMode(false);
}
PIVariantMap PIVariantEditors::FileBase::attributes() const {
return {
{Attribute::filter, filter },
{Attribute::absolutePath, is_abs },
{Attribute::onlyExisting, !is_save}
};
}
PIVariantMap PIVariantEditors::FileBase::defaultAttributes() {
return {
{Attribute::filter, "" },
{Attribute::absolutePath, false},
{Attribute::onlyExisting, true }
};
}
void PIVariantEditors::FileBase::applyAttributes(const PIVariantMap & a) {
filter = a.value(Attribute::filter).toString();
is_abs = a.value(Attribute::absolutePath).toBool();
is_save = !a.value(Attribute::onlyExisting, true).toBool();
bool ro = a.value(Attribute::readOnly).toBool();
widget->setReadOnly(ro);
sel_widget->setHidden(ro);
if (act_abs) act_abs->setChecked(is_abs);
if (act_save) act_save->setChecked(!is_save);
}
void PIVariantEditors::FileBase::setFullEditMode(bool on) {
edit_widget->setVisible(on);
}
void PIVariantEditors::FileBase::createMenu() {
act_abs = edit_menu.addAction(tr("Absolute path"), this, [this](bool on) { is_abs = on; });
act_abs->setCheckable(true);
act_abs->setChecked(is_abs);
if (is_dir) return;
act_save = edit_menu.addAction(tr("Existing only"), this, [this](bool on) { is_save = !on; });
act_save->setCheckable(true);
act_save->setChecked(!is_save);
edit_menu.addAction(tr("Set filter ..."), this, [this]() {
bool ok = false;
QString nf = QInputDialog::getText(nullptr, tr("Select filter"), tr("Input filter:"), QLineEdit::Normal, PI2QString(filter), &ok);
if (!ok) return;
filter = Q2PIString(nf);
});
}
// PIVariantEditors::File
void PIVariantEditors::File::setValue(const PIVariant & v) {
widget->setText(PI2QString(v.toFile().file));
}
PIVariant PIVariantEditors::File::value() const {
PIVariantTypes::File v;
v.file = Q2PIString(widget->text());
return v;
}
// PIVariantEditors::Dir
void PIVariantEditors::Dir::setValue(const PIVariant & v) {
widget->setText(PI2QString(v.toDir().dir));
}
PIVariant PIVariantEditors::Dir::value() const {
PIVariantTypes::Dir v;
v.dir = Q2PIString(widget->text());
return v;
}

View File

@@ -0,0 +1,309 @@
/*
PIQt Utils - Qt utilites for PIP
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 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/>.
*/
#ifndef pivariant_edit_widgets_H
#define pivariant_edit_widgets_H
#include "pivariant_edit.h"
#include <QCheckBox>
#include <QComboBox>
#include <QDateEdit>
#include <QDoubleSpinBox>
#include <QMenu>
#include <QSpinBox>
#include <QTimeEdit>
#include <clineedit.h>
#include <colorbutton.h>
#include <ecombobox.h>
#include <piqt.h>
namespace PIVariantEditors {
class QAD_PIQT_UTILS_EXPORT NumberBase: public PIVariantEditorBase {
Q_OBJECT
public:
NumberBase();
void setValueNumeric(double v);
double valueNumeric() const;
PIVariantMap attributes() const override;
static PIVariantMap defaultAttributes();
static PIVariantTypes::Enum createTypes();
void retranslate() override;
protected:
void applyAttributes(const PIVariantMap & a) override;
enum Type {
tInvalid,
tSpinBox,
tSlider,
tSpinSlider,
tEvalSpinBox,
tScrollSpinBox,
};
Type type = tInvalid;
PIString prefix, suffix;
QWidget * widget = nullptr;
bool is_int = false;
};
class QAD_PIQT_UTILS_EXPORT Bool: public PIVariantEditorBase {
Q_OBJECT
public:
Bool() {
widget = new QCheckBox();
layout()->addWidget(widget);
}
void setValue(const PIVariant & v) override { widget->setChecked(v.toBool()); }
PIVariant value() const override { return widget->isChecked(); }
private:
QCheckBox * widget;
};
class QAD_PIQT_UTILS_EXPORT Int: public NumberBase {
Q_OBJECT
public:
Int(): NumberBase() {
is_int = true;
applyAttributes(NumberBase::defaultAttributes());
}
void setValue(const PIVariant & v) override { setValueNumeric(v.toInt()); }
PIVariant value() const override { return piRoundd(valueNumeric()); }
};
class QAD_PIQT_UTILS_EXPORT Double: public NumberBase {
Q_OBJECT
public:
Double(): NumberBase() {
is_int = false;
applyAttributes(NumberBase::defaultAttributes());
}
void setValue(const PIVariant & v) override { setValueNumeric(v.toDouble()); }
PIVariant value() const override { return valueNumeric(); }
};
class QAD_PIQT_UTILS_EXPORT String: public PIVariantEditorBase {
Q_OBJECT
public:
String() {
widget = new CLineEdit();
layout()->addWidget(widget);
}
void setValue(const PIVariant & v) override { widget->setText(PI2QString(v.toString())); }
PIVariant value() const override { return Q2PIString(widget->text()); }
PIVariantMap attributes() const override;
static PIVariantMap defaultAttributes();
private:
void applyAttributes(const PIVariantMap & a) override;
CLineEdit * widget;
};
class QAD_PIQT_UTILS_EXPORT StringList: public PIVariantEditorBase {
Q_OBJECT
public:
StringList();
void setValue(const PIVariant & v) override;
PIVariant value() const override;
PIVariantMap attributes() const override;
private:
void applyAttributes(const PIVariantMap & a) override;
void retranslate() override;
EComboBox * combo;
QToolButton *butt_apply, *butt_add, *butt_del, *butt_clear;
};
class QAD_PIQT_UTILS_EXPORT Color: public PIVariantEditorBase {
Q_OBJECT
public:
Color() {
widget = new ColorButton();
layout()->addWidget(widget);
}
void setValue(const PIVariant & v) override { widget->setColor(PI2QColor(v.toColor())); }
PIVariant value() const override { return Q2PIColor(widget->color()); }
PIVariantMap attributes() const override;
static PIVariantMap defaultAttributes();
private:
void applyAttributes(const PIVariantMap & a) override;
ColorButton * widget;
};
class QAD_PIQT_UTILS_EXPORT Time: public PIVariantEditorBase {
Q_OBJECT
public:
Time() {
widget = new QTimeEdit();
widget->setDisplayFormat("h:mm:ss");
layout()->addWidget(widget);
}
void setValue(const PIVariant & v) override { widget->setTime(PI2QTime(v.toTime())); }
PIVariant value() const override { return Q2PITime(widget->time()); }
PIVariantMap attributes() const override { return {}; }
private:
void applyAttributes(const PIVariantMap & a) override;
QTimeEdit * widget;
};
class QAD_PIQT_UTILS_EXPORT Date: public PIVariantEditorBase {
Q_OBJECT
public:
Date() {
widget = new QDateEdit();
widget->setDisplayFormat("d.MM.yyyy");
layout()->addWidget(widget);
}
void setValue(const PIVariant & v) override { widget->setDate(PI2QDate(v.toDate())); }
PIVariant value() const override { return Q2PIDate(widget->date()); }
PIVariantMap attributes() const override { return {}; }
private:
void applyAttributes(const PIVariantMap & a) override;
QDateEdit * widget;
};
class QAD_PIQT_UTILS_EXPORT DateTime: public PIVariantEditorBase {
Q_OBJECT
public:
DateTime() {
widget = new QDateTimeEdit();
widget->setDisplayFormat("d.MM.yyyy h:mm:ss");
layout()->addWidget(widget);
}
void setValue(const PIVariant & v) override { widget->setDateTime(PI2QDateTime(v.toDateTime())); }
PIVariant value() const override { return Q2PIDateTime(widget->dateTime()); }
PIVariantMap attributes() const override { return {}; }
private:
void applyAttributes(const PIVariantMap & a) override;
QDateTimeEdit * widget;
};
class QAD_PIQT_UTILS_EXPORT Enum: public PIVariantEditorBase {
Q_OBJECT
public:
Enum();
void setValue(const PIVariant & v) override;
PIVariant value() const override;
PIVariantMap attributes() const override { return {}; }
private:
void applyAttributes(const PIVariantMap & a) override;
void setFullEditMode(bool on) override;
mutable PIVariantTypes::Enum src;
QComboBox * widget;
QWidget * edit_widget;
};
class QAD_PIQT_UTILS_EXPORT NetworkAddress: public PIVariantEditorBase {
Q_OBJECT
public:
NetworkAddress();
void setValue(const PIVariant & v) override;
PIVariant value() const override;
PIVariantMap attributes() const override;
static PIVariantMap defaultAttributes();
private:
void applyAttributes(const PIVariantMap & a) override;
QLineEdit * widget;
bool has_port = true;
};
class QAD_PIQT_UTILS_EXPORT FileBase: public PIVariantEditorBase {
Q_OBJECT
public:
FileBase();
PIVariantMap attributes() const override;
static PIVariantMap defaultAttributes();
protected:
void applyAttributes(const PIVariantMap & a) override;
void setFullEditMode(bool on) override;
void createMenu();
CLineEdit * widget;
QWidget * sel_widget;
QWidget * edit_widget;
QMenu edit_menu;
QAction *act_abs = nullptr, *act_save = nullptr;
bool is_dir = false, is_abs = false, is_save = false;
PIString filter;
};
class QAD_PIQT_UTILS_EXPORT File: public FileBase {
Q_OBJECT
public:
File(): FileBase() {
is_dir = false;
createMenu();
}
void setValue(const PIVariant & v) override;
PIVariant value() const override;
};
class QAD_PIQT_UTILS_EXPORT Dir: public FileBase {
Q_OBJECT
public:
Dir(): FileBase() {
is_dir = true;
createMenu();
}
void setValue(const PIVariant & v) override;
PIVariant value() const override;
};
}; // namespace PIVariantEditors
#endif

View File

@@ -0,0 +1,16 @@
<RCC>
<qresource prefix="/">
<file>../../icons/configure.png</file>
<file>../../icons/border-line.png</file>
<file>../../icons/list-add.png</file>
<file>../../icons/list-remove.png</file>
<file>../../icons/code-variable.png</file>
<file>../../icons/code-struct.png</file>
<file>../../icons/code-union.png</file>
<file>../../icons/legend.png</file>
<file>../../icons/document-open.png</file>
<file>../../icons/document-edit.png</file>
<file>../../icons/layer-visible-off.png</file>
<file>../../icons/layer-visible-on.png</file>
</qresource>
</RCC>