add QAD valuetreeeditor util
This commit is contained in:
@@ -49,12 +49,14 @@ PIValueTree PIValueTreeEdit::value() const {
|
|||||||
|
|
||||||
|
|
||||||
void PIValueTreeEdit::setGroupingEnabled(bool yes) {
|
void PIValueTreeEdit::setGroupingEnabled(bool yes) {
|
||||||
|
applyValues();
|
||||||
is_grouping = yes;
|
is_grouping = yes;
|
||||||
build();
|
build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIValueTreeEdit::setFullEditMode(bool yes) {
|
void PIValueTreeEdit::setFullEditMode(bool yes) {
|
||||||
|
applyValues();
|
||||||
is_full_edit = yes;
|
is_full_edit = yes;
|
||||||
build();
|
build();
|
||||||
}
|
}
|
||||||
@@ -121,12 +123,12 @@ void PIValueTreeEdit::build() {
|
|||||||
grid->create_edit_buttons = false;
|
grid->create_edit_buttons = false;
|
||||||
removeAll();
|
removeAll();
|
||||||
// piCout << source.attributes().value(Attribute::arrayType) << array_type;
|
// piCout << source.attributes().value(Attribute::arrayType) << array_type;
|
||||||
|
grid->button_add->hide();
|
||||||
if (current.isArray()) {
|
if (current.isArray()) {
|
||||||
widget_array = new QWidget();
|
widget_array = new QWidget();
|
||||||
ui_array->setupUi(widget_array);
|
ui_array->setupUi(widget_array);
|
||||||
applyArrayAttributes();
|
applyArrayAttributes();
|
||||||
ui_array->layoutArray->addWidget(grid);
|
ui_array->layoutArray->addWidget(grid);
|
||||||
grid->button_add->hide();
|
|
||||||
grid->show();
|
grid->show();
|
||||||
uint array_type = PIVariant::typeIDFromName(current.attribute(Attribute::arrayType).toString());
|
uint array_type = PIVariant::typeIDFromName(current.attribute(Attribute::arrayType).toString());
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QInputDialog>>
|
#include <QInputDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
|
|
||||||
@@ -349,6 +349,7 @@ void PIVariantEditors::FileBase::setFullEditMode(bool on) {
|
|||||||
edit_widget->setVisible(on);
|
edit_widget->setVisible(on);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIVariantEditors::FileBase::createMenu() {
|
void PIVariantEditors::FileBase::createMenu() {
|
||||||
act_abs = edit_menu.addAction(tr("Absolute path"), this, [this](bool on) { is_abs = on; });
|
act_abs = edit_menu.addAction(tr("Absolute path"), this, [this](bool on) { is_abs = on; });
|
||||||
act_abs->setCheckable(true);
|
act_abs->setCheckable(true);
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
#include "blockeditor.h"
|
#include "blockeditor.h"
|
||||||
|
#include "qad_locations.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
enableHighDPI();
|
|
||||||
a.setWindowIcon(QIcon(":/icons/blockview.png"));
|
a.setWindowIcon(QIcon(":/icons/blockview.png"));
|
||||||
|
enableHighDPI();
|
||||||
|
QAD::loadTranslations();
|
||||||
BlockEditor w;
|
BlockEditor w;
|
||||||
if (a.arguments().size() > 1) w.loadFile(a.arguments().back());
|
if (a.arguments().size() > 1) w.loadFile(a.arguments().back());
|
||||||
w.show();
|
w.show();
|
||||||
|
|||||||
@@ -1,105 +1,33 @@
|
|||||||
#include "pifile.h"
|
|
||||||
#include "pijson.h"
|
|
||||||
#include "piqt_connection_edit.h"
|
#include "piqt_connection_edit.h"
|
||||||
#include "pivaluetree_conversions.h"
|
|
||||||
#include "pivaluetree_edit.h"
|
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QScrollArea>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QTranslator>
|
|
||||||
#include <evalspinbox.h>
|
|
||||||
#include <piintrospection_server.h>
|
#include <piintrospection_server.h>
|
||||||
#include <qad_types.h>
|
#include <qad_types.h>
|
||||||
#include <qpiconfig.h>
|
#include <qpiconfig.h>
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
QApplication a(argc, argv);
|
|
||||||
|
|
||||||
PIValueTree root, group, array;
|
|
||||||
root.addChild({"bool", false});
|
|
||||||
root.addChild({
|
|
||||||
"integer",
|
|
||||||
256,
|
|
||||||
{{PIValueTree::Attribute::minimum, -100}, {PIValueTree::Attribute::maximum, 200}, {PIValueTree::Attribute::singleStep, 5}}
|
|
||||||
});
|
|
||||||
root.addChild({"Label here", PIVariant(), {{PIValueTree::Attribute::isLabel, true}}});
|
|
||||||
root.addChild({"string", "str"});
|
|
||||||
group.addChild({"substr", "str2"});
|
|
||||||
group.addChild({"real", 12.3});
|
|
||||||
group.setName("group");
|
|
||||||
array.setAttribute(PIValueTree::Attribute::arrayType, "string");
|
|
||||||
array.setAttribute(PIValueTree::Attribute::arrayResize, true);
|
|
||||||
array.setAttribute(PIValueTree::Attribute::arrayMinCount, 0);
|
|
||||||
array.setAttribute(PIValueTree::Attribute::arrayMaxCount, 10);
|
|
||||||
array.setName("array");
|
|
||||||
array.addChild({"0", "1E+2"});
|
|
||||||
array.addChild({"1", -5});
|
|
||||||
array.addChild({"3", 0.1});
|
|
||||||
root.addChild(group);
|
|
||||||
root.addChild(array);
|
|
||||||
PIString json = PIValueTreeConversions::toJSON(root).toJSON(PIJSON::Tree);
|
|
||||||
// piCout << PIValueTreeConversions::fromJSON(PIJSON::fromJSON(json));
|
|
||||||
|
|
||||||
PIFile f("C:/work/config.conf", PIIODevice::ReadOnly);
|
|
||||||
auto vt = PIValueTreeConversions::fromText(&f);
|
|
||||||
PIVariantTypes::Enum en;
|
|
||||||
en << "first"
|
|
||||||
<< "second";
|
|
||||||
en << PIVariantTypes::Enumerator(10, "TEN");
|
|
||||||
en.selectValue(1);
|
|
||||||
vt.addChild({"Enum", en});
|
|
||||||
// piCout << PIValueTreeConversions::toText(vt);
|
|
||||||
|
|
||||||
QScrollArea area;
|
|
||||||
area.setWidgetResizable(true);
|
|
||||||
PIValueTreeEdit e;
|
|
||||||
e.setGroupingEnabled(true);
|
|
||||||
e.setFullEditMode(true);
|
|
||||||
e.setGeometry(500, 400, 100, 50);
|
|
||||||
// e.setValue(PIValueTreeConversions::fromJSON(PIJSON::fromJSON(PIValueTreeConversions::toJSON(vt).toJSON())));
|
|
||||||
e.setValue(vt);
|
|
||||||
area.setWidget(&e);
|
|
||||||
area.show();
|
|
||||||
// piCout << PIValueTreeConversions::toText(e.value()); //.toJSON(PIJSON::Tree);
|
|
||||||
|
|
||||||
QTimer timer;
|
|
||||||
QObject::connect(&timer, &QTimer::timeout, [&]() { e.rollback(); });
|
|
||||||
// timer.start(5);
|
|
||||||
QTimer::singleShot(1000, [&e]() {
|
|
||||||
auto * qtr = new QTranslator();
|
|
||||||
qtr->load("c:/work/test_ru.qm");
|
|
||||||
qApp->installTranslator(qtr);
|
|
||||||
});
|
|
||||||
// QTimer::singleShot(2000, [&e, vt]() {
|
|
||||||
// e.setValue(PIValueTreeConversions::fromText(PIValueTreeConversions::toText(vt) + "\n[]\nAHAHA = 123\n"));
|
|
||||||
//});
|
|
||||||
// QTimer::singleShot(3000, [&e]() { e.setFullEditMode(false); });
|
|
||||||
return a.exec();
|
|
||||||
|
|
||||||
/*
|
|
||||||
PIINTROSPECTION_START(piconnedit)
|
PIINTROSPECTION_START(piconnedit)
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
enableHighDPI();
|
enableHighDPI();
|
||||||
ConnectionEdit w;
|
ConnectionEdit w;
|
||||||
if (a.arguments().size() > 1) {
|
if (a.arguments().size() > 1) {
|
||||||
QPIConfig cfg(a.arguments()[1]);
|
QPIConfig cfg(a.arguments()[1]);
|
||||||
QByteArray model = cfg.getValue("connectionmodel").toByteArray();
|
QByteArray model = cfg.getValue("connectionmodel").toByteArray();
|
||||||
if (!model.isEmpty()) w.setModel(model);
|
if (!model.isEmpty()) w.setModel(model);
|
||||||
} else
|
} else
|
||||||
w.recreateConnection();
|
w.recreateConnection();
|
||||||
if (w.exec() == QDialog::Accepted) {
|
if (w.exec() == QDialog::Accepted) {
|
||||||
QString c = QFileDialog::getSaveFileName(&w, "Save config to file", a.applicationDirPath(), "*.conf");
|
QString c = QFileDialog::getSaveFileName(&w, "Save config to file", a.applicationDirPath(), "*.conf");
|
||||||
if (!c.isEmpty()) {
|
if (!c.isEmpty()) {
|
||||||
QFile f(c);
|
QFile f(c);
|
||||||
if (f.open(QIODevice::WriteOnly)) {
|
if (f.open(QIODevice::WriteOnly)) {
|
||||||
QTextStream ts(&f);
|
QTextStream ts(&f);
|
||||||
ts << w.configuration();
|
ts << w.configuration();
|
||||||
ts << "connectionmodel = " << QByteArray2QString(w.model()) << "\n";
|
ts << "connectionmodel = " << QByteArray2QString(w.model()) << "\n";
|
||||||
f.close();
|
f.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;*/
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#include "piqt.h"
|
#include "piqt.h"
|
||||||
#include "qad_locations.h"
|
#include "qad_locations.h"
|
||||||
|
|
||||||
@@ -16,8 +17,8 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow()
|
|||||||
#endif
|
#endif
|
||||||
npal = epal = lineInput->palette();
|
npal = epal = lineInput->palette();
|
||||||
epal.setColor(lineInput->backgroundRole(), QColor(Qt::red).lighter(150));
|
epal.setColor(lineInput->backgroundRole(), QColor(Qt::red).lighter(150));
|
||||||
connect(&session, SIGNAL(loading(QPIConfig & )), this, SLOT(loading(QPIConfig & )));
|
connect(&session, SIGNAL(loading(QPIConfig &)), this, SLOT(loading(QPIConfig &)));
|
||||||
connect(&session, SIGNAL(saving(QPIConfig & )), this, SLOT(saving(QPIConfig & )));
|
connect(&session, SIGNAL(saving(QPIConfig &)), this, SLOT(saving(QPIConfig &)));
|
||||||
session.setFile(QAD::userPath(QAD::ltConfig, "session_qpicalc"));
|
session.setFile(QAD::userPath(QAD::ltConfig, "session_qpicalc"));
|
||||||
session.addEntry(this);
|
session.addEntry(this);
|
||||||
session.addEntry(lineInput);
|
session.addEntry(lineInput);
|
||||||
@@ -28,18 +29,16 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MainWindow::~MainWindow() {session.save();
|
MainWindow::~MainWindow() {
|
||||||
|
session.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::changeEvent(QEvent * e) {
|
void MainWindow::changeEvent(QEvent * e) {
|
||||||
QMainWindow::changeEvent(e);
|
QMainWindow::changeEvent(e);
|
||||||
switch (e->type()) {
|
switch (e->type()) {
|
||||||
case QEvent::LanguageChange:
|
case QEvent::LanguageChange: retranslateUi(this); break;
|
||||||
retranslateUi(this);
|
default: break;
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,9 +81,9 @@ void MainWindow::redrawGraphics() {
|
|||||||
|
|
||||||
|
|
||||||
void MainWindow::loading(QPIConfig & conf) {
|
void MainWindow::loading(QPIConfig & conf) {
|
||||||
active_ = false;
|
active_ = false;
|
||||||
QStringList vars = conf.getValue("variables").toStringList();
|
QStringList vars = conf.getValue("variables").toStringList();
|
||||||
int vc = vars.size() / 2;
|
int vc = vars.size() / 2;
|
||||||
for (int i = 0; i < vc; ++i) {
|
for (int i = 0; i < vc; ++i) {
|
||||||
QTreeWidgetItem * ti = new QTreeWidgetItem(treeVariables);
|
QTreeWidgetItem * ti = new QTreeWidgetItem(treeVariables);
|
||||||
ti->setText(0, vars[i * 2]);
|
ti->setText(0, vars[i * 2]);
|
||||||
@@ -110,8 +109,7 @@ void MainWindow::loading(QPIConfig & conf) {
|
|||||||
buttonGraphicClear->setEnabled(treeGraphics->topLevelItemCount() > 0);
|
buttonGraphicClear->setEnabled(treeGraphics->topLevelItemCount() > 0);
|
||||||
graphic->setVisualRect(conf.getValue("graphicRect", QRectF(-1., -1., 2., 2.)).toRectF());
|
graphic->setVisualRect(conf.getValue("graphicRect", QRectF(-1., -1., 2., 2.)).toRectF());
|
||||||
ba = conf.getValue("graphic_state").toByteArray();
|
ba = conf.getValue("graphic_state").toByteArray();
|
||||||
if (!ba.isEmpty())
|
if (!ba.isEmpty()) graphic->load(ba);
|
||||||
graphic->load(ba);
|
|
||||||
on_tabWidget_currentChanged(0);
|
on_tabWidget_currentChanged(0);
|
||||||
redrawGraphics();
|
redrawGraphics();
|
||||||
active_ = true;
|
active_ = true;
|
||||||
@@ -133,7 +131,8 @@ void MainWindow::saving(QPIConfig & conf) {
|
|||||||
QTreeWidgetItem * ti = treeGraphics->topLevelItem(i);
|
QTreeWidgetItem * ti = treeGraphics->topLevelItem(i);
|
||||||
vars << QString::number(ti->background(1).color().rgb()) << ti->text(2);
|
vars << QString::number(ti->background(1).color().rgb()) << ti->text(2);
|
||||||
}
|
}
|
||||||
QByteArray ba; QDataStream s(&ba, QIODevice::WriteOnly);
|
QByteArray ba;
|
||||||
|
QDataStream s(&ba, QIODevice::WriteOnly);
|
||||||
s << graphic->allGraphics();
|
s << graphic->allGraphics();
|
||||||
conf.setValue("graphics", QByteArray2QString(ba));
|
conf.setValue("graphics", QByteArray2QString(ba));
|
||||||
conf.setValue("graphicRect", graphic->visualRect());
|
conf.setValue("graphicRect", graphic->visualRect());
|
||||||
@@ -142,8 +141,10 @@ void MainWindow::saving(QPIConfig & conf) {
|
|||||||
|
|
||||||
|
|
||||||
void MainWindow::on_lineInput_textChanged(QString text) {
|
void MainWindow::on_lineInput_textChanged(QString text) {
|
||||||
if (evaluator.check(Q2PIString(text))) lineInput->setPalette(npal);
|
if (evaluator.check(Q2PIString(text)))
|
||||||
else lineInput->setPalette(epal);
|
lineInput->setPalette(npal);
|
||||||
|
else
|
||||||
|
lineInput->setPalette(epal);
|
||||||
labelParsed->setText(PI2QString(evaluator.expression()));
|
labelParsed->setText(PI2QString(evaluator.expression()));
|
||||||
labelError->setText(PI2QString(evaluator.error()));
|
labelError->setText(PI2QString(evaluator.error()));
|
||||||
}
|
}
|
||||||
@@ -151,36 +152,37 @@ void MainWindow::on_lineInput_textChanged(QString text) {
|
|||||||
|
|
||||||
void MainWindow::on_lineInput_returnPressed() {
|
void MainWindow::on_lineInput_returnPressed() {
|
||||||
bool ret = evaluator.check(Q2PIString(lineInput->text()));
|
bool ret = evaluator.check(Q2PIString(lineInput->text()));
|
||||||
if (ret) lineInput->setPalette(npal);
|
if (ret)
|
||||||
else lineInput->setPalette(epal);
|
lineInput->setPalette(npal);
|
||||||
|
else
|
||||||
|
lineInput->setPalette(epal);
|
||||||
labelParsed->setText(PI2QString(evaluator.expression()));
|
labelParsed->setText(PI2QString(evaluator.expression()));
|
||||||
labelError->setText(PI2QString(evaluator.error()));
|
labelError->setText(PI2QString(evaluator.error()));
|
||||||
if (!ret) return;
|
if (!ret) return;
|
||||||
complexd val = evaluator.evaluate();
|
complexd val = evaluator.evaluate();
|
||||||
evaluator.setVariable(ans, val);
|
evaluator.setVariable(ans, val);
|
||||||
if (val.imag() == 0) labelResult->setText(QString::number(val.real()));
|
if (val.imag() == 0)
|
||||||
|
labelResult->setText(QString::number(val.real()));
|
||||||
else {
|
else {
|
||||||
if (val.real() == 0) labelResult->setText(QString::number(val.imag()) + "i");
|
if (val.real() == 0)
|
||||||
|
labelResult->setText(QString::number(val.imag()) + "i");
|
||||||
else {
|
else {
|
||||||
if (val.imag() > 0) labelResult->setText(QString::number(val.real())
|
if (val.imag() > 0)
|
||||||
+ " + " + QString::number(val.imag()) + "i");
|
labelResult->setText(QString::number(val.real()) + " + " + QString::number(val.imag()) + "i");
|
||||||
else labelResult->setText(QString::number(val.real())
|
else
|
||||||
+ " - " + QString::number(fabs(val.imag())) + "i");
|
labelResult->setText(QString::number(val.real()) + " - " + QString::number(fabs(val.imag())) + "i");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (lineInput->text().trimmed().isEmpty()) return;
|
if (lineInput->text().trimmed().isEmpty()) return;
|
||||||
QTreeWidgetItem * ti = 0, * pti = 0;
|
QTreeWidgetItem *ti = 0, *pti = 0;
|
||||||
if (treeHistory->topLevelItemCount() > 0)
|
if (treeHistory->topLevelItemCount() > 0) pti = treeHistory->topLevelItem(treeHistory->topLevelItemCount() - 1);
|
||||||
pti = treeHistory->topLevelItem(treeHistory->topLevelItemCount() - 1);
|
|
||||||
if (pti != 0)
|
if (pti != 0)
|
||||||
if (pti->text(0) == lineInput->text())
|
if (pti->text(0) == lineInput->text()) return;
|
||||||
return;
|
|
||||||
ti = new QTreeWidgetItem(treeHistory);
|
ti = new QTreeWidgetItem(treeHistory);
|
||||||
ti->setText(0, lineInput->text());
|
ti->setText(0, lineInput->text());
|
||||||
ti->setText(1, labelResult->text());
|
ti->setText(1, labelResult->text());
|
||||||
treeHistory->addTopLevelItem(ti);
|
treeHistory->addTopLevelItem(ti);
|
||||||
if (treeHistory->verticalScrollBar()->value() == treeHistory->verticalScrollBar()->maximum())
|
if (treeHistory->verticalScrollBar()->value() == treeHistory->verticalScrollBar()->maximum()) treeHistory->scrollToBottom();
|
||||||
treeHistory->scrollToBottom();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -196,11 +198,16 @@ void MainWindow::on_treeGraphics_itemSelectionChanged() {
|
|||||||
|
|
||||||
void MainWindow::on_treeGraphics_itemDoubleClicked(QTreeWidgetItem * item, int column) {
|
void MainWindow::on_treeGraphics_itemDoubleClicked(QTreeWidgetItem * item, int column) {
|
||||||
Qt::ItemFlags f = item->flags();
|
Qt::ItemFlags f = item->flags();
|
||||||
if (column != 1) f &= ~Qt::ItemIsEditable;
|
if (column != 1)
|
||||||
else f |= Qt::ItemIsEditable;
|
f &= ~Qt::ItemIsEditable;
|
||||||
|
else
|
||||||
|
f |= Qt::ItemIsEditable;
|
||||||
item->setFlags(f);
|
item->setFlags(f);
|
||||||
if (column != 0) return;
|
if (column != 0) return;
|
||||||
QColor col = QColorDialog::getColor(item->data(0, Qt::DecorationRole).value<QColor>(), this, "Select color for graphic", QColorDialog::ShowAlphaChannel);
|
QColor col = QColorDialog::getColor(item->data(0, Qt::DecorationRole).value<QColor>(),
|
||||||
|
this,
|
||||||
|
"Select color for graphic",
|
||||||
|
QColorDialog::ShowAlphaChannel);
|
||||||
if (!col.isValid()) return;
|
if (!col.isValid()) return;
|
||||||
item->setData(0, Qt::DecorationRole, col);
|
item->setData(0, Qt::DecorationRole, col);
|
||||||
updateGraphics();
|
updateGraphics();
|
||||||
@@ -219,8 +226,8 @@ void MainWindow::on_buttonVarAdd_clicked() {
|
|||||||
|
|
||||||
|
|
||||||
void MainWindow::on_buttonVarDel_clicked() {
|
void MainWindow::on_buttonVarDel_clicked() {
|
||||||
QList<QTreeWidgetItem * > si = treeVariables->selectedItems();
|
QList<QTreeWidgetItem *> si = treeVariables->selectedItems();
|
||||||
foreach (QTreeWidgetItem * i, si)
|
foreach(QTreeWidgetItem * i, si)
|
||||||
delete i;
|
delete i;
|
||||||
buttonVarClear->setEnabled(treeVariables->topLevelItemCount() > 0);
|
buttonVarClear->setEnabled(treeVariables->topLevelItemCount() > 0);
|
||||||
}
|
}
|
||||||
@@ -243,8 +250,8 @@ void MainWindow::on_buttonGraphicAdd_clicked() {
|
|||||||
|
|
||||||
|
|
||||||
void MainWindow::on_buttonGraphicDel_clicked() {
|
void MainWindow::on_buttonGraphicDel_clicked() {
|
||||||
QList<QTreeWidgetItem * > si = treeGraphics->selectedItems();
|
QList<QTreeWidgetItem *> si = treeGraphics->selectedItems();
|
||||||
foreach (QTreeWidgetItem * i, si)
|
foreach(QTreeWidgetItem * i, si)
|
||||||
delete i;
|
delete i;
|
||||||
buttonGraphicClear->setEnabled(treeGraphics->topLevelItemCount() > 0);
|
buttonGraphicClear->setEnabled(treeGraphics->topLevelItemCount() > 0);
|
||||||
updateGraphics();
|
updateGraphics();
|
||||||
|
|||||||
19
utils/valuetreeeditor/CMakeLists.txt
Normal file
19
utils/valuetreeeditor/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
project(valuetreeeditor)
|
||||||
|
if(APPLE)
|
||||||
|
set(APP_ICON "")
|
||||||
|
elseif(WIN32)
|
||||||
|
set(APP_ICON "icons/valuetreeeditor.ico")
|
||||||
|
else()
|
||||||
|
set(APP_ICON "icons/valuetreeeditor.png")
|
||||||
|
endif()
|
||||||
|
set(APP_INFO "Editor for PIValueTree")
|
||||||
|
qad_application(${PROJECT_NAME} "Gui;Widgets" "qad_utils;qad_widgets;qad_application;qad_piqt_utils")
|
||||||
|
if (NOT DEFINED ANDROID_PLATFORM)
|
||||||
|
foreach (_qv_ IN ITEMS 5 6)
|
||||||
|
if (${LOCAL_FOUND${_qv_}})
|
||||||
|
import_version(${PROJECT_NAME}${_qv_} ${PROJECT_NAME})
|
||||||
|
import_deploy_properties(${PROJECT_NAME}${_qv_} ${PROJECT_NAME})
|
||||||
|
deploy_target(${PROJECT_NAME}${_qv_} DEPLOY_DIR ${CMAKE_CURRENT_BINARY_DIR} DESTINATION ${ROOT_DIR}/release ADD_MANIFEST)
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
BIN
utils/valuetreeeditor/icons/valuetreeeditor.ico
Normal file
BIN
utils/valuetreeeditor/icons/valuetreeeditor.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
BIN
utils/valuetreeeditor/icons/valuetreeeditor.png
Normal file
BIN
utils/valuetreeeditor/icons/valuetreeeditor.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
90
utils/valuetreeeditor/mainwindow.cpp
Normal file
90
utils/valuetreeeditor/mainwindow.cpp
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
#include "piqt.h"
|
||||||
|
#include "qad_locations.h"
|
||||||
|
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <pifile.h>
|
||||||
|
#include <pijson.h>
|
||||||
|
#include <pivaluetree.h>
|
||||||
|
#include <pivaluetree_conversions.h>
|
||||||
|
|
||||||
|
|
||||||
|
MainWindow::MainWindow(QWidget * parent): EMainWindow(parent), Ui::MainWindow() {
|
||||||
|
setupUi(this);
|
||||||
|
session.setFile(QAD::userPath(QAD::ltConfig, "session_valuetreeeditor"));
|
||||||
|
session.addEntry(this);
|
||||||
|
session.load();
|
||||||
|
widget->setGroupingEnabled(actionGrouping->isChecked());
|
||||||
|
widget->setFullEditMode(actionFull_edit_mode->isChecked());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MainWindow::~MainWindow() {
|
||||||
|
session.save();
|
||||||
|
session.clear(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::reset(bool) {
|
||||||
|
widget->setValue(PIValueTree());
|
||||||
|
setWindowTitle(tr("PIValueTree Editor"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool MainWindow::load(const QString & path) {
|
||||||
|
PIFile f(Q2PIString(path), PIIODevice::ReadOnly);
|
||||||
|
if (!f.isOpened()) return false;
|
||||||
|
PIString ext = PIFile::FileInfo(f.path()).extension().toLowerCase();
|
||||||
|
PIValueTree v;
|
||||||
|
if (ext == "conf" || ext == "ini")
|
||||||
|
v = PIValueTreeConversions::fromText(&f);
|
||||||
|
else if (ext == "json")
|
||||||
|
v = PIValueTreeConversions::fromJSON(PIJSON::fromJSON(PIString::fromUTF8(f.readAll())));
|
||||||
|
else if (ext == "bin")
|
||||||
|
v = piDeserialize<PIValueTree>(f.readAll());
|
||||||
|
widget->setValue(v);
|
||||||
|
setWindowTitle(tr("PIValueTree Editor - %1").arg(QFileInfo(path).fileName()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool MainWindow::save(const QString & path) {
|
||||||
|
PIFile f(Q2PIString(path), PIIODevice::ReadWrite);
|
||||||
|
if (!f.isOpened()) return false;
|
||||||
|
f.clear();
|
||||||
|
PIString ext = PIFile::FileInfo(f.path()).extension().toLowerCase();
|
||||||
|
auto v = widget->value();
|
||||||
|
if (ext == "conf" || ext == "ini")
|
||||||
|
f.write(PIValueTreeConversions::toText(v).toUTF8());
|
||||||
|
else if (ext == "json")
|
||||||
|
f.write(PIValueTreeConversions::toJSON(v).toJSON(PIJSON::Tree, false).toUTF8());
|
||||||
|
else if (ext == "bin")
|
||||||
|
f.write(piSerialize(v));
|
||||||
|
setWindowTitle(tr("PIValueTree Editor - %1").arg(QFileInfo(path).fileName()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::changeEvent(QEvent * e) {
|
||||||
|
QMainWindow::changeEvent(e);
|
||||||
|
switch (e->type()) {
|
||||||
|
case QEvent::LanguageChange: retranslateUi(this); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString MainWindow::loadFilter() {
|
||||||
|
return "All types(*.conf *.ini *.json *.bin);;INI format(*.conf *.ini);;JSON(*.json);;Binary(*.bin)";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::on_actionGrouping_toggled(bool on) {
|
||||||
|
widget->setGroupingEnabled(on);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::on_actionFull_edit_mode_toggled(bool on) {
|
||||||
|
widget->setFullEditMode(on);
|
||||||
|
}
|
||||||
32
utils/valuetreeeditor/mainwindow.h
Normal file
32
utils/valuetreeeditor/mainwindow.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#ifndef MAINWINDOW_H
|
||||||
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
|
#include "emainwindow.h"
|
||||||
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
|
|
||||||
|
class MainWindow
|
||||||
|
: public EMainWindow
|
||||||
|
, private Ui::MainWindow {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
MainWindow(QWidget * parent = 0);
|
||||||
|
~MainWindow();
|
||||||
|
|
||||||
|
void reset(bool full = false) override;
|
||||||
|
bool load(const QString & path) override;
|
||||||
|
bool save(const QString & path) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void changeEvent(QEvent * e);
|
||||||
|
|
||||||
|
QString loadFilter() override;
|
||||||
|
QString saveFilter() override { return loadFilter(); }
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_actionGrouping_toggled(bool on);
|
||||||
|
void on_actionFull_edit_mode_toggled(bool on);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MAINWINDOW_H
|
||||||
266
utils/valuetreeeditor/mainwindow.ui
Normal file
266
utils/valuetreeeditor/mainwindow.ui
Normal file
@@ -0,0 +1,266 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>MainWindow</class>
|
||||||
|
<widget class="QMainWindow" name="MainWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>780</width>
|
||||||
|
<height>521</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>PIValueTree Editor</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralWidget">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QScrollArea" name="scrollArea">
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::NoFrame</enum>
|
||||||
|
</property>
|
||||||
|
<property name="widgetResizable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="scrollAreaContent">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>780</width>
|
||||||
|
<height>446</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="PIValueTreeEdit" name="widget" native="true"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QToolBar" name="toolBar">
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>File</string>
|
||||||
|
</property>
|
||||||
|
<attribute name="toolBarArea">
|
||||||
|
<enum>TopToolBarArea</enum>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="toolBarBreak">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
<addaction name="actionNew"/>
|
||||||
|
<addaction name="actionOpen"/>
|
||||||
|
<addaction name="actionSave"/>
|
||||||
|
<addaction name="actionSaveAs"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menuBar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>780</width>
|
||||||
|
<height>31</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<widget class="QMenu" name="menuFile">
|
||||||
|
<property name="title">
|
||||||
|
<string>File</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionNew"/>
|
||||||
|
<addaction name="actionOpen"/>
|
||||||
|
<addaction name="actionSave"/>
|
||||||
|
<addaction name="actionSaveAs"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuView">
|
||||||
|
<property name="title">
|
||||||
|
<string>View</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionGrouping"/>
|
||||||
|
<addaction name="actionFull_edit_mode"/>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menuFile"/>
|
||||||
|
<addaction name="menuView"/>
|
||||||
|
</widget>
|
||||||
|
<action name="actionOpen">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../libs/blockview/qad_blockview.qrc">
|
||||||
|
<normaloff>:/icons/document-open.png</normaloff>:/icons/document-open.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Open...</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+O</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionSave">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../libs/blockview/qad_blockview.qrc">
|
||||||
|
<normaloff>:/icons/document-save.png</normaloff>:/icons/document-save.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Save</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+S</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionSaveAs">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../libs/widgets/qad_widgets.qrc">
|
||||||
|
<normaloff>:/icons/document-save-as.png</normaloff>:/icons/document-save-as.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Save As...</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Alt+Shift+S</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionNew">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../libs/widgets/qad_widgets.qrc">
|
||||||
|
<normaloff>:/icons/document-new.png</normaloff>:/icons/document-new.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>New</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+N</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionAbout">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../../cd/utils/pult/cdpult.qrc">
|
||||||
|
<normaloff>:/icons/dialog-information.png</normaloff>:/icons/dialog-information.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>About ...</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionGrouping">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Grouping</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionFull_edit_mode">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Full edit mode</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
</widget>
|
||||||
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>PIValueTreeEdit</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>pivaluetree_edit.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources>
|
||||||
|
<include location="../../../cd/utils/pult/cdpult.qrc"/>
|
||||||
|
<include location="../../libs/blockview/qad_blockview.qrc"/>
|
||||||
|
<include location="../../libs/widgets/qad_widgets.qrc"/>
|
||||||
|
</resources>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>actionNew</sender>
|
||||||
|
<signal>triggered()</signal>
|
||||||
|
<receiver>MainWindow</receiver>
|
||||||
|
<slot>newFile()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>-1</x>
|
||||||
|
<y>-1</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>389</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>actionOpen</sender>
|
||||||
|
<signal>triggered()</signal>
|
||||||
|
<receiver>MainWindow</receiver>
|
||||||
|
<slot>openFile()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>-1</x>
|
||||||
|
<y>-1</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>389</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>actionSaveAs</sender>
|
||||||
|
<signal>triggered()</signal>
|
||||||
|
<receiver>MainWindow</receiver>
|
||||||
|
<slot>saveAsFile()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>-1</x>
|
||||||
|
<y>-1</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>389</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>actionSave</sender>
|
||||||
|
<signal>triggered()</signal>
|
||||||
|
<receiver>MainWindow</receiver>
|
||||||
|
<slot>saveFile()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>-1</x>
|
||||||
|
<y>-1</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>389</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
<slots>
|
||||||
|
<slot>newFile()</slot>
|
||||||
|
<slot>openFile()</slot>
|
||||||
|
<slot>saveFile()</slot>
|
||||||
|
<slot>saveAsFile()</slot>
|
||||||
|
</slots>
|
||||||
|
</ui>
|
||||||
5
utils/valuetreeeditor/valuetreeeditor.qrc
Normal file
5
utils/valuetreeeditor/valuetreeeditor.qrc
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>icons/valuetreeeditor.png</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
||||||
17
utils/valuetreeeditor/valuetreeeditor_main.cpp
Normal file
17
utils/valuetreeeditor/valuetreeeditor_main.cpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#include "mainwindow.h"
|
||||||
|
#include "qad_locations.h"
|
||||||
|
#include "qad_types.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char * argv[]) {
|
||||||
|
QApplication a(argc, argv);
|
||||||
|
a.setWindowIcon(QIcon(":/icons/valuetreeeditor.png"));
|
||||||
|
enableHighDPI();
|
||||||
|
QAD::loadTranslations();
|
||||||
|
MainWindow w;
|
||||||
|
if (a.arguments().size() > 1) w.load(a.arguments().back());
|
||||||
|
w.show();
|
||||||
|
return a.exec();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user