merged with gta5view 1.8

This commit is contained in:
Syping 2020-08-25 20:47:50 +02:00
parent 181e18503c
commit 4e83cb165a
22 changed files with 2274 additions and 2145 deletions

View file

@ -70,9 +70,18 @@ JsonEditorDialog::JsonEditorDialog(SnapmaticPicture *picture, QWidget *parent) :
#if QT_VERSION >= 0x050200 #if QT_VERSION >= 0x050200
ui->txtJSON->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); ui->txtJSON->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
#else
QFont jsonFont = ui->txtJSON->font();
jsonFont.setStyleHint(QFont::Monospace);
jsonFont.setFixedPitch(true);
ui->txtJSON->setFont(jsonFont);
#endif #endif
QFontMetrics fontMetrics(ui->txtJSON->font()); QFontMetrics fontMetrics(ui->txtJSON->font());
#if QT_VERSION >= 0x050B00
ui->txtJSON->setTabStopDistance(fontMetrics.horizontalAdvance(" "));
#else
ui->txtJSON->setTabStopWidth(fontMetrics.width(" ")); ui->txtJSON->setTabStopWidth(fontMetrics.width(" "));
#endif
QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonCode.toUtf8()); QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonCode.toUtf8());
ui->txtJSON->setStyleSheet("QPlainTextEdit{background-color: rgb(46, 47, 48); color: rgb(238, 231, 172);}"); ui->txtJSON->setStyleSheet("QPlainTextEdit{background-color: rgb(46, 47, 48); color: rgb(238, 231, 172);}");

View file

@ -60,40 +60,10 @@ MapLocationDialog::~MapLocationDialog()
void MapLocationDialog::drawPointOnMap(double xpos_d, double ypos_d) void MapLocationDialog::drawPointOnMap(double xpos_d, double ypos_d)
{ {
qreal screenRatio = AppEnv::screenRatio(); ui->labPos->setText(tr("X: %1\nY: %2", "X and Y position").arg(QString::number(xpos_d), QString::number(ypos_d)));
qreal screenRatioPR = AppEnv::screenRatioPR();
int pointMakerSize = 8 * screenRatio * screenRatioPR;
QPixmap pointMakerPixmap = IconLoader::loadingPointmakerIcon().pixmap(QSize(pointMakerSize, pointMakerSize));
QSize mapPixelSize = QSize(width() * screenRatioPR, height() * screenRatioPR);
int pointMakerHalfSize = pointMakerSize / 2;
long xpos_ms = qRound(xpos_d);
long ypos_ms = qRound(ypos_d);
double xpos_ma = xpos_ms + 4000;
double ypos_ma = ypos_ms + 4000;
double xrat = (double)mapPixelSize.width() / 10000;
double yrat = (double)mapPixelSize.height() / 12000;
long xpos_mp = qRound(xpos_ma * xrat);
long ypos_mp = qRound(ypos_ma * yrat);
long xpos_pr = xpos_mp - pointMakerHalfSize;
long ypos_pr = ypos_mp + pointMakerHalfSize;
QPixmap mapPixmap(mapPixelSize);
QPainter mapPainter(&mapPixmap);
mapPainter.drawPixmap(0, 0, mapPixelSize.width(), mapPixelSize.height(), QPixmap(":/img/mappreview.jpg").scaled(mapPixelSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
mapPainter.drawPixmap(xpos_pr, mapPixelSize.height() - ypos_pr, pointMakerSize, pointMakerSize, pointMakerPixmap);
mapPainter.end();
#if QT_VERSION >= 0x050600
mapPixmap.setDevicePixelRatio(screenRatioPR);
#endif
QPalette backgroundPalette;
backgroundPalette.setBrush(backgroundRole(), QBrush(mapPixmap));
setPalette(backgroundPalette);
xpos_new = xpos_d; xpos_new = xpos_d;
ypos_new = ypos_d; ypos_new = ypos_d;
ui->labPos->setText(tr("X: %1\nY: %2", "X and Y position").arg(QString::number(xpos_d), QString::number(ypos_d))); repaint();
} }
void MapLocationDialog::on_cmdChange_clicked() void MapLocationDialog::on_cmdChange_clicked()
@ -139,6 +109,48 @@ void MapLocationDialog::updatePosFromEvent(int x, int y)
drawPointOnMap(xpos_fp, ypos_fp); drawPointOnMap(xpos_fp, ypos_fp);
} }
void MapLocationDialog::paintEvent(QPaintEvent *ev)
{
QPainter painter(this);
qreal screenRatio = AppEnv::screenRatio();
qreal screenRatioPR = AppEnv::screenRatioPR();
// Paint Map
QSize mapPixelSize = QSize(width() * screenRatioPR, height() * screenRatioPR);
painter.drawPixmap(0, 0, width(), height(), QPixmap(":/img/mappreview.jpg").scaled(mapPixelSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
// Paint Marker
int pointMarkerSize = 8 * screenRatio;
int pointMarkerHalfSize = pointMarkerSize / 2;
long xpos_ms = qRound(xpos_new);
long ypos_ms = qRound(ypos_new);
double xpos_ma = xpos_ms + 4000;
double ypos_ma = ypos_ms + 4000;
double xrat = (double)width() / 10000;
double yrat = (double)height() / 12000;
long xpos_mp = qRound(xpos_ma * xrat);
long ypos_mp = qRound(ypos_ma * yrat);
long xpos_pr;
long ypos_pr;
if (screenRatioPR != 1) {
#ifdef GTA5SYNC_WIN
xpos_pr = xpos_mp - pointMarkerHalfSize;
ypos_pr = ypos_mp + pointMarkerHalfSize;
#else
xpos_pr = xpos_mp - pointMarkerHalfSize + screenRatioPR;
ypos_pr = ypos_mp + pointMarkerHalfSize - screenRatioPR;
#endif
}
else {
xpos_pr = xpos_mp - pointMarkerHalfSize;
ypos_pr = ypos_mp + pointMarkerHalfSize;
}
QPixmap mapMarkerPixmap = IconLoader::loadingPointmakerIcon().pixmap(QSize(pointMarkerSize, pointMarkerSize));
painter.drawPixmap(xpos_pr, height() - ypos_pr, pointMarkerSize, pointMarkerSize, mapMarkerPixmap);
QDialog::paintEvent(ev);
}
void MapLocationDialog::mouseMoveEvent(QMouseEvent *ev) void MapLocationDialog::mouseMoveEvent(QMouseEvent *ev)
{ {
if (!changeMode) { ev->ignore(); } if (!changeMode) { ev->ignore(); }

View file

@ -39,6 +39,7 @@ public:
~MapLocationDialog(); ~MapLocationDialog();
protected: protected:
void paintEvent(QPaintEvent *ev);
void mouseMoveEvent(QMouseEvent *ev); void mouseMoveEvent(QMouseEvent *ev);
void mouseReleaseEvent(QMouseEvent *ev); void mouseReleaseEvent(QMouseEvent *ev);

View file

@ -25,6 +25,11 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Snapmatic Map Viewer</string> <string>Snapmatic Map Viewer</string>
</property> </property>
<property name="styleSheet">
<string notr="true">QDialog#MapLocationDialog {
background-color: transparent;
}</string>
</property>
<layout class="QVBoxLayout" name="vlMapPreview"> <layout class="QVBoxLayout" name="vlMapPreview">
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>

View file

@ -136,24 +136,33 @@ OptionsDialog::~OptionsDialog()
void OptionsDialog::setupTreeWidget() void OptionsDialog::setupTreeWidget()
{ {
for (QString playerIDStr : profileDB->getPlayers()) const QStringList players = profileDB->getPlayers();
{ if (players.length() != 0) {
bool ok; QStringList::const_iterator it = players.constBegin();
int playerID = playerIDStr.toInt(&ok); QStringList::const_iterator end = players.constEnd();
if (ok) while (it != end)
{ {
QString playerName = profileDB->getPlayerName(playerID); bool ok;
int playerID = it->toInt(&ok);
if (ok)
{
QString playerName = profileDB->getPlayerName(playerID);
QStringList playerTreeViewList; QStringList playerTreeViewList;
playerTreeViewList += playerIDStr; playerTreeViewList += *it;
playerTreeViewList += playerName; playerTreeViewList += playerName;
QTreeWidgetItem *playerItem = new QTreeWidgetItem(playerTreeViewList); QTreeWidgetItem *playerItem = new QTreeWidgetItem(playerTreeViewList);
ui->twPlayers->addTopLevelItem(playerItem); ui->twPlayers->addTopLevelItem(playerItem);
playerItems += playerItem; playerItems += playerItem;
}
it++;
} }
ui->twPlayers->sortItems(1, Qt::AscendingOrder);
}
else {
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabPlayers));
} }
ui->twPlayers->sortItems(1, Qt::AscendingOrder);
} }
void OptionsDialog::setupLanguageBox() void OptionsDialog::setupLanguageBox()
@ -362,6 +371,8 @@ void OptionsDialog::applySettings()
#if QT_VERSION >= 0x050200 #if QT_VERSION >= 0x050200
settings->setValue("NavigationBar", ui->cbSnapmaticNavigationBar->isChecked()); settings->setValue("NavigationBar", ui->cbSnapmaticNavigationBar->isChecked());
#endif #endif
#else
settings->setValue("NavigationBar", ui->cbSnapmaticNavigationBar->isChecked());
#endif #endif
settings->endGroup(); settings->endGroup();
@ -722,8 +733,9 @@ void OptionsDialog::setupSnapmaticPictureViewer()
ui->gbSnapmaticPictureViewer->setVisible(false); ui->gbSnapmaticPictureViewer->setVisible(false);
#endif #endif
#else #else
ui->cbSnapmaticNavigationBar->setVisible(false); settings->beginGroup("Interface");
ui->gbSnapmaticPictureViewer->setVisible(false); ui->cbSnapmaticNavigationBar->setChecked(settings->value("NavigationBar", true).toBool());
settings->endGroup();
#endif #endif
} }

