Added template class AutoTableModel for automatic table models based on

given list of QObject derived objects.
This commit is contained in:
2015-11-02 22:25:30 +01:00
parent 7755432484
commit b7cfb8c39c
4 changed files with 109 additions and 3 deletions
+5 -2
View File
@@ -10,6 +10,7 @@
#include <odb/result.hxx>
#include "core_global.h"
#include "context.h"
template<class T>
class Service
@@ -19,13 +20,15 @@ public:
QList<QSharedPointer<T> > all() {
odb::database *db = Context::instance().db();
Q_ASSERT(db);
odb::transaction tx(db->begin());
odb::result<T> res = db->template query<T>();
QList<QSharedPointer<T> > ret;
for (typename odb::result<T>::iterator it = res.begin(); it != res.end(); it++) {
QSharedPointer<T> entity = db->template load<T>(((T)*it).getId());
ret.append(entity);
ret.append(it.load());
}
tx.commit();