[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [krecipes] src/backends: Allow RecipeDB to use KreAllIngHeadersModels
From: José_Manuel_Santamaría_Lema <panfaust () gmail ! com>
Date: 2016-07-12 7:26:43
Message-ID: E1bMs5b-0000Ay-IJ () code ! kde ! org
[Download RAW message or body]
Git commit 8475c7aafb3d05f6e91a882be3574b2a5bf67c80 by José Manuel Santamaría Lema.
Committed on 12/07/2016 at 07:22.
Pushed by joselema into branch 'master'.
Allow RecipeDB to use KreAllIngHeadersModels
M +46 -0 src/backends/qsqlrecipedb.cpp
M +2 -0 src/backends/qsqlrecipedb.h
M +2 -1 src/backends/recipedb.cpp
M +6 -0 src/backends/recipedb.h
http://commits.kde.org/krecipes/8475c7aafb3d05f6e91a882be3574b2a5bf67c80
diff --git a/src/backends/qsqlrecipedb.cpp b/src/backends/qsqlrecipedb.cpp
index c30bd76..87bfa37 100644
--- a/src/backends/qsqlrecipedb.cpp
+++ b/src/backends/qsqlrecipedb.cpp
@@ -16,6 +16,7 @@
#include "datablocks/rating.h"
#include "datablocks/weight.h"
#include "models/kreallingredientsmodels.h"
+#include "models/kreallingheadersmodels.h"
#include "models/kresinglecolumnproxymodel.h"
#include "propertycalculator.h"
@@ -224,6 +225,51 @@ KreAllIngredientsModels * QSqlRecipeDB::allIngredientsModels()
return m_allIngredientsModels;
}
+void QSqlRecipeDB::loadAllIngHeadersModels()
+{
+ if ( !m_allIngHeadersModels ) {
+ m_allIngHeadersModels = new KreAllIngHeadersModels( this );
+ }
+
+ QStandardItemModel * sourceModel = m_allIngHeadersModels->sourceModel();
+ KreSingleColumnProxyModel * ingHeaderNameModel =
+ m_allIngHeadersModels->ingHeaderNameModel();
+ KCompletion * ingHeaderNameCompletion =
+ m_allIngHeadersModels->ingHeaderNameCompletion();
+
+ QSqlQuery query( "SELECT id,name FROM ingredient_groups", *database);
+ query.exec();
+
+ CHECK_QUERY(query,return;)
+
+ //Pre-allocate memory for model
+ sourceModel->setRowCount( getCount("ingredient_groups") );
+ sourceModel->setColumnCount( 2 );
+
+ int row = 0;
+ QModelIndex index;
+ while( query.next() ) {
+ index = sourceModel->index( row, 0 );
+ sourceModel->setData( index, query.value(0) );
+ index = sourceModel->index( row, 1 );
+ sourceModel->setData( index, query.value(1) );
+ ingHeaderNameCompletion->addItem( query.value(1).toString() );
+ ++row;
+ }
+
+ ingHeaderNameModel->sort(0);
+ ingHeaderNameModel->setDynamicSortFilter( true );
+}
+
+KreAllIngHeadersModels * QSqlRecipeDB::allIngHeadersModels()
+{
+ if ( !m_allIngHeadersModels ) {
+ loadAllIngHeadersModels();
+ }
+ return m_allIngHeadersModels;
+}
+
+
void QSqlRecipeDB::transaction()
{
if ( m_transactionsEnabled ) {
diff --git a/src/backends/qsqlrecipedb.h b/src/backends/qsqlrecipedb.h
index da8013d..472e812 100644
--- a/src/backends/qsqlrecipedb.h
+++ b/src/backends/qsqlrecipedb.h
@@ -97,6 +97,8 @@ public:
void loadAllIngredientsModels();
KreAllIngredientsModels * allIngredientsModels();
+ void loadAllIngHeadersModels();
+ KreAllIngHeadersModels * allIngHeadersModels();
virtual void transaction();
virtual void commit();
diff --git a/src/backends/recipedb.cpp b/src/backends/recipedb.cpp
index d36bfcd..bca2dd6 100644
--- a/src/backends/recipedb.cpp
+++ b/src/backends/recipedb.cpp
@@ -61,7 +61,8 @@ struct ingredient_nutrient_data
RecipeDB::RecipeDB() :
QObject(), m_categoryCache(0), haltOperation(false), process(NULL),
- m_allIngredientsModels(0)
+ m_allIngredientsModels(0),
+ m_allIngHeadersModels(0)
{
new KrecipesdbAdaptor( this );
QDBusConnection::sessionBus().registerObject("/KrecipesDB", this);
diff --git a/src/backends/recipedb.h b/src/backends/recipedb.h
index 945146f..2ff4599 100644
--- a/src/backends/recipedb.h
+++ b/src/backends/recipedb.h
@@ -47,6 +47,7 @@ class Weight;
typedef QList<Weight> WeightList;
class KreAllIngredientsModels;
+class KreAllIngHeadersModels;
class RecipeDB: public QObject
@@ -171,8 +172,12 @@ public:
/** Convenience method. Calls the above with arguments from KConfig. */
static RecipeDB* createDatabase();
+ //Database models, they are updated automatically on database changes
+ //via signals/slots connections between themselves and RecipeDB
virtual void loadAllIngredientsModels() = 0;
virtual KreAllIngredientsModels * allIngredientsModels() = 0;
+ virtual void loadAllIngHeadersModels() = 0;
+ virtual KreAllIngHeadersModels * allIngHeadersModels() = 0;
//FIXME: Actually this functions shouldn't be exposed here since RecipeDB is suposed
//to represent a generic database which may be not be based on SQL. Not a big problem
@@ -403,6 +408,7 @@ protected:
CategoryTree *m_categoryCache;
KreAllIngredientsModels * m_allIngredientsModels;
+ KreAllIngHeadersModels * m_allIngHeadersModels;
private:
QIODevice * m_dumpFile;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic