add QAD valuetreeeditor util
This commit is contained in:
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