PIValueTreeEdit individual grouping feature
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QTabWidget>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
|
|
||||||
using Attribute = PIValueTree::Attribute;
|
using Attribute = PIValueTree::Attribute;
|
||||||
@@ -48,9 +49,17 @@ PIValueTree PIValueTreeEdit::value() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIValueTreeEdit::setGroupingEnabled(bool yes) {
|
void PIValueTreeEdit::setGrouping(Grouping g) {
|
||||||
applyValues();
|
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();
|
build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,6 +113,7 @@ void PIValueTreeEdit::removeAll() {
|
|||||||
tree_edits.clear();
|
tree_edits.clear();
|
||||||
comm_labels.clear();
|
comm_labels.clear();
|
||||||
label_labels.clear();
|
label_labels.clear();
|
||||||
|
tab_widget = nullptr;
|
||||||
if (widget_array) {
|
if (widget_array) {
|
||||||
ui_array->layoutArray->removeWidget(grid);
|
ui_array->layoutArray->removeWidget(grid);
|
||||||
grid->hide();
|
grid->hide();
|
||||||
@@ -193,6 +203,11 @@ void PIValueTreeEdit::applyValues() const {
|
|||||||
auto & c(current.child(tit.key()));
|
auto & c(current.child(tit.key()));
|
||||||
if (!c.isNull()) c = tit.value()->value();
|
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[nn]->setText(PIVariantEditorBase::vtTr(nn));
|
||||||
label_labels.remove(vn);
|
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) {
|
if (a == widget_params->actionRemove) {
|
||||||
current.remove(vn);
|
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));
|
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);
|
comm_labels.remove(vn);
|
||||||
label_labels.remove(vn);
|
label_labels.remove(vn);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (a == widget_params->actionChange) {
|
if (a == widget_params->actionChange) {
|
||||||
auto & vt(current[vn]);
|
auto & vt(current[vn]);
|
||||||
@@ -277,6 +321,7 @@ void PIValueTreeEdit::actionTriggered(QToolButton * button, const PIString & vn,
|
|||||||
}
|
}
|
||||||
auto * cl = comm_labels.value(vn, nullptr);
|
auto * cl = comm_labels.value(vn, nullptr);
|
||||||
if (cl) cl->setText(PIVariantEditorBase::vtTr(vt.comment()));
|
if (cl) cl->setText(PIVariantEditorBase::vtTr(vt.comment()));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (a == widget_params->actionReorder) {
|
if (a == widget_params->actionReorder) {
|
||||||
if (!widget_reorder->showFor(current)) return;
|
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;
|
if (mi < 0 || mi >= cl.size_s()) continue;
|
||||||
current.addChild(cl[mi]);
|
current.addChild(cl[mi]);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
setGrouping((Grouping)a->data().toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -296,11 +343,14 @@ PIValueTreeEdit * PIValueTreeEdit::addTreeEdit(const PIValueTree & vt) {
|
|||||||
auto * ve = new PIValueTreeEdit();
|
auto * ve = new PIValueTreeEdit();
|
||||||
PIStringList rp = root_path;
|
PIStringList rp = root_path;
|
||||||
rp << vt.name();
|
rp << vt.name();
|
||||||
ve->root_path = rp;
|
ve->root_path = rp;
|
||||||
ve->setGroupingEnabled(is_grouping);
|
ve->parent_tree = this;
|
||||||
|
ve->setGrouping((Grouping)vt.attribute(Attribute::grouping, Parent).toInt());
|
||||||
ve->setFullEditMode(is_full_edit);
|
ve->setFullEditMode(is_full_edit);
|
||||||
ve->setValue(vt);
|
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();
|
auto * gb = new QGroupBox();
|
||||||
gb->setLayout(new QBoxLayout(QBoxLayout::TopToBottom));
|
gb->setLayout(new QBoxLayout(QBoxLayout::TopToBottom));
|
||||||
gb->layout()->addWidget(ve);
|
gb->layout()->addWidget(ve);
|
||||||
@@ -312,8 +362,21 @@ PIValueTreeEdit * PIValueTreeEdit::addTreeEdit(const PIValueTree & vt) {
|
|||||||
gb->setProperty(property_name, PI2QString(vt.name()));
|
gb->setProperty(property_name, PI2QString(vt.name()));
|
||||||
connect(gb, &QGroupBox::toggled, ve, &QWidget::setVisible);
|
connect(gb, &QGroupBox::toggled, ve, &QWidget::setVisible);
|
||||||
grid->add(vt, gb, true);
|
grid->add(vt, gb, true);
|
||||||
} else {
|
} break;
|
||||||
grid->add(vt, vt.name(), ve, vt.comment(), true);
|
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;
|
tree_edits[vt.name()] = ve;
|
||||||
return 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) {
|
void PIValueTreeEdit::newRequest(NewType type) {
|
||||||
PIString nn = Q2PIString(QInputDialog::getText(nullptr, tr("New item"), tr("Input new name:")));
|
PIString nn = Q2PIString(QInputDialog::getText(nullptr, tr("New item"), tr("Input new name:")));
|
||||||
if (nn.isEmpty()) return;
|
if (nn.isEmpty()) return;
|
||||||
@@ -396,8 +466,11 @@ PIValueTreeEdit::GridWidgets::GridWidgets(PIValueTreeEdit * p) {
|
|||||||
a->setSeparator(true);
|
a->setSeparator(true);
|
||||||
return a;
|
return a;
|
||||||
};
|
};
|
||||||
menu_group.addActions(
|
menu_group.addActions({p->widget_params->actionRename,
|
||||||
{p->widget_params->actionRename, p->widget_params->actionReorder, newSeparator(), p->widget_params->actionRemove});
|
p->widget_params->actionReorder,
|
||||||
|
p->widget_params->menu_grouping.menuAction(),
|
||||||
|
newSeparator(),
|
||||||
|
p->widget_params->actionRemove});
|
||||||
menu_conf.addActions({p->widget_params->actionRename,
|
menu_conf.addActions({p->widget_params->actionRename,
|
||||||
p->widget_params->actionChange,
|
p->widget_params->actionChange,
|
||||||
p->widget_params->actionReorder,
|
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) {
|
void PIValueTreeEdit::GridWidgets::replace(int row, QWidget * w) {
|
||||||
int col = removeRowEdits(row);
|
int col = removeRowEdits(row);
|
||||||
lay->addWidget(w, row, col, 1, -1);
|
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) {
|
int PIValueTreeEdit::GridWidgets::beginRow(const PIValueTree & vt, bool is_group) {
|
||||||
if (!create_edit_buttons) return 0;
|
if (!create_edit_buttons) return 0;
|
||||||
auto * b = new QToolButton();
|
auto * b = createConfigButton(vt, is_group);
|
||||||
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);
|
|
||||||
lay->addWidget(b, row_count, 0);
|
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;
|
widgets << b;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIValueTreeEdit::GridWidgets::rename(const PIString & prev_name, const PIString & new_name) {
|
void PIValueTreeEdit::GridWidgets::rename(const PIString & prev_name, const PIString & new_name) {
|
||||||
if (parent->is_grouping) {
|
for (auto * w: widgets) {
|
||||||
for (auto * w: widgets) {
|
auto * gb = qobject_cast<QGroupBox *>(w);
|
||||||
auto * gb = qobject_cast<QGroupBox *>(w);
|
if (!gb) continue;
|
||||||
if (!gb) continue;
|
if (gb->property(property_name).toString() == PI2QString(prev_name)) {
|
||||||
if (gb->property(property_name).toString() == PI2QString(prev_name)) {
|
gb->setProperty(property_name, PI2QString(new_name));
|
||||||
gb->setProperty(property_name, PI2QString(new_name));
|
gb->setTitle(PIVariantEditorBase::vtTr(new_name));
|
||||||
gb->setTitle(PIVariantEditorBase::vtTr(new_name));
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto * l: labels)
|
for (auto * l: labels)
|
||||||
@@ -556,12 +641,10 @@ void PIValueTreeEdit::GridWidgets::changed() {
|
|||||||
|
|
||||||
|
|
||||||
void PIValueTreeEdit::GridWidgets::retranslate() {
|
void PIValueTreeEdit::GridWidgets::retranslate() {
|
||||||
if (parent->is_grouping) {
|
for (auto * w: widgets) {
|
||||||
for (auto * w: widgets) {
|
auto * gb = qobject_cast<QGroupBox *>(w);
|
||||||
auto * gb = qobject_cast<QGroupBox *>(w);
|
if (!gb) continue;
|
||||||
if (!gb) continue;
|
gb->setTitle(PIVariantEditorBase::vtTr(Q2PIString(gb->property(property_name).toString())));
|
||||||
gb->setTitle(PIVariantEditorBase::vtTr(Q2PIString(gb->property(property_name).toString())));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (auto * l: labels) {
|
for (auto * l: labels) {
|
||||||
QString nn = PIVariantEditorBase::vtTr(Q2PIString(l->property(property_name).toString()));
|
QString nn = PIVariantEditorBase::vtTr(Q2PIString(l->property(property_name).toString()));
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
class QGridLayout;
|
class QGridLayout;
|
||||||
class QToolButton;
|
class QToolButton;
|
||||||
|
class QTabWidget;
|
||||||
class PIVariantEdit;
|
class PIVariantEdit;
|
||||||
class PIValueTreeEditParameters;
|
class PIValueTreeEditParameters;
|
||||||
class PIValueTreeEditReorder;
|
class PIValueTreeEditReorder;
|
||||||
@@ -39,20 +40,24 @@ class PIValueTreeEditArray;
|
|||||||
|
|
||||||
class QAD_PIQT_UTILS_EXPORT PIValueTreeEdit: public QWidget {
|
class QAD_PIQT_UTILS_EXPORT PIValueTreeEdit: public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_ENUMS(Grouping)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PIValueTreeEdit(QWidget * parent = nullptr);
|
PIValueTreeEdit(QWidget * parent = nullptr);
|
||||||
~PIValueTreeEdit();
|
~PIValueTreeEdit();
|
||||||
|
|
||||||
enum TreeStyle {
|
enum Grouping {
|
||||||
Label
|
Indent,
|
||||||
|
Groups,
|
||||||
|
Tabs,
|
||||||
|
Parent = 0xFF
|
||||||
};
|
};
|
||||||
|
|
||||||
void setValue(const PIValueTree & v);
|
void setValue(const PIValueTree & v);
|
||||||
PIValueTree value() const;
|
PIValueTree value() const;
|
||||||
|
|
||||||
bool isGroupingEnabled() const { return is_grouping; }
|
Grouping grouping() const { return cur_grouping; }
|
||||||
void setGroupingEnabled(bool yes);
|
void setGrouping(Grouping g);
|
||||||
bool isFullEditMode() const { return is_full_edit; }
|
bool isFullEditMode() const { return is_full_edit; }
|
||||||
void setFullEditMode(bool yes);
|
void setFullEditMode(bool yes);
|
||||||
|
|
||||||
@@ -79,6 +84,7 @@ private:
|
|||||||
void applyArrayAttributes();
|
void applyArrayAttributes();
|
||||||
QLabel * newLabel(const PIValueTree & vt);
|
QLabel * newLabel(const PIValueTree & vt);
|
||||||
void applyVariantEdit(PIVariantEdit * ve, const PIValueTree & vt);
|
void applyVariantEdit(PIVariantEdit * ve, const PIValueTree & vt);
|
||||||
|
void createTabWidget();
|
||||||
|
|
||||||
class GridWidgets: public QWidget {
|
class GridWidgets: public QWidget {
|
||||||
public:
|
public:
|
||||||
@@ -89,11 +95,14 @@ private:
|
|||||||
void removeRow(int index);
|
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, const PIString & label, QWidget * w, const PIString & comment, bool is_group = false);
|
||||||
void add(const PIValueTree & vt, QWidget * w, 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, QWidget * w);
|
||||||
void replace(int row, const PIString & label, QWidget * w, const PIString & comment);
|
void replace(int row, const PIString & label, QWidget * w, const PIString & comment);
|
||||||
int beginRow(const PIValueTree & vt, bool is_group);
|
int beginRow(const PIValueTree & vt, bool is_group);
|
||||||
void rename(const PIString & prev_name, const PIString & new_name);
|
void rename(const PIString & prev_name, const PIString & new_name);
|
||||||
void reorder(const PIMap<int, int> & map) { simplify(map); }
|
void reorder(const PIMap<int, int> & map) { simplify(map); }
|
||||||
|
void simplify(const PIMap<int, int> & map = PIMap<int, int>());
|
||||||
void clear();
|
void clear();
|
||||||
void changed();
|
void changed();
|
||||||
void retranslate();
|
void retranslate();
|
||||||
@@ -103,7 +112,6 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
int removeRowEdits(int row);
|
int removeRowEdits(int row);
|
||||||
void simplify(const PIMap<int, int> & map = PIMap<int, int>());
|
|
||||||
|
|
||||||
int row_count = 0;
|
int row_count = 0;
|
||||||
QGridLayout * lay = nullptr;
|
QGridLayout * lay = nullptr;
|
||||||
@@ -114,7 +122,8 @@ private:
|
|||||||
QIcon icon_conf;
|
QIcon icon_conf;
|
||||||
};
|
};
|
||||||
|
|
||||||
QWidget * widget_array = nullptr;
|
QWidget * widget_array = nullptr;
|
||||||
|
PIValueTreeEdit * parent_tree = nullptr;
|
||||||
PIValueTreeEditParameters * widget_params;
|
PIValueTreeEditParameters * widget_params;
|
||||||
PIValueTreeEditReorder * widget_reorder;
|
PIValueTreeEditReorder * widget_reorder;
|
||||||
PIStringList root_path;
|
PIStringList root_path;
|
||||||
@@ -122,10 +131,12 @@ private:
|
|||||||
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, label_labels;
|
PIMap<PIString, QLabel *> comm_labels, label_labels;
|
||||||
|
QTabWidget * tab_widget = nullptr;
|
||||||
Ui::PIValueTreeEditArray * ui_array;
|
Ui::PIValueTreeEditArray * ui_array;
|
||||||
GridWidgets * grid = nullptr;
|
GridWidgets * grid = nullptr;
|
||||||
|
Grouping cur_grouping = Parent, real_grouping = Indent;
|
||||||
mutable PIValueTree source, current;
|
mutable PIValueTree source, current;
|
||||||
bool is_grouping = true, is_full_edit = false;
|
bool is_full_edit = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
#include "pivaluetree_edit_parameters.h"
|
#include "pivaluetree_edit_parameters.h"
|
||||||
|
|
||||||
#include "piqt.h"
|
#include "piqt.h"
|
||||||
|
#include "pivaluetree_edit.h"
|
||||||
#include "pivariant_edit.h"
|
#include "pivariant_edit.h"
|
||||||
|
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
|
#include <QMetaEnum>
|
||||||
|
|
||||||
using Attribute = PIValueTree::Attribute;
|
using Attribute = PIValueTree::Attribute;
|
||||||
|
|
||||||
@@ -13,6 +15,19 @@ const char property_name[] = "__name__";
|
|||||||
|
|
||||||
PIValueTreeEditParameters::PIValueTreeEditParameters(QWidget * parent): QDialog(parent) {
|
PIValueTreeEditParameters::PIValueTreeEditParameters(QWidget * parent): QDialog(parent) {
|
||||||
setupUi(this);
|
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"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
class PIVariantEdit;
|
class PIVariantEdit;
|
||||||
|
|
||||||
@@ -40,6 +41,8 @@ public:
|
|||||||
|
|
||||||
bool showFor(PIValueTree & vt);
|
bool showFor(PIValueTree & vt);
|
||||||
|
|
||||||
|
QMenu menu_grouping;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void
|
void
|
||||||
createAttributes(QList<PIVariantEdit *> & list, QFormLayout * lay, const PIVariantMap & attr = PIVariantMap(), bool inv_filter = false);
|
createAttributes(QList<PIVariantEdit *> & list, QFormLayout * lay, const PIVariantMap & attr = PIVariantMap(), bool inv_filter = false);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "pivariant_edit.h"
|
#include "pivariant_edit.h"
|
||||||
|
|
||||||
#include "piqt.h"
|
#include "piqt.h"
|
||||||
|
#include "pivaluetree_edit.h"
|
||||||
|
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
|
|
||||||
@@ -33,6 +34,15 @@ PIVariantMap PIVariantEditorBase::editorDefaultAttributes(uint 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) {
|
void PIVariantEditorBase::createBoxLayout(QBoxLayout::Direction d) {
|
||||||
auto * l = new QBoxLayout(d);
|
auto * l = new QBoxLayout(d);
|
||||||
l->setContentsMargins(0, 0, 0, 0);
|
l->setContentsMargins(0, 0, 0, 0);
|
||||||
@@ -58,12 +68,9 @@ PIMap<uint, PIVariantMap> & PIVariantEditorBase::default_attributes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIVariantEdit::PIVariantEdit(QWidget * parent): QWidget(parent) {
|
PIVariantEdit::PIVariantEdit(QWidget * parent): PIVariantEditorBase(parent) {
|
||||||
label = new QLabel();
|
label = new QLabel();
|
||||||
label->setAlignment(Qt::AlignCenter);
|
label->setAlignment(Qt::AlignCenter);
|
||||||
auto * l = new QBoxLayout(QBoxLayout::LeftToRight);
|
|
||||||
l->setContentsMargins(0, 0, 0, 0);
|
|
||||||
setLayout(l);
|
|
||||||
setValue(PIVariant());
|
setValue(PIVariant());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class QAD_PIQT_UTILS_EXPORT PIVariantEditorBase: public QWidget {
|
|||||||
friend class PIVariantEdit;
|
friend class PIVariantEdit;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PIVariantEditorBase() { createBoxLayout(); }
|
PIVariantEditorBase(QWidget * parent = nullptr): QWidget(parent) { createBoxLayout(); }
|
||||||
virtual ~PIVariantEditorBase() {}
|
virtual ~PIVariantEditorBase() {}
|
||||||
|
|
||||||
virtual void setValue(const PIVariant & v) = 0;
|
virtual void setValue(const PIVariant & v) = 0;
|
||||||
@@ -67,6 +67,7 @@ public:
|
|||||||
static PIVariantEditorBase * createEditor(uint type_id);
|
static PIVariantEditorBase * createEditor(uint type_id);
|
||||||
static bool editorExists(uint type_id);
|
static bool editorExists(uint type_id);
|
||||||
static PIVariantMap editorDefaultAttributes(uint type_id);
|
static PIVariantMap editorDefaultAttributes(uint type_id);
|
||||||
|
static PIVariantTypes::Enum createGrouping();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void createBoxLayout(QBoxLayout::Direction d = QBoxLayout::LeftToRight);
|
void createBoxLayout(QBoxLayout::Direction d = QBoxLayout::LeftToRight);
|
||||||
@@ -82,21 +83,22 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class QAD_PIQT_UTILS_EXPORT PIVariantEdit: public QWidget {
|
class QAD_PIQT_UTILS_EXPORT PIVariantEdit: public PIVariantEditorBase {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PIVariantEdit(QWidget * parent = nullptr);
|
PIVariantEdit(QWidget * parent = nullptr);
|
||||||
~PIVariantEdit();
|
~PIVariantEdit();
|
||||||
|
|
||||||
void setValue(const PIVariant & v, uint type_id = 0);
|
void setValue(const PIVariant & v, uint type_id);
|
||||||
PIVariant value() const;
|
void setValue(const PIVariant & v) override { setValue(v, v.typeID()); }
|
||||||
|
PIVariant value() const override;
|
||||||
|
|
||||||
void setAttributes(const PIVariantMap & a);
|
void setAttributes(const PIVariantMap & a);
|
||||||
PIVariantMap attributes() const;
|
PIVariantMap attributes() const override;
|
||||||
|
|
||||||
void setFullEditMode(bool on);
|
void setFullEditMode(bool on) override;
|
||||||
void retranslate();
|
void retranslate() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PIVariantEditorBase * editor = nullptr;
|
PIVariantEditorBase * editor = nullptr;
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
#include "piqt.h"
|
#include "piqt.h"
|
||||||
#include "qad_locations.h"
|
#include "qad_locations.h"
|
||||||
|
|
||||||
|
#include <QActionGroup>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QMetaEnum>
|
||||||
#include <pifile.h>
|
#include <pifile.h>
|
||||||
#include <pijson.h>
|
#include <pijson.h>
|
||||||
#include <pivaluetree.h>
|
#include <pivaluetree.h>
|
||||||
@@ -15,7 +17,19 @@ MainWindow::MainWindow(QWidget * parent): EMainWindow(parent), Ui::MainWindow()
|
|||||||
session.setFile(QAD::userPath(QAD::ltConfig, "session_valuetreeeditor"));
|
session.setFile(QAD::userPath(QAD::ltConfig, "session_valuetreeeditor"));
|
||||||
session.addEntry(this);
|
session.addEntry(this);
|
||||||
session.load();
|
session.load();
|
||||||
widget->setGroupingEnabled(actionGrouping->isChecked());
|
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) {
|
||||||
|
if (me.value(i) == PIValueTreeEdit::Parent) continue;
|
||||||
|
auto * a = ag->addAction(me.key(i));
|
||||||
|
a->setCheckable(true);
|
||||||
|
a->setData(me.value(i));
|
||||||
|
if (me.value(i) == PIValueTreeEdit::Indent) a->setChecked(true);
|
||||||
|
}
|
||||||
|
menuView->addActions(ag->actions());
|
||||||
widget->setFullEditMode(actionFull_edit_mode->isChecked());
|
widget->setFullEditMode(actionFull_edit_mode->isChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,11 +94,6 @@ QString MainWindow::loadFilter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_actionGrouping_toggled(bool on) {
|
|
||||||
widget->setGroupingEnabled(on);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_actionFull_edit_mode_toggled(bool on) {
|
void MainWindow::on_actionFull_edit_mode_toggled(bool on) {
|
||||||
widget->setFullEditMode(on);
|
widget->setFullEditMode(on);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,13 +19,12 @@ public:
|
|||||||
bool save(const QString & path) override;
|
bool save(const QString & path) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void changeEvent(QEvent * e);
|
void changeEvent(QEvent * e) override;
|
||||||
|
|
||||||
QString loadFilter() override;
|
QString loadFilter() override;
|
||||||
QString saveFilter() override { return loadFilter(); }
|
QString saveFilter() override { return loadFilter(); }
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_actionGrouping_toggled(bool on);
|
|
||||||
void on_actionFull_edit_mode_toggled(bool on);
|
void on_actionFull_edit_mode_toggled(bool on);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -44,13 +44,20 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>780</width>
|
<width>780</width>
|
||||||
<height>446</height>
|
<height>444</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="PIValueTreeEdit" name="widget" native="true"/>
|
<widget class="PIValueTreeEdit" name="widget" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
@@ -94,8 +101,8 @@
|
|||||||
<property name="title">
|
<property name="title">
|
||||||
<string>View</string>
|
<string>View</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionGrouping"/>
|
|
||||||
<addaction name="actionFull_edit_mode"/>
|
<addaction name="actionFull_edit_mode"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
</widget>
|
</widget>
|
||||||
<addaction name="menuFile"/>
|
<addaction name="menuFile"/>
|
||||||
<addaction name="menuView"/>
|
<addaction name="menuView"/>
|
||||||
@@ -138,7 +145,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionNew">
|
<action name="actionNew">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../libs/widgets/qad_widgets.qrc">
|
<iconset resource="../../libs/qglview/qglview.qrc">
|
||||||
<normaloff>:/icons/document-new.png</normaloff>:/icons/document-new.png</iconset>
|
<normaloff>:/icons/document-new.png</normaloff>:/icons/document-new.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@@ -157,14 +164,6 @@
|
|||||||
<string>About ...</string>
|
<string>About ...</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionGrouping">
|
|
||||||
<property name="checkable">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Grouping</string>
|
|
||||||
</property>
|
|
||||||
</action>
|
|
||||||
<action name="actionFull_edit_mode">
|
<action name="actionFull_edit_mode">
|
||||||
<property name="checkable">
|
<property name="checkable">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
@@ -189,6 +188,7 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<include location="../../../cd/utils/pult/cdpult.qrc"/>
|
<include location="../../../cd/utils/pult/cdpult.qrc"/>
|
||||||
<include location="../../libs/blockview/qad_blockview.qrc"/>
|
<include location="../../libs/blockview/qad_blockview.qrc"/>
|
||||||
|
<include location="../../libs/qglview/qglview.qrc"/>
|
||||||
<include location="../../libs/widgets/qad_widgets.qrc"/>
|
<include location="../../libs/widgets/qad_widgets.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
<connections>
|
<connections>
|
||||||
|
|||||||
Reference in New Issue
Block a user