Changeset View
Changeset View
Standalone View
Standalone View
src/backends/julia/juliavariablemodel.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | This program is free software; you can redistribute it and/or | ||||
3 | modify it under the terms of the GNU General Public License | ||||
4 | as published by the Free Software Foundation; either version 2 | ||||
5 | of the License, or (at your option) any later version. | ||||
6 | | ||||
7 | This program is distributed in the hope that it will be useful, | ||||
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
10 | GNU General Public License for more details. | ||||
11 | | ||||
12 | You should have received a copy of the GNU General Public License | ||||
13 | along with this program; if not, write to the Free Software | ||||
14 | Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
15 | Boston, MA 02110-1301, USA. | ||||
16 | | ||||
17 | --- | ||||
18 | Copyright (C) 2018 Nikita Sirgienko <warquark@gmail.com> | ||||
19 | */ | ||||
20 | | ||||
21 | #include "juliavariablemodel.h" | ||||
22 | #include "juliaextensions.h" | ||||
23 | #include "juliasession.h" | ||||
24 | | ||||
25 | #include <QDebug> | ||||
26 | #include <QDBusReply> | ||||
27 | #include <QDBusInterface> | ||||
28 | #include <QString> | ||||
29 | | ||||
30 | #include "settings.h" | ||||
31 | | ||||
32 | using namespace Cantor; | ||||
33 | | ||||
34 | const QRegularExpression JuliaVariableModel::typeVariableInfo = QRegularExpression(QLatin1String("\\w+\\[")); | ||||
35 | | ||||
36 | JuliaVariableModel::JuliaVariableModel(JuliaSession* session): | ||||
37 | DefaultVariableModel(session), | ||||
38 | m_interface(nullptr) | ||||
39 | { | ||||
40 | } | ||||
41 | | ||||
42 | void JuliaVariableModel::setJuliaServer(QDBusInterface* interface) | ||||
43 | { | ||||
44 | m_interface = interface; | ||||
45 | } | ||||
46 | | ||||
47 | void JuliaVariableModel::update() | ||||
48 | { | ||||
49 | if (!m_interface) | ||||
50 | return; | ||||
51 | | ||||
52 | m_interface->call(QLatin1String("parseModules"), JuliaSettings::variableManagement()); | ||||
53 | | ||||
54 | const QStringList& variables = | ||||
55 | static_cast<QDBusReply<QStringList>>(m_interface->call(QLatin1String("variablesList"))).value(); | ||||
56 | | ||||
57 | QList<Variable> vars; | ||||
58 | if (JuliaSettings::variableManagement()) | ||||
59 | { | ||||
60 | const QStringList& values = | ||||
61 | static_cast<QDBusReply<QStringList>>(m_interface->call(QLatin1String("variableValuesList"))).value(); | ||||
62 | | ||||
63 | for (int i = 0; i < variables.size(); i++) | ||||
64 | { | ||||
65 | if (i >= values.size()) | ||||
66 | { | ||||
67 | qWarning() << "Don't have value for variable from julia server response, something wrong!"; | ||||
68 | continue; | ||||
69 | } | ||||
70 | | ||||
71 | const QString& name = variables[i]; | ||||
72 | QString value = values[i]; | ||||
73 | if (value != JuliaVariableManagementExtension::REMOVED_VARIABLE_MARKER) | ||||
74 | { | ||||
75 | // Register variable | ||||
76 | // We use replace here, because julia return data type for some variables, and we need | ||||
77 | // remove it to make variable view more consistent with the other backends | ||||
78 | // More info: https://bugs.kde.org/show_bug.cgi?id=377771 | ||||
79 | vars << Variable{name, value.replace(typeVariableInfo,QLatin1String("["))}; | ||||
80 | } | ||||
81 | } | ||||
82 | } | ||||
83 | else | ||||
84 | { | ||||
85 | for (int i = 0; i < variables.size(); i++) | ||||
86 | vars << Variable{variables[i], QString()}; | ||||
87 | } | ||||
88 | setVariables(vars); | ||||
89 | | ||||
90 | const QStringList& newFuncs = | ||||
91 | static_cast<QDBusReply<QStringList>>(m_interface->call(QLatin1String("functionsList"))).value(); | ||||
92 | setFunctions(newFuncs); | ||||
93 | } |