PIVariantEdit ready but widgets fullEditMode
This commit is contained in:
@@ -2,15 +2,16 @@
|
||||
|
||||
#include "piqt.h"
|
||||
#include "pivaluetree_edit_parameters.h"
|
||||
#include "pivaluetree_edit_reorder.h"
|
||||
#include "pivariant_edit.h"
|
||||
#include "qinputdialog.h"
|
||||
#include "qmessagebox.h"
|
||||
#include "qtoolbutton.h"
|
||||
#include "ui_pivaluetree_edit_array.h"
|
||||
|
||||
#include <QEvent>
|
||||
#include <QFormLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QToolButton>
|
||||
|
||||
using Attribute = PIValueTree::Attribute;
|
||||
|
||||
@@ -18,10 +19,11 @@ const char property_name[] = "__name__";
|
||||
|
||||
|
||||
PIValueTreeEdit::PIValueTreeEdit(QWidget * parent): QWidget(parent) {
|
||||
widget_params = new PIValueTreeEditParameters();
|
||||
ui_array = new Ui::PIValueTreeEditArray();
|
||||
grid = new GridWidgets(this);
|
||||
auto * lay = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
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);
|
||||
}
|
||||
@@ -81,6 +83,7 @@ void PIValueTreeEdit::removeAll() {
|
||||
array_edits.clear();
|
||||
value_edits.clear();
|
||||
tree_edits.clear();
|
||||
comm_labels.clear();
|
||||
if (widget_array) {
|
||||
ui_array->layoutArray->removeWidget(grid);
|
||||
grid->hide();
|
||||
@@ -89,7 +92,7 @@ void PIValueTreeEdit::removeAll() {
|
||||
widget_array = nullptr;
|
||||
}
|
||||
QLayoutItem * child = nullptr;
|
||||
while ((child = layout()->takeAt(0)) != nullptr) {
|
||||
while ((child = layout()->takeAt(0))) {
|
||||
delete child;
|
||||
}
|
||||
grid->clear();
|
||||
@@ -196,12 +199,17 @@ void PIValueTreeEdit::actionTriggered(QToolButton * button, const PIString & 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 (a == widget_params->actionRemove) {
|
||||
source.remove(vn);
|
||||
grid->removeRow(grid->getRow(button));
|
||||
value_edits.remove(vn);
|
||||
tree_edits.remove(vn);
|
||||
comm_labels.remove(vn);
|
||||
}
|
||||
if (a == widget_params->actionChange) {
|
||||
auto & vt(source[vn]);
|
||||
@@ -220,6 +228,19 @@ void PIValueTreeEdit::actionTriggered(QToolButton * button, const PIString & vn,
|
||||
ve->setAttributes(vt.attributes());
|
||||
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::GridWidgets(PIValueTreeEdit * p) {
|
||||
parent = p;
|
||||
icon_conf = QIcon(":/icons/configure.png");
|
||||
menu_group.addActions({p->widget_params->actionRename, p->widget_params->actionRemove});
|
||||
menu_conf.addActions({p->widget_params->actionRename, p->widget_params->actionChange, p->widget_params->actionRemove});
|
||||
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, 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"));
|
||||
@@ -351,6 +382,7 @@ void PIValueTreeEdit::GridWidgets::add(const PIValueTree & vt, QString label, QW
|
||||
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();
|
||||
}
|
||||
@@ -420,6 +452,7 @@ void PIValueTreeEdit::GridWidgets::changed() {
|
||||
if (!create_edit_buttons || !lay) return;
|
||||
lay->addWidget(button_add, row_count, 0);
|
||||
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;
|
||||
QVector<QMap<int, QWidget *>> wg;
|
||||
QMap<QWidget *, Qt::Alignment> wa;
|
||||
@@ -464,8 +497,10 @@ void PIValueTreeEdit::GridWidgets::simplify() {
|
||||
lay = new QGridLayout();
|
||||
lay->setContentsMargins(0, 0, 0, 0);
|
||||
int rindex = 0;
|
||||
for (const auto & row: wg) {
|
||||
QMapIterator<int, QWidget *> it(row);
|
||||
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();
|
||||
lay->addWidget(it.value(), rindex, it.key(), wa.value(it.value()));
|
||||
@@ -473,4 +508,5 @@ void PIValueTreeEdit::GridWidgets::simplify() {
|
||||
++rindex;
|
||||
}
|
||||
setLayout(lay);
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user