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 "QZXingFilter.h"
#include <QZXing.h>
#include <QDebug> #include <QDebug>
#include <QtConcurrent/QtConcurrent> #include <QtConcurrent/QtConcurrent>
@ -29,9 +30,9 @@ QZXingFilter::QZXingFilter(QObject *parent)
, decoding(false) , decoding(false)
{ {
/// Conecting signals to handlers that will send signals to QML /// Conecting signals to handlers that will send signals to QML
connect(&decoder, &QZXing::decodingStarted, connect(decoder_p, &QZXing::decodingStarted,
this, &QZXingFilter::handleDecodingStarted); this, &QZXingFilter::handleDecodingStarted);
connect(&decoder, &QZXing::decodingFinished, connect(decoder_p, &QZXing::decodingFinished,
this, &QZXingFilter::handleDecodingFinished); this, &QZXingFilter::handleDecodingFinished);
} }
@ -40,6 +41,16 @@ QZXingFilter::~QZXingFilter()
} }
bool QZXingFilter::isDecoding()
{
return decoding;
}
QZXing *QZXingFilter::getDecoder()
{
return decoder_p;
}
void QZXingFilter::handleDecodingStarted() void QZXingFilter::handleDecodingStarted()
{ {
decoding = true; decoding = true;
@ -50,7 +61,7 @@ void QZXingFilter::handleDecodingStarted()
void QZXingFilter::handleDecodingFinished(bool succeeded) void QZXingFilter::handleDecodingFinished(bool succeeded)
{ {
decoding = false; decoding = false;
emit decodingFinished(succeeded, decoder.getProcessTimeOfLastDecoding()); emit decodingFinished(succeeded, decoder_p->getProcessTimeOfLastDecoding());
emit isDecodingChanged(); 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"; // const QString path = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "/qrtest/test_" + QString::number(i % 100) + ".png";
// qDebug() << "saving image" << i << "at:" << path << image.save(path); // 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 /// 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. /// 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? /// TODO: Maybe there is a better way to know this orientation beforehand? Or should we try decoding all of them?
if (tag.isEmpty() && tryHarder) { if (tag.isEmpty() && tryHarder) {
image = image.mirrored(true, false); 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) { if (tag.isEmpty() && tryHarder) {
image = image.mirrored(false, true); 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) { if (tag.isEmpty() && tryHarder) {
image = image.mirrored(true, true); 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 <QObject>
#include <QAbstractVideoFilter> #include <QAbstractVideoFilter>
#include <QZXing.h>
//forward declaration
class QZXing;
/// ///
/// References: /// References:
@ -59,7 +61,7 @@ class QZXingFilter : public QAbstractVideoFilter
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool decoding READ isDecoding NOTIFY isDecodingChanged) 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) Q_PROPERTY(QRectF captureRect MEMBER captureRect NOTIFY captureRectChanged)
signals: signals:
@ -73,7 +75,7 @@ class QZXingFilter : public QAbstractVideoFilter
void handleDecodingFinished(bool succeeded); void handleDecodingFinished(bool succeeded);
private: /// Attributes private: /// Attributes
QZXing decoder; QZXing* decoder_p;
bool decoding; bool decoding;
QRectF captureRect; QRectF captureRect;
@ -84,8 +86,10 @@ class QZXingFilter : public QAbstractVideoFilter
explicit QZXingFilter(QObject *parent = 0); explicit QZXingFilter(QObject *parent = 0);
virtual ~QZXingFilter(); virtual ~QZXingFilter();
bool isDecoding() {return decoding; } bool isDecoding();
QZXing* getDecoder() { return &decoder; } QZXing* getDecoder();
// bool isDecoding() {return decoding; }
// QZXing* getDecoder() { return &decoder; }
QVideoFilterRunnable * createFilterRunnable(); QVideoFilterRunnable * createFilterRunnable();
}; };