Updated QZXingImageProvider::requestImage implementation to:

- fix bug when '?' is included without correct definition of options
 - utilize requestedSize for the generated barcode

Updated README.md file to reflect changes.
This commit is contained in:
favoritas37 2018-03-11 19:21:19 +02:00
parent 34fb8daa82
commit 9c361587a4
5 changed files with 37 additions and 67 deletions

View File

@ -204,15 +204,14 @@ Image{
} }
``` ```
Or use the encoding function with custom settings that are passed like URL query parameters: Or use the encoding function with the optional custom settings that are passed like URL query parameters:
| attribute name | value | description | | attribute name | value | description |
| -------------- | ---------- | --------------------------------------------- | | -------------- | ---------- | --------------------------------------------- |
| width | int | width in pixels |
| height | int | height in pixels |
| corretionLevel | L, M, Q, H | the error correction level | | corretionLevel | L, M, Q, H | the error correction level |
| format | qrcode | the encode formatter. Currently only QR Code. | | format | qrcode | the encode formatter. Currently only QR Code. |
the size of the image can be adjusted by using the Image.sourceWidth and Image.sourceHeight properties of Image QML element.
```qml ```qml
import QZXing 2.3 import QZXing 2.3
@ -224,11 +223,10 @@ TextField {
Image{ Image{
source: "image://QZXing/encode/" + inputField.text + source: "image://QZXing/encode/" + inputField.text +
"?width=250" + "?corretionLevel=M" +
"&height=250" +
"&corretionLevel=M" +
"&format=qrcode" "&format=qrcode"
cache: false; sourceSize.width: 320
sourceSize.height: 320
} }
``` ```

View File

@ -10,8 +10,7 @@ ApplicationWindow {
minimumWidth: formatGroupBox.width + minimumWidth: formatGroupBox.width +
errorCorrectionlevelGroupBox.width + errorCorrectionlevelGroupBox.width +
sizeGroupBox.width + 5 * advancedOptions.spacing
6 * advancedOptions.spacing
property bool isAdvancedOptionsEnabled: advancedSwitch.position; property bool isAdvancedOptionsEnabled: advancedSwitch.position;
@ -76,57 +75,33 @@ ApplicationWindow {
model: ["L", "M", "Q", "H"] model: ["L", "M", "Q", "H"]
} }
} }
GroupBox {
id: sizeGroupBox
anchors.verticalCenter: parent.verticalCenter
title: "Size"
GridLayout {
RadioButton {
id: radioButtonSize120
text: "120x120"
}
RadioButton {
id: radioButtonSize240
checked: true
text: "240x240"
}
RadioButton {
id: radioButtonSize320
text: "320x320"
}
}
}
} }
Rectangle { Rectangle {
id: barcodeRectangle
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
border.width: 1 border.width: 1
border.color: "#bdbebf" border.color: "#bdbebf"
clip: true clip: true
property int imageWidth: Math.min(height, width) * 0.7;
Image{ Image{
id:resultImage id:resultImage
anchors.centerIn: parent anchors.centerIn: parent
sourceSize.width: barcodeRectangle.imageWidth
sourceSize.height: barcodeRectangle.imageWidth
source: mainLayout.getImageRequestString() source: mainLayout.getImageRequestString()
cache: false; //cache: false;
} }
} }
function getImageRequestString() { function getImageRequestString() {
if(mainWindow.isAdvancedOptionsEnabled) { if(mainWindow.isAdvancedOptionsEnabled) {
var width;
var height;
if (radioButtonSize120.checked) {width = "120"; height = "120"}
else if (radioButtonSize240.checked) {width = "240"; height = "240"}
else if (radioButtonSize320.checked) {width = "320"; height = "320"}
return "image://QZXing/encode/" + inputField.text + return "image://QZXing/encode/" + inputField.text +
"?width="+width+ "?corretionLevel=" + errorCorrectionlevelCombo.currentText +
"&height="+height+
"&corretionLevel=" + errorCorrectionlevelCombo.currentText +
"&format=" + formatCombo.currentText "&format=" + formatCombo.currentText
} }
else else

View File

@ -1,7 +1,5 @@
TEMPLATE = app TEMPLATE = app
QT += qml quick
CONFIG += c++11 qzxing_multimedia CONFIG += c++11 qzxing_multimedia
CONFIG(debug, debug|release) { CONFIG(debug, debug|release) {

View File

@ -63,7 +63,7 @@
</application> </application>
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="23"/> <uses-sdk android:minSdkVersion="17" android:targetSdkVersion="24"/>
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/> <supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application. <!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.

View File

@ -23,49 +23,48 @@ QImage QZXingImageProvider::requestImage(const QString &id, QSize *size, const Q
return QImage(); return QImage();
} }
int optionAreaIndex = id.lastIndexOf('?'); int customSettingsIndex = id.lastIndexOf('?');
QString data; QString data;
QImage result; QImage result;
if(optionAreaIndex >= 0) QString corretionLevel;
QString format;
QZXing::EncodeErrorCorrectionLevel correctionLevelEnum =
QZXing::EncodeErrorCorrectionLevel_L;
if(customSettingsIndex >= 0)
{ {
int startOfDataIndex = slashIndex + 1; int startOfDataIndex = slashIndex + 1;
data = id.mid(startOfDataIndex, optionAreaIndex - (startOfDataIndex)); data = id.mid(startOfDataIndex, customSettingsIndex - (startOfDataIndex));
//The dummy option has been added due to a bug(?) of QUrlQuery //The dummy option has been added due to a bug(?) of QUrlQuery
// it could not recognize the first key-value pair provided // it could not recognize the first key-value pair provided
QUrlQuery optionQuery("options?dummy=&" + id.mid(optionAreaIndex + 1)); QUrlQuery optionQuery("options?dummy=&" + id.mid(customSettingsIndex + 1));
QString width = optionQuery.queryItemValue("width"); corretionLevel = optionQuery.queryItemValue("corretionLevel");
QString height = optionQuery.queryItemValue("height"); format = optionQuery.queryItemValue("format");
QString corretionLevel = optionQuery.queryItemValue("corretionLevel");
QString format = optionQuery.queryItemValue("format");
if(format != "qrcode")
{
qWarning() << "Format not supported: " << format;
return QImage();
}
if(height.isEmpty() && !width.isEmpty())
height = width;
if(width.isEmpty() && height.isEmpty())
width = height;
QZXing::EncodeErrorCorrectionLevel correctionLevelEnum;
if(corretionLevel == "H") if(corretionLevel == "H")
correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_H; correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_H;
else if(corretionLevel == "Q") else if(corretionLevel == "Q")
correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_Q; correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_Q;
else if(corretionLevel == "M") else if(corretionLevel == "M")
correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_M; correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_M;
else else if(corretionLevel == "L")
correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_L; correctionLevelEnum = QZXing::EncodeErrorCorrectionLevel_L;
}
if(!corretionLevel.isEmpty() || !format.isEmpty())
{
if(format != "qrcode")
{
qWarning() << "Format not supported: " << format;
return QImage();
}
result = QZXing::encodeData(data, QZXing::EncoderFormat_QR_CODE, result = QZXing::encodeData(data, QZXing::EncoderFormat_QR_CODE,
QSize(width.toInt(), height.toInt()), requestedSize,
correctionLevelEnum); correctionLevelEnum);
} }
else else
{ {