Added template class AutoTableModel for automatic table models based on
given list of QObject derived objects.
This commit is contained in:
+5
-2
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user