Finished hooking up barcode style controls in object editor.

This commit is contained in:
Jim Evins
2017-05-07 19:09:36 -04:00
parent 409ca1bf57
commit 56c2930db7
12 changed files with 180 additions and 177 deletions
+20 -76
View File
@@ -29,16 +29,25 @@ namespace glabels
//
BarcodeBackends::BackendMap BarcodeBackends::mBackendIdMap;
BarcodeBackends::BackendMap BarcodeBackends::mBackendNameMap;
BarcodeBackends::StyleMap BarcodeBackends::mStyleIdMap;
BarcodeBackends::StyleMap BarcodeBackends::mStyleNameMap;
QList<QString> BarcodeBackends::mBackendNameList;
QList<QString> BarcodeBackends::mNameList;
QList<BarcodeStyle> BarcodeBackends::mStyleList;
BarcodeBackends::BarcodeBackends()
{
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( "postnet", "", tr("POSTNET (any)"),
false, false, true, false, "12345-6789-12", false, 11 );
@@ -57,23 +66,12 @@ namespace glabels
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 );
}
@@ -88,65 +86,15 @@ namespace glabels
}
QString BarcodeBackends::BackendIdToName( const QString& backendId )
const QList<BarcodeStyle>& BarcodeBackends::styleList()
{
BackendMap::iterator i = mBackendIdMap.find( backendId );
if ( i != mBackendIdMap.end() )
{
return i.value();
}
return "";
return mStyleList;
}
QString BarcodeBackends::BackendNameToId( const QString& backendName )
const BarcodeStyle& BarcodeBackends::defaultStyle()
{
BackendMap::iterator i = mBackendNameMap.find( backendName );
if ( i != mBackendNameMap.end() )
{
return i.value();
}
return "";
}
const QList<QString>& BarcodeBackends::getBackendNameList()
{
return mBackendNameList;
}
const QList<QString>& BarcodeBackends::getNameList()
{
return mNameList;
}
BarcodeStyle BarcodeBackends::lookupStyleFromId( const QString& id )
{
StyleMap::iterator i = mStyleIdMap.find( id );
if ( i != mStyleIdMap.end() )
{
return i.value();
}
return BarcodeStyle( QString("code39"), QString(""), tr("Code 39"),
true, true, true, true, QString("1234567890"), true, 10 );
}
BarcodeStyle BarcodeBackends::lookupStyleFromName( const QString& name )
{
StyleMap::iterator i = mStyleNameMap.find( name );
if ( i != mStyleNameMap.end() )
{
return i.value();
}
return BarcodeStyle( QString("code39"), QString(""), tr("Code 39"),
true, true, true, true, QString("1234567890"), true, 10 );
return mStyleList[0];
}
@@ -175,11 +123,7 @@ namespace glabels
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 );
mStyleList.append( style );
}
} // namespace glabels
+4 -14
View File
@@ -54,14 +54,8 @@ namespace glabels
// Public Methods
/////////////////////////////////
public:
static QString BackendIdToName( const QString& backendId );
static QString BackendNameToId( const QString& backendName );
static const QList<QString>& getBackendNameList();
static const QList<QString>& getNameList();
static BarcodeStyle lookupStyleFromId( const QString& id );
static BarcodeStyle lookupStyleFromName( const QString& name );
static const QList<BarcodeStyle>& styleList();
static const BarcodeStyle& defaultStyle();
/////////////////////////////////
@@ -88,13 +82,9 @@ namespace glabels
typedef QMap<QString,QString> BackendMap;
static BackendMap mBackendIdMap;
static BackendMap mBackendNameMap;
typedef QMap<QString,BarcodeStyle> StyleMap;
static StyleMap mStyleIdMap;
static StyleMap mStyleNameMap;
static QList<QString> mBackendNameList;
static QList<QString> mNameList;
static QList<BarcodeStyle> mStyleList;
};
+7 -6
View File
@@ -23,6 +23,8 @@
#include "BarcodeBackends.h"
#include "BarcodeMenuItem.h"
#include <QtDebug>
namespace glabels
{
@@ -32,12 +34,11 @@ namespace glabels
///
BarcodeMenu::BarcodeMenu()
{
foreach ( QString name, BarcodeBackends::getNameList() )
foreach ( const BarcodeStyle& bcStyle, BarcodeBackends::styleList() )
{
BarcodeStyle bcStyle = BarcodeBackends::lookupStyleFromName( name );
BarcodeMenuItem* bcMenuItem = new BarcodeMenuItem( bcStyle );
connect( bcMenuItem, SIGNAL(activated()), this, SLOT(onMenuItemActivated) );
connect( bcMenuItem, SIGNAL(activated(const BarcodeStyle&)),
this, SLOT(onMenuItemActivated(const BarcodeStyle&)) );
addAction( bcMenuItem );
}
@@ -56,11 +57,11 @@ namespace glabels
///
/// onMenuItemActivated slot
///
void BarcodeMenu::onMenuItemActivated( BarcodeStyle bcStyle )
void BarcodeMenu::onMenuItemActivated( const BarcodeStyle& bcStyle )
{
mBcStyle = bcStyle;
emit styleChanged();
emit selectionChanged();
}
} // namespace glabels
+2 -2
View File
@@ -48,7 +48,7 @@ namespace glabels
// Signals
/////////////////////////////////
signals:
void styleChanged();
void selectionChanged();
/////////////////////////////////
@@ -62,7 +62,7 @@ namespace glabels
// Slots
/////////////////////////////////
private slots:
void onMenuItemActivated( BarcodeStyle bcStyle );
void onMenuItemActivated( const BarcodeStyle& bcStyle );
/////////////////////////////////
+16 -4
View File
@@ -23,6 +23,8 @@
#include "BarcodeBackends.h"
#include "BarcodeMenuItem.h"
#include <QtDebug>
namespace glabels
{
@@ -36,10 +38,10 @@ namespace glabels
mMenu = new BarcodeMenu();
setMenu( mMenu );
mBcStyle = BarcodeBackends::lookupStyleFromId( "" ); // Default style
mBcStyle = BarcodeBackends::defaultStyle();
setText( mBcStyle.name() );
connect( mMenu, SIGNAL(styleChanged()), this, SLOT(onMenuStyleChanged()) );
connect( mMenu, SIGNAL(selectionChanged()), this, SLOT(onMenuSelectionChanged()) );
}
@@ -52,15 +54,25 @@ namespace glabels
}
///
/// bcStyle setter
///
void BarcodeMenuButton::setBcStyle( const BarcodeStyle& bcStyle )
{
mBcStyle = bcStyle;
setText( mBcStyle.name() );
}
///
/// onMenuStyleChanged slot
///
void BarcodeMenuButton::onMenuStyleChanged()
void BarcodeMenuButton::onMenuSelectionChanged()
{
mBcStyle = mMenu->bcStyle();
setText( mBcStyle.name() );
emit styleChanged();
emit selectionChanged();
}
} // namespace glabels
+3 -2
View File
@@ -49,7 +49,7 @@ namespace glabels
// Signals
/////////////////////////////////
signals:
void styleChanged();
void selectionChanged();
/////////////////////////////////
@@ -57,13 +57,14 @@ namespace glabels
/////////////////////////////////
public:
BarcodeStyle bcStyle() const;
void setBcStyle( const BarcodeStyle& bcStyle );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onMenuStyleChanged();
void onMenuSelectionChanged();
/////////////////////////////////
+2
View File
@@ -20,6 +20,8 @@
#include "BarcodeMenuItem.h"
#include <QtDebug>
namespace glabels
{
+14 -1
View File
@@ -44,6 +44,8 @@ namespace glabels
{
const QColor emptyFillColor = QColor( 128, 128, 128, 128 );
const Distance pad = Distance::pt(4);
const Distance minW = Distance::pt(18);
const Distance minH = Distance::pt(18);
}
@@ -63,7 +65,7 @@ namespace glabels
mHandles << new HandleSouthWest( this );
mHandles << new HandleWest( this );
mBcStyle = BarcodeBackends::lookupStyleFromId( "code39" );
mBcStyle = BarcodeBackends::defaultStyle();
mBcTextFlag = mBcStyle.canText();
mBcChecksumFlag = mBcStyle.canChecksum();
mBcFormatDigits = mBcStyle.preferedN();
@@ -315,6 +317,12 @@ namespace glabels
delete mEditorBarcode;
}
mEditorBarcode = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() );
if ( !mEditorBarcode )
{
qWarning() << "Invalid barcode style" << mBcStyle.id() << "using \"code39\".";
mBcStyle = BarcodeBackends::defaultStyle();
mEditorBarcode = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() );
}
mEditorBarcode->setChecksum(mBcChecksumFlag);
mEditorBarcode->setShowText(mBcTextFlag);
@@ -325,6 +333,11 @@ namespace glabels
mW = Distance::pt( mEditorBarcode->width() );
mH = Distance::pt( mEditorBarcode->height() );
}
else
{
mW = max( mW, minW );
mH = max( mH, minH );
}
QPainterPath path;
path.addRect( 0, 0, mW.pt(), mH.pt() );
+36 -4
View File
@@ -249,8 +249,24 @@ namespace glabels
{
mBlocked = true;
barcodeShowTextCheck->setChecked( mObject->bcTextFlag() );
barcodeChecksumCheck->setChecked( mObject->bcChecksumFlag() );
BarcodeStyle bcStyle = mObject->bcStyle();
barcodeShowTextCheck->setEnabled( bcStyle.textOptional() );
barcodeChecksumCheck->setEnabled( bcStyle.checksumOptional() );
// May need to adjust current text flag, if style changed
bool textFlag = (mObject->bcTextFlag() && bcStyle.canText())
|| (bcStyle.canText() && !bcStyle.textOptional());
mObject->setBcTextFlag( textFlag );
// May need to adjust current checksum flag, if style changed
bool csFlag = (mObject->bcChecksumFlag() && bcStyle.canChecksum())
|| (bcStyle.canChecksum() && !bcStyle.checksumOptional());
mObject->setBcChecksumFlag( csFlag );
barcodeStyleButton->setBcStyle( bcStyle );
barcodeShowTextCheck->setChecked( textFlag );
barcodeChecksumCheck->setChecked( csFlag );
barcodeColorButton->setColorNode( mObject->bcColorNode() );
barcodeDataEdit->setText( mObject->bcData() );
@@ -702,8 +718,24 @@ namespace glabels
{
mBlocked = true;
mObject->setBcTextFlag( barcodeShowTextCheck->isChecked() );
mObject->setBcChecksumFlag( barcodeChecksumCheck->isChecked() );
BarcodeStyle bcStyle = barcodeStyleButton->bcStyle();
barcodeShowTextCheck->setEnabled( bcStyle.textOptional() );
barcodeChecksumCheck->setEnabled( bcStyle.checksumOptional() );
// May need to adjust current text flag, if style changed
bool textFlag = (barcodeShowTextCheck->isChecked() && bcStyle.canText())
|| (bcStyle.canText() && !bcStyle.textOptional());
barcodeShowTextCheck->setChecked( textFlag );
// May need to adjust current checksum flag, if style changed
bool csFlag = (barcodeChecksumCheck->isChecked() && bcStyle.canChecksum())
|| (bcStyle.canChecksum() && !bcStyle.checksumOptional());
barcodeChecksumCheck->setChecked( csFlag );
mObject->setBcStyle( bcStyle );
mObject->setBcTextFlag( textFlag );
mObject->setBcChecksumFlag( csFlag );
mObject->setBcColorNode( barcodeColorButton->colorNode() );
mObject->setBcData( barcodeDataEdit->toPlainText() );
+2
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "BarcodeBackends.h"
#include "FileUtil.h"
#include "Db.h"
#include "LabelModel.h"
@@ -89,6 +90,7 @@ int main( int argc, char **argv )
glabels::Settings::init();
glabels::Db::init();
glabels::merge::Factory::init();
glabels::BarcodeBackends::init();
//
+27 -19
View File
@@ -562,9 +562,6 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="barcodeTypeCombo"/>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="barcodeShowTextCheck">
<property name="text">
@@ -610,6 +607,9 @@
</item>
</layout>
</item>
<item row="0" column="1">
<widget class="glabels::BarcodeMenuButton" name="barcodeStyleButton"/>
</item>
</layout>
</item>
<item row="0" column="1">
@@ -1489,6 +1489,14 @@
<signal>keySelected(QString)</signal>
</slots>
</customwidget>
<customwidget>
<class>glabels::BarcodeMenuButton</class>
<extends>QPushButton</extends>
<header>BarcodeMenuButton.h</header>
<slots>
<signal>selectionChanged()</signal>
</slots>
</customwidget>
</customwidgets>
<resources>
<include location="../icons.qrc"/>
@@ -2006,22 +2014,6 @@
</hint>
</hints>
</connection>
<connection>
<sender>barcodeTypeCombo</sender>
<signal>textChanged(QString)</signal>
<receiver>ObjectEditor</receiver>
<slot>onBarcodeControlsChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>102</x>
<y>116</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>144</y>
</hint>
</hints>
</connection>
<connection>
<sender>barcodeShowTextCheck</sender>
<signal>toggled(bool)</signal>
@@ -2102,6 +2094,22 @@
</hint>
</hints>
</connection>
<connection>
<sender>barcodeStyleButton</sender>
<signal>selectionChanged()</signal>
<receiver>ObjectEditor</receiver>
<slot>onBarcodeControlsChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>114</x>
<y>121</y>
</hint>
<hint type="destinationlabel">
<x>5</x>
<y>94</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>onChanged()</slot>