Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 969c0ffc authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Make it possible to add 3D plots from the console as well

parent 0f17ccda
......@@ -16,8 +16,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
*************************************************************************************/
import org.kde.kirigami 2.5 as Kirigami
import QtQuick 2.2
import QtQuick.Controls 2.5 as QQC2
import QtQml.Models 2.10
import QtQuick.Dialogs 1.0
import org.kde.analitza 1.0
import org.kde.kalgebra.mobile 1.0
......@@ -32,24 +34,11 @@ KAlgebraPage
id: clipboard
}
Component {
id: copyAction
QQC2.Action {
property string valueHtml: "null"
readonly property string value: valueHtml.replace(/<[^>]*>/g, '');
text: i18n("Copy \"%1\"", value)
icon.name: "edit-copy"
onTriggered: {
clipboard.content = value
}
}
}
ConsoleModel {
id: consoleModel
variables: app.variables
onMessage: {
itemModel.append({ result: msg, hiddenActions: copyAction.createObject(itemModel, {valueHtml: msg }) })
itemModel.append({ result: msg, expression: result.toString() })
input.selectAll()
view.currentIndex = view.count-1
view.positionViewAtIndex(view.currentIndex, ListView.Contain)
......@@ -109,10 +98,40 @@ KAlgebraPage
}
]
SimpleListView {
Kirigami.CardsListView {
id: view
model: itemModel
role: "result"
delegate: Kirigami.Card {
contentItem: Label { text: model.result }
hiddenActions: [
QQC2.Action {
readonly property string value: result.replace(/<[^>]*>/g, '');
text: i18n("Copy \"%1\"", value)
icon.name: "edit-copy"
onTriggered: {
clipboard.content = value
}
}
]
actions: [
Kirigami.Action {
enabled: app.functionsModel().canAddFunction(expression, 2, app.variables)
text: i18n("2D Plot")
onTriggered: {
app.functionsModel().addFunction(expression, 2, app.variables)
}
},
Kirigami.Action {
enabled: app.functionsModel().canAddFunction(expression, 4, app.variables)
text: i18n("3D Plot")
onTriggered: {
app.functionsModel().addFunction(expression, 4, app.variables)
}
}
]
}
anchors {
top: parent.top
......
......@@ -31,7 +31,6 @@ KAlgebraPage
topPadding: 0
bottomPadding: 0
FileDialog {
id: fileDialog
folder: shortcuts.home
......@@ -64,6 +63,7 @@ KAlgebraPage
{
id: view
anchors.fill: parent
model: app.functionsModel()
Dialog {
id: dialog
......@@ -88,7 +88,7 @@ KAlgebraPage
Component.onCompleted: selectAll()
onAccepted: {
input.selectAll()
var err = view.addFunction(input.text, app.variables)
var err = app.functionsModel().addFunction(input.text, 4, app.variables)
if (err.length>0)
console.warn("errors:", err)
}
......
......@@ -83,9 +83,9 @@ bool ConsoleModel::addOperation(const Analitza::Expression& e, const QString& in
const auto result = res.toHtml();
addMessage(QStringLiteral("<a title='%1' href='kalgebra:/query?id=copy&func=%2'><span class='exp'>%3</span></a><br />=<a title='kalgebra:%1' href='kalgebra:/query?id=copy&func=%4'><span class='result'>%5</span></a>")
.arg(i18n("Paste to Input"), e.toString(), e.toHtml(), res.toString(), result));
.arg(i18n("Paste to Input"), e.toString(), e.toHtml(), res.toString(), result), e, res);
} else {
addMessage(i18n("<ul class='error'>Error: <b>%1</b><li>%2</li></ul>", input.toHtmlEscaped(), a.errors().join(QStringLiteral("</li>\n<li>"))));
addMessage(i18n("<ul class='error'>Error: <b>%1</b><li>%2</li></ul>", input.toHtmlEscaped(), a.errors().join(QStringLiteral("</li>\n<li>"))), {}, {});
}
return a.isCorrect();
......@@ -107,9 +107,9 @@ bool ConsoleModel::loadScript(const QUrl& path)
}
if(correct)
addMessage(i18n("Imported: %1", path.toDisplayString()));
addMessage(i18n("Imported: %1", path.toDisplayString()), {}, {});
else
addMessage(i18n("<ul class='error'>Error: Could not load %1. <br /> %2</ul>", path.toDisplayString(), a.errors().join(QStringLiteral("<br/>"))));
addMessage(i18n("<ul class='error'>Error: Could not load %1. <br /> %2</ul>", path.toDisplayString(), a.errors().join(QStringLiteral("<br/>"))), {}, {});
return correct;
}
......@@ -143,11 +143,11 @@ void ConsoleModel::setVariables(const QSharedPointer<Analitza::Variables>& vars)
a.setVariables(vars);
}
void ConsoleModel::addMessage(const QString& msg)
void ConsoleModel::addMessage(const QString& msg, const Analitza::Expression& operation, const Analitza::Expression& result)
{
m_htmlLog += msg.toUtf8();
Q_EMIT updateView();
Q_EMIT message(msg);
Q_EMIT message(msg, operation, result);
}
bool ConsoleModel::saveLog(const QUrl& savePath) const
......
......@@ -54,17 +54,17 @@ public:
QSharedPointer<Analitza::Variables> variables() const { return a.variables(); }
void setVariables(const QSharedPointer<Analitza::Variables> &vars);
Analitza::Analyzer* analyzer() { return &a; }
void addMessage(const QString &msg);
QList<QByteArray> htmlLog() const { return m_htmlLog; }
Q_SIGNALS:
void message(const QString &msg);
void message(const QString &msg, const Analitza::Expression& operation, const Analitza::Expression& result);
void updateView();
void modeChanged(ConsoleModel::ConsoleMode mode);
void operationSuccessful(const Analitza::Expression &expression, const Analitza::Expression &result);
private:
void addMessage(const QString &msg, const Analitza::Expression& operation, const Analitza::Expression& result);
QList<QByteArray> m_htmlLog;
Analitza::Analyzer a;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment