diff --git a/docs/TODO.md b/docs/TODO.md index 45562d9..4c72383 100644 --- a/docs/TODO.md +++ b/docs/TODO.md @@ -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 diff --git a/glabels-batch/main.cpp b/glabels-batch/main.cpp index 8240d02..b69afda 100644 --- a/glabels-batch/main.cpp +++ b/glabels-batch/main.cpp @@ -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 to " ), + QCoreApplication::translate( "main", "var>= 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") ) diff --git a/model/Variable.cpp b/model/Variable.cpp index fa96462..56f8b6a 100644 --- a/model/Variable.cpp +++ b/model/Variable.cpp @@ -88,6 +88,12 @@ namespace glabels } + void Variable::setInitialValue( const QString& value ) + { + mInitialValue = value; + } + + void Variable::resetValue() { switch (mType) diff --git a/model/Variable.h b/model/Variable.h index c18f74f..e0b8fe0 100644 --- a/model/Variable.h +++ b/model/Variable.h @@ -71,6 +71,8 @@ namespace glabels Increment increment() const; QString stepSize() const; + void setInitialValue( const QString& value ); + void resetValue(); void incrementValueOnItem(); void incrementValueOnCopy(); diff --git a/model/Variables.cpp b/model/Variables.cpp index 03fa927..4d16822 100644 --- a/model/Variables.cpp +++ b/model/Variables.cpp @@ -85,6 +85,27 @@ namespace glabels } + /// + /// Set initial value of multiple variables + /// + void Variables::setVariables( const QMap& 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 /// diff --git a/model/Variables.h b/model/Variables.h index 379d56f..b636f18 100644 --- a/model/Variables.h +++ b/model/Variables.h @@ -63,6 +63,8 @@ namespace glabels void deleteVariable( const QString& name ); void replaceVariable( const QString& name, const Variable& variable ); + void setVariables( const QMap& definitions ); + void resetVariables(); void incrementVariablesOnItem(); void incrementVariablesOnCopy();