diff --git a/model/Model.cpp b/model/Model.cpp index 4fe8b34..07801b2 100644 --- a/model/Model.cpp +++ b/model/Model.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -280,6 +281,22 @@ namespace glabels } + /// + /// Get directory. + /// + QString Model::dir() const + { + if ( mFileName.isEmpty() ) + { + return QDir::currentPath(); + } + else + { + return QFileInfo( mFileName ).absolutePath(); + } + } + + /// /// Get short name. /// diff --git a/model/Model.h b/model/Model.h index cfd74c8..b1c5b33 100644 --- a/model/Model.h +++ b/model/Model.h @@ -91,6 +91,7 @@ namespace glabels void setModified(); void clearModified(); + QString dir() const; QString shortName(); const QString& fileName() const; void setFileName( const QString &fileName ); diff --git a/model/ModelImageObject.cpp b/model/ModelImageObject.cpp index 5124995..550de8c 100644 --- a/model/ModelImageObject.cpp +++ b/model/ModelImageObject.cpp @@ -20,9 +20,11 @@ #include "ModelImageObject.h" +#include "Model.h" #include "Size.h" #include +#include #include #include #include @@ -431,7 +433,12 @@ namespace glabels } else { - auto* image = new QImage( mFilenameNode.text( record, variables ) ); + // Look for image file relative to project file 1st then CWD 2nd + auto* model = dynamic_cast( parent() ); + QDir::setSearchPaths( "images", {model->dir(), QDir::currentPath()} ); + QString filename = QString("images:") + mFilenameNode.text( record, variables ); + + auto* image = new QImage( filename ); if ( !image->isNull() && image->hasAlphaChannel() && (image->depth() == 32) ) { QImage* shadowImage = createShadowImage( *image, shadowColor ); @@ -528,7 +535,12 @@ namespace glabels } else if ( mFilenameNode.isField() ) { - auto* image = new QImage( mFilenameNode.text( record, variables ) ); + // Look for image file relative to project file 1st then CWD 2nd + auto* model = dynamic_cast( parent() ); + QDir::setSearchPaths( "images", {model->dir(), QDir::currentPath()} ); + QString filename = QString("images:") + mFilenameNode.text( record, variables ); + + auto* image = new QImage( filename ); if ( !image->isNull() ) { painter->drawImage( destRect, *image ); diff --git a/model/ModelObject.h b/model/ModelObject.h index e7a6c2f..6acb538 100644 --- a/model/ModelObject.h +++ b/model/ModelObject.h @@ -407,7 +407,7 @@ namespace glabels void draw( QPainter* painter, bool inEditor, merge::Record* record, - Variables* variables ) const; + Variables* variables ) const; void drawSelectionHighlight( QPainter* painter, double scale ) const; diff --git a/model/XmlLabelCreator.cpp b/model/XmlLabelCreator.cpp index a546d14..90a1ced 100644 --- a/model/XmlLabelCreator.cpp +++ b/model/XmlLabelCreator.cpp @@ -496,8 +496,18 @@ namespace glabels XmlUtil::setStringAttr( node, "type", Variable::typeToIdString( v.type() ) ); XmlUtil::setStringAttr( node, "name", v.name() ); XmlUtil::setStringAttr( node, "initialValue", v.initialValue() ); - XmlUtil::setStringAttr( node, "increment", Variable::incrementToIdString( v.increment() ) ); - XmlUtil::setStringAttr( node, "stepSize", v.stepSize() ); + + if ( (v.type() == Variable::Type::INTEGER) || + (v.type() == Variable::Type::FLOATING_POINT) ) + { + XmlUtil::setStringAttr( node, "increment", + Variable::incrementToIdString( v.increment() ) ); + + if ( v.increment() != Variable::Increment::NEVER ) + { + XmlUtil::setStringAttr( node, "stepSize", v.stepSize() ); + } + } }