Removing typed config functions in Helper.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
2995b2271a
commit
b33e1329db
11 changed files with 53 additions and 149 deletions
|
@ -138,7 +138,7 @@ class HistoryAPI extends Module {
|
||||||
if(action instanceof Action) {
|
if(action instanceof Action) {
|
||||||
console.log("Added new entry to history: " + action.getReadableString())
|
console.log("Added new entry to history: " + action.getReadableString())
|
||||||
this.undoStack.push(action)
|
this.undoStack.push(action)
|
||||||
if(this.#helper.getSettingBool("reset_redo_stack"))
|
if(this.#helper.getSetting("reset_redo_stack"))
|
||||||
this.redoStack = []
|
this.redoStack = []
|
||||||
this.emit(new AddedEvent(action))
|
this.emit(new AddedEvent(action))
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,37 +109,13 @@ export class HelperInterface extends Interface {
|
||||||
/**
|
/**
|
||||||
* Gets a setting from the config
|
* Gets a setting from the config
|
||||||
* @param {string} settingName - Setting (and its dot-separated namespace) to get (e.g. "default_graph.xmin")
|
* @param {string} settingName - Setting (and its dot-separated namespace) to get (e.g. "default_graph.xmin")
|
||||||
* @returns {boolean} Value of the setting
|
* @returns {string|number|boolean} Value of the setting
|
||||||
*/
|
|
||||||
getSettingBool = FUNCTION
|
|
||||||
/**
|
|
||||||
* Gets a setting from the config
|
|
||||||
* @param {string} settingName - Setting (and its dot-separated namespace) to get (e.g. "default_graph.xmin")
|
|
||||||
* @returns {number} Value of the setting
|
|
||||||
*/
|
|
||||||
getSettingInt = FUNCTION
|
|
||||||
/**
|
|
||||||
* Gets a setting from the config
|
|
||||||
* @param {string} settingName - Setting (and its dot-separated namespace) to get (e.g. "default_graph.xmin")
|
|
||||||
* @returns {string} Value of the setting
|
|
||||||
*/
|
*/
|
||||||
getSetting = FUNCTION
|
getSetting = FUNCTION
|
||||||
/**
|
/**
|
||||||
* Sets a setting in the config
|
* Sets a setting in the config
|
||||||
* @param {string} settingName - Setting (and its dot-separated namespace) to set (e.g. "default_graph.xmin")
|
* @param {string} settingName - Setting (and its dot-separated namespace) to set (e.g. "default_graph.xmin")
|
||||||
* @param {boolean} value
|
* @param {string|number|boolean} value
|
||||||
*/
|
|
||||||
setSettingBool = FUNCTION
|
|
||||||
/**
|
|
||||||
* Sets a setting in the config
|
|
||||||
* @param {string} settingName - Setting (and its dot-separated namespace) to set (e.g. "default_graph.xmin")
|
|
||||||
* @param {number} value
|
|
||||||
*/
|
|
||||||
setSettingInt = FUNCTION
|
|
||||||
/**
|
|
||||||
* Sets a setting in the config
|
|
||||||
* @param {string} settingName - Setting (and its dot-separated namespace) to set (e.g. "default_graph.xmin")
|
|
||||||
* @param {string} value
|
|
||||||
*/
|
*/
|
||||||
setSetting = FUNCTION
|
setSetting = FUNCTION
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -81,7 +81,7 @@ class LatexAPI extends Module {
|
||||||
initialize({ latex, helper }) {
|
initialize({ latex, helper }) {
|
||||||
super.initialize({ latex, helper })
|
super.initialize({ latex, helper })
|
||||||
this.#latex = latex
|
this.#latex = latex
|
||||||
this.enabled = helper.getSettingBool("enable_latex")
|
this.enabled = helper.getSetting("enable_latex")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -81,21 +81,9 @@ class SettingsAPI extends Module {
|
||||||
initialize({ helper }) {
|
initialize({ helper }) {
|
||||||
super.initialize({ helper })
|
super.initialize({ helper })
|
||||||
// Initialize default values.
|
// Initialize default values.
|
||||||
for(const key of this.#properties.keys()) {
|
for(const key of this.#properties.keys())
|
||||||
if(!this.#nonConfigurable.includes(key)) {
|
if(!this.#nonConfigurable.includes(key))
|
||||||
switch(typeof this.#properties.get(key)) {
|
|
||||||
case "boolean":
|
|
||||||
this.set(key, helper.getSettingBool("default_graph."+key), false)
|
|
||||||
break
|
|
||||||
case "number":
|
|
||||||
this.set(key, helper.getSettingInt("default_graph."+key), false)
|
|
||||||
break
|
|
||||||
case "string":
|
|
||||||
this.set(key, helper.getSetting("default_graph."+key), false)
|
this.set(key, helper.getSetting("default_graph."+key), false)
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -53,11 +53,11 @@ export class BoolSetting extends Setting {
|
||||||
}
|
}
|
||||||
|
|
||||||
value() {
|
value() {
|
||||||
return Helper.getSettingBool(this.nameInConfig)
|
return Helper.getSetting(this.nameInConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
set(value) {
|
set(value) {
|
||||||
Helper.setSettingBool(this.nameInConfig, value)
|
Helper.setSetting(this.nameInConfig, value === true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,11 +69,11 @@ export class NumberSetting extends Setting {
|
||||||
}
|
}
|
||||||
|
|
||||||
value() {
|
value() {
|
||||||
return Helper.getSettingInt(this.nameInConfig)
|
return Helper.getSetting(this.nameInConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
set(value) {
|
set(value) {
|
||||||
Helper.setSettingInt(this.nameInConfig, value)
|
Helper.setSetting(this.nameInConfig, +value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,11 +84,11 @@ export class EnumIntSetting extends Setting {
|
||||||
}
|
}
|
||||||
|
|
||||||
value() {
|
value() {
|
||||||
return Helper.getSettingInt(this.nameInConfig)
|
return Helper.getSetting(this.nameInConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
set(value) {
|
set(value) {
|
||||||
Helper.setSettingInt(this.nameInConfig, value)
|
Helper.setSetting(this.nameInConfig, +value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,6 +131,6 @@ export class StringSetting extends Setting {
|
||||||
}
|
}
|
||||||
|
|
||||||
set(value) {
|
set(value) {
|
||||||
Helper.setSetting(this.nameInConfig, value)
|
Helper.setSetting(this.nameInConfig, ""+value)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -37,7 +37,7 @@ const XMIN = new NumberSetting(
|
||||||
qsTranslate("Settings", "Min X"),
|
qsTranslate("Settings", "Min X"),
|
||||||
"default_graph.xmin",
|
"default_graph.xmin",
|
||||||
"xmin",
|
"xmin",
|
||||||
() => Helper.getSettingBool("default_graph.logscalex") ? 1e-100 : -Infinity
|
() => Helper.getSetting("default_graph.logscalex") ? 1e-100 : -Infinity
|
||||||
)
|
)
|
||||||
|
|
||||||
const YMAX = new NumberSetting(
|
const YMAX = new NumberSetting(
|
||||||
|
|
|
@ -53,7 +53,13 @@ export class MockHelper {
|
||||||
this.__settings = { ...DEFAULT_SETTINGS }
|
this.__settings = { ...DEFAULT_SETTINGS }
|
||||||
}
|
}
|
||||||
|
|
||||||
__getSetting(settingName) {
|
|
||||||
|
/**
|
||||||
|
* Gets a setting from the config
|
||||||
|
* @param {string} settingName - Setting (and its dot-separated namespace) to get (e.g. "default_graph.xmin")
|
||||||
|
* @returns {string|number|boolean} Value of the setting
|
||||||
|
*/
|
||||||
|
getSetting(settingName) {
|
||||||
const namespace = settingName.split(".")
|
const namespace = settingName.split(".")
|
||||||
let data = this.__settings
|
let data = this.__settings
|
||||||
for(const name of namespace)
|
for(const name of namespace)
|
||||||
|
@ -64,7 +70,12 @@ export class MockHelper {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
__setSetting(settingName, value) {
|
/**
|
||||||
|
* Sets a setting in the config
|
||||||
|
* @param {string} settingName - Setting (and its dot-separated namespace) to set (e.g. "default_graph.xmin")
|
||||||
|
* @param {string|number|boolean} value
|
||||||
|
*/
|
||||||
|
setSetting(settingName, value) {
|
||||||
const namespace = settingName.split(".")
|
const namespace = settingName.split(".")
|
||||||
const finalName = namespace.pop()
|
const finalName = namespace.pop()
|
||||||
let data = this.__settings
|
let data = this.__settings
|
||||||
|
@ -76,60 +87,6 @@ export class MockHelper {
|
||||||
data[finalName] = value
|
data[finalName] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a setting from the config
|
|
||||||
* @param {string} settingName - Setting (and its dot-separated namespace) to get (e.g. "default_graph.xmin")
|
|
||||||
* @returns {boolean} Value of the setting
|
|
||||||
*/
|
|
||||||
getSettingBool(settingName) {
|
|
||||||
return this.__getSetting(settingName) === true
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a setting from the config
|
|
||||||
* @param {string} settingName - Setting (and its dot-separated namespace) to get (e.g. "default_graph.xmin")
|
|
||||||
* @returns {number} Value of the setting
|
|
||||||
*/
|
|
||||||
getSettingInt(settingName) {
|
|
||||||
return +(this.__getSetting(settingName))
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a setting from the config
|
|
||||||
* @param {string} settingName - Setting (and its dot-separated namespace) to get (e.g. "default_graph.xmin")
|
|
||||||
* @returns {string} Value of the setting
|
|
||||||
*/
|
|
||||||
getSetting(settingName) {
|
|
||||||
return this.__getSetting(settingName).toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a setting in the config
|
|
||||||
* @param {string} settingName - Setting (and its dot-separated namespace) to set (e.g. "default_graph.xmin")
|
|
||||||
* @param {boolean} value
|
|
||||||
*/
|
|
||||||
setSettingBool(settingName, value) {
|
|
||||||
return this.__setSetting(settingName, value === true)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a setting in the config
|
|
||||||
* @param {string} settingName - Setting (and its dot-separated namespace) to set (e.g. "default_graph.xmin")
|
|
||||||
* @param {number} value
|
|
||||||
*/
|
|
||||||
setSettingInt(settingName, value) {
|
|
||||||
return this.__setSetting(settingName, +(value))
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a setting in the config
|
|
||||||
* @param {string} settingName - Setting (and its dot-separated namespace) to set (e.g. "default_graph.xmin")
|
|
||||||
* @param {string} value
|
|
||||||
*/
|
|
||||||
setSetting(settingName, value) {
|
|
||||||
return this.__setSetting(settingName, value.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends data to be written
|
* Sends data to be written
|
||||||
* @param {string} file
|
* @param {string} file
|
||||||
|
|
|
@ -221,9 +221,9 @@ Item {
|
||||||
focus: true
|
focus: true
|
||||||
selectByMouse: true
|
selectByMouse: true
|
||||||
|
|
||||||
property bool autocompleteEnabled: Helper.getSettingBool("autocompletion.enabled")
|
property bool autocompleteEnabled: Helper.getSetting("autocompletion.enabled")
|
||||||
property bool syntaxHighlightingEnabled: Helper.getSettingBool("expression_editor.colorize")
|
property bool syntaxHighlightingEnabled: Helper.getSetting("expression_editor.colorize")
|
||||||
property bool autoClosing: Helper.getSettingBool("expression_editor.autoclose")
|
property bool autoClosing: Helper.getSetting("expression_editor.autoclose")
|
||||||
property var tokens: autocompleteEnabled || syntaxHighlightingEnabled ? parent.tokens(text) : []
|
property var tokens: autocompleteEnabled || syntaxHighlightingEnabled ? parent.tokens(text) : []
|
||||||
|
|
||||||
Keys.priority: Keys.BeforeItem // Required for knowing which key the user presses.
|
Keys.priority: Keys.BeforeItem // Required for knowing which key the user presses.
|
||||||
|
@ -600,7 +600,7 @@ Item {
|
||||||
*/
|
*/
|
||||||
function colorize(tokenList) {
|
function colorize(tokenList) {
|
||||||
let parsedText = ""
|
let parsedText = ""
|
||||||
let scheme = colorSchemes[Helper.getSettingInt("expression_editor.color_scheme")]
|
let scheme = colorSchemes[Helper.getSetting("expression_editor.color_scheme")]
|
||||||
for(let token of tokenList) {
|
for(let token of tokenList) {
|
||||||
switch(token.type) {
|
switch(token.type) {
|
||||||
case JS.Parsing.TokenType.VARIABLE:
|
case JS.Parsing.TokenType.VARIABLE:
|
||||||
|
|
|
@ -44,25 +44,25 @@ ScrollView {
|
||||||
Zoom on the x axis of the diagram, provided from settings.
|
Zoom on the x axis of the diagram, provided from settings.
|
||||||
\sa Settings
|
\sa Settings
|
||||||
*/
|
*/
|
||||||
property double xzoom: Helper.getSettingInt('default_graph.xzoom')
|
property double xzoom: Helper.getSetting('default_graph.xzoom')
|
||||||
/*!
|
/*!
|
||||||
\qmlproperty double Settings::yzoom
|
\qmlproperty double Settings::yzoom
|
||||||
Zoom on the y axis of the diagram, provided from settings.
|
Zoom on the y axis of the diagram, provided from settings.
|
||||||
\sa Settings
|
\sa Settings
|
||||||
*/
|
*/
|
||||||
property double yzoom: Helper.getSettingInt('default_graph.yzoom')
|
property double yzoom: Helper.getSetting('default_graph.yzoom')
|
||||||
/*!
|
/*!
|
||||||
\qmlproperty double Settings::xmin
|
\qmlproperty double Settings::xmin
|
||||||
Minimum x of the diagram, provided from settings.
|
Minimum x of the diagram, provided from settings.
|
||||||
\sa Settings
|
\sa Settings
|
||||||
*/
|
*/
|
||||||
property double xmin: Helper.getSettingInt('default_graph.xmin')
|
property double xmin: Helper.getSetting('default_graph.xmin')
|
||||||
/*!
|
/*!
|
||||||
\qmlproperty double Settings::ymax
|
\qmlproperty double Settings::ymax
|
||||||
Maximum y of the diagram, provided from settings.
|
Maximum y of the diagram, provided from settings.
|
||||||
\sa Settings
|
\sa Settings
|
||||||
*/
|
*/
|
||||||
property double ymax: Helper.getSettingInt('default_graph.ymax')
|
property double ymax: Helper.getSetting('default_graph.ymax')
|
||||||
/*!
|
/*!
|
||||||
\qmlproperty string Settings::xaxisstep
|
\qmlproperty string Settings::xaxisstep
|
||||||
Step of the x axis graduation, provided from settings.
|
Step of the x axis graduation, provided from settings.
|
||||||
|
@ -93,34 +93,34 @@ ScrollView {
|
||||||
Width of lines that will be drawn into the canvas, provided from settings.
|
Width of lines that will be drawn into the canvas, provided from settings.
|
||||||
\sa Settings
|
\sa Settings
|
||||||
*/
|
*/
|
||||||
property double linewidth: Helper.getSettingInt('default_graph.linewidth')
|
property double linewidth: Helper.getSetting('default_graph.linewidth')
|
||||||
/*!
|
/*!
|
||||||
\qmlproperty double Settings::textsize
|
\qmlproperty double Settings::textsize
|
||||||
Font size of the text that will be drawn into the canvas, provided from settings.
|
Font size of the text that will be drawn into the canvas, provided from settings.
|
||||||
\sa Settings
|
\sa Settings
|
||||||
*/
|
*/
|
||||||
property double textsize: Helper.getSettingInt('default_graph.textsize')
|
property double textsize: Helper.getSetting('default_graph.textsize')
|
||||||
/*!
|
/*!
|
||||||
\qmlproperty bool Settings::logscalex
|
\qmlproperty bool Settings::logscalex
|
||||||
true if the canvas should be in logarithmic mode, false otherwise.
|
true if the canvas should be in logarithmic mode, false otherwise.
|
||||||
Provided from settings.
|
Provided from settings.
|
||||||
\sa Settings
|
\sa Settings
|
||||||
*/
|
*/
|
||||||
property bool logscalex: Helper.getSettingBool('default_graph.logscalex')
|
property bool logscalex: Helper.getSetting('default_graph.logscalex')
|
||||||
/*!
|
/*!
|
||||||
\qmlproperty bool Settings::showxgrad
|
\qmlproperty bool Settings::showxgrad
|
||||||
true if the x graduation should be shown, false otherwise.
|
true if the x graduation should be shown, false otherwise.
|
||||||
Provided from settings.
|
Provided from settings.
|
||||||
\sa Settings
|
\sa Settings
|
||||||
*/
|
*/
|
||||||
property bool showxgrad: Helper.getSettingBool('default_graph.showxgrad')
|
property bool showxgrad: Helper.getSetting('default_graph.showxgrad')
|
||||||
/*!
|
/*!
|
||||||
\qmlproperty bool Settings::showygrad
|
\qmlproperty bool Settings::showygrad
|
||||||
true if the y graduation should be shown, false otherwise.
|
true if the y graduation should be shown, false otherwise.
|
||||||
Provided from settings.
|
Provided from settings.
|
||||||
\sa Settings
|
\sa Settings
|
||||||
*/
|
*/
|
||||||
property bool showygrad: Helper.getSettingBool('default_graph.showygrad')
|
property bool showygrad: Helper.getSetting('default_graph.showygrad')
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
spacing: 10
|
spacing: 10
|
||||||
|
|
|
@ -15,10 +15,9 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from PySide6.QtWidgets import QMessageBox, QApplication
|
from PySide6.QtWidgets import QMessageBox, QApplication
|
||||||
from PySide6.QtCore import QRunnable, QThreadPool, QThread, QObject, Signal, Slot, QCoreApplication
|
from PySide6.QtCore import QRunnable, QThreadPool, QThread, QObject, Signal, Slot, QCoreApplication
|
||||||
from PySide6.QtQml import QQmlApplicationEngine
|
from PySide6.QtQml import QJSValue
|
||||||
from PySide6.QtGui import QImage
|
from PySide6.QtGui import QImage
|
||||||
from PySide6 import __version__ as PySide6_version
|
from PySide6 import __version__ as PySide6_version
|
||||||
|
|
||||||
|
@ -135,29 +134,13 @@ class Helper(QObject):
|
||||||
def getVersion(self):
|
def getVersion(self):
|
||||||
return __VERSION__
|
return __VERSION__
|
||||||
|
|
||||||
@Slot(str, result=str)
|
@Slot(str, result=QJSValue)
|
||||||
def getSetting(self, namespace):
|
def getSetting(self, namespace: str) -> QJSValue:
|
||||||
return str(config.getSetting(namespace))
|
return QJSValue(config.getSetting(namespace))
|
||||||
|
|
||||||
@Slot(str, result=float)
|
@Slot(str, QJSValue)
|
||||||
def getSettingInt(self, namespace):
|
def setSetting(self, namespace: str, value: QJSValue):
|
||||||
return float(config.getSetting(namespace))
|
return config.setSetting(namespace, value.toPrimitive().toVariant())
|
||||||
|
|
||||||
@Slot(str, result=bool)
|
|
||||||
def getSettingBool(self, namespace):
|
|
||||||
return bool(config.getSetting(namespace))
|
|
||||||
|
|
||||||
@Slot(str, str)
|
|
||||||
def setSetting(self, namespace, value):
|
|
||||||
return config.setSetting(namespace, str(value))
|
|
||||||
|
|
||||||
@Slot(str, bool)
|
|
||||||
def setSettingBool(self, namespace, value):
|
|
||||||
return config.setSetting(namespace, bool(value))
|
|
||||||
|
|
||||||
@Slot(str, float)
|
|
||||||
def setSettingInt(self, namespace, value):
|
|
||||||
return config.setSetting(namespace, float(value))
|
|
||||||
|
|
||||||
@Slot(result=str)
|
@Slot(result=str)
|
||||||
def getDebugInfos(self):
|
def getDebugInfos(self):
|
||||||
|
|
|
@ -158,16 +158,16 @@ class TestHelper:
|
||||||
obj = Helper(pwd, tmpfile)
|
obj = Helper(pwd, tmpfile)
|
||||||
assert obj.getVersion() == version
|
assert obj.getVersion() == version
|
||||||
assert type(obj.getDebugInfos()) == str
|
assert type(obj.getDebugInfos()) == str
|
||||||
assert type(obj.getSetting("check_for_updates")) == str
|
assert type(obj.getSetting("last_install_greet").toVariant()) == str
|
||||||
assert type(obj.getSettingInt("check_for_updates")) == float
|
assert type(obj.getSetting("check_for_updates").toVariant()) == bool
|
||||||
assert type(obj.getSettingBool("check_for_updates")) == bool
|
assert type(obj.getSetting("default_graph.xzoom").toVariant()) in [float, int]
|
||||||
|
|
||||||
def test_set_config(self, temporary):
|
def test_set_config(self, temporary):
|
||||||
tmpfile, directory = temporary
|
tmpfile, directory = temporary
|
||||||
obj = Helper(pwd, tmpfile)
|
obj = Helper(pwd, tmpfile)
|
||||||
obj.setSetting("last_install_greet", obj.getSetting("last_install_greet"))
|
obj.setSetting("last_install_greet", obj.getSetting("last_install_greet"))
|
||||||
obj.setSettingBool("check_for_updates", obj.getSettingBool("check_for_updates"))
|
obj.setSetting("check_for_updates", obj.getSetting("check_for_updates"))
|
||||||
obj.setSettingInt("default_graph.xzoom", obj.getSettingInt("default_graph.xzoom"))
|
obj.setSetting("default_graph.xzoom", obj.getSetting("default_graph.xzoom"))
|
||||||
|
|
||||||
def test_fetch_changelog(self, temporary, qtbot):
|
def test_fetch_changelog(self, temporary, qtbot):
|
||||||
tmpfile, directory = temporary
|
tmpfile, directory = temporary
|
||||||
|
|
Loading…
Reference in a new issue