Compare commits

..

3 commits

21 changed files with 790 additions and 62 deletions

View file

@ -90,6 +90,9 @@ class Helper(QObject):
data = data[5:]
elif data[0] == "{" and "type" in loads(data) and loads(data)["type"] == "logplotv1":
pass
elif data[:3] == "LPF":
# More recent version of LogarithmPlotter file, but incompatible with the current format
raise Exception(QCoreApplication.translate("This file was created by a more recent version of LogarithmPlotter and cannot be backloaded in LogarithmPlotter v{}.\nPlease update LogarithmPlotter to open this file.".format(__VERSION__)))
else:
raise Exception("Invalid LogarithmPlotter file.")
except Exception as e: # If file can't be loaded
@ -145,7 +148,7 @@ class Helper(QObject):
@Slot()
def fetchChangelog(self):
changelog_cache_path = path.join(path.dirname(path.realpath(__file__), "CHANGELOG.md"))
changelog_cache_path = path.join(path.dirname(path.realpath(__file__)), "CHANGELOG.md")
if path.exists(changelog_cache_path):
# We have a cached version of the changelog, for env that don't have access to the internet.
f = open(changelog_cache_path);
@ -154,5 +157,5 @@ class Helper(QObject):
else:
# Fetch it from the internet.
runnable = ChangelogFetcher(self)
^QThreadPool.globalInstance().start(runnable)
QThreadPool.globalInstance().start(runnable)

View file

