Use QList and QStringList instead of STL list.

This commit is contained in:
Jim Evins
2013-11-03 15:56:33 -05:00
parent 21c6b82b04
commit 54fcda7ce4
6 changed files with 101 additions and 147 deletions
+58 -81
View File
@@ -32,15 +32,15 @@
namespace libglabels namespace libglabels
{ {
std::list<Paper*> Db::mPapers; QList<Paper*> Db::mPapers;
std::list<QString> Db::mPaperIds; QStringList Db::mPaperIds;
std::list<QString> Db::mPaperNames; QStringList Db::mPaperNames;
std::list<Category*> Db::mCategories; QList<Category*> Db::mCategories;
std::list<QString> Db::mCategoryIds; QStringList Db::mCategoryIds;
std::list<QString> Db::mCategoryNames; QStringList Db::mCategoryNames;
std::list<Vendor*> Db::mVendors; QList<Vendor*> Db::mVendors;
std::list<QString> Db::mVendorNames; QStringList Db::mVendorNames;
std::list<Template*> Db::mTemplates; QList<Template*> Db::mTemplates;
QString Db::mEmpty = ""; QString Db::mEmpty = "";
@@ -57,9 +57,9 @@ namespace libglabels
{ {
if ( !isPaperIdKnown( paper->id() ) ) if ( !isPaperIdKnown( paper->id() ) )
{ {
mPapers.push_back( paper ); mPapers << paper;
mPaperIds.push_back( paper->id() ); mPaperIds << paper->id();
mPaperNames.push_back( paper->name() ); mPaperNames << paper->name();
} }
else else
{ {
@@ -73,15 +73,14 @@ namespace libglabels
if ( name.isNull() || name.isEmpty() ) if ( name.isNull() || name.isEmpty() )
{ {
qDebug( "NULL paper name." ); qDebug( "NULL paper name." );
return mPapers.front(); return mPapers.first();
} }
std::list<Paper*>::const_iterator it; foreach ( Paper *paper, mPapers )
for ( it = mPapers.begin(); it != mPapers.end(); it++ )
{ {
if ( (*it)->name() == name ) if ( paper->name() == name )
{ {
return *it; return paper;
} }
} }
@@ -95,15 +94,14 @@ namespace libglabels
if ( id.isNull() || id.isEmpty() ) if ( id.isNull() || id.isEmpty() )
{ {
qDebug( "NULL paper ID." ); qDebug( "NULL paper ID." );
return mPapers.front(); return mPapers.first();
} }
std::list<Paper*>::const_iterator it; foreach ( Paper *paper, mPapers )
for ( it = mPapers.begin(); it != mPapers.end(); it++ )
{ {
if ( (*it)->id() == id ) if ( paper->id() == id )
{ {
return *it; return paper;
} }
} }
@@ -146,10 +144,9 @@ namespace libglabels
bool Db::isPaperIdKnown( const QString &id ) bool Db::isPaperIdKnown( const QString &id )
{ {
std::list<Paper*>::const_iterator it; foreach ( Paper *paper, mPapers )
for ( it = mPapers.begin(); it != mPapers.end(); it++ )
{ {
if ( (*it)->id() == id ) if ( paper->id() == id )
{ {
return true; return true;
} }
@@ -169,9 +166,9 @@ namespace libglabels
{ {
if ( !isCategoryIdKnown( category->id() ) ) if ( !isCategoryIdKnown( category->id() ) )
{ {
mCategories.push_back( category ); mCategories << category;
mCategoryIds.push_back( category->id() ); mCategoryIds << category->id();
mCategoryNames.push_back( category->name() ); mCategoryNames << category->name();
} }
else else
{ {
@@ -185,15 +182,14 @@ namespace libglabels
if ( name.isNull() || name.isEmpty() ) if ( name.isNull() || name.isEmpty() )
{ {
qDebug( "NULL category name." ); qDebug( "NULL category name." );
return mCategories.front(); return mCategories.first();
} }
std::list<Category*>::const_iterator it; foreach ( Category *category, mCategories )
for ( it = mCategories.begin(); it != mCategories.end(); it++ )
{ {
if ( (*it)->name() == name ) if ( category->name() == name )
{ {
return *it; return category;
} }
} }
@@ -207,15 +203,14 @@ namespace libglabels
if ( id.isNull() || id.isEmpty() ) if ( id.isNull() || id.isEmpty() )
{ {
qDebug( "NULL category ID." ); qDebug( "NULL category ID." );
return mCategories.front(); return mCategories.first();
} }
std::list<Category*>::const_iterator it; foreach ( Category *category, mCategories )
for ( it = mCategories.begin(); it != mCategories.end(); it++ )
{ {
if ( (*it)->id() == id ) if ( category->id() == id )
{ {
return *it; return category;
} }
} }
@@ -258,10 +253,9 @@ namespace libglabels
bool Db::isCategoryIdKnown( const QString &id ) bool Db::isCategoryIdKnown( const QString &id )
{ {
std::list<Category*>::const_iterator it; foreach ( Category *category, mCategories )
for ( it = mCategories.begin(); it != mCategories.end(); it++ )
{ {
if ( (*it)->id() == id ) if ( category->id() == id )
{ {
return true; return true;
} }
@@ -275,8 +269,8 @@ namespace libglabels
{ {
if ( !isVendorNameKnown( vendor->name() ) ) if ( !isVendorNameKnown( vendor->name() ) )
{ {
mVendors.push_back( vendor ); mVendors << vendor;
mVendorNames.push_back( vendor->name() ); mVendorNames << vendor->name();
} }
else else
{ {
@@ -290,15 +284,14 @@ namespace libglabels
if ( name.isNull() || name.isEmpty() ) if ( name.isNull() || name.isEmpty() )
{ {
qDebug( "NULL vendor name." ); qDebug( "NULL vendor name." );
return mVendors.front(); return mVendors.first();
} }
std::list<Vendor*>::const_iterator it; foreach ( Vendor *vendor, mVendors )
for ( it = mVendors.begin(); it != mVendors.end(); it++ )
{ {
if ( (*it)->name() == name ) if ( vendor->name() == name )
{ {
return *it; return vendor;
} }
} }
@@ -325,10 +318,9 @@ namespace libglabels
bool Db::isVendorNameKnown( const QString &name ) bool Db::isVendorNameKnown( const QString &name )
{ {
std::list<Vendor*>::const_iterator it; foreach ( Vendor *vendor, mVendors )
for ( it = mVendors.begin(); it != mVendors.end(); it++ )
{ {
if ( (*it)->name() == name ) if ( vendor->name() == name )
{ {
return true; return true;
} }
@@ -342,7 +334,7 @@ namespace libglabels
{ {
if ( !isTemplateKnown( tmplate->brand(), tmplate->part() ) ) if ( !isTemplateKnown( tmplate->brand(), tmplate->part() ) )
{ {
mTemplates.push_back( tmplate ); mTemplates << tmplate;
} }
else else
{ {
@@ -356,15 +348,14 @@ namespace libglabels
if ( name.isNull() || name.isEmpty() ) if ( name.isNull() || name.isEmpty() )
{ {
qDebug( "NULL template name." ); qDebug( "NULL template name." );
return mTemplates.front(); return mTemplates.first();
} }
std::list<Template*>::const_iterator it; foreach ( Template *tmplate, mTemplates )
for ( it = mTemplates.begin(); it != mTemplates.end(); it++ )
{ {
if ( (*it)->name() == name ) if ( tmplate->name() == name )
{ {
return *it; return tmplate;
} }
} }
@@ -378,15 +369,14 @@ namespace libglabels
if ( brand.isNull() || brand.isEmpty() || part.isNull() || part.isEmpty() ) if ( brand.isNull() || brand.isEmpty() || part.isNull() || part.isEmpty() )
{ {
qDebug( "NULL template brand and/or part." ); qDebug( "NULL template brand and/or part." );
return mTemplates.front(); return mTemplates.first();
} }
std::list<Template*>::const_iterator it; foreach ( Template *tmplate, mTemplates )
for ( it = mTemplates.begin(); it != mTemplates.end(); it++ )
{ {
if ( ((*it)->brand() == brand) && ((*it)->part() == part) ) if ( (tmplate->brand() == brand) && (tmplate->part() == part) )
{ {
return *it; return tmplate;
} }
} }
@@ -397,10 +387,9 @@ namespace libglabels
bool Db::isTemplateKnown( const QString &brand, const QString &part ) bool Db::isTemplateKnown( const QString &brand, const QString &part )
{ {
std::list<Template*>::const_iterator it; foreach ( Template *tmplate, mTemplates )
for ( it = mTemplates.begin(); it != mTemplates.end(); it++ )
{ {
if ( ((*it)->brand() == brand) && ((*it)->part() == part) ) if ( (tmplate->brand() == brand) && (tmplate->part() == part) )
{ {
return true; return true;
} }
@@ -432,11 +421,8 @@ namespace libglabels
{ {
std::cout << "KNOWN PAPERS:" << std::endl; std::cout << "KNOWN PAPERS:" << std::endl;
std::list<Paper*>::const_iterator it; foreach ( Paper *paper, mPapers )
for ( it = mPapers.begin(); it != mPapers.end(); it++ )
{ {
Paper *paper = *it;
std::cout << "paper " std::cout << "paper "
<< "id='" << qPrintable(paper->id()) << "', " << "id='" << qPrintable(paper->id()) << "', "
<< "name='" << qPrintable(paper->name()) << "', " << "name='" << qPrintable(paper->name()) << "', "
@@ -454,11 +440,8 @@ namespace libglabels
{ {
std::cout << "KNOWN CATEGORIES:" << std::endl; std::cout << "KNOWN CATEGORIES:" << std::endl;
std::list<Category*>::const_iterator it; foreach ( Category *category, mCategories )
for ( it = mCategories.begin(); it != mCategories.end(); it++ )
{ {
Category *category = *it;
std::cout << "category " std::cout << "category "
<< "id='" << category->id().toStdString() << "', " << "id='" << category->id().toStdString() << "', "
<< "name='" << category->name().toStdString() << "', " << "name='" << category->name().toStdString() << "', "
@@ -473,11 +456,8 @@ namespace libglabels
{ {
std::cout << "KNOWN VENDORS:" << std::endl; std::cout << "KNOWN VENDORS:" << std::endl;
std::list<Vendor*>::const_iterator it; foreach ( Vendor *vendor, mVendors )
for ( it = mVendors.begin(); it != mVendors.end(); it++ )
{ {
Vendor *vendor = *it;
std::cout << "vendor " std::cout << "vendor "
<< "name='" << vendor->name().toStdString() << "', " << "name='" << vendor->name().toStdString() << "', "
<< "url='" << vendor->url().toStdString() << "'" << "url='" << vendor->url().toStdString() << "'"
@@ -492,11 +472,8 @@ namespace libglabels
{ {
std::cout << "KNOWN TEMPLATES:" << std::endl; std::cout << "KNOWN TEMPLATES:" << std::endl;
std::list<Template*>::const_iterator it; foreach ( Template *tmplate, mTemplates )
for ( it = mTemplates.begin(); it != mTemplates.end(); it++ )
{ {
Template *tmplate = *it;
std::cout << "template " std::cout << "template "
<< "brand='" << tmplate->brand().toStdString() << "', " << "brand='" << tmplate->brand().toStdString() << "', "
<< "part='" << tmplate->part().toStdString() << "', " << "part='" << tmplate->part().toStdString() << "', "
+10 -9
View File
@@ -25,6 +25,7 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QString> #include <QString>
#include <QDir> #include <QDir>
#include <QList>
#include "Paper.h" #include "Paper.h"
#include "Category.h" #include "Category.h"
@@ -99,18 +100,18 @@ namespace libglabels
private: private:
static std::list<Paper*> mPapers; static QList<Paper*> mPapers;
static std::list<QString> mPaperIds; static QStringList mPaperIds;
static std::list<QString> mPaperNames; static QStringList mPaperNames;
static std::list<Category*> mCategories; static QList<Category*> mCategories;
static std::list<QString> mCategoryIds; static QStringList mCategoryIds;
static std::list<QString> mCategoryNames; static QStringList mCategoryNames;
static std::list<Vendor*> mVendors; static QList<Vendor*> mVendors;
static std::list<QString> mVendorNames; static QStringList mVendorNames;
static std::list<Template*> mTemplates; static QList<Template*> mTemplates;
static QString mEmpty; static QString mEmpty;
}; };
+10 -23
View File
@@ -29,24 +29,14 @@ namespace libglabels
mId = other.mId; mId = other.mId;
mNLabels = 0; mNLabels = 0;
foreach ( Layout *layout, mLayouts )
{ {
std::list<Layout*>::const_iterator it; addLayout( layout->dup() );
for ( it = other.mLayouts.begin(); it != other.mLayouts.end(); it++ )
{
Layout *layout = (*it)->dup();
addLayout( layout );
}
} }
foreach ( Markup *markup, mMarkups )
{ {
std::list<Markup*>::const_iterator it; addMarkup( markup->dup() );
for ( it = other.mMarkups.begin(); it != other.mMarkups.end(); it++ )
{
Markup *markup = (*it)->dup();
addMarkup( markup );
}
} }
} }
@@ -55,16 +45,13 @@ namespace libglabels
{ {
std::vector<Point> origins( nLabels() ); std::vector<Point> origins( nLabels() );
std::list<Layout*>::const_iterator it; foreach ( Layout *layout, mLayouts )
for ( it = mLayouts.begin(); it != mLayouts.end(); it++ )
{ {
Layout *lo = *it; for ( int iy = 0; iy < layout->ny(); iy++ )
for ( int iy = 0; iy < lo->ny(); iy++ )
{ {
for ( int ix = 0; ix < lo->nx(); ix++ ) for ( int ix = 0; ix < layout->nx(); ix++ )
{ {
origins.push_back( Point( ix*lo->dx() + lo->x0(), iy*lo->dy() + lo->y0() ) ); origins.push_back( Point( ix*layout->dx() + layout->x0(), iy*layout->dy() + layout->y0() ) );
} }
} }
} }
@@ -75,7 +62,7 @@ namespace libglabels
void Frame::addLayout( Layout *layout ) void Frame::addLayout( Layout *layout )
{ {
mLayouts.push_back( layout ); mLayouts << layout;
// Update total number of labels // Update total number of labels
mNLabels += layout->nx() * layout->ny(); mNLabels += layout->nx() * layout->ny();
@@ -101,7 +88,7 @@ namespace libglabels
void Frame::addMarkup( Markup *markup ) void Frame::addMarkup( Markup *markup )
{ {
mMarkups.push_back( markup ); mMarkups << markup;
} }
} }
+5 -5
View File
@@ -23,8 +23,8 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QString> #include <QString>
#include <QList>
#include <list>
#include <vector> #include <vector>
#include "Units.h" #include "Units.h"
@@ -53,8 +53,8 @@ namespace libglabels
inline const QString &id() const { return mId; } inline const QString &id() const { return mId; }
inline int nLabels() const { return mNLabels; } inline int nLabels() const { return mNLabels; }
inline const QString &layoutDescription() { return mLayoutDescription; } inline const QString &layoutDescription() { return mLayoutDescription; }
inline const std::list<Layout*> &layouts() { return mLayouts; } inline const QList<Layout*> &layouts() { return mLayouts; }
inline const std::list<Markup*> &markups() { return mMarkups; } inline const QList<Markup*> &markups() { return mMarkups; }
std::vector<Point> getOrigins() const; std::vector<Point> getOrigins() const;
@@ -73,8 +73,8 @@ namespace libglabels
int mNLabels; int mNLabels;
QString mLayoutDescription; QString mLayoutDescription;
std::list<Layout*> mLayouts; QList<Layout*> mLayouts;
std::list<Markup*> mMarkups; QList<Markup*> mMarkups;
}; };
+13 -25
View File
@@ -36,22 +36,14 @@ namespace libglabels
mName = other.mName; mName = other.mName;
mProductUrl = other.mProductUrl; mProductUrl = other.mProductUrl;
foreach ( Frame *frame, other.mFrames )
{ {
std::list<Frame*>::const_iterator it; addFrame( frame );
for ( it = other.mFrames.begin(); it != other.mFrames.end(); it++ )
{
Frame *frame = (*it)->dup();
addFrame( frame );
}
} }
foreach ( QString categoryId, other.mCategoryIds )
{ {
std::list<QString>::const_iterator it; addCategory( categoryId );
for ( it = other.mCategoryIds.begin(); it != other.mCategoryIds.end(); it++ )
{
addCategory( *it );
}
} }
} }
@@ -76,13 +68,13 @@ namespace libglabels
void Template::addCategory( const QString &categoryId ) void Template::addCategory( const QString &categoryId )
{ {
mCategoryIds.push_back( categoryId ); mCategoryIds << categoryId;
} }
void Template::addFrame( Frame *frame ) void Template::addFrame( Frame *frame )
{ {
mFrames.push_back( frame ); mFrames << frame;
} }
@@ -94,11 +86,9 @@ namespace libglabels
bool Template::hasCategory( const QString &categoryId ) const bool Template::hasCategory( const QString &categoryId ) const
{ {
std::list<QString>::const_iterator it; foreach ( QString testCategoryId, mCategoryIds )
for ( it = mCategoryIds.begin(); it != mCategoryIds.end(); it++ )
{ {
if ( categoryId == *it ) if ( categoryId == testCategoryId )
{ {
return true; return true;
} }
@@ -119,22 +109,20 @@ namespace libglabels
} }
// Are frames similar // Are frames similar
Frame *frame1 = *(mFrames.begin()); Frame *frame1 = mFrames.first();
Frame *frame2 = *(other.mFrames.begin()); Frame *frame2 = other.mFrames.first();
if ( !frame1->isSimilarTo( frame2 ) ) if ( !frame1->isSimilarTo( frame2 ) )
{ {
return false; return false;
} }
// Are they layed out similarly? // Are they layed out similarly?
std::list<Layout*>::const_iterator it1; foreach ( Layout *layout1, frame1->layouts() )
std::list<Layout*>::const_iterator it2;
for ( it1 = frame1->layouts().begin(); it1 != frame1->layouts().end(); it1++ )
{ {
bool matchFound = false; bool matchFound = false;
for ( it2 = frame2->layouts().begin(); it2 != frame2->layouts().end(); it2++ ) foreach ( Layout *layout2, frame2->layouts() )
{ {
if ( (*it1)->isSimilarTo(*it2) ) if ( layout1->isSimilarTo(layout2) )
{ {
matchFound = true; matchFound = true;
break; break;
+5 -4
View File
@@ -23,8 +23,9 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QString> #include <QString>
#include <QStringList>
#include <QList>
#include <list>
#include <vector> #include <vector>
#include "Units.h" #include "Units.h"
@@ -107,10 +108,10 @@ namespace libglabels
QString mEquivPart; QString mEquivPart;
QString mName; QString mName;
QString mProductUrl; QString mProductUrl;
std::list<QString> mCategoryIds; QStringList mCategoryIds;
std::list<Frame*> mFrames; QList<Frame*> mFrames;
}; };
} }