PIValueTreeEdit individual grouping feature
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <QGroupBox>
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QTabWidget>
|
||||
#include <QToolButton>
|
||||
|
||||
using Attribute = PIValueTree::Attribute;
|
||||
@@ -48,9 +49,17 @@ PIValueTree PIValueTreeEdit::value() const {
|
||||
}
|
||||
|
||||
|
||||
void PIValueTreeEdit::setGroupingEnabled(bool yes) {
|
||||
void PIValueTreeEdit::setGrouping(Grouping g) {
|
||||
applyValues();
|
||||
is_grouping = yes;
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -104,6 +113,7 @@ void PIValueTreeEdit::removeAll() {
|
||||
tree_edits.clear();
|
||||
comm_labels.clear();
|
||||
label_labels.clear();
|
||||
tab_widget = nullptr;
|
||||
if (widget_array) {
|
||||
ui_array->layoutArray->removeWidget(grid);
|
||||
grid->hide();
|
||||
@@ -193,6 +203,11 @@ void PIValueTreeEdit::applyValues() const {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,14 +242,43 @@ void PIValueTreeEdit::actionTriggered(QToolButton * button, const PIString & 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]);
|
||||
@@ -277,6 +321,7 @@ void PIValueTreeEdit::actionTriggered(QToolButton * button, const PIString & vn,
|
||||
}
|
||||
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;
|
||||
@@ -288,7 +333,9 @@ void PIValueTreeEdit::actionTriggered(QToolButton * button, const PIString & vn,
|
||||
if (mi < 0 || mi >= cl.size_s()) continue;
|
||||
current.addChild(cl[mi]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
setGrouping((Grouping)a->data().toInt());
|
||||
}
|
||||
|
||||
|
||||
@@ -296,11 +343,14 @@ PIValueTreeEdit * PIValueTreeEdit::addTreeEdit(const PIValueTree & vt) {
|
||||
auto * ve = new PIValueTreeEdit();
|
||||
PIStringList rp = root_path;
|
||||
rp << vt.name();
|
||||
ve->root_path = rp;
|
||||
ve->setGroupingEnabled(is_grouping);
|
||||
ve->root_path = rp;
|
||||
ve->parent_tree = this;
|
||||
ve->setGrouping((Grouping)vt.attribute(Attribute::grouping, Parent).toInt());
|
||||
ve->setFullEditMode(is_full_edit);
|
||||
ve->setValue(vt);
|
||||
if (is_grouping) {
|
||||
switch (real_grouping) {
|
||||
case Indent: grid->add(vt, vt.name(), ve, vt.comment(), true); break;
|
||||
case Groups: {
|
||||
auto * gb = new QGroupBox();
|
||||
gb->setLayout(new QBoxLayout(QBoxLayout::TopToBottom));
|
||||
gb->layout()->addWidget(ve);
|
||||
@@ -312,8 +362,21 @@ PIValueTreeEdit * PIValueTreeEdit::addTreeEdit(const PIValueTree & vt) {
|
||||
gb->setProperty(property_name, PI2QString(vt.name()));
|
||||
connect(gb, &QGroupBox::toggled, ve, &QWidget::setVisible);
|
||||
grid->add(vt, gb, true);
|
||||
} else {
|
||||
grid->add(vt, vt.name(), ve, vt.comment(), 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;
|
||||
@@ -359,6 +422,13 @@ void PIValueTreeEdit::applyVariantEdit(PIVariantEdit * ve, const PIValueTree & v
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
@@ -396,8 +466,11 @@ PIValueTreeEdit::GridWidgets::GridWidgets(PIValueTreeEdit * p) {
|
||||
a->setSeparator(true);
|
||||
return a;
|
||||
};
|
||||
menu_group.addActions(
|
||||
{p->widget_params->actionRename, p->widget_params->actionReorder, newSeparator(), p->widget_params->actionRemove});
|
||||
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,
|
||||
@@ -468,6 +541,28 @@ void PIValueTreeEdit::GridWidgets::add(const PIValueTree & vt, QWidget * w, bool
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
@@ -497,31 +592,21 @@ void PIValueTreeEdit::GridWidgets::replace(int row, const PIString & label, QWid
|
||||
|
||||
int PIValueTreeEdit::GridWidgets::beginRow(const PIValueTree & vt, bool is_group) {
|
||||
if (!create_edit_buttons) return 0;
|
||||
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);
|
||||
auto * b = createConfigButton(vt, is_group);
|
||||
lay->addWidget(b, row_count, 0);
|
||||
connect(b, &QToolButton::triggered, this, [this, b](QAction * a) {
|
||||
parent->actionTriggered(b, Q2PIString(b->property(property_name).toString()), a);
|
||||
});
|
||||
widgets << b;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void PIValueTreeEdit::GridWidgets::rename(const PIString & prev_name, const PIString & new_name) {
|
||||
if (parent->is_grouping) {
|
||||
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 * 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)
|
||||
@@ -556,12 +641,10 @@ void PIValueTreeEdit::GridWidgets::changed() {
|
||||
|
||||
|
||||
void PIValueTreeEdit::GridWidgets::retranslate() {
|
||||
if (parent->is_grouping) {
|
||||
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 * 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()));
|
||||
|
||||
Reference in New Issue
Block a user