OK, I got it done. Quite a few changes necessary, but it is working:
1. in QxEntityEditor, I export to C++ using the qxPersistable template. Not relevant for this case I think.
2. For the ModelViewExport, I created a new template and a .js. Here they are:
h template:
- Code: Select all
@@COMMENT_FILE_CREATED_BY@@
#ifndef @@INCLUDE_MACRO_GUARD@@
#define @@INCLUDE_MACRO_GUARD@@
#ifdef _QX_NO_PRECOMPILED_HEADER
#ifndef Q_MOC_RUN
#include "../include/@@PROJECT_NAME@@_precompiled_header.model_view.gen.h" // Need to include precompiled header for the generated moc file
#endif // Q_MOC_RUN
#endif // _QX_NO_PRECOMPILED_HEADER
@@LIST_INCLUDE_DEPENDENCIES@@
@@NAMESPACE_BEGIN@@
typedef qx::QxModel<@@CLASS_NAME@@> @@MODEL_BASE_CLASS@@;
class @@CLASS_MACRO_EXPORT@@ @@CLASS_NAME@@_model : public @@MODEL_BASE_CLASS@@
{
Q_OBJECT
public:
@@CLASS_NAME@@_model(QObject * parent = 0);
@@CLASS_NAME@@_model(qx::IxModel * other, QObject * parent);
virtual ~@@CLASS_NAME@@_model();
@@LIST_RELATIONS_Q_INVOKABLE@@
@@COMMENT_LIST_PROPERTIES_EXPOSED_BY_MODEL@@
@@SYNC_NESTED_MODEL@@
};
@@NAMESPACE_END@@
@@MACRO_QX_REGISTER_CLASS_HPP@@(@@CUSTOM_NAMESPACE@@@@FULL_CLASS_NAME@@_model,
QObject, @@CLASS_VERSION@@, @@FULL_CLASS_NAME@@_model)
#endif // @@INCLUDE_MACRO_GUARD@@
cpp template:
- Code: Select all
@@COMMENT_FILE_CREATED_BY@@
#include "../include/@@PROJECT_NAME@@_precompiled_header.model_view.gen.h"
@@LIST_INCLUDE_DEPENDENCIES_CPP@@
#include <QxOrm_Impl.h>
@@MACRO_QX_REGISTER_CLASS_CPP@@(@@CUSTOM_NAMESPACE@@@@FULL_CLASS_NAME@@_model,
@@FULL_CLASS_NAME@@_model)
namespace qx {
template <>
void register_class(QxClass<@@CUSTOM_NAMESPACE@@@@FULL_CLASS_NAME@@_model> & t)
{@@CUSTOM_QX_REGISTER_CLASS_RELATIONS@@}
} // namespace qx
@@NAMESPACE_BEGIN@@
@@CLASS_NAME@@_model::@@CLASS_NAME@@_model(QObject * parent /* = 0 */) : @@MODEL_BASE_CLASS@@(parent) { ; }
@@CLASS_NAME@@_model::@@CLASS_NAME@@_model(qx::IxModel * other, QObject * parent) : @@MODEL_BASE_CLASS@@(other, parent) { ; }
@@CLASS_NAME@@_model::~@@CLASS_NAME@@_model() { ; }
@@IMPLEMENT_LIST_RELATIONS_Q_INVOKABLE@@
@@IMPLEMENT_SYNC_NESTED_MODEL@@
@@NAMESPACE_END@@
tried to attach, but the forum does not allow. js files...
- Code: Select all
({
customProcess : function(params)
{
try
{
var action = params[5];
var ns = "mv::"; //TODO how to get the namespace?
if (action == "CUSTOM_NAMESPACE")
return ns;
if (action == "CUSTOM_QX_REGISTER_CLASS_RELATIONS")
{
var entity_id = params[13];
var entity_details = helper.getEntityDetails(entity_id);
var entity_list_of_properties_id = ((entity_details.length > 0) ? entity_details[10] : "");
var entity_list_of_properties_array = entity_list_of_properties_id.split("|");
var r = "\n";
for (var idx = 0; idx < entity_list_of_properties_array.length; idx++)
{
var property_id = entity_list_of_properties_array[idx];
var property_details = helper.getPropertyDetails(property_id);
if (property_details[27] == 1) //property_is_relationship
r += "\tt.fct_3<QObject *, int, bool, const QString&>(& " + ns + entity_details[2] + "_model::" +
property_details[2] + ", \"" + property_details[2] + "\");\n"
}
return r;
}
// quit with 'params[0]' means : not change the default behaviour
return params[0];
}
catch (err)
{ return ("[CustomScriptError] an unexpected error occurred : " + err); }
}
})
There are 2 problems with it:
1. I cannot get the namespace in the js, so I hardcoded my namespace "mv::". How do you get the namespace?
2. Your macro @@IMPLEMENT_LIST_RELATIONS_Q_INVOKABLE@@ is now incompatible with my patch for the empty line in the model.
This generated line now always fails, and should be changed.
- Code: Select all
if ((row < 0) || (row >= this->m_model.count())) { qAssert(false); return NULL; } //this is the old
if ((row < 0) || (row >= this->m_model.count())) { if (row >= this->m_model.count() + (int) getShowEmptyLine()) qAssert(false); return NULL; } //this is the adapted
Maybe you can give me the script that implements this macro, so that I can create a custom macro to substitute it and continue my work? Right now I am substituting each occurence in the generated code.
And to use this a snippet from my testing code:
- Code: Select all
long lCount = (model->getClass()->getDataMemberX() ? model->getClass()->getDataMemberX()->count() : 0);
if (model->getClass()->getDataMemberX())
{
m_pAdminTool->AddLevel(); //ads a holding widget with layout
std::vector<boost::any> v(3, true);
QString s;
v[0] = l.first().row();
v[2] = (const QString&) s;
for (long i = 0; i < lCount; i++)
{
IxDataMember * p = model->getClass()->getDataMemberX()->get(i); if (!p) { continue; }
if (!p->getSqlRelation()) { continue; }
TableViewWithDel* tv = new TableViewWithDel(m_pAdminTool);
m_pAdminTool->m_lwViews.last()->layout()->addWidget(tv); //gets the last added holding widget (in AddLevel() above)
boost::any r;
qx_bool bInvokeOk = QxClassX::invoke("mv::" + model->getClass()->getKey() + "_model",
p->getKey(), model, v, &r);
qAssert(bInvokeOk);
tv->SetModel(qobject_cast<IxModel*>(boost::any_cast<QObject*>(r))); //now if you really get rid of boost for the next release, maybe this casting frenzy can go away...
}
}