From kde-commits Tue Jul 12 07:26:43 2016 From: =?utf-8?q?Jos=C3=A9_Manuel_Santamar=C3=ADa_Lema?= Date: Tue, 12 Jul 2016 07:26:43 +0000 To: kde-commits Subject: [krecipes] src: Add initial KreAllIngHeaders implementation. Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=146830841604778 Git commit 06ebc09880f8e6b084091eacc89fe058dae9a857 by Jos=C3=A9 Manuel San= tamar=C3=ADa Lema. Committed on 12/07/2016 at 06:25. Pushed by joselema into branch 'master'. Add initial KreAllIngHeaders implementation. M +1 -0 src/CMakeLists.txt A +159 -0 src/models/kreallingheadersmodels.cpp [License: GPL (v2+= )] A +45 -0 src/models/kreallingheadersmodels.h [License: GPL (v2+)] http://commits.kde.org/krecipes/06ebc09880f8e6b084091eacc89fe058dae9a857 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b048be8..a5ce5b8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -49,6 +49,7 @@ qt4_add_dbus_adaptor(krecipesdbs_SRCS backends/org.kde.kr= ecipesdb.xml recipedb.h = set(krecipesmodels_SRCS models/kreallingredientsmodels.cpp + models/kreallingheadersmodels.cpp models/kresinglecolumnproxymodel.cpp ) = diff --git a/src/models/kreallingheadersmodels.cpp b/src/models/kreallinghe= adersmodels.cpp new file mode 100644 index 0000000..27d7663 --- /dev/null +++ b/src/models/kreallingheadersmodels.cpp @@ -0,0 +1,159 @@ +/*************************************************************************= ** +* Copyright =C2=A9 2016 Jos=C3=A9 Manuel Santamar=C3=ADa Lema * +* = * +* This program is free software; you can redistribute it and/or modify = * +* it under the terms of the GNU General Public License as published by = * +* the Free Software Foundation; either version 2 of the License, or = * +* (at your option) any later version. = * +**************************************************************************= **/ + +#include "kreallingheadersmodels.h" + +#include "kresinglecolumnproxymodel.h" +#include "backends/recipedb.h" + +#include +#include + + +KreAllIngHeadersModels::KreAllIngHeadersModels( RecipeDB * database ): + m_database( database ) +{ + + //Create models + m_sourceModel =3D new QStandardItemModel( this ); + m_ingHeaderNameModel =3D new KreSingleColumnProxyModel( 1, this ); + m_ingHeaderNameModel->setSortCaseSensitivity( Qt::CaseInsensitive ); + m_ingHeaderNameModel->setSourceModel( m_sourceModel ); + m_ingHeaderNameCompletion =3D new KCompletion; + +// //Connect signals and slots for model updating +// connect( database, SIGNAL(ingredientCreated(const KreIngredient &)), +// this, SLOT(ingredientCreatedDBSlot(const KreIngredient &)) ); +// connect( database, SIGNAL(ingredientModified(const KreIngredient &)), +// this, SLOT(ingredientModifiedDBSlot(const KreIngredient &)) ); +// connect( database, SIGNAL(ingredientRemoved(const QVariant &)), +// this, SLOT(ingredientRemovedDBSlot(const QVariant &)) ); +} + +KreAllIngHeadersModels::~KreAllIngHeadersModels() +{ + delete m_ingHeaderNameCompletion; +} + +QStandardItemModel * KreAllIngHeadersModels::sourceModel() +{ + return m_sourceModel; +} + +KreSingleColumnProxyModel * KreAllIngHeadersModels::ingHeaderNameModel() +{ + return m_ingHeaderNameModel; +} + +KCompletion * KreAllIngHeadersModels::ingHeaderNameCompletion() +{ + return m_ingHeaderNameCompletion; +} + +//void KreAllIngredientsModels::ingredientCreatedDBSlot( const KreIngredie= nt & ingredient ) +//{ +// //Prepare the id item +// QStandardItem * itemId =3D new QStandardItem; +// itemId->setData( ingredient.id(), Qt::EditRole ); +// itemId->setEditable( false ); +// +// //Prepare the name item +// QStandardItem *itemName =3D new QStandardItem( ingredient.name()= ); +// itemName->setData( ingredient.name(), Qt::EditRole ); +// itemName->setEditable( true ); +// +// //Add the new row to the source model +// QList itemList; +// itemList << itemId << itemName; +// m_sourceModel->appendRow( itemList ); +// +// //Add the item to the completion object +// m_ingredientNameCompletion->addItem( ingredient.name() ); +//} +// +//void KreAllIngredientsModels::ingredientModifiedDBSlot( const KreIngredi= ent & newIngredient ) +//{ +// int i; +// int rowCount; +// QModelIndex index; +// +// //Rename the ingredient in the source model +// QVariant id; +// QString oldName; +// rowCount =3D m_sourceModel->rowCount(); +// for ( i =3D 0; i < rowCount; ++i ) { +// index =3D m_sourceModel->index( i, 0 ); +// id =3D m_sourceModel->data( index ); +// if ( id =3D=3D newIngredient.id() ) { +// index =3D m_sourceModel->index( i, 1 ); +// oldName =3D m_sourceModel->data( index, Qt::EditRole ).toString(); +// m_sourceModel->setData( index, newIngredient.name(), Qt::EditRole ); +// break; +// } +// } +// +// //Delete the ingredient name from the KCompletion if it was unique +// QString name; +// int oldNameMatches =3D 0; +// for ( i =3D 0; i < rowCount; ++i ) { +// index =3D m_sourceModel->index( i, 1 ); +// name =3D m_sourceModel->data( index ).toString(); +// if ( name =3D=3D oldName ) { +// ++oldNameMatches; +// } +// } +// +// //If the ingredient name was unique, delete it from completion +// if ( oldNameMatches =3D=3D 0 ) { +// m_ingredientNameCompletion->removeItem( oldName ); +// } +// +// //Add the new ingredient name to completion +// m_ingredientNameCompletion->addItem( newIngredient.name() ); +// +//} +// +//void KreAllIngredientsModels::ingredientRemovedDBSlot( const QVariant & = id ) +//{ +// int i; +// int rowCount; +// QModelIndex index; +// +// //Delete the ingredient in the source model +// QVariant currentId; +// QString oldName; +// rowCount =3D m_sourceModel->rowCount(); +// for ( i =3D 0; i < rowCount; ++i ) { +// index =3D m_sourceModel->index( i, 0 ); +// currentId =3D m_sourceModel->data( index ); +// if ( currentId =3D=3D id ) { +// index =3D m_sourceModel->index( i, 1 ); +// oldName =3D m_sourceModel->data( index, Qt::EditRole ).toString(); +// m_sourceModel->takeRow( i ); +// break; +// } +// } +// +// //Delete the ingredient name from the KCompletion if it was unique +// QString name; +// int oldNameMatches =3D 0; +// for ( i =3D 0; i < rowCount; ++i ) { +// index =3D m_sourceModel->index( i, 1 ); +// name =3D m_sourceModel->data( index ).toString(); +// if ( name =3D=3D oldName ) { +// ++oldNameMatches; +// } +// } +// +// //If the ingredient name was unique, delete it from completion +// if ( oldNameMatches =3D=3D 0 ) { +// m_ingredientNameCompletion->removeItem( oldName ); +// } +// +//} diff --git a/src/models/kreallingheadersmodels.h b/src/models/kreallinghead= ersmodels.h new file mode 100644 index 0000000..1beb749 --- /dev/null +++ b/src/models/kreallingheadersmodels.h @@ -0,0 +1,45 @@ +/*************************************************************************= ** +* Copyright =C2=A9 2016 Jos=C3=A9 Manuel Santamar=C3=ADa Lema * +* = * +* This program is free software; you can redistribute it and/or modify = * +* it under the terms of the GNU General Public License as published by = * +* the Free Software Foundation; either version 2 of the License, or = * +* (at your option) any later version. = * +**************************************************************************= **/ + +#ifndef KREALLINGHEADERSMODELS_H +#define KREALLINGHEADERSMODELS_H + +#include + +class RecipeDB; +class KreSingleColumnProxyModel; +class KreIngHeader; +class KCompletion; +class QStandardItemModel; + +class KreAllIngHeadersModels: public QObject { +Q_OBJECT + +public: + KreAllIngHeadersModels( RecipeDB * database ); + ~KreAllIngHeadersModels(); + + QStandardItemModel * sourceModel(); + KreSingleColumnProxyModel * ingHeaderNameModel(); + KCompletion * ingHeaderNameCompletion(); + +//private slots: +// void ingHeaderCreatedDBSlot( const KreIngHeader & ); +// void ingHeaderModifiedDBSlot( const KreIngHeader & ); +// void ingHeaderRemovedDBSlot( const QVariant & ); + +private: + RecipeDB * m_database; + QStandardItemModel * m_sourceModel; + KreSingleColumnProxyModel * m_ingHeaderNameModel; + KCompletion * m_ingHeaderNameCompletion; + = +}; + +#endif