diff --git a/README.md b/README.md index d771d57..aebf5d0 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,14 @@ +[![Qt Pods](http://qt-pods.org/assets/logo.png "Qt Pods")](http://qt-pods.org) ## qtqrencode Qt 5 wrapper and renderer for [qrencode](https://github.com/fukuchi/libqrencode) (QR Code encoding) library. -## Build +## Build (via qt-pods) + +You can add QrEncode to your project with a single click using qt-pods. Read more about qt-pods here: +https://github.com/cybercatalyst/qt-pods + +## Manual build You will need [Qt 5+](http://qt-project.org/downloads) and [qrencode 3.4+](http://fukuchi.org/works/qrencode). Clone this repo and build it with Qt's qmake: ```bash diff --git a/lib/qrencode/include/qrencode.h b/lib/qrencode/include/qrencode.h deleted file mode 100644 index e554bb9..0000000 --- a/lib/qrencode/include/qrencode.h +++ /dev/null @@ -1,566 +0,0 @@ -/** - * qrencode - QR Code encoder - * - * Copyright (C) 2006-2012 Kentaro Fukuchi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** \mainpage - * Libqrencode is a library for encoding data in a QR Code symbol, a kind of 2D - * symbology. - * - * \section encoding Encoding - * - * There are two methods to encode data: encoding a string/data or - * encoding a structured data. - * - * \subsection encoding-string Encoding a string/data - * You can encode a string by calling QRcode_encodeString(). - * The given string is parsed automatically and encoded. If you want to encode - * data that can be represented as a C string style (NUL terminated), you can - * simply use this way. - * - * If the input data contains Kanji (Shift-JIS) characters and you want to - * encode them as Kanji in QR Code, you should give QR_MODE_KANJI as a hint. - * Otherwise, all of non-alphanumeric characters are encoded as 8 bit data. - * If you want to encode a whole string in 8 bit mode, you can use - * QRcode_encodeString8bit() instead. - * - * Please note that a C string can not contain NUL characters. If your data - * contains NUL, you must use QRcode_encodeData(). - * - * \subsection encoding-input Encoding a structured data - * You can construct a structured input data manually. If the structure of the - * input data is known, you can use this way. - * At first, create a ::QRinput object by QRinput_new(). Then add input data - * to the QRinput object by QRinput_append(). Finally call QRcode_encodeInput() - * to encode the QRinput data. - * You can reuse the QRinput data again to encode it in other symbols with - * different parameters. - * - * \section result Result - * The encoded symbol is resulted as a ::QRcode object. It will contain - * its version number, width of the symbol and an array represents the symbol. - * See ::QRcode for the details. You can free the object by QRcode_free(). - * - * Please note that the version of the result may be larger than specified. - * In such cases, the input data would be too large to be encoded in a - * symbol of the specified version. - * - * \section structured Structured append - * Libqrencode can generate "Structured-appended" symbols that enables to split - * a large data set into mulitple QR codes. A QR code reader concatenates - * multiple QR code symbols into a string. - * Just like QRcode_encodeString(), you can use QRcode_encodeStringStructured() - * to generate structured-appended symbols. This functions returns an instance - * of ::QRcode_List. The returned list is a singly-linked list of QRcode: you - * can retrieve each QR code in this way: - * - * \code - * QRcode_List *qrcodes; - * QRcode_List *entry; - * QRcode *qrcode; - * - * qrcodes = QRcode_encodeStringStructured(...); - * entry = qrcodes; - * while(entry != NULL) { - * qrcode = entry->code; - * // do something - * entry = entry->next; - * } - * QRcode_List_free(entry); - * \endcode - * - * Instead of using auto-parsing functions, you can construct your own - * structured input. At first, instantiate an object of ::QRinput_Struct - * by calling QRinput_Struct_new(). This object can hold multiple ::QRinput, - * and one QR code is generated for a ::QRinput. - * QRinput_Struct_appendInput() appends a ::QRinput to a ::QRinput_Struct - * object. In order to generate structured-appended symbols, it is required to - * embed headers to each symbol. You can use - * QRinput_Struct_insertStructuredAppendHeaders() to insert appropriate - * headers to each symbol. You should call this function just once before - * encoding symbols. - */ - -#ifndef __QRENCODE_H__ -#define __QRENCODE_H__ - -#if defined(__cplusplus) -extern "C" { -#endif - -/** - * Encoding mode. - */ -typedef enum { - QR_MODE_NUL = -1, ///< Terminator (NUL character). Internal use only - QR_MODE_NUM = 0, ///< Numeric mode - QR_MODE_AN, ///< Alphabet-numeric mode - QR_MODE_8, ///< 8-bit data mode - QR_MODE_KANJI, ///< Kanji (shift-jis) mode - QR_MODE_STRUCTURE, ///< Internal use only - QR_MODE_ECI, ///< ECI mode - QR_MODE_FNC1FIRST, ///< FNC1, first position - QR_MODE_FNC1SECOND, ///< FNC1, second position -} QRencodeMode; - -/** - * Level of error correction. - */ -typedef enum { - QR_ECLEVEL_L = 0, ///< lowest - QR_ECLEVEL_M, - QR_ECLEVEL_Q, - QR_ECLEVEL_H ///< highest -} QRecLevel; - -/** - * Maximum version (size) of QR-code symbol. - */ -#define QRSPEC_VERSION_MAX 40 - -/** - * Maximum version (size) of QR-code symbol. - */ -#define MQRSPEC_VERSION_MAX 4 - - -/****************************************************************************** - * Input data (qrinput.c) - *****************************************************************************/ - -/** - * Singly linked list to contain input strings. An instance of this class - * contains its version and error correction level too. It is required to - * set them by QRinput_setVersion() and QRinput_setErrorCorrectionLevel(), - * or use QRinput_new2() to instantiate an object. - */ -typedef struct _QRinput QRinput; - -/** - * Instantiate an input data object. The version is set to 0 (auto-select) - * and the error correction level is set to QR_ECLEVEL_L. - * @return an input object (initialized). On error, NULL is returned and errno - * is set to indicate the error. - * @throw ENOMEM unable to allocate memory. - */ -extern QRinput *QRinput_new(void); - -/** - * Instantiate an input data object. - * @param version version number. - * @param level Error correction level. - * @return an input object (initialized). On error, NULL is returned and errno - * is set to indicate the error. - * @throw ENOMEM unable to allocate memory for input objects. - * @throw EINVAL invalid arguments. - */ -extern QRinput *QRinput_new2(int version, QRecLevel level); - -/** - * Instantiate an input data object. Object's Micro QR Code flag is set. - * Unlike with full-sized QR Code, version number must be specified (>0). - * @param version version number (1--4). - * @param level Error correction level. - * @return an input object (initialized). On error, NULL is returned and errno - * is set to indicate the error. - * @throw ENOMEM unable to allocate memory for input objects. - * @throw EINVAL invalid arguments. - */ -extern QRinput *QRinput_newMQR(int version, QRecLevel level); - -/** - * Append data to an input object. - * The data is copied and appended to the input object. - * @param input input object. - * @param mode encoding mode. - * @param size size of data (byte). - * @param data a pointer to the memory area of the input data. - * @retval 0 success. - * @retval -1 an error occurred and errno is set to indeicate the error. - * See Execptions for the details. - * @throw ENOMEM unable to allocate memory. - * @throw EINVAL input data is invalid. - * - */ -extern int QRinput_append(QRinput *input, QRencodeMode mode, int size, const unsigned char *data); - -/** - * Append ECI header. - * @param input input object. - * @param ecinum ECI indicator number (0 - 999999) - * @retval 0 success. - * @retval -1 an error occurred and errno is set to indeicate the error. - * See Execptions for the details. - * @throw ENOMEM unable to allocate memory. - * @throw EINVAL input data is invalid. - * - */ -extern int QRinput_appendECIheader(QRinput *input, unsigned int ecinum); - -/** - * Get current version. - * @param input input object. - * @return current version. - */ -extern int QRinput_getVersion(QRinput *input); - -/** - * Set version of the QR code that is to be encoded. - * This function cannot be applied to Micro QR Code. - * @param input input object. - * @param version version number (0 = auto) - * @retval 0 success. - * @retval -1 invalid argument. - */ -extern int QRinput_setVersion(QRinput *input, int version); - -/** - * Get current error correction level. - * @param input input object. - * @return Current error correcntion level. - */ -extern QRecLevel QRinput_getErrorCorrectionLevel(QRinput *input); - -/** - * Set error correction level of the QR code that is to be encoded. - * This function cannot be applied to Micro QR Code. - * @param input input object. - * @param level Error correction level. - * @retval 0 success. - * @retval -1 invalid argument. - */ -extern int QRinput_setErrorCorrectionLevel(QRinput *input, QRecLevel level); - -/** - * Set version and error correction level of the QR code at once. - * This function is recommened for Micro QR Code. - * @param input input object. - * @param version version number (0 = auto) - * @param level Error correction level. - * @retval 0 success. - * @retval -1 invalid argument. - */ -extern int QRinput_setVersionAndErrorCorrectionLevel(QRinput *input, int version, QRecLevel level); - -/** - * Free the input object. - * All of data chunks in the input object are freed too. - * @param input input object. - */ -extern void QRinput_free(QRinput *input); - -/** - * Validate the input data. - * @param mode encoding mode. - * @param size size of data (byte). - * @param data a pointer to the memory area of the input data. - * @retval 0 success. - * @retval -1 invalid arguments. - */ -extern int QRinput_check(QRencodeMode mode, int size, const unsigned char *data); - -/** - * Set of QRinput for structured symbols. - */ -typedef struct _QRinput_Struct QRinput_Struct; - -/** - * Instantiate a set of input data object. - * @return an instance of QRinput_Struct. On error, NULL is returned and errno - * is set to indicate the error. - * @throw ENOMEM unable to allocate memory. - */ -extern QRinput_Struct *QRinput_Struct_new(void); - -/** - * Set parity of structured symbols. - * @param s structured input object. - * @param parity parity of s. - */ -extern void QRinput_Struct_setParity(QRinput_Struct *s, unsigned char parity); - -/** - * Append a QRinput object to the set. QRinput created by QRinput_newMQR() - * will be rejected. - * @warning never append the same QRinput object twice or more. - * @param s structured input object. - * @param input an input object. - * @retval >0 number of input objects in the structure. - * @retval -1 an error occurred. See Exceptions for the details. - * @throw ENOMEM unable to allocate memory. - * @throw EINVAL invalid arguments. - */ -extern int QRinput_Struct_appendInput(QRinput_Struct *s, QRinput *input); - -/** - * Free all of QRinput in the set. - * @param s a structured input object. - */ -extern void QRinput_Struct_free(QRinput_Struct *s); - -/** - * Split a QRinput to QRinput_Struct. It calculates a parity, set it, then - * insert structured-append headers. QRinput created by QRinput_newMQR() will - * be rejected. - * @param input input object. Version number and error correction level must be - * set. - * @return a set of input data. On error, NULL is returned, and errno is set - * to indicate the error. See Exceptions for the details. - * @throw ERANGE input data is too large. - * @throw EINVAL invalid input data. - * @throw ENOMEM unable to allocate memory. - */ -extern QRinput_Struct *QRinput_splitQRinputToStruct(QRinput *input); - -/** - * Insert structured-append headers to the input structure. It calculates - * a parity and set it if the parity is not set yet. - * @param s input structure - * @retval 0 success. - * @retval -1 an error occurred and errno is set to indeicate the error. - * See Execptions for the details. - * @throw EINVAL invalid input object. - * @throw ENOMEM unable to allocate memory. - */ -extern int QRinput_Struct_insertStructuredAppendHeaders(QRinput_Struct *s); - -/** - * Set FNC1-1st position flag. - */ -extern int QRinput_setFNC1First(QRinput *input); - -/** - * Set FNC1-2nd position flag and application identifier. - */ -extern int QRinput_setFNC1Second(QRinput *input, unsigned char appid); - -/****************************************************************************** - * QRcode output (qrencode.c) - *****************************************************************************/ - -/** - * QRcode class. - * Symbol data is represented as an array contains width*width uchars. - * Each uchar represents a module (dot). If the less significant bit of - * the uchar is 1, the corresponding module is black. The other bits are - * meaningless for usual applications, but here its specification is described. - * - *
- * MSB 76543210 LSB
- *     |||||||`- 1=black/0=white
- *     ||||||`-- data and ecc code area
- *     |||||`--- format information
- *     ||||`---- version information
- *     |||`----- timing pattern
- *     ||`------ alignment pattern
- *     |`------- finder pattern and separator
- *     `-------- non-data modules (format, timing, etc.)
- * 
- */ -typedef struct { - int version; ///< version of the symbol - int width; ///< width of the symbol - unsigned char *data; ///< symbol data -} QRcode; - -/** - * Singly-linked list of QRcode. Used to represent a structured symbols. - * A list is terminated with NULL. - */ -typedef struct _QRcode_List { - QRcode *code; - struct _QRcode_List *next; -} QRcode_List; - -/** - * Create a symbol from the input data. - * @warning This function is THREAD UNSAFE when pthread is disabled. - * @param input input data. - * @return an instance of QRcode class. The version of the result QRcode may - * be larger than the designated version. On error, NULL is returned, - * and errno is set to indicate the error. See Exceptions for the - * details. - * @throw EINVAL invalid input object. - * @throw ENOMEM unable to allocate memory for input objects. - */ -extern QRcode *QRcode_encodeInput(QRinput *input); - -/** - * Create a symbol from the string. The library automatically parses the input - * string and encodes in a QR Code symbol. - * @warning This function is THREAD UNSAFE when pthread is disabled. - * @param string input string. It must be NUL terminated. - * @param version version of the symbol. If 0, the library chooses the minimum - * version for the given input data. - * @param level error correction level. - * @param hint tell the library how Japanese Kanji characters should be - * encoded. If QR_MODE_KANJI is given, the library assumes that the - * given string contains Shift-JIS characters and encodes them in - * Kanji-mode. If QR_MODE_8 is given, all of non-alphanumerical - * characters will be encoded as is. If you want to embed UTF-8 - * string, choose this. Other mode will cause EINVAL error. - * @param casesensitive case-sensitive(1) or not(0). - * @return an instance of QRcode class. The version of the result QRcode may - * be larger than the designated version. On error, NULL is returned, - * and errno is set to indicate the error. See Exceptions for the - * details. - * @throw EINVAL invalid input object. - * @throw ENOMEM unable to allocate memory for input objects. - * @throw ERANGE input data is too large. - */ -extern QRcode *QRcode_encodeString(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive); - -/** - * Same to QRcode_encodeString(), but encode whole data in 8-bit mode. - * @warning This function is THREAD UNSAFE when pthread is disabled. - */ -extern QRcode *QRcode_encodeString8bit(const char *string, int version, QRecLevel level); - -/** - * Micro QR Code version of QRcode_encodeString(). - * @warning This function is THREAD UNSAFE when pthread is disabled. - */ -extern QRcode *QRcode_encodeStringMQR(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive); - -/** - * Micro QR Code version of QRcode_encodeString8bit(). - * @warning This function is THREAD UNSAFE when pthread is disabled. - */ -extern QRcode *QRcode_encodeString8bitMQR(const char *string, int version, QRecLevel level); - -/** - * Encode byte stream (may include '\0') in 8-bit mode. - * @warning This function is THREAD UNSAFE when pthread is disabled. - * @param size size of the input data. - * @param data input data. - * @param version version of the symbol. If 0, the library chooses the minimum - * version for the given input data. - * @param level error correction level. - * @throw EINVAL invalid input object. - * @throw ENOMEM unable to allocate memory for input objects. - * @throw ERANGE input data is too large. - */ -extern QRcode *QRcode_encodeData(int size, const unsigned char *data, int version, QRecLevel level); - -/** - * Micro QR Code version of QRcode_encodeData(). - * @warning This function is THREAD UNSAFE when pthread is disabled. - */ -extern QRcode *QRcode_encodeDataMQR(int size, const unsigned char *data, int version, QRecLevel level); - -/** - * Free the instance of QRcode class. - * @param qrcode an instance of QRcode class. - */ -extern void QRcode_free(QRcode *qrcode); - -/** - * Create structured symbols from the input data. - * @warning This function is THREAD UNSAFE when pthread is disabled. - * @param s - * @return a singly-linked list of QRcode. - */ -extern QRcode_List *QRcode_encodeInputStructured(QRinput_Struct *s); - -/** - * Create structured symbols from the string. The library automatically parses - * the input string and encodes in a QR Code symbol. - * @warning This function is THREAD UNSAFE when pthread is disabled. - * @param string input string. It must be NUL terminated. - * @param version version of the symbol. - * @param level error correction level. - * @param hint tell the library how Japanese Kanji characters should be - * encoded. If QR_MODE_KANJI is given, the library assumes that the - * given string contains Shift-JIS characters and encodes them in - * Kanji-mode. If QR_MODE_8 is given, all of non-alphanumerical - * characters will be encoded as is. If you want to embed UTF-8 - * string, choose this. Other mode will cause EINVAL error. - * @param casesensitive case-sensitive(1) or not(0). - * @return a singly-linked list of QRcode. On error, NULL is returned, and - * errno is set to indicate the error. See Exceptions for the details. - * @throw EINVAL invalid input object. - * @throw ENOMEM unable to allocate memory for input objects. - */ -extern QRcode_List *QRcode_encodeStringStructured(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive); - -/** - * Same to QRcode_encodeStringStructured(), but encode whole data in 8-bit mode. - * @warning This function is THREAD UNSAFE when pthread is disabled. - */ -extern QRcode_List *QRcode_encodeString8bitStructured(const char *string, int version, QRecLevel level); - -/** - * Create structured symbols from byte stream (may include '\0'). Wholde data - * are encoded in 8-bit mode. - * @warning This function is THREAD UNSAFE when pthread is disabled. - * @param size size of the input data. - * @param data input dat. - * @param version version of the symbol. - * @param level error correction level. - * @return a singly-linked list of QRcode. On error, NULL is returned, and - * errno is set to indicate the error. See Exceptions for the details. - * @throw EINVAL invalid input object. - * @throw ENOMEM unable to allocate memory for input objects. - */ -extern QRcode_List *QRcode_encodeDataStructured(int size, const unsigned char *data, int version, QRecLevel level); - -/** - * Return the number of symbols included in a QRcode_List. - * @param qrlist a head entry of a QRcode_List. - * @return number of symbols in the list. - */ -extern int QRcode_List_size(QRcode_List *qrlist); - -/** - * Free the QRcode_List. - * @param qrlist a head entry of a QRcode_List. - */ -extern void QRcode_List_free(QRcode_List *qrlist); - - -/****************************************************************************** - * System utilities - *****************************************************************************/ - -/** - * Return a string that identifies the library version. - * @param major_version - * @param minor_version - * @param micro_version - */ -extern void QRcode_APIVersion(int *major_version, int *minor_version, int *micro_version); - -/** - * Return a string that identifies the library version. - * @return a string identifies the library version. The string is held by the - * library. Do NOT free it. - */ -extern char *QRcode_APIVersionString(void); - -/** - * Clear all caches. This is only for debug purpose. If you are attacking a - * complicated memory leak bug, try this to reduce the reachable blocks record. - * @warning This function is THREAD UNSAFE when pthread is disabled. - */ -extern void QRcode_clearCache(void); - -#if defined(__cplusplus) -} -#endif - -#endif /* __QRENCODE_H__ */ diff --git a/lib/qrencode/libqrencode.a b/lib/qrencode/libqrencode.a deleted file mode 100644 index 0152334..0000000 Binary files a/lib/qrencode/libqrencode.a and /dev/null differ diff --git a/qqrencode/libqtqrencode_global.h b/qqrencode/libqtqrencode_global.h deleted file mode 100644 index 9ec2bc5..0000000 --- a/qqrencode/libqtqrencode_global.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef LIBQTQRENCODE_GLOBAL_H -#define LIBQTQRENCODE_GLOBAL_H - -#include - -#if defined(LIBQTQRENCODE_LIBRARY) -# define LIBQTQRENCODESHARED_EXPORT Q_DECL_EXPORT -#else -# define LIBQTQRENCODESHARED_EXPORT Q_DECL_IMPORT -#endif - -#endif // LIBQTQRENCODE_GLOBAL_H diff --git a/qqrencode/qqrencode.pro b/qqrencode/qqrencode.pro deleted file mode 100644 index d4534ab..0000000 --- a/qqrencode/qqrencode.pro +++ /dev/null @@ -1,37 +0,0 @@ -QT += core gui svg - -!win32-msvc2010 { - QMAKE_CXXFLAGS_DEBUG += -std=c++11 -Wno-write-strings - QMAKE_CXXFLAGS_RELEASE += -std=c++11 -Wno-write-strings -} - -TARGET = qtqrencode -TEMPLATE = lib - -DEFINES += LIBQTQRENCODE_LIBRARY - -SOURCES += qqrencode.cpp - -HEADERS += qqrencode.h \ - libqtqrencode_global.h \ - qqrencode_p.h - -header_files.files = qqrencode.h \ - libqtqrencode_global.h -header_files.path = /usr/include -INSTALLS += header_files - -win32 { - LIBS += -L$$PWD/../lib/qrencode -lqrencode -} else { - target.path = /usr/lib - INSTALLS += target - macx { - LIBS += -L/usr/local/lib -lqrencode - } else { - LIBS += -lqrencode - } -} - -INCLUDEPATH += $$PWD/../lib/qrencode/include -DEPENDPATH += $$PWD/../lib/qrencode/include diff --git a/qqrencode/qqrencode.cpp b/qtqrencode.cpp similarity index 72% rename from qqrencode/qqrencode.cpp rename to qtqrencode.cpp index b85d3b1..cf7c1b5 100644 --- a/qqrencode/qqrencode.cpp +++ b/qtqrencode.cpp @@ -1,17 +1,26 @@ -#include "qqrencode.h" -#include "qqrencode_p.h" - +// Own includes +#include "qtqrencode.h" +#include "qtqrencode_p.h" + +// QrEncode includes +#ifdef Q_OS_MAC +// This is where brew puts the header +#include "/usr/local/include/qrencode.h" +#else +#include +#endif + +// Qt includes #include #include #define INCHES_PER_METER (100.0/2.54) -QQREncodePrivate::~QQREncodePrivate() -{ +QREncodePrivate::~QREncodePrivate() { QRcode_free(m_code); } -void QQREncodePrivate::paint(QPainter &painter) +void QREncodePrivate::paint(QPainter &painter) { unsigned char *row, *p; int x, y; @@ -38,48 +47,48 @@ void QQREncodePrivate::paint(QPainter &painter) } } -QQREncode::QQREncode() - : d_ptr(new QQREncodePrivate(this)) +QREncode::QREncode() + : d_ptr(new QREncodePrivate(this)) { } -QQREncode::~QQREncode() +QREncode::~QREncode() { } -void QQREncode::setLevel(QQREncode::ErrorCorrectionLevel value) +void QREncode::setLevel(QREncode::ErrorCorrectionLevel value) { - Q_D(QQREncode); + Q_D(QREncode); switch (value) { - case LOW: + case ErrorCorrectionLevelLow: d->m_level = QR_ECLEVEL_L; break; - case MEDIUM: + case ErrorCorrectionLevelMedium: d->m_level = QR_ECLEVEL_M; break; - case QUARTILE: + case ErrorCorrectionLevelQuartile: d->m_level = QR_ECLEVEL_Q; break; - case HIGH: + case ErrorCorrectionLevelHigh: d->m_level = QR_ECLEVEL_H; break; } } -QQREncode::ErrorCorrectionLevel QQREncode::getLevel() const +QREncode::ErrorCorrectionLevel QREncode::getLevel() const { - Q_D(const QQREncode); + Q_D(const QREncode); switch (d->m_level) { case QR_ECLEVEL_L: - return LOW; + return ErrorCorrectionLevelLow; case QR_ECLEVEL_M: - return MEDIUM; + return ErrorCorrectionLevelMedium; case QR_ECLEVEL_Q: - return QUARTILE; + return ErrorCorrectionLevelQuartile; case QR_ECLEVEL_H: - return HIGH; + return ErrorCorrectionLevelHigh; } - return LOW; + return ErrorCorrectionLevelLow; } //bool QQREncode::encode(QString code, QString output) @@ -99,61 +108,61 @@ QQREncode::ErrorCorrectionLevel QQREncode::getLevel() const //} -void QQREncode::setVersion(int version) +void QREncode::setVersion(int version) { - Q_D(QQREncode); + Q_D(QREncode); // 1 - 40 if (version > 0 && version <= 40) d->m_version = version; } -int QQREncode::version() const +int QREncode::version() const { - Q_D(const QQREncode); + Q_D(const QREncode); return d->m_version; } -void QQREncode::setMargin(int value) +void QREncode::setMargin(int value) { - Q_D(QQREncode); + Q_D(QREncode); if (value > -1) d->m_margin = value; } -int QQREncode::margin() const +int QREncode::margin() const { - Q_D(const QQREncode); + Q_D(const QREncode); return d->m_margin; } -void QQREncode::setMicro(bool value) +void QREncode::setMicro(bool value) { - Q_D(QQREncode); + Q_D(QREncode); d->m_micro = (value) ? 1 : 0; } -bool QQREncode::isMicro() const +bool QREncode::isMicro() const { - Q_D(const QQREncode); + Q_D(const QREncode); return (d->m_micro == 1) ? true : false; } -void QQREncode::setBackground(QColor color) +void QREncode::setBackground(QColor color) { - Q_D(QQREncode); + Q_D(QREncode); d->m_bg.setColor(color); } -void QQREncode::setForeground(QColor color) +void QREncode::setForeground(QColor color) { - Q_D(QQREncode); + Q_D(QREncode); d->m_fg.setColor(color); d->m_pen.setColor(color); } -bool QQREncode::encode(QByteArray input) +bool QREncode::encode(QByteArray input) { - Q_D(QQREncode); + Q_D(QREncode); QRcode *c = NULL; if (input.isEmpty()) return false; if (d->m_micro) { @@ -171,9 +180,9 @@ bool QQREncode::encode(QByteArray input) return true; } -bool QQREncode::encode(QString input, bool caseSensitive) +bool QREncode::encode(QString input, bool caseSensitive) { - Q_D(QQREncode); + Q_D(QREncode); if (input.isEmpty()) return false; QRcode *c = NULL; if (d->m_micro) { @@ -197,9 +206,9 @@ bool QQREncode::encode(QString input, bool caseSensitive) return true; } -bool QQREncode::encodeKanji(QByteArray input, bool caseSensitive) +bool QREncode::encodeKanji(QByteArray input, bool caseSensitive) { - Q_D(QQREncode); + Q_D(QREncode); if (input.isEmpty()) return false; QRcode *c = NULL; if (d->m_micro) { @@ -223,9 +232,9 @@ bool QQREncode::encodeKanji(QByteArray input, bool caseSensitive) return true; } -bool QQREncode::toSVG(QString output, int size) +bool QREncode::toSVG(QString output, int size) { - Q_D(QQREncode); + Q_D(QREncode); if (output.isEmpty() || d->m_code == NULL) { return false; } @@ -244,13 +253,15 @@ bool QQREncode::toSVG(QString output, int size) return true; } -QImage QQREncode::toQImage(int size) +QImage QREncode::toQImage(int size) { - Q_D(QQREncode); - if (size < 0) throw std::invalid_argument("Invalid size"); + Q_D(QREncode); + if (size < 0) { + return QImage(); + } if (d->m_code == NULL) { - std::logic_error("No qr code to convert"); + return QImage(); } int symwidth = d->m_code->width + d->m_margin * 2; diff --git a/qqrencode/qqrencode.h b/qtqrencode.h similarity index 70% rename from qqrencode/qqrencode.h rename to qtqrencode.h index 4ebf668..ef235ac 100644 --- a/qqrencode/qqrencode.h +++ b/qtqrencode.h @@ -1,27 +1,25 @@ #ifndef QQRENCODE_H #define QQRENCODE_H +// Qt includes #include -#include "libqtqrencode_global.h" +class QREncodePrivate; -class QQREncodePrivate; - -class LIBQTQRENCODESHARED_EXPORT QQREncode -{ +class QREncode { Q_GADGET Q_ENUMS(ErrorCorrectionLevel) public: enum ErrorCorrectionLevel { - LOW, - MEDIUM, - QUARTILE, - HIGH + ErrorCorrectionLevelLow, + ErrorCorrectionLevelMedium, + ErrorCorrectionLevelQuartile, + ErrorCorrectionLevelHigh }; - QQREncode(); - ~QQREncode(); + QREncode(); + ~QREncode(); void setLevel(ErrorCorrectionLevel value); ErrorCorrectionLevel getLevel() const; @@ -44,9 +42,9 @@ class LIBQTQRENCODESHARED_EXPORT QQREncode // ToDo: encode structured, rle private: - Q_DISABLE_COPY(QQREncode) - QScopedPointer d_ptr; - Q_DECLARE_PRIVATE(QQREncode) + Q_DISABLE_COPY(QREncode) + QScopedPointer d_ptr; + Q_DECLARE_PRIVATE(QREncode) }; #endif // QQRENCODE_H diff --git a/qtqrencode.pri b/qtqrencode.pri new file mode 100644 index 0000000..24b4215 --- /dev/null +++ b/qtqrencode.pri @@ -0,0 +1,13 @@ +INCLUDEPATH += \ + $$PWD + +LIBS += \ + -L../qtqrencode -lqtqrencode + +mac { + # This is where brew puts the lib in + LIBS += -L/usr/local/lib/ +} + +LIBS += -lqrencode + diff --git a/qtqrencode.pro b/qtqrencode.pro index c052998..b4d2430 100644 --- a/qtqrencode.pro +++ b/qtqrencode.pro @@ -1,8 +1,19 @@ -lessThan(QT_MAJOR_VERSION, 5) { - error("Cannot build with Qt version $${QT_VERSION}, this project requires at least Qt 5") +QT += core gui svg + +CONFIG += staticlib + +!win32-msvc2010 { + QMAKE_CXXFLAGS_DEBUG += -std=c++11 -Wno-write-strings + QMAKE_CXXFLAGS_RELEASE += -std=c++11 -Wno-write-strings } -TEMPLATE = subdirs -SUBDIRS += \ - qqrencode \ - test +TARGET = qtqrencode +TEMPLATE = lib + +SOURCES += \ + qtqrencode.cpp + +HEADERS += \ + qtqrencode.h \ + qtqrencode_p.h + diff --git a/qqrencode/qqrencode_p.h b/qtqrencode_p.h similarity index 68% rename from qqrencode/qqrencode_p.h rename to qtqrencode_p.h index 1a41e8d..602aa61 100644 --- a/qqrencode/qqrencode_p.h +++ b/qtqrencode_p.h @@ -1,28 +1,37 @@ #ifndef QQRENCODE_P_H #define QQRENCODE_P_H -#include "qqrencode.h" - +// Own includes +#include "qtqrencode.h" + +// QrEncode includes +#ifdef Q_OS_MAC +// This is where brew puts the header +#include "/usr/local/include/qrencode.h" +#else #include +#endif + +// Qt includes #include -class QQREncodePrivate +class QREncodePrivate { - Q_DECLARE_PUBLIC(QQREncode) + Q_DECLARE_PUBLIC(QREncode) public: - QQREncodePrivate(QQREncode *qqrencode) + QREncodePrivate(QREncode *qqrencode) : q_ptr(qqrencode), m_code(NULL), m_level(QR_ECLEVEL_L),m_version(1), m_margin(4), m_micro(0), m_pen(Qt::black, 0.1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin), m_bg(Qt::white), m_fg(Qt::black) { } - ~QQREncodePrivate(); + ~QREncodePrivate(); void paint(QPainter &painter); - QQREncode *q_ptr; + QREncode *q_ptr; QRcode *m_code; QRecLevel m_level; int m_version; diff --git a/test/main.cpp b/test/main.cpp deleted file mode 100644 index 7de3637..0000000 --- a/test/main.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "qqrencodetestsuite.h" -#include "testrunner.h" - -#include -#include -#include -#include - -int main(int argc, char *argv[]) -{ - QCoreApplication app(argc, argv); - -#if QT_VERSION < QT_VERSION_CHECK(5,0,0) - QTextCodec *codec = QTextCodec::codecForName("UTF-8"); - QTextCodec::setCodecForCStrings(codec); -#endif - - // Perform tests - TestRunner runner(QStringList(), &app); - /** - * Add tests here - */ - runner.addTest(new QQREncodeTestSuite(&app)); - QObject::connect(&runner, &TestRunner::finished, [&] (int result) - { - qDebug() << "Overall Result: " << (result == 0 ? "PASS" : "FAIL"); - app.quit(); - }); - QTimer::singleShot(0, &runner, SLOT(run())); - - return app.exec(); -} - diff --git a/test/qqrencodetestsuite.cpp b/test/qqrencodetestsuite.cpp deleted file mode 100644 index 4015563..0000000 --- a/test/qqrencodetestsuite.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "qqrencodetestsuite.h" - -#include -#include -#include - -const QString RESULTS_PATH = "./results/"; - -QQREncodeTestSuite::QQREncodeTestSuite(QObject *parent) : - QObject(parent) -{ -} - -void QQREncodeTestSuite::initTestCase() -{ - QDir().rmpath(RESULTS_PATH); - QDir().mkpath(RESULTS_PATH); -} - -void QQREncodeTestSuite::accessors() -{ - QQREncode encoder; - encoder.setLevel(QQREncode::ErrorCorrectionLevel::HIGH); - QCOMPARE(encoder.getLevel(),QQREncode::ErrorCorrectionLevel::HIGH); - encoder.setVersion(40); - QCOMPARE(encoder.version(), 40); - encoder.setMargin(8); - QCOMPARE(encoder.margin(),8); - encoder.setMicro(true); - QCOMPARE(encoder.isMicro(),true); -} - -void QQREncodeTestSuite::encodeAlphaNumeric() -{ - QQREncode encoder; - QVERIFY(encoder.encode(QString("abcdefghijklmnopqrstuvwxyz 1234567890$%*+-./:"))); - encoder.toSVG(RESULTS_PATH + "alphanumeric.svg",200); - QImage code = encoder.toQImage(); - code.scaled(200,200).save(RESULTS_PATH + "alphanumeric.png","PNG"); -} - -void QQREncodeTestSuite::encodeByteArray() -{ - QQREncode encoder; - unsigned char testdata[] = {0xF3, 0xFF, 0xFE, 0xF1}; - QVERIFY(encoder.encode(QByteArray((const char*)testdata, 4))); - encoder.toSVG(RESULTS_PATH + "bytearray.svg",200); - QImage code = encoder.toQImage(); - code.scaled(200,200).save(RESULTS_PATH + "bytearray.png","PNG"); -} - -void QQREncodeTestSuite::encodeKanji() -{ - QQREncode encoder; - QTextCodec *codec = QTextCodec::codecForName("Shift-JIS"); - QVERIFY(encoder.encodeKanji(codec->fromUnicode(QString("お疲れ様テスト。")))); -// delete codec; - encoder.toSVG(RESULTS_PATH + "kanji.svg",200); - QImage code = encoder.toQImage(); - code.scaled(200,200).save(RESULTS_PATH + "kanji.png","PNG"); -} - diff --git a/test/qqrencodetestsuite.h b/test/qqrencodetestsuite.h deleted file mode 100644 index de96d63..0000000 --- a/test/qqrencodetestsuite.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef QQRENCODETESTSUITE_H -#define QQRENCODETESTSUITE_H - -#include - -/** - * For now, manual inspection of images is needed to verify the resulting QR is correct. - * @brief The QQREncodeTestSuite class - */ -class QQREncodeTestSuite : public QObject -{ - Q_OBJECT -public: - explicit QQREncodeTestSuite(QObject *parent = 0); - -private slots: - void initTestCase(); - void accessors(); - void encodeAlphaNumeric(); - void encodeByteArray(); - void encodeKanji(); -}; - -#endif // QQRENCODETESTSUITE_H diff --git a/test/test.pro b/test/test.pro deleted file mode 100644 index c994ee1..0000000 --- a/test/test.pro +++ /dev/null @@ -1,40 +0,0 @@ -QT += core testlib - -!win32-msvc2010 { - QMAKE_CXXFLAGS_DEBUG += -std=c++11 - QMAKE_CXXFLAGS_RELEASE += -std=c++11 -} - -TARGET = tester -CONFIG += console - -TEMPLATE = app - -SOURCES += \ - main.cpp \ - testrunner.cpp \ - qqrencodetestsuite.cpp - -HEADERS += \ - testrunner.h \ - qqrencodetestsuite.h - -win32:CONFIG(release, debug|release) { - # WINDOWS RELEASE - PRE_TARGETDEPS += $$OUT_PWD/../qqrencode/release/qtqrencode.dll - LIBS += -L$$OUT_PWD/../qqrencode/release/ -lqtqrencode - -} else:win32:CONFIG(debug, debug|release) { - # WINDOWS DEBUG - PRE_TARGETDEPS += $$OUT_PWD/../qqrencode/debug/qtqrencode.dll - LIBS += -L$$OUT_PWD/../qqrencode/debug/ -lqtqrencode -} else:CONFIG(release, debug|release) { - PRE_TARGETDEPS += $$OUT_PWD/../qqrencode/libqtqrencode.so - LIBS += -L$$OUT_PWD/../qqrencode/ -lqtqrencode -} else:CONFIG(debug, debug|release) { - PRE_TARGETDEPS += $$OUT_PWD/../qqrencode/libqtqrencode.so - LIBS += -L$$OUT_PWD/../qqrencode/ -lqtqrencode -} - -INCLUDEPATH += $$PWD/../qqrencode -DEPENDPATH += $$PWD/../qqrencode diff --git a/test/testrunner.cpp b/test/testrunner.cpp deleted file mode 100644 index 0aa6c97..0000000 --- a/test/testrunner.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "testrunner.h" - -TestRunner::TestRunner(QStringList args, QObject *parent) : - QObject(parent), - m_arguments(args) -{ -} - -void TestRunner::addTest(QObject *test) -{ - test->setParent(this); - m_tests.append(test); -} - - -void TestRunner::run() -{ - foreach (QObject *test, m_tests) - { - m_overallResult = QTest::qExec(test, m_arguments); - if (m_overallResult != 0) - { - break; - } - } - emit finished(m_overallResult); -} diff --git a/test/testrunner.h b/test/testrunner.h deleted file mode 100644 index c661de8..0000000 --- a/test/testrunner.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TESTRUNNER_H -#define TESTRUNNER_H - -#include -#include -#include -#include - -/** - * @brief The TestRunner class - * Inspired from mlvljr's TestRunner here: - * http://stackoverflow.com/questions/1524390/what-unit-testing-framework-should-i-use-for-qt - */ -class TestRunner : public QObject -{ - Q_OBJECT -public: - explicit TestRunner(QStringList args, QObject *parent = 0); - - void addTest(QObject *test); - -signals: - void finished(int result); - -public slots: - void run(); - -private: - QStringList m_arguments; - QList m_tests; - int m_overallResult; -}; - -#endif // TESTRUNNER_H