@ -22,6 +22,15 @@ import eu.ad5001.MixedMenu 1.1
import "js/objects.js" as Objects
import "js/historylib.js" as HistoryLib
/*!
\qmltype AppMenuBar
\inqmlmodule eu.ad5001.LogarithmPlotter
\brief MenuBar for LogarithmPlotter.
Makes use of eu.ad5001.LogarithmPlotter.
\sa LogarithmPlotter
*/
MenuBar {
Menu {

View file

@ -21,22 +21,60 @@ import QtQml 2.12
import "js/objects.js" as Objects
import "js/historylib.js" as HistoryLib
/*!
\qmltype History
\inqmlmodule eu.ad5001.LogarithmPlotter
\brief QObject holding persistantly for undo & redo stacks.
\sa HistoryBrowser, historylib
*/
Item {
// Using a QtObject is necessary in order to have proper property propagation in QML
id: historyObj
/*!
\qmlproperty int History::undoCount
Count of undo actions.
*/
property int undoCount: 0
/*!
\qmlproperty int History::redoCount
Count of redo actions.
*/
property int redoCount: 0
/*!
\qmlproperty var History::undoStack
Stack of undo actions.
*/
property var undoStack: []
/*!
\qmlproperty var History::redoStack
Stack of redo actions.
*/
property var redoStack: []
// Only true when no modification was done to the current working file.
/*!
\qmlproperty bool History::saved
true when no modification was done to the current working file, false otherwise.
*/
property bool saved: true
/*!
\qmlmethod void History::clear()
Clears both undo and redo stacks completly.
*/
function clear() {
undoCount = 0
redoCount = 0
undoStack = []
redoStack = []
}
/*!
\qmlmethod var History::serialize()
Serializes history into JSON-able content.
*/
function serialize() {
let undoSt = [], redoSt = [];
for(let i = 0; i < undoCount; i++)
@ -52,6 +90,10 @@ Item {
return [undoSt, redoSt]
}
/*!
\qmlmethod void History::unserialize(var undoSt, var redoSt)
Unserializes both \c undoSt stack and \c redoSt stack from serialized content.
*/
function unserialize(undoSt, redoSt) {
clear();
for(let i = 0; i < undoSt.length; i++)
@ -63,7 +105,10 @@ Item {
objectLists.update()
}
/*!
\qmlmethod void History::addToHistory(var action)
Adds an instance of historylib.Action to history.
*/
function addToHistory(action) {
if(action instanceof HistoryLib.Action) {
console.log("Added new entry to history: " + action.getReadableString())
@ -77,6 +122,10 @@ Item {
}
}
/*!
\qmlmethod void History::undo()
Undoes the historylib.Action at the top of the undo stack and pushes it to the top of the redo stack.
*/
function undo() {
if(undoStack.length > 0) {
var action = undoStack.pop()
@ -89,6 +138,10 @@ Item {
}
}
/*!
\qmlmethod void History::redo()
Redoes the historylib.Action at the top of the redo stack and pushes it to the top of the undo stack.
*/
function redo() {
if(redoStack.length > 0) {
var action = redoStack.pop()
@ -101,6 +154,11 @@ Item {
}
}
/*!
\qmlmethod void History::undoMultipleDefered(int toUndoCount)
Undoes several historylib.Action at the top of the undo stack and pushes them to the top of the redo stack.
It undoes them deferedly to avoid overwhelming the computer while creating a cool short accelerated summary of all changes.
*/
function undoMultipleDefered(toUndoCount) {
undoTimer.toUndoCount = toUndoCount;
undoTimer.start()
@ -108,6 +166,12 @@ Item {
saved = false
}
/*!
\qmlmethod void History::redoMultipleDefered(int toRedoCount)
Redoes several historylib.Action at the top of the redo stack and pushes them to the top of the undo stack.
It redoes them deferedly to avoid overwhelming the computer while creating a cool short accelerated summary of all changes.
*/
function redoMultipleDefered(toRedoCount) {
redoTimer.toRedoCount = toRedoCount;
redoTimer.start()

View file

@ -20,11 +20,33 @@ import QtQuick.Controls 2.12
import QtQuick 2.12
import "js/utils.js" as Utils
/*!
\qmltype HistoryBrowser
\inqmlmodule eu.ad5001.LogarithmPlotter
\brief Tab of the drawer that allows to navigate through the undo and redo history.
Creates a scrollable view containing a list of history actions based on the redo stack, then a "Now" indicator
followed by the entirety of the saved undo stack. Each action can be click to restore a state of the graph at
some point of the history.
\sa LogarithmPlotter, Settings, ObjectLists
*/
ScrollView {
id: historyBrowser
/*!
\qmlproperty int HistoryBrowser::actionWidth
Width of the actions.
*/
property int actionWidth: width-20
/*!
\qmlproperty int HistoryBrowser::actionHeight
Height of the actions.
*/
property int actionHeight: 30
Flickable {
width: parent.width
height: parent.height
@ -43,7 +65,7 @@ ScrollView {
Button {
id: redoButton
width: historyBrowser.actionWidth
height: 30
height: actionHeight
flat: true
text: history.redoStack[index].getReadableString()
@ -73,7 +95,7 @@ ScrollView {
anchors.right: parent.right
anchors.top: redoColumn.bottom
width: historyBrowser.actionWidth
height: 30
height: actionHeight
color: sysPalette.highlight
Text {
anchors.verticalCenter: parent.verticalCenter
@ -96,7 +118,7 @@ ScrollView {
Button {
id: undoButton
width: historyBrowser.actionWidth
height: 30
height: actionHeight
flat: true
text: history.undoStack[history.undoCount-index-1].getReadableString()

View file

@ -21,7 +21,15 @@ import "js/objects.js" as Objects
import "js/utils.js" as Utils
import "js/mathlib.js" as MathLib
/*!
\qmltype LogGraphCanvas
\inqmlmodule eu.ad5001.LogarithmPlotter
\brief Canvas used to display the diagram.
Provides a customized canvas with several helper methods to be used by objects.
\sa LogarithmPlotter, PickLocationOverlay
*/
Canvas {
id: canvas
anchors.top: separator.bottom
@ -29,26 +37,124 @@ Canvas {
height: parent.height - 90
width: parent.width
/*!
\qmlproperty double LogGraphCanvas::xmin
Minimum x of the diagram, provided from settings.
\sa Settings
*/
property double xmin: 0
/*!
\qmlproperty double LogGraphCanvas::ymax
Maximum y of the diagram, provided from settings.
\sa Settings
*/
property double ymax: 0
/*!
\qmlproperty double LogGraphCanvas::xzoom
Zoom on the x axis of the diagram, provided from settings.
\sa Settings
*/
property double xzoom: 10
/*!
\qmlproperty double LogGraphCanvas::yzoom
Zoom on the y axis of the diagram, provided from settings.
\sa Settings
*/
property double yzoom: 10
/*!
\qmlproperty string LogGraphCanvas::xaxisstep
Step of the x axis graduation, provided from settings.
\note: Only available in non-logarithmic mode.
\sa Settings
*/
property string xaxisstep: "4"
/*!
\qmlproperty string LogGraphCanvas::yaxisstep
Step of the y axis graduation, provided from settings.
\sa Settings
*/
property string yaxisstep: "4"
/*!
\qmlproperty string LogGraphCanvas::xlabel
Label used on the x axis, provided from settings.
\sa Settings
*/
property string xlabel: ""
/*!
\qmlproperty string LogGraphCanvas::ylabel
Label used on the y axis, provided from settings.
\sa Settings
*/
property string ylabel: ""
property int maxgradx: 20
/*!
\qmlproperty double LogGraphCanvas::linewidth
Width of lines that will be drawn into the canvas, provided from settings.
\sa Settings
*/
property double linewidth: 1
/*!
\qmlproperty double LogGraphCanvas::textsize
Font size of the text that will be drawn into the canvas, provided from settings.
\sa Settings
*/
property double textsize: 14
/*!
\qmlproperty bool LogGraphCanvas::logscalex
true if the canvas should be in logarithmic mode, false otherwise.
Provided from settings.
\sa Settings
*/
property bool logscalex: false
/*!
\qmlproperty bool LogGraphCanvas::showxgrad
true if the x graduation should be shown, false otherwise.
Provided from settings.
\sa Settings
*/
property bool showxgrad: false
/*!
\qmlproperty bool LogGraphCanvas::showygrad
true if the y graduation should be shown, false otherwise.
Provided from settings.
\sa Settings
*/
property bool showygrad: false
/*!
\qmlproperty int LogGraphCanvas::maxgradx
Max power of the logarithmic scaled on the x axis in logarithmic mode.
*/
property int maxgradx: 20
/*!
\qmlproperty var LogGraphCanvas::yaxisstepExpr
Expression for the y axis step (used to create labels).
*/
property var yaxisstepExpr: (new MathLib.Expression(`x*(${yaxisstep})`))
/*!
\qmlproperty double LogGraphCanvas::yaxisstep1
Value of the for the y axis step.
*/
property double yaxisstep1: yaxisstepExpr.execute(1)
/*!
\qmlproperty int LogGraphCanvas::drawMaxY
Minimum value of y that should be drawn onto the canvas.
*/
property int drawMaxY: Math.ceil(Math.max(Math.abs(ymax), Math.abs(px2y(canvasSize.height)))/yaxisstep1)
/*!
\qmlproperty var LogGraphCanvas::xaxisstepExpr
Expression for the x axis step (used to create labels).
*/
property var xaxisstepExpr: (new MathLib.Expression(`x*(${xaxisstep})`))
/*!
\qmlproperty double LogGraphCanvas::xaxisstep1
Value of the for the x axis step.
*/
property double xaxisstep1: xaxisstepExpr.execute(1)
/*!
\qmlproperty int LogGraphCanvas::drawMaxX
Maximum value of x that should be drawn onto the canvas.
*/
property int drawMaxX: Math.ceil(Math.max(Math.abs(xmin), Math.abs(px2x(canvasSize.width)))/xaxisstep1)
@ -71,6 +177,11 @@ Canvas {
}
/*!
\qmlmethod void LogGraphCanvas::reset(var ctx)
Resets the canvas to a blank one with default setting using 2D \c ctx.
*/
function reset(ctx){
// Reset
ctx.fillStyle = "#FFFFFF"
@ -80,6 +191,11 @@ Canvas {
}
// Drawing the log based graph
/*!
\qmlmethod void LogGraphCanvas::drawGrille(var ctx)
Draws the grid using 2D \c ctx.
*/
function drawGrille(ctx) {
ctx.strokeStyle = "#C0C0C0"
if(logscalex) {
@ -100,6 +216,10 @@ Canvas {
}
}
/*!
\qmlmethod void LogGraphCanvas::drawAxises(var ctx)
Draws the graph axises using 2D \c ctx.
*/
function drawAxises(ctx) {
ctx.strokeStyle = "#000000"
var axisypos = logscalex ? 1 : 0
@ -114,6 +234,10 @@ Canvas {
drawLine(ctx, canvasSize.width, axisxpx, canvasSize.width-10, axisxpx+10)
}
/*!
\qmlmethod void LogGraphCanvas::drawLabels(var ctx)
Draws all labels (graduation & axises labels) using 2D \c ctx.
*/
function drawLabels(ctx) {
var axisypx = x2px(logscalex ? 1 : 0) // X coordinate of Y axis
var axisxpx = y2px(0) // Y coordinate of X axis
@ -157,18 +281,31 @@ Canvas {
ctx.fillStyle = "#FFFFFF"
}
/*!
\qmlmethod void LogGraphCanvas::drawXLine(var ctx, double x)
Draws an horizontal line at \c x plot coordinate using 2D \c ctx.
*/
function drawXLine(ctx, x) {
if(visible(x, ymax)) {
drawLine(ctx, x2px(x), 0, x2px(x), canvasSize.height)
}
}
/*!
\qmlmethod void LogGraphCanvas::drawXLine(var ctx, double x)
Draws an vertical line at \c y plot coordinate using 2D \c ctx.
*/
function drawYLine(ctx, y) {
if(visible(xmin, y)) {
drawLine(ctx, 0, y2px(y), canvasSize.width, y2px(y))
}
}
/*!
\qmlmethod void LogGraphCanvas::drawVisibleText(var ctx, string text, double x, double y)
Writes multline \c text onto the canvas using 2D \c ctx.
\note The \c x and \c y properties here are relative to the canvas, not the plot.
*/
function drawVisibleText(ctx, text, x, y) {
if(x > 0 && x < canvasSize.width && y > 0 && y < canvasSize.height) {
text.toString().split("\n").forEach(function(txt, i){
@ -177,7 +314,11 @@ Canvas {
}
}
// Method to calculate multi-line string dimensions
/*!
\qmlmethod var LogGraphCanvas::measureText(var ctx, string text)
Measures the wicth and height of a multiline \c text that would be drawn onto the canvas using 2D \c ctx.
Return format: dictionary {"width": width, "height": height}
*/
function measureText(ctx, text) {
var theight = 0
var twidth = 0
@ -188,32 +329,59 @@ Canvas {
return {'width': twidth, 'height': theight}
}
// Converts x coordinate to it's relative position on the canvas
/*!
\qmlmethod double LogGraphCanvas::x2px(double x)
Converts an \c x coordinate to it's relative position on the canvas.
It supports both logarithmic and non logarithmic scale depending on the currently selected mode.
*/
function x2px(x) {
if(logscalex) {
var logxmin = Math.log(xmin)
return (Math.log(x)-logxmin)*xzoom
} else return (x - xmin)*xzoom
}
// Converts y coordinate to it's relative position on the canvas
// Y is NOT ln based.
/*!
\qmlmethod double LogGraphCanvas::y2px(double y)
Converts an \c y coordinate to it's relative position on the canvas.
The y axis not supporting logarithmic scale, it only support linear convertion.
*/
function y2px(y) {
return (ymax-y)*yzoom
}
// Reverse functions
/*!
\qmlmethod double LogGraphCanvas::px2x(double px)
Converts an x \c px position on the canvas to it's corresponding coordinate on the plot.
It supports both logarithmic and non logarithmic scale depending on the currently selected mode.
*/
function px2x(px) {
if(logscalex) {
return Math.exp(px/xzoom+Math.log(xmin))
} else return (px/xzoom+xmin)
}
/*!
\qmlmethod double LogGraphCanvas::px2x(double px)
Converts an x \c px position on the canvas to it's corresponding coordinate on the plot.
It supports both logarithmic and non logarithmic scale depending on the currently selected mode.
*/
function px2y(px) {
return -(px/yzoom-ymax)
}
// Checks whether a point is visible or not.
/*!
\qmlmethod bool LogGraphCanvas::visible(double x, double y)
Checks whether a plot point (\c x, \c y) is visible or not on the canvas.
*/
function visible(x, y) {
return (x2px(x) >= 0 && x2px(x) <= canvasSize.width) && (y2px(y) >= 0 && y2px(y) <= canvasSize.height)
}
// Draws a line from a (x1, y1) to (x2, y2)
/*!
\qmlmethod bool LogGraphCanvas::drawLine(var ctx, double x1, double y1, double x2, double y2)
Draws a line from plot point (\c x1, \c y1) to plot point (\c x2, \¢ y2) using 2D \c ctx.
*/
function drawLine(ctx, x1, y1, x2, y2) {
ctx.beginPath();
ctx.moveTo(x1, y1);
@ -221,12 +389,21 @@ Canvas {
ctx.stroke();
}
/*!
\qmlmethod bool LogGraphCanvas::drawDashedLine2(var ctx, double x1, double y1, double x2, double y2)
Draws a dashed line from plot point (\c x1, \c y1) to plot point (\c x2, \¢ y2) using 2D \c ctx.
*/
function drawDashedLine2(ctx, x1, y1, x2, y2, dashPxSize = 5) {
ctx.setLineDash([dashPxSize, dashPxSize]);
drawLine(ctx, x1, y1, x2, y2)
ctx.setLineDash([]);
}
/*!
\qmlmethod bool LogGraphCanvas::drawDashedLine(var ctx, double x1, double y1, double x2, double y2)
Draws a dashed line from plot point (\c x1, \c y1) to plot point (\c x2, \¢ y2) using 2D \c ctx.
(Legacy slower method)
*/
function drawDashedLine(ctx, x1, y1, x2, y2, dashPxSize = 10) {
var distance = Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
var progPerc = dashPxSize/distance

View file

@ -28,7 +28,13 @@ import "js/objects.js" as Objects
import eu.ad5001.LogarithmPlotter.ObjectLists 1.0
import eu.ad5001.LogarithmPlotter.Popup 1.0 as Popup
/*!
\qmltype LogarithmPlotter
\inqmlmodule eu.ad5001.LogarithmPlotter
\brief Main window of LogarithmPlotter
\sa AppMenuBar, History, GreetScreen, Changelog, Alert, ObjectLists, Settings, HistoryBrowser, LogGraphCanvas, PickLocationOverlay.
*/
ApplicationWindow {
id: root
visible: true
@ -137,8 +143,8 @@ ApplicationWindow {
ymax: settings.ymax
xzoom: settings.xzoom
yzoom: settings.yzoom
xlabel: settings.xaxislabel
ylabel: settings.yaxislabel
xlabel: settings.xlabel
ylabel: settings.ylabel
yaxisstep: settings.yaxisstep
xaxisstep: settings.xaxisstep
logscalex: settings.logscalex
@ -165,6 +171,10 @@ ApplicationWindow {
}
}
/*!
\qmlmethod void LogarithmPlotter::saveDiagram(string filename)
Saves the diagram to a certain \c filename.
*/
function saveDiagram(filename) {
if(['lpf'].indexOf(filename.split('.')[filename.split('.').length-1]) == -1)
filename += '.lpf'
@ -183,8 +193,8 @@ ApplicationWindow {
"ymax": settings.ymax,
"xaxisstep": settings.xaxisstep,
"yaxisstep": settings.yaxisstep,
"xaxislabel": settings.xaxislabel,
"yaxislabel": settings.yaxislabel,
"xaxislabel": settings.xlabel,
"yaxislabel": settings.ylabel,
"logscalex": settings.logscalex,
"linewidth": settings.linewidth,
"showxgrad": settings.showxgrad,
@ -200,6 +210,10 @@ ApplicationWindow {
history.saved = true
}
/*!
\qmlmethod void LogarithmPlotter::saveDiagram(string filename)
Loads the diagram from a certain \c filename.
*/
function loadDiagram(filename) {
let basename = filename.split("/").pop()
alert.show(qsTr("Loading file '%1'.").arg(basename))
@ -215,8 +229,8 @@ ApplicationWindow {
settings.ymax = data["ymax"]
settings.xaxisstep = data["xaxisstep"]
settings.yaxisstep = data["yaxisstep"]
settings.xaxislabel = data["xaxislabel"]
settings.yaxislabel = data["yaxislabel"]
settings.xlabel = data["xaxislabel"]
settings.ylabel = data["yaxislabel"]
settings.logscalex = data["logscalex"]
if("showxgrad" in data)
settings.showxgrad = data["showxgrad"]
@ -292,6 +306,10 @@ ApplicationWindow {
}
}
/*!
\qmlmethod void LogarithmPlotter::copyDiagramToClipboard()
Copies the current diagram image to the clipboard.
*/
function copyDiagramToClipboard() {
var file = Helper.gettmpfile()
drawCanvas.save(file)
@ -299,6 +317,10 @@ ApplicationWindow {
alert.show(qsTr("Copied plot screenshot to clipboard!"))
}
/*!
\qmlmethod void LogarithmPlotter::showAlert(string alertText)
Shows an alert on the diagram.
*/
function showAlert(alertText) {
// This function is called from the backend and is used to show alerts from there.
alert.show(alertText)
@ -315,6 +337,10 @@ ApplicationWindow {
}
}
/*!
\qmlmethod void LogarithmPlotter::showUpdateMenu()
Shows the update menu in the AppMenuBar.
*/
function showUpdateMenu() {
appMenu.addMenu(updateMenu)
}

View file

@ -26,13 +26,34 @@ import "../js/historylib.js" as HistoryLib
import "../js/utils.js" as Utils
import "../js/mathlib.js" as MathLib
/*!
\qmltype EditorDialog
\inqmlmodule eu.ad5001.LogarithmPlotter.ObjectLists
\brief Dialog used to edit properties of objects.
This class contains the dialog that allows to edit all properties of objects.
\todo In the future, this class should be optimized so that each property doesn't instanciate one instance of each setting type.
\sa LogarithmPlotter, ObjectLists
*/
D.Dialog {
id: objEditor
/*!
\qmlproperty string EditorDialog::objType
Type of object being edited by the dialog.
*/
property string objType: 'Point'
/*!
\qmlproperty int EditorDialog::objIndex
Index of the objects amongst the ones of it's type.
*/
property int objIndex: 0
/*!
\qmlproperty var EditorDialog::obj
Instance of the object being edited.
*/
property var obj: Objects.currentObjects[objType][objIndex]
property QtObject editingRow: QtObject{}
property var objectLists
title: "LogarithmPlotter"
width: 350
height: 400
@ -272,9 +293,13 @@ D.Dialog {
}
}
/*!
\qmlmethod void EditorDialog::show()
Shows the editor after the object to be edited is set.
*/
function show() {
dlgCustomProperties.model = [] // Reset
var objProps = Objects.types[objEditor.objType].properties()
let objProps = Objects.types[objEditor.objType].properties()
dlgCustomProperties.model = Object.keys(objProps).map(prop => [prop, objProps[prop]]) // Converted to 2-dimentional array.
objEditor.open()
}

View file

@ -21,6 +21,13 @@ import QtQuick.Controls 2.12
import "../js/objects.js" as Objects
import "../js/historylib.js" as HistoryLib
/*!
\qmltype ObjectCreationGrid
\inqmlmodule eu.ad5001.LogarithmPlotter.ObjectLists
\brief Grid with buttons to create objects.
\sa LogarithmPlotter, ObjectLists
*/
Column {
id: createRow
property var objectEditor
@ -59,7 +66,6 @@ Column {
objectEditor.obj = Objects.currentObjects[modelData][Objects.currentObjects[modelData].length - 1]
objectEditor.objType = modelData
objectEditor.objIndex = Objects.currentObjects[modelData].length - 1
objectEditor.editingRow = objectLists.listViews[modelData].editingRows[objectEditor.objIndex]
objectEditor.show()
}
}

View file

@ -22,7 +22,17 @@ import QtQuick.Controls 2.12
import "../js/objects.js" as Objects
import "../js/historylib.js" as HistoryLib
/*!
\qmltype ObjectLists
\inqmlmodule eu.ad5001.LogarithmPlotter
\brief Tab of the drawer that allows the user to manage the objects.
This item allows the user to syntheticly see all objects, while giving the user the ability
to show, hide, delete, change the location and color, as well as opening the editor dialog
for each object.
\sa LogarithmPlotter, ObjectCreationGrid, ObjectLists
*/
ListView {
id: objectListList
@ -116,7 +126,7 @@ ListView {
objEditor.obj = Objects.currentObjects[objType][index]
objEditor.objType = objType
objEditor.objIndex = index
objEditor.editingRow = controlRow
//objEditor.editingRow = controlRow
objEditor.show()
}
}
@ -211,7 +221,6 @@ ListView {
// Object editor
EditorDialog {
id: objEditor
objectLists: objectListList
}
// Create items
@ -222,6 +231,10 @@ ListView {
objectLists: objectListList
}
/*!
\qmlmethod void ObjectLists::update()
Updates the view of the ObjectLists.
*/
function update() {
objectListList.changed()
for(var objType in objectListList.listViews) {
@ -229,6 +242,11 @@ ListView {
}
}
/*!
\qmlmethod void ObjectLists::paramTypeIn(var parameter, var types)
Checks if the type of the provided \c parameter is in \c types.
\note The type can be normal string types ('boolean', 'string', 'number'...) or object types (Enum, Dictionay, Object types...). If the latter, only the type of object type should be provided in \c types. E.g: if you want to check if the parameter is an enum, add "Enum" to types.
*/
function paramTypeIn(parameter, types = []) {
if(types.includes(parameter.toString())) return true
if(typeof parameter == 'object' && 'type' in parameter)

View file

@ -22,17 +22,60 @@ import "js/objects.js" as Objects
import "js/mathlib.js" as MathLib
import "js/historylib.js" as HistoryLib
/*!
\qmltype PickLocationOverlay
\inqmlmodule eu.ad5001.LogarithmPlotter
\brief Overlay used to pick a new location for an object.
Provides an overlay over the canvas that can be shown when the user clicks the "Set position" button
on a specific object. It allows the user to pick a new location on the canvas to place the object at.
This overlay allows to set the precision of the pick as well as whether the pick should be on the plot grid.
\sa LogarithmPlotter, LogGraphCanvas
*/
Item {
id: pickerRoot
visible: false
/*!
\qmlproperty var PickLocationOverlay::canvas
logGraphCanvas instance.
*/
property var canvas
/*!
\qmlproperty string PickLocationOverlay::objType
Type of object whose position the user is picking.
*/
property string objType: 'Point'
/*!
\qmlproperty string PickLocationOverlay::objType
Name of the object whose position the user is picking.
*/
property string objName: 'A'
property bool pickY: true
/*!
\qmlproperty bool PickLocationOverlay::pickX
true if the user should be picking a position on the x axis.
*/
property bool pickX: true
/*!
\qmlproperty bool PickLocationOverlay::pickY
true if the user should be picking a position on the y axis.
*/
property bool pickY: true
/*!
\qmlproperty string PickLocationOverlay::propertyX
Name of the object's property whose x value is being changed.
*/
property string propertyX: 'x'
/*!
\qmlproperty string PickLocationOverlay::propertyY
Name of the object's property whose y value is being changed.
*/
property string propertyY: 'y'
/*!
\qmlproperty int PickLocationOverlay::precision
Precision of the picked value (post-dot precision).
*/
property alias precision: precisionSlider.value
Rectangle {

View file

@ -20,7 +20,13 @@ import QtQuick 2.12
import QtQuick.Dialogs 1.3 as D
import QtQuick.Controls 2.12
/*!
\qmltype About
\inqmlmodule eu.ad5001.LogarithmPlotter.Popup
\brief About popup of LogarithmPlotter.
\sa LogarithmPlotter
*/
D.Dialog {
id: about
title: qsTr("About LogarithmPlotter")

View file

@ -17,7 +17,15 @@
*/
import QtQuick 2.12
/*!
\qmltype Alert
\inqmlmodule eu.ad5001.LogarithmPlotter.Popup
\brief Alert used to show status messages to the user.
This class (only one instance) allows messages to be displayed to the user that will fade in time.
\sa LogarithmPlotter
*/
Rectangle {
id: alert
color: "black"
@ -27,8 +35,20 @@ Rectangle {
width: textItem.width + 10
height: textItem.height + 10
/*!
\qmlproperty int Alert::fadingX
X of the object that is being animated.
*/
property int fadingX: parent.width - width - 10
/*!
\qmlproperty int Alert::fadeTime
Length in millisecond of the animation.
*/
property int fadeTime: 200
/*!
\qmlproperty string Alert::text
Text of the alert.
*/
property alias text: textItem.text
Text {
@ -64,6 +84,10 @@ Rectangle {
}
}
/*!
\qmlmethod void Alert::show(string alertText)
Show an alert with a certain \c alertText.
*/
function show(alertText) {
visible = true
fadeTimer.restart()

View file

@ -19,6 +19,15 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
/*!
\qmltype Changelog
\inqmlmodule eu.ad5001.LogarithmPlotter.Popup
\brief Overlay used to display the current changelog to the user.
\note The changelog is either fetched from https://api.ad5001.eu/changelog/logarithmplotter/ or taken locally when a file named CHANGELOG.md exists within the main source code.
\sa LogarithmPlotter, GreetScreen
*/
Popup {
id: changelogPopup
x: (parent.width-width)/2
@ -29,6 +38,10 @@ Popup {
focus: true
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
/*!
\qmlproperty string Changelog::changelogNeedsFetching
true when the changelog has yet to be loaded, set to false the moment it's loaded.
*/
property bool changelogNeedsFetching: true
onAboutToShow: if(changelogNeedsFetching) Helper.fetchChangelog()

View file

@ -18,6 +18,13 @@
import QtQuick.Dialogs 1.3 as D
/*!
\qmltype FileDialog
\inqmlmodule eu.ad5001.LogarithmPlotter.Popup
\brief Dialog used to prompt the user to save or load Logarithm Plot Files.
\sa LogarithmPlotter, Settings
*/
D.FileDialog {
id: fileDialog

View file

@ -19,6 +19,15 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
/*!
\qmltype GreetScreen
\inqmlmodule eu.ad5001.LogarithmPlotter.Popup
\brief Overlay displayed when LogarithmPlotter is launched for the first time or when it was just updated.
It contains several settings as well as an easy access to the changelog
\sa LogarithmPlotter, Settings, AppMenuBar, Changelog
*/
Popup {
id: greetingPopup
x: (parent.width-width)/2

View file

@ -19,20 +19,82 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
/*!
\qmltype ComboBoxSetting
\inqmlmodule eu.ad5001.LogarithmPlotter.Setting
\brief Combo box with an icon and label to make a proper setting.
\sa EditorDialog, Settings, Icon
*/
Item {
id: control
height: 30
/*!
\qmlsignal ComboBoxSetting::activated(int newIndex)
Alias of ComboBox.activated.
The corresponding handler is \c onActivated.
\sa https://doc.qt.io/qt-5/qml-qtquick-controls2-combobox.html#activated-signal
*/
signal activated(int newIndex)
/*!
\qmlsignal ComboBoxSetting::accepted()
Alias of ComboBox.accepted.
The corresponding handler is \c onAccepted.
\sa https://doc.qt.io/qt-5/qml-qtquick-controls2-combobox.html#accepted-signal
*/
signal accepted()
/*!
\qmlproperty string ComboBoxSetting::label
Label of the setting.
*/
property string label: ''
property alias model: combox.model
property alias editable: combox.editable
property alias editText: combox.editText
property alias currentIndex: combox.currentIndex
/*!
\qmlproperty string ComboBoxSetting::icon
Icon path of the setting.
*/
property string icon: ""
/*!
\qmlproperty var ComboBoxSetting::model
Model of the combo box.
\sa https://doc.qt.io/qt-5/qml-qtquick-controls2-combobox.html#model-prop
*/
property alias model: combox.model
/*!
\qmlproperty bool ComboBoxSetting::editable
Whether the combo box accepts user-inputed values.
\sa https://doc.qt.io/qt-5/qml-qtquick-controls2-combobox.html#editable-prop
*/
property alias editable: combox.editable
/*!
\qmlproperty string ComboBoxSetting::editText
Text in the text field of an editable combo box.
\sa https://doc.qt.io/qt-5/qml-qtquick-controls2-combobox.html#editText-prop
*/
property alias editText: combox.editText
/*!
\qmlproperty string ComboBoxSetting::currentIndex
Index of the current item in the combo box.
The default value is -1 when count is 0, and 0 otherwise
\sa https://doc.qt.io/qt-5/qml-qtquick-controls2-combobox.html#currentIndex-prop
*/
property alias currentIndex: combox.currentIndex
/*!
\qmlproperty string ComboBoxSetting::currentIndex
Input text validator for an editable combo box
\sa https://doc.qt.io/qt-5/qml-qtquick-controls2-combobox.html#validator-prop
*/
property alias validator: combox.validator
/*!
\qmlmethod int ComboBoxSetting::find(string elementName)
Returns the index of the specified \a elementName, or -1 if no match is found.
\sa https://doc.qt.io/qt-5/qml-qtquick-controls2-combobox.html#find-method
*/
function find(elementName) {
return combox.find(elementName)
}

View file

@ -18,8 +18,23 @@
import QtQuick 2.7
import QtGraphicalEffects 1.0
/*!
\qmltype Icon
\inqmlmodule eu.ad5001.LogarithmPlotter.Setting
\brief Colorable image.
\sa ComboBoxSetting, ListSetting, TextSetting
*/
Item {
/*!
\qmlproperty string Icon::color
Overlay color of the icon.
*/
property color color: "#000000"
/*!
\qmlproperty string Icon::source
Path of the icon image source.
*/
property alias source: img.source
Image {

View file

@ -2,23 +2,81 @@ import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQml.Models 2.12
/*!
\qmltype ListSetting
\inqmlmodule eu.ad5001.LogarithmPlotter.Setting
\brief Setting to create and edit lists and dictionaries.
\sa EditorDialog, Settings, Icon
*/
Column {
id: control
/*!
\qmlsignal ListSetting::changed()
Emitted when an entry of the setting has been changed.
The corresponding handler is \c onChanged.
*/
signal changed()
/*!
\qmlproperty string ListSetting::label
Label of the setting.
*/
property string label: ''
/*!
\qmlproperty string ListSetting::icon
Icon path of the setting.
*/
property string icon: ''
/*!
\qmlproperty bool ListSetting::dictionaryMode
true to set the export mode to dictionary, false for list.
*/
property bool dictionaryMode: false
/*!
\qmlproperty string ListSetting::keyType
Type for keys for dictionary, can be either "string" or "number".
*/
property string keyType: "string"
/*!
\qmlproperty string ListSetting::keyType
Type for values of the dictionary or list, can be either "string" or "number".
*/
property string valueType: "string"
/*!
\qmlproperty string ListSetting::preKeyLabel
Text to be put before the key for each entry.
*/
property string preKeyLabel: ""
/*!
\qmlproperty string ListSetting::postKeyLabel
Text to be put after the key for each entry. Only for dictionaries.
*/
property string postKeyLabel: ": "
/*!
\qmlproperty var ListSetting::keyRegexp
Regular expression used in the validator for keys. Only for dictionaries.
*/
property var keyRegexp: /^.+$/
/*!
\qmlproperty var ListSetting::valueRegexp
Regular expression used in the validator for values.
*/
property var valueRegexp: /^.+$/
/*!
\qmlproperty bool ListSetting::forbidAdding
If true, prevents the user from adding or removing new entries.
*/
property bool forbidAdding: false
/*!
\qmlproperty bool ListSetting::model
Model of the list/dictionnary, in the form of [{key: < key >, val: < value > }].
Use the \a importModel method to set the model.
*/
property alias model: repeater.model
Row {
@ -165,6 +223,10 @@ Column {
}
}
/*!
\qmlmethod void ListSetting::importModel(var importer)
Imports either a list or a dictionnary in the model.
*/
function importModel(importer) {
model.clear()
for(var key in importer)
@ -174,6 +236,11 @@ Column {
})
}
/*!
\qmlmethod void ListSetting::exportModel()
Exports the model either a list or a dictionnary in the model depending on \a dictionaryMode.
*/
function exportModel() {
if(dictionaryMode) {
var ret = {}

View file

@ -19,18 +19,59 @@
import QtQuick.Controls 2.12
import QtQuick 2.12
/*!
\qmltype TextSetting
\inqmlmodule eu.ad5001.LogarithmPlotter.Setting
\brief Setting to edit strings and numbers.
\sa EditorDialog, Settings, Icon
*/
Item {
id: control
height: 30
/*!
\qmlsignal TextSetting::changed(string newValue)
Emitted when the value of the text has been changed.
The corresponding handler is \c onChanged.
*/
signal changed(string newValue)
/*!
\qmlproperty bool TextSetting::isInt
If true, the input is being parsed an int before being emitting the \a changed signal.
*/
property bool isInt: false
/*!
\qmlproperty bool TextSetting::isDouble
If true, the input is being parsed an double before being emitting the \a changed signal.
*/
property bool isDouble: false
/*!
\qmlproperty double TextSetting::min
Minimum value for numbers that can be entered into the input.
*/
property double min: -1
property string label
/*!
\qmlproperty string TextSetting::defValue
Default value of the input.
*/
property string defValue
/*!
\qmlproperty string TextSetting::value
Value of the input.
*/
property alias value: input.text
/*!
\qmlproperty string TextSetting::label
Label of the setting.
*/
property string label
/*!
\qmlproperty string TextSetting::icon
Icon path of the setting.
*/
property string icon: ""
Icon {

View file

@ -22,6 +22,15 @@ import eu.ad5001.LogarithmPlotter.Setting 1.0 as Setting
import eu.ad5001.LogarithmPlotter.Popup 1.0 as Popup
import "js/utils.js" as Utils
/*!
\qmltype Settings
\inqmlmodule eu.ad5001.LogarithmPlotter
\brief Tab of the drawer that allows the user to customize how the diagram looks.
All canvas settings can found in this scrollable view, as well as buttons to copy and save the graph.
\sa LogarithmPlotter, LogGraphCanvas
*/
ScrollView {
id: settings
@ -30,20 +39,93 @@ ScrollView {
property int settingWidth: settings.width - ScrollBar.vertical.width
property Canvas canvas
/*!
\qmlproperty double Settings::xzoom
Zoom on the x axis of the diagram, provided from settings.
\sa Settings
*/
property double xzoom: 100
/*!
\qmlproperty double Settings::yzoom
Zoom on the y axis of the diagram, provided from settings.
\sa Settings
*/
property double yzoom: 10
/*!
\qmlproperty double Settings::xmin
Minimum x of the diagram, provided from settings.
\sa Settings
*/
property double xmin: 5/10
/*!
\qmlproperty double Settings::ymax
Maximum y of the diagram, provided from settings.
\sa Settings
*/
property double ymax: 25
/*!
\qmlproperty string Settings::xaxisstep
Step of the x axis graduation, provided from settings.
\note: Only available in non-logarithmic mode.
\sa Settings
*/
property string xaxisstep: "4"
/*!
\qmlproperty string Settings::yaxisstep
Step of the y axis graduation, provided from settings.
\sa Settings
*/
property string yaxisstep: "4"
property string xaxislabel: ""
property string yaxislabel: ""
/*!
\qmlproperty string Settings::xlabel
Label used on the x axis, provided from settings.
\sa Settings
*/
property string xlabel: ""
/*!
\qmlproperty string Settings::ylabel
Label used on the y axis, provided from settings.
\sa Settings
*/
property string ylabel: ""
/*!
\qmlproperty double Settings::linewidth
Width of lines that will be drawn into the canvas, provided from settings.
\sa Settings
*/
property double linewidth: 1
/*!
\qmlproperty double Settings::textsize
Font size of the text that will be drawn into the canvas, provided from settings.
\sa Settings
*/
property double textsize: 14
/*!
\qmlproperty bool Settings::logscalex
true if the canvas should be in logarithmic mode, false otherwise.
Provided from settings.
\sa Settings
*/
property bool logscalex: true
property string saveFilename: ""
/*!
\qmlproperty bool Settings::showxgrad
true if the x graduation should be shown, false otherwise.
Provided from settings.
\sa Settings
*/
property bool showxgrad: true
/*!
\qmlproperty bool Settings::showygrad
true if the y graduation should be shown, false otherwise.
Provided from settings.
\sa Settings
*/
property bool showygrad: true
/*!
\qmlproperty bool Settings::saveFilename
Path of the currently opened file. Empty if no file is opened.
*/
property string saveFilename: ""
Column {
spacing: 10
@ -59,10 +141,10 @@ ScrollView {
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
if(xAxisLabel.find(settings.xlabel) == -1) xAxisLabel.model.append({text: settings.xlabel})
xAxisLabel.editText = settings.xlabel
if(yAxisLabel.find(settings.ylabel) == -1) yAxisLabel.model.append({text: settings.ylabel})
yAxisLabel.editText = settings.ylabel
}
}
}
@ -238,19 +320,19 @@ ScrollView {
ListElement { text: "x" }
ListElement { text: "ω (rad/s)" }
}
currentIndex: find(settings.xaxislabel)
currentIndex: find(settings.xlabel)
editable: true
onAccepted: function(){
editText = Utils.parseName(editText, false)
if (find(editText) === -1) model.append({text: editText})
settings.xaxislabel = editText
settings.xlabel = editText
settings.changed()
}
onActivated: function(selectedId) {
settings.xaxislabel = model.get(selectedId).text
settings.xlabel = model.get(selectedId).text
settings.changed()
}
Component.onCompleted: editText = settings.xaxislabel
Component.onCompleted: editText = settings.xlabel
}
Setting.ComboBoxSetting {
@ -267,19 +349,19 @@ ScrollView {
ListElement { text: "φ (deg)" }
ListElement { text: "φ (rad)" }
}
currentIndex: find(settings.yaxislabel)
currentIndex: find(settings.ylabel)
editable: true
onAccepted: function(){
editText = Utils.parseName(editText, false)
if (find(editText) === -1) model.append({text: editText, yaxisstep: root.yaxisstep})
settings.yaxislabel = editText
settings.ylabel = editText
settings.changed()
}
onActivated: function(selectedId) {
settings.yaxislabel = model.get(selectedId).text
settings.ylabel = model.get(selectedId).text
settings.changed()
}
Component.onCompleted: editText = settings.yaxislabel
Component.onCompleted: editText = settings.ylabel
}
CheckBox {
@ -349,21 +431,32 @@ ScrollView {
}
}
/*!
\qmlmethod void LogGraphCanvas::save()
Saves the current canvas in the opened file. If no file is currently opened, prompts to pick a save location.
*/
function save() {
if(settings.saveFilename == "") {
console.log(fdiag, fdiag.exportMode)
fdiag.exportMode = true
fdiag.open()
saveAs()
} else {
root.saveDiagram(settings.saveFilename)
}
}
/*!
\qmlmethod void LogGraphCanvas::saveAs()
Prompts the user to pick a new save location.
*/
function saveAs() {
fdiag.exportMode = true
fdiag.open()
}
/*!
\qmlmethod void LogGraphCanvas::saveAs()
Prompts the user to pick a diagram to load.
*/
function load() {
fdiag.exportMode = false
fdiag.open()

View file

@ -145,10 +145,8 @@ class EditedProperty extends Action {
let prev = "";
let next = "";
if(this.propertyType instanceof Object) {
console.log(this.propertyType.type)
switch(this.propertyType.type) {
case "Enum":
console.log(this.propertyType.translatedValues, this.previousValue, this.propertyType.values.indexOf(this.previousValue))
prev = this.propertyType.translatedValues[this.propertyType.values.indexOf(this.previousValue)]
next = this.propertyType.translatedValues[this.propertyType.values.indexOf(this.newValue)]
break;