Allow user variables to be set from glabels-batch command line (#75)

This commit is contained in:
Jim Evins
2019-10-12 21:57:04 -04:00
parent 1a900d0ebc
commit 7a02c0b226
6 changed files with 60 additions and 2 deletions
+6 -1
View File
@@ -1,6 +1,11 @@
To Do List for gLabels 4.0 -- 2018-10-06 To Do List for gLabels 4.0 -- 2019-10-07
======================================== ========================================
Expose user variables to glabels-batch
--------------------------------------
There should be a way to set initial values of user variables from the glabels-batch
command line. Possibly even create them on the fly.
Add programmable margin to text objects Add programmable margin to text objects
--------------------------------------- ---------------------------------------
The current built-in fixed margin seems to confuse people when dealing with The current built-in fixed margin seems to confuse people when dealing with
+23 -1
View File
@@ -121,7 +121,11 @@ int main( int argc, char **argv )
QCoreApplication::translate( "main", "Print crop marks." ) }, QCoreApplication::translate( "main", "Print crop marks." ) },
{{"r","reverse"}, {{"r","reverse"},
QCoreApplication::translate( "main", "Print in reverse (mirror image)." ) } QCoreApplication::translate( "main", "Print in reverse (mirror image)." ) },
{{"D","define"},
QCoreApplication::translate( "main", "Set user variable <var> to <value>" ),
QCoreApplication::translate( "main", "var>=<value" ) }
}; };
@@ -135,6 +139,22 @@ int main( int argc, char **argv )
"file" ); "file" );
parser.process( app ); parser.process( app );
//
// Parse variable definitions from command line, if any
//
QMap<QString,QString> variableDefinitions;
for ( QString definition : parser.values("define") )
{
QStringList parts = definition.split( '=' );
if ( parts.size() != 2 )
{
qWarning() << "Error: bad variable definition: " << definition;
return -1;
}
variableDefinitions[ parts[0] ] = parts[1];
}
// //
// Initialize subsystems // Initialize subsystems
@@ -152,6 +172,8 @@ int main( int argc, char **argv )
glabels::model::Model *model = glabels::model::XmlLabelParser::readFile( filename ); glabels::model::Model *model = glabels::model::XmlLabelParser::readFile( filename );
if ( model ) if ( model )
{ {
model->variables()->setVariables( variableDefinitions );
QPrinter printer( QPrinter::HighResolution ); QPrinter printer( QPrinter::HighResolution );
printer.setColorMode( QPrinter::Color ); printer.setColorMode( QPrinter::Color );
if ( parser.isSet("printer") ) if ( parser.isSet("printer") )
+6
View File
@@ -88,6 +88,12 @@ namespace glabels
} }
void Variable::setInitialValue( const QString& value )
{
mInitialValue = value;
}
void Variable::resetValue() void Variable::resetValue()
{ {
switch (mType) switch (mType)
+2
View File
@@ -71,6 +71,8 @@ namespace glabels
Increment increment() const; Increment increment() const;
QString stepSize() const; QString stepSize() const;
void setInitialValue( const QString& value );
void resetValue(); void resetValue();
void incrementValueOnItem(); void incrementValueOnItem();
void incrementValueOnCopy(); void incrementValueOnCopy();
+21
View File
@@ -85,6 +85,27 @@ namespace glabels
} }
///
/// Set initial value of multiple variables
///
void Variables::setVariables( const QMap<QString,QString>& definitions )
{
for ( auto& name : definitions.keys() )
{
if ( hasVariable( name ) )
{
(*this)[name].setInitialValue( definitions[name] );
}
else
{
addVariable( Variable( Variable::Type::STRING,
name,
definitions[name] ) );
}
}
}
/// ///
/// Reset variables to their initial values /// Reset variables to their initial values
/// ///
+2
View File
@@ -63,6 +63,8 @@ namespace glabels
void deleteVariable( const QString& name ); void deleteVariable( const QString& name );
void replaceVariable( const QString& name, const Variable& variable ); void replaceVariable( const QString& name, const Variable& variable );
void setVariables( const QMap<QString,QString>& definitions );
void resetVariables(); void resetVariables();
void incrementVariablesOnItem(); void incrementVariablesOnItem();
void incrementVariablesOnCopy(); void incrementVariablesOnCopy();