Define static function to registers types in qzxing.cpp, not in qzxing.h

This simplifies the code for QZXingFilter (revert it to what it was before)
Also added a global include file, to include all QZXing user classes.

Reverts 5627d2fbb5, eb6bdb41e9, 1bae498386 & 213c4d684b
This commit is contained in:
oKcerG 2017-01-18 16:01:18 +01:00
parent 5627d2fbb5
commit b3d0c8209b
5 changed files with 57 additions and 53 deletions

5
src/QZXing Normal file
View File

@ -0,0 +1,5 @@
#include "QZXing.h"
#include "QZXingImageProvider.h"
#ifdef QZXING_MULTIMEDIA
#include "QZXingFilter.h"
#endif //QZXING_MULTIMEDIA

View File

@ -5,20 +5,12 @@
#include <QObject> #include <QObject>
#include <QImage> #include <QImage>
#if QT_VERSION >= 0x040700 && QT_VERSION < 0x050000 #if QT_VERSION >= 0x050000
#include <QtDeclarative> class QQuickView;
#elif QT_VERSION >= 0x050000
#include <QtQml/qqml.h>
#include <QQuickView>
#include <QQmlEngine>
#endif #endif
#include "QZXingImageProvider.h" #include "QZXingImageProvider.h"
#ifdef QZXING_MULTIMEDIA
#include "QZXingFilter.h"
#endif//#ifdef QZXING_MULTIMEDIA
// forward declaration // forward declaration
namespace zxing { namespace zxing {
class MultiFormatReader; class MultiFormatReader;
@ -80,23 +72,11 @@ public:
#ifdef QZXING_QML #ifdef QZXING_QML
#if QT_VERSION >= 0x040700 #if QT_VERSION >= 0x040700
static void registerQMLTypes() static void registerQMLTypes();
{
qmlRegisterType<QZXing>("QZXing", 2, 3, "QZXing");
#ifdef QZXING_MULTIMEDIA
qmlRegisterType<QZXingFilter>("QZXing", 2, 3, "QZXingFilter");
#endif //QZXING_MULTIMEDIA
}
#endif //QT_VERSION >= Qt 4.7 #endif //QT_VERSION >= Qt 4.7
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
static void registerQMLImageProvider(const QQuickView& view) static void registerQMLImageProvider(const QQuickView& view);
{
QQmlEngine *engine = view.engine();
engine->addImageProvider(QLatin1String("QZXing"), QZXingImageProvider::getInstance());
}
#endif //QT_VERSION >= Qt 5.0 #endif //QT_VERSION >= Qt 5.0
#endif //QZXING_QML #endif //QZXING_QML

View File

@ -1,6 +1,5 @@
#include "QZXingFilter.h" #include "QZXingFilter.h"
#include <QZXing.h>
#include <QDebug> #include <QDebug>
#include <QtConcurrent/QtConcurrent> #include <QtConcurrent/QtConcurrent>
@ -27,30 +26,18 @@ namespace {
QZXingFilter::QZXingFilter(QObject *parent) QZXingFilter::QZXingFilter(QObject *parent)
: QAbstractVideoFilter(parent) : QAbstractVideoFilter(parent)
, decoder_p(new QZXing())
, 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_p, &QZXing::decodingStarted, connect(&decoder, &QZXing::decodingStarted,
this, &QZXingFilter::handleDecodingStarted); this, &QZXingFilter::handleDecodingStarted);
connect(decoder_p, &QZXing::decodingFinished, connect(&decoder, &QZXing::decodingFinished,
this, &QZXingFilter::handleDecodingFinished); this, &QZXingFilter::handleDecodingFinished);
} }
QZXingFilter::~QZXingFilter() QZXingFilter::~QZXingFilter()
{ {
if(decoder_p)
delete decoder_p;
}
bool QZXingFilter::isDecoding()
{
return decoding;
}
QZXing *QZXingFilter::getDecoder()
{
return decoder_p;
} }
void QZXingFilter::handleDecodingStarted() void QZXingFilter::handleDecodingStarted()
@ -63,7 +50,7 @@ void QZXingFilter::handleDecodingStarted()
void QZXingFilter::handleDecodingFinished(bool succeeded) void QZXingFilter::handleDecodingFinished(bool succeeded)
{ {
decoding = false; decoding = false;
emit decodingFinished(succeeded, decoder_p->getProcessTimeOfLastDecoding()); emit decodingFinished(succeeded, decoder.getProcessTimeOfLastDecoding());
emit isDecodingChanged(); emit isDecodingChanged();
} }
@ -261,22 +248,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_p->decodeImage(image, image.width(), image.height()); QString tag = filter->decoder.decodeImage(image, image.width(), image.height());
const bool tryHarder = filter->decoder_p->getTryHarder(); const bool tryHarder = filter->decoder.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_p->decodeImage(image, image.width(), image.height()); tag = filter->decoder.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_p->decodeImage(image, image.width(), image.height()); tag = filter->decoder.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_p->decodeImage(image, image.width(), image.height()); tag = filter->decoder.decodeImage(image, image.width(), image.height());
} }
} }

