Rewrite of SnapmaticProperties

This commit is contained in:
Rafael 2016-12-10 04:35:24 +01:00
parent 601552dc26
commit ac40a0d194
6 changed files with 58 additions and 100 deletions

View file

@ -265,14 +265,14 @@ void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, QString pictu
} }
if (picture->isJsonOk()) if (picture->isJsonOk())
{ {
locX = QString::number(picture->getLocationX()); locX = QString::number(picture->getSnapmaticProperties().location.x);
locY = QString::number(picture->getLocationY()); locY = QString::number(picture->getSnapmaticProperties().location.y);
locZ = QString::number(picture->getLocationZ()); locZ = QString::number(picture->getSnapmaticProperties().location.z);
crewID = crewDB->getCrewName(picture->getCrewNumber()); crewID = crewDB->getCrewName(picture->getSnapmaticProperties().crewID);
created = picture->getCreatedDateTime().toString(Qt::DefaultLocaleShortDate); created = picture->getSnapmaticProperties().createdDateTime.toString(Qt::DefaultLocaleShortDate);
plyrsList = picture->getPlayers(); plyrsList = picture->getSnapmaticProperties().playersList;
picTitl = picture->getPictureTitl(); picTitl = picture->getPictureTitl();
picArea = picture->getArea(); picArea = picture->getSnapmaticProperties().area;
if (globalMap.contains(picArea)) if (globalMap.contains(picArea))
{ {
picAreaStr = globalMap[picArea]; picAreaStr = globalMap[picArea];

View file

@ -74,7 +74,7 @@ void ProfileLoader::run()
if (picture->readingPicture()) if (picture->readingPicture())
{ {
emit pictureLoaded(picture, picturePath); emit pictureLoaded(picture, picturePath);
int crewNumber = picture->getCrewNumber(); int crewNumber = picture->getSnapmaticProperties().crewID;
if (!crewList.contains(crewNumber)) if (!crewList.contains(crewNumber))
{ {
crewList.append(crewNumber); crewList.append(crewNumber);

View file

@ -60,18 +60,6 @@ SnapmaticPicture::SnapmaticPicture(const QString &fileName, QObject *parent) : Q
// INIT JSON // INIT JSON
jsonOk = 0; jsonOk = 0;
jsonStr = ""; jsonStr = "";
jsonLocX = 0;
jsonLocY = 0;
jsonLocZ = 0;
jsonCrewID = 0;
jsonArea = "";
jsonCreatedTimestamp = 0;
jsonPlyrsList = QStringList();
jsonMeme = 0;
jsonMug = 0;
jsonSelfie = 0;
jsonDirector = 0;
jsonRockstarEditor = 0;
} }
SnapmaticPicture::~SnapmaticPicture() SnapmaticPicture::~SnapmaticPicture()
@ -484,54 +472,52 @@ void SnapmaticPicture::parseJsonContent()
{ {
QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonStr.toLatin1()); QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonStr.toLatin1());
QJsonObject jsonObject = jsonDocument.object(); QJsonObject jsonObject = jsonDocument.object();
QVariantMap jsonMap = jsonObject.toVariantMap();
if (jsonMap.contains("loc")) if (jsonObject.contains("loc"))
{ {
QJsonObject locObject = jsonObject["loc"].toObject(); QJsonObject locObject = jsonObject["loc"].toObject();
QVariantMap locMap = locObject.toVariantMap(); if (locObject.contains("x")) { localSpJson.location.x = locObject["x"].toDouble(); }
if (locMap.contains("x")) { jsonLocX = locMap["x"].toDouble(); } if (locObject.contains("y")) { localSpJson.location.y = locObject["y"].toDouble(); }
if (locMap.contains("y")) { jsonLocY = locMap["y"].toDouble(); } if (locObject.contains("z")) { localSpJson.location.z = locObject["z"].toDouble(); }
if (locMap.contains("z")) { jsonLocZ = locMap["z"].toDouble(); }
} }
if (jsonMap.contains("area")) if (jsonObject.contains("area"))
{ {
jsonArea = jsonMap["area"].toString(); localSpJson.area = jsonObject["area"].toString();
} }
if (jsonMap.contains("crewid")) if (jsonObject.contains("crewid"))
{ {
jsonCrewID = jsonMap["crewid"].toInt(); localSpJson.crewID = jsonObject["crewid"].toInt();
} }
if (jsonMap.contains("creat")) if (jsonObject.contains("creat"))
{ {
QDateTime createdTimestamp; QDateTime createdTimestamp;
jsonCreatedTimestamp = jsonMap["creat"].toUInt(); localSpJson.createdTimestamp = jsonObject["creat"].toVariant().toUInt();
createdTimestamp.setTime_t(jsonCreatedTimestamp); createdTimestamp.setTime_t(localSpJson.createdTimestamp);
jsonCreatedDateTime = createdTimestamp; localSpJson.createdDateTime = createdTimestamp;
} }
if (jsonMap.contains("plyrs")) if (jsonObject.contains("plyrs"))
{ {
jsonPlyrsList = jsonMap["plyrs"].toStringList(); localSpJson.playersList = jsonObject["plyrs"].toVariant().toStringList();
} }
if (jsonMap.contains("meme")) if (jsonObject.contains("meme"))
{ {
jsonMeme = jsonMap["meme"].toBool(); localSpJson.isMeme = jsonObject["meme"].toBool();
} }
if (jsonMap.contains("mug")) if (jsonObject.contains("mug"))
{ {
jsonMug = jsonMap["mug"].toBool(); localSpJson.isMug = jsonObject["mug"].toBool();
} }
if (jsonMap.contains("slf")) if (jsonObject.contains("slf"))
{ {
jsonSelfie = jsonMap["slf"].toBool(); localSpJson.isSelfie = jsonObject["slf"].toBool();
} }
if (jsonMap.contains("drctr")) if (jsonObject.contains("drctr"))
{ {
jsonDirector = jsonMap["drctr"].toBool(); localSpJson.isFromDirector = jsonObject["drctr"].toBool();
} }
if (jsonMap.contains("rsedtr")) if (jsonObject.contains("rsedtr"))
{ {
jsonRockstarEditor = jsonMap["rsedtr"].toBool(); localSpJson.isFromRSEditor = jsonObject["rsedtr"].toBool();
} }
jsonOk = true; jsonOk = true;
@ -542,44 +528,14 @@ bool SnapmaticPicture::isJsonOk()
return jsonOk; return jsonOk;
} }
QString SnapmaticPicture::getArea()
{
return jsonArea;
}
QString SnapmaticPicture::getJsonStr() QString SnapmaticPicture::getJsonStr()
{ {
return jsonStr; return jsonStr;
} }
int SnapmaticPicture::getCrewNumber() SnapmaticProperties SnapmaticPicture::getSnapmaticProperties()
{ {
return jsonCrewID; return localSpJson;
}
double SnapmaticPicture::getLocationX()
{
return jsonLocX;
}
double SnapmaticPicture::getLocationY()
{
return jsonLocY;
}
double SnapmaticPicture::getLocationZ()
{
return jsonLocZ;
}
QStringList SnapmaticPicture::getPlayers()
{
return jsonPlyrsList;
}
QDateTime SnapmaticPicture::getCreatedDateTime()
{
return jsonCreatedDateTime;
} }
// VISIBILITY // VISIBILITY

View file

@ -26,6 +26,25 @@
#include <QImage> #include <QImage>
#include <QFile> #include <QFile>
struct SnapmaticProperties {
struct SnapmaticLocation {
double x;
double y;
double z;
};
int crewID;
QString area;
QStringList playersList;
uint createdTimestamp;
QDateTime createdDateTime;
bool isMeme;
bool isMug;
bool isSelfie;
bool isFromDirector;
bool isFromRSEditor;
SnapmaticLocation location;
};
class SnapmaticPicture : public QObject class SnapmaticPicture : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -51,13 +70,8 @@ public:
// JSON // JSON
bool isJsonOk(); bool isJsonOk();
QString getArea();
int getCrewNumber();
QString getJsonStr(); QString getJsonStr();
double getLocationX(); SnapmaticProperties getSnapmaticProperties();
double getLocationY();
double getLocationZ();
QStringList getPlayers();
// VISIBILITY // VISIBILITY
bool isHidden(); bool isHidden();
@ -98,22 +112,10 @@ private:
QByteArray rawPicContent; QByteArray rawPicContent;
// JSON // JSON
void parseJsonContent();
bool jsonOk; bool jsonOk;
int jsonCrewID;
QString jsonStr; QString jsonStr;
double jsonLocX; void parseJsonContent();
double jsonLocY; SnapmaticProperties localSpJson;
double jsonLocZ;
QString jsonArea;
QStringList jsonPlyrsList;
uint jsonCreatedTimestamp;
QDateTime jsonCreatedDateTime;
bool jsonMeme;
bool jsonMug;
bool jsonSelfie;
bool jsonDirector;
bool jsonRockstarEditor;
signals: signals:

View file

@ -407,7 +407,7 @@ void UserInterface::openSnapmaticFile(SnapmaticPicture *picture)
picDialog->setSnapmaticPicture(picture, true); picDialog->setSnapmaticPicture(picture, true);
picDialog->setModal(true); picDialog->setModal(true);
int crewID = picture->getCrewNumber(); int crewID = picture->getSnapmaticProperties().crewID;
if (crewID != 0) { crewDB->addCrew(crewID); } if (crewID != 0) { crewDB->addCrew(crewID); }
QObject::connect(threadDB, SIGNAL(playerNameFound(int, QString)), profileDB, SLOT(setPlayerName(int, QString))); QObject::connect(threadDB, SIGNAL(playerNameFound(int, QString)), profileDB, SLOT(setPlayerName(int, QString)));

View file

@ -435,7 +435,7 @@ int main(int argc, char *argv[])
picDialog->setWindowIcon(IconLoader::loadingAppIcon()); picDialog->setWindowIcon(IconLoader::loadingAppIcon());
picDialog->setSnapmaticPicture(&picture, readOk); picDialog->setSnapmaticPicture(&picture, readOk);
int crewID = picture.getCrewNumber(); int crewID = picture.getSnapmaticProperties().crewID;
if (crewID != 0) { crewDB->addCrew(crewID); } if (crewID != 0) { crewDB->addCrew(crewID); }
if (!readOk) { return 1; } if (!readOk) { return 1; }