Removing typed config functions in Helper.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Adsooi 2024-10-14 23:22:57 +02:00
parent 2995b2271a
commit b33e1329db
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
11 changed files with 53 additions and 149 deletions

View file

@ -138,7 +138,7 @@ class HistoryAPI extends Module {
if(action instanceof Action) {
console.log("Added new entry to history: " + action.getReadableString())
this.undoStack.push(action)
if(this.#helper.getSettingBool("reset_redo_stack"))
if(this.#helper.getSetting("reset_redo_stack"))
this.redoStack = []
this.emit(new AddedEvent(action))
}

View file

@ -109,37 +109,13 @@ export class HelperInterface extends Interface {
/**
* 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 = 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
* @returns {string|number|boolean} Value of the setting
*/
getSetting = FUNCTION
/**
* 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 = 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
* @param {string|number|boolean} value
*/
setSetting = FUNCTION
/**

View file

@ -81,7 +81,7 @@ class LatexAPI extends Module {
initialize({ latex, helper }) {
super.initialize({ latex, helper })
this.#latex = latex
this.enabled = helper.getSettingBool("enable_latex")
this.enabled = helper.getSetting("enable_latex")
}
/**

View file

@ -81,21 +81,9 @@ class SettingsAPI extends Module {
initialize({ helper }) {
super.initialize({ helper })
// Initialize default values.
for(const key of this.#properties.keys()) {
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":
for(const key of this.#properties.keys())
if(!this.#nonConfigurable.includes(key))
this.set(key, helper.getSetting("default_graph."+key), false)
break
}
}
}
}
/**

View file

@ -53,11 +53,11 @@ export class BoolSetting extends Setting {
}
value() {
return Helper.getSettingBool(this.nameInConfig)
return Helper.getSetting(this.nameInConfig)
}
set(value) {
Helper.setSettingBool(this.nameInConfig, value)
Helper.setSetting(this.nameInConfig, value === true)
}
}
@ -69,11 +69,11 @@ export class NumberSetting extends Setting {
}
value() {
return Helper.getSettingInt(this.nameInConfig)
return Helper.getSetting(this.nameInConfig)
}
set(value) {
Helper.setSettingInt(this.nameInConfig, value)
Helper.setSetting(this.nameInConfig, +value)
}
}
@ -84,11 +84,11 @@ export class EnumIntSetting extends Setting {
}
value() {
return Helper.getSettingInt(this.nameInConfig)
return Helper.getSetting(this.nameInConfig)
}
set(value) {
Helper.setSettingInt(this.nameInConfig, value)
Helper.setSetting(this.nameInConfig, +value)
}
}
@ -131,6 +131,6 @@ export class StringSetting extends Setting {
}
set(value) {
Helper.setSetting(this.nameInConfig, value)
Helper.setSetting(this.nameInConfig, ""+value)
}
}

View file

@ -37,7 +37,7 @@ const XMIN = new NumberSetting(
qsTranslate("Settings", "Min X"),
"default_graph.xmin",
"xmin",
() => Helper.getSettingBool("default_graph.logscalex") ? 1e-100 : -Infinity
() => Helper.getSetting("default_graph.logscalex") ? 1e-100 : -Infinity
)
const YMAX = new NumberSetting(

View file

@ -53,7 +53,13 @@ export class MockHelper {
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(".")
let data = this.__settings
for(const name of namespace)
@ -64,7 +70,12 @@ export class MockHelper {
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 finalName = namespace.pop()
let data = this.__settings
@ -76,60 +87,6 @@ export class MockHelper {
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
* @param {string} file

View file

@ -221,9 +221,9 @@ Item {
focus: true
selectByMouse: true
property bool autocompleteEnabled: Helper.getSettingBool("autocompletion.enabled")
property bool syntaxHighlightingEnabled: Helper.getSettingBool("expression_editor.colorize")
property bool autoClosing: Helper.getSettingBool("expression_editor.autoclose")
property bool autocompleteEnabled: Helper.getSetting("autocompletion.enabled")
property bool syntaxHighlightingEnabled: Helper.getSetting("expression_editor.colorize")
property bool autoClosing: Helper.getSetting("expression_editor.autoclose")
property var tokens: autocompleteEnabled || syntaxHighlightingEnabled ? parent.tokens(text) : []
Keys.priority: Keys.BeforeItem // Required for knowing which key the user presses.
@ -600,7 +600,7 @@ Item {
*/
function colorize(tokenList) {
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) {
switch(token.type) {
case JS.Parsing.TokenType.VARIABLE:

View file

@ -44,25 +44,25 @@ ScrollView {
Zoom on the x axis of the diagram, provided from settings.
\sa Settings
*/
property double xzoom: Helper.getSettingInt('default_graph.xzoom')
property double xzoom: Helper.getSetting('default_graph.xzoom')
/*!
\qmlproperty double Settings::yzoom
Zoom on the y axis of the diagram, provided from settings.
\sa Settings
*/
property double yzoom: Helper.getSettingInt('default_graph.yzoom')
property double yzoom: Helper.getSetting('default_graph.yzoom')
/*!
\qmlproperty double Settings::xmin
Minimum x of the diagram, provided from settings.
\sa Settings
*/
property double xmin: Helper.getSettingInt('default_graph.xmin')
property double xmin: Helper.getSetting('default_graph.xmin')
/*!
\qmlproperty double Settings::ymax
Maximum y of the diagram, provided from settings.
\sa Settings
*/
property double ymax: Helper.getSettingInt('default_graph.ymax')
property double ymax: Helper.getSetting('default_graph.ymax')
/*!
\qmlproperty string Settings::xaxisstep
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.
\sa Settings
*/
property double linewidth: Helper.getSettingInt('default_graph.linewidth')
property double linewidth: Helper.getSetting('default_graph.linewidth')
/*!
\qmlproperty double Settings::textsize
Font size of the text that will be drawn into the canvas, provided from settings.
\sa Settings
*/
property double textsize: Helper.getSettingInt('default_graph.textsize')
property double textsize: Helper.getSetting('default_graph.textsize')
/*!
\qmlproperty bool Settings::logscalex
true if the canvas should be in logarithmic mode, false otherwise.
Provided from settings.
\sa Settings
*/
property bool logscalex: Helper.getSettingBool('default_graph.logscalex')
property bool logscalex: Helper.getSetting('default_graph.logscalex')
/*!
\qmlproperty bool Settings::showxgrad
true if the x graduation should be shown, false otherwise.
Provided from settings.
\sa Settings
*/
property bool showxgrad: Helper.getSettingBool('default_graph.showxgrad')
property bool showxgrad: Helper.getSetting('default_graph.showxgrad')
/*!
\qmlproperty bool Settings::showygrad
true if the y graduation should be shown, false otherwise.
Provided from settings.
\sa Settings
*/
property bool showygrad: Helper.getSettingBool('default_graph.showygrad')
property bool showygrad: Helper.getSetting('default_graph.showygrad')
Column {
spacing: 10

View file

@ -15,10 +15,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from PySide6.QtWidgets import QMessageBox, QApplication
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 import __version__ as PySide6_version
@ -135,29 +134,13 @@ class Helper(QObject):
def getVersion(self):
return __VERSION__
@Slot(str, result=str)
def getSetting(self, namespace):
return str(config.getSetting(namespace))
@Slot(str, result=QJSValue)
def getSetting(self, namespace: str) -> QJSValue:
return QJSValue(config.getSetting(namespace))
@Slot(str, result=float)
def getSettingInt(self, namespace):
return float(config.getSetting(namespace))
@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(str, QJSValue)
def setSetting(self, namespace: str, value: QJSValue):
return config.setSetting(namespace, value.toPrimitive().toVariant())
@Slot(result=str)
def getDebugInfos(self):

View file

@ -158,16 +158,16 @@ class TestHelper:
obj = Helper(pwd, tmpfile)
assert obj.getVersion() == version
assert type(obj.getDebugInfos()) == str
assert type(obj.getSetting("check_for_updates")) == str
assert type(obj.getSettingInt("check_for_updates")) == float
assert type(obj.getSettingBool("check_for_updates")) == bool
assert type(obj.getSetting("last_install_greet").toVariant()) == str
assert type(obj.getSetting("check_for_updates").toVariant()) == bool
assert type(obj.getSetting("default_graph.xzoom").toVariant()) in [float, int]
def test_set_config(self, temporary):
tmpfile, directory = temporary
obj = Helper(pwd, tmpfile)
obj.setSetting("last_install_greet", obj.getSetting("last_install_greet"))
obj.setSettingBool("check_for_updates", obj.getSettingBool("check_for_updates"))
obj.setSettingInt("default_graph.xzoom", obj.getSettingInt("default_graph.xzoom"))
obj.setSetting("check_for_updates", obj.getSetting("check_for_updates"))
obj.setSetting("default_graph.xzoom", obj.getSetting("default_graph.xzoom"))
def test_fetch_changelog(self, temporary, qtbot):
tmpfile, directory = temporary