Skip to content

Commit

Permalink
Merge pull request #72 from gitlost/UserVariables
Browse files Browse the repository at this point in the history
User variables (includes original UserVariables branch and gitlost's mods)
  • Loading branch information
jimevins authored Aug 29, 2019
2 parents 6ab3a12 + 6bc0cb8 commit d9e6444
Show file tree
Hide file tree
Showing 110 changed files with 5,444 additions and 1,313 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ core
*.sav*
.directory
TEST-DATA
SAV*
OLD*

2 changes: 1 addition & 1 deletion backends/barcode/Backends.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ namespace glabels
glbarcode::Factory::registerType( "zint::kix", Zint::Kix::create );
glbarcode::Factory::registerType( "zint::ean", Zint::Ean::create );
glbarcode::Factory::registerType( "zint::gmtx", Zint::Gmtx::create );
glbarcode::Factory::registerType( "zint::gs1128", Zint::Gs1128::create );
glbarcode::Factory::registerType( "zint::gs1-128", Zint::Gs1128::create );
glbarcode::Factory::registerType( "zint::rss14", Zint::Rss14::create );
glbarcode::Factory::registerType( "zint::rssltd", Zint::Rssltd::create );
glbarcode::Factory::registerType( "zint::rssexp", Zint::Rssexp::create );
Expand Down
39 changes: 22 additions & 17 deletions docs/SUBSTITUTION-FIELD-SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ modifiers = modifier [ ":" modifiers ] ;
modifier = format-modifier | default-value-modifier | new-line-modifier;
```


Field Names
-----------
Field names can refer to either [Document Merge Fields](#document-merge-fields) or [User Variables](#user-variables). If a document merge field and a user variable share the same name, the document merge field takes precidence. Its syntax is simply:

```ebnf
field-name = merge-field-name | user-variable-name ;
```

### Document Merge Fields
Document merge fields are the primary source of substitution fields. A document merge field represents a field from an external data source, such as a CSV file. The valid syntax for a document merge field name is determined by the merge source, with the following exception. Merge field names cannot contain either a colon (":") or closing curly bracket ("}").

### User Variables
Substitution fields can also refer to user variables. The syntax for valid user variable names is

```ebnf
letter = "a" | "b" | ... | "z" | "A" | ... | "Z";
digit = "0" | "1" | "2" | ... | "9";
user-variable-name = ( letter | "_" ) , { letter | digit | "_" } ;
```


Modifiers
---------
### Format-Modifier (`%`)
Expand Down Expand Up @@ -89,20 +111,3 @@ ${CITY} ${STATE} ${ZIP}
`${ADDR2}` would be printed on its own line, only if it is set and non-empty.


Document Merge Fields
---------------------
Document merge fields are the primary source of substitution fields. A document merge field represents a field from an external data source, such as a CSV file.

User Defined Variables
----------------------
Alternatively, merge fields can refer to user defined variables.

Built-In Variables
------------------
Potentially, merge fields may also refer to built-in variables. Candidates include:
- LABEL_NUMBER
- PAGE_NUMBER
- DATE
- TIME
- FILE_NAME

12 changes: 12 additions & 0 deletions docs/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,15 @@ Add support for "Continuous Roll" labels

Write help documentation
------------------------


To Do List for gLabels 4.1 -- 2019-03-17
========================================

Create a "built-in" merge source
--------------------------------
As an alternative to external merge sources, let the user edit the merge source
in situ. The user can add fields. The user can add records using those fields.
The user created database will become part of the glabels project file.
For simple databases, such as a small address list, this would be much easier
to deal with than creating it externally.
8 changes: 6 additions & 2 deletions glabels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ set (glabels_sources
ColorHistory.cpp
ColorPaletteDialog.cpp
ColorPaletteItem.cpp
ColorPaletteButtonItem.cpp
ColorSwatch.cpp
Cursors.cpp
EditVariableDialog.cpp
FieldButton.cpp
File.cpp
Help.cpp
Expand All @@ -40,6 +40,7 @@ set (glabels_sources
TemplatePicker.cpp
TemplatePickerItem.cpp
UndoRedoModel.cpp
VariablesView.cpp
)

set (glabels_qobject_headers
Expand All @@ -51,7 +52,7 @@ set (glabels_qobject_headers
ColorHistory.h
ColorPaletteDialog.h
ColorPaletteItem.h
ColorPaletteButtonItem.h
EditVariableDialog.h
FieldButton.h
File.h
LabelEditor.h
Expand All @@ -69,10 +70,12 @@ set (glabels_qobject_headers
TemplateDesigner.h
TemplatePicker.h
UndoRedoModel.h
VariablesView.h
)

set (glabels_forms
ui/AboutDialog.ui
ui/EditVariableDialog.ui
ui/MergeView.ui
ui/ObjectEditor.ui
ui/PreferencesDialog.ui
Expand All @@ -95,6 +98,7 @@ set (glabels_forms
ui/TemplateDesignerOneLayoutPage.ui
ui/TemplateDesignerTwoLayoutPage.ui
ui/TemplateDesignerApplyPage.ui
ui/VariablesView.ui
)

set (glabels_resource_files
Expand Down
21 changes: 10 additions & 11 deletions glabels/ColorButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ namespace glabels


void ColorButton::init( const QString& defaultLabel,
const QColor& defaultColor,
const QColor& color )
const QColor& defaultColor,
const QColor& color,
bool showUseFieldButton )
{
mDefaultColor = defaultColor;
mColorNode = model::ColorNode( color );
Expand All @@ -61,7 +62,10 @@ namespace glabels
setText( "" );
setCheckable( true );

mDialog = new ColorPaletteDialog( defaultLabel, defaultColor, color );
mDialog = new ColorPaletteDialog( defaultLabel,
defaultColor,
color,
showUseFieldButton );

connect( this, SIGNAL(toggled(bool)), this, SLOT(onButtonToggled(bool)) );
connect( mDialog, SIGNAL(colorChanged(model::ColorNode,bool)),
Expand Down Expand Up @@ -124,15 +128,10 @@ namespace glabels
}


void ColorButton::setKeys( const QList<QString> keyList )
void ColorButton::setKeys( const merge::Merge* merge,
const model::Variables* variables )
{
mDialog->setKeys( keyList );
}


void ColorButton::clearKeys()
{
mDialog->clearKeys();
mDialog->setKeys( merge, variables );
}


Expand Down
11 changes: 8 additions & 3 deletions glabels/ColorButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,18 @@ namespace glabels
// Public Methods
/////////////////////////////////
public:
void init( const QString& defaultLabel, const QColor& defaultColor, const QColor& color );
void init( const QString& defaultLabel,
const QColor& defaultColor,
const QColor& color,
bool showUseFieldButton = true );

void setColorNode( model::ColorNode colorNode );
void setColor( QColor color );
void setToDefault();
model::ColorNode colorNode();
void setKeys( const QList<QString> keyList );
void clearKeys();

void setKeys( const merge::Merge* merge,
const model::Variables* variables );


/////////////////////////////////
Expand Down
92 changes: 61 additions & 31 deletions glabels/ColorHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,79 +46,109 @@ namespace glabels
}


void ColorHistory::addColor( const QColor &color )
void ColorHistory::addColor( const QColor &color, const QString& name )
{
QList<QColor> colorList = readColorList();
QString nameColor = name + ":" + color.name();

QStringList nameColorList = readNameColorList();

// Remove any occurrences of this color already in list
colorList.removeAll( color );
nameColorList.removeAll( nameColor );

// Now add to list
colorList.append( color );
nameColorList.append( nameColor );

// Remove oldest colors, if size exceeds current max
while ( colorList.size() > MAX_COLORS )
while ( nameColorList.size() > MAX_COLORS )
{
colorList.removeFirst();
nameColorList.removeFirst();
}

writeColorList( colorList );
writeNameColorList( nameColorList );

emit changed();
}


QList<QColor> ColorHistory::getColors()
{
return readColorList();
QList<QColor> colorList;

for ( QString& nameColor : readNameColorList() )
{
QStringList v = nameColor.split( ':' );
if ( v.size() == 2 )
{
colorList << QColor( v[1] );
}
else if ( v.size() == 1 )
{
// Old-style, no name
colorList << QColor( v[0] );
}
else
{
// Should not happen
qWarning() << "Invalid color history.";
}
}

return colorList;
}


QColor ColorHistory::getColor( int id )
QStringList ColorHistory::getNames()
{
QList<QColor> colors = readColorList();
return colors[id];
QStringList nameList;

for ( QString& nameColor : readNameColorList() )
{
QStringList v = nameColor.split( ':' );
if ( v.size() == 2 )
{
nameList << v[0];
}
else if ( v.size() == 1 )
{
// Old-style, no name
nameList << QString(tr("color %1")).arg( v[0] );
}
else
{
// Should not happen
qWarning() << "Invalid color history.";
}
}

return nameList;
}


QList<QColor> ColorHistory::readColorList()
QStringList ColorHistory::readNameColorList()
{
QStringList defaultList;
QSettings settings;

settings.beginGroup( "ColorHistory" );
QStringList colorNameList = settings.value( "colors", defaultList ).toStringList();
QStringList nameColorList = settings.value( "colors", defaultList ).toStringList();
settings.endGroup();

QList<QColor> colorList;
foreach ( QString colorName, colorNameList )
{
colorList << QColor( colorName );
}

// Remove oldest colors, if size exceeds current max
while ( colorList.size() > MAX_COLORS )
while ( nameColorList.size() > MAX_COLORS )
{
colorList.removeFirst();
nameColorList.removeFirst();
}

return colorList;
return nameColorList;
}


void ColorHistory::writeColorList( const QList<QColor>& colorList )
void ColorHistory::writeNameColorList( const QStringList& nameColorList )
{
// Build name list
QStringList colorNameList;
foreach ( QColor color, colorList )
{
colorNameList << color.name();
}

// Save
QSettings settings;
settings.beginGroup( "ColorHistory" );
settings.setValue( "colors", colorNameList );
settings.setValue( "colors", nameColorList );
settings.endGroup();
}

Expand Down
8 changes: 4 additions & 4 deletions glabels/ColorHistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ namespace glabels
// Public Methods
/////////////////////////////////
public:
void addColor( const QColor &color );
void addColor( const QColor& color, const QString& name );
QList<QColor> getColors();
QColor getColor( int id );
QStringList getNames();


/////////////////////////////////
// Private Methods
/////////////////////////////////
private:
QList<QColor> readColorList();
void writeColorList( const QList<QColor>& colorList );
QStringList readNameColorList();
void writeNameColorList( const QStringList& nameColorList );


/////////////////////////////////
Expand Down
Loading

0 comments on commit d9e6444

Please sign in to comment.