Skip to content

Commit

Permalink
Saved progress
Browse files Browse the repository at this point in the history
  • Loading branch information
h4zm1 committed Aug 24, 2021
1 parent 0ad51c6 commit 8f7e26c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
54 changes: 49 additions & 5 deletions SimplePG/SimplePG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <dwmapi.h>
#include <wingdi.h>
#include <QXmlStreamReader>

#include <QFileDialog>
#define testSpace 0x0010
long miid = 1010;
static QColor m_clear_color = QColor(Qt::white);
Expand Down Expand Up @@ -58,6 +58,8 @@ SimplePG::SimplePG(QWidget* parent)
::InsertMenuItem(hMenu, 6, true, &mii2);

correctionVal = QPoint(-7, 0);
//loading scores at startup
loadingScore();
//}
}

Expand Down Expand Up @@ -205,13 +207,56 @@ void SimplePG::on_mainBtn_clicked()
counter = new QTimer(this);
QObject::connect(counter, SIGNAL(timeout()), this, SLOT(UpdateTime()));
ui->mainBtn->setDisabled(true);
//updateScore();

return;
}
else
{
finish(false);
}
}
//parsing existing xml file for already stored scores
void SimplePG::loadingScore()
{
QXmlStreamReader xml;

QString filename = QCoreApplication::applicationDirPath() + "/score.xml";
QFile file(filename);
if (!file.open(QFile::ReadOnly | QFile::Text))
{
qDebug() << "error loading XML";
return;
}
xml.setDevice(&file);
while (!xml.atEnd())
{
xml.readNext();
if (xml.isStartElement())
{
QString name = xml.name().toString();
if (name == "score")
{
continue;
}

if (name == "best")
{
bestRecord = xml.readElementText().toInt();
ui->bRec->setText(concTime(bestRecord));
}
if (name == "last")
{
lastRecord = xml.readElementText().toInt();
ui->lRec->setText(concTime(lastRecord));
}
}
}
if (xml.hasError())
{
qDebug() << "error loading XML" << xml.errorString() << "line " << xml.lineNumber();
}
}
void SimplePG::UpdateTime()
{
//if (!counter->isActive()) return;
Expand Down Expand Up @@ -385,10 +430,9 @@ void SimplePG::dataSaver()
xml.setDevice(file);
xml.setAutoFormatting(true);
xml.writeStartDocument();
xml.writeStartElement("content");
xml.writeAttribute("record", "record holder");
xml.writeTextElement("best record", QString::number(bestRecord));
xml.writeTextElement("last record", QString::number(lastRecord));
xml.writeStartElement("score");
xml.writeTextElement("best", QString::number(bestRecord));
xml.writeTextElement("last", QString::number(lastRecord));
xml.writeEndElement();
xml.writeEndDocument();
file->close();
Expand Down
1 change: 1 addition & 0 deletions SimplePG/SimplePG.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SimplePG : public QMainWindow
void finish(bool done);
QString concTime(unsigned xtime);
void dataSaver();
void loadingScore();
//randomizing the buttons and then hide
QPoint current;
//difference between pointer's location and drag's start location.
Expand Down

0 comments on commit 8f7e26c

Please sign in to comment.