properly fix compile issue by forward declaring QZXing in QZXingFilter. Had to make decoder variable as pointer in order to avoid the compiler requirement to known the exact size of the class...that had to be forward declared. Properly addresses issue #16

This commit is contained in:
favoritas37 2017-01-17 13:37:20 +02:00
parent 213c4d684b
commit 1bae498386
2 changed files with 28 additions and 13 deletions

View File

@ -1,5 +1,6 @@
#include "QZXingFilter.h"
#include <QZXing.h>
#include <QDebug>
#include <QtConcurrent/QtConcurrent>
@ -29,9 +30,9 @@ QZXingFilter::QZXingFilter(QObject *parent)
, decoding(false)
{
/// Conecting signals to handlers that will send signals to QML
connect(&decoder, &QZXing::decodingStarted,
connect(decoder_p, &QZXing::decodingStarted,
this, &QZXingFilter::handleDecodingStarted);
connect(&decoder, &QZXing::decodingFinished,
connect(decoder_p, &QZXing::decodingFinished,
this, &QZXingFilter::handleDecodingFinished);
}
@ -40,6 +41,16 @@ QZXingFilter::~QZXingFilter()
}
bool QZXingFilter::isDecoding()
{
return decoding;
}
QZXing *QZXingFilter::getDecoder()
{
return decoder_p;
}
void QZXingFilter::handleDecodingStarted()
{
decoding = true;
@ -50,7 +61,7 @@ void QZXingFilter::handleDecodingStarted()
void QZXingFilter::handleDecodingFinished(bool succeeded)
{
decoding = false;
emit decodingFinished(succeeded, decoder.getProcessTimeOfLastDecoding());
emit decodingFinished(succeeded, decoder_p->getProcessTimeOfLastDecoding());
emit isDecodingChanged();
}
@ -248,22 +259,22 @@ void QZXingFilterRunnable::processVideoFrameProbed(SimpleVideoFrame & videoFrame
// const QString path = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "/qrtest/test_" + QString::number(i % 100) + ".png";
// qDebug() << "saving image" << i << "at:" << path << image.save(path);
QString tag = filter->decoder.decodeImage(image, image.width(), image.height());
QString tag = filter->decoder_p->decodeImage(image, image.width(), image.height());
const bool tryHarder = filter->decoder.getTryHarder();
const bool tryHarder = filter->decoder_p->getTryHarder();
/// The frames we get from the camera may be reflected horizontally or vertically
/// As the decoder can't handle reflected frames, we swap them in all possible frames, changing the swap mode each frame.
/// TODO: Maybe there is a better way to know this orientation beforehand? Or should we try decoding all of them?
if (tag.isEmpty() && tryHarder) {
image = image.mirrored(true, false);
tag = filter->decoder.decodeImage(image, image.width(), image.height());
tag = filter->decoder_p->decodeImage(image, image.width(), image.height());
}
if (tag.isEmpty() && tryHarder) {
image = image.mirrored(false, true);
tag = filter->decoder.decodeImage(image, image.width(), image.height());
tag = filter->decoder_p->decodeImage(image, image.width(), image.height());
}
if (tag.isEmpty() && tryHarder) {
image = image.mirrored(true, true);
tag = filter->decoder.decodeImage(image, image.width(), image.height());
tag = filter->decoder_p->decodeImage(image, image.width(), image.height());
}
}

View File

@ -3,7 +3,9 @@
#include <QObject>
#include <QAbstractVideoFilter>
#include <QZXing.h>
//forward declaration
class QZXing;
///
/// References:
@ -59,7 +61,7 @@ class QZXingFilter : public QAbstractVideoFilter
Q_OBJECT
Q_PROPERTY(bool decoding READ isDecoding NOTIFY isDecodingChanged)
Q_PROPERTY(QZXing* decoder READ getDecoder)
Q_PROPERTY(QZXing* decoder_p READ getDecoder)
Q_PROPERTY(QRectF captureRect MEMBER captureRect NOTIFY captureRectChanged)
signals:
@ -73,7 +75,7 @@ class QZXingFilter : public QAbstractVideoFilter
void handleDecodingFinished(bool succeeded);
private: /// Attributes
QZXing decoder;
QZXing* decoder_p;
bool decoding;
QRectF captureRect;
@ -84,8 +86,10 @@ class QZXingFilter : public QAbstractVideoFilter
explicit QZXingFilter(QObject *parent = 0);
virtual ~QZXingFilter();
bool isDecoding() {return decoding; }
QZXing* getDecoder() { return &decoder; }
bool isDecoding();
QZXing* getDecoder();
// bool isDecoding() {return decoding; }
// QZXing* getDecoder() { return &decoder; }
QVideoFilterRunnable * createFilterRunnable();
};