Allow user variables to be set from glabels-batch command line (#75)
This commit is contained in:
+6
-1
@@ -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
|
||||
---------------------------------------
|
||||
The current built-in fixed margin seems to confuse people when dealing with
|
||||
|
||||
+23
-1
@@ -121,7 +121,11 @@ int main( int argc, char **argv )
|
||||
QCoreApplication::translate( "main", "Print crop marks." ) },
|
||||
|
||||
{{"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" ) }
|
||||
};
|
||||
|
||||
|
||||
@@ -134,7 +138,23 @@ int main( int argc, char **argv )
|
||||
QCoreApplication::translate( "main", "gLabels project file to print." ),
|
||||
"file" );
|
||||
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
|
||||
@@ -152,6 +172,8 @@ int main( int argc, char **argv )
|
||||
glabels::model::Model *model = glabels::model::XmlLabelParser::readFile( filename );
|
||||
if ( model )
|
||||
{
|
||||
model->variables()->setVariables( variableDefinitions );
|
||||
|
||||
QPrinter printer( QPrinter::HighResolution );
|
||||
printer.setColorMode( QPrinter::Color );
|
||||
if ( parser.isSet("printer") )
|
||||
|
||||
@@ -88,6 +88,12 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
void Variable::setInitialValue( const QString& value )
|
||||
{
|
||||
mInitialValue = value;
|
||||
}
|
||||
|
||||
|
||||
void Variable::resetValue()
|
||||
{
|
||||
switch (mType)
|
||||
|
||||
@@ -71,6 +71,8 @@ namespace glabels
|
||||
Increment increment() const;
|
||||
QString stepSize() const;
|
||||
|
||||
void setInitialValue( const QString& value );
|
||||
|
||||
void resetValue();
|
||||
void incrementValueOnItem();
|
||||
void incrementValueOnCopy();
|
||||
|
||||
@@ -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
|
||||
///
|
||||
|
||||
@@ -63,6 +63,8 @@ namespace glabels
|
||||
void deleteVariable( const QString& name );
|
||||
void replaceVariable( const QString& name, const Variable& variable );
|
||||
|
||||
void setVariables( const QMap<QString,QString>& definitions );
|
||||
|
||||
void resetVariables();
|
||||
void incrementVariablesOnItem();
|
||||
void incrementVariablesOnCopy();
|
||||
|
||||
Reference in New Issue
Block a user