Some cleanup/restructuring of Frame and its subclasses.
This commit is contained in:
+20
-38
@@ -24,44 +24,6 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
int Frame::nLabels() const
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
std::list<Layout*>::const_iterator it;
|
||||
for ( it = mLayouts.begin(); it != mLayouts.end(); it++ )
|
||||
{
|
||||
n += (*it)->nx() * (*it)->ny();
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
QString &Frame::layoutDescription()
|
||||
{
|
||||
if ( mLayouts.size() == 1 )
|
||||
{
|
||||
Layout *layout = *mLayouts.begin();
|
||||
|
||||
/*
|
||||
* Translators: %1 = number of labels across a page,
|
||||
* %2 = number of labels down a page,
|
||||
* %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(nLabels());
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Translators: %1 is the total number of labels on a page (sheet). */
|
||||
mLayoutDescription = QString( tr("%1 per sheet") ).arg( nLabels() );
|
||||
}
|
||||
|
||||
return mLayoutDescription;
|
||||
}
|
||||
|
||||
|
||||
std::vector<Point> Frame::getOrigins() const
|
||||
{
|
||||
std::vector<Point> origins( nLabels() );
|
||||
@@ -87,6 +49,26 @@ namespace libglabels
|
||||
void Frame::addLayout( Layout *layout )
|
||||
{
|
||||
mLayouts.push_back( layout );
|
||||
|
||||
// Update total number of labels
|
||||
mNLabels += layout->nx() * layout->ny();
|
||||
|
||||
// Update layout description
|
||||
if ( mLayouts.size() == 1 )
|
||||
{
|
||||
/*
|
||||
* Translators: %1 = number of labels across a page,
|
||||
* %2 = number of labels down a page,
|
||||
* %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);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Translators: %1 is the total number of labels on a page (sheet). */
|
||||
mLayoutDescription = QString( tr("%1 per sheet") ).arg(mNLabels);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+9
-6
@@ -41,31 +41,34 @@ namespace libglabels
|
||||
Q_DECLARE_TR_FUNCTIONS(Frame)
|
||||
|
||||
protected:
|
||||
Frame( const QString &id = "0" ) : mId(id)
|
||||
Frame( const QString &id = "0" ) : mId(id), mNLabels(0), mLayoutDescription("")
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
inline const QString &id() const { return mId; }
|
||||
inline int nLabels() const { return mNLabels; }
|
||||
inline const QString &layoutDescription() { return mLayoutDescription; }
|
||||
|
||||
int nLabels() const;
|
||||
QString &layoutDescription();
|
||||
std::vector<Point> getOrigins() const;
|
||||
|
||||
void addLayout( Layout *layout );
|
||||
void addMarkup( Markup *markup );
|
||||
|
||||
virtual void getSize( double *w, double *h ) const = 0;
|
||||
virtual double w() const = 0;
|
||||
virtual double h() const = 0;
|
||||
|
||||
virtual const QString &sizeDescription( Units *units ) = 0;
|
||||
virtual bool isSimilar( Frame *b ) const = 0;
|
||||
virtual QString &getSizeDescription( Units *units ) const = 0;
|
||||
|
||||
private:
|
||||
QString mId;
|
||||
int mNLabels;
|
||||
QString mLayoutDescription;
|
||||
|
||||
std::list<Layout*> mLayouts;
|
||||
std::list<Markup*> mMarkups;
|
||||
|
||||
QString mLayoutDescription;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+11
-31
@@ -29,28 +29,6 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
void FrameCd::getSize( double *w, double *h ) const
|
||||
{
|
||||
if ( mW == 0 )
|
||||
{
|
||||
*w = 2 * mR1;
|
||||
}
|
||||
else
|
||||
{
|
||||
*w = mW;
|
||||
}
|
||||
|
||||
if ( mH == 0 )
|
||||
{
|
||||
*h = 2 * mR1;
|
||||
}
|
||||
else
|
||||
{
|
||||
*h = mH;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool FrameCd::isSimilar( Frame *b ) const
|
||||
{
|
||||
if ( FrameCd *bCd = dynamic_cast<FrameCd*>(b) )
|
||||
@@ -67,24 +45,26 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
QString &FrameCd::getSizeDescription( Units *units ) const
|
||||
const QString &FrameCd::sizeDescription( Units *units )
|
||||
{
|
||||
if ( units->id() == "in" )
|
||||
{
|
||||
QString dStr = StrUtil::formatFraction( 2 * mR1 * units->unitsPerPoint() );
|
||||
|
||||
return QString().sprintf( "%s %s %s",
|
||||
dStr.toStdString().c_str(),
|
||||
units->name().toStdString().c_str(),
|
||||
tr("diameter").toStdString().c_str() );
|
||||
mSizeDescription = QString().sprintf( "%s %s %s",
|
||||
dStr.toStdString().c_str(),
|
||||
units->name().toStdString().c_str(),
|
||||
tr("diameter").toStdString().c_str() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString().sprintf( "%.5g %s %s",
|
||||
2 * mR1 * units->unitsPerPoint(),
|
||||
units->name().toStdString().c_str(),
|
||||
tr("diameter").toStdString().c_str() );
|
||||
mSizeDescription = QString().sprintf( "%.5g %s %s",
|
||||
2 * mR1 * units->unitsPerPoint(),
|
||||
units->name().toStdString().c_str(),
|
||||
tr("diameter").toStdString().c_str() );
|
||||
}
|
||||
|
||||
return mSizeDescription;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,14 +42,13 @@ namespace libglabels
|
||||
|
||||
inline double r1() const { return mR1; }
|
||||
inline double r2() const { return mR2; }
|
||||
inline double w() const { return mW; }
|
||||
inline double h() const { return mH; }
|
||||
inline double waste() const { return mWaste; }
|
||||
|
||||
double w() const { return (mW == 0) ? 2*mR1 : mW; }
|
||||
double h() const { return (mH == 0) ? 2*mR1 : mH; }
|
||||
|
||||
void getSize( double *w, double *h ) const;
|
||||
const QString &sizeDescription( Units *units );
|
||||
bool isSimilar( Frame *b ) const;
|
||||
QString &getSizeDescription( Units *units ) const;
|
||||
|
||||
|
||||
private:
|
||||
@@ -59,6 +58,8 @@ namespace libglabels
|
||||
double mH;
|
||||
double mWaste;
|
||||
|
||||
QString mSizeDescription;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -29,13 +29,6 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
void FrameEllipse::getSize( double *w, double *h ) const
|
||||
{
|
||||
*w = mW;
|
||||
*h = mH;
|
||||
}
|
||||
|
||||
|
||||
bool FrameEllipse::isSimilar( Frame *b ) const
|
||||
{
|
||||
if ( FrameEllipse *bEllipse = dynamic_cast<FrameEllipse*>(b) )
|
||||
@@ -50,24 +43,24 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
QString &FrameEllipse::getSizeDescription( Units *units ) const
|
||||
const QString &FrameEllipse::sizeDescription( Units *units )
|
||||
{
|
||||
if ( units->id() == "in" )
|
||||
{
|
||||
QString wStr = StrUtil::formatFraction( mW * units->unitsPerPoint() );
|
||||
QString hStr = StrUtil::formatFraction( mH * units->unitsPerPoint() );
|
||||
|
||||
return QString().sprintf( "%s x %s %s",
|
||||
wStr.toStdString().c_str(),
|
||||
hStr.toStdString().c_str(),
|
||||
units->name().toStdString().c_str() );
|
||||
mSizeDescription = QString().sprintf( "%s x %s %s",
|
||||
wStr.toStdString().c_str(),
|
||||
hStr.toStdString().c_str(),
|
||||
units->name().toStdString().c_str() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString().sprintf( "%.5g x %.5g %s",
|
||||
mW * units->unitsPerPoint(),
|
||||
mH * units->unitsPerPoint(),
|
||||
units->name().toStdString().c_str() );
|
||||
mSizeDescription = QString().sprintf( "%.5g x %.5g %s",
|
||||
mW * units->unitsPerPoint(),
|
||||
mH * units->unitsPerPoint(),
|
||||
units->name().toStdString().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,14 +38,13 @@ namespace libglabels
|
||||
{
|
||||
}
|
||||
|
||||
inline double w() const { return mW; }
|
||||
inline double h() const { return mH; }
|
||||
inline double waste() const { return mWaste; }
|
||||
|
||||
double w() const { return mW; }
|
||||
double h() const { return mH; }
|
||||
|
||||
void getSize( double *w, double *h ) const;
|
||||
const QString &sizeDescription( Units *units );
|
||||
bool isSimilar( Frame *b ) const;
|
||||
QString &getSizeDescription( Units *units ) const;
|
||||
|
||||
|
||||
private:
|
||||
@@ -53,6 +52,8 @@ namespace libglabels
|
||||
double mH;
|
||||
double mWaste;
|
||||
|
||||
QString mSizeDescription;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+20
-25
@@ -29,10 +29,27 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
void FrameRect::getSize( double *w, double *h ) const
|
||||
const QString &FrameRect::sizeDescription( Units *units )
|
||||
{
|
||||
*w = mW;
|
||||
*h = mH;
|
||||
if ( units->id() == "in" )
|
||||
{
|
||||
QString wStr = StrUtil::formatFraction( mW * units->unitsPerPoint() );
|
||||
QString hStr = StrUtil::formatFraction( mH * units->unitsPerPoint() );
|
||||
|
||||
mSizeDescription = QString().sprintf( "%s x %s %s",
|
||||
wStr.toStdString().c_str(),
|
||||
hStr.toStdString().c_str(),
|
||||
units->name().toStdString().c_str() );
|
||||
}
|
||||
else
|
||||
{
|
||||
mSizeDescription = QString().sprintf( "%.5g x %.5g %s",
|
||||
mW * units->unitsPerPoint(),
|
||||
mH * units->unitsPerPoint(),
|
||||
units->name().toStdString().c_str() );
|
||||
}
|
||||
|
||||
return mSizeDescription;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,27 +66,5 @@ namespace libglabels
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
QString &FrameRect::getSizeDescription( Units *units ) const
|
||||
{
|
||||
if ( units->id() == "in" )
|
||||
{
|
||||
QString wStr = StrUtil::formatFraction( mW * units->unitsPerPoint() );
|
||||
QString hStr = StrUtil::formatFraction( mH * units->unitsPerPoint() );
|
||||
|
||||
return QString().sprintf( "%s x %s %s",
|
||||
wStr.toStdString().c_str(),
|
||||
hStr.toStdString().c_str(),
|
||||
units->name().toStdString().c_str() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString().sprintf( "%.5g x %.5g %s",
|
||||
mW * units->unitsPerPoint(),
|
||||
mH * units->unitsPerPoint(),
|
||||
units->name().toStdString().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -40,16 +40,15 @@ namespace libglabels
|
||||
{
|
||||
}
|
||||
|
||||
inline double w() const { return mW; }
|
||||
inline double h() const { return mH; }
|
||||
inline double r() const { return mR; }
|
||||
inline double xWaste() const { return mXWaste; }
|
||||
inline double yWaste() const { return mYWaste; }
|
||||
|
||||
double w() const { return mW; }
|
||||
double h() const { return mH; }
|
||||
|
||||
void getSize( double *w, double *h ) const;
|
||||
const QString &sizeDescription( Units *units );
|
||||
bool isSimilar( Frame *b ) const;
|
||||
QString &getSizeDescription( Units *units ) const;
|
||||
|
||||
|
||||
private:
|
||||
@@ -59,6 +58,8 @@ namespace libglabels
|
||||
double mXWaste;
|
||||
double mYWaste;
|
||||
|
||||
QString mSizeDescription;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+11
-16
@@ -29,13 +29,6 @@
|
||||
namespace libglabels
|
||||
{
|
||||
|
||||
void FrameRound::getSize( double *w, double *h ) const
|
||||
{
|
||||
*w = 2*mR;
|
||||
*h = 2*mR;
|
||||
}
|
||||
|
||||
|
||||
bool FrameRound::isSimilar( Frame *b ) const
|
||||
{
|
||||
if ( FrameRound *bRound = dynamic_cast<FrameRound*>(b) )
|
||||
@@ -49,24 +42,26 @@ namespace libglabels
|
||||
}
|
||||
|
||||
|
||||
QString &FrameRound::getSizeDescription( Units *units ) const
|
||||
const QString &FrameRound::sizeDescription( Units *units )
|
||||
{
|
||||
if ( units->id() == "in" )
|
||||
{
|
||||
QString dStr = StrUtil::formatFraction( 2 * mR * units->unitsPerPoint() );
|
||||
|
||||
return QString().sprintf( "%s %s %s",
|
||||
dStr.toStdString().c_str(),
|
||||
units->name().toStdString().c_str(),
|
||||
tr("diameter").toStdString().c_str() );
|
||||
mSizeDescription = QString().sprintf( "%s %s %s",
|
||||
dStr.toStdString().c_str(),
|
||||
units->name().toStdString().c_str(),
|
||||
tr("diameter").toStdString().c_str() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString().sprintf( "%.5g %s %s",
|
||||
2 * mR * units->unitsPerPoint(),
|
||||
units->name().toStdString().c_str(),
|
||||
tr("diameter").toStdString().c_str() );
|
||||
mSizeDescription = QString().sprintf( "%.5g %s %s",
|
||||
2 * mR * units->unitsPerPoint(),
|
||||
units->name().toStdString().c_str(),
|
||||
tr("diameter").toStdString().c_str() );
|
||||
}
|
||||
|
||||
return mSizeDescription;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,16 +40,18 @@ namespace libglabels
|
||||
inline double r() const { return mR; }
|
||||
inline double waste() const { return mWaste; }
|
||||
|
||||
double w() const { return 2*mR; }
|
||||
double h() const { return 2*mR; }
|
||||
|
||||
void getSize( double *w, double *h ) const;
|
||||
const QString &sizeDescription( Units *units );
|
||||
bool isSimilar( Frame *b ) const;
|
||||
QString &getSizeDescription( Units *units ) const;
|
||||
|
||||
|
||||
private:
|
||||
double mR;
|
||||
double mWaste;
|
||||
|
||||
QString mSizeDescription;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user