LogarithmPlotter/qml/Settings.qml

291 lines
8.7 KiB
QML
Raw Normal View History

/**
* 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 QtQuick.Controls 2.12
import QtQuick 2.12
2020-12-22 17:22:38 +00:00
import "js/utils.js" as Utils
2021-03-09 19:37:12 +00:00
ScrollView {
id: settings
signal changed()
property int settingWidth: settings.width
property int xzoom: 100
property int yzoom: 10
property double xmin: 5/10
property double ymax: 25
property string xaxisstep: "4"
property string yaxisstep: "4"
property string xaxislabel: ""
property string yaxislabel: ""
property bool logscalex: true
property string saveFilename: ""
2021-01-26 17:36:21 +00:00
property bool showxgrad: true
property bool showygrad: true
2021-03-09 19:37:12 +00:00
Column {
height: 30*9 //30*Math.max(1, Math.ceil(7 / columns))
//columns: Math.floor(width / settingWidth)
spacing: 10
FileDialog {
id: fdiag
onAccepted: {
var filePath = fileUrl.toString().substr(7)
settings.saveFilename = filePath
if(exportMode) {
root.saveDiagram(filePath)
} else {
root.loadDiagram(filePath)
if(xAxisLabel.find(settings.xaxislabel) == -1) xAxisLabel.model.append({text: settings.xaxislabel})
xAxisLabel.editText = settings.xaxislabel
if(yAxisLabel.find(settings.yaxislabel) == -1) yAxisLabel.model.append({text: settings.yaxislabel})
yAxisLabel.editText = settings.yaxislabel
}
}
}
2021-03-09 19:37:12 +00:00
// Line 1
// Zoom
TextSetting {
id: zoomX
height: 30
isInt: true
label: "X Zoom"
min: 1
width: settings.settingWidth
defValue: settings.xzoom
onChanged: function(newValue) {
settings.xzoom = newValue
settings.changed()
}
}
2021-03-31 13:58:21 +00:00
2021-03-09 19:37:12 +00:00
TextSetting {
id: zoomY
height: 30
isInt: true
label: "Y Zoom"
width: settings.settingWidth
defValue: settings.yzoom
onChanged: function(newValue) {
settings.yzoom = newValue
settings.changed()
}
}
2021-03-31 13:58:21 +00:00
2021-03-09 19:37:12 +00:00
// Positioning the graph
TextSetting {
id: minX
height: 30
isDouble: true
min: -Infinity
label: "Min X"
2021-03-31 13:58:21 +00:00
icon: "icons/settings/xmin.svg"
2021-03-09 19:37:12 +00:00
width: settings.settingWidth
defValue: settings.xmin
onChanged: function(newValue) {
settings.xmin = newValue
settings.changed()
}
}
2021-03-31 13:58:21 +00:00
2021-03-09 19:37:12 +00:00
TextSetting {
id: maxY
height: 30
isDouble: true
label: "Max Y"
2021-03-31 13:58:21 +00:00
icon: "icons/settings/ymax.svg"
2021-03-09 19:37:12 +00:00
width: settings.settingWidth
defValue: settings.ymax
onChanged: function(newValue) {
settings.ymax = newValue
settings.changed()
}
}
2021-03-31 13:58:21 +00:00
2021-03-09 19:37:12 +00:00
TextSetting {
id: yAxisStep
height: 30
label: "Y Axis Step"
2021-03-31 13:58:21 +00:00
icon: "icons/settings/yaxisstep.svg"
2021-03-09 19:37:12 +00:00
width: settings.settingWidth
defValue: settings.yaxisstep
onChanged: function(newValue) {
settings.yaxisstep = newValue
settings.changed()
}
}
2021-03-09 19:37:12 +00:00
TextSetting {
id: xAxisStep
height: 30
label: "X Axis Step"
2021-03-31 13:58:21 +00:00
icon: "icons/settings/xaxisstep.svg"
2021-03-09 19:37:12 +00:00
width: settings.settingWidth
defValue: settings.xaxisstep
visible: !settings.logscalex
onChanged: function(newValue) {
settings.xaxisstep = newValue
settings.changed()
}
}
2021-03-09 19:37:12 +00:00
ComboBoxSetting {
id: xAxisLabel
height: 30
width: settings.settingWidth
label: 'X Label'
2021-03-31 13:58:21 +00:00
icon: "icons/settings/xlabel.svg"
2021-03-09 19:37:12 +00:00
model: ListModel {
ListElement { text: "" }
ListElement { text: "x" }
ListElement { text: "ω (rad/s)" }
}
currentIndex: find(settings.xaxislabel)
editable: true
onAccepted: function(){
editText = Utils.parseName(editText, false)
if (find(editText) === -1) model.append({text: editText})
settings.xaxislabel = editText
settings.changed()
}
onActivated: function(selectedId) {
settings.xaxislabel = model.get(selectedId).text
settings.changed()
}
Component.onCompleted: editText = settings.xaxislabel
}
2021-03-09 19:37:12 +00:00
ComboBoxSetting {
id: yAxisLabel
height: 30
width: settings.settingWidth
label: 'Y Label'
2021-03-31 13:58:21 +00:00
icon: "icons/settings/ylabel.svg"
2021-03-09 19:37:12 +00:00
model: ListModel {
ListElement { text: "" }
ListElement { text: "y" }
ListElement { text: "G (dB)" }
ListElement { text: "φ (°)" }
ListElement { text: "φ (deg)" }
ListElement { text: "φ (rad)" }
}
currentIndex: find(settings.yaxislabel)
editable: true
onAccepted: function(){
editText = Utils.parseName(editText, false)
if (find(editText) === -1) model.append({text: editText, yaxisstep: root.yaxisstep})
settings.yaxislabel = editText
settings.changed()
}
onActivated: function(selectedId) {
settings.yaxislabel = model.get(selectedId).text
settings.changed()
}
Component.onCompleted: editText = settings.yaxislabel
}
2021-03-09 19:37:12 +00:00
CheckBox {
id: logScaleX
checked: settings.logscalex
text: 'X Log scale'
onClicked: {
settings.logscalex = checked
settings.changed()
}
}
2021-03-09 19:37:12 +00:00
CheckBox {
id: showXGrad
checked: settings.showxgrad
text: 'Show X graduation'
onClicked: {
settings.showxgrad = checked
settings.changed()
}
}
2021-03-09 19:37:12 +00:00
CheckBox {
id: showYGrad
checked: settings.showygrad
text: 'Show Y graduation'
onClicked: {
settings.showygrad = checked
settings.changed()
}
}
2021-03-09 19:37:12 +00:00
Button {
id: copyToClipboard
height: 30
width: settings.settingWidth
text: "Copy to clipboard"
icon.name: 'editcopy'
onClicked: root.copyDiagramToClipboard()
}
2021-03-09 19:37:12 +00:00
Button {
id: saveDiagram
height: 30
width: settings.settingWidth
text: "Save diagram"
icon.name: 'filesave'
onClicked: save()
}
2021-03-09 19:37:12 +00:00
Button {
id: saveDiagramAs
height: 30
width: settings.settingWidth
text: "Save diagram as"
icon.name: 'filesaveas'
onClicked: saveAs()
2021-01-26 17:36:21 +00:00
}
2021-03-09 19:37:12 +00:00
Button {
id: loadDiagram
height: 30
width: settings.settingWidth
text: "Load diagram"
icon.name: 'fileopen'
onClicked: load()
2021-01-26 17:36:21 +00:00
}
}
function save() {
if(settings.saveFilename == "") {
fdiag.exportMode = true
fdiag.open()
} else {
root.saveDiagram(settings.saveFilename)
}
}
function saveAs() {
fdiag.exportMode = true
fdiag.open()
}
function load() {
fdiag.exportMode = false
fdiag.open()
}
}