Git commit 4733f8582d65a00f285550c442672f69db1440b2 by Jos=C3=A9 Manuel San= tamar=C3=ADa Lema. Committed on 07/04/2016 at 20:20. Pushed by joselema into branch 'master'. Use the new ingredient name model in the delegate. M +7 -9 src/dialogs/recipeinput/ingredientnamedelegate.cpp M +4 -1 src/dialogs/recipeinput/ingredientnamedelegate.h M +1 -1 src/dialogs/recipeinput/ingredientseditor.cpp http://commits.kde.org/krecipes/4733f8582d65a00f285550c442672f69db1440b2 diff --git a/src/dialogs/recipeinput/ingredientnamedelegate.cpp b/src/dialo= gs/recipeinput/ingredientnamedelegate.cpp index 1161248..2a24b9f 100644 --- a/src/dialogs/recipeinput/ingredientnamedelegate.cpp +++ b/src/dialogs/recipeinput/ingredientnamedelegate.cpp @@ -11,6 +11,8 @@ = #include "dialogs/recipeinput/ingredientseditor.h" #include "backends/recipedb.h" +#include "models/kreallingredientsmodels.h" +#include "models/kresinglecolumnproxymodel.h" #include "datablocks/unit.h" = #include @@ -19,7 +21,9 @@ //#include = = -IngredientNameDelegate::IngredientNameDelegate(QObject *parent): QStyledIt= emDelegate(parent) +IngredientNameDelegate::IngredientNameDelegate( RecipeDB * database, QObje= ct *parent ): + QStyledItemDelegate(parent), + m_database(database) { } = @@ -100,12 +104,8 @@ QWidget * IngredientNameDelegate::createEditor(QWidget= *parent, const QStyleOpti = //Order editor->completionObject()->setOrder( KCompletion::Sorted ); - QSortFilterProxyModel * proxyModel =3D new QSortFilterProxyModel( editor = ); - proxyModel->setSourceModel(editor->model()); - // editor's current model must be reparented, - // otherwise QComboBox::setModel() will delete it - editor->model()->setParent(proxyModel); - editor->setModel( proxyModel ); + + editor->setModel( m_database->allIngredientsModels()->ingredientNameModel= () ); = //Fill the items and the completion objects int i =3D 0; @@ -119,12 +119,10 @@ QWidget * IngredientNameDelegate::createEditor(QWidge= t *parent, const QStyleOpti it_end =3D m_idToIngredientMap.constEnd(); } while( it !=3D it_end ) { - editor->insertItem( i, it.value().name ); editor->completionObject()->addItem( it.value().name ); ++i; ++it; } - proxyModel->sort(0); = return editor; } diff --git a/src/dialogs/recipeinput/ingredientnamedelegate.h b/src/dialogs= /recipeinput/ingredientnamedelegate.h index f44fc48..e2e052a 100644 --- a/src/dialogs/recipeinput/ingredientnamedelegate.h +++ b/src/dialogs/recipeinput/ingredientnamedelegate.h @@ -24,7 +24,8 @@ class IngredientNameDelegate : public QStyledItemDelegate Q_OBJECT = public: - IngredientNameDelegate(QObject *parent =3D 0); + IngredientNameDelegate( RecipeDB * database, + QObject *parent =3D 0 ); void loadAllIngredientsList( RecipeDB * database ); void loadAllHeadersList( RecipeDB * database ); QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option= , const QModelIndex &index) const; @@ -42,6 +43,8 @@ private slots: void headerRemovedSlot( int id ); = private: + RecipeDB * m_database; + QHash m_idToIngredientMap; QMultiHash m_ingredientNameToIdMap; = diff --git a/src/dialogs/recipeinput/ingredientseditor.cpp b/src/dialogs/re= cipeinput/ingredientseditor.cpp index 99078d0..5589ba4 100644 --- a/src/dialogs/recipeinput/ingredientseditor.cpp +++ b/src/dialogs/recipeinput/ingredientseditor.cpp @@ -186,7 +186,7 @@ void IngredientsEditor::loadIngredientList( IngredientL= ist * ingredientList ) m_sourceModel->setRowCount( ingredientList->count() ); = //Set ingredient name delegate - IngredientNameDelegate * ingredientNameDelegate =3D new IngredientNameDel= egate; + IngredientNameDelegate * ingredientNameDelegate =3D new IngredientNameDel= egate( m_database ); if ( m_database ) { ingredientNameDelegate->loadAllIngredientsList( m_database ); ingredientNameDelegate->loadAllHeadersList( m_database );