Warning, /education/kalgebra/mobile/content/ui/Tables.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2015 by Aleix Pol <aleixpol@kde.org>
0002 // SPDX-License-Identifier: GPL-2.0-or-later
0003 
0004 import QtQuick
0005 import QtQuick.Layouts
0006 import org.kde.analitza
0007 import QtQuick.Controls as QQC2
0008 import org.kde.kirigami as Kirigami
0009 import org.kde.kalgebra.mobile
0010 
0011 Kirigami.ScrollablePage {
0012     title: i18n("Value tables")
0013 
0014     property ListModel resultsModel: ListModel {}
0015 
0016     function calculateTable() {
0017         resultsModel.clear();
0018 
0019         var tmp = a.unusedVariableName()
0020         var ret = a.insertVariable(tmp, a.dependenciesToLambda(input.text))
0021         var ffrom = from.realValue, fto=to.realValue, fstep=step.realValue;
0022 //         console.log("chancho (" + ffrom + ", " + fto + " : " + fstep + ") " + ret);
0023         if((fto-ffrom>0)!=(fstep>0)) {
0024             fstep *= -1;
0025             step.value = fstep
0026         }
0027 //         console.log("chancho2 (" + ffrom + ", " + fto + " : " + fstep + ") " + ret);
0028 
0029         if(fstep===0) {
0030             resultsModel.append( { element: i18n("Errors: The step cannot be 0") } );
0031         } else if(ffrom === fto) {
0032             resultsModel.append( { element: i18n("Errors: The start and end are the same") } );
0033         } else if(!a.isCorrect) {
0034             resultsModel.append( { element: i18n("Errors: %1", ret ? ret : a.errors) } );
0035         } else {
0036             for (var i=ffrom; i<=fto &&  i>=ffrom && a.isCorrect; i+=fstep) {
0037                 var args = new Array();
0038                 args[0]=i;
0039                 var expr = a.executeFunc(tmp, args);
0040                 resultsModel.append( { element: i +" = "+ expr.expression } );
0041             }
0042         }
0043 
0044         a.removeVariable(tmp);
0045         applicationWindow().pageStack.push("qrc:/TableResultPage.qml", {
0046             'results': resultsModel
0047         });
0048     }
0049 
0050     actions: QQC2.Action {
0051         icon.name: 'dialog-ok'
0052         text: i18nc("@action:button Run table", "Run")
0053         onTriggered: calculateTable()
0054     }
0055 
0056     Analitza {
0057         id: a
0058         variables: App.variables
0059     }
0060 
0061     Kirigami.FormLayout {
0062         QQC2.TextField {
0063             Kirigami.FormData.label: i18n("Input")
0064             id: input
0065             text: "sin x";
0066             Layout.fillWidth: true
0067             onAccepted: calculateTable();
0068         }
0069         RealInput {
0070             id: from;
0071             text: "0";
0072             Kirigami.FormData.label: i18n("From:")
0073             Layout.fillWidth: true;
0074             onAccepted: calculateTable()
0075         }
0076         RealInput {
0077             id: to;
0078             text: "10";
0079             Kirigami.FormData.label: i18n("To:")
0080             Layout.fillWidth: true;
0081             onAccepted: calculateTable()
0082         }
0083 
0084         RealInput {
0085             id: step;
0086             Kirigami.FormData.label: i18n("Step")
0087             text: "1";
0088             Layout.fillWidth: true;
0089             onAccepted: calculateTable()
0090         }
0091         QQC2.Button {
0092             text: i18n("Run")
0093             onClicked: calculateTable()
0094             visible: !Kirigami.Settings.isMobile
0095         }
0096     }
0097 }