Skip to content

Commit 69f3ecf

Browse files
JaDoggBhathiya Perera
authored andcommitted
Create tute feature
1 parent d3593c4 commit 69f3ecf

16 files changed

Lines changed: 2447 additions & 1789 deletions

About.htm

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
<html>
2-
<body>
3-
<b> Express Python </b>
4-
<br />
5-
Written by Bhathiya Perera<br />
6-
<br />
7-
<b>Credits</b>
8-
<ul>
9-
<li>Qt 5.3.2</li>
10-
<li>Python 3.4.2</li>
11-
<li>Frankie Simon's Python Syntax Highlight Code (Modified)</li>
12-
<li>Mateusz Loskot's Embedding Code (Modified)</li>
13-
<li>Train Icon from awicons.com</li>
14-
<li>All Other Icons from Open Icon Library</li>
15-
</ul>
16-
<br />
17-
<b>License</b>
18-
<pre>
19-
Express Python
20-
Copyright (C) 2014 Bhathiya Perera
21-
22-
This program is free software; you can redistribute it and/or modify
23-
it under the terms of the GNU General Public License as published by
24-
the Free Software Foundation; either version 2 of the License, or
25-
(at your option) any later version.
26-
27-
This program is distributed in the hope that it will be useful,
28-
but WITHOUT ANY WARRANTY; without even the implied warranty of
29-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30-
GNU General Public License for more details.
31-
32-
You should have received a copy of the GNU General Public License along
33-
with this program; if not, write to the Free Software Foundation, Inc.,
34-
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
35-
</pre>
36-
</body>
37-
</html>
1+
<html>
2+
<body>
3+
<b> Express Python </b>
4+
<br />
5+
Written by Bhathiya Perera<br />
6+
<br />
7+
<b>Credits</b>
8+
<ul>
9+
<li>Qt 5.3.2</li>
10+
<li>Python 3.4.2</li>
11+
<li>Frankie Simon's Python Syntax Highlight Code (Modified)</li>
12+
<li>Mateusz Loskot's Embedding Code (Modified)</li>
13+
<li>Train Icon from awicons.com</li>
14+
<li>All Other Icons from Open Icon Library</li>
15+
</ul>
16+
<br />
17+
<b>License</b>
18+
<pre>
19+
Express Python
20+
Copyright (C) 2014-2016 Bhathiya Perera
21+
22+
This program is free software; you can redistribute it and/or modify
23+
it under the terms of the GNU General Public License as published by
24+
the Free Software Foundation; either version 2 of the License, or
25+
(at your option) any later version.
26+
27+
This program is distributed in the hope that it will be useful,
28+
but WITHOUT ANY WARRANTY; without even the implied warranty of
29+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30+
GNU General Public License for more details.
31+
32+
You should have received a copy of the GNU General Public License along
33+
with this program; if not, write to the Free Software Foundation, Inc.,
34+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
35+
</pre>
36+
</body>
37+
</html>

Features/xquestion.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "Features/xquestion.h"
2+
3+
XQuestion::XQuestion(QObject *parent) : QObject(parent)
4+
{
5+
}
6+
7+
void XQuestion::SetData(QString title, QString note, QString input, QString output, QString code)
8+
{
9+
m_title = title;
10+
m_note = note;
11+
m_input = input;
12+
m_output = output;
13+
m_code = code;
14+
}
15+
16+
void XQuestion::SetPassed(bool isPassed)
17+
{
18+
if(isPassed) {
19+
m_state = 1;
20+
} else {
21+
m_state = 2;
22+
}
23+
}
24+
25+
int XQuestion::GetState()
26+
{
27+
return m_state;
28+
}

Features/xquestion.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef XQUESTION_H
2+
#define XQUESTION_H
3+
4+
#include <QObject>
5+
6+
class XQuestion: public QObject {
7+
Q_OBJECT
8+
private:
9+
int m_state = 0;
10+
public:
11+
QString m_title;
12+
QString m_note;
13+
QString m_input;
14+
QString m_output;
15+
QString m_code;
16+
17+
explicit XQuestion(QObject *parent = 0);
18+
void SetData(QString title, QString note, QString input, QString output, QString code);
19+
void SetPassed(bool isPassed);
20+
int GetState();
21+
};
22+
23+
#endif // XQUESTION_H

