From 8c781ee1d4e47fd908d92a3817f1daeb3e8bd4d3 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 5 Jul 2014 21:31:43 -0400 Subject: [PATCH] Initial implementation of barcode backends db and barcode menu item. --- app/BarcodeBackends.cpp | 186 ++++++++++++++++++++++++++++++++++++++++ app/BarcodeBackends.h | 101 ++++++++++++++++++++++ app/BarcodeMenuItem.cpp | 54 ++++++++++++ app/BarcodeMenuItem.h | 64 ++++++++++++++ app/BarcodeStyle.cpp | 12 +++ app/BarcodeStyle.h | 4 + app/CMakeLists.txt | 2 + 7 files changed, 423 insertions(+) create mode 100644 app/BarcodeBackends.cpp create mode 100644 app/BarcodeBackends.h create mode 100644 app/BarcodeMenuItem.cpp create mode 100644 app/BarcodeMenuItem.h diff --git a/app/BarcodeBackends.cpp b/app/BarcodeBackends.cpp new file mode 100644 index 0000000..c51910d --- /dev/null +++ b/app/BarcodeBackends.cpp @@ -0,0 +1,186 @@ +/* BarcodeBackends.cpp + * + * Copyright (C) 2014 Jim Evins + * + * 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 . + */ + +#include "BarcodeBackends.h" + + +namespace glabels +{ + + namespace + { + const std::string default_id = "code39"; + } + + BarcodeBackends::BackendMap BarcodeBackends::mBackendIdMap; + BarcodeBackends::BackendMap BarcodeBackends::mBackendNameMap; + + BarcodeBackends::StyleMap BarcodeBackends::mStyleIdMap; + BarcodeBackends::StyleMap BarcodeBackends::mStyleNameMap; + + QList BarcodeBackends::mBackendNameList; + QList BarcodeBackends::mNameList; + + + BarcodeBackends::BarcodeBackends() + { + registerStyle( "postnet", "", tr("POSTNET (any)"), + false, false, true, false, "12345-6789-12", false, 11 ); + + registerStyle( "postnet-5", "", tr("POSTNET-5 (ZIP only)"), + false, false, true, false, "12345", false, 5 ); + + registerStyle( "postnet-9", "", tr("POSTNET-9 (ZIP+4)"), + false, false, true, false, "12345-6789", false, 9 ); + + registerStyle( "postnet-11", "", tr("POSTNET-11 (DPBC)"), + false, false, true, false, "12345-6789-12", false, 11 ); + + registerStyle( "cepnet", "", tr("CEPNET"), + false, false, true, false, "12345-678", false, 8 ); + + registerStyle( "onecode", "", tr("USPS Intelligent Mail"), + false, false, true, false, "12345678901234567890", false, 20 ); + + registerStyle( "code39", "", tr("Code 39"), + true, true, true, true, "1234567890", true, 10 ); + + registerStyle( "code39ext", "", tr("Code 39 Extended"), + true, true, true, true, "1234567890", true, 10 ); + + registerStyle( "upc-A", "", tr("UPC-A"), + true, false, true, false, "12345678901", false, 11 ); + + registerStyle( "ean-13", "", tr("EAN-13"), + true, false, true, false, "123456789012", false, 12 ); + + registerStyle( "datamatrix", "", tr("DataMatrix"), + false, false, true, false, "1234567890AB", false, 12 ); + + registerStyle( "qrcode", "", tr("QRCode"), + false, false, true, false, "1234567890AB", false, 12 ); + } + + + void BarcodeBackends::init( void ) + { + static BarcodeBackends* singletonInstance = NULL; + + if ( singletonInstance == NULL ) + { + singletonInstance = new BarcodeBackends(); + } + } + + + QString BarcodeBackends::BackendIdToName( const QString& backendId ) + { + BackendMap::iterator i = mBackendIdMap.find( backendId ); + if ( i != mBackendIdMap.end() ) + { + return i.value(); + } + + return ""; + } + + + QString BarcodeBackends::BackendNameToId( const QString& backendName ) + { + BackendMap::iterator i = mBackendNameMap.find( backendName ); + if ( i != mBackendNameMap.end() ) + { + return i.value(); + } + + return ""; + } + + + const QList& BarcodeBackends::getBackendNameList() + { + return mBackendNameList; + } + + + const QList& BarcodeBackends::getNameList() + { + return mNameList; + } + + + const BarcodeStyle* BarcodeBackends::lookupStyleFromId( const QString& id ) + { + StyleMap::iterator i = mStyleIdMap.find( id ); + if ( i != mStyleIdMap.end() ) + { + return i.value(); + } + + return 0; + } + + + const BarcodeStyle* BarcodeBackends::lookupStyleFromName( const QString& name ) + { + StyleMap::iterator i = mStyleNameMap.find( name ); + if ( i != mStyleNameMap.end() ) + { + return i.value(); + } + + return 0; + } + + + void BarcodeBackends::registerBackend( QString& id, QString& name) + { + mBackendNameList.append( name ); + mBackendIdMap.insert( id, name ); + mBackendNameMap.insert( name, id ); + } + + + void BarcodeBackends::registerStyle( const char* id, + const char* backendId, + const QString& name, + bool canText, + bool textOptional, + bool canChecksum, + bool checksumOptional, + const char* defaultDigits, + bool canFreeForm, + int preferedN ) + { + BarcodeStyle* style = new BarcodeStyle( QString(id), QString(backendId), name, + canText, textOptional, + canChecksum, checksumOptional, + QString(defaultDigits), canFreeForm, preferedN ); + + QString fqName = QString(backendId) + QString(".") + name; // Name may not be unique + + mNameList.append( name ); + mStyleIdMap.insert( id, style ); + mStyleNameMap.insert( fqName, style ); + } + + + +} diff --git a/app/BarcodeBackends.h b/app/BarcodeBackends.h new file mode 100644 index 0000000..df4263a --- /dev/null +++ b/app/BarcodeBackends.h @@ -0,0 +1,101 @@ +/* BarcodeBackends.h + * + * Copyright (C) 2014 Jim Evins + * + * 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 . + */ + +#ifndef glabels_BarcodeBackends_h +#define glabels_BarcodeBackends_h + +#include "BarcodeStyle.h" + +#include +#include +#include +#include + + +namespace glabels +{ + + /// + /// Barcode Backends Database + /// + class BarcodeBackends : public QObject + { + + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// + private: + BarcodeBackends(); + + public: + static void init( void ); + + ///////////////////////////////// + // Public Methods + ///////////////////////////////// + public: + static QString BackendIdToName( const QString& backendId ); + static QString BackendNameToId( const QString& backendName ); + + static const QList& getBackendNameList(); + static const QList& getNameList(); + + static const BarcodeStyle* lookupStyleFromId( const QString& id ); + static const BarcodeStyle* lookupStyleFromName( const QString& name ); + + + ///////////////////////////////// + // Private Methods + ///////////////////////////////// + private: + static void registerBackend( QString &id, QString &name); + + static void registerStyle( const char* id, + const char* backendId, + const QString& name, + bool canText, + bool textOptional, + bool canChecksum, + bool checksumOptional, + const char* defaultDigits, + bool canFreeForm, + int preferedN ); + + + ///////////////////////////////// + // Private Members + ///////////////////////////////// + typedef QMap BackendMap; + static BackendMap mBackendIdMap; + static BackendMap mBackendNameMap; + + typedef QMap StyleMap; + static StyleMap mStyleIdMap; + static StyleMap mStyleNameMap; + + static QList mBackendNameList; + static QList mNameList; + + }; + +} + + +#endif // glabels_BarcodeBackends_h diff --git a/app/BarcodeMenuItem.cpp b/app/BarcodeMenuItem.cpp new file mode 100644 index 0000000..333470f --- /dev/null +++ b/app/BarcodeMenuItem.cpp @@ -0,0 +1,54 @@ +/* BarcodeMenuItem.cpp + * + * Copyright (C) 2014 Jim Evins + * + * 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 . + */ + +#include "BarcodeMenuItem.h" + + +namespace glabels +{ + + /// + /// Constructor From Data + /// + BarcodeMenuItem::BarcodeMenuItem( BarcodeStyle* bcStyle, QObject* parent ) + : QAction(parent), mBcStyle(bcStyle) + { + setText( bcStyle->name() ); + } + + + /// + /// Destructor + /// + BarcodeMenuItem::~BarcodeMenuItem() + { + } + + + /// + /// bcStyle Property Getter + /// + const BarcodeStyle* BarcodeMenuItem::bcStyle() const + { + return mBcStyle; + } + +} + diff --git a/app/BarcodeMenuItem.h b/app/BarcodeMenuItem.h new file mode 100644 index 0000000..11b3104 --- /dev/null +++ b/app/BarcodeMenuItem.h @@ -0,0 +1,64 @@ +/* BarcodeMenuItem.h + * + * Copyright (C) 2014 Jim Evins + * + * 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 . + */ + +#ifndef glabels_BarcodeMenuItem_h +#define glabels_BarcodeMenuItem_h + +#include +#include "BarcodeStyle.h" + + +namespace glabels +{ + + /// + /// Barcode Menu Item + /// + class BarcodeMenuItem : public QAction + { + + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// + public: + BarcodeMenuItem( BarcodeStyle* bcStyle, QObject* parent ); + + virtual ~BarcodeMenuItem(); + + + ///////////////////////////////// + // Properties + ///////////////////////////////// + + const BarcodeStyle* bcStyle() const; + + + ///////////////////////////////// + // Private Data + ///////////////////////////////// + private: + BarcodeStyle* mBcStyle; + + }; + + +} + +#endif // glabels_BarcodeMenuItem_h diff --git a/app/BarcodeStyle.cpp b/app/BarcodeStyle.cpp index 9a8e960..39b36c1 100644 --- a/app/BarcodeStyle.cpp +++ b/app/BarcodeStyle.cpp @@ -31,6 +31,7 @@ namespace glabels /// BarcodeStyle::BarcodeStyle () : mId( "" ), + mBackendId( "" ), mName( "" ), mCanText( false ), mTextOptional( false ), @@ -47,6 +48,7 @@ namespace glabels /// Constructor From Data /// BarcodeStyle::BarcodeStyle ( const QString& id, + const QString& backendId, const QString& name, bool canText, bool textOptional, @@ -56,6 +58,7 @@ namespace glabels bool canFreeform, int preferedN ) : mId( id ), + mBackendId( backendId ), mName( name ), mCanText( canText ), mTextOptional( textOptional ), @@ -77,6 +80,15 @@ namespace glabels } + /// + /// Backend ID Property Getter + /// + const QString& BarcodeStyle::backendId() const + { + return mBackendId; + } + + /// /// Name Property Getter /// diff --git a/app/BarcodeStyle.h b/app/BarcodeStyle.h index 48e4077..fbd4bc7 100644 --- a/app/BarcodeStyle.h +++ b/app/BarcodeStyle.h @@ -40,6 +40,7 @@ namespace glabels BarcodeStyle (); BarcodeStyle ( const QString& id, + const QString& backendId, const QString& name, bool canText, bool textOptional, @@ -55,6 +56,8 @@ namespace glabels ///////////////////////////////// const QString& id() const; + const QString& backendId() const; + const QString& name() const; bool canText() const; @@ -84,6 +87,7 @@ namespace glabels ///////////////////////////////// private: QString mId; + QString mBackendId; QString mName; bool mCanText; bool mTextOptional; diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 37698e4..db0daed 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -4,6 +4,8 @@ project (app CXX) set (glabels_sources glabels_main.cpp + BarcodeBackends.cpp + BarcodeMenuItem.cpp BarcodeStyle.cpp ColorNode.cpp File.cpp