2020-12-22 00:01:36 +00:00
|
|
|
/**
|
|
|
|
* Logarithm Graph Creator - Create graphs with logarithm scales.
|
|
|
|
* Copyright (C) 2020 Ad5001
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import QtQml 2.12
|
|
|
|
import QtQuick.Controls 2.12
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
import QtQuick 2.12
|
|
|
|
import "js/objects.js" as Objects
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationWindow {
|
|
|
|
id: root
|
|
|
|
visible: true
|
|
|
|
width: 1000
|
|
|
|
height: 500
|
|
|
|
color: sysPalette.window
|
2021-03-09 10:14:12 +00:00
|
|
|
title: "Logarithmic Plotter " + (settings.saveFilename != "" ? " - " + settings.saveFilename.split('/')[settings.saveFilename.split('/').length -1] : "")
|
2020-12-22 00:01:36 +00:00
|
|
|
|
|
|
|
SystemPalette { id: sysPalette; colorGroup: SystemPalette.Active }
|
|
|
|
SystemPalette { id: sysPaletteIn; colorGroup: SystemPalette.Disabled }
|
|
|
|
|
|
|
|
menuBar: AppMenuBar {}
|
|
|
|
|
|
|
|
Drawer {
|
|
|
|
id: sidebar
|
2020-12-22 22:19:00 +00:00
|
|
|
width: 300
|
2020-12-22 00:01:36 +00:00
|
|
|
height: parent.height
|
|
|
|
y: root.menuBar.height
|
|
|
|
readonly property bool inPortrait: root.width < root.height
|
|
|
|
modal: inPortrait
|
|
|
|
interactive: inPortrait
|
|
|
|
position: inPortrait ? 0 : 1
|
|
|
|
visible: !inPortrait
|
|
|
|
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: topSeparator
|
|
|
|
color: sysPaletteIn.dark
|
|
|
|
width: parent.width
|
2021-03-09 14:01:03 +00:00
|
|
|
height: 0
|
2020-12-22 00:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TabBar {
|
|
|
|
id: sidebarSelector
|
|
|
|
width: parent.width
|
|
|
|
anchors.top: topSeparator.bottom
|
|
|
|
TabButton {
|
2020-12-22 22:19:00 +00:00
|
|
|
text: qsTr("Objects")
|
2020-12-22 00:01:36 +00:00
|
|
|
}
|
|
|
|
TabButton {
|
2020-12-22 22:19:00 +00:00
|
|
|
text: qsTr("Settings")
|
2020-12-22 00:01:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StackLayout {
|
|
|
|
anchors.top: sidebarSelector.bottom
|
2020-12-22 22:19:00 +00:00
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.topMargin: 5
|
|
|
|
anchors.leftMargin: 5
|
|
|
|
width: parent.width - 10
|
2020-12-22 00:01:36 +00:00
|
|
|
height: parent.height - sidebarSelector.height
|
2020-12-22 22:19:00 +00:00
|
|
|
currentIndex: sidebarSelector.currentIndex
|
2020-12-22 17:22:38 +00:00
|
|
|
z: -1
|
|
|
|
clip: true
|
2020-12-22 00:01:36 +00:00
|
|
|
|
|
|
|
ObjectLists {
|
|
|
|
id: objectLists
|
|
|
|
onChanged: drawCanvas.requestPaint()
|
|
|
|
}
|
2020-12-22 22:19:00 +00:00
|
|
|
|
|
|
|
Settings {
|
|
|
|
id: settings
|
|
|
|
onChanged: drawCanvas.requestPaint()
|
|
|
|
}
|
2020-12-22 00:01:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LogGraphCanvas {
|
|
|
|
id: drawCanvas
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.left: sidebar.right
|
|
|
|
height: parent.height
|
|
|
|
width: parent.width - sidebar.position*sidebar.width
|
|
|
|
x: sidebar.position*sidebar.width
|
|
|
|
|
|
|
|
xmin: settings.xmin
|
|
|
|
ymax: settings.ymax
|
|
|
|
xzoom: settings.xzoom
|
|
|
|
yzoom: settings.yzoom
|
|
|
|
xlabel: settings.xaxislabel
|
|
|
|
ylabel: settings.yaxislabel
|
|
|
|
yaxisstep: settings.yaxisstep
|
2020-12-25 18:55:47 +00:00
|
|
|
xaxisstep: settings.xaxisstep
|
2020-12-25 15:44:53 +00:00
|
|
|
logscalex: settings.logscalex
|
2021-01-26 17:36:21 +00:00
|
|
|
showxgrad: settings.showxgrad
|
|
|
|
showygrad: settings.showygrad
|
2020-12-22 00:01:36 +00:00
|
|
|
|
|
|
|
onPaint: {
|
|
|
|
var ctx = getContext("2d");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveDiagram(filename) {
|
2021-03-09 10:14:12 +00:00
|
|
|
settings.saveFilename = filename
|
2020-12-22 00:01:36 +00:00
|
|
|
var objs = {}
|
2020-12-25 22:42:31 +00:00
|
|
|
for(var objType in Objects.currentObjects){
|
2020-12-22 00:01:36 +00:00
|
|
|
objs[objType] = []
|
2020-12-25 22:42:31 +00:00
|
|
|
for(var obj of Objects.currentObjects[objType]) {
|
2020-12-22 00:01:36 +00:00
|
|
|
objs[objType].push(obj.export())
|
2020-12-25 22:42:31 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-22 00:01:36 +00:00
|
|
|
Helper.write(filename, JSON.stringify({
|
|
|
|
"xzoom": settings.xzoom,
|
|
|
|
"yzoom": settings.yzoom,
|
|
|
|
"xmin": settings.xmin,
|
|
|
|
"ymax": settings.ymax,
|
2020-12-25 18:55:47 +00:00
|
|
|
"xaxisstep": settings.xaxisstep,
|
2020-12-22 00:01:36 +00:00
|
|
|
"yaxisstep": settings.yaxisstep,
|
2020-12-22 15:47:48 +00:00
|
|
|
"xaxislabel": settings.xaxislabel,
|
|
|
|
"yaxislabel": settings.yaxislabel,
|
2020-12-25 18:55:47 +00:00
|
|
|
"logscalex": settings.logscalex,
|
2020-12-22 00:01:36 +00:00
|
|
|
"width": root.width,
|
|
|
|
"height": root.height,
|
|
|
|
"objects": objs,
|
2020-12-22 15:47:48 +00:00
|
|
|
"type": "logplotv1"
|
2020-12-22 00:01:36 +00:00
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadDiagram(filename) {
|
|
|
|
var data = JSON.parse(Helper.load(filename))
|
2021-03-09 14:01:03 +00:00
|
|
|
var error = "";
|
2020-12-25 22:42:31 +00:00
|
|
|
if(Object.keys(data).includes("type") && data["type"] == "logplotv1") {
|
2021-03-09 10:14:12 +00:00
|
|
|
settings.saveFilename = filename
|
2020-12-22 00:01:36 +00:00
|
|
|
settings.xzoom = data["xzoom"]
|
|
|
|
settings.yzoom = data["yzoom"]
|
|
|
|
settings.xmin = data["xmin"]
|
|
|
|
settings.ymax = data["ymax"]
|
2020-12-25 18:55:47 +00:00
|
|
|
settings.xaxisstep = data["xaxisstep"]
|
2020-12-22 00:01:36 +00:00
|
|
|
settings.yaxisstep = data["yaxisstep"]
|
2020-12-22 15:47:48 +00:00
|
|
|
settings.xaxislabel = data["xaxislabel"]
|
|
|
|
settings.yaxislabel = data["yaxislabel"]
|
2020-12-25 18:55:47 +00:00
|
|
|
settings.logscalex = data["logscalex"]
|
2020-12-22 00:01:36 +00:00
|
|
|
root.height = data["height"]
|
|
|
|
root.width = data["width"]
|
|
|
|
|
2020-12-24 15:07:27 +00:00
|
|
|
Objects.currentObjects = {}
|
2020-12-25 22:42:31 +00:00
|
|
|
for(var objType in data['objects']) {
|
2021-03-09 14:01:03 +00:00
|
|
|
if(Object.keys(Objects.types).indexOf(objType) > -1) {
|
|
|
|
Objects.currentObjects[objType] = []
|
|
|
|
for(var objData of data['objects'][objType]) {
|
|
|
|
var obj = new Objects.types[objType](...objData)
|
|
|
|
Objects.currentObjects[objType].push(obj)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error += "Unknown object type: " +objType + "\n";
|
2020-12-25 22:42:31 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-22 00:01:36 +00:00
|
|
|
// Refreshing sidebar
|
2020-12-22 22:19:00 +00:00
|
|
|
if(sidebarSelector.currentIndex == 0) {
|
|
|
|
// For some reason, if we load a file while the tab is on object,
|
2021-03-09 14:01:03 +00:00
|
|
|
// we get stuck in a Qt-side loop? Qt bug or side-effect here, I don't know.
|
2020-12-22 22:19:00 +00:00
|
|
|
sidebarSelector.currentIndex = 1
|
|
|
|
objectLists.update()
|
|
|
|
delayRefreshTimer.start()
|
|
|
|
} else {
|
|
|
|
objectLists.update()
|
|
|
|
}
|
2020-12-22 00:01:36 +00:00
|
|
|
}
|
2021-03-09 14:01:03 +00:00
|
|
|
if(error != "") {
|
|
|
|
|
|
|
|
}
|
2020-12-22 00:01:36 +00:00
|
|
|
}
|
|
|
|
|
2020-12-22 22:19:00 +00:00
|
|
|
Timer {
|
|
|
|
id: delayRefreshTimer
|
|
|
|
repeat: false
|
|
|
|
interval: 1
|
|
|
|
onTriggered: sidebarSelector.currentIndex = 0
|
|
|
|
}
|
|
|
|
|
2020-12-22 00:01:36 +00:00
|
|
|
function copyDiagramToClipboard() {
|
|
|
|
var file = Helper.gettmpfile()
|
|
|
|
drawCanvas.save(file)
|
|
|
|
Helper.copyImageToClipboard()
|
|
|
|
}
|
2020-12-22 15:47:48 +00:00
|
|
|
|
|
|
|
|
2020-12-22 00:01:36 +00:00
|
|
|
}
|