Features/xtute.cpp

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#include "Features/xtute.h"
2+
3+
4+
XTute::XTute(QObject *parent) : QObject(parent), m_questions(nullptr) {
5+
}
6+
7+
void XTute::extractTo(QString& note, QTextStream& in)
8+
{
9+
QString line;
10+
while (!in.atEnd()) {
11+
line = in.readLine();
12+
if(line.startsWith(tr(SEP))) {
13+
break;
14+
}
15+
if (note.length() == 0) {
16+
note.append(line);
17+
} else {
18+
note.append("\n").append(line);
19+
}
20+
}
21+
}
22+
23+
void XTute::Load(QString fileName)
24+
{
25+
delete_questions();
26+
m_questions = new QList<XQuestion*>();
27+
28+
QFile inputFile(fileName);
29+
if (inputFile.open(QIODevice::ReadOnly))
30+
{
31+
QTextStream in(&inputFile);
32+
while (!in.atEnd())
33+
{
34+
QString title, inp, code, out, note, line;
35+
inp = tr("");
36+
code = tr("");
37+
out = tr("");
38+
note = tr("");
39+
XQuestion* x = new XQuestion();
40+
41+
// Title
42+
line = in.readLine();
43+
if (!line.startsWith(tr("#>|<")) || line.length() <= 4) {
44+
break;
45+
}
46+
title = line.mid(4);
47+
48+
// Others
49+
extractTo(note, in);
50+
extractTo(inp, in);
51+
extractTo(out, in);
52+
extractTo(code, in);
53+
54+
x->SetData(title, note, inp, out, code);
55+
m_questions->append(x);
56+
57+
}
58+
inputFile.close();
59+
m_loaded = (m_questions->size() > 0);
60+
}
61+
}
62+
63+
bool XTute::IsLoaded()
64+
{
65+
return m_loaded;
66+
}
67+
68+
void XTute::InitList(QListWidget *w, QProgressBar* p)
69+
{
70+
w->clear();
71+
QListIterator<XQuestion*> i(*m_questions);
72+
int pass = 0;
73+
int total = m_questions->count();
74+
while (i.hasNext()) {
75+
XQuestion* x = i.next();
76+
QListWidgetItem* item;
77+
if (x->GetState() == 0) {
78+
item = new QListWidgetItem(m_i_tute, x->m_title, w);
79+
} else if (x->GetState() == 1) {
80+
pass++;
81+
item = new QListWidgetItem(m_i_tutepass, x->m_title, w);
82+
} else {
83+
item = new QListWidgetItem(m_i_tutefail, x->m_title, w);
84+
}
85+
w->addItem(item);
86+
}
87+
p->setValue((int)(pass * 100.0 / total));
88+
}
89+
90+
void XTute::LoadQuestion(int index, CodeEditor *inp, CodeEditor *note, CodeEditor *code)
91+
{
92+
if (index < 0) return;
93+
XQuestion* x = m_questions->at(index);
94+
inp->setPlainText(x->m_input);
95+
note->setPlainText(x->m_note);
96+
code->setPlainText(x->m_code);
97+
// Output is not loaded
98+
}
99+
100+
void XTute::Mark(int index, QString answer, QListWidget *w, QProgressBar* p)
101+
{
102+
if (index < 0) return;
103+
XQuestion* x = m_questions->value(index);
104+
x->SetPassed(x->m_output.compare(answer) == 0);
105+
InitList(w, p);
106+
}
107+
108+
void XTute::delete_questions()
109+
{
110+
if(m_questions != nullptr) {
111+
QListIterator<XQuestion*> i(*m_questions);
112+
while (i.hasNext()) {
113+
XQuestion* x = i.next();
114+
delete x;
115+
}
116+
m_questions->clear();
117+
delete m_questions;
118+
}
119+
}
120+
121+
XTute::~XTute()
122+
{
123+
delete_questions();
124+
}

Features/xtute.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef XTUTE_H
2+
#define XTUTE_H
3+
4+
#include <QObject>
5+
#include <QMap>
6+
#include <QList>
7+
#include <QIODevice>
8+
#include <QFile>
9+
#include <QApplication>
10+
#include <QListWidget>
11+
#include <QProgressBar>
12+
#include <QTextStream>
13+
#include <QPixmap>
14+
#include <QIcon>
15+
#include <QDebug>
16+
#include "CodeEditor/codeeditor.h"
17+
#include "xquestion.h"
18+
19+
#define SEP "#>>>>>>>>>>>>>><<<<<<<<<<<<<<<#"
20+
21+
class XTute : public QObject {
22+
Q_OBJECT
23+
public:
24+
explicit XTute(QObject *parent = 0);
25+
void Load(QString fileName);
26+
bool IsLoaded();
27+
void InitList(QListWidget *w, QProgressBar *p);
28+
void LoadQuestion(int index, CodeEditor *inp, CodeEditor *note, CodeEditor *code);
29+
void Mark(int index, QString answer, QListWidget *w, QProgressBar *p);
30+
~XTute();
31+
void delete_questions();
32+
private:
33+
const QIcon m_i_tute = QIcon(QPixmap(":/data/Icons/Tute.png"));
34+
const QIcon m_i_tutepass = QIcon(QPixmap(":/data/Icons/TutePass.png"));
35+
const QIcon m_i_tutefail = QIcon(QPixmap(":/data/Icons/TuteFail.png"));
36+
37+
void extractTo(QString& note, QTextStream& in);
38+
QList<XQuestion*> *m_questions;
39+
bool m_loaded = false;
40+
};
41+
42+
#endif // XTUTE_H

Icons/Test.png

11.3 KB
Loading

Icons/Tute.png

40 KB
Loading

Icons/TuteFail.png

38.6 KB
Loading

Icons/TuteLoad.png

17.3 KB
Loading

Icons/TutePass.png

39.1 KB
Loading

0 commit comments

Comments
 (0)