View file

@ -135,12 +135,15 @@ void PictureDialog::setupPictureDialog()
smpic = nullptr; smpic = nullptr;
crewStr = ""; crewStr = "";
// Get Snapmatic Resolution
QSize snapmaticResolution = SnapmaticPicture::getSnapmaticResolution();
// Avatar area // Avatar area
qreal screenRatio = AppEnv::screenRatio(); qreal screenRatio = AppEnv::screenRatio();
qreal screenRatioPR = AppEnv::screenRatioPR(); qreal screenRatioPR = AppEnv::screenRatioPR();
if (screenRatio != 1 || screenRatioPR != 1) if (screenRatio != 1 || screenRatioPR != 1)
{ {
avatarAreaPicture = QImage(":/img/avatararea.png").scaledToHeight(536 * screenRatio * screenRatioPR, Qt::FastTransformation); avatarAreaPicture = QImage(":/img/avatararea.png").scaledToHeight(snapmaticResolution.height() * screenRatio * screenRatioPR, Qt::FastTransformation);
} }
else else
{ {
@ -151,7 +154,7 @@ void PictureDialog::setupPictureDialog()
avatarSize = 470; avatarSize = 470;
// DPI calculation (picture) // DPI calculation (picture)
ui->labPicture->setFixedSize(960 * screenRatio, 536 * screenRatio); ui->labPicture->setFixedSize(snapmaticResolution.width() * screenRatio, snapmaticResolution.height() * screenRatio);
ui->labPicture->setFocusPolicy(Qt::StrongFocus); ui->labPicture->setFocusPolicy(Qt::StrongFocus);
ui->labPicture->setScaledContents(true); ui->labPicture->setScaledContents(true);
@ -199,8 +202,8 @@ void PictureDialog::setupPictureDialog()
ui->jsonLayout->setContentsMargins(4 * screenRatio, 10 * screenRatio, 4 * screenRatio, 4 * screenRatio); ui->jsonLayout->setContentsMargins(4 * screenRatio, 10 * screenRatio, 4 * screenRatio, 4 * screenRatio);
// Pre-adapt window for DPI // Pre-adapt window for DPI
setFixedWidth(960 * screenRatio); setFixedWidth(snapmaticResolution.width() * screenRatio);
setFixedHeight(536 * screenRatio); setFixedHeight(snapmaticResolution.height() * screenRatio);
} }
PictureDialog::~PictureDialog() PictureDialog::~PictureDialog()
@ -216,6 +219,15 @@ PictureDialog::~PictureDialog()
delete layout()->menuBar(); delete layout()->menuBar();
} }
#endif #endif
#else
if (naviEnabled)
{
for (QObject *obj : layout()->menuBar()->children())
{
delete obj;
}
delete layout()->menuBar();
}
#endif #endif
for (QObject *obj : manageMenu->children()) for (QObject *obj : manageMenu->children())
{ {
@ -236,18 +248,31 @@ void PictureDialog::closeEvent(QCloseEvent *ev)
void PictureDialog::addPreviousNextButtons() void PictureDialog::addPreviousNextButtons()
{ {
// Windows Vista additions
#ifdef GTA5SYNC_WIN #ifdef GTA5SYNC_WIN
#if QT_VERSION >= 0x050200 #if QT_VERSION >= 0x050200
QToolBar *uiToolbar = new QToolBar("Picture Toolbar", this); QToolBar *uiToolbar = new QToolBar("Picture Toolbar", this);
uiToolbar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); uiToolbar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
uiToolbar->setObjectName("uiToolbar"); uiToolbar->setObjectName("UiToolbar");
uiToolbar->addAction(QIcon(":/img/back.svgz"), "", this, SLOT(previousPictureRequestedSlot())); uiToolbar->addAction(QIcon(":/img/back.svgz"), "", this, SLOT(previousPictureRequestedSlot()));
uiToolbar->addAction(QIcon(":/img/next.svgz"), "", this, SLOT(nextPictureRequestedSlot())); uiToolbar->addAction(QIcon(":/img/next.svgz"), "", this, SLOT(nextPictureRequestedSlot()));
layout()->setMenuBar(uiToolbar); layout()->setMenuBar(uiToolbar);
naviEnabled = true; naviEnabled = true;
#endif #endif
#else
QToolBar *uiToolbar = new QToolBar("Picture Toolbar", this);
#if QT_VERSION < 0x050600
qreal screenRatio = AppEnv::screenRatio();
if (screenRatio != 1) {
QSize iconSize = uiToolbar->iconSize();
uiToolbar->setIconSize(QSize(iconSize.width() * screenRatio, iconSize.height() * screenRatio));
}
#endif
uiToolbar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
uiToolbar->setObjectName("UiToolbar");
uiToolbar->addAction(QIcon(":/img/back.svgz"), "", this, SLOT(previousPictureRequestedSlot()));
uiToolbar->addAction(QIcon(":/img/next.svgz"), "", this, SLOT(nextPictureRequestedSlot()));
layout()->setMenuBar(uiToolbar);
naviEnabled = true;
#endif #endif
} }
@ -368,7 +393,11 @@ void PictureDialog::resizeEvent(QResizeEvent *event)
void PictureDialog::adaptNewDialogSize(QSize newLabelSize) void PictureDialog::adaptNewDialogSize(QSize newLabelSize)
{ {
Q_UNUSED(newLabelSize) Q_UNUSED(newLabelSize)
#if QT_VERSION >= 0x050F00
int newDialogHeight = SnapmaticPicture::getSnapmaticResolution().height();
#else
int newDialogHeight = (ui->labPicture->pixmap()->height() / AppEnv::screenRatioPR()); int newDialogHeight = (ui->labPicture->pixmap()->height() / AppEnv::screenRatioPR());
#endif
newDialogHeight = newDialogHeight + ui->jsonFrame->height(); newDialogHeight = newDialogHeight + ui->jsonFrame->height();
if (naviEnabled) newDialogHeight = newDialogHeight + layout()->menuBar()->height(); if (naviEnabled) newDialogHeight = newDialogHeight + layout()->menuBar()->height();
setMaximumSize(width(), newDialogHeight); setMaximumSize(width(), newDialogHeight);
@ -686,10 +715,11 @@ void PictureDialog::renderPicture()
{ {
if (overlayEnabled) if (overlayEnabled)
{ {
QPixmap shownImagePixmap(960 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR); QSize snapmaticResolution = SnapmaticPicture::getSnapmaticResolution();
QPixmap shownImagePixmap(snapmaticResolution.width() * screenRatio * screenRatioPR, snapmaticResolution.height() * screenRatio * screenRatioPR);
shownImagePixmap.fill(Qt::transparent); shownImagePixmap.fill(Qt::transparent);
QPainter shownImagePainter(&shownImagePixmap); QPainter shownImagePainter(&shownImagePixmap);
shownImagePainter.drawImage(0, 0, snapmaticPicture.scaled(960 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); shownImagePainter.drawImage(0, 0, snapmaticPicture.scaled(snapmaticResolution.width() * screenRatio * screenRatioPR, snapmaticResolution.height() * screenRatio * screenRatioPR, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
shownImagePainter.drawImage(3 * screenRatio * screenRatioPR, 3 * screenRatio * screenRatioPR, overlayTempImage); shownImagePainter.drawImage(3 * screenRatio * screenRatioPR, 3 * screenRatio * screenRatioPR, overlayTempImage);
shownImagePainter.end(); shownImagePainter.end();
#if QT_VERSION >= 0x050600 #if QT_VERSION >= 0x050600
@ -699,10 +729,11 @@ void PictureDialog::renderPicture()
} }
else else
{ {
QPixmap shownImagePixmap(960 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR); QSize snapmaticResolution = SnapmaticPicture::getSnapmaticResolution();
QPixmap shownImagePixmap(snapmaticResolution.width() * screenRatio * screenRatioPR, snapmaticResolution.height() * screenRatio * screenRatioPR);
shownImagePixmap.fill(Qt::transparent); shownImagePixmap.fill(Qt::transparent);
QPainter shownImagePainter(&shownImagePixmap); QPainter shownImagePainter(&shownImagePixmap);
shownImagePainter.drawImage(0, 0, snapmaticPicture.scaled(960 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); shownImagePainter.drawImage(0, 0, snapmaticPicture.scaled(snapmaticResolution.width() * screenRatio * screenRatioPR, snapmaticResolution.height() * screenRatio * screenRatioPR, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
shownImagePainter.end(); shownImagePainter.end();
#if QT_VERSION >= 0x050600 #if QT_VERSION >= 0x050600
shownImagePixmap.setDevicePixelRatio(screenRatioPR); shownImagePixmap.setDevicePixelRatio(screenRatioPR);
@ -713,15 +744,16 @@ void PictureDialog::renderPicture()
else else
{ {
// Generating Avatar Preview // Generating Avatar Preview
QPixmap avatarPixmap(960 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR); QSize snapmaticResolution = SnapmaticPicture::getSnapmaticResolution();
QPixmap avatarPixmap(snapmaticResolution.width() * screenRatio * screenRatioPR, snapmaticResolution.height() * screenRatio * screenRatioPR);
QPainter snapPainter(&avatarPixmap); QPainter snapPainter(&avatarPixmap);
QFont snapPainterFont; QFont snapPainterFont;
snapPainterFont.setPixelSize(12 * screenRatio * screenRatioPR); snapPainterFont.setPixelSize(12 * screenRatio * screenRatioPR);
snapPainter.drawImage(0, 0, snapmaticPicture.scaled(960 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); snapPainter.drawImage(0, 0, snapmaticPicture.scaled(snapmaticResolution.width() * screenRatio * screenRatioPR, snapmaticResolution.height() * screenRatio * screenRatioPR, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
snapPainter.drawImage(0, 0, avatarAreaPicture); snapPainter.drawImage(0, 0, avatarAreaPicture);
snapPainter.setPen(QColor::fromRgb(255, 255, 255, 255)); snapPainter.setPen(QColor::fromRgb(255, 255, 255, 255));
snapPainter.setFont(snapPainterFont); snapPainter.setFont(snapPainterFont);
snapPainter.drawText(QRect(3 * screenRatio * screenRatioPR, 3 * screenRatio * screenRatioPR, 140 * screenRatio * screenRatioPR, 536 * screenRatio * screenRatioPR), Qt::AlignLeft | Qt::TextWordWrap, tr("Avatar Preview Mode\nPress 1 for Default View")); snapPainter.drawText(QRect(3 * screenRatio * screenRatioPR, 3 * screenRatio * screenRatioPR, 140 * screenRatio * screenRatioPR, snapmaticResolution.height() * screenRatio * screenRatioPR), Qt::AlignLeft | Qt::TextWordWrap, tr("Avatar Preview Mode\nPress 1 for Default View"));
snapPainter.end(); snapPainter.end();
#if QT_VERSION >= 0x050600 #if QT_VERSION >= 0x050600
avatarPixmap.setDevicePixelRatio(screenRatioPR); avatarPixmap.setDevicePixelRatio(screenRatioPR);

View file

@ -73,12 +73,32 @@ PlayerListDialog::PlayerListDialog(QStringList players, ProfileDatabase *profile
// Set Icon for Manage Buttons // Set Icon for Manage Buttons
if (QIcon::hasThemeIcon("go-previous") && QIcon::hasThemeIcon("go-next") && QIcon::hasThemeIcon("list-add")) if (QIcon::hasThemeIcon("go-previous") && QIcon::hasThemeIcon("go-next") && QIcon::hasThemeIcon("list-add"))
{ {
#if QT_VERSION < 0x050600
qreal screenRatio = AppEnv::screenRatio();
if (screenRatio != 1) {
QSize iconSize = ui->cmdMakeAv->iconSize();
iconSize = QSize(iconSize.width() * screenRatio, iconSize.height() * screenRatio);
ui->cmdMakeAv->setIconSize(iconSize);
ui->cmdMakeSe->setIconSize(iconSize);
ui->cmdMakeAd->setIconSize(iconSize);
}
#endif
ui->cmdMakeAv->setIcon(QIcon::fromTheme("go-previous")); ui->cmdMakeAv->setIcon(QIcon::fromTheme("go-previous"));
ui->cmdMakeSe->setIcon(QIcon::fromTheme("go-next")); ui->cmdMakeSe->setIcon(QIcon::fromTheme("go-next"));
ui->cmdMakeAd->setIcon(QIcon::fromTheme("list-add")); ui->cmdMakeAd->setIcon(QIcon::fromTheme("list-add"));
} }
else else
{ {
#if QT_VERSION < 0x050600
qreal screenRatio = AppEnv::screenRatio();
if (screenRatio != 1) {
QSize iconSize = ui->cmdMakeAv->iconSize();
iconSize = QSize(iconSize.width() * screenRatio, iconSize.height() * screenRatio);
ui->cmdMakeAv->setIconSize(iconSize);
ui->cmdMakeSe->setIconSize(iconSize);
ui->cmdMakeAd->setIconSize(iconSize);
}
#endif
ui->cmdMakeAv->setIcon(QIcon(":/img/back.svgz")); ui->cmdMakeAv->setIcon(QIcon(":/img/back.svgz"));
ui->cmdMakeSe->setIcon(QIcon(":/img/next.svgz")); ui->cmdMakeSe->setIcon(QIcon(":/img/next.svgz"));
ui->cmdMakeAd->setIcon(QIcon(":/img/add.svgz")); ui->cmdMakeAd->setIcon(QIcon(":/img/add.svgz"));

View file

@ -264,7 +264,11 @@ void ProfileInterface::insertSnapmaticIPI(QWidget *widget)
QStringList widgetsKeyList = widgets.values(); QStringList widgetsKeyList = widgets.values();
QStringList pictureKeyList = widgetsKeyList.filter("PIC", Qt::CaseSensitive); QStringList pictureKeyList = widgetsKeyList.filter("PIC", Qt::CaseSensitive);
#if QT_VERSION >= 0x050600 #if QT_VERSION >= 0x050600
#if QT_VERSION >= 0x050F00
std::sort(pictureKeyList.rbegin(), pictureKeyList.rend());
#else
qSort(pictureKeyList.rbegin(), pictureKeyList.rend()); qSort(pictureKeyList.rbegin(), pictureKeyList.rend());
#endif
#else #else
qSort(pictureKeyList.begin(), pictureKeyList.end(), qGreater<QString>()); qSort(pictureKeyList.begin(), pictureKeyList.end(), qGreater<QString>());
#endif #endif
@ -284,7 +288,11 @@ void ProfileInterface::insertSavegameIPI(QWidget *widget)
QString widgetKey = widgets[proWidget]; QString widgetKey = widgets[proWidget];
QStringList widgetsKeyList = widgets.values(); QStringList widgetsKeyList = widgets.values();
QStringList savegameKeyList = widgetsKeyList.filter("SGD", Qt::CaseSensitive); QStringList savegameKeyList = widgetsKeyList.filter("SGD", Qt::CaseSensitive);
#if QT_VERSION >= 0x050F00
std::sort(savegameKeyList.begin(), savegameKeyList.end());
#else
qSort(savegameKeyList.begin(), savegameKeyList.end()); qSort(savegameKeyList.begin(), savegameKeyList.end());
#endif
int sgdIndex = savegameKeyList.indexOf(QRegExp(widgetKey)); int sgdIndex = savegameKeyList.indexOf(QRegExp(widgetKey));
ui->vlSavegame->insertWidget(sgdIndex, proWidget); ui->vlSavegame->insertWidget(sgdIndex, proWidget);
@ -303,7 +311,11 @@ void ProfileInterface::dialogNextPictureRequested(QWidget *dialog)
QStringList widgetsKeyList = widgets.values(); QStringList widgetsKeyList = widgets.values();
QStringList pictureKeyList = widgetsKeyList.filter("PIC", Qt::CaseSensitive); QStringList pictureKeyList = widgetsKeyList.filter("PIC", Qt::CaseSensitive);
#if QT_VERSION >= 0x050600 #if QT_VERSION >= 0x050600
#if QT_VERSION >= 0x050F00
std::sort(pictureKeyList.rbegin(), pictureKeyList.rend());
#else
qSort(pictureKeyList.rbegin(), pictureKeyList.rend()); qSort(pictureKeyList.rbegin(), pictureKeyList.rend());
#endif
#else #else
qSort(pictureKeyList.begin(), pictureKeyList.end(), qGreater<QString>()); qSort(pictureKeyList.begin(), pictureKeyList.end(), qGreater<QString>());
#endif #endif
@ -338,7 +350,11 @@ void ProfileInterface::dialogPreviousPictureRequested(QWidget *dialog)
QStringList widgetsKeyList = widgets.values(); QStringList widgetsKeyList = widgets.values();
QStringList pictureKeyList = widgetsKeyList.filter("PIC", Qt::CaseSensitive); QStringList pictureKeyList = widgetsKeyList.filter("PIC", Qt::CaseSensitive);
#if QT_VERSION >= 0x050600 #if QT_VERSION >= 0x050600
#if QT_VERSION >= 0x050F00
std::sort(pictureKeyList.rbegin(), pictureKeyList.rend());
#else
qSort(pictureKeyList.rbegin(), pictureKeyList.rend()); qSort(pictureKeyList.rbegin(), pictureKeyList.rend());
#endif
#else #else
qSort(pictureKeyList.begin(), pictureKeyList.end(), qGreater<QString>()); qSort(pictureKeyList.begin(), pictureKeyList.end(), qGreater<QString>());
#endif #endif
@ -369,7 +385,12 @@ void ProfileInterface::sortingProfileInterface()
ui->vlSnapmatic->setEnabled(false); ui->vlSnapmatic->setEnabled(false);
QStringList widgetsKeyList = widgets.values(); QStringList widgetsKeyList = widgets.values();
#if QT_VERSION >= 0x050F00
std::sort(widgetsKeyList.begin(), widgetsKeyList.end());
#else
qSort(widgetsKeyList.begin(), widgetsKeyList.end()); qSort(widgetsKeyList.begin(), widgetsKeyList.end());
#endif
for (QString widgetKey : widgetsKeyList) for (QString widgetKey : widgetsKeyList)
{ {
@ -1627,7 +1648,7 @@ void ProfileInterface::contextMenuTriggeredPIC(QContextMenuEvent *ev)
contextMenuOpened = true; contextMenuOpened = true;
contextMenu.exec(ev->globalPos()); contextMenu.exec(ev->globalPos());
contextMenuOpened = false; contextMenuOpened = false;
hoverProfileWidgetCheck(); QTimer::singleShot(0, this, SLOT(hoverProfileWidgetCheck()));
} }
void ProfileInterface::contextMenuTriggeredSGD(QContextMenuEvent *ev) void ProfileInterface::contextMenuTriggeredSGD(QContextMenuEvent *ev)
@ -1660,7 +1681,7 @@ void ProfileInterface::contextMenuTriggeredSGD(QContextMenuEvent *ev)
contextMenuOpened = true; contextMenuOpened = true;
contextMenu.exec(ev->globalPos()); contextMenu.exec(ev->globalPos());
contextMenuOpened = false; contextMenuOpened = false;
hoverProfileWidgetCheck(); QTimer::singleShot(0, this, SLOT(hoverProfileWidgetCheck()));
} }
void ProfileInterface::on_saProfileContent_dropped(const QMimeData *mimeData) void ProfileInterface::on_saProfileContent_dropped(const QMimeData *mimeData)
@ -1781,19 +1802,23 @@ bool ProfileInterface::eventFilter(QObject *watched, QEvent *event)
return true; return true;
} }
} }
else if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::WindowActivate) else if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease)
{ {
if ((watched->objectName() == "SavegameWidget" || watched->objectName() == "SnapmaticWidget") && isProfileLoaded) if ((watched->objectName() == "SavegameWidget" || watched->objectName() == "SnapmaticWidget") && isProfileLoaded)
{ {
ProfileWidget *pWidget = nullptr; ProfileWidget *pWidget = nullptr;
for (ProfileWidget *widget : widgets.keys()) QMap<ProfileWidget*, QString>::const_iterator it = widgets.constBegin();
QMap<ProfileWidget*, QString>::const_iterator end = widgets.constEnd();
while (it != end)
{ {
ProfileWidget *widget = it.key();
QPoint mousePos = widget->mapFromGlobal(QCursor::pos()); QPoint mousePos = widget->mapFromGlobal(QCursor::pos());
if (widget->rect().contains(mousePos)) if (widget->rect().contains(mousePos))
{ {
pWidget = widget; pWidget = widget;
break; break;
} }
it++;
} }
if (pWidget != nullptr) if (pWidget != nullptr)
{ {
@ -1827,7 +1852,7 @@ bool ProfileInterface::eventFilter(QObject *watched, QEvent *event)
} }
else if (event->type() == QEvent::WindowDeactivate && isProfileLoaded) else if (event->type() == QEvent::WindowDeactivate && isProfileLoaded)
{ {
if (previousWidget != nullptr) if (previousWidget != nullptr && watched == previousWidget)
{ {
previousWidget->setStyleSheet(QLatin1String("")); previousWidget->setStyleSheet(QLatin1String(""));
previousWidget = nullptr; previousWidget = nullptr;
@ -1863,13 +1888,17 @@ bool ProfileInterface::eventFilter(QObject *watched, QEvent *event)
void ProfileInterface::hoverProfileWidgetCheck() void ProfileInterface::hoverProfileWidgetCheck()
{ {
ProfileWidget *pWidget = nullptr; ProfileWidget *pWidget = nullptr;
for (ProfileWidget *widget : widgets.keys()) QMap<ProfileWidget*, QString>::const_iterator it = widgets.constBegin();
QMap<ProfileWidget*, QString>::const_iterator end = widgets.constEnd();
while (it != end)
{ {
ProfileWidget *widget = it.key();
if (widget->underMouse()) if (widget->underMouse())
{ {
pWidget = widget; pWidget = widget;
break; break;
} }
it++;
} }
if (pWidget != nullptr) if (pWidget != nullptr)
{ {

View file

@ -433,8 +433,8 @@ QString SnapmaticPicture::getSnapmaticHeaderString(const QByteArray &snapmaticHe
QString SnapmaticPicture::getSnapmaticJSONString(const QByteArray &jsonBytes) QString SnapmaticPicture::getSnapmaticJSONString(const QByteArray &jsonBytes)
{ {
QByteArray jsonUsefulBytes = jsonBytes; QByteArray jsonUsefulBytes = jsonBytes;
jsonUsefulBytes.replace('\x00', QString()); jsonUsefulBytes.replace('\x00', "");
jsonUsefulBytes.replace('\x0c', QString()); jsonUsefulBytes.replace('\x0c', "");
return QString::fromUtf8(jsonUsefulBytes.trimmed()); return QString::fromUtf8(jsonUsefulBytes.trimmed());
} }
@ -1339,7 +1339,8 @@ bool SnapmaticPicture::setPictureVisible()
QSize SnapmaticPicture::getSnapmaticResolution() QSize SnapmaticPicture::getSnapmaticResolution()
{ {
return snapmaticResolution; // keep old UI size for now
return QSize(960, 536);
} }
// SNAPMATIC DEFAULTS // SNAPMATIC DEFAULTS

View file

@ -120,7 +120,7 @@ public:
bool setVisible() { return setPictureVisible(); } // Please use setPictureVisible instead bool setVisible() { return setPictureVisible(); } // Please use setPictureVisible instead
// PREDEFINED PROPERTIES // PREDEFINED PROPERTIES
QSize getSnapmaticResolution(); static QSize getSnapmaticResolution();
// SNAPMATIC DEFAULTS // SNAPMATIC DEFAULTS
bool isSnapmaticDefaultsEnforced(); bool isSnapmaticDefaultsEnforced();

View file

@ -20,6 +20,7 @@
#include "imagecropper.h" #include "imagecropper.h"
#include "AppEnv.h" #include "AppEnv.h"
#include <QPainterPath>
#include <QMouseEvent> #include <QMouseEvent>
#include <QPainter> #include <QPainter>

View file

@ -44,7 +44,7 @@
#endif #endif
#ifndef GTA5SYNC_APPVER #ifndef GTA5SYNC_APPVER
#define GTA5SYNC_APPVER "0.2.0" #define GTA5SYNC_APPVER "0.3.0"
#endif #endif
#if __cplusplus #if __cplusplus

View file

@ -39,45 +39,45 @@ QJsonDocument::QJsonDocument() : root_(0) {
// Name: QJsonDocument // Name: QJsonDocument
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonDocument::QJsonDocument(const QJsonObject &object) : root_(0) { QJsonDocument::QJsonDocument(const QJsonObject &object) : root_(0) {
setObject(object); setObject(object);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonDocument // Name: QJsonDocument
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonDocument::QJsonDocument(const QJsonArray &array) : root_(0) { QJsonDocument::QJsonDocument(const QJsonArray &array) : root_(0) {
setArray(array); setArray(array);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: QJsonDocument // Name: QJsonDocument
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonDocument::QJsonDocument(const QJsonDocument &other) : root_(0) { QJsonDocument::QJsonDocument(const QJsonDocument &other) : root_(0) {
if(other.root_) { if(other.root_) {
root_ = other.root_->clone(); root_ = other.root_->clone();
} }
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: ~QJsonDocument // Name: ~QJsonDocument
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonDocument::~QJsonDocument() { QJsonDocument::~QJsonDocument() {
delete root_; delete root_;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: operator= // Name: operator=
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonDocument &QJsonDocument::operator=(const QJsonDocument &other) { QJsonDocument &QJsonDocument::operator=(const QJsonDocument &other) {
QJsonDocument(other).swap(*this); QJsonDocument(other).swap(*this);
return *this; return *this;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: operator!= // Name: operator!=
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonDocument::operator!=(const QJsonDocument &other) const { bool QJsonDocument::operator!=(const QJsonDocument &other) const {
return !(*this == other); return !(*this == other);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -85,30 +85,30 @@ bool QJsonDocument::operator!=(const QJsonDocument &other) const {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonDocument::operator==(const QJsonDocument &other) const { bool QJsonDocument::operator==(const QJsonDocument &other) const {
if(isArray() && other.isArray()) { if(isArray() && other.isArray()) {
return array() == other.array(); return array() == other.array();
} }
if(isObject() && other.isObject()) { if(isObject() && other.isObject()) {
return object() == other.object(); return object() == other.object();
} }
if(isEmpty() && other.isEmpty()) { if(isEmpty() && other.isEmpty()) {
return true; return true;
} }
if(isNull() && other.isNull()) { if(isNull() && other.isNull()) {
return true; return true;
} }
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isArray // Name: isArray
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonDocument::isArray() const { bool QJsonDocument::isArray() const {
return root_ && root_->toArray(); return root_ && root_->toArray();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -116,56 +116,56 @@ bool QJsonDocument::isArray() const {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonDocument::isEmpty() const { bool QJsonDocument::isEmpty() const {
// TODO(eteran): figure out the rules here that Qt5 uses // TODO(eteran): figure out the rules here that Qt5 uses
// it *looks* like they define empty as being NULL // it *looks* like they define empty as being NULL
// which is obviously different than this // which is obviously different than this
return !root_; return !root_;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isNull // Name: isNull
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonDocument::isNull() const { bool QJsonDocument::isNull() const {
return !root_; return !root_;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: isObject // Name: isObject
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool QJsonDocument::isObject() const { bool QJsonDocument::isObject() const {
return root_ && root_->toObject(); return root_ && root_->toObject();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: setArray // Name: setArray
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonDocument::setArray(const QJsonArray &array) { void QJsonDocument::setArray(const QJsonArray &array) {
setRoot(array); setRoot(array);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: setObject // Name: setObject
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonDocument::setObject(const QJsonObject &object) { void QJsonDocument::setObject(const QJsonObject &object) {
setRoot(object); setRoot(object);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: setRoot // Name: setRoot
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonDocument::setRoot(const QJsonRoot &root) { void QJsonDocument::setRoot(const QJsonRoot &root) {
delete root_; delete root_;
root_ = root.clone(); root_ = root.clone();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toBinaryData // Name: toBinaryData
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QByteArray QJsonDocument::toBinaryData() const { QByteArray QJsonDocument::toBinaryData() const {
QByteArray r; QByteArray r;
// TODO(eteran): implement this // TODO(eteran): implement this
return r; return r;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -173,100 +173,107 @@ QByteArray QJsonDocument::toBinaryData() const {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QString QJsonDocument::escapeString(const QString &s) const { QString QJsonDocument::escapeString(const QString &s) const {
QString r; QString r;
Q_FOREACH(QChar ch, s) { Q_FOREACH(QChar ch, s) {
switch(ch.toLatin1()) { switch(ch.toLatin1()) {
case '\"': r.append("\\\""); break; case '\"': r.append("\\\""); break;
case '\\': r.append("\\\\"); break; case '\\': r.append("\\\\"); break;
#if 0 #if 0
case '/': r.append("\\/"); break; case '/': r.append("\\/"); break;
#endif #endif
case '\b': r.append("\\b"); break; case '\b': r.append("\\b"); break;
case '\f': r.append("\\f"); break; case '\f': r.append("\\f"); break;
case '\n': r.append("\\n"); break; case '\n': r.append("\\n"); break;
case '\r': r.append("\\r"); break; case '\r': r.append("\\r"); break;
case '\t': r.append("\\t"); break; case '\t': r.append("\\t"); break;
default: default:
r += ch; r += ch;
break; break;
} }
} }
return r; return r;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: toJson // Name: toJson
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QString QJsonDocument::toJson(const QJsonValue &v, JsonFormat format) const { QString QJsonDocument::toJson(const QJsonValue &v, JsonFormat format, int indent) const {
QString b; QString b;
QTextStream ss(&b, QIODevice::WriteOnly | QIODevice::Text); QTextStream ss(&b, QIODevice::WriteOnly | QIODevice::Text);
bool compact = (format == JsonFormat::Compact);
switch(v.type()) { switch(v.type()) {
case QJsonValue::Null: case QJsonValue::Null:
ss << "null"; ss << "null";
break; break;
case QJsonValue::Bool: case QJsonValue::Bool:
ss << (v.toBool() ? "true" : "false"); ss << (v.toBool() ? "true" : "false");
break; break;
case QJsonValue::Double: case QJsonValue::Double:
{ {
double d = v.toDouble (); double d = v.toDouble ();
if (qIsFinite(d)) { if (qIsFinite(d)) {
// +2 to format to ensure the expected precision // +2 to format to ensure the expected precision
ss << QByteArray::number(d, 'g', 15 + 2); // ::digits10 is 15 ss << QByteArray::number(d, 'g', 15 + 2); // ::digits10 is 15
} else { } else {
ss << "null"; // +INF || -INF || NaN (see RFC4627#section2.4) ss << "null"; // +INF || -INF || NaN (see RFC4627#section2.4)
} }
} }
break; break;
case QJsonValue::String: case QJsonValue::String:
ss << '"' << escapeString(v.toString()) << '"'; ss << '"' << escapeString(v.toString()) << '"';
break; break;
case QJsonValue::Array: case QJsonValue::Array:
{ {
const QJsonArray a = v.toArray(); const QJsonArray a = v.toArray();
ss << "["; ss << (compact ? "[" : "[\n");
if(!a.empty()) { if(!a.empty()) {
QJsonArray::const_iterator it = a.begin(); QJsonArray::const_iterator it = a.begin();
QJsonArray::const_iterator e = a.end(); QJsonArray::const_iterator e = a.end();
ss << toJson(*it++, format); if (!compact) ss << QByteArray(4*indent, ' ');
ss << toJson(*it++, format, indent+1);
for(;it != e; ++it) { for(;it != e; ++it) {
ss << ','; ss << (compact ? "," : ",\n");
ss << toJson(*it, format); if (!compact) ss << QByteArray(4*indent, ' ');
} ss << toJson(*it, format, indent+1);
} }
ss << "]"; }
} indent--;
break; ss << (compact ? "]" : QString("\n%1]").arg(QString(4*indent, ' ')));
case QJsonValue::Object: }
{ break;
const QJsonObject o = v.toObject(); case QJsonValue::Object:
ss << "{"; {
if(!o.empty()) { const QJsonObject o = v.toObject();
QJsonObject::const_iterator it = o.begin(); ss << (compact ? "{" : "{\n");
QJsonObject::const_iterator e = o.end(); if(!o.empty()) {
QJsonObject::const_iterator it = o.begin();
QJsonObject::const_iterator e = o.end();
ss << '"' << escapeString(it.key()) << "\": " << toJson(it.value(), format); if (!compact) ss << QByteArray(4*indent, ' ');
++it; ss << '"' << escapeString(it.key()) << (compact ? "\":" : "\": ") << toJson(it.value(), format, indent+1);
for(;it != e; ++it) { ++it;
ss << ','; for(;it != e; ++it) {
ss << '"' << escapeString(it.key()) << "\": " << toJson(it.value(), format); ss << (compact ? "," : ",\n");
} if (!compact) ss << QByteArray(4*indent, ' ');
} ss << '"' << escapeString(it.key()) << (compact ? "\":" : "\": ") << toJson(it.value(), format, indent+1);
ss << "}"; }
} }
break; indent--;
case QJsonValue::Undefined: ss << (compact ? "}" : QString("\n%1}").arg(QString(4*indent, ' ')));
Q_ASSERT(0); }
break; break;
} case QJsonValue::Undefined:
Q_ASSERT(0);
break;
}
return b; return b;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -274,19 +281,19 @@ QString QJsonDocument::toJson(const QJsonValue &v, JsonFormat format) const {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QByteArray QJsonDocument::toJson(JsonFormat format) const { QByteArray QJsonDocument::toJson(JsonFormat format) const {
Q_UNUSED(format); Q_UNUSED(format);
if(isArray()) { if(isArray()) {
QString s = toJson(array(), format); QString s = toJson(array(), format);
return s.toUtf8(); return s.toUtf8();
} }
if(isObject()) { if(isObject()) {
QString s = toJson(object(), format); QString s = toJson(object(), format);
return s.toUtf8(); return s.toUtf8();
} }
return QByteArray(); return QByteArray();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -294,17 +301,17 @@ QByteArray QJsonDocument::toJson(JsonFormat format) const {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QVariant QJsonDocument::toVariant() const { QVariant QJsonDocument::toVariant() const {
if(!isEmpty()) { if(!isEmpty()) {
if(QJsonObject *const object = root_->toObject()) { if(QJsonObject *const object = root_->toObject()) {
return object->toVariantMap(); return object->toVariantMap();
} }
if(QJsonArray *const array = root_->toArray()) { if(QJsonArray *const array = root_->toArray()) {
return array->toVariantList(); return array->toVariantList();
} }
} }
return QVariant(); return QVariant();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -312,13 +319,13 @@ QVariant QJsonDocument::toVariant() const {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonArray QJsonDocument::array() const { QJsonArray QJsonDocument::array() const {
if(!isEmpty()) { if(!isEmpty()) {
if(QJsonArray *const array = root_->toArray()) { if(QJsonArray *const array = root_->toArray()) {
return *array; return *array;
} }
} }
return QJsonArray(); return QJsonArray();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -326,54 +333,54 @@ QJsonArray QJsonDocument::array() const {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonObject QJsonDocument::object() const { QJsonObject QJsonDocument::object() const {
if(!isEmpty()) { if(!isEmpty()) {
if(QJsonObject *const object = root_->toObject()) { if(QJsonObject *const object = root_->toObject()) {
return *object; return *object;
} }
} }
return QJsonObject(); return QJsonObject();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: rawData // Name: rawData
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
const char *QJsonDocument::rawData(int *size) const { const char *QJsonDocument::rawData(int *size) const {
Q_UNUSED(size); Q_UNUSED(size);
// TODO(eteran): implement this // TODO(eteran): implement this
return 0; return 0;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: fromBinaryData // Name: fromBinaryData
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonDocument QJsonDocument::fromBinaryData(const QByteArray &data, DataValidation validation) { QJsonDocument QJsonDocument::fromBinaryData(const QByteArray &data, DataValidation validation) {
Q_UNUSED(data); Q_UNUSED(data);
Q_UNUSED(validation); Q_UNUSED(validation);
QJsonDocument doc; QJsonDocument doc;
// TODO(eteran): implement this // TODO(eteran): implement this
return doc; return doc;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: fromJson // Name: fromJson
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonDocument QJsonDocument::fromJson(const QByteArray &json, QJsonParseError *error) { QJsonDocument QJsonDocument::fromJson(const QByteArray &json, QJsonParseError *error) {
QJsonDocument doc; QJsonDocument doc;
const char *const begin = json.constData(); const char *const begin = json.constData();
const char *const end = begin + json.size(); const char *const end = begin + json.size();
QJsonParser parser(begin, end); QJsonParser parser(begin, end);
doc.root_ = parser.parse(); doc.root_ = parser.parse();
if(error) { if(error) {
*error = parser.state(); *error = parser.state();
} }
return doc; return doc;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -381,10 +388,10 @@ QJsonDocument QJsonDocument::fromJson(const QByteArray &json, QJsonParseError *e
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonDocument QJsonDocument::fromRawData(const char *data, int size, DataValidation validation) { QJsonDocument QJsonDocument::fromRawData(const char *data, int size, DataValidation validation) {
// data has to be aligned to a 4 byte boundary. // data has to be aligned to a 4 byte boundary.
Q_ASSERT(!(reinterpret_cast<quintptr>(data) % 3)); Q_ASSERT(!(reinterpret_cast<quintptr>(data) % 3));
return fromBinaryData(QByteArray::fromRawData(data, size), validation); return fromBinaryData(QByteArray::fromRawData(data, size), validation);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -392,26 +399,26 @@ QJsonDocument QJsonDocument::fromRawData(const char *data, int size, DataValidat
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
QJsonDocument QJsonDocument::fromVariant(const QVariant &variant) { QJsonDocument QJsonDocument::fromVariant(const QVariant &variant) {
QJsonDocument doc; QJsonDocument doc;
if (variant.type() == QVariant::Map) { if (variant.type() == QVariant::Map) {
doc.setObject(QJsonObject::fromVariantMap(variant.toMap())); doc.setObject(QJsonObject::fromVariantMap(variant.toMap()));
} else if (variant.type() == QVariant::Hash) { } else if (variant.type() == QVariant::Hash) {
doc.setObject(QJsonObject::fromVariantHash(variant.toHash())); doc.setObject(QJsonObject::fromVariantHash(variant.toHash()));
} else if (variant.type() == QVariant::List) { } else if (variant.type() == QVariant::List) {
doc.setArray(QJsonArray::fromVariantList(variant.toList())); doc.setArray(QJsonArray::fromVariantList(variant.toList()));
} else if (variant.type() == QVariant::StringList) { } else if (variant.type() == QVariant::StringList) {
doc.setArray(QJsonArray::fromStringList(variant.toStringList())); doc.setArray(QJsonArray::fromStringList(variant.toStringList()));
} }
return doc; return doc;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Name: swap // Name: swap
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void QJsonDocument::swap(QJsonDocument &other) { void QJsonDocument::swap(QJsonDocument &other) {
qSwap(root_, other.root_); qSwap(root_, other.root_);
} }
#endif #endif

View file

@ -36,66 +36,66 @@ class QJsonRoot;
class QJsonDocument { class QJsonDocument {
public: public:
enum DataValidation { enum DataValidation {
Validate = 0, Validate = 0,
BypassValidation = 1 BypassValidation = 1
}; };
enum JsonFormat { enum JsonFormat {
Indented, Indented,
Compact Compact
}; };
public: public:
QJsonDocument(); QJsonDocument();
QJsonDocument(const QJsonObject &object); QJsonDocument(const QJsonObject &object);
QJsonDocument(const QJsonArray &array); QJsonDocument(const QJsonArray &array);
QJsonDocument(const QJsonDocument &other); QJsonDocument(const QJsonDocument &other);
~QJsonDocument(); ~QJsonDocument();
public: public:
QJsonDocument &operator=(const QJsonDocument &other); QJsonDocument &operator=(const QJsonDocument &other);
public: public:
bool operator!=(const QJsonDocument &other) const; bool operator!=(const QJsonDocument &other) const;
bool operator==(const QJsonDocument &other) const; bool operator==(const QJsonDocument &other) const;
public: public:
bool isArray() const; bool isArray() const;
bool isEmpty() const; bool isEmpty() const;
bool isNull() const; bool isNull() const;
bool isObject() const; bool isObject() const;
public: public:
QByteArray toBinaryData() const; QByteArray toBinaryData() const;
QByteArray toJson(JsonFormat format = Indented) const; QByteArray toJson(JsonFormat format = Indented) const;
QVariant toVariant() const; QVariant toVariant() const;
public: public:
QJsonArray array() const; QJsonArray array() const;
QJsonObject object() const; QJsonObject object() const;
const char *rawData(int *size) const; const char *rawData(int *size) const;
public: public:
void setArray(const QJsonArray &array); void setArray(const QJsonArray &array);
void setObject(const QJsonObject &object); void setObject(const QJsonObject &object);
public: public:
static QJsonDocument fromBinaryData(const QByteArray &data, DataValidation validation = Validate); static QJsonDocument fromBinaryData(const QByteArray &data, DataValidation validation = Validate);
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error = 0); static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error = 0);
static QJsonDocument fromRawData(const char *data, int size, DataValidation validation = Validate); static QJsonDocument fromRawData(const char *data, int size, DataValidation validation = Validate);
static QJsonDocument fromVariant(const QVariant &variant); static QJsonDocument fromVariant(const QVariant &variant);
private: private:
void setRoot(const QJsonRoot &root); void setRoot(const QJsonRoot &root);
QString toJson(const QJsonValue &v, JsonFormat format) const; QString toJson(const QJsonValue &v, JsonFormat format, int indent = 1) const;
QString escapeString(const QString &s) const; QString escapeString(const QString &s) const;
private: private:
void swap(QJsonDocument &other); void swap(QJsonDocument &other);
private: private:
QJsonRoot *root_; QJsonRoot *root_;
}; };
#endif #endif

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff