2018-04-11 20:27:22 +03:00
|
|
|
#include "backEnd.h"
|
|
|
|
#include <cmath>
|
2018-01-20 17:44:28 +03:00
|
|
|
|
2018-04-11 20:27:22 +03:00
|
|
|
BackEnd::BackEnd():
|
2018-01-20 17:44:28 +03:00
|
|
|
QObject()
|
|
|
|
{
|
2018-04-11 22:13:34 +03:00
|
|
|
isFirstStart = true;
|
|
|
|
lvl = 1;
|
|
|
|
readCnfig();
|
2018-04-11 20:27:22 +03:00
|
|
|
}
|
|
|
|
|
2018-04-11 22:13:34 +03:00
|
|
|
void BackEnd::writeConfig() const{
|
2018-01-20 17:44:28 +03:00
|
|
|
QFile f(SAVE);
|
|
|
|
if(f.open(QIODevice::WriteOnly|QIODevice::Truncate)){
|
2018-04-11 22:13:34 +03:00
|
|
|
f.write((char*)(&isFirstStart), sizeof(isFirstStart));
|
|
|
|
f.write((char*)(&lvl), sizeof(lvl));
|
2018-01-20 17:44:28 +03:00
|
|
|
f.close();
|
|
|
|
}
|
|
|
|
}
|
2018-04-11 20:27:22 +03:00
|
|
|
|
2018-04-11 22:13:34 +03:00
|
|
|
void BackEnd::readCnfig() {
|
2018-01-20 17:44:28 +03:00
|
|
|
QFile f(SAVE);
|
|
|
|
if(f.open(QIODevice::ReadOnly)){
|
2018-04-11 22:13:34 +03:00
|
|
|
f.read((char*)&isFirstStart,sizeof(isFirstStart));
|
|
|
|
f.read((char*)&lvl,sizeof(lvl));
|
2018-01-20 17:44:28 +03:00
|
|
|
f.close();
|
2018-04-11 22:13:34 +03:00
|
|
|
emit isFirstChanged();
|
2018-01-20 17:44:28 +03:00
|
|
|
}
|
2018-04-11 22:13:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned short BackEnd::getMinSteps(const unsigned short lvl) const{
|
|
|
|
return pow(2, lvl) - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackEnd::save(const short &lvl){
|
|
|
|
this->lvl = lvl;
|
|
|
|
writeConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BackEnd::isFirst()const{
|
|
|
|
return isFirstStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackEnd::setShowHelp(bool state){
|
|
|
|
isFirstStart = state;
|
|
|
|
emit isFirstChanged();
|
|
|
|
writeConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
short BackEnd::read()const{
|
|
|
|
return lvl;
|
|
|
|
}
|
|
|
|
|
|
|
|
BackEnd::~BackEnd(){
|
|
|
|
writeConfig();
|
2018-01-20 17:44:28 +03:00
|
|
|
}
|