Skip to content
Snippets Groups Projects
Commit f37b9efe authored by SeeLook's avatar SeeLook :musical_note:
Browse files

Exam summary - use QML Texts instead of html table

- use QStringList as a model for the exam results
parent e4bbdca7
No related branches found
No related tags found
No related merge requests found
Pipeline #3151 skipped
......@@ -35,13 +35,10 @@
#include <QtCore/qdebug.h>
/**
* returns 2 columns row of table
*/
QString row2(const QString& S1, const QString& S2) {
return QString("<tr><td>%1: </td><td><b>%2</b></td></tr>").arg(S1, S2);
}
inline QStringList getDelegate(const QString& label, float value, float wTotal) {
return QStringList() << label + QLatin1String(": ") << QString(" <b>%1</b> (%2\%)").arg(value).arg(qRound(value * 100.0 / wTotal));
}
TexamSummary::TexamSummary(QQuickItem* parent) :
QQuickItem(parent)
......@@ -63,72 +60,71 @@ TexamSummary::TexamSummary(QQuickItem* parent) :
arg((qreal)exam->averageReactonTime()/10.0, 0, 'f', 1, '0')) +
"</table>", this);
*/
QString effStr;
if (m_exam->mistakes() || m_exam->halfMistaken()) {
float wAccid = 0.0, wKey = 0.0, wNote = 0.0, wOctave = 0.0, wStyle = 0.0, wPos = 0.0, wString = 0.0, wTotal;
float wInto = 0.0, wLittle = 0.0, wPoor = 0.0;
float wAccid = 0.0f, wKey = 0.0f, wNote = 0.0f, wOctave = 0.0f, wStyle = 0.0f, wPos = 0.0f, wString = 0.0f, wTotal;
float wInto = 0.0f, wLittle = 0.0f, wPoor = 0.0f;
for(int i = 0; i < m_exam->count(); ++i) {
if (!m_exam->question(i)->isCorrect()) {
if(m_exam->question(i)->wrongAccid()) wAccid++;
if(m_exam->question(i)->wrongKey()) wKey++;
if(m_exam->question(i)->wrongNote()) wNote++;
if(m_exam->question(i)->wrongOctave()) wOctave++;
if(m_exam->question(i)->wrongStyle()) wStyle++;
if(m_exam->question(i)->wrongPos()) wPos++;
if(m_exam->question(i)->wrongString()) wString++;
if(m_exam->question(i)->wrongIntonation()) wInto++;
if(m_exam->question(i)->littleNotes()) wLittle++;
if(m_exam->question(i)->poorEffect()) wPoor++;
if (m_exam->question(i)->wrongAccid()) wAccid++;
if (m_exam->question(i)->wrongKey()) wKey++;
if (m_exam->question(i)->wrongNote()) wNote++;
if (m_exam->question(i)->wrongOctave()) wOctave++;
if (m_exam->question(i)->wrongStyle()) wStyle++;
if (m_exam->question(i)->wrongPos()) wPos++;
if (m_exam->question(i)->wrongString()) wString++;
if (m_exam->question(i)->wrongIntonation()) wInto++;
if (m_exam->question(i)->littleNotes()) wLittle++;
if (m_exam->question(i)->poorEffect()) wPoor++;
}
}
effStr += QLatin1String("<tr><td colspan=\"2\">-------- ") + tr("Kinds of mistakes") + QLatin1String(": --------</td></tr>");
wTotal = wAccid + wKey + wNote + wOctave + wStyle + wPos + wString + wInto + wLittle + wPoor;
QString cp = QStringLiteral("%)"); // closing percent '%)'
if (wNote) {
effStr += row2(tr("Wrong notes"), QString("%1 (").arg(wNote) + QString::number(qRound(wNote * 100.0 / wTotal)) + cp);
m_resultsModel << getDelegate(tr("Wrong notes"), wNote, wTotal);
m_kindOfMistakes << static_cast<int>(wNote);
}
if (wAccid) {
effStr += row2(tr("Wrong accidentals"), QString("%1 (").arg(wAccid) + QString::number(qRound(wAccid * 100.0 / wTotal)) + cp);
m_resultsModel << getDelegate(tr("Wrong accidentals"), wAccid, wTotal);
m_kindOfMistakes << static_cast<int>(wAccid);
}
if (wKey) {
effStr += row2(tr("Wrong key signatures"), QString("%1 (").arg(wKey) + QString::number(qRound(wKey * 100.0 / wTotal)) + cp);
m_resultsModel << getDelegate(tr("Wrong key signatures"), wKey, wTotal);
m_kindOfMistakes << static_cast<int>(wKey);
}
if (wOctave){
effStr += row2(tr("Wrong octaves"), QString("%1 (").arg(wOctave) + QString::number(qRound(wOctave * 100.0 / wTotal)) + cp);
m_resultsModel <<getDelegate(tr("Wrong octaves"), wOctave, wTotal);
m_kindOfMistakes << static_cast<int>(wOctave);
}
if (wStyle) {
effStr += row2(tr("Wrong note names"), QString("%1 (").arg(wStyle)) + QString::number(qRound(wStyle * 100.0 / wTotal)) + cp;
m_resultsModel << getDelegate(tr("Wrong note names"), wStyle, wTotal);
m_kindOfMistakes << static_cast<int>(wStyle);
}
if (wPos) {
effStr += row2(tr("Wrong positions on guitar"), QString("%1 (").arg(wPos) + QString::number(qRound(wPos * 100.0 / wTotal)) + cp);
m_resultsModel << getDelegate(tr("Wrong positions on guitar"), wPos, wTotal);
m_kindOfMistakes << static_cast<int>(wPos);
}
if (wString) {
effStr += row2(tr("Wrong strings"), QString("%1 (").arg(wString) + QString::number(qRound(wString * 100.0 / wTotal)) + cp);
m_resultsModel << getDelegate(tr("Wrong strings"), wString, wTotal);
m_kindOfMistakes << static_cast<int>(wString);
}
if (wInto) {
effStr += row2(tr("Out of tune"), QString("%1 (").arg(wInto) + QString::number(qRound(wInto * 100.0 / wTotal)) + cp);
m_resultsModel << getDelegate(tr("Out of tune"), wInto, wTotal);
m_kindOfMistakes << static_cast<int>(wInto);
}
if (wLittle) {
effStr += row2(QApplication::translate("AnswerText", "little valid notes", "the amount of correct notes in an answer is little"),
QString("%1 (").arg(wLittle) + QString::number(qRound(wLittle * 100.0 / wTotal)) + cp);
m_resultsModel << getDelegate(QApplication::translate("AnswerText", "little valid notes", "the amount of correct notes in an answer is little"),
wLittle, wTotal);
m_kindOfMistakes << static_cast<int>(wLittle);
}
if (wPoor) {
effStr += row2(QApplication::translate("AnswerText", "poor effectiveness"),
QString("%1 (").arg(wPoor) + QString::number(qRound(wPoor * 100.0 / wTotal)) + cp);
m_resultsModel << getDelegate(QApplication::translate("AnswerText", "poor effectiveness"), wPoor, wTotal);
m_kindOfMistakes << static_cast<int>(wPoor);
}
}
m_results = tr("Results:") + QLatin1String("<table>") +
row2(TexTrans::effectTxt(), QString::number(qRound(m_exam->effectiveness())) + QLatin1String("%")) + effStr + QLatin1String("</table>");
m_resultHeader = tr("Results:") + QLatin1String("<br>") + TexTrans::effectTxt()
+ QString(": <b>%1\%</b><br><br>").arg(qRound(m_exam->effectiveness()))
+ tr("Kinds of mistakes") + QLatin1String(":");
}
......
......@@ -39,7 +39,8 @@ class TexamSummary : public QQuickItem
Q_PROPERTY(TlevelPreviewItem* levelPreview READ levelPreview WRITE setLevelPreview)
// Exam properties
Q_PROPERTY(QString student READ student NOTIFY updateExam)
Q_PROPERTY(QString results READ results NOTIFY updateExam)
Q_PROPERTY(QString resultHeader READ resultHeader NOTIFY updateExam)
Q_PROPERTY(QStringList resultsModel READ resultsModel NOTIFY updateExam)
Q_PROPERTY(QList<int> kindOfMistakes READ kindOfMistakes NOTIFY updateExam)
Q_PROPERTY(bool hasVariousMistakes READ hasVariousMistakes NOTIFY updateExam)
......@@ -50,7 +51,8 @@ public:
void setLevelPreview(TlevelPreviewItem* lp);
QString student() const;
QString results() const { return m_results; }
QString resultHeader() const { return m_resultHeader; }
QStringList resultsModel() const { return m_resultsModel; }
QList<int> kindOfMistakes() { return m_kindOfMistakes; }
......@@ -98,7 +100,8 @@ private:
Texam *m_exam = nullptr;
TlevelPreviewItem *m_levelPreview = nullptr;
bool m_accepted = false;
QString m_results;
QString m_resultHeader;
QStringList m_resultsModel;
QList<int> m_kindOfMistakes;
};
......
/** This file is part of Nootka (http://nootka.sf.net) *
* Copyright (C) 2018-2020 by Tomasz Bojczuk (seelook@gmail.com) *
* Copyright (C) 2018-2021 by Tomasz Bojczuk (seelook@gmail.com) *
* on the terms of GNU GPLv3 license (http://www.gnu.org/licenses) */
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtGraphicalEffects 1.0
import Nootka.Exam 1.0
import "../level"
......@@ -33,14 +34,37 @@ TexamSummary {
}
Text {
anchors.horizontalCenter: parent.horizontalCenter
// width: parent.width * 0.9
text: results; textFormat: Text.RichText
horizontalAlignment: Text.AlignHCenter
text: resultHeader; textFormat: Text.StyledText
font.pixelSize: NOO.factor() * 1.1
}
TpieChartItem {
Grid {
anchors.horizontalCenter: parent.horizontalCenter
columns: 2; columnSpacing: NOO.factor()
Repeater {
model: resultsModel
Text {
text: modelData
color: activPal.text; textFormat: Text.StyledText
}
}
}
Item {
visible: hasVariousMistakes
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width / 2; height: width
values: summDialog.kindOfMistakes
TpieChartItem {
id: pie
anchors.fill: parent
values: summDialog.kindOfMistakes
}
DropShadow {
anchors.fill: pie
horizontalOffset: NOO.factor() / 2; verticalOffset: NOO.factor() / 2
radius: NOO.factor() * 2
samples: 1 + radius * 2; color: activPal.shadow
source: pie
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment