Added simple page size filtering.

This commit is contained in:
Jim Evins
2013-11-13 00:04:00 -05:00
parent 5ce9121801
commit 1c02315db9
7 changed files with 77 additions and 17 deletions
+29 -1
View File
@@ -30,17 +30,45 @@ namespace gLabels
{ {
setupUi( this ); setupUi( this );
// TODO: Set default based on locale
pageSizeIsoRadio->setChecked( true );
QList<libglabels::Template*> tmplates = libglabels::Db::templates(); QList<libglabels::Template*> tmplates = libglabels::Db::templates();
templatePicker->setTemplates( tmplates ); templatePicker->setTemplates( tmplates );
templatePicker->applyFilter( searchEntry->text(),
pageSizeIsoRadio->isChecked(),
pageSizeUsRadio->isChecked(),
pageSizeOtherRadio->isChecked() );
connect( searchEntry, SIGNAL(textChanged(const QString &)), connect( searchEntry, SIGNAL(textChanged(const QString &)),
this, SLOT(searchEntryTextChanged(const QString &)) ); this, SLOT(searchEntryTextChanged(const QString &)) );
connect( pageSizeIsoRadio, SIGNAL(toggled(bool)), this, SLOT(pageSizeRadioToggled(bool)) );
connect( pageSizeUsRadio, SIGNAL(toggled(bool)), this, SLOT(pageSizeRadioToggled(bool)) );
connect( pageSizeOtherRadio, SIGNAL(toggled(bool)), this, SLOT(pageSizeRadioToggled(bool)) );
} }
void NewLabelDialog::searchEntryTextChanged( const QString &text ) void NewLabelDialog::searchEntryTextChanged( const QString &text )
{ {
templatePicker->applyFilter( text ); templatePicker->applyFilter( text,
pageSizeIsoRadio->isChecked(),
pageSizeUsRadio->isChecked(),
pageSizeOtherRadio->isChecked() );
}
void NewLabelDialog::pageSizeRadioToggled( bool checked )
{
if ( checked )
{
templatePicker->applyFilter( searchEntry->text(),
pageSizeIsoRadio->isChecked(),
pageSizeUsRadio->isChecked(),
pageSizeOtherRadio->isChecked() );
}
} }
} }
+1
View File
@@ -36,6 +36,7 @@ namespace gLabels
private slots: private slots:
void searchEntryTextChanged( const QString &text ); void searchEntryTextChanged( const QString &text );
void pageSizeRadioToggled( bool checked );
}; };
+7 -3
View File
@@ -48,13 +48,17 @@ namespace gLabels
} }
void TemplatePicker::applyFilter( const QString &searchString ) void TemplatePicker::applyFilter( const QString &searchString,
bool isoMask, bool usMask, bool otherMask )
{ {
foreach ( QListWidgetItem *item, findItems( "*", Qt::MatchWildcard ) ) foreach ( QListWidgetItem *item, findItems( "*", Qt::MatchWildcard ) )
{ {
TemplatePickerItem *tPitem = dynamic_cast<TemplatePickerItem *>(item); TemplatePickerItem *tItem = dynamic_cast<TemplatePickerItem *>(item);
if ( tPitem->tmplate()->name().contains( searchString, Qt::CaseInsensitive ) ) if ( tItem->tmplate()->name().contains( searchString, Qt::CaseInsensitive ) &&
(isoMask == tItem->tmplate()->isSizeIso()) &&
(usMask == tItem->tmplate()->isSizeUs()) &&
(otherMask == tItem->tmplate()->isSizeOther()) )
{ {
item->setHidden( false ); item->setHidden( false );
+1 -1
View File
@@ -40,7 +40,7 @@ namespace gLabels
void setTemplates( const QList <libglabels::Template*> &tmplates ); void setTemplates( const QList <libglabels::Template*> &tmplates );
void applyFilter( const QString &searchString ); void applyFilter( const QString &searchString, bool isoMask, bool usMask, bool otherMask );
private: private:
+3
View File
@@ -52,6 +52,9 @@ namespace libglabels
/* PWG 5101.1-2002 size name */ /* PWG 5101.1-2002 size name */
inline QString pwgSize() const { return mPwgSize; } inline QString pwgSize() const { return mPwgSize; }
inline bool isSizeIso() const { return mPwgSize.startsWith( "iso_" ); }
inline bool isSizeUs() const { return mPwgSize.startsWith( "na_" ); }
private: private:
QString mId; QString mId;
QString mName; QString mName;
+29
View File
@@ -28,6 +28,33 @@
namespace libglabels namespace libglabels
{ {
Template::Template( const QString &brand,
const QString &part,
const QString &description,
const QString &paperId,
double pageWidth = 0,
double pageHeight = 0 )
: mBrand(brand),
mPart(part),
mDescription(description),
mPaperId(paperId),
mPageWidth(pageWidth),
mPageHeight(pageHeight),
mIsSizeIso(false),
mIsSizeUs(false),
mName("")
{
mName.append( brand ).append( " " ).append( part );
if ( Db::isPaperIdKnown( paperId ) )
{
const Paper *paper = Db::lookupPaperFromId( paperId );
mIsSizeIso = paper->isSizeIso();
mIsSizeUs = paper->isSizeUs();
}
}
Template::Template( const Template &other ) Template::Template( const Template &other )
{ {
mBrand = other.mBrand; mBrand = other.mBrand;
@@ -36,6 +63,8 @@ namespace libglabels
mPaperId = other.mPaperId; mPaperId = other.mPaperId;
mPageWidth = other.mPageWidth; mPageWidth = other.mPageWidth;
mPageHeight = other.mPageHeight; mPageHeight = other.mPageHeight;
mIsSizeIso = other.mIsSizeIso;
mIsSizeUs = other.mIsSizeUs;
mEquivPart = other.mEquivPart; mEquivPart = other.mEquivPart;
mName = other.mName; mName = other.mName;
mProductUrl = other.mProductUrl; mProductUrl = other.mProductUrl;
+7 -12
View File
@@ -50,18 +50,8 @@ namespace libglabels
const QString &part, const QString &part,
const QString &description, const QString &description,
const QString &paperId, const QString &paperId,
double pageWidth = 0, double pageWidth,
double pageHeight = 0 ) double pageHeight );
: mBrand(brand),
mPart(part),
mDescription(description),
mPaperId(paperId),
mPageWidth(pageWidth),
mPageHeight(pageHeight),
mName("")
{
mName.append( brand ).append( " " ).append( part );
}
Template( const Template &other ); Template( const Template &other );
@@ -84,6 +74,9 @@ namespace libglabels
inline const QString &paperId() const { return mPaperId; } inline const QString &paperId() const { return mPaperId; }
inline double pageWidth() const { return mPageWidth; } inline double pageWidth() const { return mPageWidth; }
inline double pageHeight() const { return mPageHeight; } inline double pageHeight() const { return mPageHeight; }
inline bool isSizeIso() const { return mIsSizeIso; }
inline bool isSizeUs() const { return mIsSizeUs; }
inline bool isSizeOther() const { return !mIsSizeIso && !mIsSizeUs; }
inline const QString &equivPart() const { return mEquivPart; } inline const QString &equivPart() const { return mEquivPart; }
inline void setEquivPart( const QString &value ) { mEquivPart = value; } inline void setEquivPart( const QString &value ) { mEquivPart = value; }
@@ -115,6 +108,8 @@ namespace libglabels
QString mPaperId; QString mPaperId;
double mPageWidth; double mPageWidth;
double mPageHeight; double mPageHeight;
bool mIsSizeIso;
bool mIsSizeUs;
QString mEquivPart; QString mEquivPart;
QString mName; QString mName;