[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [krecipes] src: Add initial KreAllIngHeaders implementation.
From: José_Manuel_SantamarÃa_Lema <panfaust () gmail ! com>
Date: 2016-07-12 7:26:43
Message-ID: E1bMs5b-0000Ay-Gi () code ! kde ! org
[Download RAW message or body]
Git commit 06ebc09880f8e6b084091eacc89fe058dae9a857 by José Manuel SantamarÃa 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.krecipesdb.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/kreallingheadersmodels.cpp
new file mode 100644
index 0000000..27d7663
--- /dev/null
+++ b/src/models/kreallingheadersmodels.cpp
@@ -0,0 +1,159 @@
+/***************************************************************************
+* Copyright © 2016 José Manuel SantamarÃa Lema <panfaust@gail.com> *
+* *
+* 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 <KCompletion>
+#include <QStandardItemModel>
+
+
+KreAllIngHeadersModels::KreAllIngHeadersModels( RecipeDB * database ):
+ m_database( database )
+{
+
+ //Create models
+ m_sourceModel = new QStandardItemModel( this );
+ m_ingHeaderNameModel = new KreSingleColumnProxyModel( 1, this );
+ m_ingHeaderNameModel->setSortCaseSensitivity( Qt::CaseInsensitive );
+ m_ingHeaderNameModel->setSourceModel( m_sourceModel );
+ m_ingHeaderNameCompletion = 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 KreIngredient & ingredient )
+//{
+// //Prepare the id item
+// QStandardItem * itemId = new QStandardItem;
+// itemId->setData( ingredient.id(), Qt::EditRole );
+// itemId->setEditable( false );
+//
+// //Prepare the name item
+// QStandardItem *itemName = new QStandardItem( ingredient.name() );
+// itemName->setData( ingredient.name(), Qt::EditRole );
+// itemName->setEditable( true );
+//
+// //Add the new row to the source model
+// QList<QStandardItem*> itemList;
+// itemList << itemId << itemName;
+// m_sourceModel->appendRow( itemList );
+//
+// //Add the item to the completion object
+// m_ingredientNameCompletion->addItem( ingredient.name() );
+//}
+//
+//void KreAllIngredientsModels::ingredientModifiedDBSlot( const KreIngredient & newIngredient )
+//{
+// int i;
+// int rowCount;
+// QModelIndex index;
+//
+// //Rename the ingredient in the source model
+// QVariant id;
+// QString oldName;
+// rowCount = m_sourceModel->rowCount();
+// for ( i = 0; i < rowCount; ++i ) {
+// index = m_sourceModel->index( i, 0 );
+// id = m_sourceModel->data( index );
+// if ( id == newIngredient.id() ) {
+// index = m_sourceModel->index( i, 1 );
+// oldName = 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 = 0;
+// for ( i = 0; i < rowCount; ++i ) {
+// index = m_sourceModel->index( i, 1 );
+// name = m_sourceModel->data( index ).toString();
+// if ( name == oldName ) {
+// ++oldNameMatches;
+// }
+// }
+//
+// //If the ingredient name was unique, delete it from completion
+// if ( oldNameMatches == 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 = m_sourceModel->rowCount();
+// for ( i = 0; i < rowCount; ++i ) {
+// index = m_sourceModel->index( i, 0 );
+// currentId = m_sourceModel->data( index );
+// if ( currentId == id ) {
+// index = m_sourceModel->index( i, 1 );
+// oldName = 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 = 0;
+// for ( i = 0; i < rowCount; ++i ) {
+// index = m_sourceModel->index( i, 1 );
+// name = m_sourceModel->data( index ).toString();
+// if ( name == oldName ) {
+// ++oldNameMatches;
+// }
+// }
+//
+// //If the ingredient name was unique, delete it from completion
+// if ( oldNameMatches == 0 ) {
+// m_ingredientNameCompletion->removeItem( oldName );
+// }
+//
+//}
diff --git a/src/models/kreallingheadersmodels.h b/src/models/kreallingheadersmodels.h
new file mode 100644
index 0000000..1beb749
--- /dev/null
+++ b/src/models/kreallingheadersmodels.h
@@ -0,0 +1,45 @@
+/***************************************************************************
+* Copyright © 2016 José Manuel SantamarÃa Lema <panfaust@gail.com> *
+* *
+* 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 <QObject>
+
+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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic