Pointer cleanup (#242)

- Made greater use of smart pointers, eliminating many instances of manual memory management
- Do not use pointers at all for many non-polymorphic classes
- Assorted other code cleanup
This commit is contained in:
Jaye Evins
2025-10-31 16:11:28 -04:00
committed by GitHub
parent fd10d88be5
commit 8c8e447336
159 changed files with 3364 additions and 4045 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ set (Model_sources
FramePath.cpp
FrameRect.cpp
FrameRound.cpp
Handles.cpp
Handle.cpp
Layout.cpp
Markup.cpp
Model.cpp
+2 -1
View File
@@ -27,7 +27,8 @@ namespace glabels
{
Category::Category( const QString &id, const QString &name )
: mId(id), mName(name)
: mId(id),
mName(name)
{
// empty
}
+2
View File
@@ -34,7 +34,9 @@ namespace glabels
{
public:
Category() = default;
Category( const QString& id, const QString& name );
~Category() = default;
QString id() const;
QString name() const;
+11 -12
View File
@@ -18,9 +18,8 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ColorNode.h"
#include "merge/Record.h"
#include "ColorNode.h"
namespace glabels
@@ -175,25 +174,25 @@ namespace glabels
///
/// Get color, expand if necessary
///
QColor ColorNode::color( const merge::Record* record,
const Variables* variables ) const
QColor ColorNode::color( const merge::Record& record,
const Variables& variables ) const
{
QColor value = QColor( 192, 192, 192, 128 );
bool haveRecordField = mIsField && record &&
record->contains(mKey) &&
!record->value(mKey).isEmpty();
bool haveVariable = mIsField && variables &&
variables->contains(mKey) &&
!(*variables)[mKey].value().isEmpty();
bool haveRecordField = mIsField &&
record.contains(mKey) &&
!record.value(mKey).isEmpty();
bool haveVariable = mIsField &&
variables.contains(mKey) &&
!variables[mKey].value().isEmpty();
if ( haveRecordField )
{
value = QColor( record->value(mKey) );
value = QColor( record.value(mKey) );
}
else if ( haveVariable )
{
value = QColor( (*variables)[mKey].value() );
value = QColor( variables[mKey].value() );
}
else if ( !mIsField )
{
+2 -2
View File
@@ -96,8 +96,8 @@ namespace glabels
/////////////////////////////////
public:
uint32_t rgba() const;
QColor color( const merge::Record* record,
const Variables* variables ) const;
QColor color( const merge::Record& record,
const Variables& variables ) const;
/////////////////////////////////
+4 -3
View File
@@ -43,13 +43,14 @@ namespace glabels
TextNode filenameNode = imageObject->filenameNode();
if ( !filenameNode.isField() )
{
if ( const QImage* image = imageObject->image() )
auto& image = imageObject->image();
if ( !image.isNull() )
{
addImage( filenameNode.data(), *image );
addImage( filenameNode.data(), image );
}
else
{
QByteArray svg = imageObject->svg();
auto& svg = imageObject->svg();
if ( !svg.isEmpty() )
{
addSvg( filenameNode.data(), svg );
+303 -331
View File
@@ -30,7 +30,7 @@
#include "XmlTemplateCreator.h"
#include "XmlVendorParser.h"
#include <QtDebug>
#include <QDebug>
#include <QtGlobal>
#include <algorithm>
@@ -48,9 +48,9 @@ namespace glabels
{
const QString empty = "";
bool partNameLessThan( const Template *a, const Template *b )
bool partNameLessThan( const Template& a, const Template& b )
{
return StrUtil::comparePartNames( a->name(), b->name() ) < 0;
return StrUtil::comparePartNames( a.name(), b.name() ) < 0;
}
}
@@ -58,18 +58,29 @@ namespace glabels
//
// Static data
//
QList<Paper*> Db::mPapers;
QStringList Db::mPaperIds;
QStringList Db::mPaperNames;
QList<Category*> Db::mCategories;
QStringList Db::mCategoryIds;
QStringList Db::mCategoryNames;
QList<Vendor*> Db::mVendors;
QStringList Db::mVendorNames;
QList<Template*> Db::mTemplates;
QList<Paper> Db::mPapers;
QMap<QString,Paper> Db::mPapersNameMap;
QMap<QString,Paper> Db::mPapersIdMap;
QStringList Db::mPaperIds;
QStringList Db::mPaperNames;
QList<Category> Db::mCategories;
QMap<QString,Category> Db::mCategoriesNameMap;
QMap<QString,Category> Db::mCategoriesIdMap;
QStringList Db::mCategoryIds;
QStringList Db::mCategoryNames;
QList<Vendor> Db::mVendors;
QMap<QString,Vendor> Db::mVendorsNameMap;
QStringList Db::mVendorNames;
QList<Template> Db::mTemplates;
QMap<QString,Template> Db::mTemplatesNameMap;
QMap<QString,Template> Db::mUserTemplatesNameMap;
Db::Db()
void Db::init()
{
readPapers();
readCategories();
@@ -77,21 +88,8 @@ namespace glabels
readTemplates();
}
void Db::init()
{
instance();
}
Db* Db::instance()
{
static auto* db = new Db();
return db;
}
const QList<Paper*>& Db::papers()
const QList<Paper>& Db::papers()
{
return mPapers;
}
@@ -109,7 +107,7 @@ namespace glabels
}
const QList<Category*>& Db::categories()
const QList<Category>& Db::categories()
{
return mCategories;
}
@@ -127,7 +125,7 @@ namespace glabels
}
const QList<Vendor*>& Db::vendors()
const QList<Vendor>& Db::vendors()
{
return mVendors;
}
@@ -139,383 +137,251 @@ namespace glabels
}
const QList<Template*>& Db::templates()
QList<Template> Db::templates()
{
return mTemplates;
auto list = mTemplates;
list.append( mUserTemplatesNameMap.values() );
std::stable_sort( list.begin(), list.end(), partNameLessThan );
return list;
}
void Db::registerPaper( Paper *paper )
const Paper Db::lookupPaperFromName( const QString& name )
{
if ( !isPaperIdKnown( paper->id() ) )
{
mPapers << paper;
mPaperIds << paper->id();
mPaperNames << paper->name();
}
else
{
qWarning() << "Duplicate paper ID: " << paper->id();
}
}
const Paper *Db::lookupPaperFromName( const QString& name )
{
if ( name.isNull() || name.isEmpty() )
if ( name.isEmpty() )
{
qWarning() << "NULL paper name.";
return mPapers.first();
return Paper();
}
foreach ( Paper *paper, mPapers )
auto it = mPapersNameMap.find( name );
if ( it != mPapersNameMap.end() )
{
if ( paper->name() == name )
{
return paper;
}
return *it;
}
qWarning() << "Unknown paper name: " << name;
return nullptr;
return Paper();
}
const Paper *Db::lookupPaperFromId( const QString& id )
const Paper Db::lookupPaperFromId( const QString& id )
{
if ( id.isNull() || id.isEmpty() )
if ( id.isEmpty() )
{
qWarning() << "NULL paper ID.";
return mPapers.first();
qWarning() << "NULL paper id.";
return Paper();
}
foreach ( Paper *paper, mPapers )
auto it = mPapersIdMap.find( id );
if ( it != mPapersIdMap.end() )
{
if ( paper->id() == id )
{
return paper;
}
return *it;
}
qWarning() << "Unknown paper ID: " << id;
return nullptr;
return Paper();
}
QString Db::lookupPaperIdFromName( const QString& name )
{
if ( !name.isNull() && !name.isEmpty() )
{
if ( name == tr("Other") )
{
return "other";
}
else if ( name == tr("Roll") )
{
return "roll";
}
const Paper *paper = lookupPaperFromName( name );
if ( paper != nullptr )
{
return paper->id();
}
}
qWarning() << "Unknown paper name: " << name;
return empty;
return lookupPaperFromName( name ).id();
}
QString Db::lookupPaperNameFromId( const QString& id )
{
if ( !id.isNull() && !id.isEmpty() )
{
if ( id == "other" )
{
return tr("Other");
}
else if ( id == "roll" )
{
return tr("Roll");
}
const Paper *paper = lookupPaperFromId( id );
if ( paper != nullptr )
{
return paper->name();
}
}
qWarning() << "Unknown paper id: " << id;
return empty;
return lookupPaperFromId( id ).name();
}
bool Db::isPaperIdKnown( const QString& id )
{
foreach ( Paper *paper, mPapers )
{
if ( paper->id() == id )
{
return true;
}
}
return false;
return mPapersIdMap.contains( id );
}
void Db::registerCategory( Category *category )
const Category Db::lookupCategoryFromName( const QString& name )
{
if ( !isCategoryIdKnown( category->id() ) )
{
mCategories << category;
mCategoryIds << category->id();
mCategoryNames << category->name();
}
else
{
qWarning() << "Duplicate category ID: " << category->id();
}
}
const Category *Db::lookupCategoryFromName( const QString& name )
{
if ( name.isNull() || name.isEmpty() )
if ( name.isEmpty() )
{
qWarning() << "NULL category name.";
return mCategories.first();
return Category();
}
foreach ( Category *category, mCategories )
auto it = mCategoriesNameMap.find( name );
if ( it != mCategoriesNameMap.end() )
{
if ( category->name() == name )
{
return category;
}
return *it;
}
qWarning() << "Unknown category name: \"%s\"." << name;
return nullptr;
return Category();
}
const Category *Db::lookupCategoryFromId( const QString& id )
const Category Db::lookupCategoryFromId( const QString& id )
{
if ( id.isNull() || id.isEmpty() )
if ( id.isEmpty() )
{
qDebug() << "NULL category ID.";
return mCategories.first();
qWarning() << "NULL category id.";
return Category();
}
foreach ( Category *category, mCategories )
auto it = mCategoriesIdMap.find( id );
if ( it != mCategoriesIdMap.end() )
{
if ( category->id() == id )
{
return category;
}
return *it;
}
qWarning() << "Unknown category ID: " << id;
return nullptr;
qWarning() << "Unknown category ID: \"%s\"." << id;
return Category();
}
QString Db::lookupCategoryIdFromName( const QString& name )
{
if ( !name.isNull() && !name.isEmpty() )
{
const Category *category = lookupCategoryFromName( name );
if ( category != nullptr )
{
return category->id();
}
}
qWarning() << "Unknown category name: " << name;
return empty;
return lookupCategoryFromName( name ).id();
}
QString Db::lookupCategoryNameFromId( const QString& id )
{
if ( !id.isNull() && !id.isEmpty() )
{
const Category *category = lookupCategoryFromId( id );
if ( category != nullptr )
{
return category->name();
}
}
qWarning() << "Unknown category id: " << id;
return empty;
return lookupCategoryFromId( id ).name();
}
bool Db::isCategoryIdKnown( const QString& id )
{
foreach ( Category *category, mCategories )
{
if ( category->id() == id )
{
return true;
}
}
return false;
return mCategoriesIdMap.contains( id );
}
void Db::registerVendor( Vendor *vendor )
const Vendor Db::lookupVendorFromName( const QString& name )
{
if ( !isVendorNameKnown( vendor->name() ) )
{
mVendors << vendor;
mVendorNames << vendor->name();
}
else
{
qWarning() << "Duplicate vendor name: " << vendor->name();
}
}
const Vendor *Db::lookupVendorFromName( const QString& name )
{
if ( name.isNull() || name.isEmpty() )
if ( name.isEmpty() )
{
qWarning() << "NULL vendor name.";
return mVendors.first();
return Vendor();
}
foreach ( Vendor *vendor, mVendors )
auto it = mVendorsNameMap.find( name );
if ( it != mVendorsNameMap.end() )
{
if ( vendor->name() == name )
{
return vendor;
}
return *it;
}
qWarning() << "Unknown vendor name: " << name;
return nullptr;
return Vendor();
}
QString Db::lookupVendorUrlFromName( const QString& name )
{
if ( !name.isNull() && !name.isEmpty() )
{
const Vendor *vendor = lookupVendorFromName( name );
if ( vendor != nullptr )
{
return vendor->url();
}
}
qWarning() << "Unknown vendor name: " << name;
return empty;
return lookupVendorFromName( name ).url();
}
bool Db::isVendorNameKnown( const QString& name )
{
foreach ( Vendor *vendor, mVendors )
{
if ( vendor->name() == name )
{
return true;
}
}
return false;
return mVendorsNameMap.contains( name );
}
void Db::registerTemplate( Template *tmplate )
const Template Db::lookupTemplateFromName( const QString& name )
{
if ( !isTemplateKnown( tmplate->brand(), tmplate->part() ) )
{
mTemplates << tmplate;
}
else
{
qWarning() << "Duplicate template name: " << tmplate->name();
}
}
const Template *Db::lookupTemplateFromName( const QString& name )
{
if ( name.isNull() || name.isEmpty() )
if ( name.isEmpty() )
{
qWarning() << "NULL template name.";
return mTemplates.first();
return Template();
}
foreach ( Template *tmplate, mTemplates )
auto it = mTemplatesNameMap.find( name );
if ( it != mTemplatesNameMap.end() )
{
if ( tmplate->name() == name )
{
return tmplate;
}
return *it;
}
auto it2 = mUserTemplatesNameMap.find( name );
if ( it2 != mUserTemplatesNameMap.end() )
{
return *it2;
}
qWarning() << "Unknown template name: " << name;
return nullptr;
return Template();
}
const Template *Db::lookupTemplateFromBrandPart( const QString& brand, const QString& part )
const Template Db::lookupTemplateFromBrandPart( const QString& brand, const QString& part )
{
if ( brand.isNull() || brand.isEmpty() || part.isNull() || part.isEmpty() )
if ( brand.isEmpty() || part.isEmpty() )
{
qWarning() << "NULL template brand and/or part.";
return mTemplates.first();
return Template();
}
foreach ( Template *tmplate, mTemplates )
auto name = Template::brandPartToName( brand, part );
auto it = mTemplatesNameMap.find( name );
if ( it != mTemplatesNameMap.end() )
{
if ( (tmplate->brand() == brand) && (tmplate->part() == part) )
{
return tmplate;
}
return *it;
}
auto it2 = mUserTemplatesNameMap.find( name );
if ( it2 != mUserTemplatesNameMap.end() )
{
return *it2;
}
qWarning() << "Unknown template brand, part: " << brand << ", " << part;
return nullptr;
return Template();
}
const Template Db::lookupUserTemplateFromBrandPart( const QString& brand, const QString& part )
{
if ( brand.isEmpty() || part.isEmpty() )
{
qWarning() << "NULL template brand and/or part.";
return Template();
}
auto name = Template::brandPartToName( brand, part );
auto it = mUserTemplatesNameMap.find( name );
if ( it != mUserTemplatesNameMap.end() )
{
return *it;
}
qWarning() << "Unknown user template brand, part: " << brand << ", " << part;
return Template();
}
bool Db::isTemplateKnown( const QString& brand, const QString& part )
{
foreach ( Template *tmplate, mTemplates )
{
if ( (tmplate->brand() == brand) && (tmplate->part() == part) )
{
return true;
}
}
return false;
auto name = Template::brandPartToName( brand, part );
return mTemplatesNameMap.contains( name ) || mUserTemplatesNameMap.contains( name );
}
bool Db::isSystemTemplateKnown( const QString& brand, const QString& part )
{
foreach ( Template *tmplate, mTemplates )
{
if ( (tmplate->brand() == brand) &&
(tmplate->part() == part) &&
!tmplate->isUserDefined() )
{
return true;
}
}
auto name = Template::brandPartToName( brand, part );
return mTemplatesNameMap.contains( name );
}
return false;
bool Db::isUserTemplateKnown( const QString& brand, const QString& part )
{
auto name = Template::brandPartToName( brand, part );
return mUserTemplatesNameMap.contains( name );
}
@@ -523,20 +389,20 @@ namespace glabels
{
QStringList list;
const Template *tmplate1 = lookupTemplateFromName( name );
if ( tmplate1 == nullptr )
auto tmplate1 = lookupTemplateFromName( name );
if ( tmplate1.isNull() )
{
qWarning() << "Unknown template name: " << name;
return list;
}
foreach (const Template *tmplate2, mTemplates )
for ( auto& tmplate2 : templates() )
{
if ( tmplate1->name() != tmplate2->name() )
if ( tmplate1.name() != tmplate2.name() )
{
if ( tmplate1->isSimilarTo( tmplate2 ) )
if ( tmplate1.isSimilarTo( tmplate2 ) )
{
list << tmplate2->name();
list << tmplate2.name();
}
}
}
@@ -545,51 +411,53 @@ namespace glabels
}
QString Db::userTemplateFilename( const QString& brand, const QString& part )
QString Db::userTemplateFileName( const QString& brand, const QString& part )
{
QString filename = brand + "_" + part + ".template";
return FileUtil::userTemplatesDir().filePath( filename );
QString fileName = brand + "_" + part + ".template";
return FileUtil::userTemplatesDir().filePath( fileName );
}
void Db::registerUserTemplate( Template *tmplate )
void Db::registerUserTemplate( const Template& tmplate )
{
QString filename = userTemplateFilename( tmplate->brand(), tmplate->part() );
if ( isTemplateKnown( tmplate.brand(), tmplate.part() ) )
{
qWarning() << "Duplicate template name: " << tmplate.name();
return;
}
QString fileName = userTemplateFileName( tmplate.brand(), tmplate.part() );
// Write file
if ( XmlTemplateCreator().writeTemplate( tmplate, filename ) )
if ( XmlTemplateCreator().writeTemplate( tmplate, fileName ) )
{
// Add template to list of registered templates
registerTemplate( tmplate );
Settings::addToRecentTemplateList( tmplate->name() );
mUserTemplatesNameMap[ tmplate.name() ] = tmplate;
mUserTemplatesNameMap[ tmplate.name() ].setFileName( fileName );
mUserTemplatesNameMap[ tmplate.name() ].setIsUserDefined( true );
Settings::addToRecentTemplateList( tmplate.name() );
}
else
{
qWarning() << "Problem writing user template" << filename;
qWarning() << "Problem writing user template" << fileName;
}
}
void Db::deleteUserTemplateByBrandPart( const QString& brand, const QString& part )
{
Template* tmplate;
foreach ( Template *candidate, mTemplates )
auto tmplate = lookupUserTemplateFromBrandPart( brand, part );
if ( !tmplate.isNull() && tmplate.isUserDefined() )
{
if ( candidate->isUserDefined() &&
(candidate->brand() == brand) && (candidate->part() == part) )
{
tmplate = candidate;
break;
}
mUserTemplatesNameMap.remove( Template::brandPartToName( brand, part ) );
QFile( tmplate.fileName() ).remove();
}
if ( tmplate )
else
{
mTemplates.removeOne( tmplate );
delete tmplate;
QString filename = userTemplateFilename( brand, part );
QFile( filename ).remove();
qWarning() << "Not a user defined template:" << tmplate.name();
}
}
@@ -598,14 +466,14 @@ namespace glabels
{
qDebug() << "KNOWN PAPERS:";
foreach ( Paper *paper, mPapers )
for ( auto& paper : mPapers )
{
qDebug() << "paper "
<< "id=" << paper->id() << ", "
<< "name=" << paper->name() << ", "
<< "width=" << paper->width().pt() << "pts, "
<< "height=" << paper->height().pt() << "pts, "
<< "pwg_size=" << paper->pwgSize();
<< "id=" << paper.id() << ", "
<< "name=" << paper.name() << ", "
<< "width=" << paper.width().pt() << "pts, "
<< "height=" << paper.height().pt() << "pts, "
<< "pwg_size=" << paper.pwgSize();
}
qDebug();
@@ -616,11 +484,11 @@ namespace glabels
{
qDebug() << "KNOWN CATEGORIES:";
foreach ( Category *category, mCategories )
for ( auto& category : mCategories )
{
qDebug() << "category "
<< "id=" << category->id() << ", "
<< "name=" << category->name();
<< "id=" << category.id() << ", "
<< "name=" << category.name();
}
qDebug();
@@ -631,11 +499,11 @@ namespace glabels
{
qDebug() << "KNOWN VENDORS:";
foreach ( Vendor *vendor, mVendors )
for ( auto& vendor : mVendors )
{
qDebug() << "vendor "
<< "name='" << vendor->name() << ", "
<< "url='" << vendor->url();
<< "name='" << vendor.name() << ", "
<< "url='" << vendor.url();
}
qDebug();
@@ -646,12 +514,12 @@ namespace glabels
{
qDebug() << "KNOWN TEMPLATES:";
foreach ( Template *tmplate, mTemplates )
for ( auto& tmplate : mTemplates )
{
qDebug() << "template "
<< "brand=" << tmplate->brand() << ", "
<< "part=" << tmplate->part() << ", "
<< "description=" << tmplate->description();
<< "brand=" << tmplate.brand() << ", "
<< "part=" << tmplate.part() << ", "
<< "description=" << tmplate.description();
}
qDebug();
@@ -668,16 +536,37 @@ namespace glabels
{
XmlPaperParser parser;
foreach ( QString fileName, dir.entryList( QDir::Files ) )
for ( auto fileName : dir.entryList( QDir::Files ) )
{
if ( fileName == "paper-sizes.xml" )
{
parser.readFile( dir.absoluteFilePath( fileName ) );
auto list = parser.readFile( dir.absoluteFilePath( fileName ) );
for ( auto& paper : list )
{
registerPaper( paper );
}
}
}
}
void Db::registerPaper( const Paper& paper )
{
if ( !isPaperIdKnown( paper.id() ) )
{
mPapers.push_back( paper );
mPapersNameMap[ paper.name() ] = paper;
mPapersIdMap[ paper.id() ] = paper;
mPaperIds.push_back( paper.id() );
mPaperNames.push_back( paper.name() );
}
else
{
qWarning() << "Duplicate paper ID: " << paper.id();
}
}
void Db::readCategories()
{
readCategoriesFromDir( FileUtil::systemTemplatesDir() );
@@ -688,16 +577,37 @@ namespace glabels
{
XmlCategoryParser parser;
foreach ( QString fileName, dir.entryList( QDir::Files ) )
for ( auto fileName : dir.entryList( QDir::Files ) )
{
if ( fileName == "categories.xml" )
{
parser.readFile( dir.absoluteFilePath( fileName ) );
auto list = parser.readFile( dir.absoluteFilePath( fileName ) );
for ( auto& category : list )
{
registerCategory( category );
}
}
}
}
void Db::registerCategory( const Category& category )
{
if ( !isCategoryIdKnown( category.id() ) )
{
mCategories.push_back( category );
mCategoriesNameMap[ category.name() ] = category;
mCategoriesIdMap[ category.id() ] = category;
mCategoryIds.push_back( category.id() );
mCategoryNames.push_back( category.name() );
}
else
{
qWarning() << "Duplicate category ID: " << category.id();
}
}
void Db::readVendors()
{
readVendorsFromDir( FileUtil::systemTemplatesDir() );
@@ -708,36 +618,98 @@ namespace glabels
{
XmlVendorParser parser;
foreach ( QString fileName, dir.entryList( QDir::Files ) )
for ( auto fileName : dir.entryList( QDir::Files ) )
{
if ( fileName == "vendors.xml" )
{
parser.readFile( dir.absoluteFilePath( fileName ) );
auto list = parser.readFile( dir.absoluteFilePath( fileName ) );
for ( auto& vendor : list )
{
registerVendor( vendor );
}
}
}
}
void Db::registerVendor( const Vendor& vendor )
{
if ( !isVendorNameKnown( vendor.name() ) )
{
mVendors.push_back( vendor );
mVendorsNameMap[ vendor.name() ] = vendor;
mVendorNames.push_back( vendor.name() );
}
else
{
qWarning() << "Duplicate vendor name: " << vendor.name();
}
}
void Db::readTemplates()
{
readTemplatesFromDir( FileUtil::systemTemplatesDir(), false );
readTemplatesFromDir( FileUtil::manualUserTemplatesDir(), false );
readTemplatesFromDir( FileUtil::userTemplatesDir(), true );
readTemplatesFromDir( FileUtil::systemTemplatesDir() );
readTemplatesFromDir( FileUtil::manualUserTemplatesDir() );
std::stable_sort( mTemplates.begin(), mTemplates.end(), partNameLessThan );
readUserTemplatesFromDir( FileUtil::userTemplatesDir() );
}
void Db::readTemplatesFromDir( const QDir& dir, bool isUserDefined )
void Db::readTemplatesFromDir( const QDir& dir )
{
QStringList filters;
filters << "*-templates.xml" << "*.template";
XmlTemplateParser parser;
foreach ( QString fileName, dir.entryList( filters, QDir::Files ) )
for ( auto& fileName : dir.entryList( filters, QDir::Files ) )
{
parser.readFile( dir.absoluteFilePath( fileName ), isUserDefined );
auto list = parser.readFile( dir.absoluteFilePath( fileName ) );
for ( auto& tmplate : list )
{
registerTemplate( tmplate );
}
list = parser.readEquivsFromFile( dir.absoluteFilePath( fileName ) );
for ( auto& tmplate : list )
{
registerTemplate( tmplate );
}
}
}
void Db::registerTemplate( const Template& tmplate )
{
if ( !isTemplateKnown( tmplate.brand(), tmplate.part() ) )
{
mTemplates.push_back( tmplate );
mTemplatesNameMap[ tmplate.name() ] = tmplate;
}
else
{
qWarning() << "Duplicate template name: " << tmplate.name();
}
}
void Db::readUserTemplatesFromDir( const QDir& dir )
{
QStringList filters;
filters << "*-templates.xml" << "*.template";
XmlTemplateParser parser;
for ( auto& fileName : dir.entryList( filters, QDir::Files ) )
{
auto list = parser.readFile( dir.absoluteFilePath( fileName ) );
for ( auto& tmplate : list )
{
registerUserTemplate( tmplate );
}
}
}
+43 -35
View File
@@ -27,7 +27,6 @@
#include "Template.h"
#include "Vendor.h"
#include <QCoreApplication>
#include <QDir>
#include <QList>
#include <QString>
@@ -40,60 +39,55 @@ namespace glabels
class Db
{
Q_DECLARE_TR_FUNCTIONS(Db)
private:
Db();
public:
Db() = delete;
static void init();
static Db* instance();
static const QList<Paper*>& papers();
static const QList<Paper>& papers();
static const QStringList& paperIds();
static const QStringList& paperNames();
static const QList<Category*>& categories();
static const QList<Category>& categories();
static const QStringList& categoryIds();
static const QStringList& categoryNames();
static const QList<Vendor*>& vendors();
static const QList<Vendor>& vendors();
static const QStringList& vendorNames();
static const QList<Template*>& templates();
static QList<Template> templates();
static void registerPaper( Paper *paper );
static const Paper *lookupPaperFromName( const QString& name );
static const Paper *lookupPaperFromId( const QString& id );
static const Paper lookupPaperFromName( const QString& name );
static const Paper lookupPaperFromId( const QString& id );
static QString lookupPaperIdFromName( const QString& name );
static QString lookupPaperNameFromId( const QString& id );
static bool isPaperIdKnown( const QString& id );
static void registerCategory( Category *category );
static const Category *lookupCategoryFromName( const QString& name );
static const Category *lookupCategoryFromId( const QString& id );
static const Category lookupCategoryFromName( const QString& name );
static const Category lookupCategoryFromId( const QString& id );
static QString lookupCategoryIdFromName( const QString& name );
static QString lookupCategoryNameFromId( const QString& id );
static bool isCategoryIdKnown( const QString& id );
static void registerVendor( Vendor *vendor );
static const Vendor *lookupVendorFromName( const QString& name );
static const Vendor lookupVendorFromName( const QString& name );
static QString lookupVendorUrlFromName( const QString& name );
static bool isVendorNameKnown( const QString& id );
static void registerTemplate( Template *tmplate );
static const Template *lookupTemplateFromName( const QString& name );
static const Template *lookupTemplateFromBrandPart( const QString& brand,
const QString& part );
static const Template lookupTemplateFromName( const QString& name );
static const Template lookupTemplateFromBrandPart( const QString& brand,
const QString& part );
static const Template lookupUserTemplateFromBrandPart( const QString& brand,
const QString& part );
static bool isTemplateKnown( const QString& brand, const QString& part );
static bool isSystemTemplateKnown( const QString& brand, const QString& part );
static bool isUserTemplateKnown( const QString& brand, const QString& part );
static QStringList getNameListOfSimilarTemplates( const QString& name );
static QString userTemplateFilename( const QString& brand, const QString& part );
static void registerUserTemplate( Template *tmplate );
static QString userTemplateFileName( const QString& brand, const QString& part );
static void registerUserTemplate( const Template &tmplate );
static void deleteUserTemplateByBrandPart( const QString& brand,
const QString& part );
@@ -108,30 +102,44 @@ namespace glabels
static void readPapers();
static void readPapersFromDir( const QDir& dir );
static void registerPaper( const Paper& paper );
static void readCategories();
static void readCategoriesFromDir( const QDir& dir );
static void registerCategory( const Category& category );
static void readVendors();
static void readVendorsFromDir( const QDir& dir );
static void registerVendor( const Vendor& vendor );
static void readTemplates();
static void readTemplatesFromDir( const QDir& dir, bool isUserDefined );
static void readTemplatesFromDir( const QDir& dir );
static void registerTemplate( const Template& tmplate );
static void readUserTemplatesFromDir( const QDir& dir );
private:
static QList<Paper*> mPapers;
static QStringList mPaperIds;
static QStringList mPaperNames;
static QList<Paper> mPapers;
static QMap<QString,Paper> mPapersNameMap;
static QMap<QString,Paper> mPapersIdMap;
static QStringList mPaperIds;
static QStringList mPaperNames;
static QList<Category*> mCategories;
static QStringList mCategoryIds;
static QStringList mCategoryNames;
static QList<Category> mCategories;
static QMap<QString,Category> mCategoriesNameMap;
static QMap<QString,Category> mCategoriesIdMap;
static QStringList mCategoryIds;
static QStringList mCategoryNames;
static QList<Vendor*> mVendors;
static QStringList mVendorNames;
static QList<Vendor> mVendors;
static QMap<QString,Vendor> mVendorsNameMap;
static QStringList mVendorNames;
static QList<Template*> mTemplates;
static QList<Template> mTemplates;
static QMap<QString,Template> mTemplatesNameMap;
static QMap<QString,Template> mUserTemplatesNameMap;
};
+4 -4
View File
@@ -56,7 +56,7 @@ namespace glabels
}
Distance::Distance( double d, const Units& units )
Distance::Distance( double d, Units units )
{
switch (units.toEnum())
{
@@ -128,7 +128,7 @@ namespace glabels
}
double Distance::inUnits( const Units& units ) const
double Distance::inUnits( Units units ) const
{
double d;
@@ -188,7 +188,7 @@ namespace glabels
}
QString Distance::toString( const Units& units ) const
QString Distance::toString( Units units ) const
{
return QString::number( inUnits(units) ) + units.toIdString();
}
@@ -211,7 +211,7 @@ namespace glabels
}
QDebug operator<<( QDebug dbg, const glabels::model::Distance& distance )
QDebug operator<<( QDebug dbg, glabels::model::Distance distance )
{
QDebugStateSaver saver(dbg);
+40 -40
View File
@@ -41,7 +41,7 @@ namespace glabels
public:
Distance();
Distance( double d, Units::Enum unitsEnum = Units::PT );
Distance( double d, const Units& units );
Distance( double d, Units units );
Distance( double d, const QString& unitsId );
static Distance pt( double dPts );
@@ -57,38 +57,38 @@ namespace glabels
double mm() const;
double cm() const;
double pc() const;
double inUnits( const Units& units ) const;
double inUnits( Units units ) const;
double inUnits( Units::Enum unitsEnum ) const;
double inUnits( const QString& unitsId ) const;
QString toString( const Units& units ) const;
QString toString( Units units ) const;
QString toString( Units::Enum unitsEnum ) const;
QString toString( const QString& unitsId ) const;
Distance& operator+=( const Distance& d );
Distance& operator-=( const Distance& d );
Distance& operator+=( Distance d );
Distance& operator-=( Distance d );
Distance& operator*=( double f );
Distance operator-();
friend inline Distance operator+( const Distance& d1, const Distance& d2 );
friend inline Distance operator-( const Distance& d1, const Distance& d2 );
friend inline Distance operator*( double x, const Distance& d );
friend inline Distance operator*( const Distance& d, double x );
friend inline double operator/( const Distance& d1, const Distance& d2 );
friend inline Distance operator/( const Distance& d, double x );
friend inline Distance operator+( Distance d1, Distance d2 );
friend inline Distance operator-( Distance d1, Distance d2 );
friend inline Distance operator*( double x, Distance d );
friend inline Distance operator*( Distance d, double x );
friend inline double operator/( Distance d1, Distance d2 );
friend inline Distance operator/( Distance d, double x );
friend inline bool operator<( const Distance& d1, const Distance& d2 );
friend inline bool operator<=( const Distance& d1, const Distance& d2 );
friend inline bool operator>( const Distance& d1, const Distance& d2 );
friend inline bool operator>=( const Distance& d1, const Distance& d2 );
friend inline bool operator==( const Distance& d1, const Distance& d2 );
friend inline bool operator!=( const Distance& d1, const Distance& d2 );
friend inline bool operator<( Distance d1, Distance d2 );
friend inline bool operator<=( Distance d1, Distance d2 );
friend inline bool operator>( Distance d1, Distance d2 );
friend inline bool operator>=( Distance d1, Distance d2 );
friend inline bool operator==( Distance d1, Distance d2 );
friend inline bool operator!=( Distance d1, Distance d2 );
friend inline Distance fabs( const Distance& d );
friend inline Distance min( const Distance& d1, const Distance& d2 );
friend inline Distance max( const Distance& d1, const Distance& d2 );
friend inline Distance fmod( const Distance& d1, const Distance& d2 );
friend inline Distance fabs( Distance d );
friend inline Distance min( Distance d1, Distance d2 );
friend inline Distance max( Distance d1, Distance d2 );
friend inline Distance fmod( Distance d1, Distance d2 );
private:
@@ -101,7 +101,7 @@ namespace glabels
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::Distance& distance );
QDebug operator<<( QDebug dbg, const glabels::model::Distance distance );
//
@@ -190,14 +190,14 @@ namespace glabels
}
inline Distance& Distance::operator+=( const Distance& d )
inline Distance& Distance::operator+=( Distance d )
{
mDPts += d.mDPts;
return *this;
}
inline Distance& Distance::operator-=( const Distance& d )
inline Distance& Distance::operator-=( Distance d )
{
mDPts -= d.mDPts;
return *this;
@@ -217,97 +217,97 @@ namespace glabels
}
inline Distance operator+( const Distance& d1, const Distance& d2 )
inline Distance operator+( Distance d1, Distance d2 )
{
return Distance::pt( d1.mDPts + d2.mDPts );
}
inline Distance operator-( const Distance& d1, const Distance& d2 )
inline Distance operator-( Distance d1, Distance d2 )
{
return Distance::pt( d1.mDPts - d2.mDPts );
}
inline Distance operator*( double x, const Distance& d )
inline Distance operator*( double x, Distance d )
{
return Distance::pt( x * d.mDPts );
}
inline Distance operator*( const Distance& d, double x )
inline Distance operator*( Distance d, double x )
{
return Distance::pt( d.mDPts * x );
}
inline double operator/( const Distance& d1, const Distance& d2 )
inline double operator/( Distance d1, Distance d2 )
{
return d1.mDPts / d2.mDPts;
}
inline Distance operator/( const Distance& d, double x )
inline Distance operator/( Distance d, double x )
{
return Distance::pt( d.mDPts / x );
}
inline bool operator<( const Distance& d1, const Distance& d2 )
inline bool operator<( Distance d1, Distance d2 )
{
return d1.mDPts < d2.mDPts;
}
inline bool operator<=( const Distance& d1, const Distance& d2 )
inline bool operator<=( Distance d1, Distance d2 )
{
return d1.mDPts <= d2.mDPts;
}
inline bool operator>( const Distance& d1, const Distance& d2 )
inline bool operator>( Distance d1, Distance d2 )
{
return d1.mDPts > d2.mDPts;
}
inline bool operator>=( const Distance& d1, const Distance& d2 )
inline bool operator>=( Distance d1, Distance d2 )
{
return d1.mDPts >= d2.mDPts;
}
inline bool operator==( const Distance& d1, const Distance& d2 )
inline bool operator==( Distance d1, Distance d2 )
{
return d1.mDPts == d2.mDPts;
}
inline bool operator!=( const Distance& d1, const Distance& d2 )
inline bool operator!=( Distance d1, Distance d2 )
{
return d1.mDPts != d2.mDPts;
}
inline Distance fabs( const Distance& d )
inline Distance fabs( Distance d )
{
return Distance::pt( qFabs( d.mDPts ) );
}
inline Distance min( const Distance& d1, const Distance& d2 )
inline Distance min( Distance d1, Distance d2 )
{
return (d1.mDPts < d2.mDPts) ? d1 : d2;
}
inline Distance max( const Distance& d1, const Distance& d2 )
inline Distance max( Distance d1, Distance d2 )
{
return (d1.mDPts > d2.mDPts) ? d1 : d2;
}
inline Distance fmod( const Distance& d1, const Distance& d2 )
inline Distance fmod( Distance d1, Distance d2 )
{
return Distance::pt( std::fmod( d1.mDPts, d2.mDPts ) );
}
+20 -63
View File
@@ -18,15 +18,11 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Frame.h"
#include "FrameCd.h"
#include "FrameContinuous.h"
#include "FrameEllipse.h"
#include "FramePath.h"
#include "FrameRect.h"
#include "FrameRound.h"
#include "Markup.h"
#include <QDebug>
#include <algorithm>
@@ -37,7 +33,9 @@ namespace glabels
{
Frame::Frame( const QString& id )
: mId(id), mNLabels(0), mLayoutDescription("")
: mId(id),
mNLabels(0),
mLayoutDescription("")
{
// empty
}
@@ -48,23 +46,14 @@ namespace glabels
mId = other.mId;
mNLabels = 0;
foreach ( const Layout& layout, other.mLayouts )
for ( const auto& layout : other.mLayouts )
{
addLayout( layout );
}
foreach ( Markup *markup, other.mMarkups )
for ( const auto& markup : other.mMarkups )
{
addMarkup( markup->dup() );
}
}
Frame::~Frame()
{
while ( !mMarkups.isEmpty() )
{
delete mMarkups.takeFirst();
mMarkups.push_back( markup->clone() );
}
}
@@ -87,13 +76,13 @@ namespace glabels
}
const QList<Layout>& Frame::layouts() const
const std::list<Layout>& Frame::layouts() const
{
return mLayouts;
}
const QList<Markup*>& Frame::markups() const
const std::list<std::unique_ptr<Markup>>& Frame::markups() const
{
return mMarkups;
}
@@ -104,7 +93,7 @@ namespace glabels
QVector<Point> origins( nLabels() );
int i = 0;
foreach ( const Layout& layout, mLayouts )
for ( auto& layout : mLayouts )
{
for ( int iy = 0; iy < layout.ny(); iy++ )
{
@@ -123,7 +112,7 @@ namespace glabels
void Frame::addLayout( const Layout& layout )
{
mLayouts << layout;
mLayouts.push_back( layout );
// Update total number of labels
mNLabels += layout.nx() * layout.ny();
@@ -147,15 +136,16 @@ namespace glabels
}
void Frame::addMarkup( Markup *markup )
void Frame::addMarkup( const Markup& markup )
{
mMarkups << markup;
mMarkups.push_back( markup.clone() );
}
void Frame::setH( const Distance& h )
bool Frame::setH( Distance h )
{
// Default implementation does nothing
return false;
}
}
@@ -164,42 +154,9 @@ namespace glabels
QDebug operator<<( QDebug dbg, const glabels::model::Frame& frame )
{
if ( auto* frameCd = dynamic_cast<const glabels::model::FrameCd*>(&frame) )
{
dbg << *frameCd;
return dbg;
}
else if ( auto* frameContinuous = dynamic_cast<const glabels::model::FrameContinuous*>(&frame) )
{
dbg << *frameContinuous;
return dbg;
}
else if ( auto* frameEllipse = dynamic_cast<const glabels::model::FrameEllipse*>(&frame) )
{
dbg << *frameEllipse;
return dbg;
}
else if ( auto* framePath = dynamic_cast<const glabels::model::FramePath*>(&frame) )
{
dbg << *framePath;
return dbg;
}
else if ( auto* frameRect = dynamic_cast<const glabels::model::FrameRect*>(&frame) )
{
dbg << *frameRect;
return dbg;
}
else if ( auto* frameRound = dynamic_cast<const glabels::model::FrameRound*>(&frame) )
{
dbg << *frameRound;
return dbg;
}
else
{
QDebugStateSaver saver(dbg);
QDebugStateSaver saver(dbg);
dbg.nospace() << "UNKNOWN FRAME";
frame.print( dbg );
return dbg;
}
return dbg;
}
+18 -17
View File
@@ -24,25 +24,23 @@
#include "Distance.h"
#include "Layout.h"
#include "Markup.h"
#include "Point.h"
#include <QCoreApplication>
#include <QDebug>
#include <QList>
#include <QPainterPath>
#include <QString>
#include <QVector>
#include <list>
namespace glabels
{
namespace model
{
// Forward references
class Markup;
class Frame
{
Q_DECLARE_TR_FUNCTIONS(Frame)
@@ -52,32 +50,35 @@ namespace glabels
Frame( const Frame& other );
public:
virtual ~Frame();
virtual Frame* dup() const = 0;
virtual ~Frame() = default;
virtual std::unique_ptr<Frame> clone() const = 0;
QString id() const;
int nLabels() const;
QString layoutDescription() const;
const QList<Layout>& layouts() const;
const QList<Markup*>& markups() const;
const std::list<Layout>& layouts() const;
const std::list<std::unique_ptr<Markup>>& markups() const;
QVector<Point> getOrigins() const;
void addLayout( const Layout& layout );
void addMarkup( Markup* markup );
void addMarkup( const Markup& markup );
virtual Distance w() const = 0;
virtual Distance h() const = 0;
virtual void setH( const Distance& h );
virtual bool setH( Distance h );
virtual QString sizeDescription( const Units& units ) const = 0;
virtual bool isSimilarTo( Frame* other ) const = 0;
virtual QString sizeDescription( Units units ) const = 0;
virtual bool isSimilarTo( const Frame& other ) const = 0;
virtual const QPainterPath& path() const = 0;
virtual const QPainterPath& clipPath() const = 0;
virtual QPainterPath marginPath( const Distance& xSize,
const Distance& ySize ) const = 0;
virtual QPainterPath marginPath( Distance xSize, Distance ySize ) const = 0;
// Debugging support
virtual void print( QDebug& dbg ) const = 0;
private:
@@ -85,8 +86,8 @@ namespace glabels
int mNLabels;
QString mLayoutDescription;
QList<Layout> mLayouts;
QList<Markup*> mMarkups;
std::list<Layout> mLayouts;
std::list<std::unique_ptr<Markup>> mMarkups;
};
}
+46 -32
View File
@@ -18,12 +18,13 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "FrameCd.h"
#include "Constants.h"
#include "StrUtil.h"
#include <QtDebug>
#include <QDebug>
namespace glabels
@@ -31,13 +32,18 @@ namespace glabels
namespace model
{
FrameCd::FrameCd( const Distance& r1,
const Distance& r2,
const Distance& w,
const Distance& h,
const Distance& waste,
const QString& id )
: Frame(id), mR1(r1), mR2(r2), mW(w), mH(h), mWaste(waste)
FrameCd::FrameCd( Distance r1,
Distance r2,
Distance w,
Distance h,
Distance waste,
const QString& id )
: Frame(id),
mR1(r1),
mR2(r2),
mW(w),
mH(h),
mWaste(waste)
{
Distance wReal = (mW == 0) ? 2*mR1 : mW;
Distance hReal = (mH == 0) ? 2*mR1 : mH;
@@ -93,9 +99,9 @@ namespace glabels
}
Frame* FrameCd::dup() const
std::unique_ptr<Frame> FrameCd::clone() const
{
return new FrameCd( *this );
return std::make_unique<FrameCd>( *this );
}
@@ -129,7 +135,7 @@ namespace glabels
}
QString FrameCd::sizeDescription( const Units& units ) const
QString FrameCd::sizeDescription( Units units ) const
{
if ( units.toEnum() == Units::IN )
{
@@ -145,9 +151,9 @@ namespace glabels
}
bool FrameCd::isSimilarTo( Frame* other ) const
bool FrameCd::isSimilarTo( const Frame& other ) const
{
if ( auto *otherCd = dynamic_cast<FrameCd*>(other) )
if ( auto *otherCd = dynamic_cast<const FrameCd*>(&other) )
{
if ( (fabs( mW - otherCd->mW ) <= EPSILON) &&
(fabs( mH - otherCd->mH ) <= EPSILON) &&
@@ -173,8 +179,7 @@ namespace glabels
}
QPainterPath FrameCd::marginPath( const Distance& xSize,
const Distance& ySize ) const
QPainterPath FrameCd::marginPath( Distance xSize, Distance ySize ) const
{
// Note: ignore ySize, assume xSize == ySize
Distance size = xSize;
@@ -207,24 +212,33 @@ namespace glabels
return path;
}
// Debugging support
void FrameCd::print( QDebug& dbg ) const
{
dbg.nospace() << "FrameCd{ "
<< id() << ","
<< r1() << ","
<< r2() << ","
<< waste() << ","
<< w() << ","
<< h() << ","
<< "list{ ";
for ( auto& layout : layouts() )
{
dbg.nospace() << layout << ",";
}
dbg.nospace() << " }"
<< "list{ ";
for ( auto& markup : markups() )
{
dbg.nospace() << *markup << ",";
}
dbg.nospace() << " }"
<< " }";
}
}
}
QDebug operator<<( QDebug dbg, const glabels::model::FrameCd& frame )
{
QDebugStateSaver saver(dbg);
dbg.nospace() << "FrameCd{ "
<< frame.id() << ","
<< frame.r1() << ","
<< frame.r2() << ","
<< frame.waste() << ","
<< frame.w() << ","
<< frame.h() << ","
<< frame.layouts() << ","
<< frame.markups()
<< " }";
return dbg;
}
+13 -15
View File
@@ -35,16 +35,16 @@ namespace glabels
Q_DECLARE_TR_FUNCTIONS(FrameCd)
public:
FrameCd( const Distance& r1,
const Distance& r2,
const Distance& w,
const Distance& h,
const Distance& waste,
const QString& id = "0" );
FrameCd( Distance r1,
Distance r2,
Distance w,
Distance h,
Distance waste,
const QString& id = "0" );
FrameCd( const FrameCd &other ) = default;
Frame *dup() const override;
std::unique_ptr<Frame> clone() const override;
Distance r1() const;
Distance r2() const;
@@ -53,13 +53,15 @@ namespace glabels
Distance w() const override;
Distance h() const override;
QString sizeDescription( const Units& units ) const override;
bool isSimilarTo( Frame* other ) const override;
QString sizeDescription( Units units ) const override;
bool isSimilarTo( const Frame& other ) const override;
const QPainterPath& path() const override;
const QPainterPath& clipPath() const override;
QPainterPath marginPath( const Distance& xSize,
const Distance& ySize ) const override;
QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
// Debugging support
void print( QDebug& dbg ) const override;
private:
@@ -78,8 +80,4 @@ namespace glabels
}
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::FrameCd& frame );
#endif // model_FrameCd_h
+48 -33
View File
@@ -18,31 +18,39 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "FrameContinuous.h"
#include "Constants.h"
#include "StrUtil.h"
#include <QDebug>
namespace glabels
{
namespace model
{
FrameContinuous::FrameContinuous( const Distance& w,
const Distance& hMin,
const Distance& hMax,
const Distance& hDefault,
const QString& id )
: Frame(id), mW(w), mHMin(hMin), mHMax(hMax), mHDefault(hDefault), mH(hDefault)
FrameContinuous::FrameContinuous( Distance w,
Distance hMin,
Distance hMax,
Distance hDefault,
const QString& id )
: Frame(id),
mW(w),
mHMin(hMin),
mHMax(hMax),
mHDefault(hDefault),
mH(hDefault)
{
mPath.addRect( 0, 0, mW.pt(), mH.pt() );
}
Frame* FrameContinuous::dup() const
std::unique_ptr<Frame> FrameContinuous::clone() const
{
return new FrameContinuous( *this );
return std::make_unique<FrameContinuous>( *this );
}
@@ -76,15 +84,16 @@ namespace glabels
}
void FrameContinuous::setH( const Distance& h )
bool FrameContinuous::setH( Distance h )
{
mH = h;
mPath = QPainterPath(); // clear path
mPath.addRect( 0, 0, mW.pt(), mH.pt() );
return true;
}
QString FrameContinuous::sizeDescription( const Units& units ) const
QString FrameContinuous::sizeDescription( Units units ) const
{
if ( units.toEnum() == Units::IN )
{
@@ -99,9 +108,9 @@ namespace glabels
}
bool FrameContinuous::isSimilarTo( Frame* other ) const
bool FrameContinuous::isSimilarTo( const Frame& other ) const
{
if ( auto *otherContinuous = dynamic_cast<FrameContinuous*>(other) )
if ( auto *otherContinuous = dynamic_cast<const FrameContinuous*>(&other) )
{
if ( fabs( mW - otherContinuous->mW ) <= EPSILON )
{
@@ -124,8 +133,7 @@ namespace glabels
}
QPainterPath FrameContinuous::marginPath( const Distance& xSize,
const Distance& ySize ) const
QPainterPath FrameContinuous::marginPath( Distance xSize, Distance ySize ) const
{
Distance w = mW - 2*xSize;
Distance h = mH - 2*ySize;
@@ -137,24 +145,31 @@ namespace glabels
}
// Debugging support
void FrameContinuous::print( QDebug& dbg ) const
{
dbg.nospace() << "FrameContinuous{ "
<< id() << ","
<< w() << ","
<< h() << ","
<< hMin() << ","
<< hMax() << ","
<< hDefault() << ","
<< "list{ ";
for ( auto& layout : layouts() )
{
dbg.nospace() << layout << ",";
}
dbg.nospace() << " }"
<< "list{ ";
for ( auto& markup : markups() )
{
dbg.nospace() << *markup << ",";
}
dbg.nospace() << " }"
<< " }";
}
}
}
QDebug operator<<( QDebug dbg, const glabels::model::FrameContinuous& frame )
{
QDebugStateSaver saver(dbg);
dbg.nospace() << "FrameContinuous{ "
<< frame.id() << ","
<< frame.w() << ","
<< frame.h() << ","
<< frame.hMin() << ","
<< frame.hMax() << ","
<< frame.hDefault() << ","
<< frame.layouts() << ","
<< frame.markups()
<< " }";
return dbg;
}
+13 -15
View File
@@ -35,15 +35,15 @@ namespace glabels
Q_DECLARE_TR_FUNCTIONS(FrameContinuous)
public:
FrameContinuous( const Distance& w,
const Distance& hMin,
const Distance& hMax,
const Distance& hDefault,
const QString& id = "0" );
FrameContinuous( Distance w,
Distance hMin,
Distance hMax,
Distance hDefault,
const QString& id = "0" );
FrameContinuous( const FrameContinuous& other ) = default;
Frame* dup() const override;
std::unique_ptr<Frame> clone() const override;
Distance w() const override;
Distance h() const override;
@@ -52,16 +52,18 @@ namespace glabels
Distance hMax() const;
Distance hDefault() const;
void setH( const Distance& h ) override;
bool setH( Distance h ) override;
QString sizeDescription( const Units& units ) const override;
QString sizeDescription( Units units ) const override;
bool isSimilarTo( Frame* other ) const override;
bool isSimilarTo( const Frame& other ) const override;
const QPainterPath& path() const override;
const QPainterPath& clipPath() const override;
QPainterPath marginPath( const Distance& xSize,
const Distance& ySize ) const override;
QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
// Debugging support
void print( QDebug& dbg ) const override;
private:
@@ -78,8 +80,4 @@ namespace glabels
}
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::FrameContinuous& frame );
#endif // model_FrameContinuous_h
+42 -29
View File
@@ -18,31 +18,37 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "FrameEllipse.h"
#include "Constants.h"
#include "StrUtil.h"
#include <QDebug>
namespace glabels
{
namespace model
{
FrameEllipse::FrameEllipse( const Distance& w,
const Distance& h,
const Distance& waste,
const QString& id )
: Frame(id), mW(w), mH(h), mWaste(waste)
FrameEllipse::FrameEllipse( Distance w,
Distance h,
Distance waste,
const QString& id )
: Frame(id),
mW(w),
mH(h),
mWaste(waste)
{
mPath.addEllipse( 0, 0, mW.pt(), mH.pt() );
mClipPath.addEllipse( -mWaste.pt(), -mWaste.pt(), (mW+2*mWaste).pt(), (mH+2*mWaste).pt() );
}
Frame* FrameEllipse::dup() const
std::unique_ptr<Frame> FrameEllipse::clone() const
{
return new FrameEllipse( *this );
return std::make_unique<FrameEllipse>( *this );
}
@@ -64,7 +70,7 @@ namespace glabels
}
QString FrameEllipse::sizeDescription( const Units& units ) const
QString FrameEllipse::sizeDescription( Units units ) const
{
if ( units.toEnum() == Units::IN )
{
@@ -82,9 +88,9 @@ namespace glabels
}
bool FrameEllipse::isSimilarTo( Frame* other ) const
bool FrameEllipse::isSimilarTo( const Frame& other ) const
{
if ( auto* otherEllipse = dynamic_cast<FrameEllipse*>(other) )
if ( auto* otherEllipse = dynamic_cast<const FrameEllipse*>(&other) )
{
if ( (fabs( mW - otherEllipse->mW ) <= EPSILON) &&
(fabs( mH - otherEllipse->mH ) <= EPSILON) )
@@ -108,8 +114,7 @@ namespace glabels
}
QPainterPath FrameEllipse::marginPath( const Distance& xSize,
const Distance& ySize ) const
QPainterPath FrameEllipse::marginPath( Distance xSize, Distance ySize ) const
{
// Note: ignore ySize, assume xSize == ySize
Distance size = xSize;
@@ -123,22 +128,30 @@ namespace glabels
return path;
}
// Debugging support
void FrameEllipse::print( QDebug& dbg ) const
{
dbg.nospace() << "FrameEllipse{ "
<< id() << ","
<< w() << ","
<< h() << ","
<< waste() << ","
<< "list{ ";
for ( auto& layout : layouts() )
{
dbg.nospace() << layout << ",";
}
dbg.nospace() << " }"
<< "list{ ";
for ( auto& markup : markups() )
{
dbg.nospace() << *markup << ",";
}
dbg.nospace() << " }"
<< " }";
}
}
}
QDebug operator<<( QDebug dbg, const glabels::model::FrameEllipse& frame )
{
QDebugStateSaver saver(dbg);
dbg.nospace() << "FrameEllipse{ "
<< frame.id() << ","
<< frame.w() << ","
<< frame.h() << ","
<< frame.waste() << ","
<< frame.layouts() << ","
<< frame.markups()
<< " }";
return dbg;
}
+11 -13
View File
@@ -35,27 +35,29 @@ namespace glabels
Q_DECLARE_TR_FUNCTIONS(FrameEllipse)
public:
FrameEllipse( const Distance& w,
const Distance& h,
const Distance& waste,
const QString& id = "0" );
FrameEllipse( Distance w,
Distance h,
Distance waste,
const QString& id = "0" );
FrameEllipse( const FrameEllipse& other ) = default;
Frame* dup() const override;
std::unique_ptr<Frame> clone() const override;
Distance waste() const;
Distance w() const override;
Distance h() const override;
QString sizeDescription( const Units& units ) const override;
bool isSimilarTo( Frame* other ) const override;
QString sizeDescription( Units units ) const override;
bool isSimilarTo( const Frame& other ) const override;
const QPainterPath& path() const override;
const QPainterPath& clipPath() const override;
QPainterPath marginPath( const Distance& xSize,
const Distance& ySize ) const override;
QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
// Debugging support
void print( QDebug& dbg ) const override;
private:
@@ -72,8 +74,4 @@ namespace glabels
}
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::FrameEllipse& frame );
#endif // model_FrameEllipse_h
+41 -28
View File
@@ -18,11 +18,14 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "FramePath.h"
#include "Constants.h"
#include "StrUtil.h"
#include <QDebug>
namespace glabels
{
@@ -30,11 +33,15 @@ namespace glabels
{
FramePath::FramePath( const QPainterPath& path,
const Distance& xWaste,
const Distance& yWaste,
const Units& originalUnits,
Distance xWaste,
Distance yWaste,
Units originalUnits,
const QString& id )
: Frame(id), mXWaste(xWaste), mYWaste(yWaste), mPath(path), mOriginalUnits(originalUnits)
: Frame(id),
mXWaste(xWaste),
mYWaste(yWaste),
mPath(path),
mOriginalUnits(originalUnits)
{
QRectF r = path.boundingRect();
@@ -46,9 +53,9 @@ namespace glabels
}
Frame* FramePath::dup() const
std::unique_ptr<Frame> FramePath::clone() const
{
return new FramePath( *this );
return std::make_unique<FramePath>( *this );
}
@@ -82,7 +89,7 @@ namespace glabels
}
QString FramePath::sizeDescription( const Units& units ) const
QString FramePath::sizeDescription( Units units ) const
{
if ( units.toEnum() == Units::IN )
{
@@ -100,9 +107,9 @@ namespace glabels
}
bool FramePath::isSimilarTo( Frame* other ) const
bool FramePath::isSimilarTo( const Frame& other ) const
{
if ( auto *otherPath = dynamic_cast<FramePath*>(other) )
if ( auto *otherPath = dynamic_cast<const FramePath*>(&other) )
{
if ( mPath == otherPath->mPath )
{
@@ -125,29 +132,35 @@ namespace glabels
}
QPainterPath FramePath::marginPath( const Distance& xSize,
const Distance& ySize ) const
QPainterPath FramePath::marginPath( Distance xSize, Distance ySize ) const
{
return mPath; // No margin
}
// Debugging support
void FramePath::print( QDebug& dbg ) const
{
dbg.nospace() << "FramePath{ "
<< id() << ","
<< path() << ","
<< xWaste() << ","
<< yWaste() << ","
<< "list{ ";
for ( auto& layout : layouts() )
{
dbg.nospace() << layout << ",";
}
dbg.nospace() << " }"
<< "list{ ";
for ( auto& markup : markups() )
{
dbg.nospace() << *markup << ",";
}
dbg.nospace() << " }"
<< " }";
}
}
}
QDebug operator<<( QDebug dbg, const glabels::model::FramePath& frame )
{
QDebugStateSaver saver(dbg);
dbg.nospace() << "FramePath{ "
<< frame.id() << ","
<< frame.path() << ","
<< frame.xWaste() << ","
<< frame.yWaste() << ","
<< frame.layouts() << ","
<< frame.markups()
<< " }";
return dbg;
}
+10 -12
View File
@@ -36,14 +36,14 @@ namespace glabels
public:
FramePath( const QPainterPath& path,
const Distance& xWaste,
const Distance& yWaste,
const Units& originalUnits,
Distance xWaste,
Distance yWaste,
Units originalUnits,
const QString& id = "0" );
FramePath( const FramePath& other ) = default;
Frame* dup() const override;
std::unique_ptr<Frame> clone() const override;
Distance xWaste() const;
Distance yWaste() const;
@@ -53,14 +53,16 @@ namespace glabels
Distance w() const override;
Distance h() const override;
QString sizeDescription( const Units& units ) const override;
QString sizeDescription( Units units ) const override;
bool isSimilarTo( Frame* other ) const override;
bool isSimilarTo( const Frame& other ) const override;
const QPainterPath& path() const override;
const QPainterPath& clipPath() const override;
QPainterPath marginPath( const Distance& xSize,
const Distance& ySize ) const override;
QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
// Debugging support
void print( QDebug& dbg ) const override;
private:
@@ -79,8 +81,4 @@ namespace glabels
}
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::FramePath& frame );
#endif // model_FramePath_h
+47 -33
View File
@@ -18,24 +18,32 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "FrameRect.h"
#include "Constants.h"
#include "StrUtil.h"
#include <QDebug>
namespace glabels
{
namespace model
{
FrameRect::FrameRect( const Distance& w,
const Distance& h,
const Distance& r,
const Distance& xWaste,
const Distance& yWaste,
const QString& id )
: Frame(id), mW(w), mH(h), mR(r), mXWaste(xWaste), mYWaste(yWaste)
FrameRect::FrameRect( Distance w,
Distance h,
Distance r,
Distance xWaste,
Distance yWaste,
const QString& id )
: Frame(id),
mW(w),
mH(h),
mR(r),
mXWaste(xWaste),
mYWaste(yWaste)
{
mPath.addRoundedRect( 0, 0, mW.pt(), mH.pt(), mR.pt(), mR.pt() );
@@ -45,9 +53,9 @@ namespace glabels
}
Frame* FrameRect::dup() const
std::unique_ptr<Frame> FrameRect::clone() const
{
return new FrameRect( *this );
return std::make_unique<FrameRect>( *this );
}
@@ -81,7 +89,7 @@ namespace glabels
}
QString FrameRect::sizeDescription( const Units& units ) const
QString FrameRect::sizeDescription( Units units ) const
{
if ( units.toEnum() == Units::IN )
{
@@ -99,9 +107,9 @@ namespace glabels
}
bool FrameRect::isSimilarTo( Frame* other ) const
bool FrameRect::isSimilarTo( const Frame& other ) const
{
if ( auto *otherRect = dynamic_cast<FrameRect*>(other) )
if ( auto *otherRect = dynamic_cast<const FrameRect*>(&other) )
{
if ( (fabs( mW - otherRect->mW ) <= EPSILON) &&
(fabs( mH - otherRect->mH ) <= EPSILON) )
@@ -125,8 +133,7 @@ namespace glabels
}
QPainterPath FrameRect::marginPath( const Distance& xSize,
const Distance& ySize ) const
QPainterPath FrameRect::marginPath( Distance xSize, Distance ySize ) const
{
Distance w = mW - 2*xSize;
Distance h = mH - 2*ySize;
@@ -139,24 +146,31 @@ namespace glabels
}
// Debugging support
void FrameRect::print( QDebug& dbg ) const
{
dbg.nospace() << "FrameRect{ "
<< id() << ","
<< w() << ","
<< h() << ","
<< r() << ","
<< xWaste() << ","
<< yWaste() << ","
<< "list{ ";
for ( auto& layout : layouts() )
{
dbg.nospace() << layout << ",";
}
dbg.nospace() << " }"
<< "list{ ";
for ( auto& markup : markups() )
{
dbg.nospace() << *markup << ",";
}
dbg.nospace() << " }"
<< " }";
}
}
}
QDebug operator<<( QDebug dbg, const glabels::model::FrameRect& frame )
{
QDebugStateSaver saver(dbg);
dbg.nospace() << "FrameRect{ "
<< frame.id() << ","
<< frame.w() << ","
<< frame.h() << ","
<< frame.r() << ","
<< frame.xWaste() << ","
<< frame.yWaste() << ","
<< frame.layouts() << ","
<< frame.markups()
<< " }";
return dbg;
}
+13 -15
View File
@@ -35,16 +35,16 @@ namespace glabels
Q_DECLARE_TR_FUNCTIONS(FrameRect)
public:
FrameRect( const Distance& w,
const Distance& h,
const Distance& r,
const Distance& xWaste,
const Distance& yWaste,
const QString& id = "0" );
FrameRect( Distance w,
Distance h,
Distance r,
Distance xWaste,
Distance yWaste,
const QString& id = "0" );
FrameRect( const FrameRect& other ) = default;
Frame* dup() const override;
std::unique_ptr<Frame> clone() const override;
Distance r() const;
Distance xWaste() const;
@@ -53,14 +53,16 @@ namespace glabels
Distance w() const override;
Distance h() const override;
QString sizeDescription( const Units& units ) const override;
QString sizeDescription( Units units ) const override;
bool isSimilarTo( Frame* other ) const override;
bool isSimilarTo( const Frame& other ) const override;
const QPainterPath& path() const override;
const QPainterPath& clipPath() const override;
QPainterPath marginPath( const Distance& xSize,
const Distance& ySize ) const override;
QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
// Debugging support
void print( QDebug& dbg ) const override;
private:
@@ -79,8 +81,4 @@ namespace glabels
}
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::FrameRect& frame );
#endif // model_FrameRect_h
+40 -27
View File
@@ -18,21 +18,26 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "FrameRound.h"
#include "Constants.h"
#include "StrUtil.h"
#include <QDebug>
namespace glabels
{
namespace model
{
FrameRound::FrameRound( const Distance& r,
const Distance& waste,
const QString& id )
: Frame(id), mR(r), mWaste(waste)
FrameRound::FrameRound( Distance r,
Distance waste,
const QString& id )
: Frame(id),
mR(r),
mWaste(waste)
{
mPath.addEllipse( 0, 0, 2*mR.pt(), 2*mR.pt() );
mClipPath.addEllipse( -mWaste.pt(), -mWaste.pt(),
@@ -40,9 +45,9 @@ namespace glabels
}
Frame* FrameRound::dup() const
std::unique_ptr<Frame> FrameRound::clone() const
{
return new FrameRound( *this );
return std::make_unique<FrameRound>( *this );
}
@@ -70,7 +75,7 @@ namespace glabels
}
QString FrameRound::sizeDescription( const Units& units ) const
QString FrameRound::sizeDescription( Units units ) const
{
if ( units.toEnum() == Units::IN )
{
@@ -86,9 +91,9 @@ namespace glabels
}
bool FrameRound::isSimilarTo( Frame* other ) const
bool FrameRound::isSimilarTo( const Frame& other ) const
{
if ( auto *otherRound = dynamic_cast<FrameRound*>(other) )
if ( auto *otherRound = dynamic_cast<const FrameRound*>(&other) )
{
if ( fabs( mR - otherRound->mR ) <= EPSILON )
{
@@ -111,8 +116,7 @@ namespace glabels
}
QPainterPath FrameRound::marginPath( const Distance& xSize,
const Distance& ySize ) const
QPainterPath FrameRound::marginPath( Distance xSize, Distance ySize ) const
{
// Note: ignore ySize, assume xSize == ySize
Distance size = xSize;
@@ -125,21 +129,30 @@ namespace glabels
return path;
}
// Debugging support
void FrameRound::print( QDebug& dbg ) const
{
dbg.nospace() << "FrameRound{ "
<< id() << ","
<< r() << ","
<< waste() << ","
<< "list{ ";
for ( auto& layout : layouts() )
{
dbg.nospace() << layout << ",";
}
dbg.nospace() << " }"
<< "list{ ";
for ( auto& markup : markups() )
{
dbg.nospace() << *markup << ",";
}
dbg.nospace() << " }"
<< " }";
}
}
}
QDebug operator<<( QDebug dbg, const glabels::model::FrameRound& frame )
{
QDebugStateSaver saver(dbg);
dbg.nospace() << "FrameRound{ "
<< frame.id() << ","
<< frame.r() << ","
<< frame.waste() << ","
<< frame.layouts() << ","
<< frame.markups()
<< " }";
return dbg;
}
+10 -12
View File
@@ -35,13 +35,13 @@ namespace glabels
Q_DECLARE_TR_FUNCTIONS(FrameRound)
public:
FrameRound( const Distance& r,
const Distance& waste,
const QString& id = "0" );
FrameRound( Distance r,
Distance waste,
const QString& id = "0" );
FrameRound( const FrameRound &other ) = default;
Frame *dup() const override;
std::unique_ptr<Frame> clone() const override;
Distance r() const;
Distance waste() const;
@@ -49,13 +49,15 @@ namespace glabels
Distance w() const override;
Distance h() const override;
QString sizeDescription( const Units& units ) const override;
bool isSimilarTo( Frame* other ) const override;
QString sizeDescription( Units units ) const override;
bool isSimilarTo( const Frame& other ) const override;
const QPainterPath& path() const override;
const QPainterPath& clipPath() const override;
QPainterPath marginPath( const Distance& xSize,
const Distance& ySize ) const override;
QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
// Debugging support
void print( QDebug& dbg ) const override;
private:
@@ -71,8 +73,4 @@ namespace glabels
}
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::FrameRound& frame );
#endif // model_FrameRound_h
+225
View File
@@ -0,0 +1,225 @@
/* Handles.cpp
*
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Handle.h"
#include "ModelObject.h"
#include <QColor>
#include <QDebug>
namespace glabels
{
namespace model
{
//
// Private
//
namespace
{
const double handlePixels = 7;
const double handleOutlineWidthPixels = 1;
const QColor handleFillColor( 0, 192, 0, 96 );
const QColor originHandleFillColor( 192, 0, 0, 96 );
const QColor handleOutlineColor( 0, 0, 0, 192 );
}
///
/// Handle Constructor
///
Handle::Handle( ModelObject* owner, Location location )
: mOwner(owner), mLocation(location)
{
// empty
}
///
/// Is Handle null?
///
bool Handle::isNull() const
{
return mLocation == NULL_HANDLE;
}
///
/// Handle owner
///
ModelObject* Handle::owner() const
{
return mOwner;
}
///
/// Handle location
///
Handle::Location Handle::location() const
{
return mLocation;
}
///
/// Draw Handle
///
void Handle::draw( QPainter* painter, double scale ) const
{
switch ( mLocation )
{
case NW:
drawAt( painter, scale, 0, 0, originHandleFillColor );
break;
case N:
drawAt( painter, scale, mOwner->w()/2, 0, handleFillColor );
break;
case NE:
drawAt( painter, scale, mOwner->w(), 0, handleFillColor );
break;
case E:
drawAt( painter, scale, mOwner->w(), mOwner->h()/2, handleFillColor );
break;
case SE:
drawAt( painter, scale, mOwner->w(), mOwner->h(), handleFillColor );
break;
case S:
drawAt( painter, scale, mOwner->w()/2, mOwner->h(), handleFillColor );
break;
case SW:
drawAt( painter, scale, 0, mOwner->h(), handleFillColor );
break;
case W:
drawAt( painter, scale, 0, mOwner->h()/2, handleFillColor );
break;
case P1:
drawAt( painter, scale, 0, 0, originHandleFillColor );
break;
case P2:
drawAt( painter, scale, mOwner->w(), mOwner->h(), handleFillColor );
break;
default:
qWarning() << "Unknown Handle location";
break;
}
}
///
/// Handle Path
///
QPainterPath Handle::path( double scale ) const
{
switch ( mLocation )
{
case NW:
return pathAt( scale, 0, 0 );
break;
case N:
return pathAt( scale, mOwner->w()/2, 0 );
break;
case NE:
return pathAt( scale, mOwner->w(), 0 );
break;
case E:
return pathAt( scale, mOwner->w(), mOwner->h()/2 );
break;
case SE:
return pathAt( scale, mOwner->w(), mOwner->h() );
break;
case S:
return pathAt( scale, mOwner->w()/2, mOwner->h() );
break;
case SW:
return pathAt( scale, 0, mOwner->h() );
break;
case W:
return pathAt( scale, 0, mOwner->h()/2 );
break;
case P1:
return pathAt( scale, 0, 0 );
break;
case P2:
return pathAt( scale, mOwner->w(), mOwner->h() );
break;
default:
qWarning() << "Unknown Handle location";
return QPainterPath(); // Empty
break;
}
}
///
/// Draw Handle at x,y
///
void Handle::drawAt( QPainter* painter,
double scale,
Distance x,
Distance y,
QColor color ) const
{
painter->save();
painter->translate( x.pt(), y.pt() );
double s = 1.0 / scale;
QPen pen( handleOutlineColor );
pen.setCosmetic( true );
pen.setWidth( handleOutlineWidthPixels );
painter->setPen( pen );
painter->setBrush( color );
painter->drawRect( QRectF( -s*handlePixels/2.0, -s*handlePixels/2.0,
s*handlePixels, s*handlePixels ) );
painter->restore();
}
///
/// Create Handle path at x,y
///
QPainterPath Handle::pathAt( double scale,
Distance x,
Distance y ) const
{
QPainterPath path;
double s = 1/scale;
path.addRect( -s*handlePixels/2, -s*handlePixels/2, s*handlePixels, s*handlePixels );
path.translate( x.pt(), y.pt() );
return path;
}
}
}
+101
View File
@@ -0,0 +1,101 @@
/* Handles.h
*
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef model_Handles_h
#define model_Handles_h
#include "Distance.h"
#include <QPainter>
#include <QPainterPath>
namespace glabels
{
namespace model
{
// Forward References
class ModelObject;
///
/// Handle Base Class
///
class Handle
{
////////////////////////////
// Location enumeration
////////////////////////////
public:
enum Location { NULL_HANDLE, NW, N, NE, E, SE, S, SW, W, P1, P2 };
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
Handle() = default;
Handle( ModelObject* owner, Location location );
~Handle() = default;
////////////////////////////
// Attribute Methods
////////////////////////////
bool isNull() const;
ModelObject* owner() const;
Location location() const;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
void draw( QPainter* painter, double scale ) const;
QPainterPath path( double scale ) const;
private:
void drawAt( QPainter* painter,
double scale,
Distance x,
Distance y,
QColor color ) const;
QPainterPath pathAt( double scale,
Distance x,
Distance y ) const;
////////////////////////////
// Private Data
////////////////////////////
protected:
ModelObject* mOwner{ nullptr };
Location mLocation{ NULL_HANDLE };
};
}
}
#endif // model_Handles_h
-591
View File
@@ -1,591 +0,0 @@
/* Handles.cpp
*
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Handles.h"
#include "ModelObject.h"
#include <QColor>
#include <QtDebug>
namespace glabels
{
namespace model
{
//
// Private
//
namespace
{
const double handlePixels = 7;
const double handleOutlineWidthPixels = 1;
const QColor handleFillColor( 0, 192, 0, 96 );
const QColor originHandleFillColor( 192, 0, 0, 96 );
const QColor handleOutlineColor( 0, 0, 0, 192 );
}
///
/// Handle Constructor
///
Handle::Handle( ModelObject* owner, Location location )
: mOwner(owner), mLocation(location)
{
// empty
}
///
/// Handle Destructor
///
Handle::~Handle()
{
// empty
}
///
/// Handle owner
///
ModelObject* Handle::owner() const
{
return mOwner;
}
///
/// Handle location
///
Handle::Location Handle::location() const
{
return mLocation;
}
///
/// Draw Handle at x,y
///
void Handle::drawAt( QPainter* painter,
double scale,
const Distance& x,
const Distance& y,
QColor color ) const
{
painter->save();
painter->translate( x.pt(), y.pt() );
double s = 1.0 / scale;
QPen pen( handleOutlineColor );
pen.setCosmetic( true );
pen.setWidth( handleOutlineWidthPixels );
painter->setPen( pen );
painter->setBrush( color );
painter->drawRect( QRectF( -s*handlePixels/2.0, -s*handlePixels/2.0,
s*handlePixels, s*handlePixels ) );
painter->restore();
}
///
/// Create Handle path at x,y
///
QPainterPath Handle::pathAt( double scale,
const Distance& x,
const Distance& y ) const
{
QPainterPath path;
double s = 1/scale;
path.addRect( -s*handlePixels/2, -s*handlePixels/2, s*handlePixels, s*handlePixels );
path.translate( x.pt(), y.pt() );
return path;
}
///
/// HandleNorth Constructor
///
HandleNorth::HandleNorth( ModelObject* owner )
: Handle( owner, N )
{
// empty
}
///
/// HandleNorth Destructor
///
HandleNorth::~HandleNorth()
{
// empty
}
///
/// HandleNorth Clone
///
HandleNorth* HandleNorth::clone( ModelObject* newOwner ) const
{
return new HandleNorth( newOwner );
}
///
/// Draw HandleNorth
///
void HandleNorth::draw( QPainter* painter, double scale ) const
{
drawAt( painter, scale, mOwner->w()/2, 0, handleFillColor );
}
///
/// HandleNorth Path
///
QPainterPath HandleNorth::path( double scale ) const
{
return pathAt( scale, mOwner->w()/2, 0 );
}
///
/// HandleNorthEast Constructor
///
HandleNorthEast::HandleNorthEast( ModelObject* owner )
: Handle( owner, NE )
{
// empty
}
///
/// HandleNorthEast Destructor
///
HandleNorthEast::~HandleNorthEast()
{
// empty
}
///
/// HandleNorthEast Clone
///
HandleNorthEast* HandleNorthEast::clone( ModelObject* newOwner ) const
{
return new HandleNorthEast( newOwner );
}
///
/// Draw HandleNorthEast
///
void HandleNorthEast::draw( QPainter* painter, double scale ) const
{
drawAt( painter, scale, mOwner->w(), 0, handleFillColor );
}
///
/// HandleNorthEast Path
///
QPainterPath HandleNorthEast::path( double scale ) const
{
return pathAt( scale, mOwner->w(), 0 );
}
///
/// HandleEast Constructor
///
HandleEast::HandleEast( ModelObject* owner )
: Handle( owner, E )
{
// empty
}
///
/// HandleEast Destructor
///
HandleEast::~HandleEast()
{
// empty
}
///
/// HandleEast Clone
///
HandleEast* HandleEast::clone( ModelObject* newOwner ) const
{
return new HandleEast( newOwner );
}
///
/// Draw HandleEast
///
void HandleEast::draw( QPainter* painter, double scale ) const
{
drawAt( painter, scale, mOwner->w(), mOwner->h()/2, handleFillColor );
}
///
/// HandleEast Path
///
QPainterPath HandleEast::path( double scale ) const
{
return pathAt( scale, mOwner->w(), mOwner->h()/2 );
}
///
/// HandleSouthEast Constructor
///
HandleSouthEast::HandleSouthEast( ModelObject* owner )
: Handle( owner, SE )
{
// empty
}
///
/// HandleSouthEast Destructor
///
HandleSouthEast::~HandleSouthEast()
{
// empty
}
///
/// HandleSouthEast Clone
///
HandleSouthEast* HandleSouthEast::clone( ModelObject* newOwner ) const
{
return new HandleSouthEast( newOwner );
}
///
/// Draw HandleSouthEast
///
void HandleSouthEast::draw( QPainter* painter, double scale ) const
{
drawAt( painter, scale, mOwner->w(), mOwner->h(), handleFillColor );
}
///
/// HandleSouthEast Path
///
QPainterPath HandleSouthEast::path( double scale ) const
{
return pathAt( scale, mOwner->w(), mOwner->h() );
}
///
/// HandleSouth Constructor
///
HandleSouth::HandleSouth( ModelObject* owner )
: Handle( owner, S )
{
// empty
}
///
/// HandleSouth Destructor
///
HandleSouth::~HandleSouth()
{
// empty
}
///
/// HandleSouth Clone
///
HandleSouth* HandleSouth::clone( ModelObject* newOwner ) const
{
return new HandleSouth( newOwner );
}
///
/// Draw HandleSouth
///
void HandleSouth::draw( QPainter* painter, double scale ) const
{
drawAt( painter, scale, mOwner->w()/2, mOwner->h(), handleFillColor );
}
///
/// HandleSouth Path
///
QPainterPath HandleSouth::path( double scale ) const
{
return pathAt( scale, mOwner->w()/2, mOwner->h() );
}
///
/// HandleSouthWest Constructor
///
HandleSouthWest::HandleSouthWest( ModelObject* owner )
: Handle( owner, SW )
{
// empty
}
///
/// HandleSouthWest Destructor
///
HandleSouthWest::~HandleSouthWest()
{
// empty
}
///
/// HandleSouthWest Clone
///
HandleSouthWest* HandleSouthWest::clone( ModelObject* newOwner ) const
{
return new HandleSouthWest( newOwner );
}
///
/// Draw HandleSouthWest
///
void HandleSouthWest::draw( QPainter* painter, double scale ) const
{
drawAt( painter, scale, 0, mOwner->h(), handleFillColor );
}
///
/// HandleSouthWest Path
///
QPainterPath HandleSouthWest::path( double scale ) const
{
return pathAt( scale, 0, mOwner->h() );
}
///
/// HandleWest Constructor
///
HandleWest::HandleWest( ModelObject* owner )
: Handle( owner, W )
{
// empty
}
///
/// HandleWest Destructor
///
HandleWest::~HandleWest()
{
// empty
}
///
/// HandleWest Clone
///
HandleWest* HandleWest::clone( ModelObject* newOwner ) const
{
return new HandleWest( newOwner );
}
///
/// Draw HandleWest
///
void HandleWest::draw( QPainter* painter, double scale ) const
{
drawAt( painter, scale, 0, mOwner->h()/2, handleFillColor );
}
///
/// HandleWest Path
///
QPainterPath HandleWest::path( double scale ) const
{
return pathAt( scale, 0, mOwner->h()/2 );
}
///
/// HandleNorthWest Constructor
///
HandleNorthWest::HandleNorthWest( ModelObject* owner )
: Handle( owner, NW )
{
// empty
}
///
/// HandleNorthWest Destructor
///
HandleNorthWest::~HandleNorthWest()
{
// empty
}
///
/// HandleNorthWest Clone
///
HandleNorthWest* HandleNorthWest::clone( ModelObject* newOwner ) const
{
return new HandleNorthWest( newOwner );
}
///
/// Draw HandleNorthWest
///
void HandleNorthWest::draw( QPainter* painter, double scale ) const
{
drawAt( painter, scale, 0, 0, originHandleFillColor );
}
///
/// HandleNorthWest Path
///
QPainterPath HandleNorthWest::path( double scale ) const
{
return pathAt( scale, 0, 0 );
}
///
/// HandleP1 Constructor
///
HandleP1::HandleP1( ModelObject* owner )
: Handle( owner, P1 )
{
// empty
}
///
/// HandleP1 Destructor
///
HandleP1::~HandleP1()
{
// empty
}
///
/// HandleP1 Clone
///
HandleP1* HandleP1::clone( ModelObject* newOwner ) const
{
return new HandleP1( newOwner );
}
///
/// Draw HandleP1
///
void HandleP1::draw( QPainter* painter, double scale ) const
{
drawAt( painter, scale, 0, 0, originHandleFillColor );
}
///
/// HandleP1 Path
///
QPainterPath HandleP1::path( double scale ) const
{
return pathAt( scale, 0, 0 );
}
///
/// HandleP2 Constructor
///
HandleP2::HandleP2( ModelObject* owner )
: Handle( owner, P2 )
{
// empty
}
///
/// HandleP2 Destructor
///
HandleP2::~HandleP2()
{
// empty
}
///
/// HandleP2 Clone
///
HandleP2* HandleP2::clone( ModelObject* newOwner ) const
{
return new HandleP2( newOwner );
}
///
/// Draw HandleP2
///
void HandleP2::draw( QPainter* painter, double scale ) const
{
drawAt( painter, scale, mOwner->w(), mOwner->h(), handleFillColor );
}
///
/// HandleP2 Path
///
QPainterPath HandleP2::path( double scale ) const
{
return pathAt( scale, mOwner->w(), mOwner->h() );
}
}
}
-339
View File
@@ -1,339 +0,0 @@
/* Handles.h
*
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef model_Handles_h
#define model_Handles_h
#include "Distance.h"
#include <QPainter>
#include <QPainterPath>
namespace glabels
{
namespace model
{
// Forward References
class ModelObject;
///
/// Handle Base Class
///
class Handle
{
////////////////////////////
// Location enumeration
////////////////////////////
public:
enum Location { NW, N, NE, E, SE, S, SW, W, P1, P2 };
////////////////////////////
// Lifecycle Methods
////////////////////////////
protected:
Handle( ModelObject* owner, Location location );
public:
virtual ~Handle();
////////////////////////////
// Duplication
////////////////////////////
virtual Handle* clone( ModelObject* newOwner ) const = 0;
////////////////////////////
// Attribute Methods
////////////////////////////
ModelObject* owner() const;
Location location() const;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const = 0;
virtual QPainterPath path( double scale ) const = 0;
protected:
void drawAt( QPainter* painter,
double scale,
const Distance& x,
const Distance& y,
QColor color ) const;
QPainterPath pathAt( double scale,
const Distance& x,
const Distance& y ) const;
////////////////////////////
// Protected Data
////////////////////////////
protected:
ModelObject* mOwner;
Location mLocation;
};
///
/// HandleNorth Class
///
class HandleNorth : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleNorth( ModelObject* owner );
~HandleNorth() override;
HandleNorth* clone( ModelObject* newOwner ) const override;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
void draw( QPainter* painter, double scale ) const override;
QPainterPath path( double scale ) const override;
};
///
/// HandleNorthEast Class
///
class HandleNorthEast : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleNorthEast( ModelObject* owner );
~HandleNorthEast() override;
HandleNorthEast* clone( ModelObject* newOwner ) const override;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
void draw( QPainter* painter, double scale ) const override;
QPainterPath path( double scale ) const override;
};
///
/// HandleEast Class
///
class HandleEast : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleEast( ModelObject* owner );
~HandleEast() override;
HandleEast* clone( ModelObject* newOwner ) const override;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
void draw( QPainter* painter, double scale ) const override;
QPainterPath path( double scale ) const override;
};
///
/// HandleSouthEast Class
///
class HandleSouthEast : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleSouthEast( ModelObject* owner );
~HandleSouthEast() override;
HandleSouthEast* clone( ModelObject* newOwner ) const override;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
void draw( QPainter* painter, double scale ) const override;
QPainterPath path( double scale ) const override;
};
///
/// HandleSouth Class
///
class HandleSouth : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleSouth( ModelObject* owner );
~HandleSouth() override;
HandleSouth* clone( ModelObject* newOwner ) const override;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
void draw( QPainter* painter, double scale ) const override;
QPainterPath path( double scale ) const override;
};
///
/// HandleSouthWest Class
///
class HandleSouthWest : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleSouthWest( ModelObject* owner );
~HandleSouthWest() override;
HandleSouthWest* clone( ModelObject* newOwner ) const override;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
void draw( QPainter* painter, double scale ) const override;
QPainterPath path( double scale ) const override;
};
///
/// HandleWest Class
///
class HandleWest : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleWest( ModelObject* owner );
~HandleWest() override;
HandleWest* clone( ModelObject* newOwner ) const override;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
void draw( QPainter* painter, double scale ) const override;
QPainterPath path( double scale ) const override;
};
///
/// HandleNorthWest Class
///
class HandleNorthWest : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleNorthWest( ModelObject* owner );
~HandleNorthWest() override;
HandleNorthWest* clone( ModelObject* newOwner ) const override;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
void draw( QPainter* painter, double scale ) const override;
QPainterPath path( double scale ) const override;
};
///
/// HandleP1 Class
///
class HandleP1 : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleP1( ModelObject* owner );
~HandleP1() override;
HandleP1* clone( ModelObject* newOwner ) const override;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
void draw( QPainter* painter, double scale ) const override;
QPainterPath path( double scale ) const override;
};
///
/// HandleP2 Class
///
class HandleP2 : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleP2( ModelObject* owner );
~HandleP2() override;
////////////////////////////
// Duplication
////////////////////////////
HandleP2* clone( ModelObject* newOwner ) const override;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
void draw( QPainter* painter, double scale ) const override;
QPainterPath path( double scale ) const override;
};
}
}
#endif // model_Handles_h
+12 -15
View File
@@ -30,26 +30,23 @@ namespace glabels
namespace model
{
Layout::Layout( int nx,
int ny,
const Distance& x0,
const Distance& y0,
const Distance& dx,
const Distance& dy )
: mNx(nx), mNy(ny), mX0(x0), mY0(y0), mDx(dx), mDy(dy)
Layout::Layout( int nx,
int ny,
Distance x0,
Distance y0,
Distance dx,
Distance dy )
: mNx(nx),
mNy(ny),
mX0(x0),
mY0(y0),
mDx(dx),
mDy(dy)
{
// empty
}
Layout::Layout( const Layout& other )
: mNx(other.mNx), mNy(other.mNy), mX0(other.mX0), mY0(other.mY0),
mDx(other.mDx), mDy(other.mDy)
{
// empty
}
int Layout::nx() const
{
return mNx;
+7 -7
View File
@@ -36,14 +36,14 @@ namespace glabels
{
public:
Layout( int nx,
int ny,
const Distance& x0,
const Distance& y0,
const Distance& dx,
const Distance& dy );
Layout( int nx,
int ny,
Distance x0,
Distance y0,
Distance dx,
Distance dy );
Layout( const Layout &other );
Layout( const Layout& other ) = default;
int nx() const;
int ny() const;
+111 -38
View File
@@ -18,44 +18,49 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Markup.h"
#include "Frame.h"
namespace glabels
{
namespace model
{
QPainterPath Markup::path( const Frame* frame ) const
QPainterPath Markup::path( const Frame& frame ) const
{
// Use cached path -- default does not depend on frame size
return mPath;
}
MarkupMargin::MarkupMargin( const Distance& size )
: mXSize(size), mYSize(size)
MarkupMargin::MarkupMargin( Distance size )
: mXSize(size),
mYSize(size)
{
}
MarkupMargin::MarkupMargin( const Distance& xSize,
const Distance& ySize )
: mXSize(xSize), mYSize(ySize)
MarkupMargin::MarkupMargin( Distance xSize,
Distance ySize )
: mXSize(xSize),
mYSize(ySize)
{
}
QPainterPath MarkupMargin::path( const Frame* frame ) const
QPainterPath MarkupMargin::path( const Frame& frame ) const
{
// Re-calculate path -- frame size may have changed
return frame->marginPath( mXSize, mYSize );
return frame.marginPath( mXSize, mYSize );
}
Markup* MarkupMargin::dup() const
std::unique_ptr<Markup> MarkupMargin::clone() const
{
return new MarkupMargin( mXSize, mYSize );
return std::make_unique<MarkupMargin>( mXSize, mYSize );
}
@@ -71,20 +76,31 @@ namespace glabels
}
MarkupLine::MarkupLine( const Distance& x1,
const Distance& y1,
const Distance& x2,
const Distance& y2 )
: mX1(x1), mY1(y1), mX2(x2), mY2(y2)
void MarkupMargin::print( QDebug& dbg ) const
{
dbg.nospace() << "MarkupMargin{ "
<< mXSize << "," << mYSize
<< " }";
}
MarkupLine::MarkupLine( Distance x1,
Distance y1,
Distance x2,
Distance y2 )
: mX1(x1),
mY1(y1),
mX2(x2),
mY2(y2)
{
mPath.moveTo( x1.pt(), y1.pt() );
mPath.lineTo( x2.pt(), y2.pt() );
}
Markup* MarkupLine::dup() const
std::unique_ptr<Markup> MarkupLine::clone() const
{
return new MarkupLine( mX1, mY1, mX2, mY2 );
return std::make_unique<MarkupLine>( mX1, mY1, mX2, mY2 );
}
@@ -112,20 +128,33 @@ namespace glabels
}
MarkupRect::MarkupRect( const Distance& x1,
const Distance& y1,
const Distance& w,
const Distance& h,
const Distance& r )
: mX1(x1), mY1(y1), mW(w), mH(h), mR(r)
void MarkupLine::print( QDebug& dbg ) const
{
dbg.nospace() << "MarkupLine{ "
<< mX1 << "," << mY1 << ","
<< mX2 << "," << mY2
<< " }";
}
MarkupRect::MarkupRect( Distance x1,
Distance y1,
Distance w,
Distance h,
Distance r )
: mX1(x1),
mY1(y1),
mW(w),
mH(h),
mR(r)
{
mPath.addRoundedRect( x1.pt(), y1.pt(), w.pt(), h.pt(), r.pt(), r.pt() );
}
Markup* MarkupRect::dup() const
std::unique_ptr<Markup> MarkupRect::clone() const
{
return new MarkupRect( mX1, mY1, mW, mH, mR );
return std::make_unique<MarkupRect>( mX1, mY1, mW, mH, mR );
}
@@ -159,19 +188,32 @@ namespace glabels
}
MarkupEllipse::MarkupEllipse( const Distance& x1,
const Distance& y1,
const Distance& w,
const Distance& h )
: mX1(x1), mY1(y1), mW(w), mH(h)
void MarkupRect::print( QDebug& dbg ) const
{
dbg.nospace() << "MarkupRect{ "
<< mX1 << "," << mY1 << ","
<< mW << "," << mH << ","
<< mR
<< " }";
}
MarkupEllipse::MarkupEllipse( Distance x1,
Distance y1,
Distance w,
Distance h )
: mX1(x1),
mY1(y1),
mW(w),
mH(h)
{
mPath.addEllipse( x1.pt(), y1.pt(), w.pt(), h.pt() );
}
Markup* MarkupEllipse::dup() const
std::unique_ptr<Markup> MarkupEllipse::clone() const
{
return new MarkupEllipse( mX1, mY1, mW, mH );
return std::make_unique<MarkupEllipse>( mX1, mY1, mW, mH );
}
@@ -199,17 +241,28 @@ namespace glabels
}
MarkupCircle::MarkupCircle( const Distance& x0,
const Distance& y0,
const Distance& r )
: mX0(x0), mY0(y0), mR(r)
void MarkupEllipse::print( QDebug& dbg ) const
{
dbg.nospace() << "MarkupEllipse{ "
<< mX1 << "," << mY1 << ","
<< mW << "," << mH
<< " }";
}
MarkupCircle::MarkupCircle( Distance x0,
Distance y0,
Distance r )
: mX0(x0),
mY0(y0),
mR(r)
{
mPath.addEllipse( (x0-r).pt(), (y0-r).pt(), 2*r.pt(), 2*r.pt() );
}
Markup* MarkupCircle::dup() const
std::unique_ptr<Markup> MarkupCircle::clone() const
{
return new MarkupCircle( mX0, mY0, mR );
return std::make_unique<MarkupCircle>( mX0, mY0, mR );
}
@@ -230,5 +283,25 @@ namespace glabels
return mR;
}
void MarkupCircle::print( QDebug& dbg ) const
{
dbg.nospace() << "MarkupCircle{ "
<< mX0 << "," << mY0 << ","
<< mR
<< " }";
}
}
}
QDebug operator<<( QDebug dbg, const glabels::model::Markup& markup )
{
QDebugStateSaver saver(dbg);
markup.print( dbg );
return dbg;
}
+54 -28
View File
@@ -22,24 +22,31 @@
#define model_Markup_h
#include "Frame.h"
#include "Distance.h"
#include <QPainterPath>
#include <memory>
namespace glabels
{
namespace model
{
class Frame; // Forward reference
class Markup
{
public:
virtual ~Markup() = default;
virtual Markup* dup() const = 0;
virtual std::unique_ptr<Markup> clone() const = 0;
virtual QPainterPath path( const Frame* frame ) const;
virtual QPainterPath path( const Frame& frame ) const;
// Debugging support
virtual void print( QDebug& dbg ) const = 0;
protected:
QPainterPath mPath;
@@ -49,17 +56,20 @@ namespace glabels
class MarkupMargin : public Markup
{
public:
MarkupMargin( const Distance& size );
MarkupMargin( Distance size );
MarkupMargin( const Distance& xSize,
const Distance& ySize );
MarkupMargin( Distance xSize,
Distance ySize );
QPainterPath path( const Frame* frame ) const override;
QPainterPath path( const Frame& frame ) const override;
Distance xSize() const;
Distance ySize() const;
Markup* dup() const override;
std::unique_ptr<Markup> clone() const override;
// Debugging support
void print( QDebug& dbg ) const override;
private:
Distance mXSize;
@@ -70,17 +80,20 @@ namespace glabels
class MarkupLine : public Markup
{
public:
MarkupLine( const Distance& x1,
const Distance& y1,
const Distance& x2,
const Distance& y2 );
MarkupLine( Distance x1,
Distance y1,
Distance x2,
Distance y2 );
Distance x1() const;
Distance y1() const;
Distance x2() const;
Distance y2() const;
Markup* dup() const override;
std::unique_ptr<Markup> clone() const override;
// Debugging support
void print( QDebug& dbg ) const override;
private:
Distance mX1;
@@ -93,11 +106,11 @@ namespace glabels
class MarkupRect : public Markup
{
public:
MarkupRect( const Distance& x1,
const Distance& y1,
const Distance& w,
const Distance& h,
const Distance& r );
MarkupRect( Distance x1,
Distance y1,
Distance w,
Distance h,
Distance r );
Distance x1() const;
Distance y1() const;
@@ -105,7 +118,10 @@ namespace glabels
Distance h() const;
Distance r() const;
Markup* dup() const override;
std::unique_ptr<Markup> clone() const override;
// Debugging support
void print( QDebug& dbg ) const override;
private:
Distance mX1;
@@ -119,17 +135,20 @@ namespace glabels
class MarkupEllipse : public Markup
{
public:
MarkupEllipse( const Distance& x1,
const Distance& y1,
const Distance& w,
const Distance& h );
MarkupEllipse( Distance x1,
Distance y1,
Distance w,
Distance h );
Distance x1() const;
Distance y1() const;
Distance w() const;
Distance h() const;
Markup* dup() const override;
std::unique_ptr<Markup> clone() const override;
// Debugging support
void print( QDebug& dbg ) const override;
private:
Distance mX1;
@@ -142,15 +161,18 @@ namespace glabels
class MarkupCircle : public Markup
{
public:
MarkupCircle( const Distance& x0,
const Distance& y0,
const Distance& r );
MarkupCircle( Distance x0,
Distance y0,
Distance r );
Distance x0() const;
Distance y0() const;
Distance r() const;
Markup* dup() const override;
std::unique_ptr<Markup> clone() const override;
// Debugging support
void print( QDebug& dbg ) const override;
private:
Distance mX0;
@@ -163,4 +185,8 @@ namespace glabels
}
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::Markup& markup );
#endif // model_Markup_h
+54 -50
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Model.h"
#include "ModelObject.h"
@@ -55,17 +56,9 @@ namespace glabels
///
Model::Model()
{
mVariables = new Variables();
mMerge = new merge::None();
mMerge.reset( new merge::None() );
connect( mVariables, SIGNAL(changed()), this, SLOT(onVariablesChanged()) );
}
Model::Model( merge::Merge* merge, Variables* variables )
{
mVariables = variables; // Shared
mMerge = merge; // Shared
connect( &mVariables, SIGNAL(changed()), this, SLOT(onVariablesChanged()) );
}
@@ -75,7 +68,6 @@ namespace glabels
Model::~Model()
{
qDeleteAll( mObjectList );
// Final instance of mMerge and mVariables to be deleted by Model owner
}
@@ -84,7 +76,7 @@ namespace glabels
///
Model* Model::save() const
{
auto* savedModel = new Model( mMerge, mVariables ); // mMerge and mVariables shared between models
auto* savedModel = new Model(); // mMerge shared between models
if ( mFileName.isEmpty() && mUntitledInstance == 0 )
{
@@ -127,6 +119,10 @@ namespace glabels
connect( object, SIGNAL(moved()), this, SLOT(onObjectMoved()) );
}
mVariables.copy( savedModel->mVariables );
mMerge = savedModel->mMerge;
// Emit signals based on potential changes
emit changed();
emit selectionChanged();
@@ -170,34 +166,34 @@ namespace glabels
///
/// Get template
///
const Template* Model::tmplate() const
const Template& Model::tmplate() const
{
return &mTmplate;
return mTmplate;
}
///
/// Get frame
///
const Frame* Model::frame() const
const Frame* Model::frame( const QString& id ) const
{
return mTmplate.frames().constFirst();
return mTmplate.frame( id );
}
///
/// Set template
///
void Model::setTmplate( const Template* tmplate )
void Model::setTmplate( const Template& tmplate )
{
mTmplate = *tmplate;
mTmplate = tmplate;
setModified();
emit changed();
emit sizeChanged();
Settings::addToRecentTemplateList( tmplate->name() );
Settings::addToRecentTemplateList( tmplate.name() );
}
@@ -232,10 +228,9 @@ namespace glabels
///
Distance Model::w() const
{
auto& frames = mTmplate.frames();
if ( !frames.isEmpty() )
auto frame = mTmplate.frame();
if ( frame )
{
auto* frame = mTmplate.frames().constFirst();
return mRotate ? frame->h() : frame->w();
}
else
@@ -250,10 +245,9 @@ namespace glabels
///
Distance Model::h() const
{
auto& frames = mTmplate.frames();
if ( !frames.isEmpty() )
auto frame = mTmplate.frame();
if ( frame )
{
auto* frame = mTmplate.frames().constFirst();
return mRotate ? frame->w() : frame->h();
}
else
@@ -266,12 +260,10 @@ namespace glabels
///
/// Set height (if variable length)
///
void Model::setH( const Distance& h )
void Model::setH( Distance h )
{
if ( auto* frame = mTmplate.frames().first() )
if ( mTmplate.setH( h ) )
{
frame->setH( h );
setModified();
emit changed();
@@ -350,7 +342,16 @@ namespace glabels
///
/// Get variables object
///
Variables* Model::variables() const
Variables& Model::variables()
{
return mVariables;
}
///
/// Get const reference to variables object
///
const Variables& Model::constVariables() const
{
return mVariables;
}
@@ -361,7 +362,7 @@ namespace glabels
///
merge::Merge* Model::merge() const
{
return mMerge;
return mMerge.get();
}
@@ -372,11 +373,10 @@ namespace glabels
{
if ( merge != mMerge )
{
delete mMerge;
mMerge = merge;
mMerge.reset( merge );
connect( mMerge, SIGNAL(sourceChanged()), this, SLOT(onMergeSourceChanged()) );
connect( mMerge, SIGNAL(selectionChanged()), this, SLOT(onMergeSelectionChanged()) );
connect( mMerge.get(), SIGNAL(sourceChanged()), this, SLOT(onMergeSourceChanged()) );
connect( mMerge.get(), SIGNAL(selectionChanged()), this, SLOT(onMergeSelectionChanged()) );
setModified();
@@ -445,9 +445,9 @@ namespace glabels
///
/// Object at x,y
///
ModelObject* Model::objectAt( double scale,
const Distance& x,
const Distance& y ) const
ModelObject* Model::objectAt( double scale,
Distance x,
Distance y ) const
{
/* Search object list in reverse order. I.e. from top to bottom. */
QList<ModelObject*>::const_iterator it = mObjectList.end();
@@ -468,20 +468,22 @@ namespace glabels
///
/// Handle at x,y
///
Handle* Model::handleAt( double scale,
const Distance& x,
const Distance& y ) const
const Handle& Model::handleAt( double scale,
Distance x,
Distance y ) const
{
static Handle nullHandle;
foreach( ModelObject* object, mObjectList )
{
Handle* handle = object->handleAt( scale, x, y );
if ( handle )
auto& handle = object->handleAt( scale, x, y );
if ( !handle.isNull() )
{
return handle;
}
}
return nullptr;
return nullHandle;
}
@@ -1216,7 +1218,7 @@ namespace glabels
///
/// Move Selected Objects By dx,dy
///
void Model::moveSelection( const Distance& dx, const Distance& dy )
void Model::moveSelection( Distance dx, Distance dy )
{
foreach ( ModelObject* object, mObjectList )
{
@@ -1387,7 +1389,7 @@ namespace glabels
///
/// Set Line Width Of Selected Objects
///
void Model::setSelectionLineWidth( const Distance& lineWidth )
void Model::setSelectionLineWidth( Distance lineWidth )
{
foreach ( ModelObject* object, mObjectList )
{
@@ -1450,8 +1452,7 @@ namespace glabels
{
QClipboard *clipboard = QApplication::clipboard();
QByteArray buffer;
XmlLabelCreator::serializeObjects( getSelection(), this, buffer );
auto buffer = XmlLabelCreator::serializeObjects( getSelection(), this );
auto *mimeData = new QMimeData;
mimeData->setData( MIME_TYPE, buffer );
@@ -1607,11 +1608,14 @@ namespace glabels
///
/// Draw label objects
///
void Model::draw( QPainter* painter, bool inEditor, merge::Record* record, Variables* variables ) const
void Model::draw( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variablesInstance ) const
{
foreach ( ModelObject* object, mObjectList )
{
object->draw( painter, inEditor, record, variables );
object->draw( painter, inEditor, record, variablesInstance );
}
}
+22 -20
View File
@@ -60,7 +60,7 @@ namespace glabels
/////////////////////////////////
public:
Model();
Model( merge::Merge* merge, Variables* variables );
Model( merge::Merge* merge );
~Model();
@@ -100,9 +100,9 @@ namespace glabels
const QString& fileName() const;
void setFileName( const QString &fileName );
const Template* tmplate() const;
const Frame* frame() const;
void setTmplate( const Template* tmplate );
const Template& tmplate() const;
const Frame* frame( const QString& id = "0" ) const;
void setTmplate( const Template& tmplate );
bool rotate() const;
void setRotate( bool rotate );
@@ -110,11 +110,12 @@ namespace glabels
Distance w() const;
Distance h() const;
void setH( const Distance& h );
void setH( Distance h );
const QList<ModelObject*>& objectList() const;
Variables* variables() const;
Variables& variables();
const Variables& constVariables() const;
merge::Merge* merge() const;
void setMerge( merge::Merge* merge );
@@ -127,13 +128,13 @@ namespace glabels
void addObject( ModelObject* object );
void deleteObject( ModelObject* object );
ModelObject* objectAt( double scale,
const Distance& x,
const Distance& y ) const;
ModelObject* objectAt( double scale,
Distance x,
Distance y ) const;
Handle* handleAt( double scale,
const Distance& x,
const Distance& y ) const;
const Handle& handleAt( double scale,
Distance x,
Distance y ) const;
/////////////////////////////////
@@ -188,7 +189,7 @@ namespace glabels
void centerSelection();
void centerSelectionHoriz();
void centerSelectionVert();
void moveSelection( const Distance& dx, const Distance& dy );
void moveSelection( Distance dx, Distance dy );
void setSelectionFontFamily( const QString& fontFamily );
void setSelectionFontSize( double fontSize );
void setSelectionFontWeight( QFont::Weight fontWeight );
@@ -197,7 +198,7 @@ namespace glabels
void setSelectionTextVAlign( Qt::Alignment textVAlign );
void setSelectionTextLineSpacing( double textLineSpacing );
void setSelectionTextColorNode( ColorNode textColorNode );
void setSelectionLineWidth( const Distance& lineWidth );
void setSelectionLineWidth( Distance lineWidth );
void setSelectionLineColorNode( ColorNode lineColorNode );
void setSelectionFillColorNode( ColorNode fillColorNode );
@@ -218,10 +219,10 @@ namespace glabels
// Drawing operations
/////////////////////////////////
public:
void draw( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const;
void draw( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variablesInstance ) const;
/////////////////////////////////
@@ -247,8 +248,9 @@ namespace glabels
QList<ModelObject*> mObjectList;
Variables* mVariables;
merge::Merge* mMerge;
Variables mVariables;
QSharedPointer<merge::Merge> mMerge;
};
}
+39 -72
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ModelBarcodeObject.h"
#include "Size.h"
@@ -58,16 +59,16 @@ namespace glabels
///
ModelBarcodeObject::ModelBarcodeObject()
{
mOutline = new Outline( this );
mOutline.setOwner( this );
mHandles << new HandleNorthWest( this );
mHandles << new HandleNorth( this );
mHandles << new HandleNorthEast( this );
mHandles << new HandleEast( this );
mHandles << new HandleSouthEast( this );
mHandles << new HandleSouth( this );
mHandles << new HandleSouthWest( this );
mHandles << new HandleWest( this );
mHandles.push_back( Handle( this, Handle::NW ) );
mHandles.push_back( Handle( this, Handle::N ) );
mHandles.push_back( Handle( this, Handle::NE ) );
mHandles.push_back( Handle( this, Handle::E ) );
mHandles.push_back( Handle( this, Handle::SE ) );
mHandles.push_back( Handle( this, Handle::S ) );
mHandles.push_back( Handle( this, Handle::SW ) );
mHandles.push_back( Handle( this, Handle::W ) );
mBcStyle = barcode::Backends::defaultStyle();
mBcTextFlag = mBcStyle.canText();
@@ -76,9 +77,6 @@ namespace glabels
mBcData = "";
mBcColorNode = ColorNode( Qt::black );
mEditorBarcode = nullptr;
mEditorDefaultBarcode = nullptr;
update(); // Initialize cached editor layouts
}
@@ -86,10 +84,10 @@ namespace glabels
///
/// Constructor
///
ModelBarcodeObject::ModelBarcodeObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
ModelBarcodeObject::ModelBarcodeObject( Distance x0,
Distance y0,
Distance w,
Distance h,
bool lockAspectRatio,
const barcode::Style& bcStyle,
bool bcTextFlag,
@@ -99,16 +97,16 @@ namespace glabels
const QTransform& matrix )
: ModelObject( x0, y0, w, h, lockAspectRatio, matrix )
{
mOutline = new Outline( this );
mOutline.setOwner( this );
mHandles << new HandleNorthWest( this );
mHandles << new HandleNorth( this );
mHandles << new HandleNorthEast( this );
mHandles << new HandleEast( this );
mHandles << new HandleSouthEast( this );
mHandles << new HandleSouth( this );
mHandles << new HandleSouthWest( this );
mHandles << new HandleWest( this );
mHandles.push_back( Handle( this, Handle::NW ) );
mHandles.push_back( Handle( this, Handle::N ) );
mHandles.push_back( Handle( this, Handle::NE ) );
mHandles.push_back( Handle( this, Handle::E ) );
mHandles.push_back( Handle( this, Handle::SE ) );
mHandles.push_back( Handle( this, Handle::S ) );
mHandles.push_back( Handle( this, Handle::SW ) );
mHandles.push_back( Handle( this, Handle::W ) );
mBcStyle = bcStyle;
mBcTextFlag = bcTextFlag;
@@ -117,9 +115,6 @@ namespace glabels
mBcData = bcData;
mBcColorNode = bcColorNode;
mEditorBarcode = nullptr;
mEditorDefaultBarcode = nullptr;
update(); // Initialize cached editor layouts
}
@@ -137,30 +132,10 @@ namespace glabels
mBcData = object->mBcData;
mBcColorNode = object->mBcColorNode;
mEditorBarcode = nullptr;
mEditorDefaultBarcode = nullptr;
update(); // Initialize cached editor layouts
}
///
/// Destructor
///
ModelBarcodeObject::~ModelBarcodeObject()
{
delete mOutline;
foreach( Handle* handle, mHandles )
{
delete handle;
}
mHandles.clear();
delete mEditorBarcode;
}
///
/// Clone
///
@@ -311,10 +286,10 @@ namespace glabels
///
/// Draw shadow of object
///
void ModelBarcodeObject::drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const
void ModelBarcodeObject::drawShadow( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const
{
// Barcodes don't support shadows.
}
@@ -323,10 +298,10 @@ namespace glabels
///
/// Draw object itself
///
void ModelBarcodeObject::drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const
void ModelBarcodeObject::drawObject( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const
{
QColor bcColor = mBcColorNode.color( record, variables );
@@ -367,16 +342,12 @@ namespace glabels
//
// Build barcode from data
//
if ( mEditorBarcode )
{
delete mEditorBarcode;
}
mEditorBarcode = glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() );
mEditorBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() ) );
if ( !mEditorBarcode )
{
qWarning() << "Invalid barcode style" << mBcStyle.fullId() << "using \"code39\".";
mBcStyle = barcode::Backends::defaultStyle();
mEditorBarcode = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() );
mEditorBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() ) );
}
mEditorBarcode->setChecksum(mBcChecksumFlag);
mEditorBarcode->setShowText(mBcTextFlag);
@@ -386,16 +357,12 @@ namespace glabels
//
// Build a place holder barcode to display in editor, if cannot display actual barcode
//
if ( mEditorDefaultBarcode )
{
delete mEditorDefaultBarcode;
}
mEditorDefaultBarcode = glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() );
mEditorDefaultBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() ) );
if ( !mEditorDefaultBarcode )
{
qWarning() << "Invalid barcode style" << mBcStyle.fullId() << "using \"code39\".";
mBcStyle = barcode::Backends::defaultStyle();
mEditorDefaultBarcode = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() );
mEditorDefaultBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() ) );
}
mEditorDefaultBarcode->setChecksum(mBcChecksumFlag);
mEditorDefaultBarcode->setShowText(mBcTextFlag);
@@ -452,10 +419,10 @@ namespace glabels
/// Draw barcode in final printout or preview
///
void
ModelBarcodeObject::drawBc( QPainter* painter,
const QColor& color,
merge::Record* record,
Variables* variables ) const
ModelBarcodeObject::drawBc( QPainter* painter,
const QColor& color,
const merge::Record& record,
const Variables& variables ) const
{
painter->setPen( QPen( color ) );
+21 -19
View File
@@ -28,6 +28,8 @@
#include "glbarcode/Barcode.h"
#include <memory>
namespace glabels
{
@@ -47,10 +49,10 @@ namespace glabels
public:
ModelBarcodeObject();
ModelBarcodeObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
ModelBarcodeObject( Distance x0,
Distance y0,
Distance w,
Distance h,
bool lockAspectRatio,
const barcode::Style& bcStyle,
bool bcTextFlag,
@@ -61,7 +63,7 @@ namespace glabels
ModelBarcodeObject( const ModelBarcodeObject* object );
~ModelBarcodeObject() override;
virtual ~ModelBarcodeObject() = default;
///////////////////////////////////////////////////////////////
@@ -127,15 +129,15 @@ namespace glabels
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
void drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
void drawShadow( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const override;
void drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
void drawObject( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const override;
QPainterPath hoverPath( double scale ) const override;
@@ -149,10 +151,10 @@ namespace glabels
void drawBcInEditor( QPainter* painter, const QColor& color ) const;
void drawBc( QPainter* painter,
const QColor& color,
merge::Record* record,
Variables* variables ) const;
void drawBc( QPainter* painter,
const QColor& color,
const merge::Record& record,
const Variables& variables ) const;
void drawPlaceHolder( QPainter* painter, const QColor& color, const QString& text ) const;
@@ -169,8 +171,8 @@ namespace glabels
RawText mBcData;
ColorNode mBcColorNode;
glbarcode::Barcode* mEditorBarcode;
glbarcode::Barcode* mEditorDefaultBarcode;
std::unique_ptr<glbarcode::Barcode> mEditorBarcode;
std::unique_ptr<glbarcode::Barcode> mEditorDefaultBarcode;
QPainterPath mHoverPath;
+35 -33
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ModelBoxObject.h"
#include <QBrush>
@@ -50,24 +51,34 @@ namespace glabels
///
/// Constructor
///
ModelBoxObject::ModelBoxObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
bool lockAspectRatio,
const Distance& lineWidth,
const ColorNode& lineColorNode,
const ColorNode& fillColorNode,
ModelBoxObject::ModelBoxObject( Distance x0,
Distance y0,
Distance w,
Distance h,
bool lockAspectRatio,
Distance lineWidth,
const ColorNode& lineColorNode,
const ColorNode& fillColorNode,
const QTransform& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: ModelShapeObject( x0, y0, w, h, lockAspectRatio,
lineWidth, lineColorNode, fillColorNode,
bool shadowState,
Distance shadowX,
Distance shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: ModelShapeObject( x0,
y0,
w,
h,
lockAspectRatio,
lineWidth,
lineColorNode,
fillColorNode,
matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
shadowState,
shadowX,
shadowY,
shadowOpacity,
shadowColorNode )
{
// empty
}
@@ -83,15 +94,6 @@ namespace glabels
}
///
/// Destructor
///
ModelBoxObject::~ModelBoxObject()
{
// empty
}
///
/// Clone
///
@@ -104,10 +106,10 @@ namespace glabels
///
/// Draw shadow of object
///
void ModelBoxObject::drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const
void ModelBoxObject::drawShadow( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const
{
QColor lineColor = mLineColorNode.color( record, variables );
QColor fillColor = mFillColorNode.color( record, variables );
@@ -152,10 +154,10 @@ namespace glabels
///
/// Draw object itself
///
void ModelBoxObject::drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const
void ModelBoxObject::drawObject( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const
{
QColor lineColor = mLineColorNode.color( record, variables );
QColor fillColor = mFillColorNode.color( record, variables );
+22 -22
View File
@@ -43,24 +43,24 @@ namespace glabels
public:
ModelBoxObject();
ModelBoxObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
bool lockAspectRatio,
const Distance& lineWidth,
const ColorNode& lineColorNode,
const ColorNode& fillColorNode,
ModelBoxObject( Distance x0,
Distance y0,
Distance w,
Distance h,
bool lockAspectRatio,
Distance lineWidth,
const ColorNode& lineColorNode,
const ColorNode& fillColorNode,
const QTransform& matrix = QTransform(),
bool shadowState = false,
const Distance& shadowX = 0,
const Distance& shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
bool shadowState = false,
Distance shadowX = 0,
Distance shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
ModelBoxObject( const ModelBoxObject* object );
~ModelBoxObject() override;
virtual ~ModelBoxObject() = default;
///////////////////////////////////////////////////////////////
@@ -73,15 +73,15 @@ namespace glabels
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
void drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
void drawShadow( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const override;
void drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
void drawObject( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const override;
QPainterPath hoverPath( double scale ) const override;
+35 -33
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ModelEllipseObject.h"
#include <QBrush>
@@ -50,24 +51,34 @@ namespace glabels
///
/// Constructor
///
ModelEllipseObject::ModelEllipseObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
bool lockAspectRatio,
const Distance& lineWidth,
const ColorNode& lineColorNode,
const ColorNode& fillColorNode,
ModelEllipseObject::ModelEllipseObject( Distance x0,
Distance y0,
Distance w,
Distance h,
bool lockAspectRatio,
Distance lineWidth,
const ColorNode& lineColorNode,
const ColorNode& fillColorNode,
const QTransform& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: ModelShapeObject( x0, y0, w, h, lockAspectRatio,
lineWidth, lineColorNode, fillColorNode,
bool shadowState,
Distance shadowX,
Distance shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: ModelShapeObject( x0,
y0,
w,
h,
lockAspectRatio,
lineWidth,
lineColorNode,
fillColorNode,
matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
shadowState,
shadowX,
shadowY,
shadowOpacity,
shadowColorNode )
{
// empty
}
@@ -83,15 +94,6 @@ namespace glabels
}
///
/// Destructor
///
ModelEllipseObject::~ModelEllipseObject()
{
// empty
}
///
/// Clone
///
@@ -104,10 +106,10 @@ namespace glabels
///
/// Draw shadow of object
///
void ModelEllipseObject::drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const
void ModelEllipseObject::drawShadow( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const
{
QColor lineColor = mLineColorNode.color( record, variables );
QColor fillColor = mFillColorNode.color( record, variables );
@@ -152,10 +154,10 @@ namespace glabels
///
/// Draw object itself
///
void ModelEllipseObject::drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const
void ModelEllipseObject::drawObject( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const
{
QColor lineColor = mLineColorNode.color( record, variables );
QColor fillColor = mFillColorNode.color( record, variables );
+22 -22
View File
@@ -43,24 +43,24 @@ namespace glabels
public:
ModelEllipseObject();
ModelEllipseObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
bool lockAspectRatio,
const Distance& lineWidth,
const ColorNode& lineColorNode,
const ColorNode& fillColorNode,
ModelEllipseObject( Distance x0,
Distance y0,
Distance w,
Distance h,
bool lockAspectRatio,
Distance lineWidth,
const ColorNode& lineColorNode,
const ColorNode& fillColorNode,
const QTransform& matrix = QTransform(),
bool shadowState = false,
const Distance& shadowX = 0,
const Distance& shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
bool shadowState = false,
Distance shadowX = 0,
Distance shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
ModelEllipseObject( const ModelEllipseObject* object );
~ModelEllipseObject() override;
virtual ~ModelEllipseObject() = default;
///////////////////////////////////////////////////////////////
@@ -73,15 +73,15 @@ namespace glabels
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
void drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
void drawShadow( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const override;
void drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
void drawObject( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const override;
QPainterPath hoverPath( double scale ) const override;
+168 -259
View File
@@ -18,17 +18,18 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ModelImageObject.h"
#include "Model.h"
#include "Size.h"
#include <QBrush>
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QImage>
#include <QPen>
#include <QtDebug>
namespace glabels
@@ -39,7 +40,7 @@ namespace glabels
///
/// Static data
///
QImage* ModelImageObject::smDefaultImage = nullptr;
QImage ModelImageObject::smDefaultImage( ":images/checkerboard.png" );
//
@@ -56,23 +57,18 @@ namespace glabels
///
/// Constructor
///
ModelImageObject::ModelImageObject() : mImage(nullptr), mSvgRenderer(nullptr)
ModelImageObject::ModelImageObject()
{
mOutline = new Outline( this );
mOutline.setOwner( this );
mHandles << new HandleNorthWest( this );
mHandles << new HandleNorth( this );
mHandles << new HandleNorthEast( this );
mHandles << new HandleEast( this );
mHandles << new HandleSouthEast( this );
mHandles << new HandleSouth( this );
mHandles << new HandleSouthWest( this );
mHandles << new HandleWest( this );
if ( smDefaultImage == nullptr )
{
smDefaultImage = new QImage( ":images/checkerboard.png" );
}
mHandles.push_back( Handle( this, Handle::NW ) );
mHandles.push_back( Handle( this, Handle::N ) );
mHandles.push_back( Handle( this, Handle::NE ) );
mHandles.push_back( Handle( this, Handle::E ) );
mHandles.push_back( Handle( this, Handle::SE ) );
mHandles.push_back( Handle( this, Handle::S ) );
mHandles.push_back( Handle( this, Handle::SW ) );
mHandles.push_back( Handle( this, Handle::W ) );
mLockAspectRatio = true;
}
@@ -81,43 +77,43 @@ namespace glabels
///
/// Constructor
///
ModelImageObject::ModelImageObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
bool lockAspectRatio,
const TextNode& filenameNode,
ModelImageObject::ModelImageObject( Distance x0,
Distance y0,
Distance w,
Distance h,
bool lockAspectRatio,
const TextNode& filenameNode,
const QTransform& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: ModelObject( x0, y0, w, h, lockAspectRatio,
bool shadowState,
Distance shadowX,
Distance shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: ModelObject( x0,
y0,
w,
h,
lockAspectRatio,
matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
shadowState,
shadowX,
shadowY,
shadowOpacity,
shadowColorNode )
{
mOutline = new Outline( this );
mOutline.setOwner( this );
mHandles << new HandleNorthWest( this );
mHandles << new HandleNorth( this );
mHandles << new HandleNorthEast( this );
mHandles << new HandleEast( this );
mHandles << new HandleSouthEast( this );
mHandles << new HandleSouth( this );
mHandles << new HandleSouthWest( this );
mHandles << new HandleWest( this );
if ( smDefaultImage == nullptr )
{
smDefaultImage = new QImage( ":images/checkerboard.png" );
}
mHandles.push_back( Handle( this, Handle::NW ) );
mHandles.push_back( Handle( this, Handle::N ) );
mHandles.push_back( Handle( this, Handle::NE ) );
mHandles.push_back( Handle( this, Handle::E ) );
mHandles.push_back( Handle( this, Handle::SE ) );
mHandles.push_back( Handle( this, Handle::S ) );
mHandles.push_back( Handle( this, Handle::SW ) );
mHandles.push_back( Handle( this, Handle::W ) );
mFilenameNode = filenameNode;
mImage = nullptr;
mSvgRenderer = nullptr;
loadImage();
}
@@ -125,85 +121,92 @@ namespace glabels
///
/// Constructor
///
ModelImageObject::ModelImageObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
bool lockAspectRatio,
const QString& filename,
const QImage& image,
ModelImageObject::ModelImageObject( Distance x0,
Distance y0,
Distance w,
Distance h,
bool lockAspectRatio,
const QString& filename,
const QImage& image,
const QTransform& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: ModelObject( x0, y0, w, h, lockAspectRatio,
bool shadowState,
Distance shadowX,
Distance shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: ModelObject( x0,
y0,
w,
h,
lockAspectRatio,
matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
shadowState,
shadowX,
shadowY,
shadowOpacity,
shadowColorNode )
{
mOutline = new Outline( this );
mOutline.setOwner( this );
mHandles << new HandleNorthWest( this );
mHandles << new HandleNorth( this );
mHandles << new HandleNorthEast( this );
mHandles << new HandleEast( this );
mHandles << new HandleSouthEast( this );
mHandles << new HandleSouth( this );
mHandles << new HandleSouthWest( this );
mHandles << new HandleWest( this );
mHandles.push_back( Handle( this, Handle::NW ) );
mHandles.push_back( Handle( this, Handle::N ) );
mHandles.push_back( Handle( this, Handle::NE ) );
mHandles.push_back( Handle( this, Handle::E ) );
mHandles.push_back( Handle( this, Handle::SE ) );
mHandles.push_back( Handle( this, Handle::S ) );
mHandles.push_back( Handle( this, Handle::SW ) );
mHandles.push_back( Handle( this, Handle::W ) );
if ( smDefaultImage == nullptr )
{
smDefaultImage = new QImage( ":images/checkerboard.png" );
}
mImage = new QImage(image);
mImage = image;
mFilenameNode = TextNode( false, filename );
mSvgRenderer = nullptr;
}
///
/// Constructor
///
ModelImageObject::ModelImageObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
ModelImageObject::ModelImageObject( Distance x0,
Distance y0,
Distance w,
Distance h,
bool lockAspectRatio,
const QString& filename,
const QByteArray& svg,
const QTransform& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
Distance shadowX,
Distance shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: ModelObject( x0, y0, w, h, lockAspectRatio,
: ModelObject( x0,
y0,
w,
h,
lockAspectRatio,
matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
shadowState,
shadowX,
shadowY,
shadowOpacity,
shadowColorNode )
{
mOutline = new Outline( this );
mOutline.setOwner( this );
mHandles << new HandleNorthWest( this );
mHandles << new HandleNorth( this );
mHandles << new HandleNorthEast( this );
mHandles << new HandleEast( this );
mHandles << new HandleSouthEast( this );
mHandles << new HandleSouth( this );
mHandles << new HandleSouthWest( this );
mHandles << new HandleWest( this );
mHandles.push_back( Handle( this, Handle::NW ) );
mHandles.push_back( Handle( this, Handle::N ) );
mHandles.push_back( Handle( this, Handle::NE ) );
mHandles.push_back( Handle( this, Handle::E ) );
mHandles.push_back( Handle( this, Handle::SE ) );
mHandles.push_back( Handle( this, Handle::S ) );
mHandles.push_back( Handle( this, Handle::SW ) );
mHandles.push_back( Handle( this, Handle::W ) );
if ( smDefaultImage == nullptr )
if ( QSvgRenderer( svg ).isValid() )
{
smDefaultImage = new QImage( ":images/checkerboard.png" );
mSvg = svg;
}
mSvg = svg;
mSvgRenderer = new QSvgRenderer( mSvg );
mFilenameNode = TextNode( false, filename );
mImage = nullptr;
}
@@ -213,50 +216,11 @@ namespace glabels
ModelImageObject::ModelImageObject( const ModelImageObject* object ) : ModelObject(object)
{
mFilenameNode = object->mFilenameNode;
if ( object->mImage )
{
mImage = new QImage( *object->mImage );
}
else
{
mImage = nullptr;
}
if ( object->mSvgRenderer )
{
mSvgRenderer = new QSvgRenderer( object->mSvg );
}
else
{
mSvgRenderer = nullptr;
}
mImage = object->mImage;
mSvg = object->mSvg;
}
///
/// Destructor
///
ModelImageObject::~ModelImageObject()
{
delete mOutline;
foreach( Handle* handle, mHandles )
{
delete handle;
}
mHandles.clear();
if ( mImage )
{
delete mImage;
}
if ( mSvgRenderer )
{
delete mSvgRenderer;
}
}
///
/// Clone
///
@@ -293,7 +257,7 @@ namespace glabels
///
/// Image image Property Getter
///
const QImage* ModelImageObject::image() const
const QImage& ModelImageObject::image() const
{
return mImage;
}
@@ -306,19 +270,10 @@ namespace glabels
{
if ( !value.isNull() )
{
if ( mImage )
{
delete mImage;
mImage = nullptr;
}
if ( mSvgRenderer )
{
delete mSvgRenderer;
mSvgRenderer = nullptr;
}
mSvg.clear();
mImage = new QImage(value);
quint16 cs = qChecksum( QByteArray( (const char*)mImage->constBits(), mImage->sizeInBytes() ) );
mImage = value;
quint16 cs = qChecksum( QByteArray( (const char*)mImage.constBits(), mImage.sizeInBytes() ) );
mFilenameNode = TextNode( false, QString("%image_%1%").arg( cs ) );
emit changed();
@@ -333,18 +288,9 @@ namespace glabels
{
if ( !value.isNull() )
{
if ( mImage )
{
delete mImage;
mImage = nullptr;
}
if ( mSvgRenderer )
{
delete mSvgRenderer;
mSvgRenderer = nullptr;
}
mSvg.clear();
mImage = new QImage(value);
mImage = value;
mFilenameNode = TextNode( false, name );
emit changed();
@@ -355,7 +301,7 @@ namespace glabels
///
/// Image svg Property Getter
///
QByteArray ModelImageObject::svg() const
const QByteArray& ModelImageObject::svg() const
{
return mSvg;
}
@@ -368,19 +314,13 @@ namespace glabels
{
if ( !value.isEmpty() )
{
if ( mImage )
{
delete mImage;
mImage = nullptr;
}
if ( mSvgRenderer )
{
delete mSvgRenderer;
mSvgRenderer = nullptr;
}
mImage = QImage(); // clear
mSvg.clear();
mSvg = value;
mSvgRenderer = new QSvgRenderer( mSvg );
if ( QSvgRenderer( value ).isValid() )
{
mSvg = value;
}
mFilenameNode = TextNode( false, name );
emit changed();
@@ -395,15 +335,15 @@ namespace glabels
{
Size size( Distance::pt(72), Distance::pt(72) );
if ( mImage )
if ( !mImage.isNull() )
{
QSize qsize = mImage->size();
QSize qsize = mImage.size();
size.setW( Distance::pt( qsize.width() ) );
size.setH( Distance::pt( qsize.height() ) );
}
else if ( mSvgRenderer )
else if ( !mSvg.isEmpty() )
{
QSize qsize = mSvgRenderer->defaultSize();
QSize qsize = QSvgRenderer( mSvg ).defaultSize();
size.setW( Distance::pt( qsize.width() ) );
size.setH( Distance::pt( qsize.height() ) );
}
@@ -415,23 +355,22 @@ namespace glabels
///
/// Draw shadow of object
///
void ModelImageObject::drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const
void ModelImageObject::drawShadow( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const
{
QRectF destRect( 0, 0, mW.pt(), mH.pt() );
QColor shadowColor = mShadowColorNode.color( record, variables );
shadowColor.setAlphaF( mShadowOpacity );
if ( mImage && mImage->hasAlphaChannel() && (mImage->depth() == 32) )
if ( !mImage.isNull() && mImage.hasAlphaChannel() && (mImage.depth() == 32) )
{
QImage* shadowImage = createShadowImage( *mImage, shadowColor );
painter->drawImage( destRect, *shadowImage );
delete shadowImage;
auto shadowImage = createShadowImage( mImage, shadowColor );
painter->drawImage( destRect, shadowImage );
}
else if ( mImage || mSvgRenderer || inEditor )
else if ( !mImage.isNull() || !mSvg.isEmpty() || inEditor )
{
painter->setBrush( shadowColor );
painter->setPen( QPen( Qt::NoPen ) );
@@ -441,16 +380,14 @@ namespace glabels
else
{
QString filename = mFilenameNode.text( record, variables ).trimmed();
QImage* image;
QSvgRenderer* svgRenderer;
QImage image;
QByteArray svg;
if ( readImageFile( filename, image, svgRenderer, svg ) )
if ( readImageFile( filename, image, svg ) )
{
if ( image && image->hasAlphaChannel() && (image->depth() == 32) )
if ( !image.isNull() && image.hasAlphaChannel() && (image.depth() == 32) )
{
QImage* shadowImage = createShadowImage( *image, shadowColor );
painter->drawImage( destRect, *shadowImage );
delete shadowImage;
QImage shadowImage = createShadowImage( image, shadowColor );
painter->drawImage( destRect, shadowImage );
}
else
{
@@ -459,14 +396,6 @@ namespace glabels
painter->drawRect( destRect );
}
if ( image )
{
delete image;
}
else
{
delete svgRenderer;
}
}
}
}
@@ -475,21 +404,21 @@ namespace glabels
///
/// Draw object itself
///
void ModelImageObject::drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const
void ModelImageObject::drawObject( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const
{
QRectF destRect( 0, 0, mW.pt(), mH.pt() );
if ( inEditor && (mFilenameNode.isField() || (!mImage && !mSvgRenderer) ) )
if ( inEditor && (mFilenameNode.isField() || (mImage.isNull() && mSvg.isEmpty()) ) )
{
//
// Render default place holder image
//
painter->save();
painter->setRenderHint( QPainter::SmoothPixmapTransform, false );
painter->drawImage( destRect, *smDefaultImage );
painter->drawImage( destRect, smDefaultImage );
painter->restore();
//
@@ -540,31 +469,28 @@ namespace glabels
labelText );
}
}
else if ( mImage )
else if ( !mImage.isNull() )
{
painter->drawImage( destRect, *mImage );
painter->drawImage( destRect, mImage );
}
else if ( mSvgRenderer )
else if ( !mSvg.isEmpty() )
{
mSvgRenderer->render( painter, destRect );
QSvgRenderer( mSvg ).render( painter, destRect );
}
else if ( mFilenameNode.isField() )
{
QString filename = mFilenameNode.text( record, variables ).trimmed();
QImage* image;
QSvgRenderer* svgRenderer;
QImage image;
QByteArray svg;
if ( readImageFile( filename, image, svgRenderer, svg ) )
if ( readImageFile( filename, image, svg ) )
{
if ( image )
if ( !image.isNull() )
{
painter->drawImage( destRect, *image );
delete image;
painter->drawImage( destRect, image );
}
else
else if ( !svg.isEmpty() )
{
svgRenderer->render( painter, destRect );
delete svgRenderer;
QSvgRenderer( svg ).render( painter, destRect );
}
}
}
@@ -588,34 +514,26 @@ namespace glabels
///
void ModelImageObject::loadImage()
{
if ( mImage )
{
delete mImage;
mImage = nullptr;
}
if ( mSvgRenderer )
{
delete mSvgRenderer;
mSvgRenderer = nullptr;
}
mImage = QImage(); // clear
mSvg.clear();
if ( !mFilenameNode.isField() )
{
QString filename = mFilenameNode.data();
if ( readImageFile( filename, mImage, mSvgRenderer, mSvg ) )
if ( readImageFile( filename, mImage, mSvg ) )
{
double aspectRatio = 0;
if ( mSvgRenderer )
if ( !mSvg.isEmpty() )
{
// Adjust size based on aspect ratio of SVG image
QRectF rect = mSvgRenderer->viewBoxF();
QRectF rect = QSvgRenderer( mSvg ).viewBoxF();
aspectRatio = rect.width() ? rect.height() / rect.width() : 0;
}
else
{
// Adjust size based on aspect ratio of image
double imageW = mImage->width();
double imageH = mImage->height();
double imageW = mImage.width();
double imageH = mImage.height();
aspectRatio = imageW ? imageH / imageW : 0;
}
@@ -639,12 +557,10 @@ namespace glabels
/// Read an image or svg file
///
bool ModelImageObject::readImageFile( const QString& fileName,
QImage*& image,
QSvgRenderer*& svgRenderer,
QImage& image,
QByteArray& svg ) const
{
image = nullptr;
svgRenderer = nullptr;
image = QImage(); // clear
svg.clear();
if ( !fileName.isEmpty() )
@@ -667,48 +583,41 @@ namespace glabels
{
svg = file.readAll();
file.close();
svgRenderer = new QSvgRenderer( svg );
if ( !svgRenderer->isValid() )
QSvgRenderer renderer( svg );
if ( !renderer.isValid() )
{
delete svgRenderer;
svgRenderer = nullptr;
svg.clear();
}
}
}
else
{
image = new QImage( fileInfo.filePath() );
if ( image->isNull() )
{
delete image;
image = nullptr;
}
image = QImage( fileInfo.filePath() );
}
}
}
return image != nullptr || svgRenderer != nullptr;
return !image.isNull() || !svg.isEmpty();
}
///
/// Create shadow image
///
QImage* ModelImageObject::createShadowImage( const QImage& image,
const QColor& color ) const
QImage ModelImageObject::createShadowImage( const QImage& image,
const QColor& color ) const
{
int r = color.red();
int g = color.green();
int b = color.blue();
int a = color.alpha();
auto* shadow = new QImage( image );
for ( int iy = 0; iy < shadow->height(); iy++ )
QImage shadow = image;
for ( int iy = 0; iy < shadow.height(); iy++ )
{
auto* scanLine = (QRgb*)shadow->scanLine( iy );
auto* scanLine = (QRgb*)shadow.scanLine( iy );
for ( int ix = 0; ix < shadow->width(); ix++ )
for ( int ix = 0; ix < shadow.width(); ix++ )
{
scanLine[ix] = qRgba( r, g, b, (a*qAlpha(scanLine[ix]))/255 );
}
+47 -49
View File
@@ -45,50 +45,50 @@ namespace glabels
public:
ModelImageObject();
ModelImageObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
bool lockAspectRatio,
const TextNode& filenameNode,
ModelImageObject( Distance x0,
Distance y0,
Distance w,
Distance h,
bool lockAspectRatio,
const TextNode& filenameNode,
const QTransform& matrix = QTransform(),
bool shadowState = false,
const Distance& shadowX = 0,
const Distance& shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
bool shadowState = false,
Distance shadowX = 0,
Distance shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
ModelImageObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
bool lockAspectRatio,
const QString& filename,
const QImage& image,
ModelImageObject( Distance x0,
Distance y0,
Distance w,
Distance h,
bool lockAspectRatio,
const QString& filename,
const QImage& image,
const QTransform& matrix = QTransform(),
bool shadowState = false,
const Distance& shadowX = 0,
const Distance& shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
bool shadowState = false,
Distance shadowX = 0,
Distance shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
ModelImageObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
ModelImageObject( Distance x0,
Distance y0,
Distance w,
Distance h,
bool lockAspectRatio,
const QString& filename,
const QByteArray& svg,
const QTransform& matrix = QTransform(),
bool shadowState = false,
const Distance& shadowX = 0,
const Distance& shadowY = 0,
Distance shadowX = 0,
Distance shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
ModelImageObject( const ModelImageObject* object );
~ModelImageObject() override;
virtual ~ModelImageObject() = default;
///////////////////////////////////////////////////////////////
@@ -110,14 +110,14 @@ namespace glabels
//
// Image Property: image
//
const QImage* image() const override;
const QImage& image() const override;
void setImage( const QImage& value ) override;
void setImage( const QString& name, const QImage& value ) override;
//
// Image Property: svg
//
QByteArray svg() const override;
const QByteArray& svg() const override;
void setSvg( const QString& name, const QByteArray& value ) override;
//
@@ -135,15 +135,15 @@ namespace glabels
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
void drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
void drawShadow( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const override;
void drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
void drawObject( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const override;
QPainterPath hoverPath( double scale ) const override;
@@ -154,24 +154,22 @@ namespace glabels
void loadImage();
bool readImageFile( const QString& fileName,
QImage*& image,
QSvgRenderer*& svgRenderer,
QImage& image,
QByteArray& svg ) const;
QImage* createShadowImage( const QImage& image,
const QColor& color ) const;
QImage createShadowImage( const QImage& image,
const QColor& color ) const;
///////////////////////////////////////////////////////////////
// Private Members
///////////////////////////////////////////////////////////////
protected:
TextNode mFilenameNode;
QImage* mImage;
QSvgRenderer* mSvgRenderer;
QByteArray mSvg;
TextNode mFilenameNode;
QImage mImage;
QByteArray mSvg;
static QImage* smDefaultImage;
static QImage smDefaultImage;
};
+35 -49
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ModelLineObject.h"
#include <QBrush>
@@ -43,10 +44,8 @@ namespace glabels
///
ModelLineObject::ModelLineObject()
{
mOutline = nullptr;
mHandles << new HandleP1( this );
mHandles << new HandleP2( this );
mHandles.push_back( Handle( this, Handle::P1 ) );
mHandles.push_back( Handle( this, Handle::P2 ) );
mLineWidth = 1.0;
mLineColorNode = ColorNode( QColor( 0, 0, 0 ) );
@@ -56,32 +55,32 @@ namespace glabels
///
/// Constructor
///
ModelLineObject::ModelLineObject( const Distance& x0,
const Distance& y0,
const Distance& dx,
const Distance& dy,
const Distance& lineWidth,
const ColorNode& lineColorNode,
ModelLineObject::ModelLineObject( Distance x0,
Distance y0,
Distance dx,
Distance dy,
Distance lineWidth,
const ColorNode& lineColorNode,
const QTransform& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: ModelObject( x0, y0, dx, dy, false /*lockAspectRatio*/,
bool shadowState,
Distance shadowX,
Distance shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: ModelObject( x0,
y0,
dx,
dy,
false /*lockAspectRatio*/,
matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
shadowState,
shadowX,
shadowY,
shadowOpacity,
shadowColorNode )
{
mOutline = new Outline( this );
mHandles << new HandleNorthWest( this );
mHandles << new HandleNorth( this );
mHandles << new HandleNorthEast( this );
mHandles << new HandleEast( this );
mHandles << new HandleSouthEast( this );
mHandles << new HandleSouth( this );
mHandles << new HandleSouthWest( this );
mHandles << new HandleWest( this );
mHandles.push_back( Handle( this, Handle::P1 ) );
mHandles.push_back( Handle( this, Handle::P2 ) );
mLineWidth = lineWidth;
mLineColorNode = lineColorNode;
@@ -99,19 +98,6 @@ namespace glabels
}
///
/// Destructor
///
ModelLineObject::~ModelLineObject()
{
foreach( Handle* handle, mHandles )
{
delete handle;
}
mHandles.clear();
}
///
/// Clone
///
@@ -133,7 +119,7 @@ namespace glabels
///
/// Line Width Property Setter
///
void ModelLineObject::setLineWidth( const Distance& value )
void ModelLineObject::setLineWidth( Distance value )
{
if ( mLineWidth != value )
{
@@ -186,10 +172,10 @@ namespace glabels
///
/// Draw shadow of object
///
void ModelLineObject::drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const
void ModelLineObject::drawShadow( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const
{
QColor lineColor = mLineColorNode.color( record, variables );
QColor shadowColor = mShadowColorNode.color( record, variables );
@@ -207,10 +193,10 @@ namespace glabels
///
/// Draw object itself
///
void ModelLineObject::drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const
void ModelLineObject::drawObject( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const
{
QColor lineColor = mLineColorNode.color( record, variables );
+21 -21
View File
@@ -43,22 +43,22 @@ namespace glabels
public:
ModelLineObject();
ModelLineObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const Distance& lineWidth,
const ColorNode& lineColorNode,
ModelLineObject( Distance x0,
Distance y0,
Distance w,
Distance h,
Distance lineWidth,
const ColorNode& lineColorNode,
const QTransform& matrix = QTransform(),
bool shadowState = false,
const Distance& shadowX = 0,
const Distance& shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
bool shadowState = false,
Distance shadowX = 0,
Distance shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
ModelLineObject( const ModelLineObject* object );
~ModelLineObject() override;
virtual ~ModelLineObject() = default;
///////////////////////////////////////////////////////////////
@@ -75,7 +75,7 @@ namespace glabels
// Line Property: lineWidth
//
Distance lineWidth() const override;
void setLineWidth( const Distance& value ) override;
void setLineWidth( Distance value ) override;
//
@@ -97,15 +97,15 @@ namespace glabels
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
void drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
void drawShadow( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const override;
void drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
void drawObject( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const override;
QPainterPath hoverPath( double scale ) const override;
+66 -78
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ModelObject.h"
#include "ColorNode.h"
@@ -43,7 +44,8 @@ namespace glabels
///
/// Constructor
///
ModelObject::ModelObject() : QObject(nullptr)
ModelObject::ModelObject()
: QObject(nullptr)
{
mId = msNextId++;
@@ -61,25 +63,24 @@ namespace glabels
mShadowOpacity = 0.5;
mSelectedFlag = false;
mOutline = nullptr;
}
///
/// Constructor
///
ModelObject::ModelObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
bool lockAspectRatio,
ModelObject::ModelObject( Distance x0,
Distance y0,
Distance w,
Distance h,
bool lockAspectRatio,
const QTransform& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode ) : QObject(nullptr)
bool shadowState,
Distance shadowX,
Distance shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: QObject(nullptr)
{
mId = msNextId++;
@@ -97,8 +98,6 @@ namespace glabels
mShadowOpacity = shadowOpacity;
mSelectedFlag = false;
mOutline = nullptr;
}
@@ -123,33 +122,21 @@ namespace glabels
mShadowOpacity = object->mShadowOpacity;
mShadowColorNode = object->mShadowColorNode;
foreach ( Handle* handle, object->mHandles )
if ( object->mOutline.isEnabled() )
{
mHandles.append( handle->clone( this ) );
mOutline = object->mOutline;
mOutline.setOwner( this );
}
for ( auto& handle : object->mHandles )
{
mHandles.push_back( Handle( this, handle.location() ) );
}
if ( object->mOutline )
{
mOutline = object->mOutline->clone( this );
}
else
{
mOutline = nullptr;
}
mMatrix = object->mMatrix;
}
///
/// Destructor
///
ModelObject::~ModelObject()
{
// empty
}
///
/// ID Property Getter
///
@@ -198,7 +185,7 @@ namespace glabels
///
/// X0 Property Setter
///
void ModelObject::setX0( const Distance& value )
void ModelObject::setX0( Distance value )
{
if ( mX0 != value )
{
@@ -220,7 +207,7 @@ namespace glabels
///
/// Y0 Property Setter
///
void ModelObject::setY0( const Distance& value )
void ModelObject::setY0( Distance value )
{
if ( mY0 != value )
{
@@ -242,7 +229,7 @@ namespace glabels
///
/// W (Width) Property Setter
///
void ModelObject::setW( const Distance& value )
void ModelObject::setW( Distance value )
{
if ( mW != value )
{
@@ -265,7 +252,7 @@ namespace glabels
///
/// H (Height) Property Setter
///
void ModelObject::setH( const Distance& value )
void ModelObject::setH( Distance value )
{
if ( mH != value )
{
@@ -354,7 +341,7 @@ namespace glabels
///
/// Shadow X Property Setter
///
void ModelObject::setShadowX( const Distance& value )
void ModelObject::setShadowX( Distance value )
{
if ( mShadowX != value )
{
@@ -376,7 +363,7 @@ namespace glabels
///
/// Shadow Y Property Setter
///
void ModelObject::setShadowY( const Distance& value )
void ModelObject::setShadowY( Distance value )
{
if ( mShadowY != value )
{
@@ -704,9 +691,10 @@ namespace glabels
/// Virtual Image Property Default Getter
/// (Overridden by concrete class)
///
const QImage* ModelObject::image() const
const QImage& ModelObject::image() const
{
return nullptr;
static QImage dummyImage;
return dummyImage;
}
@@ -734,9 +722,10 @@ namespace glabels
/// Virtual SVG Property Default Getter
/// (Overridden by concrete class)
///
QByteArray ModelObject::svg() const
const QByteArray& ModelObject::svg() const
{
return QByteArray();
static QByteArray dummySvg;
return dummySvg;
}
@@ -764,7 +753,7 @@ namespace glabels
/// Virtual Line Width Property Default Setter
/// (Overridden by concrete class)
///
void ModelObject::setLineWidth( const Distance& value )
void ModelObject::setLineWidth( Distance value )
{
// empty
}
@@ -973,8 +962,8 @@ namespace glabels
///
/// Set Absolute Position
///
void ModelObject::setPosition( const Distance& x0,
const Distance& y0 )
void ModelObject::setPosition( Distance x0,
Distance y0 )
{
if ( ( mX0 != x0 ) || ( mY0 != y0 ) )
{
@@ -989,8 +978,8 @@ namespace glabels
///
/// Set Relative Position
///
void ModelObject::setPositionRelative( const Distance& dx,
const Distance& dy )
void ModelObject::setPositionRelative( Distance dx,
Distance dy )
{
if ( ( dx != 0 ) || ( dy != 0 ) )
{
@@ -1014,8 +1003,8 @@ namespace glabels
///
/// Set Size
///
void ModelObject::setSize( const Distance& w,
const Distance& h )
void ModelObject::setSize( Distance w,
Distance h )
{
mW = w;
mH = h;
@@ -1028,7 +1017,7 @@ namespace glabels
///
/// Set Size
///
void ModelObject::setSize( const Size& size )
void ModelObject::setSize( Size size )
{
mW = size.w();
mH = size.h();
@@ -1041,8 +1030,8 @@ namespace glabels
///
/// Set Size (But Maintain Current Aspect Ratio)
///
void ModelObject::setSizeHonorAspect( const Distance& w,
const Distance& h )
void ModelObject::setSizeHonorAspect( Distance w,
Distance h )
{
double aspectRatio = mH / mW;
Distance wNew = w;
@@ -1064,7 +1053,7 @@ namespace glabels
///
/// Set Width (But Maintain Current Aspect Ratio)
///
void ModelObject::setWHonorAspect( const Distance& w )
void ModelObject::setWHonorAspect( Distance w )
{
double aspectRatio = mH / mW;
Distance h = w * aspectRatio;
@@ -1083,7 +1072,7 @@ namespace glabels
///
/// Set Height (But Maintain Current Aspect Ratio)
///
void ModelObject::setHHonorAspect( const Distance& h )
void ModelObject::setHHonorAspect( Distance h )
{
double aspectRatio = mH / mW;
Distance w = h / aspectRatio;
@@ -1169,9 +1158,9 @@ namespace glabels
///
/// Is this object located at x,y?
///
bool ModelObject::isLocatedAt( double scale,
const Distance& x,
const Distance& y ) const
bool ModelObject::isLocatedAt( double scale,
Distance x,
Distance y ) const
{
QPointF p( x.pt(), y.pt() );
@@ -1185,9 +1174,9 @@ namespace glabels
{
return true;
}
else if ( isSelected() && mOutline )
else if ( isSelected() )
{
if ( mOutline->hoverPath( scale ).contains( p ) )
if ( mOutline.hoverPath( scale ).contains( p ) )
{
return true;
}
@@ -1200,18 +1189,20 @@ namespace glabels
///
/// Is one of this object's handles locate at x,y? If so, return it.
///
Handle* ModelObject::handleAt( double scale,
const Distance& x,
const Distance& y ) const
const Handle& ModelObject::handleAt( double scale,
Distance x,
Distance y ) const
{
static Handle nullHandle;
if ( mSelectedFlag )
{
QPointF p( x.pt(), y.pt() );
p -= QPointF( mX0.pt(), mY0.pt() ); // Translate point to x0,y0
foreach ( Handle* handle, mHandles )
for ( auto& handle : mHandles )
{
QPainterPath handlePath = mMatrix.map( handle->path( scale ) );
QPainterPath handlePath = mMatrix.map( handle.path( scale ) );
if ( handlePath.contains( p ) )
{
return handle;
@@ -1219,17 +1210,17 @@ namespace glabels
}
}
return nullptr;
return nullHandle;
}
///
/// Draw object + shadow
///
void ModelObject::draw( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const
void ModelObject::draw( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const
{
painter->save();
painter->translate( mX0.pt(), mY0.pt() );
@@ -1260,14 +1251,11 @@ namespace glabels
painter->translate( mX0.pt(), mY0.pt() );
painter->setTransform( mMatrix, true );
if ( mOutline )
{
mOutline->draw( painter );
}
mOutline.draw( painter );
foreach( Handle* handle, mHandles )
for( auto& handle : mHandles )
{
handle->draw( painter, scale );
handle.draw( painter, scale );
}
painter->restore();
+48 -44
View File
@@ -24,7 +24,7 @@
#include "ColorNode.h"
#include "Distance.h"
#include "Handles.h"
#include "Handle.h"
#include "Outline.h"
#include "TextNode.h"
#include "Variables.h"
@@ -37,6 +37,9 @@
#include <QTransform>
#include <QPainter>
#include <list>
#include <memory>
namespace glabels
{
@@ -61,22 +64,22 @@ namespace glabels
protected:
ModelObject();
ModelObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
bool lockAspectRatio = false,
ModelObject( Distance x0,
Distance y0,
Distance w,
Distance h,
bool lockAspectRatio = false,
const QTransform& matrix = QTransform(),
bool shadowState = false,
const Distance& shadowX = 0,
const Distance& shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
bool shadowState = false,
Distance shadowX = 0,
Distance shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
ModelObject( const ModelObject* object );
public:
~ModelObject() override;
virtual ~ModelObject() = default;
///////////////////////////////////////////////////////////////
@@ -114,28 +117,28 @@ namespace glabels
// x0 Property ( x coordinate of origin )
//
Distance x0() const;
void setX0( const Distance& value );
void setX0( Distance value );
//
// y0 Property ( y coordinate of origin )
//
Distance y0() const;
void setY0( const Distance& value );
void setY0( Distance value );
//
// w Property ( width of bounding box )
//
Distance w() const;
void setW( const Distance& value );
void setW( Distance value );
//
// h Property ( height of bounding box )
//
Distance h() const;
void setH( const Distance& value );
void setH( Distance value );
//
@@ -163,14 +166,14 @@ namespace glabels
// Shadow x Offset Property
//
Distance shadowX() const;
void setShadowX( const Distance& value );
void setShadowX( Distance value );
//
// Shadow y Offset Property
//
Distance shadowY() const;
void setShadowY( const Distance& value );
void setShadowY( Distance value );
//
@@ -295,7 +298,7 @@ namespace glabels
//
// Virtual Image Property: image
//
virtual const QImage* image() const;
virtual const QImage& image() const;
virtual void setImage( const QImage& value );
virtual void setImage( const QString& name, const QImage& value );
@@ -303,7 +306,7 @@ namespace glabels
//
// Virtual Image Property: svg
//
virtual QByteArray svg() const;
virtual const QByteArray& svg() const;
virtual void setSvg( const QString& name, const QByteArray& value );
@@ -315,7 +318,7 @@ namespace glabels
// Virtual Shape Property: lineWidth
//
virtual Distance lineWidth() const;
virtual void setLineWidth( const Distance& value );
virtual void setLineWidth( Distance value );
//
@@ -392,43 +395,43 @@ namespace glabels
// Position and Size methods
///////////////////////////////////////////////////////////////
public:
void setPosition( const Distance& x0, const Distance& y0 );
void setPositionRelative( const Distance& dx, const Distance& dy );
void setPosition( Distance x0, Distance y0 );
void setPositionRelative( Distance dx, Distance dy );
Size size() const;
void setSize( const Distance& w, const Distance& h );
void setSize( const Size& size );
void setSizeHonorAspect( const Distance& w, const Distance& h );
void setWHonorAspect( const Distance& w );
void setHHonorAspect( const Distance& h );
void setSize( Distance w, Distance h );
void setSize( Size size );
void setSizeHonorAspect( Distance w, Distance h );
void setWHonorAspect( Distance w );
void setHHonorAspect( Distance h );
Region getExtent();
void rotate( double thetaDegs );
void flipHoriz();
void flipVert();
bool isLocatedAt( double scale, const Distance& x, const Distance& y ) const;
Handle* handleAt( double scale, const Distance& x, const Distance& y ) const;
bool isLocatedAt( double scale, Distance x, Distance y ) const;
const Handle& handleAt( double scale, Distance x, Distance y ) const;
///////////////////////////////////////////////////////////////
// Drawing operations
///////////////////////////////////////////////////////////////
public:
void draw( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const;
void draw( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const;
void drawSelectionHighlight( QPainter* painter, double scale ) const;
protected:
virtual void drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const = 0;
virtual void drawShadow( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const = 0;
virtual void drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const = 0;
virtual void drawObject( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const = 0;
virtual QPainterPath hoverPath( double scale ) const = 0;
@@ -453,8 +456,9 @@ namespace glabels
double mShadowOpacity;
ColorNode mShadowColorNode;
QList<Handle*> mHandles;
Outline* mOutline;
Outline mOutline;
QList<Handle> mHandles;
///////////////////////////////////////////////////////////////
+42 -49
View File
@@ -34,16 +34,16 @@ namespace glabels
///
ModelShapeObject::ModelShapeObject()
{
mOutline = new Outline( this );
mOutline.setOwner( this );
mHandles << new HandleNorthWest( this );
mHandles << new HandleNorth( this );
mHandles << new HandleNorthEast( this );
mHandles << new HandleEast( this );
mHandles << new HandleSouthEast( this );
mHandles << new HandleSouth( this );
mHandles << new HandleSouthWest( this );
mHandles << new HandleWest( this );
mHandles.push_back( Handle( this, Handle::NW ) );
mHandles.push_back( Handle( this, Handle::N ) );
mHandles.push_back( Handle( this, Handle::NE ) );
mHandles.push_back( Handle( this, Handle::E ) );
mHandles.push_back( Handle( this, Handle::SE ) );
mHandles.push_back( Handle( this, Handle::S ) );
mHandles.push_back( Handle( this, Handle::SW ) );
mHandles.push_back( Handle( this, Handle::W ) );
mLineWidth = 1.0;
mLineColorNode = ColorNode( QColor( 0, 0, 0 ) );
@@ -54,34 +54,42 @@ namespace glabels
///
/// Constructor
///
ModelShapeObject::ModelShapeObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
bool lockAspectRatio,
const Distance& lineWidth,
const ColorNode& lineColorNode,
const ColorNode& fillColorNode,
ModelShapeObject::ModelShapeObject( Distance x0,
Distance y0,
Distance w,
Distance h,
bool lockAspectRatio,
Distance lineWidth,
const ColorNode& lineColorNode,
const ColorNode& fillColorNode,
const QTransform& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: ModelObject( x0, y0, w, h, lockAspectRatio,
bool shadowState,
Distance shadowX,
Distance shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: ModelObject( x0,
y0,
w,
h,
lockAspectRatio,
matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
shadowState,
shadowX,
shadowY,
shadowOpacity,
shadowColorNode )
{
mOutline = new Outline( this );
mOutline.setOwner( this );
mHandles << new HandleNorthWest( this );
mHandles << new HandleNorth( this );
mHandles << new HandleNorthEast( this );
mHandles << new HandleEast( this );
mHandles << new HandleSouthEast( this );
mHandles << new HandleSouth( this );
mHandles << new HandleSouthWest( this );
mHandles << new HandleWest( this );
mHandles.push_back( Handle( this, Handle::NW ) );
mHandles.push_back( Handle( this, Handle::N ) );
mHandles.push_back( Handle( this, Handle::NE ) );
mHandles.push_back( Handle( this, Handle::E ) );
mHandles.push_back( Handle( this, Handle::SE ) );
mHandles.push_back( Handle( this, Handle::S ) );
mHandles.push_back( Handle( this, Handle::SW ) );
mHandles.push_back( Handle( this, Handle::W ) );
mLineWidth = lineWidth;
mLineColorNode = lineColorNode;
@@ -100,21 +108,6 @@ namespace glabels
}
///
/// Destructor
///
ModelShapeObject::~ModelShapeObject()
{
delete mOutline;
foreach( Handle* handle, mHandles )
{
delete handle;
}
mHandles.clear();
}
///
/// Line Width Property Getter
///
@@ -127,7 +120,7 @@ namespace glabels
///
/// Line Width Property Setter
///
void ModelShapeObject::setLineWidth( const Distance& value )
void ModelShapeObject::setLineWidth( Distance value )
{
if ( mLineWidth != value )
{
+15 -15
View File
@@ -43,24 +43,24 @@ namespace glabels
protected:
ModelShapeObject();
ModelShapeObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
bool lockAspectRatio,
const Distance& lineWidth,
const ColorNode& lineColorNode,
const ColorNode& fillColorNode,
ModelShapeObject( Distance x0,
Distance y0,
Distance w,
Distance h,
bool lockAspectRatio,
Distance lineWidth,
const ColorNode& lineColorNode,
const ColorNode& fillColorNode,
const QTransform& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode );
bool shadowState,
Distance shadowX,
Distance shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode );
ModelShapeObject( const ModelShapeObject* object );
public:
~ModelShapeObject() override;
virtual ~ModelShapeObject() = default;
///////////////////////////////////////////////////////////////
@@ -71,7 +71,7 @@ namespace glabels
// Shape Property: lineWidth
//
Distance lineWidth() const override;
void setLineWidth( const Distance& value ) override;
void setLineWidth( Distance value ) override;
//
+59 -54
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ModelTextObject.h"
#include "Size.h"
@@ -49,16 +50,16 @@ namespace glabels
///
ModelTextObject::ModelTextObject()
{
mOutline = new Outline( this );
mOutline.setOwner( this );
mHandles << new HandleNorthWest( this );
mHandles << new HandleNorth( this );
mHandles << new HandleNorthEast( this );
mHandles << new HandleEast( this );
mHandles << new HandleSouthEast( this );
mHandles << new HandleSouth( this );
mHandles << new HandleSouthWest( this );
mHandles << new HandleWest( this );
mHandles.push_back( Handle( this, Handle::NW ) );
mHandles.push_back( Handle( this, Handle::N ) );
mHandles.push_back( Handle( this, Handle::NE ) );
mHandles.push_back( Handle( this, Handle::E ) );
mHandles.push_back( Handle( this, Handle::SE ) );
mHandles.push_back( Handle( this, Handle::S ) );
mHandles.push_back( Handle( this, Handle::SW ) );
mHandles.push_back( Handle( this, Handle::W ) );
mText = "";
mFontFamily = "Sans";
@@ -78,10 +79,10 @@ namespace glabels
///
/// Constructor
///
ModelTextObject::ModelTextObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
ModelTextObject::ModelTextObject( Distance x0,
Distance y0,
Distance w,
Distance h,
bool lockAspectRatio,
const QString& text,
const QString& fontFamily,
@@ -97,24 +98,32 @@ namespace glabels
bool textAutoShrink,
const QTransform& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
Distance shadowX,
Distance shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: ModelObject( x0, y0, w, h, lockAspectRatio,
: ModelObject( x0,
y0,
w,
h,
lockAspectRatio,
matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
shadowState,
shadowX,
shadowY,
shadowOpacity,
shadowColorNode )
{
mOutline = new Outline( this );
mOutline.setOwner( this );
mHandles << new HandleNorthWest( this );
mHandles << new HandleNorth( this );
mHandles << new HandleNorthEast( this );
mHandles << new HandleEast( this );
mHandles << new HandleSouthEast( this );
mHandles << new HandleSouth( this );
mHandles << new HandleSouthWest( this );
mHandles << new HandleWest( this );
mHandles.push_back( Handle( this, Handle::NW ) );
mHandles.push_back( Handle( this, Handle::N ) );
mHandles.push_back( Handle( this, Handle::NE ) );
mHandles.push_back( Handle( this, Handle::E ) );
mHandles.push_back( Handle( this, Handle::SE ) );
mHandles.push_back( Handle( this, Handle::S ) );
mHandles.push_back( Handle( this, Handle::SW ) );
mHandles.push_back( Handle( this, Handle::W ) );
mText = text;
mFontFamily = fontFamily;
@@ -161,13 +170,8 @@ namespace glabels
///
ModelTextObject::~ModelTextObject()
{
delete mOutline;
foreach( Handle* handle, mHandles )
{
delete handle;
}
mHandles.clear();
qDeleteAll( mEditorLayouts );
mEditorLayouts.clear();
}
@@ -484,21 +488,21 @@ namespace glabels
QRectF boundingRect;
for ( int i = 0; i < document.blockCount(); i++ )
{
QTextLayout* layout = new QTextLayout( document.findBlockByNumber(i).text() );
QTextLayout layout( document.findBlockByNumber(i).text() );
layout->setFont( font );
layout->setTextOption( textOption );
layout->setCacheEnabled(true);
layout.setFont( font );
layout.setTextOption( textOption );
layout.setCacheEnabled(true);
layout->beginLayout();
for ( QTextLine l = layout->createLine(); l.isValid(); l = layout->createLine() )
layout.beginLayout();
for ( QTextLine l = layout.createLine(); l.isValid(); l = layout.createLine() )
{
l.setPosition( QPointF( x, y ) );
y += dy;
}
layout->endLayout();
layout.endLayout();
boundingRect = layout->boundingRect().united( boundingRect );
boundingRect = layout.boundingRect().united( boundingRect );
}
return Size( boundingRect.width() + 2*marginPts, boundingRect.height() + 2*marginPts );
@@ -517,10 +521,10 @@ namespace glabels
///
/// Draw shadow of object
///
void ModelTextObject::drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const
void ModelTextObject::drawShadow( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const
{
QColor textColor = mTextColorNode.color( record, variables );
@@ -544,10 +548,10 @@ namespace glabels
///
/// Draw object itself
///
void ModelTextObject::drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const
void ModelTextObject::drawObject( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const
{
QColor textColor = mTextColorNode.color( record, variables );
@@ -697,10 +701,10 @@ namespace glabels
/// Draw text in final printout or preview
///
void
ModelTextObject::drawText( QPainter* painter,
const QColor& color,
merge::Record* record,
Variables* variables ) const
ModelTextObject::drawText( QPainter* painter,
const QColor& color,
const merge::Record& record,
const Variables& variables ) const
{
painter->save();
@@ -794,7 +798,8 @@ namespace glabels
/// Determine auto shrink font size
///
double
ModelTextObject::autoShrinkFontSize( merge::Record* record, Variables* variables ) const
ModelTextObject::autoShrinkFontSize( const merge::Record& record,
const Variables& variables ) const
{
QFont font;
font.setFamily( mFontFamily );
+21 -21
View File
@@ -46,10 +46,10 @@ namespace glabels
public:
ModelTextObject();
ModelTextObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
ModelTextObject( Distance x0,
Distance y0,
Distance w,
Distance h,
bool lockAspectRatio,
const QString& text,
const QString& fontFamily,
@@ -65,14 +65,14 @@ namespace glabels
bool textAutoShrink,
const QTransform& matrix = QTransform(),
bool shadowState = false,
const Distance& shadowX = 0,
const Distance& shadowY = 0,
Distance shadowX = 0,
Distance shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
ModelTextObject( const ModelTextObject* object );
~ModelTextObject() override;
virtual ~ModelTextObject();
///////////////////////////////////////////////////////////////
@@ -186,15 +186,15 @@ namespace glabels
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
void drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
void drawShadow( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const override;
void drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
void drawObject( QPainter* painter,
bool inEditor,
const merge::Record& record,
const Variables& variables ) const override;
QPainterPath hoverPath( double scale ) const override;
@@ -209,13 +209,13 @@ namespace glabels
void drawTextInEditor( QPainter* painter,
const QColor& color ) const;
void drawText( QPainter* painter,
const QColor& color,
merge::Record* record,
Variables* variables ) const;
void drawText( QPainter* painter,
const QColor& color,
const merge::Record& record,
const Variables& variables ) const;
double autoShrinkFontSize( merge::Record* record,
Variables* variables ) const;
double autoShrinkFontSize( const merge::Record& record,
const Variables& variables ) const;
///////////////////////////////////////////////////////////////
+28 -42
View File
@@ -45,11 +45,12 @@ namespace glabels
///
/// Outline Constructor
/// Set owner and enable outline
///
Outline::Outline( ModelObject* owner )
: mOwner(owner)
void Outline::setOwner( ModelObject* owner )
{
mOwner = owner;
mDashes << dashSize << dashSize;
mPen1.setColor( outlineColor1 );
@@ -68,32 +69,11 @@ namespace glabels
///
/// Outline Copy constructor
/// Is enabled? (I.e. not all objects have an outline (e.g. line objects))
///
Outline::Outline( const Outline* outline, ModelObject* newOwner )
: mOwner(newOwner)
bool Outline::isEnabled() const
{
mDashes = outline->mDashes;
mPen1 = outline->mPen1;
mPen2 = outline->mPen2;
}
///
/// Outline Destructor
///
Outline::~Outline()
{
// empty
}
///
/// Clone Outline
///
Outline* Outline::clone( ModelObject* newOwner ) const
{
return new Outline( this, newOwner );
return mOwner;
}
@@ -102,17 +82,20 @@ namespace glabels
///
void Outline::draw( QPainter* painter ) const
{
painter->save();
if ( mOwner )
{
painter->save();
painter->setBrush( Qt::NoBrush );
painter->setBrush( Qt::NoBrush );
painter->setPen( mPen1 );
painter->drawRect( QRectF( 0, 0, mOwner->w().pt(), mOwner->h().pt() ) );
painter->setPen( mPen1 );
painter->drawRect( QRectF( 0, 0, mOwner->w().pt(), mOwner->h().pt() ) );
painter->setPen( mPen2 );
painter->drawRect( QRectF( 0, 0, mOwner->w().pt(), mOwner->h().pt() ) );
painter->setPen( mPen2 );
painter->drawRect( QRectF( 0, 0, mOwner->w().pt(), mOwner->h().pt() ) );
painter->restore();
painter->restore();
}
}
@@ -121,16 +104,19 @@ namespace glabels
///
QPainterPath Outline::hoverPath( double scale ) const
{
double s = 1 / scale;
QPainterPath path;
path.addRect( -s*slopPixels, -s*slopPixels,
mOwner->w().pt()+s*2*slopPixels, mOwner->h().pt()+s*2*slopPixels );
path.closeSubpath();
path.addRect( s*slopPixels, s*slopPixels,
mOwner->w().pt()-s*2*slopPixels, mOwner->h().pt()-s*2*slopPixels );
if ( mOwner )
{
double s = 1 / scale;
path.addRect( -s*slopPixels, -s*slopPixels,
mOwner->w().pt()+s*2*slopPixels, mOwner->h().pt()+s*2*slopPixels );
path.closeSubpath();
path.addRect( s*slopPixels, s*slopPixels,
mOwner->w().pt()-s*2*slopPixels, mOwner->h().pt()-s*2*slopPixels );
}
return path;
}
+10 -8
View File
@@ -25,6 +25,8 @@
#include <QPainter>
#include <QPainterPath>
#include <memory>
namespace glabels
{
@@ -36,7 +38,7 @@ namespace glabels
///
/// Outline Base Class
/// Outline Class
///
class Outline
{
@@ -44,15 +46,15 @@ namespace glabels
// Lifecycle Methods
////////////////////////////
public:
Outline( ModelObject* owner );
Outline( const Outline* outline, ModelObject* newOwner );
virtual ~Outline();
Outline() = default;
~Outline() = default;
////////////////////////////
// Duplication
// Ownership
////////////////////////////
Outline* clone( ModelObject* newOwner ) const;
void setOwner( ModelObject* owner );
bool isEnabled() const;
////////////////////////////
@@ -67,7 +69,7 @@ namespace glabels
// Private Data
////////////////////////////
private:
ModelObject* mOwner;
ModelObject* mOwner{ nullptr };
QVector<qreal> mDashes;
QPen mPen1;
+29 -29
View File
@@ -62,7 +62,6 @@ namespace glabels
connect( mModel, SIGNAL(changed()), this, SLOT(onModelChanged()) );
onModelChanged();
mVariables = mModel->variables();
}
@@ -168,7 +167,7 @@ namespace glabels
{
if ( mModel )
{
return QRectF( 0, 0, mModel->tmplate()->pageWidth().pt(), mModel->tmplate()->pageHeight().pt() );
return QRectF( 0, 0, mModel->tmplate().pageWidth().pt(), mModel->tmplate().pageHeight().pt() );
}
else
{
@@ -232,7 +231,7 @@ namespace glabels
///
void PageRenderer::print( QPrinter* printer ) const
{
QSizeF pageSize( mModel->tmplate()->pageWidth().pt(), mModel->tmplate()->pageHeight().pt() );
QSizeF pageSize( mModel->tmplate().pageWidth().pt(), mModel->tmplate().pageHeight().pt() );
printer->setPageSize( QPageSize(pageSize, QPageSize::Point) );
printer->setFullPage( true );
printer->setPageMargins( QMarginsF(0, 0, 0, 0), QPageLayout::Point );
@@ -298,7 +297,8 @@ namespace glabels
int iCopy = 0;
int iItem = mStartItem;
int iCurrentPage = 0;
mVariables->resetVariables();
Variables variables( mModel->constVariables() );
while ( (iCopy < mNCopies) && (iCurrentPage <= iPage) )
{
@@ -313,7 +313,7 @@ namespace glabels
painter->save();
clipLabel( painter );
printLabel( painter, nullptr, mVariables );
printLabel( painter, merge::NullRecord(), variables );
painter->restore(); // From before clip
@@ -328,11 +328,11 @@ namespace glabels
iCurrentPage = iItem / mNItemsPerPage;
// User variable book keeping
mVariables->incrementVariablesOnItem();
mVariables->incrementVariablesOnCopy();
variables.incrementVariablesOnItem();
variables.incrementVariablesOnCopy();
if ( (iItem % mNItemsPerPage) == 0 /* starting a new page */ )
{
mVariables->incrementVariablesOnPage();
variables.incrementVariablesOnPage();
}
}
}
@@ -346,7 +346,7 @@ namespace glabels
int iItem = mStartItem;
int iCurrentPage = 0;
const QList<merge::Record*> records = mMerge->selectedRecords();
auto records = mMerge->selectedRecords();
int iRecord = 0;
int nRecords = records.size();
@@ -355,7 +355,7 @@ namespace glabels
return;
}
mVariables->resetVariables();
Variables variables( mModel->constVariables() );
while ( (iCopy < mNCopies) && (iCurrentPage <= iPage) )
{
@@ -370,7 +370,7 @@ namespace glabels
painter->save();
clipLabel( painter );
printLabel( painter, records[iRecord], mVariables );
printLabel( painter, records[iRecord], variables );
painter->restore(); // From before clip
@@ -400,14 +400,14 @@ namespace glabels
iCurrentPage = iItem / mNItemsPerPage;
// User variable book keeping
mVariables->incrementVariablesOnItem();
variables.incrementVariablesOnItem();
if ( iRecord == 0 )
{
mVariables->incrementVariablesOnCopy();
variables.incrementVariablesOnCopy();
}
if ( (iItem % mNItemsPerPage) == 0 /* starting a new page */ )
{
mVariables->incrementVariablesOnPage();
variables.incrementVariablesOnPage();
}
}
}
@@ -421,7 +421,7 @@ namespace glabels
int iItem = mStartItem;
int iCurrentPage = 0;
const QList<merge::Record*> records = mMerge->selectedRecords();
auto records = mMerge->selectedRecords();
int iRecord = 0;
int nRecords = records.size();
@@ -430,7 +430,7 @@ namespace glabels
return;
}
mVariables->resetVariables();
Variables variables( mModel->constVariables() );
while ( (iRecord < nRecords) && (iCurrentPage <= iPage) )
{
@@ -445,7 +445,7 @@ namespace glabels
painter->save();
clipLabel( painter );
printLabel( painter, records[iRecord], mVariables );
printLabel( painter, records[iRecord], variables );
painter->restore(); // From before clip
@@ -475,15 +475,15 @@ namespace glabels
iCurrentPage = iItem / mNItemsPerPage;
// User variable book keeping
mVariables->incrementVariablesOnItem();
mVariables->incrementVariablesOnCopy();
variables.incrementVariablesOnItem();
variables.incrementVariablesOnCopy();
if ( iCopy == 0 )
{
mVariables->resetOnCopyVariables();
variables.resetOnCopyVariables();
}
if ( (iItem % mNItemsPerPage) == 0 /* starting a new page */ )
{
mVariables->incrementVariablesOnPage();
variables.incrementVariablesOnPage();
}
}
}
@@ -501,7 +501,7 @@ namespace glabels
Distance w = mModel->frame()->w();
Distance h = mModel->frame()->h();
foreach ( const Layout& layout, mModel->frame()->layouts() )
for ( auto& layout : mModel->frame()->layouts() )
{
Distance xMin = layout.x0();
Distance yMin = layout.y0();
@@ -516,8 +516,8 @@ namespace glabels
Distance y1 = max( yMin-tickOffset, Distance::pt(0) );
Distance y2 = max( y1-tickLength, Distance::pt(0) );
Distance y3 = min( yMax+tickOffset, mModel->tmplate()->pageHeight() );
Distance y4 = min( y3+tickLength, mModel->tmplate()->pageHeight() );
Distance y3 = min( yMax+tickOffset, mModel->tmplate().pageHeight() );
Distance y4 = min( y3+tickLength, mModel->tmplate().pageHeight() );
painter->drawLine( x1.pt(), y1.pt(), x1.pt(), y2.pt() );
painter->drawLine( x2.pt(), y1.pt(), x2.pt(), y2.pt() );
@@ -533,8 +533,8 @@ namespace glabels
Distance x1 = max( xMin-tickOffset, Distance::pt(0) );
Distance x2 = max( x1-tickLength, Distance::pt(0) );
Distance x3 = min( xMax+tickOffset, mModel->tmplate()->pageWidth() );
Distance x4 = min( x3+tickLength, mModel->tmplate()->pageWidth() );
Distance x3 = min( xMax+tickOffset, mModel->tmplate().pageWidth() );
Distance x4 = min( x3+tickLength, mModel->tmplate().pageWidth() );
painter->drawLine( x1.pt(), y1.pt(), x2.pt(), y1.pt() );
painter->drawLine( x1.pt(), y2.pt(), x2.pt(), y2.pt() );
@@ -570,9 +570,9 @@ namespace glabels
}
void PageRenderer::printLabel( QPainter* painter,
merge::Record* record,
Variables* variables ) const
void PageRenderer::printLabel( QPainter* painter,
const merge::Record& record,
Variables& variables ) const
{
painter->save();
+2 -3
View File
@@ -104,7 +104,7 @@ namespace glabels
void printCropMarks( QPainter* painter ) const;
void printOutline( QPainter* painter ) const;
void clipLabel( QPainter* painter ) const;
void printLabel( QPainter* painter, merge::Record* record, Variables* variables ) const;
void printLabel( QPainter* painter, const merge::Record& record, Variables& variables ) const;
/////////////////////////////////
@@ -113,8 +113,7 @@ namespace glabels
private:
const Model* mModel{ nullptr };
const merge::Merge* mMerge{ nullptr };
Variables* mVariables{ nullptr };
int mNCopies{ 0 };
int mStartItem{ 0 };
int mLastItem{ 0 };
+10 -6
View File
@@ -26,12 +26,16 @@ namespace glabels
namespace model
{
Paper::Paper( const QString& id,
const QString& name,
const Distance& width,
const Distance& height,
const QString& pwgSize )
: mId(id), mName(name), mWidth(width), mHeight(height), mPwgSize(pwgSize)
Paper::Paper( const QString& id,
const QString& name,
Distance width,
Distance height,
const QString& pwgSize )
: mId(id),
mName(name),
mWidth(width),
mHeight(height),
mPwgSize(pwgSize)
{
// empty
}
+7 -5
View File
@@ -35,11 +35,13 @@ namespace glabels
class Paper
{
public:
Paper( const QString& id,
const QString& name,
const Distance& width,
const Distance& height,
const QString& pwgSize );
Paper() = default;
Paper( const QString& id,
const QString& name,
Distance width,
Distance height,
const QString& pwgSize );
~Paper() = default;
QString id() const;
QString name() const;
+1 -1
View File
@@ -73,7 +73,7 @@ namespace glabels
qsizetype
ParserState::charsLeft() const
{
return mString->size() - mPos;
return std::max( mString->size() - mPos, qsizetype(0) );
}
+1 -1
View File
@@ -47,7 +47,7 @@ namespace glabels
private:
const QString* mString;
const QString* mString{ nullptr };
qsizetype mPos{ 0 };
};
+2 -1
View File
@@ -23,6 +23,7 @@
#include "ParserState.h"
#include <QDebug>
#include <QRegularExpression>
@@ -70,7 +71,7 @@ namespace glabels
///
/// Expand all place holders
///
QString RawText::expand( merge::Record* record, Variables* variables ) const
QString RawText::expand( const merge::Record& record, const Variables& variables ) const
{
QString text;
+2 -2
View File
@@ -52,7 +52,7 @@ namespace glabels
/////////////////////////////////
QString toString() const;
std::string toStdString() const;
QString expand( merge::Record* record, Variables* variables ) const;
QString expand( const merge::Record& record, const Variables& variables ) const;
bool hasPlaceHolders() const;
bool isEmpty() const;
@@ -71,7 +71,7 @@ namespace glabels
struct Token
{
bool isField;
bool isField{ false };
QString text;
SubstitutionField field;
};
+17 -8
View File
@@ -29,7 +29,11 @@ namespace glabels
///
/// Constructor
///
Region::Region() : mX1(0), mY1(0), mX2(0), mY2(0)
Region::Region()
: mX1(0),
mY1(0),
mX2(0),
mY2(0)
{
// empty
}
@@ -38,9 +42,14 @@ namespace glabels
///
/// Constructor
///
Region::Region( const Distance& x1, const Distance& y1,
const Distance& x2, const Distance& y2 )
: mX1(x1), mY1(y1), mX2(x2), mY2(y2)
Region::Region( Distance x1,
Distance y1,
Distance x2,
Distance y2 )
: mX1(x1),
mY1(y1),
mX2(x2),
mY2(y2)
{
// empty
}
@@ -58,7 +67,7 @@ namespace glabels
///
/// Set x1
///
void Region::setX1( const Distance& value )
void Region::setX1( Distance value )
{
mX1 = value;
}
@@ -76,7 +85,7 @@ namespace glabels
///
/// Set y1
///
void Region::setY1( const Distance& value )
void Region::setY1( Distance value )
{
mY1 = value;
}
@@ -94,7 +103,7 @@ namespace glabels
///
/// Set x2
///
void Region::setX2( const Distance& value )
void Region::setX2( Distance value )
{
mX2 = value;
}
@@ -112,7 +121,7 @@ namespace glabels
///
/// Set y2
///
void Region::setY2( const Distance& value )
void Region::setY2( Distance value )
{
mY2 = value;
}
+8 -6
View File
@@ -43,8 +43,10 @@ namespace glabels
/////////////////////////////////
public:
Region();
Region( const Distance& x1, const Distance& y1,
const Distance& x2, const Distance& y2 );
Region( Distance x1,
Distance y1,
Distance x2,
Distance y2 );
/////////////////////////////////
@@ -55,21 +57,21 @@ namespace glabels
// X1 Property
//
Distance x1() const;
void setX1( const Distance& value );
void setX1( Distance value );
//
// Y1 Property
//
Distance y1() const;
void setY1( const Distance& value );
void setY1( Distance value );
//
// X2 Property
//
Distance x2() const;
void setX2( const Distance& value );
void setX2( Distance value );
@@ -77,7 +79,7 @@ namespace glabels
// Y2 Property
//
Distance y2() const;
void setY2( const Distance& value );
void setY2( Distance value );
/////////////////////////////////
+11 -11
View File
@@ -21,6 +21,8 @@
#include "Settings.h"
#include "Version.h"
#include <QLocale>
#include <QPrinterInfo>
#include <QString>
@@ -35,20 +37,19 @@ namespace glabels
//
// Static data
//
Settings* Settings::mInstance = nullptr;
std::unique_ptr<Settings> Settings::mInstance;
Settings::Settings()
{
// empty
}
void Settings::init()
{
if ( mInstance == nullptr )
// Note: init() hould be called after
// - QCoreApplication::setOrganizationName(), and
// - QCoreApplication::setApplicationName()
if ( !mInstance )
{
mInstance = new Settings();
mInstance.reset( new Settings() );
}
}
@@ -56,8 +57,7 @@ namespace glabels
Settings* Settings::instance()
{
init();
return mInstance;
return mInstance.get();
}
@@ -82,7 +82,7 @@ namespace glabels
}
void Settings::setUnits( const Units& units )
void Settings::setUnits( Units units )
{
QString idString = units.toIdString();
+6 -3
View File
@@ -23,11 +23,14 @@
#include "Distance.h"
#include "Units.h"
#include <QListView>
#include <QSettings>
#include <QStringList>
#include <memory>
namespace glabels
{
@@ -50,7 +53,7 @@ namespace glabels
// Life Cycle
/////////////////////////////////
private:
Settings();
Settings() = default;
public:
static void init();
@@ -69,7 +72,7 @@ namespace glabels
/////////////////////////////////
public:
static Units units();
static void setUnits( const Units& units );
static void setUnits( Units units );
static PageSizeFamily preferedPageSizeFamily();
static void setPreferedPageSizeFamily( PageSizeFamily preferedPageSizeFamily );
@@ -111,7 +114,7 @@ namespace glabels
private:
static Settings* mInstance;
static std::unique_ptr<Settings> mInstance;
static const int mMaxRecentFiles{5};
};
+6 -3
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Size.h"
@@ -38,7 +39,9 @@ namespace glabels
///
/// Constructor
///
Size::Size( const Distance& w, const Distance& h ) : mW(w), mH(h)
Size::Size( Distance w, Distance h )
: mW(w),
mH(h)
{
// empty
}
@@ -56,7 +59,7 @@ namespace glabels
///
/// Set w
///
void Size::setW( const Distance& value )
void Size::setW( Distance value )
{
mW = value;
}
@@ -74,7 +77,7 @@ namespace glabels
///
/// Set h
///
void Size::setH( const Distance& value )
void Size::setH( Distance value )
{
mH = value;
}
+3 -3
View File
@@ -43,7 +43,7 @@ namespace glabels
/////////////////////////////////
public:
Size();
Size( const Distance& w, const Distance& h );
Size( Distance w, Distance h );
/////////////////////////////////
@@ -54,14 +54,14 @@ namespace glabels
// w Property
//
Distance w() const;
void setW( const Distance& value );
void setW( Distance value );
//
// H Property
//
Distance h() const;
void setH( const Distance& value );
void setH( Distance value );
/////////////////////////////////
+8 -10
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SubstitutionField.h"
#include <QTextStream>
@@ -42,25 +43,22 @@ namespace glabels
}
QString SubstitutionField::evaluate( const merge::Record* record,
const Variables* variables ) const
QString SubstitutionField::evaluate( const merge::Record& record,
const Variables& variables ) const
{
QString value = mDefaultValue;
bool haveRecordField = record &&
record->contains(mFieldName) &&
!record->value(mFieldName).isEmpty();
bool haveVariable = variables &&
variables->contains(mFieldName) &&
!(*variables)[mFieldName].value().isEmpty();
bool haveRecordField = record.contains(mFieldName) &&
!record.value(mFieldName).isEmpty();
bool haveVariable = variables.contains(mFieldName) && !variables[mFieldName].value().isEmpty();
if ( haveRecordField )
{
value = record->value(mFieldName);
value = record.value(mFieldName);
}
else if ( haveVariable )
{
value = (*variables)[mFieldName].value();
value = variables[mFieldName].value();
}
if ( !mFormatType.isNull() )
+3 -3
View File
@@ -41,7 +41,7 @@ namespace glabels
SubstitutionField();
SubstitutionField( const QString& string );
QString evaluate( const merge::Record* record, const Variables* variables ) const;
QString evaluate( const merge::Record& record, const Variables& variables ) const;
QString fieldName() const;
QString defaultValue() const;
@@ -70,9 +70,9 @@ namespace glabels
QString mDefaultValue;
QString mFormat;
QChar mFormatType;
QChar mFormatType{};
bool mNewLine;
bool mNewLine{ false };
};
}
+119 -94
View File
@@ -33,14 +33,15 @@ namespace glabels
namespace model
{
Template::Template( const QString& brand,
const QString& part,
const QString& description,
const QString& paperId,
const Distance& pageWidth,
const Distance& pageHeight,
const Distance& rollWidth,
bool isUserDefined )
Template::Template( const QString& brand,
const QString& part,
const QString& description,
const QString& paperId,
Distance pageWidth,
Distance pageHeight,
Distance rollWidth,
const QString& fileName,
bool isUserDefined )
: mBrand(brand),
mPart(part),
mDescription(description),
@@ -48,15 +49,16 @@ namespace glabels
mPageWidth(pageWidth),
mPageHeight(pageHeight),
mRollWidth(rollWidth),
mFileName(fileName),
mIsUserDefined(isUserDefined)
{
mName.append( brand ).append( " " ).append( part );
mName = brandPartToName( brand, part );
if ( Db::isPaperIdKnown( paperId ) )
{
const Paper* paper = Db::lookupPaperFromId( paperId );
mIsSizeIso = paper->isSizeIso();
mIsSizeUs = paper->isSizeUs();
auto paper = Db::lookupPaperFromId( paperId );
mIsSizeIso = paper.isSizeIso();
mIsSizeUs = paper.isSizeUs();
}
mIsRoll = (paperId == "roll");
@@ -65,70 +67,61 @@ namespace glabels
Template::Template( const Template& other )
{
mBrand = other.mBrand;
mPart = other.mPart;
mDescription = other.mDescription;
mPaperId = other.mPaperId;
mPageWidth = other.mPageWidth;
mPageHeight = other.mPageHeight;
mRollWidth = other.mRollWidth;
mIsSizeIso = other.mIsSizeIso;
mIsSizeUs = other.mIsSizeUs;
mIsRoll = other.mIsRoll;
mEquivPart = other.mEquivPart;
mName = other.mName;
mProductUrl = other.mProductUrl;
mBrand = other.mBrand;
mPart = other.mPart;
mDescription = other.mDescription;
mPaperId = other.mPaperId;
mPageWidth = other.mPageWidth;
mPageHeight = other.mPageHeight;
mRollWidth = other.mRollWidth;
mIsSizeIso = other.mIsSizeIso;
mIsSizeUs = other.mIsSizeUs;
mIsRoll = other.mIsRoll;
mEquivPart = other.mEquivPart;
mName = other.mName;
mProductUrl = other.mProductUrl;
mFileName = other.mFileName;
mIsUserDefined = other.mIsUserDefined;
foreach ( Frame* frame, other.mFrames )
if ( other.mFrame )
{
addFrame( frame->dup() );
mFrame = other.mFrame->clone();
}
foreach ( QString categoryId, other.mCategoryIds )
for ( auto& categoryId : other.mCategoryIds )
{
addCategory( categoryId );
}
}
Template::~Template()
{
while ( !mFrames.isEmpty() )
{
delete mFrames.takeFirst();
}
}
Template& Template::operator=( const Template& other )
{
if ( this != &other )
{
mBrand = other.mBrand;
mPart = other.mPart;
mDescription = other.mDescription;
mPaperId = other.mPaperId;
mPageWidth = other.mPageWidth;
mPageHeight = other.mPageHeight;
mRollWidth = other.mRollWidth;
mIsSizeIso = other.mIsSizeIso;
mIsSizeUs = other.mIsSizeUs;
mIsRoll = other.mIsRoll;
mEquivPart = other.mEquivPart;
mName = other.mName;
mProductUrl = other.mProductUrl;
mBrand = other.mBrand;
mPart = other.mPart;
mDescription = other.mDescription;
mPaperId = other.mPaperId;
mPageWidth = other.mPageWidth;
mPageHeight = other.mPageHeight;
mRollWidth = other.mRollWidth;
mIsSizeIso = other.mIsSizeIso;
mIsSizeUs = other.mIsSizeUs;
mIsRoll = other.mIsRoll;
mEquivPart = other.mEquivPart;
mName = other.mName;
mProductUrl = other.mProductUrl;
mFileName = other.mFileName;
mIsUserDefined = other.mIsUserDefined;
while ( !mFrames.isEmpty() )
if ( other.mFrame )
{
delete mFrames.takeFirst();
}
foreach ( Frame* frame, other.mFrames )
{
addFrame( frame->dup() );
mFrame = other.mFrame->clone();
}
mCategoryIds.clear();
foreach ( QString categoryId, other.mCategoryIds )
for ( auto& categoryId : other.mCategoryIds )
{
addCategory( categoryId );
}
@@ -138,29 +131,19 @@ namespace glabels
}
// Generic full page template
Template* Template::fullPage( const QString& paperId )
{
// TODO
return nullptr;
}
// From equivalent part number
Template* Template::fromEquiv( const QString& brand,
const QString& part,
const QString& equivPart )
Template Template::fromEquiv( const QString& brand,
const QString& part,
const QString& equivPart )
{
const Template* other = Db::lookupTemplateFromBrandPart( brand, equivPart );
if ( other != nullptr )
if ( Db::isTemplateKnown( brand, equivPart ) )
{
Template* tmplate = new Template( *other );
auto tmplate = Db::lookupTemplateFromBrandPart( brand, equivPart );
tmplate->mPart = part;
tmplate->mEquivPart = equivPart;
tmplate.mPart = part;
tmplate.mEquivPart = equivPart;
tmplate->mName = "";
tmplate->mName.append( brand ).append( " " ).append( part );
tmplate.mName = brandPartToName( brand, part );
return tmplate;
}
@@ -169,11 +152,24 @@ namespace glabels
qWarning() << "Error: cannot create equivalent template for "
<< brand << ", " << equivPart
<< ". Forward references not supported.";
return nullptr;
return Template();
}
}
QString Template::brandPartToName( const QString& brand,
const QString& part )
{
return QString( "%1 %2" ).arg( brand ).arg( part );
}
bool Template::isNull() const
{
return mBrand.isEmpty() || mPart.isEmpty();
}
QString Template::brand() const
{
return mBrand;
@@ -192,7 +188,7 @@ namespace glabels
}
QString Template::paperDescription( const Units& units ) const
QString Template::paperDescription( Units units ) const
{
if ( mPaperId == "other" )
{
@@ -231,8 +227,7 @@ namespace glabels
Distance Template::pageHeight() const
{
// Adjust height if continuous tape
const model::Frame* frame = mFrames.constFirst();
if ( const auto* frameContinuous = dynamic_cast<const model::FrameContinuous*>(frame) )
if ( const auto* frameContinuous = dynamic_cast<const model::FrameContinuous*>( mFrame.get() ) )
{
return frameContinuous->h();
}
@@ -273,12 +268,30 @@ namespace glabels
}
QString Template::fileName() const
{
return mFileName;
}
void Template::setFileName( const QString& value )
{
mFileName = value;
}
bool Template::isUserDefined() const
{
return mIsUserDefined;
}
void Template::setIsUserDefined( bool isUserDefined )
{
mIsUserDefined = isUserDefined;
}
QString Template::equivPart() const
{
return mEquivPart;
@@ -309,9 +322,9 @@ namespace glabels
}
const QList<Frame*>& Template::frames() const
const Frame* Template::frame( const QString& id ) const
{
return mFrames;
return mFrame.get();
}
@@ -321,9 +334,9 @@ namespace glabels
}
void Template::addFrame( Frame* frame )
void Template::addFrame( const Frame& frame )
{
mFrames << frame;
mFrame = frame.clone();
}
@@ -335,7 +348,7 @@ namespace glabels
bool Template::hasCategory( const QString& categoryId ) const
{
foreach ( QString testCategoryId, mCategoryIds )
for ( auto& testCategoryId : mCategoryIds )
{
if ( categoryId == testCategoryId )
{
@@ -347,29 +360,29 @@ namespace glabels
}
bool Template::isSimilarTo( const Template* other ) const
bool Template::isSimilarTo( const Template& other ) const
{
// Does page size match?
if ( (mPaperId != other->mPaperId) ||
(mPageWidth != other->mPageWidth ) ||
(mPageHeight != other->mPageHeight ) )
if ( (mPaperId != other.mPaperId) ||
(mPageWidth != other.mPageWidth ) ||
(mPageHeight != other.mPageHeight ) )
{
return false;
}
// Are frames similar
Frame* frame1 = mFrames.first();
Frame* frame2 = other->mFrames.first();
if ( !frame1->isSimilarTo( frame2 ) )
auto& frame1 = mFrame;
auto& frame2 = other.mFrame;
if ( !frame1->isSimilarTo( *frame2 ) )
{
return false;
}
// Are they layed out similarly?
foreach ( const Layout& layout1, frame1->layouts() )
for ( auto& layout1 : frame1->layouts() )
{
bool matchFound = false;
foreach ( const Layout& layout2, frame2->layouts() )
for ( auto& layout2 : frame2->layouts() )
{
if ( layout1.isSimilarTo( layout2 ) )
{
@@ -387,6 +400,18 @@ namespace glabels
}
bool Template::setH( Distance h )
{
if ( mFrame )
{
return mFrame->setH( h );
}
else
{
return false;
}
}
}
}
@@ -405,7 +430,7 @@ QDebug operator<<( QDebug dbg, const glabels::model::Template& tmplate )
<< tmplate.isSizeUs() << ","
<< tmplate.isSizeOther() << ","
<< tmplate.isRoll() << ","
<< *tmplate.frames().constFirst() << ","
<< *tmplate.frame() << ","
<< " }";
return dbg;
}
+42 -33
View File
@@ -45,35 +45,37 @@ namespace glabels
Template() = default;
Template( const QString& brand,
const QString& part,
const QString& description,
const QString& paperId,
const Distance& pageWidth,
const Distance& pageHeight,
const Distance& rollWidth = 0,
bool isUserDefined = false );
Template( const QString& brand,
const QString& part,
const QString& description,
const QString& paperId,
Distance pageWidth,
Distance pageHeight,
Distance rollWidth = 0,
const QString& fileName = "",
bool isUserDefined = false );
Template( const Template& other );
~Template();
~Template() = default;
Template& operator=( const Template& other );
// Generic full page template
static Template* fullPage( const QString& paperId );
// From equivalent part number
static Template* fromEquiv( const QString& brand,
const QString& part,
const QString& equivPart );
static Template fromEquiv( const QString& brand,
const QString& part,
const QString& equivPart );
static QString brandPartToName( const QString& brand,
const QString& part );
bool isNull() const;
QString brand() const;
QString part() const;
QString description() const;
QString paperDescription( const Units& units ) const;
QString paperDescription( Units units ) const;
QString paperId() const;
Distance pageWidth() const;
Distance pageHeight() const;
@@ -83,7 +85,11 @@ namespace glabels
bool isSizeOther() const;
bool isRoll() const;
QString fileName() const;
void setFileName( const QString& fileName );
bool isUserDefined() const;
void setIsUserDefined( bool isUserDefined );
QString equivPart() const;
void setEquivPart( const QString& value );
@@ -94,39 +100,42 @@ namespace glabels
QString name() const;
void addCategory( const QString& categoryId );
void addFrame( Frame* frame );
void addFrame( const Frame& frame );
const QList<Frame*>& frames() const;
const Frame* frame( const QString& id = "0" ) const;
bool operator==( const Template& other ) const;
bool hasCategory( const QString& categoryId ) const;
bool isSimilarTo( const Template* other ) const;
bool isSimilarTo( const Template& other ) const;
bool setH( Distance h );
private:
QString mBrand;
QString mPart;
QString mDescription;
QString mBrand;
QString mPart;
QString mDescription;
QString mPaperId;
Distance mPageWidth;
Distance mPageHeight;
Distance mRollWidth;
QString mPaperId;
Distance mPageWidth;
Distance mPageHeight;
Distance mRollWidth;
bool mIsSizeIso{ false };
bool mIsSizeUs{ false };
bool mIsRoll{ false };
bool mIsSizeIso{ false };
bool mIsSizeUs{ false };
bool mIsRoll{ false };
bool mIsUserDefined{ false };
QString mFileName;
bool mIsUserDefined{ false };
QString mEquivPart;
QString mName;
QString mEquivPart;
QString mName;
QString mProductUrl;
QStringList mCategoryIds;
QList<Frame*> mFrames;
std::unique_ptr<Frame> mFrame; // TODO: support multiple frames mapped by ID
};
}
+11 -10
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TextNode.h"
@@ -105,25 +106,25 @@ namespace glabels
///
/// Get text, expand if necessary
///
QString TextNode::text( const merge::Record* record,
const Variables* variables ) const
QString TextNode::text( const merge::Record& record,
const Variables& variables ) const
{
QString value("");
bool haveRecordField = mIsField && record &&
record->contains(mData) &&
!record->value(mData).isEmpty();
bool haveVariable = mIsField && variables &&
variables->contains(mData) &&
!(*variables)[mData].value().isEmpty();
bool haveRecordField = mIsField &&
record.contains(mData) &&
!record.value(mData).isEmpty();
bool haveVariable = mIsField &&
variables.contains(mData) &&
!variables[mData].value().isEmpty();
if ( haveRecordField )
{
value = record->value(mData);
value = record.value(mData);
}
else if ( haveVariable )
{
value = (*variables)[mData].value();
value = variables[mData].value();
}
else if ( !mIsField )
{
+2 -2
View File
@@ -77,8 +77,8 @@ namespace glabels
/////////////////////////////////
// Misc. Methods
/////////////////////////////////
QString text( const merge::Record* record,
const Variables* variables ) const;
QString text( const merge::Record& record,
const Variables& variables ) const;
/////////////////////////////////
+9 -5
View File
@@ -30,18 +30,22 @@ namespace glabels
///
/// Copy constructor
///
Variables::Variables( const Variables* variables )
: QMap<QString,Variable>(*variables)
Variables::Variables( const Variables& other )
: QMap<QString,Variable>(other)
{
}
///
/// Clone
/// Copy contents from other
///
Variables* Variables::clone() const
void Variables::copy( const Variables& other )
{
return new Variables( this );
clear();
for ( const auto& v : other )
{
insert( v.name(), v );
}
}
+3 -3
View File
@@ -46,13 +46,13 @@ namespace glabels
/////////////////////////////////
public:
Variables() = default;
Variables( const Variables* variables );
Variables( const Variables& other );
/////////////////////////////////
// Object duplication
// Copy from other object
/////////////////////////////////
Variables* clone() const;
void copy( const Variables& other );
/////////////////////////////////
+3 -1
View File
@@ -26,7 +26,9 @@ namespace glabels
namespace model
{
Vendor::Vendor( const QString &name, const QString &url ) : mName(name), mUrl(url)
Vendor::Vendor( const QString &name, const QString &url )
: mName(name),
mUrl(url)
{
// empty
}
+2
View File
@@ -33,7 +33,9 @@ namespace glabels
class Vendor
{
public:
Vendor() = default;
Vendor( const QString &name, const QString &url );
~Vendor() = default;
QString name() const;
QString url() const;
+4
View File
@@ -29,6 +29,10 @@ namespace glabels
namespace Version
{
const QString ORGANIZATION_NAME = "@ORGANIZATION_NAME@";
const QString ORGANIZATION_DOMAIN = "@ORGANIZATION_DOMAIN@";
const QString APPLICATION_NAME = "@APPLICATION_NAME@";
const QString WEBSITE = "http://@WEBSITE@";
const QString BUG_WEBSITE = "@BUG_WEBSITE@";
+14 -16
View File
@@ -18,10 +18,9 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "XmlCategoryParser.h"
#include "Category.h"
#include "Db.h"
#include "XmlUtil.h"
#include <QDomDocument>
@@ -35,7 +34,7 @@ namespace glabels
namespace model
{
bool XmlCategoryParser::readFile( const QString &fileName )
QList<Category> XmlCategoryParser::readFile( const QString &fileName )
{
QFile file( fileName );
@@ -43,7 +42,7 @@ namespace glabels
{
qWarning() << "Error: Cannot read file " << fileName
<< ": " << file.errorString();
return false;
return QList<Category>(); // Empty list
}
@@ -57,28 +56,29 @@ namespace glabels
qWarning() << "Error: Parse error at line " << errorLine
<< "column " << errorColumn
<< ": " << errorString;
return false;
return QList<Category>(); // Empty list
}
QDomElement root = doc.documentElement();
if ( root.tagName() != "Glabels-categories" )
{
qWarning() << "Error: Not a Glabels-categories file.";
return false;
return QList<Category>(); // Empty list
}
parseRootNode( root );
return true;
return parseRootNode( root );
}
void XmlCategoryParser::parseRootNode( const QDomElement &node )
QList<Category> XmlCategoryParser::parseRootNode( const QDomElement &node )
{
QList<Category> list;
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
{
if ( child.toElement().tagName() == "Category" )
{
parseCategoryNode( child.toElement() );
list.push_back( parseCategoryNode( child.toElement() ) );
}
else if ( !child.isComment() )
{
@@ -87,19 +87,17 @@ namespace glabels
<< ", Ignored.";
}
}
return list;
}
void XmlCategoryParser::parseCategoryNode( const QDomElement &node )
Category XmlCategoryParser::parseCategoryNode( const QDomElement &node )
{
QString id = XmlUtil::getStringAttr( node, "id", "" );
QString name = XmlUtil::getI18nAttr( node, "name", "" );
auto *category = new Category( id, name );
if ( category != nullptr )
{
Db::registerCategory( category );
}
return Category( id, name );
}
+6 -3
View File
@@ -22,7 +22,10 @@
#define model_XmlCategoryParser_h
#include "Category.h"
#include <QDomElement>
#include <QList>
#include <QString>
@@ -36,11 +39,11 @@ namespace glabels
public:
XmlCategoryParser() = default;
bool readFile( const QString &fileName );
QList<Category> readFile( const QString &fileName );
private:
void parseRootNode( const QDomElement &node );
void parseCategoryNode( const QDomElement &node );
QList<Category> parseRootNode( const QDomElement &node );
Category parseCategoryNode( const QDomElement &node );
};
}
+5 -6
View File
@@ -82,10 +82,9 @@ namespace glabels
}
void
QByteArray
XmlLabelCreator::serializeObjects( const QList<ModelObject*>& objects,
const Model* model,
QByteArray& buffer )
const Model* model )
{
QDomDocument doc;
@@ -99,7 +98,7 @@ namespace glabels
createDataNode( root, model, objects );
createObjectsNode( root, model, objects, false );
buffer = doc.toByteArray( 2 );
return doc.toByteArray( 2 );
}
@@ -122,7 +121,7 @@ namespace glabels
createMergeNode( root, model );
}
if ( model->variables()->size() != 0 )
if ( model->constVariables().size() != 0 )
{
createVariablesNode( root, model );
}
@@ -508,7 +507,7 @@ namespace glabels
QDomElement node = doc.createElement( "Variables" );
parent.appendChild( node );
for ( const auto& v : *model->variables() )
for ( const auto& v : model->constVariables() )
{
createVariableNode( node, v );
}
+2 -3
View File
@@ -57,9 +57,8 @@ namespace glabels
static void writeBuffer( const Model* model,
QByteArray& buffer );
static void serializeObjects( const QList<ModelObject*>& objects,
const Model* model,
QByteArray& buffer );
static QByteArray serializeObjects( const QList<ModelObject*>& objects,
const Model* model );
private:
static void createDoc( QDomDocument& doc,
+3 -4
View File
@@ -271,15 +271,14 @@ namespace glabels
if ( tagName == "Template" )
{
Template* tmplate = XmlTemplateParser().parseTemplateNode( child.toElement() );
if ( tmplate == nullptr )
auto tmplate = XmlTemplateParser().parseTemplateNode( child.toElement() );
if ( tmplate.isNull() )
{
qWarning() << "Unable to parse template";
delete model;
return nullptr;
}
model->setTmplate( tmplate ); // Copies arg
delete tmplate;
}
else if ( tagName == "Objects" )
{
@@ -795,7 +794,7 @@ namespace glabels
auto increment = Variable::idStringToIncrement( incrementString );
Variable v( type, name, initialValue, increment, stepSize );
model->variables()->addVariable( v );
model->variables().addVariable( v );
}
+2 -3
View File
@@ -104,15 +104,14 @@ namespace glabels
if ( tagName == "Template" )
{
Template* tmplate = XmlTemplateParser().parseTemplateNode( childElement );
if ( tmplate == nullptr )
auto tmplate = XmlTemplateParser().parseTemplateNode( childElement );
if ( tmplate.isNull() )
{
qWarning() << "Unable to parse template";
delete label;
return nullptr;
}
label->setTmplate( tmplate ); // Copies arg
delete tmplate;
}
else if ( tagName == "Objects" )
{
+15 -16
View File
@@ -18,10 +18,9 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "XmlPaperParser.h"
#include "Db.h"
#include "Paper.h"
#include "XmlUtil.h"
#include <QDomDocument>
@@ -35,7 +34,7 @@ namespace glabels
namespace model
{
bool XmlPaperParser::readFile( const QString &fileName )
QList<Paper> XmlPaperParser::readFile( const QString &fileName )
{
QFile file( fileName );
@@ -43,7 +42,7 @@ namespace glabels
{
qWarning() << "Error: Cannot read file " << fileName
<< ": " << file.errorString();
return false;
return QList<Paper>(); // Empty list
}
@@ -57,28 +56,30 @@ namespace glabels
qWarning() << "Error: Parse error at line " << errorLine
<< "column " << errorColumn
<< ": " << errorString;
return false;
return QList<Paper>(); // Empty list
}
QDomElement root = doc.documentElement();
if ( root.tagName() != "Glabels-paper-sizes" )
{
qWarning() << "Error: Not a Glabels-paper-sizes file.";
return false;
return QList<Paper>(); // Empty list
}
parseRootNode( root );
return true;
return parseRootNode( root );
}
void XmlPaperParser::parseRootNode( const QDomElement &node )
QList<Paper> XmlPaperParser::parseRootNode( const QDomElement &node )
{
QList<Paper> list;
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
{
if ( child.toElement().tagName() == "Paper-size" )
{
parsePaperSizeNode( child.toElement() );
list.push_back( parsePaperSizeNode( child.toElement() ) );
}
else if ( !child.isComment() )
{
@@ -87,10 +88,12 @@ namespace glabels
<< ", Ignored.";
}
}
return list;
}
void XmlPaperParser::parsePaperSizeNode( const QDomElement &node )
Paper XmlPaperParser::parsePaperSizeNode( const QDomElement &node )
{
QString id = XmlUtil::getStringAttr( node, "id", "" );
QString name = XmlUtil::getI18nAttr( node, "name", "" );
@@ -100,11 +103,7 @@ namespace glabels
QString pwgSize = XmlUtil::getStringAttr( node, "pwg_size", "" );
auto *paper = new Paper( id, name, width, height, pwgSize );
if ( paper != nullptr )
{
Db::registerPaper( paper );
}
return Paper( id, name, width, height, pwgSize );
}
+7 -4
View File
@@ -22,8 +22,11 @@
#define model_XmlPaperParser_h
#include <QString>
#include "Paper.h"
#include <QDomElement>
#include <QList>
#include <QString>
namespace glabels
@@ -36,11 +39,11 @@ namespace glabels
public:
XmlPaperParser() = default;
bool readFile( const QString &fileName );
QList<Paper> readFile( const QString &fileName );
private:
void parseRootNode( const QDomElement &node );
void parsePaperSizeNode( const QDomElement &node );
QList<Paper> parseRootNode( const QDomElement &node );
Paper parsePaperSizeNode( const QDomElement &node );
};
}
+25 -25
View File
@@ -34,13 +34,13 @@ namespace glabels
namespace model
{
bool XmlTemplateCreator::writeTemplates( const QList<const Template*> tmplates, const QString &fileName )
bool XmlTemplateCreator::writeTemplates( const QList<Template> tmplates, const QString &fileName )
{
QDomDocument doc( "Glabels-templates" );
QDomElement root = doc.createElement( "Glabels-templates" );
doc.appendChild( root );
foreach ( const Template* tmplate, tmplates )
for ( auto& tmplate : tmplates )
{
createTemplateNode( root, tmplate );
}
@@ -66,9 +66,9 @@ namespace glabels
}
bool XmlTemplateCreator::writeTemplate( const Template* tmplate, const QString& fileName )
bool XmlTemplateCreator::writeTemplate( const Template& tmplate, const QString& fileName )
{
QList<const Template*> tmplates;
QList<Template> tmplates;
tmplates.append(tmplate);
@@ -76,40 +76,40 @@ namespace glabels
}
void XmlTemplateCreator::createTemplateNode( QDomElement &parent, const Template* tmplate )
void XmlTemplateCreator::createTemplateNode( QDomElement &parent, const Template& tmplate )
{
QDomDocument doc = parent.ownerDocument();
QDomElement node = doc.createElement( "Template" );
parent.appendChild( node );
XmlUtil::setStringAttr( node, "brand", tmplate->brand() );
XmlUtil::setStringAttr( node, "part", tmplate->part() );
XmlUtil::setStringAttr( node, "brand", tmplate.brand() );
XmlUtil::setStringAttr( node, "part", tmplate.part() );
XmlUtil::setStringAttr( node, "size", tmplate->paperId() );
if ( tmplate->isSizeOther() )
XmlUtil::setStringAttr( node, "size", tmplate.paperId() );
if ( tmplate.isSizeOther() )
{
XmlUtil::setLengthAttr( node, "width", tmplate->pageWidth() );
XmlUtil::setLengthAttr( node, "height", tmplate->pageHeight() );
XmlUtil::setLengthAttr( node, "width", tmplate.pageWidth() );
XmlUtil::setLengthAttr( node, "height", tmplate.pageHeight() );
}
if ( tmplate->isRoll() )
if ( tmplate.isRoll() )
{
XmlUtil::setLengthAttr( node, "roll_width", tmplate->rollWidth() );
XmlUtil::setLengthAttr( node, "roll_width", tmplate.rollWidth() );
}
XmlUtil::setStringAttr( node, "description", tmplate->description() );
XmlUtil::setStringAttr( node, "description", tmplate.description() );
if ( !tmplate->productUrl().isEmpty() )
if ( !tmplate.productUrl().isEmpty() )
{
createMetaNode( node, "product_url", tmplate->productUrl() );
createMetaNode( node, "product_url", tmplate.productUrl() );
}
#if TODO
foreach ( QString categoryId, tmplate->categoryIds() )
for ( auto& categoryId : tmplate.categoryIds() )
{
createMetaNode( node, "category", categoryId );
}
#endif
foreach ( Frame* frame, tmplate->frames() )
if ( auto frame = tmplate.frame() )
{
createLabelNode( node, frame );
}
@@ -263,25 +263,25 @@ namespace glabels
void XmlTemplateCreator::createLabelNodeCommon( QDomElement &node, const Frame *frame )
{
foreach ( Markup* markup, frame->markups() )
for ( auto& markup : frame->markups() )
{
if ( auto* markupMargin = dynamic_cast<MarkupMargin*>(markup) )
if ( auto* markupMargin = dynamic_cast<MarkupMargin*>(markup.get()) )
{
createMarkupMarginNode( node, markupMargin );
}
else if ( auto* markupLine = dynamic_cast<MarkupLine*>(markup) )
else if ( auto* markupLine = dynamic_cast<MarkupLine*>(markup.get()) )
{
createMarkupLineNode( node, markupLine );
}
else if ( auto* markupCircle = dynamic_cast<MarkupCircle*>(markup) )
else if ( auto* markupCircle = dynamic_cast<MarkupCircle*>(markup.get()) )
{
createMarkupCircleNode( node, markupCircle );
}
else if ( auto* markupRect = dynamic_cast<MarkupRect*>(markup) )
else if ( auto* markupRect = dynamic_cast<MarkupRect*>(markup.get()) )
{
createMarkupRectNode( node, markupRect );
}
else if ( auto* markupEllipse = dynamic_cast<MarkupEllipse*>(markup) )
else if ( auto* markupEllipse = dynamic_cast<MarkupEllipse*>(markup.get()) )
{
createMarkupEllipseNode( node, markupEllipse );
}
@@ -291,7 +291,7 @@ namespace glabels
}
}
foreach ( const Layout& layout, frame->layouts() )
for ( auto& layout : frame->layouts() )
{
createLayoutNode( node, layout );
}
+3 -3
View File
@@ -46,9 +46,9 @@ namespace glabels
public:
XmlTemplateCreator() = default;
bool writeTemplates( const QList<const Template*> tmplates, const QString& fileName );
bool writeTemplate( const Template* tmplate, const QString& fileName );
void createTemplateNode( QDomElement& parent, const Template* tmplate );
bool writeTemplates( const QList<Template> tmplates, const QString& fileName );
bool writeTemplate( const Template& tmplate, const QString& fileName );
void createTemplateNode( QDomElement& parent, const Template& tmplate );
private:
void createMetaNode( QDomElement& parent, const QString& attr, const QString& value );
+114 -64
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "XmlTemplateParser.h"
#include "Db.h"
@@ -32,10 +33,10 @@
#include "Template.h"
#include "XmlUtil.h"
#include <QFile>
#include <QDebug>
#include <QDomDocument>
#include <QDomNode>
#include <QtDebug>
#include <QFile>
namespace glabels
@@ -43,7 +44,7 @@ namespace glabels
namespace model
{
bool XmlTemplateParser::readFile( const QString &fileName, bool isUserDefined )
QList<Template> XmlTemplateParser::readFile( const QString& fileName )
{
QFile file( fileName );
@@ -51,7 +52,7 @@ namespace glabels
{
qWarning() << "Error: Cannot read file " << fileName
<< ": " << file.errorString();
return false;
return QList<Template>(); // Empty list
}
@@ -65,35 +66,79 @@ namespace glabels
qWarning() << "Error: Parse error at line " << errorLine
<< "column " << errorColumn
<< ": " << errorString;
return false;
return QList<Template>(); // Empty list
}
QDomElement root = doc.documentElement();
if ( root.tagName() != "Glabels-templates" )
{
qWarning() << "Error: Not a Glabels-templates file";
return false;
return QList<Template>(); // Empty list
}
parseRootNode( root, isUserDefined );
return true;
return parseRootNode( root, fileName, TEMPLATE_PASS );
}
void XmlTemplateParser::parseRootNode( const QDomElement &node, bool isUserDefined )
QList<Template> XmlTemplateParser::readEquivsFromFile( const QString& fileName )
{
QFile file( fileName );
if ( !file.open( QFile::ReadOnly | QFile::Text) )
{
qWarning() << "Error: Cannot read file " << fileName
<< ": " << file.errorString();
return QList<Template>(); // Empty list
}
QDomDocument doc;
QString errorString;
int errorLine;
int errorColumn;
if ( !doc.setContent( &file, false, &errorString, &errorLine, &errorColumn ) )
{
qWarning() << "Error: Parse error at line " << errorLine
<< "column " << errorColumn
<< ": " << errorString;
return QList<Template>(); // Empty list
}
QDomElement root = doc.documentElement();
if ( root.tagName() != "Glabels-templates" )
{
qWarning() << "Error: Not a Glabels-templates file";
return QList<Template>(); // Empty list
}
return parseRootNode( root, fileName, EQUIV_PASS );
}
QList<Template> XmlTemplateParser::parseRootNode( const QDomElement& node,
const QString& fileName,
Pass pass )
{
QList<Template> list;
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
{
if ( child.toElement().tagName() == "Template" )
{
Template *tmplate = parseTemplateNode( child.toElement(), isUserDefined );
if ( tmplate != nullptr )
bool isEquivNode = child.toElement().hasAttribute( "equiv" );
if ( ( (pass == TEMPLATE_PASS) && !isEquivNode ) ||
( (pass == EQUIV_PASS) && isEquivNode ) )
{
Db::registerTemplate( tmplate );
}
else
{
qWarning() << "Warning: could not create template, Ignored.";
auto tmplate = parseTemplateNode( child.toElement(), fileName );
if ( !tmplate.isNull() )
{
list.push_back( tmplate );
}
else
{
qWarning() << "Warning: could not create template, Ignored.";
}
}
}
else if ( !child.isComment() )
@@ -103,10 +148,13 @@ namespace glabels
<< ", Ignored.";
}
}
return list;
}
Template *XmlTemplateParser::parseTemplateNode( const QDomElement &node, bool isUserDefined )
Template XmlTemplateParser::parseTemplateNode( const QDomElement& node,
const QString& fileName )
{
QString brand = XmlUtil::getStringAttr( node, "brand", "" );
QString part = XmlUtil::getStringAttr( node, "part", "" );
@@ -124,12 +172,12 @@ namespace glabels
else
{
qWarning() << "Error: missing name or brand/part attributes.";
return nullptr;
return Template();
}
}
Template *tmplate = nullptr;
Template tmplate;
QString equivPart = XmlUtil::getStringAttr( node, "equiv", "" );
if ( equivPart != nullptr )
@@ -157,15 +205,10 @@ namespace glabels
if ( Db::isPaperIdKnown( paperId ) )
{
const Paper *paper = Db::lookupPaperFromId( paperId );
if ( paper == nullptr )
{
qWarning() << "Error: unknown paper ID: " << paperId;
return nullptr;
}
auto paper = Db::lookupPaperFromId( paperId );
tmplate = new Template( brand, part, description,
paper->id(), paper->width(), paper->height(), isUserDefined );
tmplate = Template( brand, part, description,
paper.id(), paper.width(), paper.height(), 0, fileName );
}
else
{
@@ -173,7 +216,14 @@ namespace glabels
Distance height = XmlUtil::getLengthAttr( node, "height", Distance(0) );
Distance rollWidth = XmlUtil::getLengthAttr( node, "roll_width", Distance(0) );
tmplate = new Template( brand, part, description, paperId, width, height, rollWidth, isUserDefined );
tmplate = Template( brand,
part,
description,
paperId,
width,
height,
rollWidth,
fileName );
}
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
@@ -219,23 +269,23 @@ namespace glabels
}
void XmlTemplateParser::parseMetaNode( const QDomElement &node, Template *tmplate )
void XmlTemplateParser::parseMetaNode( const QDomElement& node, Template& tmplate )
{
QString productUrl = XmlUtil::getStringAttr( node, "product_url", "" );
if ( productUrl != "" )
{
tmplate->setProductUrl( productUrl );
tmplate.setProductUrl( productUrl );
}
QString categoryId = XmlUtil::getStringAttr( node, "category", "" );
if ( categoryId != "" )
{
tmplate->addCategory( categoryId );
tmplate.addCategory( categoryId );
}
}
void XmlTemplateParser::parseLabelRectangleNode( const QDomElement &node, Template *tmplate )
void XmlTemplateParser::parseLabelRectangleNode( const QDomElement& node, Template& tmplate )
{
QString id = XmlUtil::getStringAttr( node, "id", "0" );
@@ -257,15 +307,15 @@ namespace glabels
yWaste = XmlUtil::getLengthAttr( node, "y_waste", Distance(0) );
}
Frame *frame = new FrameRect( w, h, r, xWaste, yWaste, id );
FrameRect frame( w, h, r, xWaste, yWaste, id );
parseLabelNodeCommon( node, frame );
tmplate->addFrame( frame );
tmplate.addFrame( frame );
}
void XmlTemplateParser::parseLabelEllipseNode( const QDomElement &node, Template *tmplate )
void XmlTemplateParser::parseLabelEllipseNode( const QDomElement& node, Template& tmplate )
{
QString id = XmlUtil::getStringAttr( node, "id", "0" );
@@ -273,30 +323,30 @@ namespace glabels
Distance h = XmlUtil::getLengthAttr( node, "height", Distance(0) );
Distance waste = XmlUtil::getLengthAttr( node, "waste", Distance(0) );
Frame *frame = new FrameEllipse( w, h, waste, id );
FrameEllipse frame( w, h, waste, id );
parseLabelNodeCommon( node, frame );
tmplate->addFrame( frame );
tmplate.addFrame( frame );
}
void XmlTemplateParser::parseLabelRoundNode( const QDomElement &node, Template *tmplate )
void XmlTemplateParser::parseLabelRoundNode( const QDomElement& node, Template& tmplate )
{
QString id = XmlUtil::getStringAttr( node, "id", "0" );
Distance r = XmlUtil::getLengthAttr( node, "radius", Distance(0) );
Distance waste = XmlUtil::getLengthAttr( node, "waste", Distance(0) );
Frame *frame = new FrameRound( r, waste, id );
FrameRound frame( r, waste, id );
parseLabelNodeCommon( node, frame );
tmplate->addFrame( frame );
tmplate.addFrame( frame );
}
void XmlTemplateParser::parseLabelCdNode( const QDomElement &node, Template *tmplate )
void XmlTemplateParser::parseLabelCdNode( const QDomElement& node, Template& tmplate )
{
QString id = XmlUtil::getStringAttr( node, "id", "0" );
@@ -306,15 +356,15 @@ namespace glabels
Distance h = XmlUtil::getLengthAttr( node, "height", Distance(0) );
Distance waste = XmlUtil::getLengthAttr( node, "waste", Distance(0) );
Frame *frame = new FrameCd( r1, r2, w, h, waste, id );
FrameCd frame( r1, r2, w, h, waste, id );
parseLabelNodeCommon( node, frame );
tmplate->addFrame( frame );
tmplate.addFrame( frame );
}
void XmlTemplateParser::parseLabelPathNode( const QDomElement &node, Template *tmplate )
void XmlTemplateParser::parseLabelPathNode( const QDomElement& node, Template& tmplate )
{
QString id = XmlUtil::getStringAttr( node, "id", "0" );
@@ -335,15 +385,15 @@ namespace glabels
yWaste = XmlUtil::getLengthAttr( node, "y_waste", Distance(0) );
}
Frame *frame = new FramePath( d, xWaste, yWaste, dUnits, id );
FramePath frame( d, xWaste, yWaste, dUnits, id );
parseLabelNodeCommon( node, frame );
tmplate->addFrame( frame );
tmplate.addFrame( frame );
}
void XmlTemplateParser::parseLabelContinuousNode( const QDomElement &node, Template *tmplate )
void XmlTemplateParser::parseLabelContinuousNode( const QDomElement& node, Template& tmplate )
{
QString id = XmlUtil::getStringAttr( node, "id", "0" );
@@ -353,19 +403,19 @@ namespace glabels
Distance hMax = XmlUtil::getLengthAttr( node, "max_height", Distance(0) );
Distance hDefault = XmlUtil::getLengthAttr( node, "default_height", Distance(0) );
Frame *frame = new FrameContinuous( w, hMin, hMax, hDefault, id );
FrameContinuous frame( w, hMin, hMax, hDefault, id );
if ( h > Distance(0) )
{
frame->setH( h );
frame.setH( h );
}
parseLabelNodeCommon( node, frame );
tmplate->addFrame( frame );
tmplate.addFrame( frame );
}
void XmlTemplateParser::parseLabelNodeCommon( const QDomElement &node, Frame *frame )
void XmlTemplateParser::parseLabelNodeCommon( const QDomElement& node, Frame& frame )
{
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
{
@@ -403,7 +453,7 @@ namespace glabels
}
void XmlTemplateParser::parseLayoutNode( const QDomElement &node, Frame *frame )
void XmlTemplateParser::parseLayoutNode( const QDomElement& node, Frame& frame )
{
int nX = XmlUtil::getIntAttr( node, "nx", 1 );
int nY = XmlUtil::getIntAttr( node, "ny", 1 );
@@ -414,11 +464,11 @@ namespace glabels
Distance dX = XmlUtil::getLengthAttr( node, "dx", Distance(0) );
Distance dY = XmlUtil::getLengthAttr( node, "dy", Distance(0) );
frame->addLayout( Layout( nX, nY, x0, y0, dX, dY ) );
frame.addLayout( Layout( nX, nY, x0, y0, dX, dY ) );
}
void XmlTemplateParser::parseMarkupMarginNode( const QDomElement &node, Frame *frame )
void XmlTemplateParser::parseMarkupMarginNode( const QDomElement& node, Frame& frame )
{
Distance size = XmlUtil::getLengthAttr( node, "size", Distance(0) );
Distance xSize = XmlUtil::getLengthAttr( node, "x_size", Distance(0) );
@@ -426,37 +476,37 @@ namespace glabels
if ( size > Distance(0) )
{
frame->addMarkup( new MarkupMargin( size ) );
frame.addMarkup( MarkupMargin( size ) );
}
else
{
frame->addMarkup( new MarkupMargin( xSize, ySize ) );
frame.addMarkup( MarkupMargin( xSize, ySize ) );
}
}
void XmlTemplateParser::parseMarkupLineNode( const QDomElement &node, Frame *frame )
void XmlTemplateParser::parseMarkupLineNode( const QDomElement& node, Frame& frame )
{
Distance x1 = XmlUtil::getLengthAttr( node, "x1", Distance(0) );
Distance y1 = XmlUtil::getLengthAttr( node, "y1", Distance(0) );
Distance x2 = XmlUtil::getLengthAttr( node, "x2", Distance(0) );
Distance y2 = XmlUtil::getLengthAttr( node, "y2", Distance(0) );
frame->addMarkup( new MarkupLine( x1, y1, x2, y2 ) );
frame.addMarkup( MarkupLine( x1, y1, x2, y2 ) );
}
void XmlTemplateParser::parseMarkupCircleNode( const QDomElement &node, Frame *frame )
void XmlTemplateParser::parseMarkupCircleNode( const QDomElement& node, Frame& frame )
{
Distance x0 = XmlUtil::getLengthAttr( node, "x0", Distance(0) );
Distance y0 = XmlUtil::getLengthAttr( node, "y0", Distance(0) );
Distance r = XmlUtil::getLengthAttr( node, "radius", Distance(0) );
frame->addMarkup( new MarkupCircle( x0, y0, r ) );
frame.addMarkup( MarkupCircle( x0, y0, r ) );
}
void XmlTemplateParser::parseMarkupRectNode( const QDomElement &node, Frame *frame )
void XmlTemplateParser::parseMarkupRectNode( const QDomElement& node, Frame& frame )
{
Distance x1 = XmlUtil::getLengthAttr( node, "x1", Distance(0) );
Distance y1 = XmlUtil::getLengthAttr( node, "y1", Distance(0) );
@@ -464,18 +514,18 @@ namespace glabels
Distance h = XmlUtil::getLengthAttr( node, "h", Distance(0) );
Distance r = XmlUtil::getLengthAttr( node, "r", Distance(0) );
frame->addMarkup( new MarkupRect( x1, y1, w, h, r ) );
frame.addMarkup( MarkupRect( x1, y1, w, h, r ) );
}
void XmlTemplateParser::parseMarkupEllipseNode( const QDomElement &node, Frame *frame )
void XmlTemplateParser::parseMarkupEllipseNode( const QDomElement& node, Frame& frame )
{
Distance x1 = XmlUtil::getLengthAttr( node, "x1", Distance(0) );
Distance y1 = XmlUtil::getLengthAttr( node, "y1", Distance(0) );
Distance w = XmlUtil::getLengthAttr( node, "w", Distance(0) );
Distance h = XmlUtil::getLengthAttr( node, "h", Distance(0) );
frame->addMarkup( new MarkupEllipse( x1, y1, w, h ) );
frame.addMarkup( MarkupEllipse( x1, y1, w, h ) );
}
+25 -17
View File
@@ -25,6 +25,7 @@
#include "Template.h"
#include <QDomElement>
#include <QList>
#include <QString>
@@ -38,25 +39,32 @@ namespace glabels
public:
XmlTemplateParser() = default;
bool readFile( const QString &fileName, bool isUserDefined = false );
Template *parseTemplateNode( const QDomElement &node, bool isUserDefined = false );
QList<Template> readFile( const QString& fileName );
QList<Template> readEquivsFromFile( const QString& fileName );
Template parseTemplateNode( const QDomElement& node,
const QString& fileName = "" );
private:
void parseRootNode( const QDomElement &node, bool isUserDefined );
void parseMetaNode( const QDomElement &node, Template *tmplate );
void parseLabelRectangleNode( const QDomElement &node, Template *tmplate );
void parseLabelEllipseNode( const QDomElement &node, Template *tmplate );
void parseLabelRoundNode( const QDomElement &node, Template *tmplate );
void parseLabelCdNode( const QDomElement &node, Template *tmplate );
void parseLabelPathNode( const QDomElement &node, Template *tmplate );
void parseLabelContinuousNode( const QDomElement &node, Template *tmplate );
void parseLabelNodeCommon( const QDomElement &node, Frame *frame );
void parseLayoutNode( const QDomElement &node, Frame *frame );
void parseMarkupMarginNode( const QDomElement &node, Frame *frame );
void parseMarkupLineNode( const QDomElement &node, Frame *frame );
void parseMarkupCircleNode( const QDomElement &node, Frame *frame );
void parseMarkupRectNode( const QDomElement &node, Frame *frame );
void parseMarkupEllipseNode( const QDomElement &node, Frame *frame );
enum Pass { TEMPLATE_PASS, EQUIV_PASS };
QList<Template> parseRootNode( const QDomElement& node,
const QString& fileName,
Pass pass );
void parseMetaNode( const QDomElement& node, Template& tmplate );
void parseLabelRectangleNode( const QDomElement& node, Template& tmplate );
void parseLabelEllipseNode( const QDomElement& node, Template& tmplate );
void parseLabelRoundNode( const QDomElement& node, Template& tmplate );
void parseLabelCdNode( const QDomElement& node, Template& tmplate );
void parseLabelPathNode( const QDomElement& node, Template& tmplate );
void parseLabelContinuousNode( const QDomElement& node, Template& tmplate );
void parseLabelNodeCommon( const QDomElement& node, Frame& frame );
void parseLayoutNode( const QDomElement& node, Frame& frame );
void parseMarkupMarginNode( const QDomElement& node, Frame& frame );
void parseMarkupLineNode( const QDomElement& node, Frame& frame );
void parseMarkupCircleNode( const QDomElement& node, Frame& frame );
void parseMarkupRectNode( const QDomElement& node, Frame& frame );
void parseMarkupEllipseNode( const QDomElement& node, Frame& frame );
};
+15 -71
View File
@@ -34,37 +34,18 @@ namespace glabels
//
// Static data
//
XmlUtil* XmlUtil::mInstance = nullptr;
XmlUtil::XmlUtil()
{
mUnits = Units(Units::PT);
}
void XmlUtil::init()
{
if ( mInstance == nullptr )
{
mInstance = new XmlUtil();
}
}
Units XmlUtil::mUnits = Units(Units::PT);
Units XmlUtil::units()
{
init();
return mInstance->mUnits;
return mUnits;
}
void XmlUtil::setUnits( const Units& units )
void XmlUtil::setUnits( Units units )
{
init();
mInstance->mUnits = units;
mUnits = units;
}
@@ -72,8 +53,6 @@ namespace glabels
const QString& name,
const QString& default_value )
{
init();
return node.attribute( name, default_value );
}
@@ -82,8 +61,6 @@ namespace glabels
const QString& name,
double default_value )
{
init();
QString valueString = node.attribute( name, "" );
if ( valueString != "" )
{
@@ -108,8 +85,6 @@ namespace glabels
const QString& name,
bool default_value )
{
init();
QString valueString = node.attribute( name, "" );
if ( valueString != "" )
{
@@ -145,8 +120,6 @@ namespace glabels
const QString& name,
int default_value )
{
init();
QString valueString = node.attribute( name, "" );
if ( valueString != "" )
{
@@ -171,8 +144,6 @@ namespace glabels
const QString& name,
uint32_t default_value )
{
init();
QString valueString = node.attribute( name, "" );
if ( valueString != "" )
{
@@ -197,8 +168,6 @@ namespace glabels
const QString& name,
const QString& default_value )
{
init();
QString i18nString = node.attribute( QString("_").append(name), "" );
if ( i18nString == "" )
@@ -212,10 +181,8 @@ namespace glabels
Distance XmlUtil::getLengthAttr( const QDomElement& node,
const QString& name,
const Distance& default_value )
Distance default_value )
{
init();
QString valueString = node.attribute( name, "" );
if ( valueString != "" )
{
@@ -243,8 +210,6 @@ namespace glabels
const QString& name,
QFont::Weight default_value )
{
init();
QString valueString = node.attribute( name, "" );
if ( valueString != "" )
{
@@ -272,8 +237,6 @@ namespace glabels
const QString& name,
Qt::Alignment default_value )
{
init();
QString valueString = node.attribute( name, "" );
if ( valueString != "" )
{
@@ -317,8 +280,6 @@ namespace glabels
const QString& name,
QTextOption::WrapMode default_value )
{
init();
QString valueString = node.attribute( name, "" );
if ( valueString != "" )
{
@@ -346,12 +307,10 @@ namespace glabels
}
Units XmlUtil::getUnitsAttr( const QDomElement& node,
const QString& name,
const Units& default_value )
Units XmlUtil::getUnitsAttr( const QDomElement& node,
const QString& name,
Units default_value )
{
init();
QString valueString = node.attribute( name, "" );
if ( valueString != "" )
{
@@ -362,12 +321,10 @@ namespace glabels
}
QPainterPath XmlUtil::getPathDataAttr( const QDomElement& node,
const QString& name,
const Units& units )
QPainterPath XmlUtil::getPathDataAttr( const QDomElement& node,
const QString& name,
Units units )
{
init();
QPainterPath d;
//
@@ -493,8 +450,6 @@ namespace glabels
const QString& name,
const QString& value )
{
init();
node.setAttribute( name, value );
}
@@ -503,8 +458,6 @@ namespace glabels
const QString& name,
double value )
{
init();
node.setAttribute( name, QString::number(value) );
}
@@ -513,8 +466,6 @@ namespace glabels
const QString& name,
bool value )
{
init();
node.setAttribute( name, value ? "true" : "false" );
}
@@ -523,8 +474,6 @@ namespace glabels
const QString& name,
int value )
{
init();
node.setAttribute( name, QString::number(value) );
}
@@ -533,20 +482,15 @@ namespace glabels
const QString& name,
uint32_t value )
{
init();
node.setAttribute( name, "0x" + QString::number(value, 16) );
}
void XmlUtil::setLengthAttr( QDomElement& node,
const QString& name,
const Distance& value )
Distance value )
{
init();
Units units = mInstance->mUnits;
node.setAttribute( name, QString::number(value.inUnits(units)) + units.toIdString() );
node.setAttribute( name, QString::number(value.inUnits(mUnits)) + mUnits.toIdString() );
}
@@ -622,7 +566,7 @@ namespace glabels
void XmlUtil::setUnitsAttr( QDomElement& node,
const QString& name,
const Units& value )
Units value )
{
node.setAttribute( name, value.toIdString() );
}
@@ -631,7 +575,7 @@ namespace glabels
void XmlUtil::setPathDataAttr( QDomElement& node,
const QString& name,
const QPainterPath& path,
const Units& units )
Units units )
{
QString pathString;
for ( int i = 0; i < path.elementCount(); i++ )
+11 -20
View File
@@ -41,16 +41,11 @@ namespace glabels
class XmlUtil
{
private:
XmlUtil();
public:
static void init();
XmlUtil() = delete;
static Units units();
static void setUnits( const Units& units );
static void setUnits( Units units );
static QString getStringAttr( const QDomElement& node,
const QString& name,
@@ -78,7 +73,7 @@ namespace glabels
static Distance getLengthAttr( const QDomElement& node,
const QString& name,
const Distance& default_value );
Distance default_value );
static QFont::Weight getWeightAttr( const QDomElement& node,
const QString& name,
@@ -94,11 +89,11 @@ namespace glabels
static Units getUnitsAttr( const QDomElement& node,
const QString& name,
const Units& default_value );
Units default_value );
static QPainterPath getPathDataAttr( const QDomElement& node,
const QString& name,
const Units& units );
static QPainterPath getPathDataAttr( const QDomElement& node,
const QString& name,
Units units );
static void setStringAttr( QDomElement& node,
@@ -123,7 +118,7 @@ namespace glabels
static void setLengthAttr( QDomElement& node,
const QString& name,
const Distance& value );
Distance value );
static void setWeightAttr( QDomElement& node,
const QString& name,
@@ -139,19 +134,15 @@ namespace glabels
static void setUnitsAttr( QDomElement& node,
const QString& name,
const Units& value );
Units value );
static void setPathDataAttr( QDomElement& node,
const QString& name,
const QPainterPath& value,
const Units& units );
Units units );
private:
Units mUnits;
static XmlUtil* mInstance;
static Units mUnits;
};
+14 -16
View File
@@ -18,10 +18,9 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "XmlVendorParser.h"
#include "Db.h"
#include "Vendor.h"
#include "XmlUtil.h"
#include <QDomDocument>
@@ -35,7 +34,7 @@ namespace glabels
namespace model
{
bool XmlVendorParser::readFile( const QString &fileName )
QList<Vendor> XmlVendorParser::readFile( const QString &fileName )
{
QFile file( fileName );
@@ -43,7 +42,7 @@ namespace glabels
{
qWarning() << "Error: Cannot read file " << fileName
<< ": " << file.errorString();
return false;
return QList<Vendor>(); // Empty list
}
@@ -57,28 +56,29 @@ namespace glabels
qWarning() << "Error: Parse error at line " << errorLine
<< "column " << errorColumn
<< ": " << errorString;
return false;
return QList<Vendor>(); // Empty list
}
QDomElement root = doc.documentElement();
if ( root.tagName() != "Glabels-vendors" )
{
qWarning() << "Error: Not a Glabels-vendors file.";
return false;
return QList<Vendor>(); // Empty list
}
parseRootNode( root );
return true;
return parseRootNode( root );
}
void XmlVendorParser::parseRootNode( const QDomElement &node )
QList<Vendor> XmlVendorParser::parseRootNode( const QDomElement &node )
{
QList<Vendor> list;
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
{
if ( child.toElement().tagName() == "Vendor" )
{
parseVendorNode( child.toElement() );
list.push_back( parseVendorNode( child.toElement() ) );
}
else if ( !child.isComment() )
{
@@ -87,19 +87,17 @@ namespace glabels
<< ", Ignored.";
}
}
return list;
}
void XmlVendorParser::parseVendorNode( const QDomElement &node )
Vendor XmlVendorParser::parseVendorNode( const QDomElement &node )
{
QString name = XmlUtil::getStringAttr( node, "name", "" );
QString url = XmlUtil::getStringAttr( node, "url", "" );
auto *vendor = new Vendor( name, url );
if ( vendor != nullptr )
{
Db::registerVendor( vendor );
}
return Vendor( name, url );
}
+6 -3
View File
@@ -22,7 +22,10 @@
#define model_XmlVendorParser_h
#include "Vendor.h"
#include <QDomElement>
#include <QList>
#include <QString>
@@ -36,11 +39,11 @@ namespace glabels
public:
XmlVendorParser() = default;
bool readFile( const QString &fileName );
QList<Vendor> readFile( const QString &fileName );
private:
void parseRootNode( const QDomElement &node );
void parseVendorNode( const QDomElement &node );
QList<Vendor> parseRootNode( const QDomElement &node );
Vendor parseVendorNode( const QDomElement &node );
};
}
+1
View File
@@ -22,6 +22,7 @@ if (Qt6Test_FOUND)
qt6_wrap_cpp (TestXmlLabel_moc_sources TestXmlLabel.h)
add_executable (TestXmlLabel TestXmlLabel.cpp ${TestXmlLabel_moc_sources})
target_link_libraries (TestXmlLabel Model Qt6::Test)
target_compile_definitions(TestXmlLabel PRIVATE TEST_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
add_test (NAME XmlLabel COMMAND TestXmlLabel)
#=======================================
+21 -24
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TestColorNode.h"
#include "model/ColorNode.h"
@@ -53,10 +54,8 @@ void TestColorNode::colorNode()
QCOMPARE( colorNode.color(), blackTransparent );
QCOMPARE( colorNode.key(), QString( "" ) );
QCOMPARE( colorNode.rgba(), rgbaBlackTransparent );
QCOMPARE( colorNode.color( nullptr, nullptr ), blackTransparent );
QCOMPARE( colorNode.color( &record, nullptr ), blackTransparent );
QCOMPARE( colorNode.color( nullptr, &vars ), blackTransparent );
QCOMPARE( colorNode.color( &record, &vars ), blackTransparent );
QCOMPARE( colorNode.color( NullRecord(), vars ), blackTransparent );
QCOMPARE( colorNode.color( record, vars ), blackTransparent );
colorNode.setField( true );
QVERIFY( colorNode.isField() );
@@ -66,10 +65,8 @@ void TestColorNode::colorNode()
colorNode.setColor( white );
QCOMPARE( colorNode.color(), white );
QCOMPARE( colorNode.rgba(), rgbaWhite );
QCOMPARE( colorNode.color( nullptr, nullptr ), white );
QCOMPARE( colorNode.color( &record, nullptr ), white );
QCOMPARE( colorNode.color( nullptr, &vars ), white );
QCOMPARE( colorNode.color( &record, &vars ), white );
QCOMPARE( colorNode.color( NullRecord(), vars ), white );
QCOMPARE( colorNode.color( record, vars ), white );
colorNode.setKey( "key1" );
QCOMPARE( colorNode.key(), QString( "key1" ) );
@@ -109,27 +106,27 @@ void TestColorNode::colorNode()
QVERIFY( colorNode.isField() ); // Defaults to true if given key only
QCOMPARE( colorNode.key(), QString( "key1" ) );
QCOMPARE( colorNode.color(), blackTransparent );
QCOMPARE( colorNode.color( &record, &vars ), silver80 ); // Defaults to silver if given non-matching record/variables
QCOMPARE( colorNode.color( record, vars ), silver80 ); // Defaults to silver if given non-matching record/variables
record["key1"] = "white";
QCOMPARE( colorNode.color( &record, nullptr ), white );
QCOMPARE( colorNode.color( record, vars ), white );
record["key1"] = "red";
QCOMPARE( colorNode.color( &record, nullptr ), red );
QCOMPARE( colorNode.color( record, vars ), red );
record["key1"] = "#FF0000";
QCOMPARE( colorNode.color( &record, nullptr ), red );
QCOMPARE( colorNode.color( record, vars ), red );
record["key1"] = "#FFFF0000"; // ARGB
QCOMPARE( colorNode.color( &record, nullptr ), red );
QCOMPARE( colorNode.color( record, vars ), red );
record["key1"] = "#8000FF00";
QCOMPARE( colorNode.color( &record, nullptr ), green80 );
QCOMPARE( colorNode.color( record, vars ), green80 );
colorNode.setKey( "key2" );
QCOMPARE( colorNode.color( &record, nullptr ), silver80 );
QCOMPARE( colorNode.color( record, vars ), silver80 );
record["key2"] = "#8000FF00";
QCOMPARE( colorNode.color( &record, nullptr ), green80 );
QCOMPARE( colorNode.color( record, vars ), green80 );
///
/// Variable
@@ -138,40 +135,40 @@ void TestColorNode::colorNode()
QVERIFY( colorNode.isField() ); // Defaults to true if given key only
QCOMPARE( colorNode.key(), QString( "c1" ) );
QCOMPARE( colorNode.color(), blackTransparent );
QCOMPARE( colorNode.color( &record, &vars ), silver80 ); // Defaults to silver if given non-matching record/variables
QCOMPARE( colorNode.color( record, vars ), silver80 ); // Defaults to silver if given non-matching record/variables
{
Variable c1( Variable::Type::COLOR, "c1", "white", Variable::Increment::PER_ITEM );
vars.addVariable( c1 );
}
QCOMPARE( colorNode.color( nullptr, &vars ), white );
QCOMPARE( colorNode.color( NullRecord(), vars ), white );
vars.incrementVariablesOnItem();
QCOMPARE( colorNode.color( nullptr, &vars ), white );
QCOMPARE( colorNode.color( NullRecord(), vars ), white );
{
Variable c1( Variable::Type::COLOR, "c1", "red", Variable::Increment::PER_ITEM );
vars.addVariable( c1 );
}
QCOMPARE( colorNode.color( nullptr, &vars ), red );
QCOMPARE( colorNode.color( NullRecord(), vars ), red );
{
Variable c1( Variable::Type::COLOR, "c1", "#8000FF00", Variable::Increment::PER_ITEM );
vars.addVariable( c1 );
}
QCOMPARE( colorNode.color( nullptr, &vars ), green80 );
QCOMPARE( colorNode.color( NullRecord(), vars ), green80 );
colorNode.setKey( "c2" );
QCOMPARE( colorNode.color( &record, nullptr ), silver80 );
QCOMPARE( colorNode.color( record, vars ), silver80 );
{
Variable c2( Variable::Type::COLOR, "c2", "#8000FF00", Variable::Increment::PER_ITEM );
vars.addVariable( c2 );
}
QCOMPARE( colorNode.color( nullptr, &vars ), green80 );
QCOMPARE( colorNode.color( NullRecord(), vars ), green80 );
///
/// Record beats variable
///
record["c2"] = "red";
QCOMPARE( colorNode.color( &record, &vars ), red );
QCOMPARE( colorNode.color( record, vars ), red );
}
+52 -54
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TestMerge.h"
#include "merge/Factory.h"
@@ -184,7 +185,7 @@ void TestMerge::text()
merge->setSource( file.fileName() );
QCOMPARE( merge->source(), file.fileName() );
const QList<Record*>& recordList = merge->recordList();
const QList<Record>& recordList = merge->recordList();
QCOMPARE( recordList.size(), 6 );
//
@@ -193,54 +194,54 @@ void TestMerge::text()
const char* h1 = keyed ? "header1" : "1";
const char* h2 = keyed ? "header 2" : "2";
const char* h3 = keyed ? "header3" : "3";
const Record* record;
Record record;
record = recordList[0];
QVERIFY( record->contains( h1 ) );
QCOMPARE( record->value( h1 ), QString( " val11" ) );
QVERIFY( record->contains( h2 ) );
QCOMPARE( record->value( h2 ), QString( "\"val 12\"" ) );
QVERIFY( record->contains( h3 ) );
QCOMPARE( record->value( h3 ), QString( " \"val 13\"" ) ); // NOTE: Treats as unquoted due to leading spaces
QVERIFY( record.contains( h1 ) );
QCOMPARE( record.value( h1 ), QString( " val11" ) );
QVERIFY( record.contains( h2 ) );
QCOMPARE( record.value( h2 ), QString( "\"val 12\"" ) );
QVERIFY( record.contains( h3 ) );
QCOMPARE( record.value( h3 ), QString( " \"val 13\"" ) ); // NOTE: Treats as unquoted due to leading spaces
record = recordList[1];
QVERIFY( record->contains( h1 ) );
QCOMPARE( record->value( h1 ), QString( " val21\"" ) );
QVERIFY( record->contains( h2 ) );
QCOMPARE( record->value( h2 ), QString( "\"val 22" ) );
QVERIFY( record->contains( h3 ) );
QCOMPARE( record->value( h3 ), QString( "" ) );
QVERIFY( record.contains( h1 ) );
QCOMPARE( record.value( h1 ), QString( " val21\"" ) );
QVERIFY( record.contains( h2 ) );
QCOMPARE( record.value( h2 ), QString( "\"val 22" ) );
QVERIFY( record.contains( h3 ) );
QCOMPARE( record.value( h3 ), QString( "" ) );
record = recordList[2];
QVERIFY( record->contains( h1 ) );
QCOMPARE( record->value( h1 ), QString( "\"\"" ) );
QVERIFY( record->contains( h2 ) );
QCOMPARE( record->value( h2 ), QString( "val \"32" ) );
QVERIFY( record->contains( h3 ) );
QCOMPARE( record->value( h3 ), QString( "val \"\"33" ) );
QVERIFY( record.contains( h1 ) );
QCOMPARE( record.value( h1 ), QString( "\"\"" ) );
QVERIFY( record.contains( h2 ) );
QCOMPARE( record.value( h2 ), QString( "val \"32" ) );
QVERIFY( record.contains( h3 ) );
QCOMPARE( record.value( h3 ), QString( "val \"\"33" ) );
record = recordList[3];
QVERIFY( record->contains( h1 ) );
QCOMPARE( record->value( h1 ), QString( "" ) );
QVERIFY( record->contains( h2 ) );
QCOMPARE( record->value( h2 ), QString( "" ) );
QVERIFY( record->contains( h3 ) );
QCOMPARE( record->value( h3 ), QString( "" ) );
QVERIFY( record.contains( h1 ) );
QCOMPARE( record.value( h1 ), QString( "" ) );
QVERIFY( record.contains( h2 ) );
QCOMPARE( record.value( h2 ), QString( "" ) );
QVERIFY( record.contains( h3 ) );
QCOMPARE( record.value( h3 ), QString( "" ) );
record = recordList[4];
QVERIFY( record->contains( h1 ) );
QCOMPARE( record->value( h1 ), QString( "val\n \t r \\ x51" ) );
QVERIFY( record->contains( h2 ) );
QCOMPARE( record->value( h2 ), QString( "val\n \t r \\ x52" ) );
QVERIFY( !record->contains( h3 ) );
QVERIFY( record.contains( h1 ) );
QCOMPARE( record.value( h1 ), QString( "val\n \t r \\ x51" ) );
QVERIFY( record.contains( h2 ) );
QCOMPARE( record.value( h2 ), QString( "val\n \t r \\ x52" ) );
QVERIFY( !record.contains( h3 ) );
record = recordList[5];
QVERIFY( record->contains( h1 ) );
QCOMPARE( record->value( h1 ), QString( "val \"61" ) );
QVERIFY( record->contains( h2 ) );
QCOMPARE( record->value( h2 ), QString( "val\"" ).append( delim ).append( "\n\"\u2019\\52" ) ); // NOTE: CR missing (QIODevice::Text strips all CRs from stream)
QVERIFY( record->contains( h3 ) );
QCOMPARE( record->value( h3 ), QString( "val63" ) );
QVERIFY( record.contains( h1 ) );
QCOMPARE( record.value( h1 ), QString( "val \"61" ) );
QVERIFY( record.contains( h2 ) );
QCOMPARE( record.value( h2 ), QString( "val\"" ).append( delim ).append( "\n\"\u2019\\52" ) ); // NOTE: CR missing (QIODevice::Text strips all CRs from stream)
QVERIFY( record.contains( h3 ) );
QCOMPARE( record.value( h3 ), QString( "val63" ) );
//
// Selection
@@ -249,13 +250,11 @@ void TestMerge::text()
merge->unselectAll();
QCOMPARE( merge->nSelectedRecords(), 0 );
record = recordList[1];
merge->select( (Record*)record );
merge->setSelected( 1 );
QCOMPARE( merge->nSelectedRecords(), 1 );
QCOMPARE( merge->selectedRecords().size(), 1 );
QCOMPARE( merge->selectedRecords().first(), record ); // Pointers same
merge->unselect( (Record*)record );
merge->setSelected( 1, false );
QCOMPARE( merge->nSelectedRecords(), 0 );
QCOMPARE( merge->selectedRecords().size(), 0 );
@@ -291,15 +290,15 @@ void TestMerge::text()
QCOMPARE( cloneMerge->id(), merge->id() );
QCOMPARE( cloneMerge->source(), merge->source() );
QCOMPARE( cloneMerge->recordList().size(), merge->recordList().size() );
QCOMPARE( *(cloneMerge->recordList()[0]), *(merge->recordList()[0]) ); // Pointers different
QCOMPARE( *(cloneMerge->recordList()[1]), *(merge->recordList()[1]) );
QCOMPARE( *(cloneMerge->recordList()[2]), *(merge->recordList()[2]) );
QCOMPARE( *(cloneMerge->recordList()[3]), *(merge->recordList()[3]) );
QCOMPARE( *(cloneMerge->recordList()[4]), *(merge->recordList()[4]) );
QCOMPARE( *(cloneMerge->recordList()[5]), *(merge->recordList()[5]) );
QCOMPARE( cloneMerge->recordList()[0], merge->recordList()[0] );
QCOMPARE( cloneMerge->recordList()[1], merge->recordList()[1] );
QCOMPARE( cloneMerge->recordList()[2], merge->recordList()[2] );
QCOMPARE( cloneMerge->recordList()[3], merge->recordList()[3] );
QCOMPARE( cloneMerge->recordList()[4], merge->recordList()[4] );
QCOMPARE( cloneMerge->recordList()[5], merge->recordList()[5] );
QCOMPARE( cloneMerge->nSelectedRecords(), merge->nSelectedRecords() );
QCOMPARE( cloneMerge->selectedRecords().size(), merge->selectedRecords().size() );
QCOMPARE( *(cloneMerge->selectedRecords()[0]), *(merge->selectedRecords()[0]) );
QCOMPARE( cloneMerge->selectedRecords()[0], merge->selectedRecords()[0] );
QCOMPARE( cloneMerge->keys(), merge->keys() );
QCOMPARE( cloneMerge->primaryKey(), merge->primaryKey() );
delete cloneMerge;
@@ -333,14 +332,13 @@ void TestMerge::record()
QVERIFY( record.contains( "key" ) );
QCOMPARE( record["key"], QString( "val" ) );
Record* cloneRecord = record.clone();
QCOMPARE( cloneRecord->isSelected(), true );
QVERIFY( cloneRecord->contains( "key" ) );
QCOMPARE( cloneRecord->value( "key" ), QString( "val" ) );
delete cloneRecord;
Record cloneRecord = record;
QCOMPARE( cloneRecord.isSelected(), true );
QVERIFY( cloneRecord.contains( "key" ) );
QCOMPARE( cloneRecord.value( "key" ), QString( "val" ) );
record.setSelected( false );
Record record2( &record );
Record record2( record );
QCOMPARE( record2.isSelected(), false );
QVERIFY( record2.contains( "key" ) );
QCOMPARE( record2["key"], QString( "val" ) );
+42 -46
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TestModel.h"
#include "model/Model.h"
@@ -29,6 +30,7 @@
#include "model/FrameContinuous.h"
#include "model/Region.h"
#include "model/Settings.h"
#include "model/Version.h"
#include "merge/Factory.h"
#include "merge/Merge.h"
@@ -36,6 +38,7 @@
#include "merge/TextCsv.h"
#include "merge/TextCsvKeys.h"
#include <QCoreApplication>
#include <QDebug>
#include <QRegularExpression>
@@ -48,8 +51,10 @@ using namespace glabels::merge;
void TestModel::initTestCase()
{
Factory::init();
QCoreApplication::setOrganizationName( glabels::model::Version::ORGANIZATION_NAME );
Settings::init();
Factory::init();
}
@@ -70,23 +75,23 @@ void TestModel::model()
QCOMPARE( model.h(), Distance( 0 ) );
Template tmplate( "Test Brand", "part", "desc", "testPaperId", 100, 400 );
FrameRect* frame = new FrameRect( 100, 200, 5, 0, 0, "rect1" );
QVERIFY( frame->w() != frame->h() );
FrameRect frame( 100, 200, 5, 0, 0, "rect1" );
QVERIFY( frame.w() != frame.h() );
tmplate.addFrame( frame );
model.setTmplate( &tmplate ); // Copies
QCOMPARE( model.tmplate()->brand(), QString( "Test Brand" ) );
QCOMPARE( model.tmplate()->part(), QString( "part" ) );
QCOMPARE( model.tmplate()->description(), QString( "desc" ) );
QCOMPARE( model.tmplate()->paperId(), QString( "testPaperId" ) );
QCOMPARE( model.tmplate()->pageWidth(), Distance( 100 ) );
QCOMPARE( model.tmplate()->pageHeight(), Distance( 400 ) );
model.setTmplate( tmplate ); // Copies
QCOMPARE( model.tmplate().brand(), QString( "Test Brand" ) );
QCOMPARE( model.tmplate().part(), QString( "part" ) );
QCOMPARE( model.tmplate().description(), QString( "desc" ) );
QCOMPARE( model.tmplate().paperId(), QString( "testPaperId" ) );
QCOMPARE( model.tmplate().pageWidth(), Distance( 100 ) );
QCOMPARE( model.tmplate().pageHeight(), Distance( 400 ) );
QVERIFY( model.isModified() );
QVERIFY( model.frame()->id() == frame->id() );
QVERIFY( model.frame()->id() == frame.id() );
QCOMPARE( model.w(), Distance( 100 ) );
QCOMPARE( model.h(), Distance( 200 ) );
QCOMPARE( model.w(), frame->w() );
QCOMPARE( model.h(), frame->h() );
QCOMPARE( model.w(), frame.w() );
QCOMPARE( model.h(), frame.h() );
model.clearModified();
QVERIFY( !model.isModified() );
@@ -99,8 +104,8 @@ void TestModel::model()
QVERIFY( model.rotate() );
QVERIFY( model.isModified() );
QCOMPARE( model.w(), frame->h() );
QCOMPARE( model.h(), frame->w() );
QCOMPARE( model.w(), frame.h() );
QCOMPARE( model.h(), frame.w() );
model.setRotate( false );
QVERIFY( !model.rotate() );
@@ -109,20 +114,20 @@ void TestModel::model()
QVERIFY( !model.isModified() );
model.setH( 300 ); // Default does nothing
QCOMPARE( model.h(), Distance( 200 ) );
QVERIFY( model.isModified() ); // Set anyway
QCOMPARE( model.h(), Distance( 200 ) ); // Should still bee 200
QVERIFY( !model.isModified() ); // Should not be modified
// Continuous frame implements setH()
Template tmplate2( "Test Brand2", "part2", "desc2", "testPaperId2", 100, 400 );
FrameContinuous* frame2 = new FrameContinuous( 100, 0, 500, 200, "continuous1" );
QCOMPARE( frame2->h(), Distance( 200 ) );
FrameContinuous frame2( 100, 0, 500, 200, "continuous1" );
QCOMPARE( frame2.h(), Distance( 200 ) );
tmplate2.addFrame( frame2 );
model.setTmplate( &tmplate2 );
QVERIFY( model.frame()->id() == frame2->id() );
model.setTmplate( tmplate2 );
QVERIFY( model.frame()->id() == frame2.id() );
QCOMPARE( model.w(), Distance( 100 ) );
QCOMPARE( model.h(), Distance( 200 ) );
QCOMPARE( model.w(), frame2->w() );
QCOMPARE( model.h(), frame2->h() );
QCOMPARE( model.w(), frame2.w() );
QCOMPARE( model.h(), frame2.h() );
model.clearModified();
QVERIFY( !model.isModified() );
@@ -300,10 +305,10 @@ void TestModel::saveRestore()
// Set template/frame
//
Template tmplate( "Test Brand", "part", "desc", "testPaperId", 110, 410 );
FrameRect* frame = new FrameRect( 120, 220, 5, 0, 0, "rect1" );
FrameRect frame( 120, 220, 5, 0, 0, "rect1" );
tmplate.addFrame( frame );
model->setTmplate( &tmplate ); // Copies
QCOMPARE( model->tmplate()->brand(), QString( "Test Brand" ) );
model->setTmplate( tmplate ); // Copies
QCOMPARE( model->tmplate().brand(), QString( "Test Brand" ) );
QVERIFY( model->isModified() );
model->clearModified();
@@ -327,9 +332,9 @@ void TestModel::saveRestore()
Variable i( Variable::Type::INTEGER, "i", "2", Variable::Increment::PER_ITEM, "2" );
Variable f( Variable::Type::FLOATING_POINT, "f", "6.54", Variable::Increment::PER_COPY, "0.12" );
model->variables()->addVariable( i );
model->variables().addVariable( i );
QVERIFY( model->isModified() );
model->variables()->addVariable( f );
model->variables().addVariable( f );
QVERIFY( model->isModified() );
model->clearModified();
@@ -375,7 +380,6 @@ void TestModel::saveRestore()
Model* saved = model->save();
QVERIFY( saved->isModified() );
QCOMPARE( saved->merge(), model->merge() ); // Shared
QCOMPARE( saved->variables(), model->variables() ); // Shared
QCOMPARE( saved->isModified(), model->isModified() );
QCOMPARE( saved->shortName(), modelShortName );
QCOMPARE( saved->shortName(), model->shortName() );
@@ -391,10 +395,10 @@ void TestModel::saveRestore()
// Modify original
Template tmplate2( "Test Brand2", "part2", "desc2", "testPaperId2", 230, 630 );
FrameRect* frame2 = new FrameRect( 240, 340, 5, 0, 0, "rect2" );
FrameRect frame2( 240, 340, 5, 0, 0, "rect2" );
tmplate2.addFrame( frame2 );
model->setTmplate( &tmplate2 );
QCOMPARE( model->tmplate()->brand(), QString( "Test Brand2" ) );
model->setTmplate( tmplate2 );
QCOMPARE( model->tmplate().brand(), QString( "Test Brand2" ) );
QCOMPARE( model->w(), Distance( 240 ) );
QCOMPARE( model->h(), Distance( 340 ) );
@@ -419,21 +423,20 @@ void TestModel::saveRestore()
QCOMPARE( merge2->source(), csv2.fileName() );
QCOMPARE( merge2->recordList().size(), 4 );
model->setMerge( merge2 ); // Deletes original so saved->merge() now invalid
model->setMerge( merge2 );
QCOMPARE( model->merge(), merge2 );
Model* modified = model->save();
QCOMPARE( modified->merge(), merge2 ); // Shared
Variable c( Variable::Type::COLOR, "c", "blue", Variable::Increment::PER_PAGE );
model->variables()->addVariable( c );
QCOMPARE( model->variables(), saved->variables() ); // Shared.
model->variables().addVariable( c );
// Verify differences
QVERIFY( model->shortName() != modelShortName );
QVERIFY( model->shortName() != saved->shortName() );
QVERIFY( model->fileName() != saved->fileName() );
QVERIFY( model->tmplate()->brand() != saved->tmplate()->brand() );
QVERIFY( model->tmplate().brand() != saved->tmplate().brand() );
QVERIFY( model->rotate() != saved->rotate() );
QVERIFY( model->w() != saved->w() );
QVERIFY( model->h() != saved->h() );
@@ -448,7 +451,7 @@ void TestModel::saveRestore()
QCOMPARE( model->shortName(), modelShortName );
QCOMPARE( model->shortName(), saved->shortName() );
QCOMPARE( model->fileName(), saved->fileName() );
QCOMPARE( model->tmplate()->brand(), saved->tmplate()->brand() );
QCOMPARE( model->tmplate().brand(), saved->tmplate().brand() );
QCOMPARE( model->rotate(), saved->rotate() );
QCOMPARE( model->w(), saved->w() );
QCOMPARE( model->h(), saved->h() );
@@ -459,16 +462,12 @@ void TestModel::saveRestore()
QCOMPARE( model->objectList().at(1)->x0(), saved->objectList().at(1)->x0() );
QCOMPARE( model->objectList().at(1)->y0(), saved->objectList().at(1)->y0() );
QCOMPARE( model->merge(), merge2 ); // Unchanged
QVERIFY( model->merge() != saved->merge() ); // NOTE saved->merge() now points to deleted object
QCOMPARE( model->variables(), saved->variables() ); // Unchanged
// Unrestore
model->restore( modified );
QVERIFY( model->shortName() != modelShortName );
QVERIFY( model->shortName() != saved->shortName() );
QVERIFY( model->fileName() != saved->fileName() );
QVERIFY( model->tmplate()->brand() != saved->tmplate()->brand() );
QVERIFY( model->tmplate().brand() != saved->tmplate().brand() );
QVERIFY( model->rotate() != saved->rotate() );
QVERIFY( model->w() != saved->w() );
QVERIFY( model->h() != saved->h() );
@@ -477,11 +476,10 @@ void TestModel::saveRestore()
QVERIFY( model->objectList().at(0)->x0() != saved->objectList().at(0)->x0() );
QVERIFY( model->objectList().at(0)->y0() != saved->objectList().at(0)->y0() );
QCOMPARE( model->merge(), merge2 ); // Same
QCOMPARE( model->variables(), saved->variables() ); // Same
QCOMPARE( model->shortName(), modified->shortName() );
QCOMPARE( model->fileName(), modified->fileName() );
QCOMPARE( model->tmplate()->brand(), modified->tmplate()->brand() );
QCOMPARE( model->tmplate().brand(), modified->tmplate().brand() );
QCOMPARE( model->rotate(), modified->rotate() );
QCOMPARE( model->w(), modified->w() );
QCOMPARE( model->h(), modified->h() );
@@ -489,8 +487,6 @@ void TestModel::saveRestore()
QCOMPARE( model->objectList().at(0)->x0(), modified->objectList().at(0)->x0() );
QCOMPARE( model->objectList().at(0)->y0(), modified->objectList().at(0)->y0() );
delete model->merge(); // Final instance owned by us
delete model->variables(); // Instance owned by us
delete model;
delete saved;
delete modified;
+5 -7
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TestModelImageObject.h"
#include "Test_Constants.h"
@@ -85,7 +86,7 @@ void TestModelImageObject::readImageFile()
QFileInfo pngGreenFileInfo( pngGreen.fileName() );
Variable var( Variable::Type::STRING, "var", pngGreenFileInfo.fileName(), Variable::Increment::PER_ITEM ); // Relative path
model.variables()->addVariable( var );
model.variables().addVariable( var );
model.addObject( object.clone() );
@@ -103,7 +104,7 @@ void TestModelImageObject::readImageFile()
QFileInfo svgMagentaFileInfo( svgMagenta.fileName() );
Variable var2( Variable::Type::STRING, "var2", svgMagentaFileInfo.fileName(), Variable::Increment::PER_ITEM ); // Absolute path
model.variables()->addVariable( var2 );
model.variables().addVariable( var2 );
model.addObject( object.clone() );
@@ -187,7 +188,7 @@ void TestModelImageObject::readImageFile()
///
/// Draw
///
const QList<Record*> records = merge->selectedRecords();
const QList<Record> records = merge->selectedRecords();
QCOMPARE( records.size(), 8 );
QImage paintDevice( 10, 10 * model.objectList().size() * records.size(), QImage::Format_RGB32 );
@@ -207,7 +208,7 @@ void TestModelImageObject::readImageFile()
{
// Merge
qDebug() << "record" << i;
color = records[i]->value( "type" ) == "png" ? Qt::blue : Qt::red;
color = records[i].value( "type" ) == "png" ? Qt::blue : Qt::red;
QCOMPARE( paintDevice.pixelColor( 1, 0 + i * yTranslate ), white );
QCOMPARE( paintDevice.pixelColor( 1, 1 + i * yTranslate ), color );
QCOMPARE( paintDevice.pixelColor( 1, 8 + i * yTranslate ), color );
@@ -246,7 +247,4 @@ void TestModelImageObject::readImageFile()
QCOMPARE( paintDevice.pixelColor( 1, 49 + i * yTranslate ), white );
QCOMPARE( paintDevice.pixelColor( 9, 49 + i * yTranslate ), magentaShadow );
}
delete model.merge();
delete model.variables();
}
+14 -11
View File
@@ -18,13 +18,14 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TestRawText.h"
#include "model/RawText.h"
#include "merge/Record.h"
#include <QtDebug>
#include <QDebug>
QTEST_MAIN(TestRawText)
@@ -38,18 +39,20 @@ void TestRawText::rawText()
RawText rawText;
Record record;
Variables variables;
QVERIFY( rawText.isEmpty() );
QVERIFY( !rawText.hasPlaceHolders() );
QCOMPARE( rawText.toString(), QString( "" ) );
QCOMPARE( rawText.toStdString(), std::string( "" ) );
QCOMPARE( rawText.expand( &record, nullptr ), QString( "" ) );
QCOMPARE( rawText.expand( record, variables ), QString( "" ) );
rawText = "text";
QVERIFY( !rawText.isEmpty() );
QVERIFY( !rawText.hasPlaceHolders() );
QCOMPARE( rawText.toString(), QString( "text" ) );
QCOMPARE( rawText.toStdString(), std::string( "text" ) );
QCOMPARE( rawText.expand( &record, nullptr ), QString( "text" ) );
QCOMPARE( rawText.expand( record, variables ), QString( "text" ) );
RawText rawText2( "text" );
QVERIFY( !rawText2.isEmpty() );
@@ -61,34 +64,34 @@ void TestRawText::rawText()
QVERIFY( rawText.hasPlaceHolders() );
QCOMPARE( rawText.toString(), QString( "${key1}" ) );
QCOMPARE( rawText.toStdString(), std::string( "${key1}" ) );
QCOMPARE( rawText.expand( &record, nullptr ), QString( "" ) );
QCOMPARE( rawText.expand( record, variables ), QString( "" ) );
///
/// Record
///
record["key1"] = "val1";
QCOMPARE( rawText.expand( &record, nullptr ), QString( "val1" ) );
QCOMPARE( rawText.expand( record, variables ), QString( "val1" ) );
rawText = "${key1}${key2}";
QVERIFY( rawText.hasPlaceHolders() );
QCOMPARE( rawText.expand( &record, nullptr ), QString( "val1" ) );
QCOMPARE( rawText.expand( record, variables ), QString( "val1" ) );
record["key2"] = "val2";
QCOMPARE( rawText.expand( &record, nullptr ), QString( "val1val2" ) );
QCOMPARE( rawText.expand( record, variables ), QString( "val1val2" ) );
rawText = "${key1}text${key2}";
QVERIFY( rawText.hasPlaceHolders() );
QCOMPARE( rawText.expand( &record, nullptr ), QString( "val1textval2" ) );
QCOMPARE( rawText.expand( record, variables ), QString( "val1textval2" ) );
rawText = "text1${key1}text2${key2}text3";
QVERIFY( rawText.hasPlaceHolders() );
QCOMPARE( rawText.expand( &record, nullptr ), QString( "text1val1text2val2text3" ) );
QCOMPARE( rawText.expand( record, variables ), QString( "text1val1text2val2text3" ) );
rawText = "${key1}text${key2}${key3}";
QVERIFY( rawText.hasPlaceHolders() );
QCOMPARE( rawText.expand( &record, nullptr ), QString( "val1textval2" ) );
QCOMPARE( rawText.expand( record, variables ), QString( "val1textval2" ) );
rawText = "${key2}${key3}${key1}";
QVERIFY( rawText.hasPlaceHolders() );
QCOMPARE( rawText.expand( &record, nullptr ), QString( "val2val1" ) );
QCOMPARE( rawText.expand( record, variables ), QString( "val2val1" ) );
}
+48 -47
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TestSubstitutionField.h"
#include "model/SubstitutionField.h"
@@ -174,10 +175,10 @@ void TestSubstitutionField::simpleEvaluation()
record1[ "3" ] = "Opqrstu";
record1[ "4" ] = "Vwxyz!@";
QCOMPARE( f1.evaluate( &record1, &variables ), QString( "Abcdefg" ) );
QCOMPARE( f2.evaluate( &record1, &variables ), QString( "Hijklmn" ) );
QCOMPARE( f3.evaluate( &record1, &variables ), QString( "Opqrstu" ) );
QCOMPARE( f4.evaluate( &record1, &variables ), QString( "Vwxyz!@" ) );
QCOMPARE( f1.evaluate( record1, variables ), QString( "Abcdefg" ) );
QCOMPARE( f2.evaluate( record1, variables ), QString( "Hijklmn" ) );
QCOMPARE( f3.evaluate( record1, variables ), QString( "Opqrstu" ) );
QCOMPARE( f4.evaluate( record1, variables ), QString( "Vwxyz!@" ) );
merge::Record record2;
record2[ "1" ] = "1234567";
@@ -185,10 +186,10 @@ void TestSubstitutionField::simpleEvaluation()
record2[ "3" ] = "8901234";
record2[ "4" ] = "#$%^&*";
QCOMPARE( f1.evaluate( &record2, &variables ), QString( "1234567" ) );
QCOMPARE( f2.evaluate( &record2, &variables ), QString( "FooBar" ) );
QCOMPARE( f3.evaluate( &record2, &variables ), QString( "8901234" ) );
QCOMPARE( f4.evaluate( &record2, &variables ), QString( "#$%^&*" ) );
QCOMPARE( f1.evaluate( record2, variables ), QString( "1234567" ) );
QCOMPARE( f2.evaluate( record2, variables ), QString( "FooBar" ) );
QCOMPARE( f3.evaluate( record2, variables ), QString( "8901234" ) );
QCOMPARE( f4.evaluate( record2, variables ), QString( "#$%^&*" ) );
}
@@ -209,17 +210,17 @@ void TestSubstitutionField::defaultValueEvaluation()
record1[ "3" ] = "Opqrstu";
record1[ "4" ] = "Vwxyz!@";
QCOMPARE( f1.evaluate( &record1, &variables ), QString( "Abcdefg" ) );
QCOMPARE( f2.evaluate( &record1, &variables ), QString( "Hijklmn" ) );
QCOMPARE( f3.evaluate( &record1, &variables ), QString( "Opqrstu" ) );
QCOMPARE( f4.evaluate( &record1, &variables ), QString( "Vwxyz!@" ) );
QCOMPARE( f1.evaluate( record1, variables ), QString( "Abcdefg" ) );
QCOMPARE( f2.evaluate( record1, variables ), QString( "Hijklmn" ) );
QCOMPARE( f3.evaluate( record1, variables ), QString( "Opqrstu" ) );
QCOMPARE( f4.evaluate( record1, variables ), QString( "Vwxyz!@" ) );
merge::Record record2; // All fields empty
QCOMPARE( f1.evaluate( &record2, &variables ), QString( "foo1" ) );
QCOMPARE( f2.evaluate( &record2, &variables ), QString( "foo2" ) );
QCOMPARE( f3.evaluate( &record2, &variables ), QString( "foo3" ) );
QCOMPARE( f4.evaluate( &record2, &variables ), QString( "foo4" ) );
QCOMPARE( f1.evaluate( record2, variables ), QString( "foo1" ) );
QCOMPARE( f2.evaluate( record2, variables ), QString( "foo2" ) );
QCOMPARE( f3.evaluate( record2, variables ), QString( "foo3" ) );
QCOMPARE( f4.evaluate( record2, variables ), QString( "foo4" ) );
merge::Record record3;
record3[ "1" ] = "xyzzy";
@@ -227,10 +228,10 @@ void TestSubstitutionField::defaultValueEvaluation()
// Field "3" empty
record3[ "4" ] = "plugh";
QCOMPARE( f1.evaluate( &record3, &variables ), QString( "xyzzy" ) );
QCOMPARE( f2.evaluate( &record3, &variables ), QString( "foo2" ) );
QCOMPARE( f3.evaluate( &record3, &variables ), QString( "foo3" ) );
QCOMPARE( f4.evaluate( &record3, &variables ), QString( "plugh" ) );
QCOMPARE( f1.evaluate( record3, variables ), QString( "xyzzy" ) );
QCOMPARE( f2.evaluate( record3, variables ), QString( "foo2" ) );
QCOMPARE( f3.evaluate( record3, variables ), QString( "foo3" ) );
QCOMPARE( f4.evaluate( record3, variables ), QString( "plugh" ) );
}
@@ -261,15 +262,15 @@ void TestSubstitutionField::formattedStringEvaluation()
record1[ "7" ] = "-100";
record1[ "8" ] = "3.14";
QCOMPARE( f1.evaluate( &record1, &variables ), QString( " 0" ) );
QCOMPARE( f2.evaluate( &record1, &variables ), QString( " 1" ) );
QCOMPARE( f3.evaluate( &record1, &variables ), QString( " -1" ) );
QCOMPARE( f4.evaluate( &record1, &variables ), QString( " 3.14" ) );
QCOMPARE( f1.evaluate( record1, variables ), QString( " 0" ) );
QCOMPARE( f2.evaluate( record1, variables ), QString( " 1" ) );
QCOMPARE( f3.evaluate( record1, variables ), QString( " -1" ) );
QCOMPARE( f4.evaluate( record1, variables ), QString( " 3.14" ) );
QCOMPARE( f5.evaluate( &record1, &variables ), QString( "0 " ) );
QCOMPARE( f6.evaluate( &record1, &variables ), QString( "100 " ) );
QCOMPARE( f7.evaluate( &record1, &variables ), QString( "-100 " ) );
QCOMPARE( f8.evaluate( &record1, &variables ), QString( "3.14 " ) );
QCOMPARE( f5.evaluate( record1, variables ), QString( "0 " ) );
QCOMPARE( f6.evaluate( record1, variables ), QString( "100 " ) );
QCOMPARE( f7.evaluate( record1, variables ), QString( "-100 " ) );
QCOMPARE( f8.evaluate( record1, variables ), QString( "3.14 " ) );
}
@@ -300,15 +301,15 @@ void TestSubstitutionField::formattedFloatEvaluation()
record1[ "7" ] = "-100";
record1[ "8" ] = "3.14";
QCOMPARE( f1.evaluate( &record1, &variables ), QString( "+0.00" ) );
QCOMPARE( f2.evaluate( &record1, &variables ), QString( "+1.00" ) );
QCOMPARE( f3.evaluate( &record1, &variables ), QString( "-1.00" ) );
QCOMPARE( f4.evaluate( &record1, &variables ), QString( "+3.14" ) );
QCOMPARE( f1.evaluate( record1, variables ), QString( "+0.00" ) );
QCOMPARE( f2.evaluate( record1, variables ), QString( "+1.00" ) );
QCOMPARE( f3.evaluate( record1, variables ), QString( "-1.00" ) );
QCOMPARE( f4.evaluate( record1, variables ), QString( "+3.14" ) );
QCOMPARE( f5.evaluate( &record1, &variables ), QString( "+0.00e+00" ) );
QCOMPARE( f6.evaluate( &record1, &variables ), QString( "+1.00e+02" ) );
QCOMPARE( f7.evaluate( &record1, &variables ), QString( "-1.00e+02" ) );
QCOMPARE( f8.evaluate( &record1, &variables ), QString( "+3.14e+00" ) );
QCOMPARE( f5.evaluate( record1, variables ), QString( "+0.00e+00" ) );
QCOMPARE( f6.evaluate( record1, variables ), QString( "+1.00e+02" ) );
QCOMPARE( f7.evaluate( record1, variables ), QString( "-1.00e+02" ) );
QCOMPARE( f8.evaluate( record1, variables ), QString( "+3.14e+00" ) );
}
@@ -339,15 +340,15 @@ void TestSubstitutionField::formattedIntEvaluation()
record1[ "7" ] = "-1";
record1[ "8" ] = "314";
QCOMPARE( f1.evaluate( &record1, &variables ), QString( "00000000" ) );
QCOMPARE( f2.evaluate( &record1, &variables ), QString( "00000001" ) );
QCOMPARE( f3.evaluate( &record1, &variables ), QString( "-0000001" ) );
QCOMPARE( f4.evaluate( &record1, &variables ), QString( "00000000" ) ); // Invalid integer value
QCOMPARE( f1.evaluate( record1, variables ), QString( "00000000" ) );
QCOMPARE( f2.evaluate( record1, variables ), QString( "00000001" ) );
QCOMPARE( f3.evaluate( record1, variables ), QString( "-0000001" ) );
QCOMPARE( f4.evaluate( record1, variables ), QString( "00000000" ) ); // Invalid integer value
QCOMPARE( f5.evaluate( &record1, &variables ), QString( "00000064" ) ); // 100(decimal) == 64(hex)
QCOMPARE( f6.evaluate( &record1, &variables ), QString( "00000100" ) );
QCOMPARE( f7.evaluate( &record1, &variables ), QString( "00000000" ) ); // Invalid unsigned integer
QCOMPARE( f8.evaluate( &record1, &variables ), QString( "0000013a" ) ); // 314(decimal) == 13a(hex)
QCOMPARE( f5.evaluate( record1, variables ), QString( "00000064" ) ); // 100(decimal) == 64(hex)
QCOMPARE( f6.evaluate( record1, variables ), QString( "00000100" ) );
QCOMPARE( f7.evaluate( record1, variables ), QString( "00000000" ) ); // Invalid unsigned integer
QCOMPARE( f8.evaluate( record1, variables ), QString( "0000013a" ) ); // 314(decimal) == 13a(hex)
}
@@ -370,7 +371,7 @@ void TestSubstitutionField::newLineEvaluation()
merge::Record record3;
// ADDR2 not defined
QCOMPARE( addr2.evaluate( &record1, &variables ), QString( "\nApt. 5B" ) ); // Prepends a newline
QCOMPARE( addr2.evaluate( &record2, &variables ), QString( "" ) ); // Evaluates empty
QCOMPARE( addr2.evaluate( &record3, &variables ), QString( "" ) ); // Evaluates empty
QCOMPARE( addr2.evaluate( record1, variables ), QString( "\nApt. 5B" ) ); // Prepends a newline
QCOMPARE( addr2.evaluate( record2, variables ), QString( "" ) ); // Evaluates empty
QCOMPARE( addr2.evaluate( record3, variables ), QString( "" ) ); // Evaluates empty
}

Some files were not shown because too many files have changed in this diff Show More