threading issues fixed

This commit is contained in:
Rafael 2017-02-17 12:07:37 +01:00
parent a8501be581
commit 7591d805c9
13 changed files with 251 additions and 93 deletions

View file

@ -24,6 +24,7 @@
#include <QVariantMap>
#include <QJsonArray>
#include <QFileInfo>
#include <QPainter>
#include <QString>
#include <QBuffer>
#include <QDebug>
@ -51,6 +52,9 @@ SnapmaticPicture::SnapmaticPicture(const QString &fileName, QObject *parent) : Q
titlStreamCharacterMax = 39;
rawPicContent = "";
// PREDEFINED PROPERTIES
snapmaticResolution = QSize(960, 536);
reset();
}
@ -64,7 +68,7 @@ void SnapmaticPicture::reset()
rawPicContent = "";
// INIT PIC
cachePicture = QImage(0, 0, QImage::Format_RGB32);
cachePicture = QImage(0, 0, QImage::Format_RGB888);
jpegRawContentSize = 0;
picExportFileName = "";
isCustomFormat = 0;
@ -79,9 +83,12 @@ void SnapmaticPicture::reset()
// INIT JSON
jsonOk = 0;
jsonStr = "";
// SNAPMATIC PROPERTIES
localSpJson = {};
}
bool SnapmaticPicture::readingPicture(bool writeEnabled_, bool cacheEnabled_)
bool SnapmaticPicture::readingPicture(bool writeEnabled_, bool cacheEnabled_, bool fastLoad)
{
// Start opening file
// lastStep is like currentStep
@ -239,6 +246,21 @@ bool SnapmaticPicture::readingPicture(bool writeEnabled_, bool cacheEnabled_)
QImage tempPicture;
picOk = tempPicture.loadFromData(jpegRawContent, "JPEG");
}
else if (!fastLoad)
{
QImage tempPicture = QImage(snapmaticResolution, QImage::Format_RGB888);
QPainter tempPainter(&tempPicture);
if (cachePicture.size() == snapmaticResolution)
{
tempPainter.drawImage(0, 0, cachePicture);
}
else
{
tempPainter.drawImage(0, 0, cachePicture.scaled(snapmaticResolution, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
}
tempPainter.end();
cachePicture = tempPicture;
}
// Read JSON Stream
if (!picStream->isReadable())
@ -351,12 +373,12 @@ void SnapmaticPicture::updateStrings()
picExportFileName = sortStr + "_" + cmpPicTitl;
}
bool SnapmaticPicture::readingPictureFromFile(const QString &fileName, bool writeEnabled_, bool cacheEnabled_)
bool SnapmaticPicture::readingPictureFromFile(const QString &fileName, bool writeEnabled_, bool cacheEnabled_, bool fastLoad)
{
if (fileName != "")
{
picFilePath = fileName;
return readingPicture(writeEnabled_, cacheEnabled_);
return readingPicture(writeEnabled_, cacheEnabled_, fastLoad);
}
else
{
@ -561,19 +583,30 @@ QImage SnapmaticPicture::getImage()
else if (writeEnabled)
{
bool returnOk = 0;
QImage returnPicture;
QImage tempPicture;
QImage returnPicture(snapmaticResolution, QImage::Format_RGB888);
QBuffer snapmaticStream(&rawPicContent);
snapmaticStream.open(QIODevice::ReadOnly);
if (snapmaticStream.seek(jpegStreamEditorBegin))
{
QByteArray jpegRawContent = snapmaticStream.read(jpegPicStreamLength);
returnOk = returnPicture.loadFromData(jpegRawContent, "JPEG");
returnOk = tempPicture.loadFromData(jpegRawContent, "JPEG");
}
snapmaticStream.close();
if (returnOk)
{
QPainter returnPainter(&returnPicture);
if (tempPicture.size() == snapmaticResolution)
{
returnPainter.drawImage(0, 0, tempPicture);
}
else
{
returnPainter.drawImage(0, 0, tempPicture.scaled(snapmaticResolution, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
}
returnPainter.end();
return returnPicture;
}
}
@ -589,7 +622,7 @@ QImage SnapmaticPicture::getImage()
lastStep = "1;/1,OpenFile," + StringParser::convertDrawStringForLog(picFilePath);
picFile->deleteLater();
delete picFile;
return QImage(0, 0, QImage::Format_RGB32);
return QImage(0, 0, QImage::Format_RGB888);
}
rawPicContent = picFile->read(snapmaticFileMaxSize);
picFile->close();
@ -610,7 +643,7 @@ QImage SnapmaticPicture::getImage()
return returnPicture;
}
}
return QImage(0, 0, QImage::Format_RGB32);
return QImage(0, 0, QImage::Format_RGB888);
}
int SnapmaticPicture::getContentMaxLength()
@ -636,7 +669,7 @@ void SnapmaticPicture::setPicFilePath(QString picFilePath_)
void SnapmaticPicture::clearCache()
{
cacheEnabled = false;
cachePicture = QImage(0, 0, QImage::Format_RGB32);
cachePicture = QImage(0, 0, QImage::Format_RGB888);
}
// JSON part
@ -827,3 +860,10 @@ bool SnapmaticPicture::setPictureVisible()
}
return true;
}
// PREDEFINED PROPERTIES
QSize SnapmaticPicture::getSnapmaticResolution()
{
return snapmaticResolution;
}