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