Merge pull request #95 from igniti-gmbh/imageprovider-size

Always respect requestedSize in QZXingImageProvider
This commit is contained in:
Nikolaos Ftylitakis 2018-12-17 08:22:29 +02:00 committed by GitHub
commit 352a77f4ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 31 deletions

View File

@ -10,7 +10,8 @@ QZXingImageProvider::QZXingImageProvider() : QQuickImageProvider(QQuickImageProv
QImage QZXingImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
int slashIndex = id.indexOf('/');
if (slashIndex == -1) {
if (slashIndex == -1)
{
qWarning() << "Can't parse url" << id << ". Usage is encode?<format>/<data>";
return QImage();
}
@ -23,15 +24,11 @@ QImage QZXingImageProvider::requestImage(const QString &id, QSize *size, const Q
return QImage();
}
int customSettingsIndex = id.lastIndexOf('?');
QString data;
QImage result;
QString corretionLevel;
QString format;
QZXing::EncodeErrorCorrectionLevel correctionLevelEnum =
QZXing::EncodeErrorCorrectionLevel_L;
QZXing::EncoderFormat format = QZXing::EncoderFormat_QR_CODE;
QZXing::EncodeErrorCorrectionLevel correctionLevel = QZXing::EncodeErrorCorrectionLevel_L;
int customSettingsIndex = id.lastIndexOf('?');
if(customSettingsIndex >= 0)
{
int startOfDataIndex = slashIndex + 1;
@ -41,37 +38,28 @@ QImage QZXingImageProvider::requestImage(const QString &id, QSize *size, const Q
// it could not recognize the first key-value pair provided
QUrlQuery optionQuery("options?dummy=&" + id.mid(customSettingsIndex + 1));
corretionLevel = optionQuery.queryItemValue("corretionLevel");
format = optionQuery.queryItemValue("format");
if(corretionLevel == "H")
correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_H;
else if(corretionLevel == "Q")
correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_Q;
else if(corretionLevel == "M")
correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_M;
else if(corretionLevel == "L")
correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_L;
}
if(!corretionLevel.isEmpty() || !format.isEmpty())
QString correctionLevelString = optionQuery.queryItemValue("corretionLevel");
QString formatString = optionQuery.queryItemValue("format");
if(formatString != "qrcode")
{
if(format != "qrcode")
{
qWarning() << "Format not supported: " << format;
qWarning() << "Format not supported: " << formatString;
return QImage();
}
result = QZXing::encodeData(data, QZXing::EncoderFormat_QR_CODE,
requestedSize,
correctionLevelEnum);
}
else
if(correctionLevelString == "H")
correctionLevel = QZXing::EncodeErrorCorrectionLevel_H;
else if(correctionLevelString == "Q")
correctionLevel = QZXing::EncodeErrorCorrectionLevel_Q;
else if(correctionLevelString == "M")
correctionLevel = QZXing::EncodeErrorCorrectionLevel_M;
else if(correctionLevelString == "L")
correctionLevel = QZXing::EncodeErrorCorrectionLevel_L;
} else
{
data = id.mid(slashIndex + 1);
result = QZXing::encodeData(data);
}
QImage result = QZXing::encodeData(data, format, requestedSize, correctionLevel);
*size = result.size();
return result;
}