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

List:       kde-commits
Subject:    [krecipes] src/backends: Add loadIngredientMaps() method
From:       José_Manuel_Santamaría_Lema <panfaust () gmail ! com>
Date:       2016-04-01 18:19:06
Message-ID: E1am3f0-0004Ph-NS () scm ! kde ! org
[Download RAW message or body]

Git commit 4884488c45692573e7ef117a01ac30077f121b87 by José Manuel Santamaría Lema.
Committed on 01/04/2016 at 15:07.
Pushed by joselema into branch 'master'.

Add loadIngredientMaps() method

M  +21   -0    src/backends/qsqlrecipedb.cpp
M  +2    -0    src/backends/qsqlrecipedb.h
M  +2    -0    src/backends/recipedb.h

http://commits.kde.org/krecipes/4884488c45692573e7ef117a01ac30077f121b87

diff --git a/src/backends/qsqlrecipedb.cpp b/src/backends/qsqlrecipedb.cpp
index 9898b85..a658eae 100644
--- a/src/backends/qsqlrecipedb.cpp
+++ b/src/backends/qsqlrecipedb.cpp
@@ -521,6 +521,27 @@ int QSqlRecipeDB::loadIngredients( ElementList *list, int limit, int offset )
 	return numberOfIngredients;
 }
 
+void QSqlRecipeDB::loadIngredientMaps( QHash<RecipeDB::IdType,Element> * idToIngredientMap,
+	QHash<QString,RecipeDB::IdType> * nameToIdMap )
+{
+	idToIngredientMap->clear();
+	nameToIdMap->clear();
+
+	QSqlQuery query;
+	query.prepare( "SELECT id,name FROM ingredients" );
+	query.exec();
+
+	CHECK_QUERY(query,return;)
+
+	while( query.next() ) {
+		Element ing;
+		ing.id = m_query->value( 0 ).toInt();
+		ing.name = unescapeAndDecode( m_query->value( 1 ).toByteArray() );
+		idToIngredientMap->insert( ing.id, ing );
+		nameToIdMap->insert( ing.name, ing.id );
+	}
+}
+
 int QSqlRecipeDB::loadPrepMethods( ElementList *list, int limit, int offset )
 {
 	list->clear();
diff --git a/src/backends/qsqlrecipedb.h b/src/backends/qsqlrecipedb.h
index a8a7698..34c78e1 100644
--- a/src/backends/qsqlrecipedb.h
+++ b/src/backends/qsqlrecipedb.h
@@ -149,6 +149,8 @@ public:
 	void loadCategories( ElementList *list, int limit = -1, int offset = 0 );
 	int loadIngredientGroups( ElementList *list );
 	int loadIngredients( ElementList *list, int limit = -1, int offset = 0 );
+	void loadIngredientMaps( QHash<RecipeDB::IdType,Element> * idToIngredientMap,
+		QHash<QString,RecipeDB::IdType> * nameToIdMap );
 	void loadPossibleUnits( int ingredientID, UnitList *list );
 	int loadPrepMethods( ElementList *list, int limit = -1, int offset = 0 );
 	// Loads the list of possible properties by default, all the ingredient
diff --git a/src/backends/recipedb.h b/src/backends/recipedb.h
index d7fb29e..eccd024 100644
--- a/src/backends/recipedb.h
+++ b/src/backends/recipedb.h
@@ -222,6 +222,8 @@ public:
 	virtual void loadCategories( ElementList *list, int limit = -1, int offset = 0 ) = 0;
 	virtual int loadIngredientGroups( ElementList *list ) = 0;
 	virtual int loadIngredients( ElementList *list, int limit = -1, int offset = 0 ) = 0;
+	virtual void loadIngredientMaps( QHash<RecipeDB::IdType,Element> * idToIngredientMap,
+		QHash<QString,RecipeDB::IdType> * nameToIdMap ) = 0;
 	virtual void loadPossibleUnits( int ingredientID, UnitList *list ) = 0;
 	virtual int loadPrepMethods( ElementList *list, int limit = -1, int offset = 0 ) = 0;
 	// Loads the list of possible properties by default, all the ingredient properties

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

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