-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmediator.cpp
71 lines (60 loc) · 1.82 KB
/
mediator.cpp
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
#include "mediator.h"
#include <QDir>
#include <iostream>
Mediator::Mediator(QObject *parent): QObject(parent)
{
// set data path
dataPath = QStandardPaths::standardLocations(QStandardPaths::DataLocation).value(0);
QDir dir(dataPath);
if (!dir.exists())
dir.mkpath(dataPath);
if (!dataPath.isEmpty() && !dataPath.endsWith("/"))
dataPath += "/";
dataPath += "gym_post_data.txt";
_postModel = new PostModel(dataPath);
std::cout << dataPath.toStdString() << std::endl;
}
void Mediator::insertPost(QString title, QDateTime date, QString content, QString reaction, quint16 weight, quint16 calories, bool run, QList<QUrl> photos)
{
_postModel->insertPost(title, date, content, reaction, weight, calories, run, photos);
emit postModelChanged();
saveAll();
}
void Mediator::editPost(int index, QString title, QDateTime date, QString content, QString reaction, quint16 weight, quint16 calories, bool run, QList<QUrl> photos)
{
_postModel->editPost(index, title, date, content, reaction, weight, calories, run, photos);
emit postModelChanged();
saveAll();
}
void Mediator::deletePost(int index)
{
_postModel->deletePost(index);
emit postModelChanged();
saveAll();
}
void Mediator::addPoints(int points)
{
_postModel->addPoints(points);
}
QString Mediator::getWorkoutsContent()
{
// load cached
if (!workoutsContent.isEmpty())
return workoutsContent;
// or load from file
QFile qfile(":workouts/workouts.json");
QTextStream qtxstream(&qfile);
qfile.open(QIODevice::ReadOnly | QIODevice::Text);
QString content = "", line;
while(!qtxstream.atEnd())
{
line = qtxstream.readLine();
content += line;
}
workoutsContent = content;
return content;
}
void Mediator::saveAll()
{
_postModel->saveModel();
}