Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Education
KAlgebra
Commits
865a57e3
Commit
865a57e3
authored
Jun 14, 2017
by
Aleix Pol Gonzalez
🐧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use the ConsoleModel from kalgebramobile
parent
f209635f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
95 additions
and
44 deletions
+95
-44
mobile/CMakeLists.txt
mobile/CMakeLists.txt
+1
-0
mobile/kalgebramobile.cpp
mobile/kalgebramobile.cpp
+4
-0
mobile/plugins/Console.qml
mobile/plugins/Console.qml
+23
-18
src/consolehtml.cpp
src/consolehtml.cpp
+18
-6
src/consolehtml.h
src/consolehtml.h
+4
-3
src/consolemodel.cpp
src/consolemodel.cpp
+30
-10
src/consolemodel.h
src/consolemodel.h
+15
-7
No files found.
mobile/CMakeLists.txt
View file @
865a57e3
...
...
@@ -6,6 +6,7 @@ endif()
qt5_add_resources
(
KALGEBRAMOBILE_SRCS resources.qrc
)
add_executable
(
kalgebramobile pluginsmodel.cpp
../src/consolemodel.cpp
kalgebramobile.cpp main.cpp
${
KALGEBRAMOBILE_SRCS
}
)
target_link_libraries
(
kalgebramobile Qt5::Qml Qt5::Quick Qt5::Gui
...
...
mobile/kalgebramobile.cpp
View file @
865a57e3
...
...
@@ -22,6 +22,8 @@
#include <analitza/variables.h>
#include <analitza/expression.h>
#include "../src/consolemodel.h"
#include <qqml.h>
#include "pluginsmodel.h"
...
...
@@ -37,7 +39,9 @@ KAlgebraMobile::KAlgebraMobile(QObject* parent)
s_self
=
this
;
qmlRegisterType
<
PluginsModel
>
(
"org.kde.kalgebra.mobile"
,
1
,
0
,
"PluginsModel"
);
qmlRegisterType
<
ConsoleModel
>
(
"org.kde.kalgebra.mobile"
,
1
,
0
,
"ConsoleModel"
);
qmlRegisterType
<
QAbstractItemModel
>
();
qmlRegisterUncreatableType
<
Analitza
::
Expression
>
(
"org.kde.kalgebra.mobile"
,
1
,
0
,
"Expression"
,
"because"
);
}
PlotsModel
*
KAlgebraMobile
::
functionsModel
()
...
...
mobile/plugins/Console.qml
View file @
865a57e3
import
QtQuick
2.2
import
QtQuick
.
Dialogs
1.0
import
org
.
kde
.
analitza
1.0
import
org
.
kde
.
kalgebra
.
mobile
1.0
import
widgets
1.0
KAlgebraPage
...
...
@@ -8,10 +9,22 @@ KAlgebraPage
id
:
page
ListModel
{
id
:
itemModel
}
Analitza
{
id
:
a
variables
:
app
.
variables
calculate
:
false
ConsoleModel
{
id
:
consoleModel
// variables: app.variables
mode
:
ConsoleModel
.
Evaluate
onErrorMessage
:
{
var
toadd
=
i18n
(
"
Error: %1
"
,
error
)
itemModel
.
insert
(
0
,
{
result
:
toadd
})
input
.
selectAll
()
view
.
currentIndex
=
0
}
onOperationSuccessfulString
:
{
itemModel
.
insert
(
0
,
{
result
:
expression
+
"
=
"
+
result
})
input
.
selectAll
()
view
.
currentIndex
=
0
}
}
FileDialog
{
...
...
@@ -22,7 +35,9 @@ KAlgebraPage
property
var
proceed
}
function
proceedLoadScript
()
function
proceedLoadScript
()
{
}
contextualActions
:
[
Action
{
...
...
@@ -42,8 +57,8 @@ KAlgebraPage
},
// --
Action
{
text
:
a
.
c
alculate
?
i18n
(
"
Evaluate...
"
)
:
i18n
(
"
Calculate...
"
)
onTriggered
:
a
.
calculate
=
!
a
.
calculat
e
text
:
consoleModel
.
mode
==
ConsoleModel
.
C
alculate
?
i18n
(
"
Evaluate...
"
)
:
i18n
(
"
Calculate...
"
)
onTriggered
:
consoleModel
.
mode
=
!
consoleModel
.
mod
e
},
// --
Action
{
...
...
@@ -58,17 +73,7 @@ KAlgebraPage
focus
:
true
Keys.onReturnPressed
:
{
var
res
=
a
.
execute
(
text
)
var
toadd
=
""
if
(
!
a
.
isCorrect
)
toadd
=
"
Error:
"
+
(
res
?
res
:
a
.
errors
)
else
toadd
=
text
+
"
=
"
+
res
.
expression
itemModel
.
insert
(
0
,
{
result
:
toadd
,
resultsInput
:
text
})
input
.
selectAll
()
view
.
currentIndex
=
0
consoleModel
.
addOperation
(
text
)
}
anchors
{
...
...
src/consolehtml.cpp
View file @
865a57e3
...
...
@@ -98,9 +98,10 @@ public:
ConsoleHtml
::
ConsoleHtml
(
QWidget
*
parent
)
:
QWebEngineView
(
parent
)
,
m_model
(
new
ConsoleModel
)
,
m_model
(
new
ConsoleModel
(
this
,
false
)
)
{
connect
(
m_model
.
data
(),
&
ConsoleModel
::
updateView
,
this
,
&
ConsoleHtml
::
updateView
);
connect
(
m_model
.
data
(),
&
ConsoleModel
::
operationSuccessful
,
this
,
&
ConsoleHtml
::
includeOperation
);
connect
(
m_model
.
data
(),
&
ConsoleModel
::
errorMessage
,
this
,
&
ConsoleHtml
::
addMessage
);
setPage
(
new
ConsolePage
(
this
));
}
...
...
@@ -190,10 +191,14 @@ bool ConsoleHtml::saveLog(const QUrl& path) const
return
correct
;
}
void
ConsoleHtml
::
updateView
(
const
QString
&
newEntry
,
const
Analitza
::
Expression
&
res
)
void
ConsoleHtml
::
includeOperation
(
const
Analitza
::
Expression
&
e
,
const
Analitza
::
Expression
&
res
)
{
QString
options
;
QString
options
,
newEntry
;
if
(
res
.
isCorrect
())
{
const
auto
result
=
res
.
toHtml
();
newEntry
=
QStringLiteral
(
"<a title='%1' href='kalgebra:/query?id=copy&func=%2'><span class='exp'>%3</span></a><br />=<a title='kalgebra:%1' href='/query?id=copy&func=%4'><span class='result'>%5</span>"
)
.
arg
(
i18n
(
"Paste to Input"
),
e
.
toString
(),
e
.
toHtml
(),
res
.
toString
(),
result
);
Analitza
::
Analyzer
lambdifier
(
m_model
->
variables
());
lambdifier
.
setExpression
(
res
);
Analitza
::
Expression
lambdaexp
=
lambdifier
.
dependenciesToLambda
();
...
...
@@ -214,7 +219,16 @@ void ConsoleHtml::updateView(const QString& newEntry, const Analitza::Expression
if
(
!
options
.
isEmpty
())
options
=
"<div class='options'>"
+
i18n
(
"Options: %1"
,
options
)
+
"</div>"
;
}
updateViewWithOptions
(
newEntry
,
options
);
}
void
ConsoleHtml
::
updateView
(
const
QString
&
newEntry
)
{
updateViewWithOptions
(
newEntry
,
{});
}
void
ConsoleHtml
::
updateViewWithOptions
(
const
QString
&
newEntry
,
const
QString
&
options
)
{
QByteArray
code
;
code
+=
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
standalone=
\"
no
\"
?>
\n
"
;
code
+=
"<html xmlns=
\"
http://www.w3.org/1999/xhtml
\"
xml:lang=
\"
en
\"
>
\n
<head>
\n\t
<title> :) </title>
\n
"
;
...
...
@@ -265,7 +279,7 @@ void ConsoleHtml::clear()
{
m_model
->
clear
();
m_htmlLog
.
clear
();
updateView
(
QString
()
,
{}
);
updateView
(
QString
());
}
void
ConsoleHtml
::
modifyVariable
(
const
QString
&
name
,
const
Analitza
::
Expression
&
exp
)
...
...
@@ -282,5 +296,3 @@ void ConsoleHtml::paste()
{
emit
paste
(
selectedText
());
}
#include "consolehtml.moc"
src/consolehtml.h
View file @
865a57e3
...
...
@@ -105,10 +105,11 @@ class ConsoleHtml : public QWebEngineView
void
addMessage
(
const
QString
&
message
);
private:
void
includeOperation
(
const
Analitza
::
Expression
&
expression
,
const
Analitza
::
Expression
&
result
);
void
updateView
(
const
QString
&
newEntry
);
void
updateViewWithOptions
(
const
QString
&
newEntry
,
const
QString
&
options
);
QStringList
m_htmlLog
;
void
updateView
(
const
QString
&
newEntry
,
const
Analitza
::
Expression
&
exp
);
QList
<
InlineOptions
*>
m_options
;
QScopedPointer
<
ConsoleModel
>
m_model
;
};
...
...
src/consolemodel.cpp
View file @
865a57e3
...
...
@@ -22,6 +22,21 @@
#include <QUrl>
#include <KLocalizedString>
ConsoleModel
::
ConsoleModel
(
QObject
*
parent
,
bool
preferString
)
:
QObject
(
parent
)
{
if
(
preferString
)
{
connect
(
this
,
&
ConsoleModel
::
operationSuccessful
,
this
,
[
this
](
const
Analitza
::
Expression
&
exp
,
const
Analitza
::
Expression
&
res
)
{
operationSuccessfulString
(
exp
.
toString
(),
res
.
toString
());
});
}
}
bool
ConsoleModel
::
addOperation
(
const
QString
&
input
)
{
return
addOperation
(
Analitza
::
Expression
(
input
),
input
);
}
bool
ConsoleModel
::
addOperation
(
const
Analitza
::
Expression
&
e
,
const
QString
&
input
)
{
Analitza
::
Expression
res
;
...
...
@@ -35,20 +50,16 @@ bool ConsoleModel::addOperation(const Analitza::Expression& e, const QString& in
}
}
QString
result
,
newEntry
;
if
(
a
.
isCorrect
())
{
result
=
res
.
toHtml
();
a
.
insertVariable
(
QStringLiteral
(
"ans"
),
res
);
m_script
+=
e
;
//Script won't have the errors
newEntry
=
QString
(
"<a title='%1' href='kalgebra:/query?id=copy&func=%2'><span class='exp'>%3</span></a><br />=<a title='kalgebra:%1' href='/query?id=copy&func=%4'><span class='result'>%5</span>"
)
.
arg
(
i18n
(
"Paste to Input"
)).
arg
(
e
.
toString
()).
arg
(
e
.
toHtml
()).
arg
(
res
.
toString
()).
arg
(
result
);
Q_EMIT
operationSuccessful
(
e
,
res
);
}
else
{
errorMessage
(
i18n
(
"<ul class='error'>Error: <b>%1</b><li>%2</li></ul>"
,
input
.
toHtmlEscaped
(),
a
.
errors
().
join
(
QStringLiteral
(
"</li>
\n
<li>"
))));
Q_EMIT
errorMessage
(
i18n
(
"<ul class='error'>Error: <b>%1</b><li>%2</li></ul>"
,
input
.
toHtmlEscaped
(),
a
.
errors
().
join
(
QStringLiteral
(
"</li>
\n
<li>"
))));
Q_EMIT
updateView
({});
}
updateView
(
newEntry
);
return
a
.
isCorrect
();
}
...
...
@@ -69,10 +80,10 @@ bool ConsoleModel::loadScript(const QString& path)
if
(
!
correct
)
{
Q_EMIT
errorMessage
(
i18n
(
"<ul class='error'>Error: Could not load %1. <br /> %2</ul>"
,
path
,
a
.
errors
().
join
(
QStringLiteral
(
"<br/>"
))));
updateView
(
QString
());
Q_EMIT
updateView
(
QString
());
}
else
updateView
(
i18n
(
"Imported: %1"
,
path
));
Q_EMIT
updateView
(
i18n
(
"Imported: %1"
,
path
));
return
correct
;
}
...
...
@@ -92,3 +103,12 @@ bool ConsoleModel::saveScript(const QString& savePath)
return
correct
;
}
void
ConsoleModel
::
setMode
(
ConsoleMode
mode
)
{
if
(
m_mode
!=
mode
)
{
m_mode
=
mode
;
Q_EMIT
modeChanged
(
mode
);
}
}
src/consolemodel.h
View file @
865a57e3
...
...
@@ -26,8 +26,11 @@
class
ConsoleModel
:
public
QObject
{
Q_OBJECT
Q_PROPERTY
(
ConsoleMode
mode
READ
mode
WRITE
setMode
)
Q_PROPERTY
(
ConsoleMode
mode
READ
mode
WRITE
setMode
NOTIFY
modeChanged
)
Q_PROPERTY
(
Analitza
::
Variables
*
variables
READ
variables
)
public:
ConsoleModel
(
QObject
*
parent
=
nullptr
,
bool
preferString
=
true
);
/** This enumeration controles the way the console will calculate and show his results. */
enum
ConsoleMode
{
Evaluation
,
/**< Simplifies the expression, tries to simplify when sees a variable not defined. */
...
...
@@ -35,20 +38,25 @@ public:
};
Q_ENUM
(
ConsoleMode
)
Q_SCRIPTABLE
bool
addOperation
(
const
QString
&
input
);
bool
addOperation
(
const
Analitza
::
Expression
&
e
,
const
QString
&
input
);
bool
loadScript
(
const
QString
&
path
);
bool
saveScript
(
const
QString
&
path
);
Q_SCRIPTABLE
bool
loadScript
(
const
QString
&
path
);
Q_SCRIPTABLE
bool
saveScript
(
const
QString
&
path
);
Q_SCRIPTABLE
void
clear
()
{
m_script
.
clear
();
}
Analitza
::
Variables
*
variables
()
const
{
return
a
.
variables
();
}
ConsoleMode
mode
()
const
{
return
m_mode
;
}
void
setMode
(
ConsoleMode
mode
)
{
m_mode
=
mode
;
}
void
clear
()
{
m_script
.
clear
();
}
void
setMode
(
ConsoleMode
mode
);
Analitza
::
Variables
*
variables
()
const
{
return
a
.
variables
();
}
Analitza
::
Analyzer
*
analyzer
()
{
return
&
a
;
}
Q_SIGNALS:
void
errorMessage
(
const
QString
&
error
);
void
updateView
(
const
QString
&
newEntry
,
const
Analitza
::
Expression
&
result
=
{});
void
updateView
(
const
QString
&
entry
);
void
modeChanged
(
ConsoleMode
mode
);
void
operationSuccessful
(
const
Analitza
::
Expression
&
expression
,
const
Analitza
::
Expression
&
result
);
void
operationSuccessfulString
(
const
QString
&
expression
,
const
QString
&
result
);
private:
Analitza
::
Analyzer
a
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment