diff --git a/libglabels/Db.cpp b/libglabels/Db.cpp index cadb2c8..f4f43c6 100644 --- a/libglabels/Db.cpp +++ b/libglabels/Db.cpp @@ -32,15 +32,15 @@ namespace libglabels { - std::list Db::mPapers; - std::list Db::mPaperIds; - std::list Db::mPaperNames; - std::list Db::mCategories; - std::list Db::mCategoryIds; - std::list Db::mCategoryNames; - std::list Db::mVendors; - std::list Db::mVendorNames; - std::list Db::mTemplates; + QList Db::mPapers; + QStringList Db::mPaperIds; + QStringList Db::mPaperNames; + QList Db::mCategories; + QStringList Db::mCategoryIds; + QStringList Db::mCategoryNames; + QList Db::mVendors; + QStringList Db::mVendorNames; + QList 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::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::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::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::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::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::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::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::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::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::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::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::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::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::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::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() << "', " diff --git a/libglabels/Db.h b/libglabels/Db.h index 1bcccff..7af28d0 100644 --- a/libglabels/Db.h +++ b/libglabels/Db.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "Paper.h" #include "Category.h" @@ -99,18 +100,18 @@ namespace libglabels private: - static std::list mPapers; - static std::list mPaperIds; - static std::list mPaperNames; + static QList mPapers; + static QStringList mPaperIds; + static QStringList mPaperNames; - static std::list mCategories; - static std::list mCategoryIds; - static std::list mCategoryNames; + static QList mCategories; + static QStringList mCategoryIds; + static QStringList mCategoryNames; - static std::list mVendors; - static std::list mVendorNames; + static QList mVendors; + static QStringList mVendorNames; - static std::list mTemplates; + static QList mTemplates; static QString mEmpty; }; diff --git a/libglabels/Frame.cpp b/libglabels/Frame.cpp index 316df43..174ccbd 100644 --- a/libglabels/Frame.cpp +++ b/libglabels/Frame.cpp @@ -29,24 +29,14 @@ namespace libglabels mId = other.mId; mNLabels = 0; + foreach ( Layout *layout, mLayouts ) { - std::list::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::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 origins( nLabels() ); - std::list::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; } } diff --git a/libglabels/Frame.h b/libglabels/Frame.h index 8fc5e0c..ff80e72 100644 --- a/libglabels/Frame.h +++ b/libglabels/Frame.h @@ -23,8 +23,8 @@ #include #include +#include -#include #include #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 &layouts() { return mLayouts; } - inline const std::list &markups() { return mMarkups; } + inline const QList &layouts() { return mLayouts; } + inline const QList &markups() { return mMarkups; } std::vector getOrigins() const; @@ -73,8 +73,8 @@ namespace libglabels int mNLabels; QString mLayoutDescription; - std::list mLayouts; - std::list mMarkups; + QList mLayouts; + QList mMarkups; }; diff --git a/libglabels/Template.cpp b/libglabels/Template.cpp index c0cd6f6..dde8bf8 100644 --- a/libglabels/Template.cpp +++ b/libglabels/Template.cpp @@ -36,22 +36,14 @@ namespace libglabels mName = other.mName; mProductUrl = other.mProductUrl; + foreach ( Frame *frame, other.mFrames ) { - std::list::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::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::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::const_iterator it1; - std::list::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; diff --git a/libglabels/Template.h b/libglabels/Template.h index 6642c8e..1da0f51 100644 --- a/libglabels/Template.h +++ b/libglabels/Template.h @@ -23,8 +23,9 @@ #include #include +#include +#include -#include #include #include "Units.h" @@ -107,10 +108,10 @@ namespace libglabels QString mEquivPart; QString mName; - QString mProductUrl; - std::list mCategoryIds; + QString mProductUrl; + QStringList mCategoryIds; - std::list mFrames; + QList mFrames; }; }