Created QrEncode barcode backend.
This commit is contained in:
+39
-14
@@ -20,6 +20,12 @@
|
||||
|
||||
#include "BarcodeBackends.h"
|
||||
|
||||
#include "glbarcode/Factory.h"
|
||||
|
||||
#if HAVE_QRENCODE
|
||||
#include "BarcodeBackends/QrEncode.h"
|
||||
#endif // HAVE_QRENCODE
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
@@ -27,9 +33,8 @@ namespace glabels
|
||||
//
|
||||
// Static data
|
||||
//
|
||||
BarcodeBackends::BackendMap BarcodeBackends::mBackendIdMap;
|
||||
BarcodeBackends::BackendMap BarcodeBackends::mBackendNameMap;
|
||||
QList<QString> BarcodeBackends::mBackendNameList;
|
||||
QStringList BarcodeBackends::mBackendIdList;
|
||||
QMap<QString,QString> BarcodeBackends::mBackendNameMap;
|
||||
|
||||
QList<BarcodeStyle> BarcodeBackends::mStyleList;
|
||||
|
||||
@@ -66,11 +71,20 @@ namespace glabels
|
||||
registerStyle( "onecode", "", tr("USPS Intelligent Mail"),
|
||||
false, false, true, false, "12345678901234567890", false, 20 );
|
||||
|
||||
registerStyle( "datamatrix", "", tr("DataMatrix"),
|
||||
registerStyle( "datamatrix", "", tr("IEC16022 (DataMatrix)"),
|
||||
false, false, true, false, "1234567890AB", false, 12 );
|
||||
|
||||
registerStyle( "qrcode", "", tr("QRCode"),
|
||||
#if HAVE_QRENCODE
|
||||
//
|
||||
// Libqrencode backend
|
||||
//
|
||||
registerBackend( "qrencode", "QREncode" );
|
||||
|
||||
glbarcode::Factory::registerType( "qrencode::qrcode", barcode::QrEncode::createQrCode );
|
||||
|
||||
registerStyle( "qrcode", "qrencode", tr("IEC18004 (QRCode)"),
|
||||
false, false, true, false, "1234567890AB", false, 12 );
|
||||
#endif // HAVE_QRENCODE
|
||||
|
||||
}
|
||||
|
||||
@@ -86,6 +100,18 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
const QStringList& BarcodeBackends::backendList()
|
||||
{
|
||||
return mBackendIdList;
|
||||
}
|
||||
|
||||
|
||||
QString BarcodeBackends::backendName( const QString& backendId )
|
||||
{
|
||||
return mBackendNameMap[ backendId ];
|
||||
}
|
||||
|
||||
|
||||
const QList<BarcodeStyle>& BarcodeBackends::styleList()
|
||||
{
|
||||
return mStyleList;
|
||||
@@ -112,29 +138,28 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
void BarcodeBackends::registerBackend( QString& id, QString& name)
|
||||
void BarcodeBackends::registerBackend( const QString& backendId, const QString& backendName )
|
||||
{
|
||||
mBackendNameList.append( name );
|
||||
mBackendIdMap.insert( id, name );
|
||||
mBackendNameMap.insert( name, id );
|
||||
mBackendIdList.append( backendId );
|
||||
mBackendNameMap[ backendId ] = backendName;
|
||||
}
|
||||
|
||||
|
||||
void BarcodeBackends::registerStyle( const char* id,
|
||||
const char* backendId,
|
||||
void BarcodeBackends::registerStyle( const QString& id,
|
||||
const QString& backendId,
|
||||
const QString& name,
|
||||
bool canText,
|
||||
bool textOptional,
|
||||
bool canChecksum,
|
||||
bool checksumOptional,
|
||||
const char* defaultDigits,
|
||||
const QString& defaultDigits,
|
||||
bool canFreeForm,
|
||||
int preferedN )
|
||||
{
|
||||
BarcodeStyle style( QString(id), QString(backendId), name,
|
||||
BarcodeStyle style( id, backendId, name,
|
||||
canText, textOptional,
|
||||
canChecksum, checksumOptional,
|
||||
QString(defaultDigits),
|
||||
defaultDigits,
|
||||
canFreeForm, preferedN );
|
||||
|
||||
mStyleList.append( style );
|
||||
|
||||
@@ -54,6 +54,8 @@ namespace glabels
|
||||
// Public Methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
static const QStringList& backendList();
|
||||
static QString backendName( const QString& backendId );
|
||||
static const QList<BarcodeStyle>& styleList();
|
||||
static const BarcodeStyle& defaultStyle();
|
||||
static const BarcodeStyle& style( const QString& backendId, const QString& StyleId );
|
||||
@@ -63,16 +65,16 @@ namespace glabels
|
||||
// Private Methods
|
||||
/////////////////////////////////
|
||||
private:
|
||||
static void registerBackend( QString &id, QString &name);
|
||||
static void registerBackend( const QString &backendId, const QString &backendName );
|
||||
|
||||
static void registerStyle( const char* id,
|
||||
const char* backendId,
|
||||
static void registerStyle( const QString& id,
|
||||
const QString& backendId,
|
||||
const QString& name,
|
||||
bool canText,
|
||||
bool textOptional,
|
||||
bool canChecksum,
|
||||
bool checksumOptional,
|
||||
const char* defaultDigits,
|
||||
const QString& defaultDigits,
|
||||
bool canFreeForm,
|
||||
int preferedN );
|
||||
|
||||
@@ -80,10 +82,8 @@ namespace glabels
|
||||
/////////////////////////////////
|
||||
// Private Members
|
||||
/////////////////////////////////
|
||||
typedef QMap<QString,QString> BackendMap;
|
||||
static BackendMap mBackendIdMap;
|
||||
static BackendMap mBackendNameMap;
|
||||
static QList<QString> mBackendNameList;
|
||||
static QStringList mBackendIdList;
|
||||
static QMap<QString,QString> mBackendNameMap;
|
||||
|
||||
static QList<BarcodeStyle> mStyleList;
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#=======================================
|
||||
# Sources
|
||||
#=======================================
|
||||
set (barcode_sources
|
||||
QrEncode.cpp
|
||||
)
|
||||
|
||||
add_library (Barcode STATIC
|
||||
${barcode_sources}
|
||||
)
|
||||
|
||||
|
||||
#=======================================
|
||||
# Where to find stuff
|
||||
#=======================================
|
||||
include_directories (
|
||||
)
|
||||
|
||||
link_directories (
|
||||
)
|
||||
|
||||
|
||||
#=======================================
|
||||
# Subdirectories
|
||||
#=======================================
|
||||
|
||||
|
||||
#=======================================
|
||||
# Install
|
||||
#=======================================
|
||||
@@ -0,0 +1,89 @@
|
||||
/* QrEncode.cpp
|
||||
*
|
||||
* Copyright (C) 2017 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if HAVE_QRENCODE
|
||||
|
||||
#include "QrEncode.h"
|
||||
|
||||
#include "qrencode.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace barcode
|
||||
{
|
||||
|
||||
/*
|
||||
* Static QrCode barcode creation method
|
||||
*/
|
||||
glbarcode::Barcode* QrEncode::createQrCode()
|
||||
{
|
||||
return new QrEncode();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* QrEncode data validation, implements glbarcode::Barcode2dBase::validate()
|
||||
*/
|
||||
bool QrEncode::validate( const std::string& rawData )
|
||||
{
|
||||
if ( rawData.size() == 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* QrEncode data encoding, implements glbarcode::Barcode2dBase::encode()
|
||||
*/
|
||||
bool QrEncode::encode( const std::string& cookedData, glbarcode::Matrix<bool>& encodedData )
|
||||
{
|
||||
QRcode *qrcode = QRcode_encodeString( cookedData.c_str(), 0, QR_ECLEVEL_M, QR_MODE_8, 1 );
|
||||
if ( qrcode == NULL )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int w = qrcode->width;
|
||||
encodedData.resize( w, w );
|
||||
|
||||
|
||||
for ( int iy = 0; iy < w; iy++ )
|
||||
{
|
||||
for ( int ix = 0; ix < w; ix++ )
|
||||
{
|
||||
encodedData[iy][ix] = qrcode->data[ iy*w + ix ] & 0x01;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QRcode_free( qrcode );
|
||||
QRcode_clearCache();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HAVE_QRENCODE
|
||||
@@ -0,0 +1,55 @@
|
||||
/* QrEncode.h
|
||||
*
|
||||
* Copyright (C) 2017 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef barcode_QrEncode_h
|
||||
#define barcode_QrEncode_h
|
||||
|
||||
|
||||
#include "glbarcode/Barcode2dBase.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
namespace barcode
|
||||
{
|
||||
|
||||
/**
|
||||
* LibQREncode barcode backend
|
||||
*
|
||||
* Implements glbarcode::Barcode2dBase.
|
||||
*/
|
||||
class QrEncode : public glbarcode::Barcode2dBase
|
||||
{
|
||||
public:
|
||||
static Barcode* createQrCode();
|
||||
|
||||
|
||||
private:
|
||||
bool validate( const std::string& rawData ) override;
|
||||
|
||||
bool encode( const std::string& cookedData,
|
||||
glbarcode::Matrix<bool>& encodedData ) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // barcode_QrEncode_h
|
||||
+24
-4
@@ -36,11 +36,31 @@ namespace glabels
|
||||
{
|
||||
foreach ( const BarcodeStyle& bcStyle, BarcodeBackends::styleList() )
|
||||
{
|
||||
BarcodeMenuItem* bcMenuItem = new BarcodeMenuItem( bcStyle );
|
||||
connect( bcMenuItem, SIGNAL(activated(const BarcodeStyle&)),
|
||||
this, SLOT(onMenuItemActivated(const BarcodeStyle&)) );
|
||||
if ( bcStyle.backendId() == "" )
|
||||
{
|
||||
BarcodeMenuItem* bcMenuItem = new BarcodeMenuItem( bcStyle );
|
||||
connect( bcMenuItem, SIGNAL(activated(const BarcodeStyle&)),
|
||||
this, SLOT(onMenuItemActivated(const BarcodeStyle&)) );
|
||||
|
||||
addAction( bcMenuItem );
|
||||
addAction( bcMenuItem );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( const QString& backendId, BarcodeBackends::backendList() )
|
||||
{
|
||||
QMenu* subMenu = addMenu( BarcodeBackends::backendName( backendId ) );
|
||||
|
||||
foreach ( const BarcodeStyle& bcStyle, BarcodeBackends::styleList() )
|
||||
{
|
||||
if ( bcStyle.backendId() == backendId )
|
||||
{
|
||||
BarcodeMenuItem* bcMenuItem = new BarcodeMenuItem( bcStyle );
|
||||
connect( bcMenuItem, SIGNAL(activated(const BarcodeStyle&)),
|
||||
this, SLOT(onMenuItemActivated(const BarcodeStyle&)) );
|
||||
|
||||
subMenu->addAction( bcMenuItem );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -80,6 +80,22 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Full ID Property Getter
|
||||
///
|
||||
QString BarcodeStyle::fullId() const
|
||||
{
|
||||
if ( mBackendId == "" )
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
else
|
||||
{
|
||||
return mBackendId + "::" + mId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Backend ID Property Getter
|
||||
///
|
||||
|
||||
@@ -57,6 +57,8 @@ namespace glabels
|
||||
/////////////////////////////////
|
||||
const QString& id() const;
|
||||
|
||||
QString fullId() const;
|
||||
|
||||
const QString& backendId() const;
|
||||
|
||||
const QString& name() const;
|
||||
|
||||
@@ -11,6 +11,13 @@ endif ()
|
||||
# Uncomment to build with pedantic flags
|
||||
#add_compile_options (-Werror -Wall -Wpedantic)
|
||||
|
||||
if (${LIBQRENCODE_FOUND})
|
||||
add_definitions (-DHAVE_QRENCODE=1)
|
||||
else (${LIBQRENCODE_FOUND})
|
||||
set (LIBQRENCODE_INCLUDE_DIR "")
|
||||
set (LIBQRENCODE_LIBRARIES "")
|
||||
endif (${LIBQRENCODE_FOUND})
|
||||
|
||||
|
||||
#=======================================
|
||||
# Auto-generate Version.h
|
||||
@@ -177,6 +184,7 @@ add_executable (glabels-qt WIN32
|
||||
)
|
||||
|
||||
target_link_libraries (glabels-qt
|
||||
Barcode
|
||||
Merge
|
||||
glbarcode
|
||||
${Qt5Widgets_LIBRARIES}
|
||||
@@ -184,6 +192,7 @@ target_link_libraries (glabels-qt
|
||||
${Qt5Xml_LIBRARIES}
|
||||
${Qt5Svg_LIBRARIES}
|
||||
${ZLIB_LIBRARIES}
|
||||
${LIBQRENCODE_LIBRARIES}
|
||||
)
|
||||
|
||||
|
||||
@@ -197,6 +206,7 @@ include_directories (
|
||||
${Qt5PrintSupport_INCLUDE_DIRS}
|
||||
${Qt5Xml_INCLUDE_DIRS}
|
||||
${Qt5Svg_INCLUDE_DIRS}
|
||||
${LIBQRENCODE_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
link_directories (
|
||||
@@ -206,6 +216,7 @@ link_directories (
|
||||
#=======================================
|
||||
# Subdirectories
|
||||
#=======================================
|
||||
add_subdirectory (BarcodeBackends)
|
||||
add_subdirectory (Merge)
|
||||
|
||||
|
||||
|
||||
@@ -363,10 +363,10 @@ namespace glabels
|
||||
{
|
||||
delete mEditorBarcode;
|
||||
}
|
||||
mEditorBarcode = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() );
|
||||
mEditorBarcode = glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() );
|
||||
if ( !mEditorBarcode )
|
||||
{
|
||||
qWarning() << "Invalid barcode style" << mBcStyle.id() << "using \"code39\".";
|
||||
qWarning() << "Invalid barcode style" << mBcStyle.fullId() << "using \"code39\".";
|
||||
mBcStyle = BarcodeBackends::defaultStyle();
|
||||
mEditorBarcode = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() );
|
||||
}
|
||||
@@ -382,10 +382,10 @@ namespace glabels
|
||||
{
|
||||
delete mEditorDefaultBarcode;
|
||||
}
|
||||
mEditorDefaultBarcode = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() );
|
||||
mEditorDefaultBarcode = glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() );
|
||||
if ( !mEditorDefaultBarcode )
|
||||
{
|
||||
qWarning() << "Invalid barcode style" << mBcStyle.id() << "using \"code39\".";
|
||||
qWarning() << "Invalid barcode style" << mBcStyle.fullId() << "using \"code39\".";
|
||||
mBcStyle = BarcodeBackends::defaultStyle();
|
||||
mEditorDefaultBarcode = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() );
|
||||
}
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
cmake_minimum_required (VERSION 2.8.12)
|
||||
|
||||
###############################################################################
|
||||
# gLabels Merge subsystem
|
||||
###############################################################################
|
||||
project (Merge CXX)
|
||||
|
||||
|
||||
#=======================================
|
||||
# Sources
|
||||
#=======================================
|
||||
|
||||
Reference in New Issue
Block a user