first commit
This commit is contained in:
52
test/qxBlogModelView/src/author.cpp
Normal file
52
test/qxBlogModelView/src/author.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "../include/precompiled.h"
|
||||
|
||||
#include "../include/author.h"
|
||||
#include "../include/blog.h"
|
||||
|
||||
#include <QxOrm_Impl.h>
|
||||
|
||||
QX_REGISTER_CPP_QX_BLOG(author)
|
||||
|
||||
namespace qx {
|
||||
template <> void register_class(QxClass<author> & t)
|
||||
{
|
||||
t.id(& author::m_id, "author_id");
|
||||
|
||||
t.data(& author::m_name, "name");
|
||||
t.data(& author::m_birthdate, "birthdate");
|
||||
t.data(& author::m_sex, "sex");
|
||||
|
||||
t.relationOneToMany(& author::m_blogX, "list_blog", "author_id");
|
||||
|
||||
t.fct_0<int>(std::mem_fn(& author::age), "age"); // using std::mem_fn() here is just a workaround for an issue with some versions of MSVC, it is not required with a full compliant C++11 compiler (http://stackoverflow.com/questions/23778883/vs2013-stdfunction-with-member-function)
|
||||
}}
|
||||
|
||||
int author::age() const
|
||||
{
|
||||
if (! m_birthdate.isValid()) { return -1; }
|
||||
return (QDate::currentDate().year() - m_birthdate.year());
|
||||
}
|
||||
|
||||
QString author::getauthor_id() const { return m_id; }
|
||||
|
||||
QString author::getname() const { return m_name; }
|
||||
|
||||
QDate author::getbirthdate() const { return m_birthdate; }
|
||||
|
||||
author::enum_sex author::getsex() const { return m_sex; }
|
||||
|
||||
author::type_list_of_blog author::getlist_of_blog() const { return m_blogX; }
|
||||
|
||||
author::type_list_of_blog & author::list_of_blog() { return m_blogX; }
|
||||
|
||||
const author::type_list_of_blog & author::list_of_blog() const { return m_blogX; }
|
||||
|
||||
void author::setauthor_id(const QString & val) { m_id = val; }
|
||||
|
||||
void author::setname(const QString & val) { m_name = val; }
|
||||
|
||||
void author::setbirthdate(const QDate & val) { m_birthdate = val; }
|
||||
|
||||
void author::setsex(const author::enum_sex & val) { m_sex = val; }
|
||||
|
||||
void author::setlist_of_blog(const author::type_list_of_blog & val) { m_blogX = val; }
|
||||
53
test/qxBlogModelView/src/blog.cpp
Normal file
53
test/qxBlogModelView/src/blog.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "../include/precompiled.h"
|
||||
|
||||
#include "../include/blog.h"
|
||||
|
||||
#include <QxOrm_Impl.h>
|
||||
|
||||
QX_REGISTER_CPP_QX_BLOG(blog)
|
||||
|
||||
namespace qx {
|
||||
template <> void register_class(QxClass<blog> & t)
|
||||
{
|
||||
t.id(& blog::m_id, "blog_id");
|
||||
|
||||
t.data(& blog::m_title, "blog_title");
|
||||
t.data(& blog::m_text, "blog_text");
|
||||
t.data(& blog::m_dt_creation, "date_creation");
|
||||
|
||||
t.relationManyToOne(& blog::m_author, "author_id");
|
||||
t.relationOneToMany(& blog::m_commentX, "list_comment", "blog_id");
|
||||
t.relationManyToMany(& blog::m_categoryX, "list_category", "category_blog", "blog_id", "category_id");
|
||||
}}
|
||||
|
||||
long blog::getblog_id() const { return m_id; }
|
||||
|
||||
QString blog::gettitle() const { return m_title; }
|
||||
|
||||
QString blog::gettext() const { return m_text; }
|
||||
|
||||
blog::type_author blog::getauthor() const { return m_author; }
|
||||
|
||||
blog::type_list_of_comment blog::getlist_of_comment() const { return m_commentX; }
|
||||
|
||||
blog::type_list_of_comment & blog::list_of_comment() { return m_commentX; }
|
||||
|
||||
const blog::type_list_of_comment & blog::list_of_comment() const { return m_commentX; }
|
||||
|
||||
blog::type_list_of_category blog::getlist_of_category() const { return m_categoryX; }
|
||||
|
||||
blog::type_list_of_category & blog::list_of_category() { return m_categoryX; }
|
||||
|
||||
const blog::type_list_of_category & blog::list_of_category() const { return m_categoryX; }
|
||||
|
||||
void blog::setblog_id(const long & val) { m_id = val; }
|
||||
|
||||
void blog::settitle(const QString & val) { m_title = val; }
|
||||
|
||||
void blog::settext(const QString & val) { m_text = val; }
|
||||
|
||||
void blog::setauthor(const blog::type_author & val) { m_author = val; }
|
||||
|
||||
void blog::setlist_of_comment(const blog::type_list_of_comment & val) { m_commentX = val; }
|
||||
|
||||
void blog::setlist_of_category(const blog::type_list_of_category & val) { m_categoryX = val; }
|
||||
39
test/qxBlogModelView/src/category.cpp
Normal file
39
test/qxBlogModelView/src/category.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "../include/precompiled.h"
|
||||
|
||||
#include "../include/category.h"
|
||||
#include "../include/blog.h"
|
||||
|
||||
#include <QxOrm_Impl.h>
|
||||
|
||||
QX_REGISTER_CPP_QX_BLOG(category)
|
||||
|
||||
namespace qx {
|
||||
template <> void register_class(QxClass<category> & t)
|
||||
{
|
||||
t.id(& category::m_id, "category_id");
|
||||
|
||||
t.data(& category::m_name, "name");
|
||||
t.data(& category::m_desc, "description");
|
||||
|
||||
t.relationManyToMany(& category::m_blogX, "list_blog", "category_blog", "category_id", "blog_id");
|
||||
}}
|
||||
|
||||
long category::getcategory_id() const { return m_id; }
|
||||
|
||||
QString category::getname() const { return m_name; }
|
||||
|
||||
QString category::getdescription() const { return m_desc; }
|
||||
|
||||
category::type_list_of_blog category::getlist_of_blog() const { return m_blogX; }
|
||||
|
||||
category::type_list_of_blog & category::list_of_blog() { return m_blogX; }
|
||||
|
||||
const category::type_list_of_blog & category::list_of_blog() const { return m_blogX; }
|
||||
|
||||
void category::setcategory_id(const long & val) { m_id = val; }
|
||||
|
||||
void category::setname(const QString & val) { m_name = val; }
|
||||
|
||||
void category::setdescription(const QString & val) { m_desc = val; }
|
||||
|
||||
void category::setlist_of_blog(const category::type_list_of_blog & val) { m_blogX = val; }
|
||||
36
test/qxBlogModelView/src/comment.cpp
Normal file
36
test/qxBlogModelView/src/comment.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "../include/precompiled.h"
|
||||
|
||||
#include "../include/comment.h"
|
||||
#include "../include/blog.h"
|
||||
|
||||
#include <QxOrm_Impl.h>
|
||||
|
||||
QX_REGISTER_CPP_QX_BLOG(comment)
|
||||
|
||||
namespace qx {
|
||||
template <> void register_class(QxClass<comment> & t)
|
||||
{
|
||||
t.id(& comment::m_id, "comment_id");
|
||||
|
||||
t.data(& comment::m_title, "comment_title");
|
||||
t.data(& comment::m_text, "comment_text");
|
||||
t.data(& comment::m_dt_create, "date_creation");
|
||||
|
||||
t.relationManyToOne(& comment::m_blog, "blog_id");
|
||||
}}
|
||||
|
||||
long comment::getcomment_id() const { return m_id; }
|
||||
|
||||
QString comment::gettitle() const { return m_title; }
|
||||
|
||||
QString comment::gettext() const { return m_text; }
|
||||
|
||||
comment::type_blog_id comment::getblog_id() const { return m_blog; }
|
||||
|
||||
void comment::setcomment_id(const long & val) { m_id = val; }
|
||||
|
||||
void comment::settitle(const QString & val) { m_title = val; }
|
||||
|
||||
void comment::settext(const QString & val) { m_text = val; }
|
||||
|
||||
void comment::setblog_id(const comment::type_blog_id & val) { m_blog = val; }
|
||||
325
test/qxBlogModelView/src/main.cpp
Normal file
325
test/qxBlogModelView/src/main.cpp
Normal file
@@ -0,0 +1,325 @@
|
||||
#include "../include/precompiled.h"
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
#include <QtWidgets/qapplication.h>
|
||||
#include <QtWidgets/qtableview.h>
|
||||
#include <QtQuick/qquickview.h>
|
||||
#include <QtQml/qqmlcontext.h>
|
||||
#else // (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
#include <QtGui/qapplication.h>
|
||||
#include <QtGui/qtableview.h>
|
||||
#include <QtDeclarative/qdeclarativeview.h>
|
||||
#include <QtDeclarative/qdeclarativecontext.h>
|
||||
#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
|
||||
#include "../include/blog.h"
|
||||
#include "../include/author.h"
|
||||
#include "../include/comment.h"
|
||||
#include "../include/category.h"
|
||||
|
||||
#include "../include/model_view_from_qxee/blog.model_view.gen.h"
|
||||
|
||||
#include <QxOrm_Impl.h>
|
||||
|
||||
void init_data();
|
||||
void test_qt_widget();
|
||||
void test_qml_view();
|
||||
void test_qml_view_with_relationship();
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
init_data();
|
||||
test_qt_widget();
|
||||
test_qml_view();
|
||||
test_qml_view_with_relationship();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void init_data()
|
||||
{
|
||||
QFile::remove("./qxBlog.sqlite");
|
||||
|
||||
// Parameters to connect to database
|
||||
qx::QxSqlDatabase::getSingleton()->setDriverName("QSQLITE");
|
||||
qx::QxSqlDatabase::getSingleton()->setDatabaseName("./qxBlog.sqlite");
|
||||
qx::QxSqlDatabase::getSingleton()->setHostName("localhost");
|
||||
qx::QxSqlDatabase::getSingleton()->setUserName("root");
|
||||
qx::QxSqlDatabase::getSingleton()->setPassword("");
|
||||
|
||||
// Only for debug purpose : assert if invalid offset detected fetching a relation
|
||||
qx::QxSqlDatabase::getSingleton()->setVerifyOffsetRelation(true);
|
||||
|
||||
// Create all tables in database
|
||||
QSqlError daoError = qx::dao::create_table<author>();
|
||||
daoError = qx::dao::create_table<comment>();
|
||||
daoError = qx::dao::create_table<category>();
|
||||
daoError = qx::dao::create_table<blog>();
|
||||
|
||||
// Create a list of 3 author
|
||||
author_ptr author_1; author_1.reset(new author());
|
||||
author_ptr author_2; author_2.reset(new author());
|
||||
author_ptr author_3; author_3.reset(new author());
|
||||
|
||||
author_1->m_id = "author_id_1"; author_1->m_name = "author_1";
|
||||
author_1->m_sex = author::male; author_1->m_birthdate = QDate::currentDate();
|
||||
author_2->m_id = "author_id_2"; author_2->m_name = "author_2";
|
||||
author_2->m_sex = author::female; author_2->m_birthdate = QDate::currentDate();
|
||||
author_3->m_id = "author_id_3"; author_3->m_name = "author_3";
|
||||
author_3->m_sex = author::female; author_3->m_birthdate = QDate::currentDate();
|
||||
|
||||
list_author authorX;
|
||||
authorX.insert(author_1->m_id, author_1);
|
||||
authorX.insert(author_2->m_id, author_2);
|
||||
authorX.insert(author_3->m_id, author_3);
|
||||
|
||||
// Insert list of 3 author into database
|
||||
daoError = qx::dao::insert(authorX);
|
||||
qAssert(qx::dao::count<author>() == 3);
|
||||
|
||||
// Clone author 2 : 'author_id_2'
|
||||
author_ptr author_clone = qx::clone(* author_2);
|
||||
qAssert(author_clone->m_id == "author_id_2");
|
||||
qAssert(author_clone->m_sex == author::female);
|
||||
|
||||
// Create a query to fetch only female author : 'author_id_2' and 'author_id_3'
|
||||
qx::QxSqlQuery query("WHERE author.sex = :sex");
|
||||
query.bind(":sex", author::female);
|
||||
|
||||
list_author list_of_female_author;
|
||||
daoError = qx::dao::fetch_by_query(query, list_of_female_author);
|
||||
qAssert(list_of_female_author.count() == 2);
|
||||
|
||||
// Dump list of female author (xml serialization)
|
||||
qx::dump(list_of_female_author);
|
||||
|
||||
// Create 3 categories
|
||||
category_ptr category_1 = category_ptr(new category());
|
||||
category_ptr category_2 = category_ptr(new category());
|
||||
category_ptr category_3 = category_ptr(new category());
|
||||
|
||||
category_1->m_name = "category_1"; category_1->m_desc = "desc_1";
|
||||
category_2->m_name = "category_2"; category_2->m_desc = "desc_2";
|
||||
category_3->m_name = "category_3"; category_3->m_desc = "desc_3";
|
||||
|
||||
{ // Create a scope to destroy temporary connexion to database
|
||||
|
||||
// Open a transaction to database
|
||||
QSqlDatabase db = qx::QxSqlDatabase::getDatabase();
|
||||
bool bCommit = db.transaction();
|
||||
|
||||
// Insert 3 categories into database, use 'db' parameter for the transaction
|
||||
daoError = qx::dao::insert(category_1, (& db)); bCommit = (bCommit && ! daoError.isValid());
|
||||
daoError = qx::dao::insert(category_2, (& db)); bCommit = (bCommit && ! daoError.isValid());
|
||||
daoError = qx::dao::insert(category_3, (& db)); bCommit = (bCommit && ! daoError.isValid());
|
||||
|
||||
qAssert(bCommit);
|
||||
qAssert(category_1->m_id != 0);
|
||||
qAssert(category_2->m_id != 0);
|
||||
qAssert(category_3->m_id != 0);
|
||||
|
||||
// Terminate transaction => commit or rollback if there is error
|
||||
if (bCommit) { db.commit(); }
|
||||
else { db.rollback(); }
|
||||
|
||||
} // End of scope : 'db' is destroyed
|
||||
|
||||
// Create a blog with the class name (factory)
|
||||
qx::any blog_any = qx::create("blog");
|
||||
blog_ptr blog_1;
|
||||
try { blog_1 = qx::any_cast<blog_ptr>(blog_any); }
|
||||
catch (...) { blog_1.reset(new blog()); }
|
||||
blog_1->m_text = "blog_text_1";
|
||||
blog_1->m_dt_creation = QDateTime::currentDateTime();
|
||||
blog_1->m_author = author_1;
|
||||
|
||||
// Insert 'blog_1' into database with 'save()' method
|
||||
daoError = qx::dao::save(blog_1);
|
||||
|
||||
// Modify 'blog_1' properties and save into database
|
||||
blog_1->m_text = "update blog_text_1";
|
||||
blog_1->m_author = author_2;
|
||||
daoError = qx::dao::save(blog_1);
|
||||
|
||||
// Add 2 comments to 'blog_1'
|
||||
comment_ptr comment_1; comment_1.reset(new comment());
|
||||
comment_ptr comment_2; comment_2.reset(new comment());
|
||||
|
||||
comment_1->m_text = "comment_1 text";
|
||||
comment_1->m_dt_create = QDateTime::currentDateTime();
|
||||
comment_1->m_blog = blog_1;
|
||||
comment_2->m_text = "comment_2 text";
|
||||
comment_2->m_dt_create = QDateTime::currentDateTime();
|
||||
comment_2->m_blog = blog_1;
|
||||
|
||||
daoError = qx::dao::insert(comment_1);
|
||||
daoError = qx::dao::insert(comment_2);
|
||||
qAssert(qx::dao::count<comment>() == 2);
|
||||
|
||||
// Add 2 categories to 'blog_1' => must insert into extra-table 'category_blog'
|
||||
blog_1->m_categoryX.insert(category_1->m_id, category_1);
|
||||
blog_1->m_categoryX.insert(category_3->m_id, category_3);
|
||||
daoError = qx::dao::save_with_relation("list_category", blog_1);
|
||||
|
||||
// Fetch blog into a new variable with all relation : 'author', 'comment' and 'category'
|
||||
blog_ptr blog_tmp; blog_tmp.reset(new blog());
|
||||
blog_tmp->m_id = blog_1->m_id;
|
||||
daoError = qx::dao::fetch_by_id_with_all_relation(blog_tmp);
|
||||
|
||||
qAssert(blog_tmp->m_commentX.count() == 2);
|
||||
qAssert(blog_tmp->m_categoryX.count() == 2);
|
||||
qAssert(blog_tmp->m_text == "update blog_text_1");
|
||||
qAssert(blog_tmp->m_author && blog_tmp->m_author->m_id == "author_id_2");
|
||||
|
||||
// Fetch blog into a new variable with many relations using "*->*->*->*" (4 levels of relationships)
|
||||
blog_tmp.reset(new blog());
|
||||
blog_tmp->m_id = blog_1->m_id;
|
||||
daoError = qx::dao::fetch_by_id_with_relation("*->*->*->*", blog_tmp);
|
||||
|
||||
qAssert(blog_tmp->m_commentX.count() == 2);
|
||||
qAssert(blog_tmp->m_categoryX.count() == 2);
|
||||
qAssert(blog_tmp->m_text == "update blog_text_1");
|
||||
qAssert(blog_tmp->m_author && blog_tmp->m_author->m_id == "author_id_2");
|
||||
|
||||
// Dump 'blog_tmp' result from database (xml serialization)
|
||||
qx::dump(blog_tmp);
|
||||
|
||||
// Check qx::dao::save_with_relation_recursive() function
|
||||
daoError = qx::dao::save_with_relation_recursive(blog_tmp);
|
||||
qAssert(! daoError.isValid());
|
||||
daoError = qx::dao::save_with_relation_recursive(blog_tmp, qx::dao::save_mode::e_update_only);
|
||||
qAssert(! daoError.isValid());
|
||||
|
||||
// Call 'age()' method with class name and method name (reflexion)
|
||||
qx_bool bInvokeOk = qx::QxClassX::invoke("author", "age", author_1);
|
||||
qAssert(bInvokeOk);
|
||||
|
||||
// Test 'isDirty()' method
|
||||
qx::dao::ptr<blog> blog_isdirty = qx::dao::ptr<blog>(new blog());
|
||||
blog_isdirty->m_id = blog_1->m_id;
|
||||
daoError = qx::dao::fetch_by_id(blog_isdirty);
|
||||
qAssert(! daoError.isValid() && ! blog_isdirty.isDirty());
|
||||
|
||||
blog_isdirty->m_text = "blog property 'text' modified => blog is dirty !!!";
|
||||
QStringList lstDiff; bool bDirty = blog_isdirty.isDirty(lstDiff);
|
||||
qAssert(bDirty && (lstDiff.count() == 1) && (lstDiff.at(0) == "blog_text"));
|
||||
if (bDirty) { qDebug("[QxOrm] test dirty 1 : blog is dirty => '%s'", qPrintable(lstDiff.join("|"))); }
|
||||
|
||||
// Update only property 'm_text' of 'blog_isdirty'
|
||||
daoError = qx::dao::update_optimized(blog_isdirty);
|
||||
qAssert(! daoError.isValid() && ! blog_isdirty.isDirty());
|
||||
qx::dump(blog_isdirty);
|
||||
|
||||
// Test 'isDirty()' method with a container
|
||||
typedef qx::dao::ptr< QList<author_ptr> > type_lst_author_test_is_dirty;
|
||||
type_lst_author_test_is_dirty container_isdirty = type_lst_author_test_is_dirty(new QList<author_ptr>());
|
||||
daoError = qx::dao::fetch_all(container_isdirty);
|
||||
qAssert(! daoError.isValid() && ! container_isdirty.isDirty() && (container_isdirty->count() == 3));
|
||||
|
||||
author_ptr author_ptr_dirty = container_isdirty->at(1);
|
||||
author_ptr_dirty->m_name = "author name modified at index 1 => container is dirty !!!";
|
||||
bDirty = container_isdirty.isDirty(lstDiff);
|
||||
qAssert(bDirty && (lstDiff.count() == 1));
|
||||
if (bDirty) { qDebug("[QxOrm] test dirty 2 : container is dirty => '%s'", qPrintable(lstDiff.join("|"))); }
|
||||
|
||||
author_ptr_dirty = container_isdirty->at(2);
|
||||
author_ptr_dirty->m_birthdate = QDate(1998, 03, 06);
|
||||
bDirty = container_isdirty.isDirty(lstDiff);
|
||||
qAssert(bDirty && (lstDiff.count() == 2));
|
||||
if (bDirty) { qDebug("[QxOrm] test dirty 3 : container is dirty => '%s'", qPrintable(lstDiff.join("|"))); }
|
||||
|
||||
// Update only property 'm_name' at position 1, only property 'm_birthdate' at position 2 and nothing at position 0
|
||||
daoError = qx::dao::update_optimized(container_isdirty);
|
||||
qAssert(! daoError.isValid() && ! container_isdirty.isDirty());
|
||||
qx::dump(container_isdirty);
|
||||
|
||||
// Fetch only property 'm_dt_creation' of blog
|
||||
QStringList lstColumns = QStringList() << "date_creation";
|
||||
list_blog lst_blog_with_only_date_creation;
|
||||
daoError = qx::dao::fetch_all(lst_blog_with_only_date_creation, NULL, lstColumns);
|
||||
qAssert(! daoError.isValid() && (lst_blog_with_only_date_creation.size() > 0));
|
||||
if ((lst_blog_with_only_date_creation.size() > 0) && (lst_blog_with_only_date_creation[0].get() != NULL))
|
||||
{ qAssert(lst_blog_with_only_date_creation[0]->m_text.isEmpty()); }
|
||||
qx::dump(lst_blog_with_only_date_creation);
|
||||
|
||||
// Dump all registered classes into QxOrm context (introspection engine)
|
||||
qx::QxClassX::dumpAllClasses();
|
||||
|
||||
// Call a custom SQL query or a stored procedure
|
||||
qx_query testStoredProc("SELECT * FROM author");
|
||||
daoError = qx::dao::call_query(testStoredProc);
|
||||
qAssert(! daoError.isValid());
|
||||
testStoredProc.dumpSqlResult();
|
||||
|
||||
// Call a custom SQL query or a stored procedure and fetch automatically properties (with a collection of items)
|
||||
qx_query testStoredProcBis("SELECT * FROM author");
|
||||
authorX.clear();
|
||||
daoError = qx::dao::execute_query(testStoredProcBis, authorX);
|
||||
qAssert(! daoError.isValid()); qAssert(authorX.count() > 0);
|
||||
qx::dump(authorX);
|
||||
|
||||
// Call a custom SQL query or a stored procedure and fetch automatically properties
|
||||
qx_query testStoredProcThird("SELECT name, category_id FROM category");
|
||||
category_ptr category_tmp = category_ptr(new category());
|
||||
daoError = qx::dao::execute_query(testStoredProcThird, category_tmp);
|
||||
qAssert(! daoError.isValid()); qAssert(category_tmp->m_id != 0);
|
||||
qx::dump(category_tmp);
|
||||
|
||||
// Just to test compilation of nested models
|
||||
qx::IxModel * pNestedModel1 = qx::model_view::create_nested_model(NULL, QModelIndex(), category_tmp); Q_UNUSED(pNestedModel1);
|
||||
qx::IxModel * pNestedModel2 = qx::model_view::create_nested_model(NULL, QModelIndex(), authorX); Q_UNUSED(pNestedModel2);
|
||||
}
|
||||
|
||||
void test_qt_widget()
|
||||
{
|
||||
qx::IxModel * pModel = new qx::QxModel<author>();
|
||||
pModel->qxFetchAll();
|
||||
|
||||
QTableView tableView;
|
||||
tableView.setModel(pModel);
|
||||
tableView.setSortingEnabled(true);
|
||||
tableView.show();
|
||||
qApp->exec();
|
||||
}
|
||||
|
||||
void test_qml_view()
|
||||
{
|
||||
qx::IxModel * pModel = new qx::QxModel<author>();
|
||||
pModel->qxFetchAll();
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
QQuickView qmlView;
|
||||
QString sQmlFile = "qrc:/documents/main_qt6.qml";
|
||||
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
QQuickView qmlView;
|
||||
QString sQmlFile = "qrc:/documents/main.qml";
|
||||
#else // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
QDeclarativeView qmlView;
|
||||
QString sQmlFile = "qrc:/documents/main_qt4.qml";
|
||||
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
|
||||
qmlView.rootContext()->setContextProperty("myModel", pModel);
|
||||
qmlView.setSource(QUrl(sQmlFile));
|
||||
qmlView.show();
|
||||
qApp->exec();
|
||||
}
|
||||
|
||||
void test_qml_view_with_relationship()
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
qx::IxModel * pModel = new model_view::blog_model();
|
||||
pModel->qxFetchAll(QStringList() << "*");
|
||||
|
||||
QQuickView qmlView;
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
QString sQmlFile = "qrc:/documents/main_relationship_qt6.qml";
|
||||
#else // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
QString sQmlFile = "qrc:/documents/main_relationship.qml";
|
||||
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
|
||||
qmlView.rootContext()->setContextProperty("myModel", pModel);
|
||||
qmlView.setSource(QUrl(sQmlFile));
|
||||
qmlView.show();
|
||||
qApp->exec();
|
||||
#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/************************************************************************************************
|
||||
** File created by QxEntityEditor 1.1.9 (2016/05/04 10:05) : please, do NOT modify this file ! **
|
||||
************************************************************************************************/
|
||||
|
||||
#include "../../include/precompiled.h"
|
||||
|
||||
#include "../../include/model_view_from_qxee/author.model_view.gen.h"
|
||||
#include "../../include/model_view_from_qxee/blog.model_view.gen.h"
|
||||
|
||||
#include <QxMemLeak.h>
|
||||
|
||||
namespace model_view {
|
||||
|
||||
author_model::author_model(QObject * parent /* = 0 */) : author_model_base_class(parent) { ; }
|
||||
|
||||
author_model::author_model(qx::IxModel * other, QObject * parent) : author_model_base_class(other, parent) { ; }
|
||||
|
||||
author_model::~author_model() { ; }
|
||||
|
||||
QObject * author_model::list_of_blog(int row, bool bLoadFromDatabase /* = false */, const QString & sAppendRelations /* = QString() */)
|
||||
{
|
||||
QString sRelation = "list_blog";
|
||||
qx::IxModel * pChild = (bLoadFromDatabase ? NULL : this->getChild(row, sRelation));
|
||||
if (pChild) { return static_cast<QObject *>(pChild); }
|
||||
|
||||
if ((row < 0) || (row >= this->m_model.count())) { qAssert(false); return NULL; }
|
||||
author_model_base_class::type_ptr ptr = this->m_model.getByIndex(row);
|
||||
if (! ptr) { qAssert(false); return NULL; }
|
||||
QString id = ptr->getauthor_id();
|
||||
author::type_list_of_blog value = ptr->getlist_of_blog();
|
||||
|
||||
if (bLoadFromDatabase)
|
||||
{
|
||||
if (! sAppendRelations.isEmpty() && ! sAppendRelations.startsWith("->") && ! sAppendRelations.startsWith(">>")) { sRelation += "->" + sAppendRelations; }
|
||||
else if (! sAppendRelations.isEmpty()) { sRelation += sAppendRelations; }
|
||||
author tmp;
|
||||
tmp.setauthor_id(id);
|
||||
this->m_lastError = qx::dao::fetch_by_id_with_relation(sRelation, tmp);
|
||||
if (this->m_lastError.isValid()) { return NULL; }
|
||||
value = tmp.getlist_of_blog();
|
||||
ptr->setlist_of_blog(value);
|
||||
}
|
||||
|
||||
model_view::blog_model * pNewChild = NULL;
|
||||
pChild = qx::model_view::create_nested_model_with_type(this, QModelIndex(), value, pNewChild);
|
||||
if (pChild) { this->insertChild(row, "list_blog", pChild); }
|
||||
return static_cast<QObject *>(pChild);
|
||||
}
|
||||
|
||||
void author_model::syncNestedModel(int row, const QStringList & relation)
|
||||
{
|
||||
Q_UNUSED(relation);
|
||||
qx::IxModel * pNestedModel = NULL;
|
||||
if ((row < 0) || (row >= this->m_model.count())) { return; }
|
||||
author_model_base_class::type_ptr ptr = this->m_model.getByIndex(row);
|
||||
if (! ptr) { return; }
|
||||
|
||||
pNestedModel = this->getChild(row, "list_blog");
|
||||
if (pNestedModel)
|
||||
{
|
||||
this->syncNestedModelRecursive(pNestedModel, relation);
|
||||
author::type_list_of_blog value;
|
||||
qx::model_view::sync_nested_model(pNestedModel, value);
|
||||
ptr->setlist_of_blog(value);
|
||||
}
|
||||
}
|
||||
|
||||
void author_model::syncAllNestedModel(const QStringList & relation)
|
||||
{
|
||||
if (this->m_lstChild.count() <= 0) { return; }
|
||||
for (long l = 0; l < this->m_model.count(); l++)
|
||||
{ this->syncNestedModel(static_cast<int>(l), relation); }
|
||||
}
|
||||
|
||||
} // namespace model_view
|
||||
@@ -0,0 +1,155 @@
|
||||
/************************************************************************************************
|
||||
** File created by QxEntityEditor 1.1.9 (2016/05/04 10:05) : please, do NOT modify this file ! **
|
||||
************************************************************************************************/
|
||||
|
||||
#include "../../include/precompiled.h"
|
||||
|
||||
#include "../../include/model_view_from_qxee/blog.model_view.gen.h"
|
||||
#include "../../include/model_view_from_qxee/author.model_view.gen.h"
|
||||
#include "../../include/model_view_from_qxee/comment.model_view.gen.h"
|
||||
#include "../../include/model_view_from_qxee/category.model_view.gen.h"
|
||||
|
||||
#include <QxMemLeak.h>
|
||||
|
||||
namespace model_view {
|
||||
|
||||
blog_model::blog_model(QObject * parent /* = 0 */) : blog_model_base_class(parent) { ; }
|
||||
|
||||
blog_model::blog_model(qx::IxModel * other, QObject * parent) : blog_model_base_class(other, parent) { ; }
|
||||
|
||||
blog_model::~blog_model() { ; }
|
||||
|
||||
QObject * blog_model::author_id(int row, bool bLoadFromDatabase /* = false */, const QString & sAppendRelations /* = QString() */)
|
||||
{
|
||||
QString sRelation = "author_id";
|
||||
qx::IxModel * pChild = (bLoadFromDatabase ? NULL : this->getChild(row, sRelation));
|
||||
if (pChild) { return static_cast<QObject *>(pChild); }
|
||||
|
||||
if ((row < 0) || (row >= this->m_model.count())) { qAssert(false); return NULL; }
|
||||
blog_model_base_class::type_ptr ptr = this->m_model.getByIndex(row);
|
||||
if (! ptr) { qAssert(false); return NULL; }
|
||||
long id = ptr->getblog_id();
|
||||
blog::type_author value = ptr->getauthor();
|
||||
|
||||
if (bLoadFromDatabase)
|
||||
{
|
||||
if (! sAppendRelations.isEmpty() && ! sAppendRelations.startsWith("->") && ! sAppendRelations.startsWith(">>")) { sRelation += "->" + sAppendRelations; }
|
||||
else if (! sAppendRelations.isEmpty()) { sRelation += sAppendRelations; }
|
||||
blog tmp;
|
||||
tmp.setblog_id(id);
|
||||
this->m_lastError = qx::dao::fetch_by_id_with_relation(sRelation, tmp);
|
||||
if (this->m_lastError.isValid()) { return NULL; }
|
||||
value = tmp.getauthor();
|
||||
ptr->setauthor(value);
|
||||
}
|
||||
|
||||
model_view::author_model * pNewChild = NULL;
|
||||
pChild = qx::model_view::create_nested_model_with_type(this, QModelIndex(), value, pNewChild);
|
||||
if (pChild) { this->insertChild(row, "author_id", pChild); }
|
||||
return static_cast<QObject *>(pChild);
|
||||
}
|
||||
|
||||
QObject * blog_model::list_of_comment(int row, bool bLoadFromDatabase /* = false */, const QString & sAppendRelations /* = QString() */)
|
||||
{
|
||||
QString sRelation = "list_comment";
|
||||
qx::IxModel * pChild = (bLoadFromDatabase ? NULL : this->getChild(row, sRelation));
|
||||
if (pChild) { return static_cast<QObject *>(pChild); }
|
||||
|
||||
if ((row < 0) || (row >= this->m_model.count())) { qAssert(false); return NULL; }
|
||||
blog_model_base_class::type_ptr ptr = this->m_model.getByIndex(row);
|
||||
if (! ptr) { qAssert(false); return NULL; }
|
||||
long id = ptr->getblog_id();
|
||||
blog::type_list_of_comment value = ptr->getlist_of_comment();
|
||||
|
||||
if (bLoadFromDatabase)
|
||||
{
|
||||
if (! sAppendRelations.isEmpty() && ! sAppendRelations.startsWith("->") && ! sAppendRelations.startsWith(">>")) { sRelation += "->" + sAppendRelations; }
|
||||
else if (! sAppendRelations.isEmpty()) { sRelation += sAppendRelations; }
|
||||
blog tmp;
|
||||
tmp.setblog_id(id);
|
||||
this->m_lastError = qx::dao::fetch_by_id_with_relation(sRelation, tmp);
|
||||
if (this->m_lastError.isValid()) { return NULL; }
|
||||
value = tmp.getlist_of_comment();
|
||||
ptr->setlist_of_comment(value);
|
||||
}
|
||||
|
||||
model_view::comment_model * pNewChild = NULL;
|
||||
pChild = qx::model_view::create_nested_model_with_type(this, QModelIndex(), value, pNewChild);
|
||||
if (pChild) { this->insertChild(row, "list_comment", pChild); }
|
||||
return static_cast<QObject *>(pChild);
|
||||
}
|
||||
|
||||
QObject * blog_model::list_of_category(int row, bool bLoadFromDatabase /* = false */, const QString & sAppendRelations /* = QString() */)
|
||||
{
|
||||
QString sRelation = "list_category";
|
||||
qx::IxModel * pChild = (bLoadFromDatabase ? NULL : this->getChild(row, sRelation));
|
||||
if (pChild) { return static_cast<QObject *>(pChild); }
|
||||
|
||||
if ((row < 0) || (row >= this->m_model.count())) { qAssert(false); return NULL; }
|
||||
blog_model_base_class::type_ptr ptr = this->m_model.getByIndex(row);
|
||||
if (! ptr) { qAssert(false); return NULL; }
|
||||
long id = ptr->getblog_id();
|
||||
blog::type_list_of_category value = ptr->getlist_of_category();
|
||||
|
||||
if (bLoadFromDatabase)
|
||||
{
|
||||
if (! sAppendRelations.isEmpty() && ! sAppendRelations.startsWith("->") && ! sAppendRelations.startsWith(">>")) { sRelation += "->" + sAppendRelations; }
|
||||
else if (! sAppendRelations.isEmpty()) { sRelation += sAppendRelations; }
|
||||
blog tmp;
|
||||
tmp.setblog_id(id);
|
||||
this->m_lastError = qx::dao::fetch_by_id_with_relation(sRelation, tmp);
|
||||
if (this->m_lastError.isValid()) { return NULL; }
|
||||
value = tmp.getlist_of_category();
|
||||
ptr->setlist_of_category(value);
|
||||
}
|
||||
|
||||
model_view::category_model * pNewChild = NULL;
|
||||
pChild = qx::model_view::create_nested_model_with_type(this, QModelIndex(), value, pNewChild);
|
||||
if (pChild) { this->insertChild(row, "list_category", pChild); }
|
||||
return static_cast<QObject *>(pChild);
|
||||
}
|
||||
|
||||
void blog_model::syncNestedModel(int row, const QStringList & relation)
|
||||
{
|
||||
Q_UNUSED(relation);
|
||||
qx::IxModel * pNestedModel = NULL;
|
||||
if ((row < 0) || (row >= this->m_model.count())) { return; }
|
||||
blog_model_base_class::type_ptr ptr = this->m_model.getByIndex(row);
|
||||
if (! ptr) { return; }
|
||||
|
||||
pNestedModel = this->getChild(row, "author_id");
|
||||
if (pNestedModel)
|
||||
{
|
||||
this->syncNestedModelRecursive(pNestedModel, relation);
|
||||
blog::type_author value;
|
||||
qx::model_view::sync_nested_model(pNestedModel, value);
|
||||
ptr->setauthor(value);
|
||||
}
|
||||
|
||||
pNestedModel = this->getChild(row, "list_comment");
|
||||
if (pNestedModel)
|
||||
{
|
||||
this->syncNestedModelRecursive(pNestedModel, relation);
|
||||
blog::type_list_of_comment value;
|
||||
qx::model_view::sync_nested_model(pNestedModel, value);
|
||||
ptr->setlist_of_comment(value);
|
||||
}
|
||||
|
||||
pNestedModel = this->getChild(row, "list_category");
|
||||
if (pNestedModel)
|
||||
{
|
||||
this->syncNestedModelRecursive(pNestedModel, relation);
|
||||
blog::type_list_of_category value;
|
||||
qx::model_view::sync_nested_model(pNestedModel, value);
|
||||
ptr->setlist_of_category(value);
|
||||
}
|
||||
}
|
||||
|
||||
void blog_model::syncAllNestedModel(const QStringList & relation)
|
||||
{
|
||||
if (this->m_lstChild.count() <= 0) { return; }
|
||||
for (long l = 0; l < this->m_model.count(); l++)
|
||||
{ this->syncNestedModel(static_cast<int>(l), relation); }
|
||||
}
|
||||
|
||||
} // namespace model_view
|
||||
@@ -0,0 +1,75 @@
|
||||
/************************************************************************************************
|
||||
** File created by QxEntityEditor 1.1.9 (2016/05/04 10:05) : please, do NOT modify this file ! **
|
||||
************************************************************************************************/
|
||||
|
||||
#include "../../include/precompiled.h"
|
||||
|
||||
#include "../../include/model_view_from_qxee/category.model_view.gen.h"
|
||||
#include "../../include/model_view_from_qxee/blog.model_view.gen.h"
|
||||
|
||||
#include <QxMemLeak.h>
|
||||
|
||||
namespace model_view {
|
||||
|
||||
category_model::category_model(QObject * parent /* = 0 */) : category_model_base_class(parent) { ; }
|
||||
|
||||
category_model::category_model(qx::IxModel * other, QObject * parent) : category_model_base_class(other, parent) { ; }
|
||||
|
||||
category_model::~category_model() { ; }
|
||||
|
||||
QObject * category_model::list_of_blog(int row, bool bLoadFromDatabase /* = false */, const QString & sAppendRelations /* = QString() */)
|
||||
{
|
||||
QString sRelation = "list_blog";
|
||||
qx::IxModel * pChild = (bLoadFromDatabase ? NULL : this->getChild(row, sRelation));
|
||||
if (pChild) { return static_cast<QObject *>(pChild); }
|
||||
|
||||
if ((row < 0) || (row >= this->m_model.count())) { qAssert(false); return NULL; }
|
||||
category_model_base_class::type_ptr ptr = this->m_model.getByIndex(row);
|
||||
if (! ptr) { qAssert(false); return NULL; }
|
||||
long id = ptr->getcategory_id();
|
||||
category::type_list_of_blog value = ptr->getlist_of_blog();
|
||||
|
||||
if (bLoadFromDatabase)
|
||||
{
|
||||
if (! sAppendRelations.isEmpty() && ! sAppendRelations.startsWith("->") && ! sAppendRelations.startsWith(">>")) { sRelation += "->" + sAppendRelations; }
|
||||
else if (! sAppendRelations.isEmpty()) { sRelation += sAppendRelations; }
|
||||
category tmp;
|
||||
tmp.setcategory_id(id);
|
||||
this->m_lastError = qx::dao::fetch_by_id_with_relation(sRelation, tmp);
|
||||
if (this->m_lastError.isValid()) { return NULL; }
|
||||
value = tmp.getlist_of_blog();
|
||||
ptr->setlist_of_blog(value);
|
||||
}
|
||||
|
||||
model_view::blog_model * pNewChild = NULL;
|
||||
pChild = qx::model_view::create_nested_model_with_type(this, QModelIndex(), value, pNewChild);
|
||||
if (pChild) { this->insertChild(row, "list_blog", pChild); }
|
||||
return static_cast<QObject *>(pChild);
|
||||
}
|
||||
|
||||
void category_model::syncNestedModel(int row, const QStringList & relation)
|
||||
{
|
||||
Q_UNUSED(relation);
|
||||
qx::IxModel * pNestedModel = NULL;
|
||||
if ((row < 0) || (row >= this->m_model.count())) { return; }
|
||||
category_model_base_class::type_ptr ptr = this->m_model.getByIndex(row);
|
||||
if (! ptr) { return; }
|
||||
|
||||
pNestedModel = this->getChild(row, "list_blog");
|
||||
if (pNestedModel)
|
||||
{
|
||||
this->syncNestedModelRecursive(pNestedModel, relation);
|
||||
category::type_list_of_blog value;
|
||||
qx::model_view::sync_nested_model(pNestedModel, value);
|
||||
ptr->setlist_of_blog(value);
|
||||
}
|
||||
}
|
||||
|
||||
void category_model::syncAllNestedModel(const QStringList & relation)
|
||||
{
|
||||
if (this->m_lstChild.count() <= 0) { return; }
|
||||
for (long l = 0; l < this->m_model.count(); l++)
|
||||
{ this->syncNestedModel(static_cast<int>(l), relation); }
|
||||
}
|
||||
|
||||
} // namespace model_view
|
||||
@@ -0,0 +1,75 @@
|
||||
/************************************************************************************************
|
||||
** File created by QxEntityEditor 1.1.9 (2016/05/04 10:05) : please, do NOT modify this file ! **
|
||||
************************************************************************************************/
|
||||
|
||||
#include "../../include/precompiled.h"
|
||||
|
||||
#include "../../include/model_view_from_qxee/comment.model_view.gen.h"
|
||||
#include "../../include/model_view_from_qxee/blog.model_view.gen.h"
|
||||
|
||||
#include <QxMemLeak.h>
|
||||
|
||||
namespace model_view {
|
||||
|
||||
comment_model::comment_model(QObject * parent /* = 0 */) : comment_model_base_class(parent) { ; }
|
||||
|
||||
comment_model::comment_model(qx::IxModel * other, QObject * parent) : comment_model_base_class(other, parent) { ; }
|
||||
|
||||
comment_model::~comment_model() { ; }
|
||||
|
||||
QObject * comment_model::blog_id(int row, bool bLoadFromDatabase /* = false */, const QString & sAppendRelations /* = QString() */)
|
||||
{
|
||||
QString sRelation = "blog_id";
|
||||
qx::IxModel * pChild = (bLoadFromDatabase ? NULL : this->getChild(row, sRelation));
|
||||
if (pChild) { return static_cast<QObject *>(pChild); }
|
||||
|
||||
if ((row < 0) || (row >= this->m_model.count())) { qAssert(false); return NULL; }
|
||||
comment_model_base_class::type_ptr ptr = this->m_model.getByIndex(row);
|
||||
if (! ptr) { qAssert(false); return NULL; }
|
||||
long id = ptr->getcomment_id();
|
||||
comment::type_blog_id value = ptr->getblog_id();
|
||||
|
||||
if (bLoadFromDatabase)
|
||||
{
|
||||
if (! sAppendRelations.isEmpty() && ! sAppendRelations.startsWith("->") && ! sAppendRelations.startsWith(">>")) { sRelation += "->" + sAppendRelations; }
|
||||
else if (! sAppendRelations.isEmpty()) { sRelation += sAppendRelations; }
|
||||
comment tmp;
|
||||
tmp.setcomment_id(id);
|
||||
this->m_lastError = qx::dao::fetch_by_id_with_relation(sRelation, tmp);
|
||||
if (this->m_lastError.isValid()) { return NULL; }
|
||||
value = tmp.getblog_id();
|
||||
ptr->setblog_id(value);
|
||||
}
|
||||
|
||||
model_view::blog_model * pNewChild = NULL;
|
||||
pChild = qx::model_view::create_nested_model_with_type(this, QModelIndex(), value, pNewChild);
|
||||
if (pChild) { this->insertChild(row, "blog_id", pChild); }
|
||||
return static_cast<QObject *>(pChild);
|
||||
}
|
||||
|
||||
void comment_model::syncNestedModel(int row, const QStringList & relation)
|
||||
{
|
||||
Q_UNUSED(relation);
|
||||
qx::IxModel * pNestedModel = NULL;
|
||||
if ((row < 0) || (row >= this->m_model.count())) { return; }
|
||||
comment_model_base_class::type_ptr ptr = this->m_model.getByIndex(row);
|
||||
if (! ptr) { return; }
|
||||
|
||||
pNestedModel = this->getChild(row, "blog_id");
|
||||
if (pNestedModel)
|
||||
{
|
||||
this->syncNestedModelRecursive(pNestedModel, relation);
|
||||
comment::type_blog_id value;
|
||||
qx::model_view::sync_nested_model(pNestedModel, value);
|
||||
ptr->setblog_id(value);
|
||||
}
|
||||
}
|
||||
|
||||
void comment_model::syncAllNestedModel(const QStringList & relation)
|
||||
{
|
||||
if (this->m_lstChild.count() <= 0) { return; }
|
||||
for (long l = 0; l < this->m_model.count(); l++)
|
||||
{ this->syncNestedModel(static_cast<int>(l), relation); }
|
||||
}
|
||||
|
||||
} // namespace model_view
|
||||
Reference in New Issue
Block a user