Look for image files from substitution fields relative to project file.

This commit is contained in:
Jim Evins
2019-08-04 23:32:50 -04:00
parent f41461ef26
commit 3fedb16c2c
5 changed files with 45 additions and 5 deletions
+17
View File
@@ -32,6 +32,7 @@
#include <QApplication> #include <QApplication>
#include <QClipboard> #include <QClipboard>
#include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QMimeData> #include <QMimeData>
#include <QtDebug> #include <QtDebug>
@@ -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. /// Get short name.
/// ///
+1
View File
@@ -91,6 +91,7 @@ namespace glabels
void setModified(); void setModified();
void clearModified(); void clearModified();
QString dir() const;
QString shortName(); QString shortName();
const QString& fileName() const; const QString& fileName() const;
void setFileName( const QString &fileName ); void setFileName( const QString &fileName );
+14 -2
View File
@@ -20,9 +20,11 @@
#include "ModelImageObject.h" #include "ModelImageObject.h"
#include "Model.h"
#include "Size.h" #include "Size.h"
#include <QBrush> #include <QBrush>
#include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QImage> #include <QImage>
#include <QPen> #include <QPen>
@@ -431,7 +433,12 @@ namespace glabels
} }
else 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<Model*>( 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) ) if ( !image->isNull() && image->hasAlphaChannel() && (image->depth() == 32) )
{ {
QImage* shadowImage = createShadowImage( *image, shadowColor ); QImage* shadowImage = createShadowImage( *image, shadowColor );
@@ -528,7 +535,12 @@ namespace glabels
} }
else if ( mFilenameNode.isField() ) 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<Model*>( parent() );
QDir::setSearchPaths( "images", {model->dir(), QDir::currentPath()} );
QString filename = QString("images:") + mFilenameNode.text( record, variables );
auto* image = new QImage( filename );
if ( !image->isNull() ) if ( !image->isNull() )
{ {
painter->drawImage( destRect, *image ); painter->drawImage( destRect, *image );
+1 -1
View File
@@ -407,7 +407,7 @@ namespace glabels
void draw( QPainter* painter, void draw( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, merge::Record* record,
Variables* variables ) const; Variables* variables ) const;
void drawSelectionHighlight( QPainter* painter, double scale ) const; void drawSelectionHighlight( QPainter* painter, double scale ) const;
+12 -2
View File
@@ -496,8 +496,18 @@ namespace glabels
XmlUtil::setStringAttr( node, "type", Variable::typeToIdString( v.type() ) ); XmlUtil::setStringAttr( node, "type", Variable::typeToIdString( v.type() ) );
XmlUtil::setStringAttr( node, "name", v.name() ); XmlUtil::setStringAttr( node, "name", v.name() );
XmlUtil::setStringAttr( node, "initialValue", v.initialValue() ); 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() );
}
}
} }