Added category filter to SelectProductDialog.

This commit is contained in:
Jim Evins
2016-04-02 23:48:58 -04:00
parent 9f6697376d
commit 9d1fcbaca3
7 changed files with 297 additions and 85 deletions
+92 -4
View File
@@ -39,13 +39,30 @@ SelectProductDialog::SelectProductDialog( QWidget *parent )
pageSizeUsCheck->setChecked( Settings::searchUsPaperSizes() );
pageSizeOtherCheck->setChecked( Settings::searchOtherPaperSizes() );
anyCategoryCheck->setChecked( Settings::searchAllCategories() );
mCategoryIdList = Settings::searchCategoryList();
QList<glabels::Category*> categories = glabels::Db::categories();
foreach ( glabels::Category *category, categories )
{
QCheckBox* check = new QCheckBox( category->name() );
check->setChecked( mCategoryIdList.contains( category->id() ) || anyCategoryCheck->isChecked() );
categoriesLayout->addWidget( check );
mCheckToCategoryMap[check] = category->id();
connect( check, SIGNAL(clicked()), this, SLOT(onCategoryCheckClicked()) );
}
QList<glabels::Template*> tmplates = glabels::Db::templates();
templatePicker->setTemplates( tmplates );
templatePicker->applyFilter( searchEntry->text(),
pageSizeIsoCheck->isChecked(),
pageSizeUsCheck->isChecked(),
pageSizeOtherCheck->isChecked() );
pageSizeOtherCheck->isChecked(),
anyCategoryCheck->isChecked(),
mCategoryIdList );
}
///
@@ -72,7 +89,9 @@ void SelectProductDialog::onSearchEntryTextChanged()
templatePicker->applyFilter( searchEntry->text(),
pageSizeIsoCheck->isChecked(),
pageSizeUsCheck->isChecked(),
pageSizeOtherCheck->isChecked() );
pageSizeOtherCheck->isChecked(),
anyCategoryCheck->isChecked(),
mCategoryIdList );
}
@@ -86,7 +105,7 @@ void SelectProductDialog::onSearchClearButtonClicked()
///
/// Page Size Check Toggled Slot
/// Page Size Check Clicked Slot
///
void SelectProductDialog::onPageSizeCheckClicked()
{
@@ -97,7 +116,56 @@ void SelectProductDialog::onPageSizeCheckClicked()
templatePicker->applyFilter( searchEntry->text(),
pageSizeIsoCheck->isChecked(),
pageSizeUsCheck->isChecked(),
pageSizeOtherCheck->isChecked() );
pageSizeOtherCheck->isChecked(),
anyCategoryCheck->isChecked(),
mCategoryIdList );
}
///
/// Any category Check Clicked Slot
///
void SelectProductDialog::onAnyCategoryCheckClicked()
{
if ( anyCategoryCheck->isChecked() )
{
foreach( QCheckBox* check, mCheckToCategoryMap.keys() )
{
check->setChecked( true );
}
}
loadCategoryList();
templatePicker->applyFilter( searchEntry->text(),
pageSizeIsoCheck->isChecked(),
pageSizeUsCheck->isChecked(),
pageSizeOtherCheck->isChecked(),
anyCategoryCheck->isChecked(),
mCategoryIdList );
}
///
/// Category Check Clicked Slot
///
void SelectProductDialog::onCategoryCheckClicked()
{
bool allFlag = true;
foreach( QCheckBox* check, mCheckToCategoryMap.keys() )
{
allFlag = allFlag && check->isChecked();
}
anyCategoryCheck->setChecked( allFlag );
loadCategoryList();
templatePicker->applyFilter( searchEntry->text(),
pageSizeIsoCheck->isChecked(),
pageSizeUsCheck->isChecked(),
pageSizeOtherCheck->isChecked(),
anyCategoryCheck->isChecked(),
mCategoryIdList );
}
@@ -129,3 +197,23 @@ void SelectProductDialog::timerEvent( QTimerEvent *event )
mTimer.stop();
close();
}
///
/// Load category list
///
void SelectProductDialog::loadCategoryList()
{
mCategoryIdList.clear();
foreach( QCheckBox* check, mCheckToCategoryMap.keys() )
{
if ( check->isChecked() )
{
mCategoryIdList.append( mCheckToCategoryMap[check] );
}
}
Settings::setSearchAllCategories( anyCategoryCheck->isChecked() );
Settings::setSearchCategoryList( mCategoryIdList );
}
+13
View File
@@ -53,6 +53,8 @@ private slots:
void onSearchEntryTextChanged();
void onSearchClearButtonClicked();
void onPageSizeCheckClicked();
void onAnyCategoryCheckClicked();
void onCategoryCheckClicked();
void onTemplatePickerSelectionChanged();
void onCancelButtonClicked();
@@ -64,11 +66,22 @@ protected:
void timerEvent(QTimerEvent *event);
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
void loadCategoryList();
/////////////////////////////////
// Private data
/////////////////////////////////
private:
QBasicTimer mTimer;
QMap<QCheckBox*,QString> mCheckToCategoryMap;
QStringList mCategoryIdList;
bool mCanceled;
};
+44 -3
View File
@@ -22,6 +22,7 @@
#include <QLocale>
#include <QString>
#include <QtDebug>
Settings* Settings::mInstance = 0;
@@ -108,7 +109,6 @@ bool Settings::searchIsoPaperSizes()
void Settings::setSearchIsoPaperSizes( bool searchIsoPaperSizes )
{
mInstance->beginGroup( "Search" );
mInstance->setValue( "isoPaperSizes", searchIsoPaperSizes );
mInstance->endGroup();
@@ -143,7 +143,6 @@ bool Settings::searchUsPaperSizes()
void Settings::setSearchUsPaperSizes( bool searchUsPaperSizes )
{
mInstance->beginGroup( "Search" );
mInstance->setValue( "usPaperSizes", searchUsPaperSizes );
mInstance->endGroup();
@@ -167,7 +166,6 @@ bool Settings::searchOtherPaperSizes()
void Settings::setSearchOtherPaperSizes( bool searchOtherPaperSizes )
{
mInstance->beginGroup( "Search" );
mInstance->setValue( "otherPaperSizes", searchOtherPaperSizes );
mInstance->endGroup();
@@ -176,3 +174,46 @@ void Settings::setSearchOtherPaperSizes( bool searchOtherPaperSizes )
}
bool Settings::searchAllCategories()
{
// Guess at a suitable default
bool defaultValue = true;
mInstance->beginGroup( "Search" );
bool returnValue = mInstance->value( "allCategories", defaultValue ).toBool();
mInstance->endGroup();
return returnValue;
}
void Settings::setSearchAllCategories( bool searchAllCategories )
{
mInstance->beginGroup( "Search" );
mInstance->setValue( "allCategories", searchAllCategories );
mInstance->endGroup();
emit mInstance->changed();
}
QStringList Settings::searchCategoryList()
{
QStringList defaultList;
mInstance->beginGroup( "Search" );
QStringList returnList = mInstance->value( "categoryList", defaultList ).toStringList();
mInstance->endGroup();
return returnList;
}
void Settings::setSearchCategoryList( const QStringList& searchCategoryList )
{
mInstance->beginGroup( "Search" );
mInstance->setValue( "categoryList", searchCategoryList );
mInstance->endGroup();
emit mInstance->changed();
}
+7
View File
@@ -24,6 +24,7 @@
#include <QSettings>
#include "libglabels/Distance.h"
#include <QStringList>
///
@@ -71,6 +72,12 @@ public:
static bool searchOtherPaperSizes();
static void setSearchOtherPaperSizes( bool searchOtherPaperSizes );
static bool searchAllCategories();
static void setSearchAllCategories( bool searchAllCategories );
static QStringList searchCategoryList();
static void setSearchCategoryList( const QStringList& searchCategoryList );
private:
static Settings* mInstance;
+20 -2
View File
@@ -55,18 +55,36 @@ void TemplatePicker::setTemplates( const QList <glabels::Template*> &tmplates )
/// Apply Filter to Narrow Template Choices
///
void TemplatePicker::applyFilter( const QString &searchString,
bool isoMask, bool usMask, bool otherMask )
bool isoMask, bool usMask, bool otherMask,
bool anyCategory, const QStringList& categoryIds )
{
foreach ( QListWidgetItem *item, findItems( "*", Qt::MatchWildcard ) )
{
TemplatePickerItem *tItem = dynamic_cast<TemplatePickerItem *>(item);
bool nameMask = tItem->tmplate()->name().contains( searchString, Qt::CaseInsensitive );
bool sizeMask =
(isoMask && tItem->tmplate()->isSizeIso()) ||
(usMask && tItem->tmplate()->isSizeUs()) ||
(otherMask && tItem->tmplate()->isSizeOther());
if ( tItem->tmplate()->name().contains( searchString, Qt::CaseInsensitive ) && sizeMask )
bool categoryMask;
if ( anyCategory )
{
categoryMask = true;
}
else
{
categoryMask = false;
foreach ( QString id, categoryIds )
{
categoryMask = categoryMask || tItem->tmplate()->hasCategory( id );
}
}
if ( nameMask && sizeMask && categoryMask )
{
item->setHidden( false );
}
+3 -1
View File
@@ -53,7 +53,9 @@ public:
/////////////////////////////////
// Methods
/////////////////////////////////
void applyFilter( const QString &searchString, bool isoMask, bool usMask, bool otherMask );
void applyFilter( const QString &searchString,
bool isoMask, bool usMask, bool otherMask,
bool anyCategory, const QStringList& categoryIds );
const glabels::Template *selectedTemplate();
+118 -75
View File
@@ -85,7 +85,7 @@
<bool>false</bool>
</property>
<property name="title">
<string>Page size</string>
<string>Filter by paper size</string>
</property>
<property name="flat">
<bool>false</bool>
@@ -118,6 +118,32 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Filter by category</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" rowspan="2">
<layout class="QVBoxLayout" name="categoriesLayout">
<item>
<widget class="QCheckBox" name="anyCategoryCheck">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>All categories</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
@@ -182,82 +208,18 @@
</resources>
<connections>
<connection>
<sender>searchEntry</sender>
<signal>textChanged(QString)</signal>
<receiver>SelectProductDialog</receiver>
<slot>onSearchEntryTextChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>69</x>
<y>48</y>
</hint>
<hint type="destinationlabel">
<x>2</x>
<y>53</y>
</hint>
</hints>
</connection>
<connection>
<sender>searchClearButton</sender>
<signal>clicked()</signal>
<receiver>SelectProductDialog</receiver>
<slot>onSearchClearButtonClicked()</slot>
<hints>
<hint type="sourcelabel">
<x>177</x>
<y>52</y>
</hint>
<hint type="destinationlabel">
<x>190</x>
<y>7</y>
</hint>
</hints>
</connection>
<connection>
<sender>templatePicker</sender>
<signal>itemSelectionChanged()</signal>
<receiver>SelectProductDialog</receiver>
<slot>onTemplatePickerSelectionChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>232</x>
<y>550</y>
</hint>
<hint type="destinationlabel">
<x>244</x>
<y>697</y>
</hint>
</hints>
</connection>
<connection>
<sender>cancelButton</sender>
<signal>clicked()</signal>
<receiver>SelectProductDialog</receiver>
<slot>onCancelButtonClicked()</slot>
<hints>
<hint type="sourcelabel">
<x>864</x>
<y>648</y>
</hint>
<hint type="destinationlabel">
<x>689</x>
<y>704</y>
</hint>
</hints>
</connection>
<connection>
<sender>pageSizeIsoCheck</sender>
<sender>pageSizeOtherCheck</sender>
<signal>clicked()</signal>
<receiver>SelectProductDialog</receiver>
<slot>onPageSizeCheckClicked()</slot>
<hints>
<hint type="sourcelabel">
<x>40</x>
<y>112</y>
<x>35</x>
<y>169</y>
</hint>
<hint type="destinationlabel">
<x>2</x>
<y>116</y>
<x>8</x>
<y>168</y>
</hint>
</hints>
</connection>
@@ -278,18 +240,98 @@
</hints>
</connection>
<connection>
<sender>pageSizeOtherCheck</sender>
<sender>templatePicker</sender>
<signal>itemSelectionChanged()</signal>
<receiver>SelectProductDialog</receiver>
<slot>onTemplatePickerSelectionChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>232</x>
<y>550</y>
</hint>
<hint type="destinationlabel">
<x>244</x>
<y>697</y>
</hint>
</hints>
</connection>
<connection>
<sender>pageSizeIsoCheck</sender>
<signal>clicked()</signal>
<receiver>SelectProductDialog</receiver>
<slot>onPageSizeCheckClicked()</slot>
<hints>
<hint type="sourcelabel">
<x>35</x>
<y>169</y>
<x>40</x>
<y>112</y>
</hint>
<hint type="destinationlabel">
<x>8</x>
<y>168</y>
<x>2</x>
<y>116</y>
</hint>
</hints>
</connection>
<connection>
<sender>cancelButton</sender>
<signal>clicked()</signal>
<receiver>SelectProductDialog</receiver>
<slot>onCancelButtonClicked()</slot>
<hints>
<hint type="sourcelabel">
<x>955</x>
<y>648</y>
</hint>
<hint type="destinationlabel">
<x>689</x>
<y>704</y>
</hint>
</hints>
</connection>
<connection>
<sender>searchClearButton</sender>
<signal>clicked()</signal>
<receiver>SelectProductDialog</receiver>
<slot>onSearchClearButtonClicked()</slot>
<hints>
<hint type="sourcelabel">
<x>177</x>
<y>52</y>
</hint>
<hint type="destinationlabel">
<x>190</x>
<y>7</y>
</hint>
</hints>
</connection>
<connection>
<sender>searchEntry</sender>
<signal>textChanged(QString)</signal>
<receiver>SelectProductDialog</receiver>
<slot>onSearchEntryTextChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>69</x>
<y>48</y>
</hint>
<hint type="destinationlabel">
<x>2</x>
<y>53</y>
</hint>
</hints>
</connection>
<connection>
<sender>anyCategoryCheck</sender>
<signal>clicked()</signal>
<receiver>SelectProductDialog</receiver>
<slot>onAnyCategoryCheckClicked()</slot>
<hints>
<hint type="sourcelabel">
<x>31</x>
<y>234</y>
</hint>
<hint type="destinationlabel">
<x>-7</x>
<y>240</y>
</hint>
</hints>
</connection>
@@ -302,5 +344,6 @@
<slot>onCancelButtonClicked()</slot>
<slot>onSelectButtonClicked()</slot>
<slot>onPageSizeCheckClicked()</slot>
<slot>onAnyCategoryCheckClicked()</slot>
</slots>
</ui>