PIValueTreeEdit arrays fix, support for array comment (only from source now)
This commit is contained in:
@@ -4,7 +4,7 @@ cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default
|
|||||||
project(QAD)
|
project(QAD)
|
||||||
set(QAD_MAJOR 2)
|
set(QAD_MAJOR 2)
|
||||||
set(QAD_MINOR 16)
|
set(QAD_MINOR 16)
|
||||||
set(QAD_REVISION 1)
|
set(QAD_REVISION 2)
|
||||||
set(QAD_SUFFIX )
|
set(QAD_SUFFIX )
|
||||||
set(QAD_COMPANY SHS)
|
set(QAD_COMPANY SHS)
|
||||||
set(QAD_DOMAIN org.SHS)
|
set(QAD_DOMAIN org.SHS)
|
||||||
|
|||||||
@@ -180,22 +180,11 @@ void PIValueTreeEdit::build() {
|
|||||||
auto * ve = new PIVariantEdit();
|
auto * ve = new PIVariantEdit();
|
||||||
ve->setAttributes(current.attributes());
|
ve->setAttributes(current.attributes());
|
||||||
ve->setValue(i.value(), array_type);
|
ve->setValue(i.value(), array_type);
|
||||||
grid->add(PIValueTree(), PIString::fromNumber(++index), ve, i.comment());
|
grid->add(PIValueTree({PIString::fromNumber(index), PIVariant()}), PIString::fromNumber(index + 1), ve, i.comment());
|
||||||
|
++index;
|
||||||
array_edits << ve;
|
array_edits << ve;
|
||||||
}
|
}
|
||||||
connect(ui_array->spinCount, QOverload<int>::of(&QSpinBox::valueChanged), widget_array, [this, array_type](int value) {
|
connect(ui_array->spinCount, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int) { PIValueTreeEdit::resizeArray(); });
|
||||||
value = piMaxi(value, 0);
|
|
||||||
for (int i = grid->rowCount() - 1; i >= value; --i)
|
|
||||||
grid->removeRow(i);
|
|
||||||
array_edits.resize(grid->rowCount());
|
|
||||||
for (int i = grid->rowCount(); i < value; ++i) {
|
|
||||||
auto * ve = new PIVariantEdit();
|
|
||||||
ve->setAttributes(current.attributes());
|
|
||||||
ve->setValue(PIVariant::fromType(array_type), array_type);
|
|
||||||
grid->add(PIValueTree(), PIString::fromNumber(i + 1), ve, "");
|
|
||||||
array_edits << ve;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
layout()->addWidget(widget_array);
|
layout()->addWidget(widget_array);
|
||||||
} else {
|
} else {
|
||||||
grid->create_edit_buttons = is_full_edit;
|
grid->create_edit_buttons = is_full_edit;
|
||||||
@@ -223,8 +212,12 @@ void PIValueTreeEdit::applyValues() const {
|
|||||||
if (current.isArray()) {
|
if (current.isArray()) {
|
||||||
if (array_edits.isNotEmpty()) current.mergeAttributes(array_edits[0]->attributes());
|
if (array_edits.isNotEmpty()) current.mergeAttributes(array_edits[0]->attributes());
|
||||||
current.clearChildren();
|
current.clearChildren();
|
||||||
for (int i = 0; i < array_edits.size_s(); ++i)
|
for (int i = 0; i < array_edits.size_s(); ++i) {
|
||||||
current.addChild({PIString::fromNumber(i), array_edits[i]->value()});
|
PIValueTree vt(PIString::fromNumber(i), array_edits[i]->value());
|
||||||
|
auto comm_lbl = comm_labels.value(vt.name());
|
||||||
|
if (comm_lbl) vt.setComment(Q2PIString(comm_lbl->text()));
|
||||||
|
current.addChild(vt);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
auto vit = value_edits.makeIterator();
|
auto vit = value_edits.makeIterator();
|
||||||
while (vit.next()) {
|
while (vit.next()) {
|
||||||
@@ -322,6 +315,7 @@ void PIValueTreeEdit::actionTriggered(QToolButton * button, const PIString & vn,
|
|||||||
vt = ve->value();
|
vt = ve->value();
|
||||||
if (!widget_params->showFor(vt)) return;
|
if (!widget_params->showFor(vt)) return;
|
||||||
ve->setValue(vt);
|
ve->setValue(vt);
|
||||||
|
ve->resizeArray();
|
||||||
// ve->applyArrayAttributes();
|
// ve->applyArrayAttributes();
|
||||||
} else {
|
} else {
|
||||||
bool was_label = vt.attribute(Attribute::isLabel, false).toBool();
|
bool was_label = vt.attribute(Attribute::isLabel, false).toBool();
|
||||||
@@ -465,6 +459,23 @@ void PIValueTreeEdit::createTabWidget() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIValueTreeEdit::resizeArray() {
|
||||||
|
if (!ui_array) return;
|
||||||
|
uint array_type = PIVariant::typeIDFromName(current.attribute(Attribute::arrayType).toString());
|
||||||
|
int value = piMaxi(ui_array->spinCount->value(), 0);
|
||||||
|
for (int i = grid->rowCount() - 1; i >= value; --i)
|
||||||
|
grid->removeRow(i);
|
||||||
|
array_edits.resize(grid->rowCount());
|
||||||
|
for (int i = grid->rowCount(); i < value; ++i) {
|
||||||
|
auto * ve = new PIVariantEdit();
|
||||||
|
ve->setAttributes(current.attributes());
|
||||||
|
ve->setValue(PIVariant::fromType(array_type), array_type);
|
||||||
|
grid->add(PIValueTree(), PIString::fromNumber(i + 1), ve, "");
|
||||||
|
array_edits << ve;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIValueTreeEdit::newRequest(NewType type) {
|
void PIValueTreeEdit::newRequest(NewType type) {
|
||||||
PIString nn;
|
PIString nn;
|
||||||
if (rootTreeEdit()->allowed_names && (type == NewType::Value)) {
|
if (rootTreeEdit()->allowed_names && (type == NewType::Value)) {
|
||||||
@@ -502,7 +513,7 @@ void PIValueTreeEdit::newRequest(NewType type) {
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case NewType::Value: addValueEdit(vt); break;
|
case NewType::Value: addValueEdit(vt); break;
|
||||||
case NewType::Group: addTreeEdit(vt); break;
|
case NewType::Group: addTreeEdit(vt); break;
|
||||||
case NewType::Array: addTreeEdit(vt); break;
|
case NewType::Array: addTreeEdit(vt)->resizeArray(); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ private:
|
|||||||
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();
|
void createTabWidget();
|
||||||
|
void resizeArray();
|
||||||
|
|
||||||
class GridWidgets: public QWidget {
|
class GridWidgets: public QWidget {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ MainWindow::~MainWindow() {
|
|||||||
void MainWindow::reset(bool) {
|
void MainWindow::reset(bool) {
|
||||||
widget->setValue(PIValueTree());
|
widget->setValue(PIValueTree());
|
||||||
setWindowTitle(tr("PIValueTree Editor"));
|
setWindowTitle(tr("PIValueTree Editor"));
|
||||||
|
file_name.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -50,6 +51,7 @@ bool MainWindow::load(const QString & path) {
|
|||||||
PIFile f(Q2PIString(path), PIIODevice::ReadOnly);
|
PIFile f(Q2PIString(path), PIIODevice::ReadOnly);
|
||||||
if (!f.isOpened()) return false;
|
if (!f.isOpened()) return false;
|
||||||
PIString ext = PIFile::FileInfo(f.path()).extension().toLowerCase();
|
PIString ext = PIFile::FileInfo(f.path()).extension().toLowerCase();
|
||||||
|
file_name = path;
|
||||||
PIValueTree v;
|
PIValueTree v;
|
||||||
if (ext == "conf" || ext == "ini")
|
if (ext == "conf" || ext == "ini")
|
||||||
v = PIValueTreeConversions::fromText(&f);
|
v = PIValueTreeConversions::fromText(&f);
|
||||||
@@ -67,6 +69,7 @@ bool MainWindow::save(const QString & path) {
|
|||||||
PIFile f(Q2PIString(path), PIIODevice::ReadWrite);
|
PIFile f(Q2PIString(path), PIIODevice::ReadWrite);
|
||||||
if (!f.isOpened()) return false;
|
if (!f.isOpened()) return false;
|
||||||
f.clear();
|
f.clear();
|
||||||
|
file_name = path;
|
||||||
PIString ext = PIFile::FileInfo(f.path()).extension().toLowerCase();
|
PIString ext = PIFile::FileInfo(f.path()).extension().toLowerCase();
|
||||||
auto v = widget->value();
|
auto v = widget->value();
|
||||||
if (ext == "conf" || ext == "ini")
|
if (ext == "conf" || ext == "ini")
|
||||||
|
|||||||
Reference in New Issue
Block a user