-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.cpp
More file actions
102 lines (88 loc) · 2.7 KB
/
Copy pathview.cpp
File metadata and controls
102 lines (88 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "view.h"
#include <QDebug>
#include <QString>
View::View(QQuickItem *parent):
QQuickItem(parent)
{
matrix = new MatrixModel();
}
void View::message(QString msg)
{
if (msg == "apply_dimensions") {
applyDimension();
}
if(msg=="toggle_scalars") {
if (matrix->hasScalars()){
matrix->showScalars(false);
applyDimension();
}else{
matrix->showScalars(true);
applyDimension();
}
}
if (msg == "row_reduce") {
matrix->rowReduce();
printMatrix();
}
if(msg=="solve") {
matrix->solve();
printMatrix();
}
}
void View::printMatrix()
{
int n = matrix->getN();
int m = matrix->getM();
QQuickItem *matrix_grid = this->findChild<QQuickItem*>("matrix_grid");
for (int i = 0;i<matrix_grid->childItems().length();i++){
matrix_grid->childItems().at(i)->deleteLater();
}
matrix_grid->childItems().clear();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
//Below are used when c++ write on window
QQmlComponent component(engine, QUrl::fromLocalFile("MatrixMoo/MatrixEntry.qml"));
QQuickItem * entry = qobject_cast<QQuickItem*>(component.create());
entry->setParentItem(matrix_grid);
entry->setParent(engine);
entry->setProperty("text",matrix->getEntry(i,j));
//otherwise, column will always be 2 as defined in main.qml
connect(entry, SIGNAL(editingFinished()), this, SLOT(saveMatrix()));
}
}
}
void View::saveMatrix()
{
int n = matrix->getN();
int m = matrix->getM();
QQuickItem * matrix_grid = this->findChild<QQuickItem*>("matrix_grid");
for (int i = 0; i <n;i++) {
for (int j = 0; j < m; j++) {
QQuickItem * entry = matrix_grid->childItems().at(i*m+j);
matrix->setEntry(i,j,entry->property("text").toDouble());
}
}
}
void View::applyDimension()
{
QQuickItem* n_dim = this->findChild<QQuickItem*>("n_dimension");
QQuickItem * m_dim = this->findChild<QQuickItem*>("m_dimension");
int n = n_dim->property("text").toInt();
int m = m_dim->property("text").toInt();
QQuickItem* matrix_grid = this->findChild<QQuickItem*>("matrix_grid");
matrix_grid->setWidth(m*100);
matrix_grid->setHeight(n*60);
if (matrix->hasScalars()) {
matrix_grid->setWidth((m+1)*100);
matrix->applyDimension(n,m+1);
matrix_grid->setProperty("columns",m+1);
}else{
matrix->applyDimension(n,m);
matrix_grid->setProperty("columns",m);
}
printMatrix();
}
void View::initialize(QQmlApplicationEngine* enginePtr)
{
engine=enginePtr;
}