View File

@ -5,9 +5,7 @@
#include <QAbstractVideoFilter> #include <QAbstractVideoFilter>
#include <QDebug> #include <QDebug>
#include <QFuture> #include <QFuture>
#include <QZXing.h>
//forward declaration
class QZXing;
/// ///
/// References: /// References:
@ -77,7 +75,7 @@ class QZXingFilter : public QAbstractVideoFilter
void handleDecodingFinished(bool succeeded); void handleDecodingFinished(bool succeeded);
private: /// Attributes private: /// Attributes
QZXing* decoder_p; QZXing decoder;
bool decoding; bool decoding;
QRectF captureRect; QRectF captureRect;
@ -88,10 +86,8 @@ class QZXingFilter : public QAbstractVideoFilter
explicit QZXingFilter(QObject *parent = 0); explicit QZXingFilter(QObject *parent = 0);
virtual ~QZXingFilter(); virtual ~QZXingFilter();
bool isDecoding(); bool isDecoding() {return decoding; }
QZXing* getDecoder(); QZXing* getDecoder() { return &decoder; }
// bool isDecoding() {return decoding; }
// QZXing* getDecoder() { return &decoder; }
QVideoFilterRunnable * createFilterRunnable(); QVideoFilterRunnable * createFilterRunnable();
}; };

View File

@ -19,6 +19,18 @@
#include <QQmlContext> #include <QQmlContext>
#include <QQuickImageProvider> #include <QQuickImageProvider>
#if QT_VERSION >= 0x040700 && QT_VERSION < 0x050000
#include <QtDeclarative>
#elif QT_VERSION >= 0x050000
#include <QtQml/qqml.h>
#include <QQuickView>
#endif
#include "QZXingFilter.h"
#include "QZXingImageProvider.h"
using namespace zxing; using namespace zxing;
QZXing::QZXing(QObject *parent) : QObject(parent), tryHarder_(false) QZXing::QZXing(QObject *parent) : QObject(parent), tryHarder_(false)
@ -61,6 +73,30 @@ QZXing::QZXing(QZXing::DecoderFormat decodeHints, QObject *parent) : QObject(par
setDecoder(decodeHints); setDecoder(decodeHints);
} }
#ifdef QZXING_QML
#if QT_VERSION >= 0x040700
void QZXing::registerQMLTypes()
{
qmlRegisterType<QZXing>("QZXing", 2, 3, "QZXing");
#ifdef QZXING_MULTIMEDIA
qmlRegisterType<QZXingFilter>("QZXing", 2, 3, "QZXingFilter");
#endif //QZXING_MULTIMEDIA
}
#endif //QT_VERSION >= Qt 4.7
#if QT_VERSION >= 0x050000
void QZXing::registerQMLImageProvider(const QQuickView& view)
{
QQmlEngine *engine = view.engine();
engine->addImageProvider(QLatin1String("QZXing"), QZXingImageProvider::getInstance());
}
#endif //QT_VERSION >= Qt 5.0
#endif //QZXING_QML
void QZXing::setTryHarder(bool tryHarder) void QZXing::setTryHarder(bool tryHarder)
{ {
tryHarder_ = tryHarder; tryHarder_ = tryHarder;