From 50e52d6675b20da1579526196c2f7ecc0744b37f Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 3 Apr 2016 18:42:01 -0400 Subject: [PATCH] Added recently-used products tab to SelectProductDialog. --- glabels/LabelModel.h | 3 + glabels/SelectProductDialog.cpp | 38 ++- glabels/SelectProductDialog.h | 1 + glabels/Settings.cpp | 33 +++ glabels/Settings.h | 3 + glabels/TemplatePicker.cpp | 36 ++- glabels/TemplatePicker.h | 4 +- glabels/ui/SelectProductDialog.ui | 446 ++++++++++++++++++------------ 8 files changed, 371 insertions(+), 193 deletions(-) diff --git a/glabels/LabelModel.h b/glabels/LabelModel.h index 3b2806a..1a690a8 100644 --- a/glabels/LabelModel.h +++ b/glabels/LabelModel.h @@ -27,6 +27,7 @@ #include "MergeRecord.h" #include "libglabels/Template.h" +#include "Settings.h" // Forward References @@ -265,6 +266,8 @@ inline void LabelModel::setTmplate( const glabels::Template* tmplate ) mModified = true; emit changed(); emit sizeChanged(); + + Settings::addToRecentTemplateList( tmplate->name() ); } } diff --git a/glabels/SelectProductDialog.cpp b/glabels/SelectProductDialog.cpp index 976e01f..6aff8e0 100644 --- a/glabels/SelectProductDialog.cpp +++ b/glabels/SelectProductDialog.cpp @@ -60,12 +60,12 @@ SelectProductDialog::SelectProductDialog( QWidget *parent ) QList tmplates = glabels::Db::templates(); templatePicker->setTemplates( tmplates ); - templatePicker->applyFilter( searchEntry->text(), - pageSizeIsoCheck->isChecked(), - pageSizeUsCheck->isChecked(), - pageSizeOtherCheck->isChecked(), - allCategoriesRadio->isChecked(), - mCategoryIdList ); + if ( Settings::recentTemplateList().count() > 0 ) + { + modeNotebook->setCurrentIndex(1); + } + + onModeTabChanged(); } /// @@ -84,6 +84,32 @@ const glabels::Template* SelectProductDialog::tmplate() const } +/// +/// Mode Notebook Tab Changed Slot +/// +void SelectProductDialog::onModeTabChanged() +{ + switch (modeNotebook->currentIndex()) + { + case 0: + // Search Tab + templatePicker->applyFilter( searchEntry->text(), + pageSizeIsoCheck->isChecked(), + pageSizeUsCheck->isChecked(), + pageSizeOtherCheck->isChecked(), + allCategoriesRadio->isChecked(), + mCategoryIdList ); + break; + case 1: + // Recent Tab + templatePicker->applyFilter( Settings::recentTemplateList() ); + break; + default: + qDebug() << "onModeTabChanged(): unknown tab!"; + } +} + + /// /// Search Entry Text Changed Slot /// diff --git a/glabels/SelectProductDialog.h b/glabels/SelectProductDialog.h index 75da7f4..298e687 100644 --- a/glabels/SelectProductDialog.h +++ b/glabels/SelectProductDialog.h @@ -50,6 +50,7 @@ public: // Slots ///////////////////////////////// private slots: + void onModeTabChanged(); void onSearchEntryTextChanged(); void onSearchClearButtonClicked(); void onPageSizeCheckClicked(); diff --git a/glabels/Settings.cpp b/glabels/Settings.cpp index 957a29c..cce9ff1 100644 --- a/glabels/Settings.cpp +++ b/glabels/Settings.cpp @@ -217,3 +217,36 @@ void Settings::setSearchCategoryList( const QStringList& searchCategoryList ) emit mInstance->changed(); } + + +QStringList Settings::recentTemplateList() +{ + QStringList defaultList; + + mInstance->beginGroup( "Recent" ); + QStringList returnList = mInstance->value( "templateList", defaultList ).toStringList(); + mInstance->endGroup(); + + return returnList; +} + + +void Settings::addToRecentTemplateList( const QString& name ) +{ + mInstance->beginGroup( "Recent" ); + + QStringList list = mInstance->value( "templateList" ).toStringList(); + + list.removeAll( name ); + list.prepend( name ); + while ( list.count() > 10 ) + { + list.removeLast(); + } + + mInstance->setValue( "templateList", list ); + + mInstance->endGroup(); + + emit mInstance->changed(); +} diff --git a/glabels/Settings.h b/glabels/Settings.h index 25fd79e..bded513 100644 --- a/glabels/Settings.h +++ b/glabels/Settings.h @@ -78,6 +78,9 @@ public: static QStringList searchCategoryList(); static void setSearchCategoryList( const QStringList& searchCategoryList ); + static QStringList recentTemplateList(); + static void addToRecentTemplateList( const QString& name ); + private: static Settings* mInstance; diff --git a/glabels/TemplatePicker.cpp b/glabels/TemplatePicker.cpp index b8d537f..91e5ce8 100644 --- a/glabels/TemplatePicker.cpp +++ b/glabels/TemplatePicker.cpp @@ -52,9 +52,9 @@ void TemplatePicker::setTemplates( const QList &tmplates ) /// -/// Apply Filter to Narrow Template Choices +/// Apply Filter to Narrow Template Choices by search criteria /// -void TemplatePicker::applyFilter( const QString &searchString, +void TemplatePicker::applyFilter( const QString& searchString, bool isoMask, bool usMask, bool otherMask, bool anyCategory, const QStringList& categoryIds ) { @@ -97,6 +97,38 @@ void TemplatePicker::applyFilter( const QString &searchString, } +/// +/// Apply Filter to Narrow Template Choices by a list of names +/// +void TemplatePicker::applyFilter( const QStringList& names ) +{ + foreach ( QListWidgetItem *item, findItems( "*", Qt::MatchWildcard ) ) + { + TemplatePickerItem *tItem = dynamic_cast(item); + + bool match = false; + foreach ( QString name, names ) + { + if ( tItem->tmplate()->name() == name ) + { + match = true; + break; + } + } + + if ( match ) + { + item->setHidden( false ); + } + else + { + item->setHidden( true ); + item->setSelected( false ); + } + } +} + + /// /// Get Currently Selected Template /// diff --git a/glabels/TemplatePicker.h b/glabels/TemplatePicker.h index 029119a..857ef0d 100644 --- a/glabels/TemplatePicker.h +++ b/glabels/TemplatePicker.h @@ -53,10 +53,12 @@ public: ///////////////////////////////// // Methods ///////////////////////////////// - void applyFilter( const QString &searchString, + void applyFilter( const QString& searchString, bool isoMask, bool usMask, bool otherMask, bool anyCategory, const QStringList& categoryIds ); + void applyFilter( const QStringList& names ); + const glabels::Template *selectedTemplate(); }; diff --git a/glabels/ui/SelectProductDialog.ui b/glabels/ui/SelectProductDialog.ui index 4ba5667..6855657 100644 --- a/glabels/ui/SelectProductDialog.ui +++ b/glabels/ui/SelectProductDialog.ui @@ -6,7 +6,7 @@ 0 0 - 987 + 997 661 @@ -19,176 +19,237 @@ - - - - - Search - - - - - - - 0 - 0 - - - - - 180 - 0 - - - - Search - - - - - - - - - - - :/icons/16x16/actions/edit-clear.png:/icons/16x16/actions/edit-clear.png - - - - 16 - 16 - - - - true - - - - - - - - - - - 0 - 0 - - - - - 146 - 87 - - - - - 9 - - - - false - - - Filter by paper size - - - false - - - false - - - - 3 - - - - - ISO sizes - - - - - - - US sizes - - - - - - - Other - - - - - - - - - - Filter by category - - - - 3 - - - - - All - - - - - - - Selected - - - - - - - - 0 + + + + 0 + 0 + + + + 0 + + + + Search all + + + + + + + + 6 - - 0 + + 6 - - - - 3 + + + + + 0 + 0 + - - 20 + + + 180 + 0 + - + + Search + + + + + + + + + + + :/icons/16x16/actions/edit-clear.png:/icons/16x16/actions/edit-clear.png + + + + 16 + 16 + + + + true + + - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - + + + + + + 0 + 0 + + + + + 146 + 87 + + + + + 9 + + + + false + + + Filter by paper size + + + false + + + false + + + + 3 + + + + + ISO sizes + + + + + + + US sizes + + + + + + + Other + + + + + + + + + + Filter by category + + + + 3 + + + + + All + + + + + + + Selected + + + + + + + + 0 + + + 0 + + + + + 3 + + + 20 + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Search entire product database. + + + true + + + + + + + + Recent + + + + + + Select from recently used products. + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + @@ -245,8 +306,8 @@ onPageSizeCheckClicked() - 35 - 169 + 75 + 207 8 @@ -261,8 +322,8 @@ onPageSizeCheckClicked() - 38 - 144 + 78 + 184 4 @@ -277,12 +338,12 @@ onTemplatePickerSelectionChanged() - 232 - 550 + 483 + 561 244 - 697 + 660 @@ -293,8 +354,8 @@ onPageSizeCheckClicked() - 40 - 112 + 80 + 161 2 @@ -314,7 +375,7 @@ 689 - 704 + 660 @@ -325,8 +386,8 @@ onSearchClearButtonClicked() - 177 - 52 + 231 + 103 190 @@ -341,8 +402,8 @@ onSearchEntryTextChanged() - 69 - 48 + 93 + 104 2 @@ -357,11 +418,11 @@ onCategoryRadioClicked() - 36 - 226 + 76 + 270 - -5 + 0 223 @@ -373,8 +434,8 @@ onCategoryRadioClicked() - 32 - 246 + 72 + 294 1 @@ -382,6 +443,22 @@ + + modeNotebook + currentChanged(int) + SelectProductDialog + onModeTabChanged() + + + 59 + 25 + + + 4 + 26 + + + onSearchClearButtonClicked() @@ -392,5 +469,6 @@ onSelectButtonClicked() onPageSizeCheckClicked() onCategoryRadioClicked() + onModeTabChanged()