From 1f5e555e00b4119f7fbcf79bd0533b733c90c0f6 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Fri, 15 Nov 2013 21:58:28 -0500 Subject: [PATCH] Added similar list to NewLabelDialog. --- app/NewLabelDialog.cpp | 22 ++++++++++++++++++++++ app/ui/NewLabelDialog.ui | 6 +++--- libglabels/Db.cpp | 26 ++++++++++++++++++++++++++ libglabels/Db.h | 1 + libglabels/Template.cpp | 10 +++++----- libglabels/Template.h | 2 +- 6 files changed, 58 insertions(+), 9 deletions(-) diff --git a/app/NewLabelDialog.cpp b/app/NewLabelDialog.cpp index 3cd5c74..b4c29f9 100644 --- a/app/NewLabelDialog.cpp +++ b/app/NewLabelDialog.cpp @@ -42,6 +42,9 @@ namespace gLabels pageSizeUsRadio->isChecked(), pageSizeOtherRadio->isChecked() ); + similarBrowser->setAttribute(Qt::WA_TranslucentBackground); + similarBrowser->viewport()->setAutoFillBackground(false); + connect( searchEntry, SIGNAL(textChanged(const QString &)), this, SLOT(searchEntryTextChanged(const QString &)) ); @@ -123,6 +126,25 @@ namespace gLabels QString layoutString = frame->layoutDescription(); layoutLabel->setText( layoutString ); + + QStringList list = libglabels::Db::getNameListOfSimilarTemplates( tmplate->name() ); + if ( list.isEmpty() ) + { + similarLabel->hide(); + similarBrowser->hide(); + } + else + { + similarLabel->show(); + similarBrowser->show(); + + QString similarListString; + foreach ( QString name, list ) + { + similarListString += name + "\n"; + } + similarBrowser->setText( similarListString ); + } } } diff --git a/app/ui/NewLabelDialog.ui b/app/ui/NewLabelDialog.ui index fa6661d..37f47fd 100644 --- a/app/ui/NewLabelDialog.ui +++ b/app/ui/NewLabelDialog.ui @@ -245,9 +245,9 @@ - + - Similar products: + Similar to: @@ -261,7 +261,7 @@ - 180 + 150 16777215 diff --git a/libglabels/Db.cpp b/libglabels/Db.cpp index 483d85e..b0890eb 100644 --- a/libglabels/Db.cpp +++ b/libglabels/Db.cpp @@ -411,6 +411,32 @@ namespace libglabels } + QStringList Db::getNameListOfSimilarTemplates( const QString &name ) + { + QStringList list; + + const Template *tmplate1 = lookupTemplateFromName( name ); + if ( tmplate1 == NULL ) + { + qDebug( "Unknown template name: \"%s\".", qPrintable(name) ); + return list; + } + + foreach (const Template *tmplate2, mTemplates ) + { + if ( tmplate1->name() != tmplate2->name() ) + { + if ( tmplate1->isSimilarTo( tmplate2 ) ) + { + list << tmplate2->name(); + } + } + } + + return list; + } + + void Db::registerUserTemplate( Template *templat ) { // TODO diff --git a/libglabels/Db.h b/libglabels/Db.h index 11d1f6b..676dfe3 100644 --- a/libglabels/Db.h +++ b/libglabels/Db.h @@ -86,6 +86,7 @@ namespace libglabels static const Template *lookupTemplateFromName( const QString &name ); static const Template *lookupTemplateFromBrandPart( const QString &brand, const QString &part ); static bool isTemplateKnown( const QString &brand, const QString &part ); + static QStringList getNameListOfSimilarTemplates( const QString &name ); static void registerUserTemplate( Template *tmplate ); static void deleteUserTemplateByName( const QString &name ); diff --git a/libglabels/Template.cpp b/libglabels/Template.cpp index cb8b9e6..a46be27 100644 --- a/libglabels/Template.cpp +++ b/libglabels/Template.cpp @@ -156,19 +156,19 @@ namespace libglabels } - bool Template::isSimilarTo( const Template &other ) const + bool Template::isSimilarTo( const Template *other ) const { // Does page size match? - if ( (mPaperId != other.mPaperId) || - (mPageWidth != other.mPageWidth ) || - (mPageHeight != other.mPageHeight ) ) + if ( (mPaperId != other->mPaperId) || + (mPageWidth != other->mPageWidth ) || + (mPageHeight != other->mPageHeight ) ) { return false; } // Are frames similar Frame *frame1 = mFrames.first(); - Frame *frame2 = other.mFrames.first(); + Frame *frame2 = other->mFrames.first(); if ( !frame1->isSimilarTo( frame2 ) ) { return false; diff --git a/libglabels/Template.h b/libglabels/Template.h index a0d4b32..8d468e9 100644 --- a/libglabels/Template.h +++ b/libglabels/Template.h @@ -97,7 +97,7 @@ namespace libglabels bool operator==( const Template &other ) const; bool hasCategory( const QString &categoryId ) const; - bool isSimilarTo( const Template &other ) const; + bool isSimilarTo( const Template *other ) const; private: