Skip to content

Commit

Permalink
Relocate code
Browse files Browse the repository at this point in the history
  • Loading branch information
plfiorini committed Apr 6, 2024
1 parent f7c3915 commit f8c6fcf
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 72 deletions.
28 changes: 13 additions & 15 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
qt_add_executable(LiriCalculator
WIN32 MACOSX_BUNDLE
main/main.cpp
filehandler/filehandler.cpp filehandler/filehandler.h
main.cpp
filehandler.cpp filehandler.h
)

qt_add_qml_module(LiriCalculator
URI Application
VERSION 2.0
QML_FILES
engine/qmldir
engine/math.js
engine/MathJs.qml
ui/qmldir
ui/ButtonsPanel.qml
ui/ButtonsView.qml
ui/CalculationLine.qml
ui/CalculationZone.qml
ui/HistoryPanel.qml
ui/Main.qml
ui/NavButton.qml
ui/Shortcuts.qml
ui/Styles.qml
qml/ButtonsPanel.qml
qml/ButtonsView.qml
qml/CalculationLine.qml
qml/CalculationZone.qml
qml/HistoryPanel.qml
qml/Main.qml
qml/math.js
qml/MathJs.qml
qml/NavButton.qml
qml/Shortcuts.qml
qml/Styles.qml
RESOURCES
icons/icon.png
)
Expand Down
22 changes: 0 additions & 22 deletions src/engine/MathJs.qml

This file was deleted.

1 change: 0 additions & 1 deletion src/engine/qmldir

This file was deleted.

File renamed without changes.
2 changes: 2 additions & 0 deletions src/filehandler/filehandler.h → src/filehandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <QObject>
#include <QUrl>
#include <QQmlEngine>

QT_BEGIN_NAMESPACE
class QTextDocument;
Expand All @@ -12,6 +13,7 @@ QT_END_NAMESPACE
class FileHandler : public QObject
{
Q_OBJECT
QML_ELEMENT

Q_PROPERTY(QQuickTextDocument *document READ document WRITE setDocument NOTIFY documentChanged)
Q_PROPERTY(QString fileName READ fileName NOTIFY fileUrlChanged)
Expand Down
7 changes: 0 additions & 7 deletions src/main/main.cpp → src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
#include <QStandardPaths>
#include <QTranslator>

#include "../filehandler/filehandler.h"

using namespace Qt::StringLiterals;

int main(int argc, char *argv[])
Expand Down Expand Up @@ -72,16 +70,11 @@ int main(int argc, char *argv[])
engine.rootContext()->setContextProperty(QStringLiteral("debug"), false);
#endif

qmlRegisterType<FileHandler>("filehandler", 1, 0, "FileHandler");

// Quit on error
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
QCoreApplication::instance(), QCoreApplication::quit,
Qt::QueuedConnection);

// setup qml imports
engine.addImportPath(QStringLiteral("qrc:/"));

// load main ui
engine.loadFromModule("Application", "Main");

Expand Down
2 changes: 0 additions & 2 deletions src/ui/ButtonsPanel.qml → src/qml/ButtonsPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Controls.Material
import Fluid.Controls
import ".."
import "../engine"

Rectangle {
id: buttonsPanel
Expand Down
2 changes: 0 additions & 2 deletions src/ui/ButtonsView.qml → src/qml/ButtonsView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Controls.Material
import Fluid.Controls
import ".."


Rectangle {
id: buttonsView
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions src/ui/HistoryPanel.qml → src/qml/HistoryPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Controls.Material
import Fluid.Controls
import ".."
import "../engine"

Rectangle {
id: historyPanel
Expand Down
28 changes: 8 additions & 20 deletions src/ui/Main.qml → src/qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ import QtQuick.Controls
import Fluid.Controls as FluidControls
import Fluid.Controls
import Qt.labs.platform
import filehandler
import ".."
import "../engine"
import Application
import "math.js" as MathJs

ApplicationWindow {
id: root
Expand Down Expand Up @@ -59,6 +58,9 @@ ApplicationWindow {
title: 'Calculator'

Component.onCompleted: {
MathJs.mathJs.config({
number: 'BigNumber'
});
calculationZone.retrieveFormulaFocus();
retrieveHistory();
}
Expand All @@ -74,20 +76,6 @@ ApplicationWindow {
property alias history: root.history
}

property var mathJs: mathJsLoader.item ? mathJsLoader.item.mathJs : null;

Loader {
id: mathJsLoader
source: "../engine/MathJs.qml"
asynchronous: true
active: true
onLoaded: {
mathJs.config({
number: 'BigNumber'
});
}
}

CalculationZone {
id: calculationZone
anchors.top: parent.top
Expand Down Expand Up @@ -322,18 +310,18 @@ ApplicationWindow {
var NUMBER_LENGTH_LIMIT = 14;

if (bigNumberToFormat.toString().length > NUMBER_LENGTH_LIMIT) {
var resultLength = mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10},
var resultLength = MathJs.mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10},
precision: NUMBER_LENGTH_LIMIT}).toString().length;

return mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10},
return MathJs.mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10},
precision: (NUMBER_LENGTH_LIMIT - resultLength + NUMBER_LENGTH_LIMIT)}).toString();
}
return bigNumberToFormat.toString()
}

function calculate(formula, wantArray) {
try {
var res = mathJs.eval(formula);
var res = MathJs.mathJs.eval(formula);
if (!wantArray) {
res = formatBigNumber(res);
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion src/ui/qmldir

This file was deleted.

0 comments on commit f8c6fcf

Please sign in to comment.