PIVariantEdit ready but widgets fullEditMode
This commit is contained in:
@@ -2,15 +2,16 @@
|
|||||||
|
|
||||||
#include "piqt.h"
|
#include "piqt.h"
|
||||||
#include "pivaluetree_edit_parameters.h"
|
#include "pivaluetree_edit_parameters.h"
|
||||||
|
#include "pivaluetree_edit_reorder.h"
|
||||||
#include "pivariant_edit.h"
|
#include "pivariant_edit.h"
|
||||||
#include "qinputdialog.h"
|
|
||||||
#include "qmessagebox.h"
|
|
||||||
#include "qtoolbutton.h"
|
|
||||||
#include "ui_pivaluetree_edit_array.h"
|
#include "ui_pivaluetree_edit_array.h"
|
||||||
|
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QToolButton>
|
||||||
|
|
||||||
using Attribute = PIValueTree::Attribute;
|
using Attribute = PIValueTree::Attribute;
|
||||||
|
|
||||||
@@ -18,10 +19,11 @@ const char property_name[] = "__name__";
|
|||||||
|
|
||||||
|
|
||||||
PIValueTreeEdit::PIValueTreeEdit(QWidget * parent): QWidget(parent) {
|
PIValueTreeEdit::PIValueTreeEdit(QWidget * parent): QWidget(parent) {
|
||||||
widget_params = new PIValueTreeEditParameters();
|
widget_params = new PIValueTreeEditParameters();
|
||||||
ui_array = new Ui::PIValueTreeEditArray();
|
widget_reorder = new PIValueTreeEditReorder();
|
||||||
grid = new GridWidgets(this);
|
ui_array = new Ui::PIValueTreeEditArray();
|
||||||
auto * lay = new QBoxLayout(QBoxLayout::TopToBottom);
|
grid = new GridWidgets(this);
|
||||||
|
auto * lay = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||||
lay->setContentsMargins(0, 0, 0, 0);
|
lay->setContentsMargins(0, 0, 0, 0);
|
||||||
setLayout(lay);
|
setLayout(lay);
|
||||||
}
|
}
|
||||||
@@ -81,6 +83,7 @@ void PIValueTreeEdit::removeAll() {
|
|||||||
array_edits.clear();
|
array_edits.clear();
|
||||||
value_edits.clear();
|
value_edits.clear();
|
||||||
tree_edits.clear();
|
tree_edits.clear();
|
||||||
|
comm_labels.clear();
|
||||||
if (widget_array) {
|
if (widget_array) {
|
||||||
ui_array->layoutArray->removeWidget(grid);
|
ui_array->layoutArray->removeWidget(grid);
|
||||||
grid->hide();
|
grid->hide();
|
||||||
@@ -89,7 +92,7 @@ void PIValueTreeEdit::removeAll() {
|
|||||||
widget_array = nullptr;
|
widget_array = nullptr;
|
||||||
}
|
}
|
||||||
QLayoutItem * child = nullptr;
|
QLayoutItem * child = nullptr;
|
||||||
while ((child = layout()->takeAt(0)) != nullptr) {
|
while ((child = layout()->takeAt(0))) {
|
||||||
delete child;
|
delete child;
|
||||||
}
|
}
|
||||||
grid->clear();
|
grid->clear();
|
||||||
@@ -196,12 +199,17 @@ void PIValueTreeEdit::actionTriggered(QToolButton * button, const PIString & vn,
|
|||||||
tree_edits[nn] = tree_edits[vn];
|
tree_edits[nn] = tree_edits[vn];
|
||||||
tree_edits.remove(vn);
|
tree_edits.remove(vn);
|
||||||
}
|
}
|
||||||
|
if (comm_labels.contains(vn)) {
|
||||||
|
comm_labels[nn] = comm_labels[vn];
|
||||||
|
comm_labels.remove(vn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (a == widget_params->actionRemove) {
|
if (a == widget_params->actionRemove) {
|
||||||
source.remove(vn);
|
source.remove(vn);
|
||||||
grid->removeRow(grid->getRow(button));
|
grid->removeRow(grid->getRow(button));
|
||||||
value_edits.remove(vn);
|
value_edits.remove(vn);
|
||||||
tree_edits.remove(vn);
|
tree_edits.remove(vn);
|
||||||
|
comm_labels.remove(vn);
|
||||||
}
|
}
|
||||||
if (a == widget_params->actionChange) {
|
if (a == widget_params->actionChange) {
|
||||||
auto & vt(source[vn]);
|
auto & vt(source[vn]);
|
||||||
@@ -220,6 +228,19 @@ void PIValueTreeEdit::actionTriggered(QToolButton * button, const PIString & vn,
|
|||||||
ve->setAttributes(vt.attributes());
|
ve->setAttributes(vt.attributes());
|
||||||
ve->setValue(vt.value());
|
ve->setValue(vt.value());
|
||||||
}
|
}
|
||||||
|
auto * cl = comm_labels.value(vn, nullptr);
|
||||||
|
if (cl) cl->setText(PI2QString(vt.comment()));
|
||||||
|
}
|
||||||
|
if (a == widget_params->actionReorder) {
|
||||||
|
if (!widget_reorder->showFor(source)) return;
|
||||||
|
grid->reorder(widget_reorder->map);
|
||||||
|
auto cl = source.children();
|
||||||
|
source.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;
|
||||||
|
source.addChild(cl[mi]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,10 +325,20 @@ void PIValueTreeEdit::newRequest(NewType type) {
|
|||||||
// PIValueTreeEdit::GridWidgets
|
// PIValueTreeEdit::GridWidgets
|
||||||
|
|
||||||
PIValueTreeEdit::GridWidgets::GridWidgets(PIValueTreeEdit * p) {
|
PIValueTreeEdit::GridWidgets::GridWidgets(PIValueTreeEdit * p) {
|
||||||
parent = p;
|
parent = p;
|
||||||
icon_conf = QIcon(":/icons/configure.png");
|
icon_conf = QIcon(":/icons/configure.png");
|
||||||
menu_group.addActions({p->widget_params->actionRename, p->widget_params->actionRemove});
|
auto newSeparator = []() {
|
||||||
menu_conf.addActions({p->widget_params->actionRename, p->widget_params->actionChange, p->widget_params->actionRemove});
|
auto * a = new QAction();
|
||||||
|
a->setSeparator(true);
|
||||||
|
return a;
|
||||||
|
};
|
||||||
|
menu_group.addActions(
|
||||||
|
{p->widget_params->actionRename, p->widget_params->actionReorder, 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});
|
menu_new.addActions({p->widget_params->actionValue, p->widget_params->actionGroup, p->widget_params->actionArray});
|
||||||
button_add = new QToolButton();
|
button_add = new QToolButton();
|
||||||
button_add->setIcon(QIcon(":/icons/list-add.png"));
|
button_add->setIcon(QIcon(":/icons/list-add.png"));
|
||||||
@@ -351,6 +382,7 @@ void PIValueTreeEdit::GridWidgets::add(const PIValueTree & vt, QString label, QW
|
|||||||
lay->addWidget(c, row_count, col++, Qt::AlignVCenter | Qt::AlignLeft);
|
lay->addWidget(c, row_count, col++, Qt::AlignVCenter | Qt::AlignLeft);
|
||||||
widgets << l << w << c;
|
widgets << l << w << c;
|
||||||
labels << l;
|
labels << l;
|
||||||
|
parent->comm_labels[vt.name()] = c;
|
||||||
++row_count;
|
++row_count;
|
||||||
changed();
|
changed();
|
||||||
}
|
}
|
||||||
@@ -420,6 +452,7 @@ void PIValueTreeEdit::GridWidgets::changed() {
|
|||||||
if (!create_edit_buttons || !lay) return;
|
if (!create_edit_buttons || !lay) return;
|
||||||
lay->addWidget(button_add, row_count, 0);
|
lay->addWidget(button_add, row_count, 0);
|
||||||
button_add->show();
|
button_add->show();
|
||||||
|
adjustSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -444,7 +477,7 @@ void PIValueTreeEdit::GridWidgets::removeRow(int index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIValueTreeEdit::GridWidgets::simplify() {
|
void PIValueTreeEdit::GridWidgets::simplify(const PIMap<int, int> & map) {
|
||||||
if (!lay) return;
|
if (!lay) return;
|
||||||
QVector<QMap<int, QWidget *>> wg;
|
QVector<QMap<int, QWidget *>> wg;
|
||||||
QMap<QWidget *, Qt::Alignment> wa;
|
QMap<QWidget *, Qt::Alignment> wa;
|
||||||
@@ -464,8 +497,10 @@ void PIValueTreeEdit::GridWidgets::simplify() {
|
|||||||
lay = new QGridLayout();
|
lay = new QGridLayout();
|
||||||
lay->setContentsMargins(0, 0, 0, 0);
|
lay->setContentsMargins(0, 0, 0, 0);
|
||||||
int rindex = 0;
|
int rindex = 0;
|
||||||
for (const auto & row: wg) {
|
for (int i = 0; i < wg.size(); ++i) {
|
||||||
QMapIterator<int, QWidget *> it(row);
|
int mi = map.value(i, i);
|
||||||
|
if (mi < 0 || mi >= wg.size()) continue;
|
||||||
|
QMapIterator<int, QWidget *> it(wg[mi]);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
lay->addWidget(it.value(), rindex, it.key(), wa.value(it.value()));
|
lay->addWidget(it.value(), rindex, it.key(), wa.value(it.value()));
|
||||||
@@ -473,4 +508,5 @@ void PIValueTreeEdit::GridWidgets::simplify() {
|
|||||||
++rindex;
|
++rindex;
|
||||||
}
|
}
|
||||||
setLayout(lay);
|
setLayout(lay);
|
||||||
|
adjustSize();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class QGridLayout;
|
|||||||
class QToolButton;
|
class QToolButton;
|
||||||
class PIVariantEdit;
|
class PIVariantEdit;
|
||||||
class PIValueTreeEditParameters;
|
class PIValueTreeEditParameters;
|
||||||
|
class PIValueTreeEditReorder;
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class PIValueTreeEditArray;
|
class PIValueTreeEditArray;
|
||||||
}
|
}
|
||||||
@@ -87,6 +88,7 @@ private:
|
|||||||
void add(const PIValueTree & vt, QWidget * w, bool is_group = false);
|
void add(const PIValueTree & vt, QWidget * w, bool is_group = false);
|
||||||
int beginRow(const PIValueTree & vt, bool is_group);
|
int beginRow(const PIValueTree & vt, bool is_group);
|
||||||
void rename(QString prev_name, QString new_name);
|
void rename(QString prev_name, QString new_name);
|
||||||
|
void reorder(const PIMap<int, int> & map) { simplify(map); }
|
||||||
void clear();
|
void clear();
|
||||||
void changed();
|
void changed();
|
||||||
|
|
||||||
@@ -94,7 +96,7 @@ private:
|
|||||||
QToolButton * button_add;
|
QToolButton * button_add;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void simplify();
|
void simplify(const PIMap<int, int> & map = PIMap<int, int>());
|
||||||
|
|
||||||
int row_count = 0;
|
int row_count = 0;
|
||||||
QGridLayout * lay = nullptr;
|
QGridLayout * lay = nullptr;
|
||||||
@@ -107,10 +109,12 @@ private:
|
|||||||
|
|
||||||
QWidget * widget_array = nullptr;
|
QWidget * widget_array = nullptr;
|
||||||
PIValueTreeEditParameters * widget_params;
|
PIValueTreeEditParameters * widget_params;
|
||||||
|
PIValueTreeEditReorder * widget_reorder;
|
||||||
PIStringList root_path;
|
PIStringList root_path;
|
||||||
PIVector<PIVariantEdit *> array_edits;
|
PIVector<PIVariantEdit *> array_edits;
|
||||||
PIMap<PIString, PIVariantEdit *> value_edits;
|
PIMap<PIString, PIVariantEdit *> value_edits;
|
||||||
PIMap<PIString, PIValueTreeEdit *> tree_edits;
|
PIMap<PIString, PIValueTreeEdit *> tree_edits;
|
||||||
|
PIMap<PIString, QLabel *> comm_labels;
|
||||||
Ui::PIValueTreeEditArray * ui_array;
|
Ui::PIValueTreeEditArray * ui_array;
|
||||||
GridWidgets * grid = nullptr;
|
GridWidgets * grid = nullptr;
|
||||||
mutable PIValueTree source;
|
mutable PIValueTree source;
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ bool PIValueTreeEditParameters::showFor(PIValueTree & vt) {
|
|||||||
checkHidden->setChecked(vt.attribute(Attribute::hidden, false).toBool());
|
checkHidden->setChecked(vt.attribute(Attribute::hidden, false).toBool());
|
||||||
checkReadOnly->setChecked(vt.attribute(Attribute::readOnly, false).toBool());
|
checkReadOnly->setChecked(vt.attribute(Attribute::readOnly, false).toBool());
|
||||||
checkLabel->setChecked(vt.attribute(Attribute::isLabel, false).toBool());
|
checkLabel->setChecked(vt.attribute(Attribute::isLabel, false).toBool());
|
||||||
|
lineComment->setText(PI2QString(vt.comment()));
|
||||||
createAttributes(ve_attr, layoutAttributes, vt.attributes());
|
createAttributes(ve_attr, layoutAttributes, vt.attributes());
|
||||||
|
|
||||||
if (exec() != QDialog::Accepted) return false;
|
if (exec() != QDialog::Accepted) return false;
|
||||||
@@ -76,6 +77,7 @@ bool PIValueTreeEditParameters::showFor(PIValueTree & vt) {
|
|||||||
vt.setValue(var);
|
vt.setValue(var);
|
||||||
}
|
}
|
||||||
applyAttributes(vt);
|
applyAttributes(vt);
|
||||||
|
vt.setComment(Q2PIString(lineComment->text()));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,10 @@
|
|||||||
#define pivaluetree_edit_parameters_H
|
#define pivaluetree_edit_parameters_H
|
||||||
|
|
||||||
#include "pivaluetree.h"
|
#include "pivaluetree.h"
|
||||||
#include "qformlayout.h"
|
|
||||||
#include "ui_pivaluetree_edit_parameters.h"
|
#include "ui_pivaluetree_edit_parameters.h"
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QFormLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
|
||||||
class PIVariantEdit;
|
class PIVariantEdit;
|
||||||
|
|||||||
@@ -47,6 +47,16 @@
|
|||||||
<item row="3" column="1">
|
<item row="3" column="1">
|
||||||
<widget class="EComboBox" name="comboType"/>
|
<widget class="EComboBox" name="comboType"/>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@@ -148,8 +158,22 @@
|
|||||||
<string>Array</string>
|
<string>Array</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</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>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>CLineEdit</class>
|
||||||
|
<extends>QLineEdit</extends>
|
||||||
|
<header>clineedit.h</header>
|
||||||
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>EComboBox</class>
|
<class>EComboBox</class>
|
||||||
<extends>QComboBox</extends>
|
<extends>QComboBox</extends>
|
||||||
|
|||||||
30
libs/piqt_widgets/pivaluetree_edit_reorder.cpp
Normal file
30
libs/piqt_widgets/pivaluetree_edit_reorder.cpp
Normal 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;
|
||||||
|
}
|
||||||
47
libs/piqt_widgets/pivaluetree_edit_reorder.h
Normal file
47
libs/piqt_widgets/pivaluetree_edit_reorder.h
Normal 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
|
||||||
152
libs/piqt_widgets/pivaluetree_edit_reorder.ui
Normal file
152
libs/piqt_widgets/pivaluetree_edit_reorder.ui
Normal 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>
|
||||||
@@ -6,5 +6,6 @@
|
|||||||
<file>../../icons/code-variable.png</file>
|
<file>../../icons/code-variable.png</file>
|
||||||
<file>../../icons/code-struct.png</file>
|
<file>../../icons/code-struct.png</file>
|
||||||
<file>../../icons/code-union.png</file>
|
<file>../../icons/code-union.png</file>
|
||||||
|
<file>../../icons/legend.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|||||||
@@ -1,34 +1,100 @@
|
|||||||
#include <QApplication>
|
#include "pifile.h"
|
||||||
#include "piqt_connection_edit.h"
|
#include "pijson.h"
|
||||||
#include <QFileDialog>
|
#include "piqt_connection_edit.h"
|
||||||
#include <qpiconfig.h>
|
#include "pivaluetree_conversions.h"
|
||||||
#include <qad_types.h>
|
#include "pivaluetree_edit.h"
|
||||||
#include <evalspinbox.h>
|
|
||||||
#include <piintrospection_server.h>
|
#include <QApplication>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QScrollArea>
|
||||||
int main(int argc, char * argv[]) {
|
#include <QTimer>
|
||||||
PIINTROSPECTION_START(piconnedit)
|
#include <evalspinbox.h>
|
||||||
QApplication a(argc, argv);
|
#include <piintrospection_server.h>
|
||||||
enableHighDPI();
|
#include <qad_types.h>
|
||||||
ConnectionEdit w;
|
#include <qpiconfig.h>
|
||||||
if (a.arguments().size() > 1) {
|
|
||||||
QPIConfig cfg(a.arguments()[1]);
|
int main(int argc, char * argv[]) {
|
||||||
QByteArray model = cfg.getValue("connectionmodel").toByteArray();
|
QApplication a(argc, argv);
|
||||||
if (!model.isEmpty()) w.setModel(model);
|
|
||||||
} else
|
PIValueTree root, group, array;
|
||||||
w.recreateConnection();
|
root.addChild({"bool", false});
|
||||||
if (w.exec() == QDialog::Accepted) {
|
root.addChild({
|
||||||
QString c = QFileDialog::getSaveFileName(&w, "Save config to file", a.applicationDirPath(), "*.conf");
|
"integer",
|
||||||
if (!c.isEmpty()) {
|
256,
|
||||||
QFile f(c);
|
{{PIValueTree::Attribute::minimum, -100}, {PIValueTree::Attribute::maximum, 200}, {PIValueTree::Attribute::singleStep, 5}}
|
||||||
if (f.open(QIODevice::WriteOnly)) {
|
});
|
||||||
QTextStream ts(&f);
|
root.addChild({"Label here", PIVariant(), {{PIValueTree::Attribute::isLabel, true}}});
|
||||||
ts << w.configuration();
|
root.addChild({"string", "str"});
|
||||||
ts << "connectionmodel = " << QByteArray2QString(w.model()) << "\n";
|
group.addChild({"substr", "str2"});
|
||||||
f.close();
|
group.addChild({"real", 12.3});
|
||||||
}
|
group.setName("group");
|
||||||
}
|
array.setAttribute(PIValueTree::Attribute::arrayType, "string");
|
||||||
}
|
array.setAttribute(PIValueTree::Attribute::arrayResize, true);
|
||||||
return 0;
|
array.setAttribute(PIValueTree::Attribute::arrayMinCount, 0);
|
||||||
}
|
array.setAttribute(PIValueTree::Attribute::arrayMaxCount, 10);
|
||||||
|
array.setName("array");
|
||||||
|
array.addChild({"0", "1E+2"});
|
||||||
|
array.addChild({"1", -5});
|
||||||
|
array.addChild({"3", 0.1});
|
||||||
|
root.addChild(group);
|
||||||
|
root.addChild(array);
|
||||||
|
PIString json = PIValueTreeConversions::toJSON(root).toJSON(PIJSON::Tree);
|
||||||
|
// piCout << PIValueTreeConversions::fromJSON(PIJSON::fromJSON(json));
|
||||||
|
|
||||||
|
PIFile f("C:/work/config.conf", PIIODevice::ReadOnly);
|
||||||
|
auto vt = PIValueTreeConversions::fromText(&f);
|
||||||
|
PIVariantTypes::Enum en;
|
||||||
|
en << "first"
|
||||||
|
<< "second";
|
||||||
|
en << PIVariantTypes::Enumerator(10, "TEN");
|
||||||
|
en.selectValue(1);
|
||||||
|
vt.addChild({"Enum", en});
|
||||||
|
// piCout << PIValueTreeConversions::toText(vt);
|
||||||
|
|
||||||
|
QScrollArea area;
|
||||||
|
area.setWidgetResizable(true);
|
||||||
|
PIValueTreeEdit e;
|
||||||
|
e.setGroupingEnabled(false);
|
||||||
|
e.setFullEditMode(true);
|
||||||
|
e.setGeometry(500, 400, 100, 50);
|
||||||
|
// e.setValue(PIValueTreeConversions::fromJSON(PIJSON::fromJSON(PIValueTreeConversions::toJSON(vt).toJSON())));
|
||||||
|
e.setValue(vt);
|
||||||
|
area.setWidget(&e);
|
||||||
|
area.show();
|
||||||
|
// piCout << PIValueTreeConversions::toText(e.value()); //.toJSON(PIJSON::Tree);
|
||||||
|
|
||||||
|
QTimer timer;
|
||||||
|
QObject::connect(&timer, &QTimer::timeout, [&]() { e.rollback(); });
|
||||||
|
// timer.start(5);
|
||||||
|
// QTimer::singleShot(1000, [&e](){e.setValue(50);});
|
||||||
|
// QTimer::singleShot(2000, [&e, vt]() {
|
||||||
|
// e.setValue(PIValueTreeConversions::fromText(PIValueTreeConversions::toText(vt) + "\n[]\nAHAHA = 123\n"));
|
||||||
|
//});
|
||||||
|
// QTimer::singleShot(3000, [&e]() { e.setFullEditMode(false); });
|
||||||
|
return a.exec();
|
||||||
|
|
||||||
|
/*
|
||||||
|
PIINTROSPECTION_START(piconnedit)
|
||||||
|
QApplication a(argc, argv);
|
||||||
|
enableHighDPI();
|
||||||
|
ConnectionEdit w;
|
||||||
|
if (a.arguments().size() > 1) {
|
||||||
|
QPIConfig cfg(a.arguments()[1]);
|
||||||
|
QByteArray model = cfg.getValue("connectionmodel").toByteArray();
|
||||||
|
if (!model.isEmpty()) w.setModel(model);
|
||||||
|
} else
|
||||||
|
w.recreateConnection();
|
||||||
|
if (w.exec() == QDialog::Accepted) {
|
||||||
|
QString c = QFileDialog::getSaveFileName(&w, "Save config to file", a.applicationDirPath(), "*.conf");
|
||||||
|
if (!c.isEmpty()) {
|
||||||
|
QFile f(c);
|
||||||
|
if (f.open(QIODevice::WriteOnly)) {
|
||||||
|
QTextStream ts(&f);
|
||||||
|
ts << w.configuration();
|
||||||
|
ts << "connectionmodel = " << QByteArray2QString(w.model()) << "\n";
|
||||||
|
f.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;*/
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user