PIValueTreeEdit can translate content
This commit is contained in:
@@ -117,7 +117,7 @@ void PIValueTreeEdit::build() {
|
||||
auto * ve = new PIVariantEdit();
|
||||
ve->setAttributes(source.attributes());
|
||||
ve->setValue(i.value(), array_type);
|
||||
grid->add(PIValueTree(), QString::number(++index), ve, PI2QString(i.comment()));
|
||||
grid->add(PIValueTree(), PIString::fromNumber(++index), ve, i.comment());
|
||||
array_edits << ve;
|
||||
}
|
||||
connect(ui_array->spinCount, QOverload<int>::of(&QSpinBox::valueChanged), widget_array, [this, array_type](int value) {
|
||||
@@ -129,7 +129,7 @@ void PIValueTreeEdit::build() {
|
||||
auto * ve = new PIVariantEdit();
|
||||
ve->setAttributes(source.attributes());
|
||||
ve->setValue(PIVariant::fromType(array_type), array_type);
|
||||
grid->add(PIValueTree(), QString::number(i + 1), ve, "");
|
||||
grid->add(PIValueTree(), PIString::fromNumber(i + 1), ve, "");
|
||||
array_edits << ve;
|
||||
}
|
||||
});
|
||||
@@ -190,7 +190,7 @@ void PIValueTreeEdit::actionTriggered(QToolButton * button, const PIString & vn,
|
||||
}
|
||||
source[vn].setName(nn);
|
||||
button->setProperty(property_name, PI2QString(nn));
|
||||
grid->rename(PI2QString(vn), PI2QString(nn));
|
||||
grid->rename(vn, nn);
|
||||
if (value_edits.contains(vn)) {
|
||||
value_edits[nn] = value_edits[vn];
|
||||
value_edits.remove(vn);
|
||||
@@ -205,7 +205,7 @@ void PIValueTreeEdit::actionTriggered(QToolButton * button, const PIString & vn,
|
||||
}
|
||||
if (label_labels.contains(vn)) {
|
||||
label_labels[nn] = label_labels[vn];
|
||||
label_labels[nn]->setText(PI2QString(nn));
|
||||
label_labels[nn]->setText(PIVariantEditorBase::vtTr(nn));
|
||||
label_labels.remove(vn);
|
||||
}
|
||||
}
|
||||
@@ -241,7 +241,7 @@ void PIValueTreeEdit::actionTriggered(QToolButton * button, const PIString & vn,
|
||||
} else {
|
||||
auto * ve = new PIVariantEdit();
|
||||
applyVariantEdit(ve, vt);
|
||||
grid->replace(grid->getRow(button), PI2QString(vt.name()), ve, PI2QString(vt.comment()));
|
||||
grid->replace(grid->getRow(button), vt.name(), ve, vt.comment());
|
||||
value_edits[vt.name()] = ve;
|
||||
}
|
||||
ve = nullptr;
|
||||
@@ -254,7 +254,7 @@ void PIValueTreeEdit::actionTriggered(QToolButton * button, const PIString & vn,
|
||||
}
|
||||
}
|
||||
auto * cl = comm_labels.value(vn, nullptr);
|
||||
if (cl) cl->setText(PI2QString(vt.comment()));
|
||||
if (cl) cl->setText(PIVariantEditorBase::vtTr(vt.comment()));
|
||||
}
|
||||
if (a == widget_params->actionReorder) {
|
||||
if (!widget_reorder->showFor(source)) return;
|
||||
@@ -287,10 +287,11 @@ PIValueTreeEdit * PIValueTreeEdit::addTreeEdit(const PIValueTree & vt) {
|
||||
gb->setCheckable(true);
|
||||
gb->setChecked(true);
|
||||
gb->setAlignment(Qt::AlignCenter);
|
||||
gb->setProperty(property_name, PI2QString(vt.name()));
|
||||
connect(gb, &QGroupBox::toggled, ve, &QWidget::setVisible);
|
||||
grid->add(vt, gb, true);
|
||||
} else {
|
||||
grid->add(vt, PI2QString(vt.name()), ve, PI2QString(vt.comment()), true);
|
||||
grid->add(vt, vt.name(), ve, vt.comment(), true);
|
||||
}
|
||||
tree_edits[vt.name()] = ve;
|
||||
return ve;
|
||||
@@ -300,7 +301,7 @@ PIValueTreeEdit * PIValueTreeEdit::addTreeEdit(const PIValueTree & vt) {
|
||||
void PIValueTreeEdit::addValueEdit(const PIValueTree & vt) {
|
||||
auto * ve = new PIVariantEdit();
|
||||
applyVariantEdit(ve, vt);
|
||||
grid->add(vt, PI2QString(vt.name()), ve, PI2QString(vt.comment()));
|
||||
grid->add(vt, vt.name(), ve, vt.comment());
|
||||
value_edits[vt.name()] = ve;
|
||||
}
|
||||
|
||||
@@ -322,7 +323,7 @@ void PIValueTreeEdit::applyArrayAttributes() {
|
||||
QLabel * PIValueTreeEdit::newLabel(const PIValueTree & vt) {
|
||||
auto * l = new QLabel();
|
||||
l->setAlignment(Qt::AlignCenter);
|
||||
l->setText(PI2QString(vt.name()));
|
||||
l->setText(PIVariantEditorBase::vtTr(vt.name()));
|
||||
l->setStyleSheet(PI2QString(vt.attribute(Attribute::style).toString()));
|
||||
label_labels[vt.name()] = l;
|
||||
return l;
|
||||
@@ -410,11 +411,18 @@ int PIValueTreeEdit::GridWidgets::getRow(QWidget * w) const {
|
||||
}
|
||||
|
||||
|
||||
void PIValueTreeEdit::GridWidgets::add(const PIValueTree & vt, QString label, QWidget * w, const QString & comment, bool is_group) {
|
||||
int col = beginRow(vt, is_group);
|
||||
if (!label.isEmpty()) label += ':';
|
||||
auto * l = new QLabel(label);
|
||||
auto * c = new QLabel(comment);
|
||||
void PIValueTreeEdit::GridWidgets::add(const PIValueTree & vt,
|
||||
const PIString & label,
|
||||
QWidget * w,
|
||||
const PIString & comment,
|
||||
bool is_group) {
|
||||
int col = beginRow(vt, is_group);
|
||||
auto * l = new QLabel();
|
||||
auto * c = new QLabel(PIVariantEditorBase::vtTr(comment));
|
||||
l->setProperty(property_name, PI2QString(label));
|
||||
QString nn = PIVariantEditorBase::vtTr(label);
|
||||
if (!nn.isEmpty()) nn += ':';
|
||||
l->setText(nn);
|
||||
l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
c->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
@@ -445,11 +453,14 @@ void PIValueTreeEdit::GridWidgets::replace(int row, QWidget * w) {
|
||||
}
|
||||
|
||||
|
||||
void PIValueTreeEdit::GridWidgets::replace(int row, QString label, QWidget * w, const QString & comment) {
|
||||
int col = removeRowEdits(row);
|
||||
if (!label.isEmpty()) label += ':';
|
||||
auto * l = new QLabel(label);
|
||||
auto * c = new QLabel(comment);
|
||||
void PIValueTreeEdit::GridWidgets::replace(int row, const PIString & label, QWidget * w, const PIString & comment) {
|
||||
int col = removeRowEdits(row);
|
||||
auto * l = new QLabel();
|
||||
auto * c = new QLabel(PIVariantEditorBase::vtTr(comment));
|
||||
l->setProperty(property_name, PI2QString(label));
|
||||
QString nn = PIVariantEditorBase::vtTr(label);
|
||||
if (!nn.isEmpty()) nn += ':';
|
||||
l->setText(nn);
|
||||
l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
c->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
@@ -458,6 +469,7 @@ void PIValueTreeEdit::GridWidgets::replace(int row, QString label, QWidget * w,
|
||||
lay->addWidget(c, row, col++, Qt::AlignVCenter | Qt::AlignLeft);
|
||||
widgets << l << w << c;
|
||||
labels << l;
|
||||
parent->comm_labels[label] = c;
|
||||
}
|
||||
|
||||
|
||||
@@ -478,22 +490,24 @@ int PIValueTreeEdit::GridWidgets::beginRow(const PIValueTree & vt, bool is_group
|
||||
}
|
||||
|
||||
|
||||
void PIValueTreeEdit::GridWidgets::rename(QString prev_name, QString new_name) {
|
||||
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->title() == prev_name) {
|
||||
gb->setTitle(new_name);
|
||||
if (gb->property(property_name).toString() == PI2QString(prev_name)) {
|
||||
gb->setProperty(property_name, PI2QString(new_name));
|
||||
gb->setTitle(PIVariantEditorBase::vtTr(new_name));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!prev_name.isEmpty()) prev_name += ':';
|
||||
if (!new_name.isEmpty()) new_name += ':';
|
||||
for (auto * l: labels)
|
||||
if (l->text() == prev_name) {
|
||||
l->setText(new_name);
|
||||
if (l->property(property_name).toString() == PI2QString(prev_name)) {
|
||||
l->setProperty(property_name, PI2QString(new_name));
|
||||
QString nn = PIVariantEditorBase::vtTr(new_name);
|
||||
if (!nn.isEmpty()) nn += ':';
|
||||
l->setText(nn);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,12 +86,12 @@ private:
|
||||
int rowCount() const { return row_count; }
|
||||
int getRow(QWidget * w) const;
|
||||
void removeRow(int index);
|
||||
void add(const PIValueTree & vt, QString label, QWidget * w, const QString & 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 replace(int row, QWidget * w);
|
||||
void replace(int row, QString label, QWidget * w, const QString & comment);
|
||||
void replace(int row, const PIString & label, QWidget * w, const PIString & comment);
|
||||
int beginRow(const PIValueTree & vt, bool is_group);
|
||||
void rename(QString prev_name, QString new_name);
|
||||
void rename(const PIString & prev_name, const PIString & new_name);
|
||||
void reorder(const PIMap<int, int> & map) { simplify(map); }
|
||||
void clear();
|
||||
void changed();
|
||||
|
||||
@@ -5,6 +5,15 @@
|
||||
#include <QEvent>
|
||||
|
||||
|
||||
QString PIVariantEditorBase::vtTr(const PIString & txt) {
|
||||
PIByteArray utf = txt.toUTF8();
|
||||
utf.append(0);
|
||||
QString ret = QCoreApplication::translate("QAD::PIValueTreeEdit", reinterpret_cast<const char *>(utf.data()));
|
||||
ret.detach();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIVariantEditorBase * PIVariantEditorBase::createEditor(uint type_id) {
|
||||
auto f = factories().value(type_id, nullptr);
|
||||
if (!f) return nullptr;
|
||||
|
||||
@@ -48,6 +48,8 @@ public:
|
||||
virtual PIVariantMap attributes() const { return PIVariantMap(); }
|
||||
static PIVariantMap defaultAttributes() { return PIVariantMap(); }
|
||||
|
||||
static QString vtTr(const PIString & txt);
|
||||
|
||||
template<typename T>
|
||||
static void registerEditor(uint type_id) {
|
||||
if (factories().contains(type_id)) {
|
||||
|
||||
@@ -28,11 +28,11 @@ using Attribute = PIValueTree::Attribute;
|
||||
|
||||
PIVariantMap PIVariantEditors::Int::attributes() const {
|
||||
return {
|
||||
{Attribute::minimum, widget->minimum() },
|
||||
{Attribute::maximum, widget->maximum() },
|
||||
{Attribute::singleStep, widget->singleStep() },
|
||||
{Attribute::prefix, Q2PIString(widget->prefix())},
|
||||
{Attribute::suffix, Q2PIString(widget->suffix())},
|
||||
{Attribute::minimum, widget->minimum() },
|
||||
{Attribute::maximum, widget->maximum() },
|
||||
{Attribute::singleStep, widget->singleStep()},
|
||||
{Attribute::prefix, prefix },
|
||||
{Attribute::suffix, suffix },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -49,10 +49,12 @@ PIVariantMap PIVariantEditors::Int::defaultAttributes() {
|
||||
|
||||
|
||||
void PIVariantEditors::Int::applyAttributes(const PIVariantMap & a) {
|
||||
prefix = a.value(Attribute::prefix).toString();
|
||||
suffix = a.value(Attribute::suffix).toString();
|
||||
widget->setPrefix(PIVariantEditorBase::vtTr(prefix));
|
||||
widget->setSuffix(PIVariantEditorBase::vtTr(suffix));
|
||||
widget->setRange(a.value(Attribute::minimum, widget->minimum()).toInt(), a.value(Attribute::maximum, widget->maximum()).toInt());
|
||||
widget->setSingleStep(a.value(Attribute::singleStep, widget->singleStep()).toInt());
|
||||
widget->setPrefix(PI2QString(a.value(Attribute::prefix, Q2PIString(widget->prefix())).toString()));
|
||||
widget->setSuffix(PI2QString(a.value(Attribute::suffix, Q2PIString(widget->suffix())).toString()));
|
||||
widget->setReadOnly(a.value(Attribute::readOnly, widget->isReadOnly()).toBool());
|
||||
}
|
||||
|
||||
@@ -61,12 +63,12 @@ void PIVariantEditors::Int::applyAttributes(const PIVariantMap & a) {
|
||||
|
||||
PIVariantMap PIVariantEditors::Double::attributes() const {
|
||||
return {
|
||||
{Attribute::minimum, widget->minimum() },
|
||||
{Attribute::maximum, widget->maximum() },
|
||||
{Attribute::singleStep, widget->singleStep() },
|
||||
{Attribute::decimals, widget->decimals() },
|
||||
{Attribute::prefix, Q2PIString(widget->prefix())},
|
||||
{Attribute::suffix, Q2PIString(widget->suffix())},
|
||||
{Attribute::minimum, widget->minimum() },
|
||||
{Attribute::maximum, widget->maximum() },
|
||||
{Attribute::singleStep, widget->singleStep()},
|
||||
{Attribute::decimals, widget->decimals() },
|
||||
{Attribute::prefix, prefix },
|
||||
{Attribute::suffix, suffix },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -84,11 +86,13 @@ PIVariantMap PIVariantEditors::Double::defaultAttributes() {
|
||||
|
||||
|
||||
void PIVariantEditors::Double::applyAttributes(const PIVariantMap & a) {
|
||||
prefix = a.value(Attribute::prefix).toString();
|
||||
suffix = a.value(Attribute::suffix).toString();
|
||||
widget->setPrefix(PIVariantEditorBase::vtTr(prefix));
|
||||
widget->setSuffix(PIVariantEditorBase::vtTr(suffix));
|
||||
widget->setRange(a.value(Attribute::minimum, widget->minimum()).toDouble(), a.value(Attribute::maximum, widget->maximum()).toDouble());
|
||||
widget->setSingleStep(a.value(Attribute::singleStep, widget->singleStep()).toDouble());
|
||||
widget->setDecimals(a.value(Attribute::decimals, widget->decimals()).toInt());
|
||||
widget->setPrefix(PI2QString(a.value(Attribute::prefix, Q2PIString(widget->prefix())).toString()));
|
||||
widget->setSuffix(PI2QString(a.value(Attribute::suffix, Q2PIString(widget->suffix())).toString()));
|
||||
widget->setReadOnly(a.value(Attribute::readOnly, widget->isReadOnly()).toBool());
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ public:
|
||||
|
||||
private:
|
||||
void applyAttributes(const PIVariantMap & a) override;
|
||||
PIString prefix, suffix;
|
||||
QSpinBox * widget;
|
||||
};
|
||||
|
||||
@@ -87,6 +88,7 @@ public:
|
||||
|
||||
private:
|
||||
void applyAttributes(const PIVariantMap & a) override;
|
||||
PIString prefix, suffix;
|
||||
QDoubleSpinBox * widget;
|
||||
};
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <QFileDialog>
|
||||
#include <QScrollArea>
|
||||
#include <QTimer>
|
||||
#include <QTranslator>>
|
||||
#include <evalspinbox.h>
|
||||
#include <piintrospection_server.h>
|
||||
#include <qad_types.h>
|
||||
@@ -15,6 +16,9 @@
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
QApplication a(argc, argv);
|
||||
auto * qtr = new QTranslator();
|
||||
qtr->load("c:/work/test_ru.qm");
|
||||
a.installTranslator(qtr);
|
||||
|
||||
PIValueTree root, group, array;
|
||||
root.addChild({"bool", false});
|
||||
|
||||
Reference in New Issue
Block a user