Merge branch 'ContinuousRollLabels'

This commit is contained in:
Jim Evins
2018-11-30 21:04:41 -05:00
133 changed files with 7973 additions and 2822 deletions
+2
View File
@@ -26,7 +26,9 @@ set (Model_sources
FileUtil.cpp
Frame.cpp
FrameCd.cpp
FrameContinuous.cpp
FrameEllipse.cpp
FramePath.cpp
FrameRect.cpp
FrameRound.cpp
Handles.cpp
+15 -11
View File
@@ -67,13 +67,10 @@ namespace glabels
QList<Vendor*> Db::mVendors;
QStringList Db::mVendorNames;
QList<Template*> Db::mTemplates;
QString Db::mPaperNameOther;
Db::Db()
{
mPaperNameOther = tr("Other");
readPapers();
readCategories();
readVendors();
@@ -209,6 +206,15 @@ namespace glabels
{
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 )
{
@@ -225,9 +231,13 @@ namespace glabels
{
if ( !id.isNull() && !id.isEmpty() )
{
if ( isPaperIdOther( id ) )
if ( id == "roll" )
{
return mPaperNameOther;
return tr("Roll");
}
else
{
return tr("Other");
}
const Paper *paper = lookupPaperFromId( id );
@@ -256,12 +266,6 @@ namespace glabels
}
bool Db::isPaperIdOther( const QString& id )
{
return ( id == "Other" );
}
void Db::registerCategory( Category *category )
{
if ( !isCategoryIdKnown( category->id() ) )
-3
View File
@@ -71,7 +71,6 @@ namespace glabels
static QString lookupPaperIdFromName( const QString& name );
static QString lookupPaperNameFromId( const QString& id );
static bool isPaperIdKnown( const QString& id );
static bool isPaperIdOther( const QString& id );
static void registerCategory( Category *category );
static const Category *lookupCategoryFromName( const QString& name );
@@ -134,8 +133,6 @@ namespace glabels
static QList<Template*> mTemplates;
static QString mPaperNameOther;
};
}
+10
View File
@@ -208,3 +208,13 @@ namespace glabels
}
}
QDebug operator<<( QDebug dbg, const glabels::model::Distance& distance )
{
QDebugStateSaver saver(dbg);
dbg.nospace() << distance.pt() << "pt";
return dbg;
}
+12
View File
@@ -69,6 +69,7 @@ namespace glabels
Distance& operator+=( const Distance& d );
Distance& operator-=( const Distance& d );
Distance& operator*=( double f );
Distance operator-();
friend inline Distance operator+( const Distance& d1, const Distance& d2 );
@@ -100,6 +101,10 @@ namespace glabels
}
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::Distance& distance );
//
// Inline methods
//
@@ -200,6 +205,13 @@ namespace glabels
}
inline Distance& Distance::operator*=( double f )
{
mDPts *= f;
return *this;
}
inline Distance Distance::operator-()
{
return Distance::pt( -mDPts );
+66 -11
View File
@@ -20,6 +20,12 @@
#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 <algorithm>
@@ -42,12 +48,12 @@ namespace glabels
mId = other.mId;
mNLabels = 0;
foreach ( Layout *layout, mLayouts )
foreach ( const Layout& layout, other.mLayouts )
{
addLayout( layout->dup() );
addLayout( layout );
}
foreach ( Markup *markup, mMarkups )
foreach ( Markup *markup, other.mMarkups )
{
addMarkup( markup->dup() );
}
@@ -72,7 +78,7 @@ namespace glabels
}
const QList<Layout*>& Frame::layouts() const
const QList<Layout>& Frame::layouts() const
{
return mLayouts;
}
@@ -89,13 +95,13 @@ namespace glabels
QVector<Point> origins( nLabels() );
int i = 0;
foreach ( Layout *layout, mLayouts )
foreach ( const Layout& layout, mLayouts )
{
for ( int iy = 0; iy < layout->ny(); iy++ )
for ( int iy = 0; iy < layout.ny(); iy++ )
{
for ( int ix = 0; ix < layout->nx(); ix++ )
for ( int ix = 0; ix < layout.nx(); ix++ )
{
origins[i++] = Point( ix*layout->dx() + layout->x0(), iy*layout->dy() + layout->y0() );
origins[i++] = Point( ix*layout.dx() + layout.x0(), iy*layout.dy() + layout.y0() );
}
}
}
@@ -106,12 +112,12 @@ namespace glabels
}
void Frame::addLayout( Layout *layout )
void Frame::addLayout( const Layout& layout )
{
mLayouts << layout;
// Update total number of labels
mNLabels += layout->nx() * layout->ny();
mNLabels += layout.nx() * layout.ny();
// Update layout description
if ( mLayouts.size() == 1 )
@@ -122,7 +128,7 @@ namespace glabels
* %3 = total number of labels on a page (sheet).
*/
mLayoutDescription = QString( tr("%1 x %2 (%3 per sheet)") )
.arg(layout->nx()).arg(layout->ny()).arg(mNLabels);
.arg(layout.nx()).arg(layout.ny()).arg(mNLabels);
}
else
{
@@ -137,5 +143,54 @@ namespace glabels
mMarkups << markup;
}
void Frame::setH( const Distance& h )
{
// Default implementation does nothing
}
}
}
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);
dbg.nospace() << "UNKNOWN FRAME";
return dbg;
}
}
+12 -4
View File
@@ -27,6 +27,7 @@
#include "Point.h"
#include <QCoreApplication>
#include <QDebug>
#include <QList>
#include <QPainterPath>
#include <QString>
@@ -56,23 +57,26 @@ namespace glabels
QString id() const;
int nLabels() const;
QString layoutDescription() const;
const QList<Layout*>& layouts() const;
const QList<Layout>& layouts() const;
const QList<Markup*>& markups() const;
QVector<Point> getOrigins() const;
void addLayout( Layout* layout );
void addLayout( const Layout& layout );
void addMarkup( Markup* markup );
virtual Distance w() const = 0;
virtual Distance h() const = 0;
virtual void setH( const Distance& h );
virtual QString sizeDescription( const Units& units ) const = 0;
virtual bool isSimilarTo( Frame* other ) const = 0;
virtual const QPainterPath& path() const = 0;
virtual const QPainterPath& clipPath() const = 0;
virtual QPainterPath marginPath( const Distance& size ) const = 0;
virtual QPainterPath marginPath( const Distance& xSize,
const Distance& ySize ) const = 0;
private:
@@ -80,7 +84,7 @@ namespace glabels
int mNLabels;
QString mLayoutDescription;
QList<Layout*> mLayouts;
QList<Layout> mLayouts;
QList<Markup*> mMarkups;
};
@@ -88,4 +92,8 @@ namespace glabels
}
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::Frame& frame );
#endif // model_Frame_h
+24 -10
View File
@@ -93,15 +93,6 @@ namespace glabels
}
FrameCd::FrameCd( const FrameCd& other )
: Frame(other),
mR1(other.mR1), mR2(other.mR2), mW(other.mW), mH(other.mH), mWaste(other.mWaste),
mPath(other.mPath)
{
// empty
}
Frame* FrameCd::dup() const
{
return new FrameCd( *this );
@@ -187,8 +178,12 @@ namespace glabels
}
QPainterPath FrameCd::marginPath( const Distance& size ) const
QPainterPath FrameCd::marginPath( const Distance& xSize,
const Distance& ySize ) const
{
// Note: ignore ySize, assume xSize == ySize
Distance size = xSize;
Distance wReal = (mW == 0) ? 2*mR1 : mW;
Distance hReal = (mH == 0) ? 2*mR1 : mH;
@@ -219,3 +214,22 @@ namespace glabels
}
}
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;
}
+7 -2
View File
@@ -42,7 +42,7 @@ namespace glabels
const Distance& waste,
const QString& id = "0" );
FrameCd( const FrameCd &other );
FrameCd( const FrameCd &other ) = default;
Frame *dup() const override;
@@ -58,7 +58,8 @@ namespace glabels
const QPainterPath& path() const override;
const QPainterPath& clipPath() const override;
QPainterPath marginPath( const Distance& size ) const override;
QPainterPath marginPath( const Distance& xSize,
const Distance& ySize ) const override;
private:
@@ -77,4 +78,8 @@ namespace glabels
}
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::FrameCd& frame );
#endif // model_FrameCd_h
+166
View File
@@ -0,0 +1,166 @@
/* FrameContinuous.cpp
*
* Copyright (C) 2018 Jim 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 "FrameContinuous.h"
#include "Constants.h"
#include "StrUtil.h"
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)
{
mPath.addRect( 0, 0, mW.pt(), mH.pt() );
}
Frame* FrameContinuous::dup() const
{
return new FrameContinuous( *this );
}
Distance FrameContinuous::w() const
{
return mW;
}
Distance FrameContinuous::h() const
{
return mH;
}
Distance FrameContinuous::hMin() const
{
return mHMin;
}
Distance FrameContinuous::hMax() const
{
return mHMax;
}
Distance FrameContinuous::hDefault() const
{
return mHDefault;
}
void FrameContinuous::setH( const Distance& h )
{
mH = h;
mPath = QPainterPath(); // clear path
mPath.addRect( 0, 0, mW.pt(), mH.pt() );
}
QString FrameContinuous::sizeDescription( const Units& units ) const
{
if ( units.toEnum() == Units::IN )
{
QString wStr = StrUtil::formatFraction( mW.in() );
return QString().sprintf( "%s %s %s",
qPrintable(wStr),
qPrintable(units.toTrName()),
qPrintable(tr("wide")) );
}
else
{
return QString().sprintf( "%.3f %s %s",
mW.inUnits(units),
qPrintable(units.toTrName()),
qPrintable(tr("wide")) );
}
}
bool FrameContinuous::isSimilarTo( Frame* other ) const
{
if ( auto *otherContinuous = dynamic_cast<FrameContinuous*>(other) )
{
if ( fabs( mW - otherContinuous->mW ) <= EPSILON )
{
return true;
}
}
return false;
}
const QPainterPath& FrameContinuous::path() const
{
return mPath;
}
const QPainterPath& FrameContinuous::clipPath() const
{
return mPath;
}
QPainterPath FrameContinuous::marginPath( const Distance& xSize,
const Distance& ySize ) const
{
Distance w = mW - 2*xSize;
Distance h = mH - 2*ySize;
QPainterPath path;
path.addRect( xSize.pt(), ySize.pt(), w.pt(), h.pt() );
return path;
}
}
}
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;
}
+85
View File
@@ -0,0 +1,85 @@
/* FrameContinuous.h
*
* Copyright (C) 2018 Jim 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_FrameContinuous_h
#define model_FrameContinuous_h
#include "Frame.h"
namespace glabels
{
namespace model
{
class FrameContinuous : public Frame
{
Q_DECLARE_TR_FUNCTIONS(FrameContinuous)
public:
FrameContinuous( const Distance& w,
const Distance& hMin,
const Distance& hMax,
const Distance& hDefault,
const QString& id = "0" );
FrameContinuous( const FrameContinuous& other ) = default;
Frame* dup() const override;
Distance w() const override;
Distance h() const override;
Distance hMin() const;
Distance hMax() const;
Distance hDefault() const;
void setH( const Distance& h ) override;
QString sizeDescription( const Units& units ) const override;
bool isSimilarTo( Frame* other ) const override;
const QPainterPath& path() const override;
const QPainterPath& clipPath() const override;
QPainterPath marginPath( const Distance& xSize,
const Distance& ySize ) const override;
private:
Distance mW;
Distance mHMin;
Distance mHMax;
Distance mHDefault;
Distance mH;
QPainterPath mPath;
};
}
}
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::FrameContinuous& frame );
#endif // model_FrameContinuous_h
+22 -8
View File
@@ -40,13 +40,6 @@ namespace glabels
}
FrameEllipse::FrameEllipse( const FrameEllipse& other )
: Frame(other), mW(other.mW), mH(other.mH), mWaste(other.mWaste), mPath(other.mPath)
{
// empty
}
Frame* FrameEllipse::dup() const
{
return new FrameEllipse( *this );
@@ -119,8 +112,12 @@ namespace glabels
}
QPainterPath FrameEllipse::marginPath( const Distance& size ) const
QPainterPath FrameEllipse::marginPath( const Distance& xSize,
const Distance& ySize ) const
{
// Note: ignore ySize, assume xSize == ySize
Distance size = xSize;
Distance w = mW - 2*size;
Distance h = mH - 2*size;
@@ -132,3 +129,20 @@ namespace glabels
}
}
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;
}
+7 -2
View File
@@ -40,7 +40,7 @@ namespace glabels
const Distance& waste,
const QString& id = "0" );
FrameEllipse( const FrameEllipse& other );
FrameEllipse( const FrameEllipse& other ) = default;
Frame* dup() const override;
@@ -54,7 +54,8 @@ namespace glabels
const QPainterPath& path() const override;
const QPainterPath& clipPath() const override;
QPainterPath marginPath( const Distance& size ) const override;
QPainterPath marginPath( const Distance& xSize,
const Distance& ySize ) const override;
private:
@@ -71,4 +72,8 @@ namespace glabels
}
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::FrameEllipse& frame );
#endif // model_FrameEllipse_h
+157
View File
@@ -0,0 +1,157 @@
/* FramePath.cpp
*
* Copyright (C) 2018 Jim 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 "FramePath.h"
#include "Constants.h"
#include "StrUtil.h"
namespace glabels
{
namespace model
{
FramePath::FramePath( const QPainterPath& path,
const Distance& xWaste,
const Distance& yWaste,
const Units& originalUnits,
const QString& id )
: Frame(id), mXWaste(xWaste), mYWaste(yWaste), mPath(path), mOriginalUnits(originalUnits)
{
QRectF r = path.boundingRect();
mW = Distance::pt( r.width() );
mH = Distance::pt( r.height() );
mClipPath.addRect( r.x()-mXWaste.pt(), r.y()-mYWaste.pt(),
r.width() + 2*mXWaste.pt(), r.height() + 2*mYWaste.pt() );
}
Frame* FramePath::dup() const
{
return new FramePath( *this );
}
Distance FramePath::w() const
{
return mW;
}
Distance FramePath::h() const
{
return mH;
}
Distance FramePath::xWaste() const
{
return mXWaste;
}
Distance FramePath::yWaste() const
{
return mYWaste;
}
Units FramePath::originalUnits() const
{
return mOriginalUnits;
}
QString FramePath::sizeDescription( const Units& units ) const
{
if ( units.toEnum() == Units::IN )
{
QString wStr = StrUtil::formatFraction( mW.in() );
QString hStr = StrUtil::formatFraction( mH.in() );
return QString().sprintf( "%s x %s %s",
qPrintable(wStr),
qPrintable(hStr),
qPrintable(units.toTrName()) );
}
else
{
return QString().sprintf( "%.5g x %.5g %s",
mW.inUnits(units),
mH.inUnits(units),
qPrintable(units.toTrName()) );
}
}
bool FramePath::isSimilarTo( Frame* other ) const
{
if ( auto *otherPath = dynamic_cast<FramePath*>(other) )
{
if ( mPath == otherPath->mPath )
{
return true;
}
}
return false;
}
const QPainterPath& FramePath::path() const
{
return mPath;
}
const QPainterPath& FramePath::clipPath() const
{
return mClipPath;
}
QPainterPath FramePath::marginPath( const Distance& xSize,
const Distance& ySize ) const
{
return mPath; // No margin
}
}
}
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;
}
+86
View File
@@ -0,0 +1,86 @@
/* FramePath.h
*
* Copyright (C) 2018 Jim 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_FramePath_h
#define model_FramePath_h
#include "Frame.h"
namespace glabels
{
namespace model
{
class FramePath : public Frame
{
Q_DECLARE_TR_FUNCTIONS(FramePath)
public:
FramePath( const QPainterPath& path,
const Distance& xWaste,
const Distance& yWaste,
const Units& originalUnits,
const QString& id = "0" );
FramePath( const FramePath& other ) = default;
Frame* dup() const override;
Distance xWaste() const;
Distance yWaste() const;
Units originalUnits() const;
Distance w() const override;
Distance h() const override;
QString sizeDescription( const Units& units ) const override;
bool isSimilarTo( Frame* other ) const override;
const QPainterPath& path() const override;
const QPainterPath& clipPath() const override;
QPainterPath marginPath( const Distance& xSize,
const Distance& ySize ) const override;
private:
Distance mW;
Distance mH;
Distance mXWaste;
Distance mYWaste;
QPainterPath mPath;
QPainterPath mClipPath;
Units mOriginalUnits;
};
}
}
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::FramePath& frame );
#endif // model_FramePath_h
+25 -14
View File
@@ -44,16 +44,7 @@ namespace glabels
mR.pt(), mR.pt() );
}
FrameRect::FrameRect( const FrameRect &other )
: Frame(other),
mW(other.mW), mH(other.mH), mR(other.mR), mXWaste(other.mXWaste),
mYWaste(other.mYWaste), mPath(other.mPath)
{
// empty
}
Frame* FrameRect::dup() const
{
return new FrameRect( *this );
@@ -138,14 +129,15 @@ namespace glabels
}
QPainterPath FrameRect::marginPath( const Distance& size ) const
QPainterPath FrameRect::marginPath( const Distance& xSize,
const Distance& ySize ) const
{
Distance w = mW - 2*size;
Distance h = mH - 2*size;
Distance r = std::max( mR - size, Distance(0.0) );
Distance w = mW - 2*xSize;
Distance h = mH - 2*ySize;
Distance r = std::max( mR - std::min(xSize, ySize), Distance(0.0) );
QPainterPath path;
path.addRoundedRect( size.pt(), size.pt(), w.pt(), h.pt(), r.pt(), r.pt() );
path.addRoundedRect( xSize.pt(), ySize.pt(), w.pt(), h.pt(), r.pt(), r.pt() );
return path;
}
@@ -153,3 +145,22 @@ namespace glabels
}
}
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;
}
+7 -2
View File
@@ -42,7 +42,7 @@ namespace glabels
const Distance& yWaste,
const QString& id = "0" );
FrameRect( const FrameRect& other );
FrameRect( const FrameRect& other ) = default;
Frame* dup() const override;
@@ -59,7 +59,8 @@ namespace glabels
const QPainterPath& path() const override;
const QPainterPath& clipPath() const override;
QPainterPath marginPath( const Distance& size ) const override;
QPainterPath marginPath( const Distance& xSize,
const Distance& ySize ) const override;
private:
@@ -78,4 +79,8 @@ namespace glabels
}
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::FrameRect& frame );
#endif // model_FrameRect_h
+21 -8
View File
@@ -40,13 +40,6 @@ namespace glabels
}
FrameRound::FrameRound( const FrameRound& other )
: Frame(other), mR(other.mR), mWaste(other.mWaste), mPath(other.mPath)
{
// empty
}
Frame* FrameRound::dup() const
{
return new FrameRound( *this );
@@ -123,8 +116,12 @@ namespace glabels
}
QPainterPath FrameRound::marginPath( const Distance& size ) const
QPainterPath FrameRound::marginPath( const Distance& xSize,
const Distance& ySize ) const
{
// Note: ignore ySize, assume xSize == ySize
Distance size = xSize;
Distance r = mR - size;
QPainterPath path;
@@ -135,3 +132,19 @@ namespace glabels
}
}
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;
}
+7 -2
View File
@@ -39,7 +39,7 @@ namespace glabels
const Distance& waste,
const QString& id = "0" );
FrameRound( const FrameRound &other );
FrameRound( const FrameRound &other ) = default;
Frame *dup() const override;
@@ -54,7 +54,8 @@ namespace glabels
const QPainterPath& path() const override;
const QPainterPath& clipPath() const override;
QPainterPath marginPath( const Distance& size ) const override;
QPainterPath marginPath( const Distance& xSize,
const Distance& ySize ) const override;
private:
@@ -70,4 +71,8 @@ namespace glabels
}
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::FrameRound& frame );
#endif // model_FrameRound_h
+24 -14
View File
@@ -86,22 +86,32 @@ namespace glabels
}
bool Layout::isSimilarTo( const Layout *other )
bool Layout::isSimilarTo( const Layout& other ) const
{
return ( (mNx == other->mNx) &&
(mNy == other->mNy) &&
(fabs(mX0 - other->mX0) < EPSILON) &&
(fabs(mY0 - other->mY0) < EPSILON) &&
(fabs(mDx - other->mDx) < EPSILON) &&
(fabs(mDy - other->mDy) < EPSILON) );
}
Layout* Layout::dup() const
{
auto *other = new Layout( *this );
return other;
return ( (mNx == other.mNx) &&
(mNy == other.mNy) &&
(fabs(mX0 - other.mX0) < EPSILON) &&
(fabs(mY0 - other.mY0) < EPSILON) &&
(fabs(mDx - other.mDx) < EPSILON) &&
(fabs(mDy - other.mDy) < EPSILON) );
}
}
}
QDebug operator<<( QDebug dbg, const glabels::model::Layout& layout )
{
QDebugStateSaver saver(dbg);
dbg.nospace() << "Layout{ "
<< layout.nx() << ","
<< layout.ny() << ","
<< layout.x0() << ","
<< layout.y0() << ","
<< layout.dx() << ","
<< layout.dy()
<< " }";
return dbg;
}
+7 -3
View File
@@ -24,6 +24,8 @@
#include "Distance.h"
#include <QDebug>
namespace glabels
{
@@ -52,9 +54,7 @@ namespace glabels
Distance dx() const;
Distance dy() const;
bool isSimilarTo( const Layout *other );
Layout* dup() const;
bool isSimilarTo( const Layout& other ) const;
private:
@@ -71,4 +71,8 @@ namespace glabels
}
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::Layout& layout );
#endif // model_Layout_h
+27 -8
View File
@@ -26,29 +26,48 @@ namespace glabels
namespace model
{
const QPainterPath& Markup::path() const
QPainterPath Markup::path( const Frame* frame ) const
{
// Use cached path -- default does not depend on frame size
return mPath;
}
MarkupMargin::MarkupMargin( const Frame* frame,
const Distance& size )
: mFrame(frame), mSize(size)
MarkupMargin::MarkupMargin( const Distance& size )
: mXSize(size), mYSize(size)
{
mPath = frame->marginPath( size );
}
MarkupMargin::MarkupMargin( const Distance& xSize,
const Distance& ySize )
: mXSize(xSize), mYSize(ySize)
{
}
QPainterPath MarkupMargin::path( const Frame* frame ) const
{
// Re-calculate path -- frame size may have changed
return frame->marginPath( mXSize, mYSize );
}
Markup* MarkupMargin::dup() const
{
return new MarkupMargin( mFrame, mSize );
return new MarkupMargin( mXSize, mYSize );
}
Distance MarkupMargin::size() const
Distance MarkupMargin::xSize() const
{
return mSize;
return mXSize;
}
Distance MarkupMargin::ySize() const
{
return mYSize;
}
+11 -6
View File
@@ -37,7 +37,7 @@ namespace glabels
public:
virtual Markup* dup() const = 0;
const QPainterPath& path() const;
virtual QPainterPath path( const Frame* frame ) const;
protected:
QPainterPath mPath;
@@ -47,16 +47,21 @@ namespace glabels
class MarkupMargin : public Markup
{
public:
MarkupMargin( const Frame* frame,
const Distance& size );
MarkupMargin( const Distance& size );
Distance size() const;
MarkupMargin( const Distance& xSize,
const Distance& ySize );
QPainterPath path( const Frame* frame ) const override;
Distance xSize() const;
Distance ySize() const;
Markup* dup() const override;
private:
const Frame* mFrame;
Distance mSize;
Distance mXSize;
Distance mYSize;
};
+50 -15
View File
@@ -55,12 +55,21 @@ namespace glabels
/// Default constructor.
///
Model::Model()
: mUntitledInstance(0), mModified(true), mTmplate(nullptr), mFrame(nullptr), mRotate(false)
: mUntitledInstance(0), mModified(true), mRotate(false)
{
mMerge = new merge::None();
}
///
/// Destructor.
///
Model::~Model()
{
delete mMerge;
}
///
/// Save model state
///
@@ -90,7 +99,6 @@ namespace glabels
mModified = savedModel->mModified;
mFileName = savedModel->mFileName;
mTmplate = savedModel->mTmplate;
mFrame = savedModel->mFrame;
mRotate = savedModel->mRotate;
foreach ( ModelObject* savedObject, savedModel->mObjectList )
@@ -155,7 +163,7 @@ namespace glabels
///
const Template* Model::tmplate() const
{
return mTmplate;
return &mTmplate;
}
@@ -164,7 +172,7 @@ namespace glabels
///
const Frame* Model::frame() const
{
return mFrame;
return mTmplate.frames().constFirst();
}
@@ -173,18 +181,14 @@ namespace glabels
///
void Model::setTmplate( const Template* tmplate )
{
if (mTmplate != tmplate)
{
mTmplate = tmplate;
mFrame = tmplate->frames().first();
mTmplate = *tmplate;
setModified();
setModified();
emit changed();
emit sizeChanged();
emit changed();
emit sizeChanged();
Settings::addToRecentTemplateList( tmplate->name() );
}
Settings::addToRecentTemplateList( tmplate->name() );
}
@@ -219,7 +223,14 @@ namespace glabels
///
Distance Model::w() const
{
return mRotate ? mFrame->h() : mFrame->w();
if ( auto* frame = mTmplate.frames().constFirst() )
{
return mRotate ? frame->h() : frame->w();
}
else
{
return Distance::pt(0);
}
}
@@ -228,7 +239,31 @@ namespace glabels
///
Distance Model::h() const
{
return mRotate ? mFrame->w() : mFrame->h();
if ( auto* frame = mTmplate.frames().constFirst() )
{
return mRotate ? frame->w() : frame->h();
}
else
{
return Distance::pt(0);
}
}
///
/// Set height (if variable length)
///
void Model::setH( const Distance& h )
{
if ( auto* frame = mTmplate.frames().first() )
{
frame->setH( h );
setModified();
emit changed();
emit sizeChanged();
}
}
+5 -4
View File
@@ -57,7 +57,7 @@ namespace glabels
/////////////////////////////////
public:
Model();
~Model() override = default;
~Model();
/////////////////////////////////
@@ -103,6 +103,8 @@ namespace glabels
Distance w() const;
Distance h() const;
void setH( const Distance& h );
const QList<ModelObject*>& objectList() const;
merge::Merge* merge() const;
@@ -222,11 +224,10 @@ namespace glabels
int mUntitledInstance;
bool mModified;
QString mFileName;
const Template* mTmplate;
const Frame* mFrame;
Template mTmplate;
bool mRotate;
QList<ModelObject*> mObjectList;
QList<ModelObject*> mObjectList;
merge::Merge* mMerge;
};
+13 -9
View File
@@ -193,6 +193,10 @@ namespace glabels
void PageRenderer::print( QPrinter* printer ) const
{
QSizeF pageSize( mModel->tmplate()->pageWidth().pt(), mModel->tmplate()->pageHeight().pt() );
if ( mModel->tmplate()->pageWidth().pt() > mModel->tmplate()->pageHeight().pt() )
{
printer->setOrientation( QPrinter::Landscape );
}
printer->setPageSize( QPageSize(pageSize, QPageSize::Point) );
printer->setFullPage( true );
printer->setPageMargins( 0, 0, 0, 0, QPrinter::Point );
@@ -338,16 +342,16 @@ namespace glabels
Distance w = mModel->frame()->w();
Distance h = mModel->frame()->h();
foreach ( Layout* layout, mModel->frame()->layouts() )
foreach ( const Layout& layout, mModel->frame()->layouts() )
{
Distance xMin = layout->x0();
Distance yMin = layout->y0();
Distance xMax = layout->x0() + layout->dx()*(layout->nx()-1) + w;
Distance yMax = layout->y0() + layout->dy()*(layout->ny()-1) + h;
Distance xMin = layout.x0();
Distance yMin = layout.y0();
Distance xMax = layout.x0() + layout.dx()*(layout.nx()-1) + w;
Distance yMax = layout.y0() + layout.dy()*(layout.ny()-1) + h;
for ( int ix = 0; ix < layout->nx(); ix++ )
for ( int ix = 0; ix < layout.nx(); ix++ )
{
Distance x1 = xMin + ix*layout->dx();
Distance x1 = xMin + ix*layout.dx();
Distance x2 = x1 + w;
Distance y1 = max( yMin-tickOffset, Distance::pt(0) );
@@ -362,9 +366,9 @@ namespace glabels
painter->drawLine( x2.pt(), y3.pt(), x2.pt(), y4.pt() );
}
for ( int iy = 0; iy < layout->ny(); iy++ )
for ( int iy = 0; iy < layout.ny(); iy++ )
{
Distance y1 = yMin + iy*layout->dy();
Distance y1 = yMin + iy*layout.dy();
Distance y2 = y1 + h;
Distance x1 = max( xMin-tickOffset, Distance::pt(0) );
+1 -1
View File
@@ -61,7 +61,7 @@ namespace glabels
if ( denom[i] == 0.0 )
{
/* None of our denominators work. */
return QString().sprintf( "%.5g", x );
return QString().sprintf( "%.3f", x );
}
if ( denom[i] == 1.0 )
{
+97 -8
View File
@@ -21,6 +21,7 @@
#include "Template.h"
#include "Db.h"
#include "FrameContinuous.h"
#include <QtDebug>
@@ -36,6 +37,7 @@ namespace glabels
const QString& paperId,
const Distance& pageWidth,
const Distance& pageHeight,
const Distance& rollWidth,
bool isUserDefined )
: mBrand(brand),
mPart(part),
@@ -43,6 +45,7 @@ namespace glabels
mPaperId(paperId),
mPageWidth(pageWidth),
mPageHeight(pageHeight),
mRollWidth(rollWidth),
mIsUserDefined(isUserDefined),
mIsSizeIso(false),
mIsSizeUs(false),
@@ -56,6 +59,8 @@ namespace glabels
mIsSizeIso = paper->isSizeIso();
mIsSizeUs = paper->isSizeUs();
}
mIsRoll = (paperId == "roll");
}
@@ -67,15 +72,17 @@ namespace glabels
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;
foreach ( Frame* frame, other.mFrames )
{
addFrame( frame );
addFrame( frame->dup() );
}
foreach ( QString categoryId, other.mCategoryIds )
@@ -85,9 +92,50 @@ namespace glabels
}
Template* Template::dup() const
Template::~Template()
{
return new Template( *this );
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;
while ( !mFrames.isEmpty() )
{
delete mFrames.takeFirst();
}
foreach ( Frame* frame, other.mFrames )
{
addFrame( frame->dup() );
}
mCategoryIds.clear();
foreach ( QString categoryId, other.mCategoryIds )
{
addCategory( categoryId );
}
}
return *this;
}
@@ -107,7 +155,7 @@ namespace glabels
const Template* other = Db::lookupTemplateFromBrandPart( brand, equivPart );
if ( other != nullptr )
{
Template* tmplate = other->dup();
Template* tmplate = new Template( *other );
tmplate->mPart = part;
tmplate->mEquivPart = equivPart;
@@ -159,7 +207,22 @@ namespace glabels
Distance Template::pageHeight() const
{
return mPageHeight;
// Adjust height if continuous tape
const model::Frame* frame = mFrames.constFirst();
if ( const auto* frameContinuous = dynamic_cast<const model::FrameContinuous*>(frame) )
{
return frameContinuous->h();
}
else
{
return mPageHeight;
}
}
Distance Template::rollWidth() const
{
return mRollWidth;
}
@@ -181,6 +244,12 @@ namespace glabels
}
bool Template::isRoll() const
{
return mIsRoll;
}
bool Template::isUserDefined() const
{
return mIsUserDefined;
@@ -274,12 +343,12 @@ namespace glabels
}
// Are they layed out similarly?
foreach ( Layout* layout1, frame1->layouts() )
foreach ( const Layout& layout1, frame1->layouts() )
{
bool matchFound = false;
foreach ( Layout* layout2, frame2->layouts() )
foreach ( const Layout& layout2, frame2->layouts() )
{
if ( layout1->isSimilarTo(layout2) )
if ( layout1.isSimilarTo( layout2 ) )
{
matchFound = true;
break;
@@ -297,3 +366,23 @@ namespace glabels
}
}
QDebug operator<<( QDebug dbg, const glabels::model::Template& tmplate )
{
QDebugStateSaver saver(dbg);
dbg.nospace() << "Template{ "
<< tmplate.brand() << "," << tmplate.part() << "," << tmplate.description() << ","
<< tmplate.paperId() << ","
<< tmplate.pageWidth() << ","
<< tmplate.pageHeight() << ","
<< tmplate.rollWidth() << ","
<< tmplate.isSizeIso() << ","
<< tmplate.isSizeUs() << ","
<< tmplate.isSizeOther() << ","
<< tmplate.isRoll() << ","
<< *tmplate.frames().constFirst() << ","
<< " }";
return dbg;
}
+15 -1
View File
@@ -43,17 +43,22 @@ namespace glabels
public:
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 Template& other );
Template* dup() const;
~Template();
Template& operator=( const Template& other );
// Generic full page template
static Template* fullPage( const QString& paperId );
@@ -71,9 +76,11 @@ namespace glabels
QString paperId() const;
Distance pageWidth() const;
Distance pageHeight() const;
Distance rollWidth() const;
bool isSizeIso() const;
bool isSizeUs() const;
bool isSizeOther() const;
bool isRoll() const;
bool isUserDefined() const;
@@ -104,8 +111,10 @@ namespace glabels
QString mPaperId;
Distance mPageWidth;
Distance mPageHeight;
Distance mRollWidth;
bool mIsSizeIso;
bool mIsSizeUs;
bool mIsRoll;
bool mIsUserDefined;
@@ -119,7 +128,12 @@ namespace glabels
};
}
}
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::Template& tmplate );
#endif // model_Template_h
+62 -10
View File
@@ -91,7 +91,10 @@ namespace glabels
XmlUtil::setLengthAttr( node, "width", tmplate->pageWidth() );
XmlUtil::setLengthAttr( node, "height", tmplate->pageHeight() );
}
if ( tmplate->isRoll() )
{
XmlUtil::setLengthAttr( node, "roll_width", tmplate->rollWidth() );
}
XmlUtil::setStringAttr( node, "description", tmplate->description() );
@@ -141,6 +144,14 @@ namespace glabels
{
createLabelCdNode( parent, frameCd );
}
else if ( const auto* framePath = dynamic_cast<const FramePath*>(frame) )
{
createLabelPathNode( parent, framePath );
}
else if ( const auto* frameContinuous = dynamic_cast<const FrameContinuous*>(frame) )
{
createLabelContinuousNode( parent, frameContinuous );
}
else
{
Q_ASSERT_X( false, "XmlTemplateCreator::createLabelNode", "Invalid frame type." );
@@ -217,6 +228,39 @@ namespace glabels
}
void XmlTemplateCreator::createLabelPathNode( QDomElement &parent, const FramePath* frame )
{
QDomDocument doc = parent.ownerDocument();
QDomElement node = doc.createElement( "Label-path" );
parent.appendChild( node );
XmlUtil::setStringAttr( node, "id", frame->id() );
XmlUtil::setLengthAttr( node, "x_waste", frame->xWaste() );
XmlUtil::setLengthAttr( node, "y_waste", frame->yWaste() );
XmlUtil::setUnitsAttr( node, "d_units", frame->originalUnits() );
XmlUtil::setPathDataAttr( node, "d", frame->path(), frame->originalUnits() );
createLabelNodeCommon( node, frame );
}
void XmlTemplateCreator::createLabelContinuousNode( QDomElement &parent, const FrameContinuous* frame )
{
QDomDocument doc = parent.ownerDocument();
QDomElement node = doc.createElement( "Label-continuous" );
parent.appendChild( node );
XmlUtil::setStringAttr( node, "id", frame->id() );
XmlUtil::setLengthAttr( node, "width", frame->w() );
XmlUtil::setLengthAttr( node, "height", frame->h() );
XmlUtil::setLengthAttr( node, "min_height", frame->hMin() );
XmlUtil::setLengthAttr( node, "max_height", frame->hMin() );
XmlUtil::setLengthAttr( node, "default_height", frame->hDefault() );
createLabelNodeCommon( node, frame );
}
void XmlTemplateCreator::createLabelNodeCommon( QDomElement &node, const Frame *frame )
{
foreach ( Markup* markup, frame->markups() )
@@ -247,27 +291,27 @@ namespace glabels
}
}
foreach ( Layout* layout, frame->layouts() )
foreach ( const Layout& layout, frame->layouts() )
{
createLayoutNode( node, layout );
}
}
void XmlTemplateCreator::createLayoutNode( QDomElement& parent, const Layout* layout )
void XmlTemplateCreator::createLayoutNode( QDomElement& parent, const Layout& layout )
{
QDomDocument doc = parent.ownerDocument();
QDomElement node = doc.createElement( "Layout" );
parent.appendChild( node );
XmlUtil::setIntAttr( node, "nx", layout->nx() );
XmlUtil::setIntAttr( node, "ny", layout->ny() );
XmlUtil::setIntAttr( node, "nx", layout.nx() );
XmlUtil::setIntAttr( node, "ny", layout.ny() );
XmlUtil::setLengthAttr( node, "x0", layout->x0() );
XmlUtil::setLengthAttr( node, "y0", layout->y0() );
XmlUtil::setLengthAttr( node, "x0", layout.x0() );
XmlUtil::setLengthAttr( node, "y0", layout.y0() );
XmlUtil::setLengthAttr( node, "dx", layout->dx() );
XmlUtil::setLengthAttr( node, "dy", layout->dy() );
XmlUtil::setLengthAttr( node, "dx", layout.dx() );
XmlUtil::setLengthAttr( node, "dy", layout.dy() );
}
@@ -277,7 +321,15 @@ namespace glabels
QDomElement node = doc.createElement( "Markup-margin" );
parent.appendChild( node );
XmlUtil::setLengthAttr( node, "size", markup->size() );
if ( markup->xSize() == markup->ySize() )
{
XmlUtil::setLengthAttr( node, "size", markup->xSize() );
}
else
{
XmlUtil::setLengthAttr( node, "x_size", markup->xSize() );
XmlUtil::setLengthAttr( node, "y_size", markup->ySize() );
}
}
+5 -1
View File
@@ -23,7 +23,9 @@
#include "FrameCd.h"
#include "FrameContinuous.h"
#include "FrameEllipse.h"
#include "FramePath.h"
#include "FrameRect.h"
#include "FrameRound.h"
#include "Layout.h"
@@ -55,8 +57,10 @@ namespace glabels
void createLabelEllipseNode( QDomElement& parent, const FrameEllipse* frame );
void createLabelRoundNode( QDomElement& parent, const FrameRound* frame );
void createLabelCdNode( QDomElement& parent, const FrameCd* frame );
void createLabelPathNode( QDomElement& parent, const FramePath* frame );
void createLabelContinuousNode( QDomElement& parent, const FrameContinuous* frame );
void createLabelNodeCommon( QDomElement& node, const Frame* frame );
void createLayoutNode( QDomElement& parent, const Layout* layout );
void createLayoutNode( QDomElement& parent, const Layout& layout );
void createMarkupMarginNode( QDomElement& parent, const MarkupMargin* markupMargin );
void createMarkupLineNode( QDomElement& parent, const MarkupLine* markupLine );
void createMarkupCircleNode( QDomElement& parent, const MarkupCircle* markupCircle );
+76 -5
View File
@@ -25,6 +25,8 @@
#include "FrameCd.h"
#include "FrameRound.h"
#include "FrameEllipse.h"
#include "FramePath.h"
#include "FrameContinuous.h"
#include "Layout.h"
#include "Markup.h"
#include "Template.h"
@@ -153,7 +155,7 @@ namespace glabels
QString description = XmlUtil::getI18nAttr( node, "description", "" );
QString paperId = XmlUtil::getStringAttr( node, "size", "" );
if ( !Db::isPaperIdOther( paperId ) )
if ( Db::isPaperIdKnown( paperId ) )
{
const Paper *paper = Db::lookupPaperFromId( paperId );
if ( paper == nullptr )
@@ -169,8 +171,9 @@ namespace glabels
{
Distance width = XmlUtil::getLengthAttr( node, "width", Distance(0) );
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, isUserDefined );
tmplate = new Template( brand, part, description, paperId, width, height, rollWidth, isUserDefined );
}
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
@@ -195,6 +198,14 @@ namespace glabels
{
parseLabelCdNode( child.toElement(), tmplate );
}
else if ( child.toElement().tagName() == "Label-path" )
{
parseLabelPathNode( child.toElement(), tmplate );
}
else if ( child.toElement().tagName() == "Label-continuous" )
{
parseLabelContinuousNode( child.toElement(), tmplate );
}
else if ( !child.isComment() )
{
qWarning() << "Warning: bad element: "
@@ -303,6 +314,57 @@ namespace glabels
}
void XmlTemplateParser::parseLabelPathNode( const QDomElement &node, Template *tmplate )
{
QString id = XmlUtil::getStringAttr( node, "id", "0" );
Units dUnits = XmlUtil::getUnitsAttr( node, "d_units", Units::pc() );
QPainterPath d = XmlUtil::getPathDataAttr( node, "d", dUnits );
Distance xWaste, yWaste;
Distance waste = XmlUtil::getLengthAttr( node, "waste", Distance(-1) );
if ( waste >= Distance(0) )
{
xWaste = waste;
yWaste = waste;
}
else
{
xWaste = XmlUtil::getLengthAttr( node, "x_waste", Distance(0) );
yWaste = XmlUtil::getLengthAttr( node, "y_waste", Distance(0) );
}
Frame *frame = new FramePath( d, xWaste, yWaste, dUnits, id );
parseLabelNodeCommon( node, frame );
tmplate->addFrame( frame );
}
void XmlTemplateParser::parseLabelContinuousNode( const QDomElement &node, Template *tmplate )
{
QString id = XmlUtil::getStringAttr( node, "id", "0" );
Distance w = XmlUtil::getLengthAttr( node, "width", Distance(0) );
Distance h = XmlUtil::getLengthAttr( node, "height", Distance(0) );
Distance hMin = XmlUtil::getLengthAttr( node, "min_height", Distance(0) );
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 );
if ( h > Distance(0) )
{
frame->setH( h );
}
parseLabelNodeCommon( node, frame );
tmplate->addFrame( frame );
}
void XmlTemplateParser::parseLabelNodeCommon( const QDomElement &node, Frame *frame )
{
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
@@ -352,15 +414,24 @@ namespace glabels
Distance dX = XmlUtil::getLengthAttr( node, "dx", Distance(0) );
Distance dY = XmlUtil::getLengthAttr( node, "dy", Distance(0) );
frame->addLayout( new Layout( nX, nY, x0, y0, dX, dY ) );
frame->addLayout( Layout( nX, nY, x0, y0, dX, dY ) );
}
void XmlTemplateParser::parseMarkupMarginNode( const QDomElement &node, Frame *frame )
{
Distance size = XmlUtil::getLengthAttr( node, "size", Distance(0) );
Distance size = XmlUtil::getLengthAttr( node, "size", Distance(0) );
Distance xSize = XmlUtil::getLengthAttr( node, "x_size", Distance(0) );
Distance ySize = XmlUtil::getLengthAttr( node, "y_size", Distance(0) );
frame->addMarkup( new MarkupMargin( frame, size ) );
if ( size > Distance(0) )
{
frame->addMarkup( new MarkupMargin( size ) );
}
else
{
frame->addMarkup( new MarkupMargin( xSize, ySize ) );
}
}
+2
View File
@@ -48,6 +48,8 @@ namespace glabels
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 );
+188
View File
@@ -345,6 +345,149 @@ namespace glabels
}
Units XmlUtil::getUnitsAttr( const QDomElement& node,
const QString& name,
const Units& default_value )
{
init();
QString valueString = node.attribute( name, "" );
if ( valueString != "" )
{
return Units( valueString );
}
return default_value;
}
QPainterPath XmlUtil::getPathDataAttr( const QDomElement& node,
const QString& name,
const Units& units )
{
init();
QPainterPath d;
//
// Simple path data parser
//
QStringList tokens = node.attribute( name, "" ).split( " ", QString::SkipEmptyParts );
enum { CMD, MX, MY, MDX, MDY, LX, LY, LDX, LDY, HX, HDX, VY, VDY } state = CMD;
Distance x = 0;
Distance y = 0;
Distance dx = 0;
Distance dy = 0;
QPointF c;
for ( unsigned int i = 0; i < tokens.size(); i++ )
{
switch (state)
{
case CMD:
switch (tokens[i][0].unicode())
{
case 'M':
state = MX;
break;
case 'm':
state = MDX;
break;
case 'L':
state = LX;
break;
case 'l':
state = LDX;
break;
case 'H':
state = HX;
break;
case 'h':
state = HDX;
break;
case 'V':
state = VY;
break;
case 'v':
state = VDY;
break;
case 'Z':
case 'z':
d.closeSubpath();
state = CMD;
break;
}
break;
case MX:
x = Distance( tokens[i].toDouble(), units );
state = MY;
break;
case MY:
y = Distance( tokens[i].toDouble(), units );
d.moveTo( x.pt(), y.pt() );
state = CMD;
break;
case MDX:
dx = Distance( tokens[i].toDouble(), units );
state = MDY;
break;
case MDY:
dy = Distance( tokens[i].toDouble(), units );
c = d.currentPosition();
d.moveTo( c.x()+x.pt(), c.y()+y.pt() );
state = CMD;
break;
case LX:
x = Distance( tokens[i].toDouble(), units );
state = LY;
break;
case LY:
y = Distance( tokens[i].toDouble(), units );
d.lineTo( x.pt(), y.pt() );
state = CMD;
break;
case LDX:
dx = Distance( tokens[i].toDouble(), units );
state = LDY;
break;
case LDY:
dy = Distance( tokens[i].toDouble(), units );
c = d.currentPosition();
d.lineTo( c.x()+dx.pt(), c.y()+dy.pt() );
state = CMD;
break;
case HX:
x = Distance( tokens[i].toDouble(), units );
c = d.currentPosition();
d.lineTo( x.pt(), c.y() );
state = CMD;
break;
case HDX:
dx = Distance( tokens[i].toDouble(), units );
c = d.currentPosition();
d.lineTo( c.x()+dx.pt(), c.y() );
state = CMD;
break;
case VY:
y = Distance( tokens[i].toDouble(), units );
c = d.currentPosition();
d.lineTo( c.x(), y.pt() );
state = CMD;
break;
case VDY:
dy = Distance( tokens[i].toDouble(), units );
c = d.currentPosition();
d.lineTo( c.x(), c.y()+dy.pt() );
state = CMD;
break;
}
}
return d;
}
void XmlUtil::setStringAttr( QDomElement& node,
const QString& name,
const QString& value )
@@ -476,5 +619,50 @@ namespace glabels
}
void XmlUtil::setUnitsAttr( QDomElement& node,
const QString& name,
const Units& value )
{
node.setAttribute( name, value.toIdString() );
}
void XmlUtil::setPathDataAttr( QDomElement& node,
const QString& name,
const QPainterPath& path,
const Units& units )
{
QString pathString;
for ( int i = 0; i < path.elementCount(); i++ )
{
auto element = path.elementAt( i );
// QPainterPath is natively in pts
Distance x = Distance::pt( element.x );
Distance y = Distance::pt( element.y );
// Translate desired units for path data
double xValue = x.inUnits( units );
double yValue = y.inUnits( units );
if ( element.isMoveTo() )
{
pathString.append( QString( "M %1 %2" ).arg( xValue ).arg( yValue ) );
}
else if ( element.isLineTo() )
{
pathString.append( QString( "L %1 %2" ).arg( xValue ).arg( yValue ) );
}
if ( i < (path.elementCount() - 1) )
{
pathString.append( " " );
}
}
node.setAttribute( name, pathString );
}
}
}
+19
View File
@@ -26,6 +26,7 @@
#include <QDomElement>
#include <QFont>
#include <QPainterPath>
#include <QString>
#include <Qt>
#include <QTextOption>
@@ -91,6 +92,14 @@ namespace glabels
const QString& name,
QTextOption::WrapMode default_value );
static Units getUnitsAttr( const QDomElement& node,
const QString& name,
const Units& default_value );
static QPainterPath getPathDataAttr( const QDomElement& node,
const QString& name,
const Units& units );
static void setStringAttr( QDomElement& node,
const QString& name,
@@ -128,6 +137,16 @@ namespace glabels
const QString& name,
QTextOption::WrapMode value );
static void setUnitsAttr( QDomElement& node,
const QString& name,
const Units& value );
static void setPathDataAttr( QDomElement& node,
const QString& name,
const QPainterPath& value,
const Units& units );
private:
Units mUnits;