From kde-commits Thu Apr 07 20:25:06 2016 From: =?utf-8?q?Jos=C3=A9_Manuel_Santamar=C3=ADa_Lema?= Date: Thu, 07 Apr 2016 20:25:06 +0000 To: kde-commits Subject: [krecipes] src: Add model for ingredient name. Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=146006072104698 Git commit 806f46cea7b44689a591ae13494359871b19c99a by Jos=C3=A9 Manuel San= tamar=C3=ADa Lema. Committed on 07/04/2016 at 20:13. Pushed by joselema into branch 'master'. Add model for ingredient name. M +1 -0 src/CMakeLists.txt M +11 -1 src/models/kreallingredientsmodels.cpp M +3 -0 src/models/kreallingredientsmodels.h C +12 -9 src/models/kresinglecolumnproxymodel.cpp [from: src/models/k= reallingredientsmodels.cpp - 058% similarity] C +10 -13 src/models/kresinglecolumnproxymodel.h [from: src/models/kre= allingredientsmodels.h - 066% similarity] http://commits.kde.org/krecipes/806f46cea7b44689a591ae13494359871b19c99a diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b104aa1..b133f0a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,6 +41,7 @@ qt4_add_dbus_adaptor(krecipesdbs_SRCS backends/org.kde.kr= ecipesdb.xml recipedb.h = set(krecipesmodels_SRCS models/kreallingredientsmodels.cpp + models/kresinglecolumnproxymodel.cpp ) = ############ importers ############### diff --git a/src/models/kreallingredientsmodels.cpp b/src/models/kreallingr= edientsmodels.cpp index 1da6a5e..3ef16ac 100644 --- a/src/models/kreallingredientsmodels.cpp +++ b/src/models/kreallingredientsmodels.cpp @@ -9,16 +9,26 @@ = #include "kreallingredientsmodels.h" = +#include "kresinglecolumnproxymodel.h" + #include = = KreAllIngredientsModels::KreAllIngredientsModels( RecipeDB * database ): m_database( database ) { - m_sourceModel =3D new QStandardItemModel( this ); + m_sourceModel =3D new QStandardItemModel; + m_ingredientNameModel =3D new KreSingleColumnProxyModel( 1 ); + m_ingredientNameModel->setSortCaseSensitivity( Qt::CaseInsensitive ); + m_ingredientNameModel->setSourceModel( m_sourceModel ); } = QStandardItemModel * KreAllIngredientsModels::sourceModel() { return m_sourceModel; } + +KreSingleColumnProxyModel * KreAllIngredientsModels::ingredientNameModel() +{ + return m_ingredientNameModel; +} diff --git a/src/models/kreallingredientsmodels.h b/src/models/kreallingred= ientsmodels.h index 52cf264..1a0f7b9 100644 --- a/src/models/kreallingredientsmodels.h +++ b/src/models/kreallingredientsmodels.h @@ -13,6 +13,7 @@ #include = class RecipeDB; +class KreSingleColumnProxyModel; class QStandardItemModel; = class KreAllIngredientsModels: public QObject { @@ -22,10 +23,12 @@ public: KreAllIngredientsModels( RecipeDB * database ); = QStandardItemModel * sourceModel(); + KreSingleColumnProxyModel * ingredientNameModel(); = private: RecipeDB * m_database; QStandardItemModel * m_sourceModel; + KreSingleColumnProxyModel * m_ingredientNameModel; = }; = diff --git a/src/models/kreallingredientsmodels.cpp b/src/models/kresinglec= olumnproxymodel.cpp similarity index 58% copy from src/models/kreallingredientsmodels.cpp copy to src/models/kresinglecolumnproxymodel.cpp index 1da6a5e..c28ef35 100644 --- a/src/models/kreallingredientsmodels.cpp +++ b/src/models/kresinglecolumnproxymodel.cpp @@ -7,18 +7,21 @@ * (at your option) any later version. = * **************************************************************************= **/ = -#include "kreallingredientsmodels.h" +#include "kresinglecolumnproxymodel.h" = -#include - - -KreAllIngredientsModels::KreAllIngredientsModels( RecipeDB * database ): - m_database( database ) +KreSingleColumnProxyModel::KreSingleColumnProxyModel( int column ): + QSortFilterProxyModel( 0 ), + m_acceptedColumn( column ) { - m_sourceModel =3D new QStandardItemModel( this ); } = -QStandardItemModel * KreAllIngredientsModels::sourceModel() +bool KreSingleColumnProxyModel::filterAcceptsColumn( int source_column, = + const QModelIndex& source_parent ) const { - return m_sourceModel; + if ( source_column =3D=3D m_acceptedColumn ) { + return QSortFilterProxyModel::filterAcceptsColumn( + source_column, source_parent ); + } else { + return false; + } } diff --git a/src/models/kreallingredientsmodels.h b/src/models/kresinglecol= umnproxymodel.h similarity index 66% copy from src/models/kreallingredientsmodels.h copy to src/models/kresinglecolumnproxymodel.h index 52cf264..fdeffa5 100644 --- a/src/models/kreallingredientsmodels.h +++ b/src/models/kresinglecolumnproxymodel.h @@ -7,26 +7,23 @@ * (at your option) any later version. = * **************************************************************************= **/ = -#ifndef KREALLINGREDIENTSMODELS_H -#define KREALLINGREDIENTSMODELS_H +#ifndef KRESINGLECOLUMNMODEL_H +#define KRESINGLECOLUMNMODEL_H = -#include +#include = -class RecipeDB; -class QStandardItemModel; - -class KreAllIngredientsModels: public QObject { +class KreSingleColumnProxyModel: public QSortFilterProxyModel { Q_OBJECT = public: - KreAllIngredientsModels( RecipeDB * database ); + KreSingleColumnProxyModel( int column ); + +protected: + bool filterAcceptsColumn( int source_column, = + const QModelIndex& source_parent ) const; = - QStandardItemModel * sourceModel(); + int m_acceptedColumn; = -private: - RecipeDB * m_database; - QStandardItemModel * m_sourceModel; - = }; = #endif