git-svn-id: svn://db.shs.com.ru/libs@475 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -28,7 +28,7 @@ pip_code_model(CCM "../pip/src_main/io_devices/piiodevice.h" "../pip/src_main/io
|
||||
find_qt(${QtVersions} Core Gui)
|
||||
qt_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM)
|
||||
qt_add_library(${PROJECT_NAME} ${LIBTYPE} out_CPP CCM)
|
||||
qt_target_link_libraries(${PROJECT_NAME} pip qad_utils qad_widgets qad_blockview)
|
||||
qt_target_link_libraries(${PROJECT_NAME} pip qad_utils qad_widgets qad_blockview piqt)
|
||||
message(STATUS "Building ${PROJECT_NAME}")
|
||||
|
||||
if (LIBPROJECT)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
namespace Ui {
|
||||
class ConnectionEdit;
|
||||
};
|
||||
}
|
||||
|
||||
class FilterItem;
|
||||
class DeviceItem;
|
||||
|
||||
75
piqt_utils/piqt_iodevice_edit.cpp
Normal file
75
piqt_utils/piqt_iodevice_edit.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "piqt_iodevice_edit.h"
|
||||
#include "piqt_iodevice_edit_dialog.h"
|
||||
#include "qvariantedit_custom.h"
|
||||
#include <QLineEdit>
|
||||
#include <QToolButton>
|
||||
#include <QBoxLayout>
|
||||
|
||||
|
||||
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());
|
||||
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->exec(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());
|
||||
}
|
||||
51
piqt_utils/piqt_iodevice_edit.h
Normal file
51
piqt_utils/piqt_iodevice_edit.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef PIQT_IODEVICE_EDIT_H
|
||||
#define PIQT_IODEVICE_EDIT_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "qad_types.h"
|
||||
|
||||
class QLineEdit;
|
||||
class QToolButton;
|
||||
class IODeviceEditDialog;
|
||||
|
||||
|
||||
class 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 __IODeviceEditRegistrator__ {
|
||||
public:
|
||||
__IODeviceEditRegistrator__();
|
||||
};
|
||||
|
||||
static __IODeviceEditRegistrator__ __iodeviceeditregistrator__;
|
||||
|
||||
#endif // PIQT_IODEVICE_EDIT_H
|
||||
103
piqt_utils/piqt_iodevice_edit_dialog.cpp
Normal file
103
piqt_utils/piqt_iodevice_edit_dialog.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#include "ui_piqt_iodevice_edit_dialog.h"
|
||||
#include "piqt_iodevice_edit_dialog.h"
|
||||
#include "piqt.h"
|
||||
#include "picodeinfo.h"
|
||||
#include "piiodevice.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)
|
||||
ui->comboMode->addItem(PI2QString(e.name + " (" + PIString::fromNumber(e.value) + ")"), QVariant::fromValue<int>(e.value));
|
||||
}
|
||||
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();
|
||||
cb->setText(PI2QString(e.name + " (" + PIString::fromNumber(e.value) + ")"));
|
||||
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());
|
||||
PIVector<const PIObject * > rd(PICollection::groupElements("__PIIODevices__"));
|
||||
piForeachC (PIObject * d, rd) {
|
||||
const PIIODevice * dev = ((const PIIODevice * )d);
|
||||
if (prefix != dev->fullPathPrefix())
|
||||
continue;
|
||||
ps = PI2QPropertyStorage(dev->constructVariant().get());
|
||||
ui->widgetProperties->setStorage(&ps);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QAD::IODevice IODeviceEditDialog::exec(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) {
|
||||
ui->comboType->setCurrentText(d.prefix);
|
||||
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);
|
||||
}
|
||||
34
piqt_utils/piqt_iodevice_edit_dialog.h
Normal file
34
piqt_utils/piqt_iodevice_edit_dialog.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef PIQT_IODEVICE_EDIT_DIALOG_H
|
||||
#define PIQT_IODEVICE_EDIT_DIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "qad_types.h"
|
||||
#include "propertystorage.h"
|
||||
|
||||
namespace Ui {
|
||||
class IODeviceEditDialog;
|
||||
}
|
||||
|
||||
class IODeviceEditDialog: public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit IODeviceEditDialog(QWidget * parent = 0);
|
||||
~IODeviceEditDialog();
|
||||
|
||||
QAD::IODevice exec(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
|
||||
138
piqt_utils/piqt_iodevice_edit_dialog.ui
Normal file
138
piqt_utils/piqt_iodevice_edit_dialog.ui
Normal 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>
|
||||
Reference in New Issue
Block a user