[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [krecipes] src/models: Update ingredient headers models with changes from the database.
From:       José_Manuel_Santamaría_Lema <panfaust () gmail ! com>
Date:       2016-07-12 9:00:40
Message-ID: E1bMtYW-0005HL-10 () code ! kde ! org
[Download RAW message or body]

Git commit 1bd488aa1dc84c9a9f26d733db8ecf0f6c5743e6 by José Manuel Santamaría Lema.
Committed on 12/07/2016 at 08:47.
Pushed by joselema into branch 'master'.

Update ingredient headers models with changes from the database.

M  +106  -108  src/models/kreallingheadersmodels.cpp
M  +4    -4    src/models/kreallingheadersmodels.h

http://commits.kde.org/krecipes/1bd488aa1dc84c9a9f26d733db8ecf0f6c5743e6

diff --git a/src/models/kreallingheadersmodels.cpp b/src/models/kreallingheadersmodels.cpp
index 27d7663..61f9c0e 100644
--- a/src/models/kreallingheadersmodels.cpp
+++ b/src/models/kreallingheadersmodels.cpp
@@ -27,13 +27,13 @@ KreAllIngHeadersModels::KreAllIngHeadersModels( RecipeDB * database ):
 	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 &)) );
+	//Connect signals and slots for model updating
+	connect( database, SIGNAL(ingHeaderCreated(const KreIngHeader &)),
+		this, SLOT(ingHeaderCreatedDBSlot(const KreIngHeader &)) );
+	connect( database, SIGNAL(ingHeaderModified(const KreIngHeader &)),
+		this, SLOT(ingHeaderModifiedDBSlot(const KreIngHeader &)) );
+	connect( database, SIGNAL(ingHeaderRemoved(const QVariant &)),
+		this, SLOT(ingHeaderRemovedDBSlot(const QVariant &)) );
 }
 
 KreAllIngHeadersModels::~KreAllIngHeadersModels()
@@ -56,104 +56,102 @@ 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 );
-//	}
-//
-//}
+void KreAllIngHeadersModels::ingHeaderCreatedDBSlot( const KreIngHeader & ingHeader )
+{
+	//Prepare the id item
+	QStandardItem * itemId = new QStandardItem;
+	itemId->setData( ingHeader.id(), Qt::EditRole );
+	itemId->setEditable( false );
+
+	//Prepare the name item
+	QStandardItem *itemName = new QStandardItem( ingHeader.name() );
+	itemName->setData( ingHeader.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_ingHeaderNameCompletion->addItem( ingHeader.name() );
+}
+
+void KreAllIngHeadersModels::ingHeaderModifiedDBSlot( const KreIngHeader & newIngHeader )
+{
+	int i;
+	int rowCount;
+	QModelIndex index;
+
+	//Rename the ingredient header 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 == newIngHeader.id() ) {
+			index = m_sourceModel->index( i, 1 );
+			oldName = m_sourceModel->data( index, Qt::EditRole ).toString();
+			m_sourceModel->setData( index, newIngHeader.name(), Qt::EditRole );
+			break;
+		}
+	}
+
+	//Delete the ingredient header 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 header name was unique, delete it from completion
+	if ( oldNameMatches == 0 ) {
+		m_ingHeaderNameCompletion->removeItem( oldName );
+	}
+
+	//Add the new ingredient header name to completion
+	m_ingHeaderNameCompletion->addItem( newIngHeader.name() );
+}
+
+void KreAllIngHeadersModels::ingHeaderRemovedDBSlot( const QVariant & id )
+{
+	int i;
+	int rowCount;
+	QModelIndex index;
+
+	//Delete the ingredient header 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 header 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 header name was unique, delete it from completion
+	if ( oldNameMatches == 0 ) {
+		m_ingHeaderNameCompletion->removeItem( oldName );
+	}
+}
diff --git a/src/models/kreallingheadersmodels.h b/src/models/kreallingheadersmodels.h
index 1beb749..237dfcb 100644
--- a/src/models/kreallingheadersmodels.h
+++ b/src/models/kreallingheadersmodels.h
@@ -29,10 +29,10 @@ public:
 	KreSingleColumnProxyModel * ingHeaderNameModel();
 	KCompletion * ingHeaderNameCompletion();
 
-//private slots:
-//	void ingHeaderCreatedDBSlot( const KreIngHeader & );
-//	void ingHeaderModifiedDBSlot( const KreIngHeader & );
-//	void ingHeaderRemovedDBSlot( const QVariant & );
+private slots:
+	void ingHeaderCreatedDBSlot( const KreIngHeader & );
+	void ingHeaderModifiedDBSlot( const KreIngHeader & );
+	void ingHeaderRemovedDBSlot( const QVariant & );
 
 private:
 	RecipeDB * m_database;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic