added json error msgs

This commit is contained in:
Rafael 2016-03-21 22:40:03 +01:00
parent 53430d82c1
commit efe1727170
2 changed files with 26 additions and 6 deletions

View file

@ -42,7 +42,17 @@ PictureDialog::~PictureDialog()
void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, bool readOk) void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, bool readOk)
{ {
if (readOk) // Showing error if reading error
if (!readOk)
{
QMessageBox::warning(this,tr("Snapmatic Picture Viewer"),tr("Failed at %1").arg(picture->getLastStep())); return;
}
if (picture->isPicOk())
{
ui->labPicture->setPixmap(picture->getPixmap());
}
if (picture->isJsonOk())
{ {
QString locX = QString::number(picture->getLocationX()); QString locX = QString::number(picture->getLocationX());
QString locY = QString::number(picture->getLocationY()); QString locY = QString::number(picture->getLocationY());
@ -51,19 +61,28 @@ void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, bool readOk)
QStringList plyrsList = picture->getPlayers(); QStringList plyrsList = picture->getPlayers();
QString plyrsStr; QString plyrsStr;
foreach (const QString &player, plyrsList) if (plyrsList.length() >= 1)
{ {
plyrsStr.append(", "); foreach (const QString &player, plyrsList)
plyrsStr.append(player); {
plyrsStr.append(", ");
plyrsStr.append(player);
}
plyrsStr.remove(0,2);
} }
if (plyrsStr.length() >= 1) { plyrsStr.remove(0,2); } else
{
plyrsStr = tr("No player");
}
if (crewID == "") { crewID = tr("No crew"); }
this->setWindowTitle(windowTitleStr.arg(picture->getPictureStr())); this->setWindowTitle(windowTitleStr.arg(picture->getPictureStr()));
ui->labJSON->setText(jsonDrawString.arg(locX, locY, locZ, plyrsStr, crewID)); ui->labJSON->setText(jsonDrawString.arg(locX, locY, locZ, plyrsStr, crewID));
ui->labPicture->setPixmap(picture->getPixmap());
} }
else else
{ {
ui->labJSON->setText(jsonDrawString.arg("0.0", "0.0", "0.0", tr("No player"), tr("No crew")));
QMessageBox::warning(this,tr("Snapmatic Picture Viewer"),tr("Failed at %1").arg(picture->getLastStep())); QMessageBox::warning(this,tr("Snapmatic Picture Viewer"),tr("Failed at %1").arg(picture->getLastStep()));
} }
} }

View file

@ -49,6 +49,7 @@ int main(int argc, char *argv[])
bool readOk = picture.readingPictureFromFile(arg1); bool readOk = picture.readingPictureFromFile(arg1);
picDialog.setWindowFlags(picDialog.windowFlags()^Qt::WindowContextHelpButtonHint); picDialog.setWindowFlags(picDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
picDialog.setSnapmaticPicture(&picture, readOk); picDialog.setSnapmaticPicture(&picture, readOk);
if (!readOk) { return 1; }
picDialog.show(); picDialog.show();
return a.exec(); return a.exec();