Q_PROPERTY decls where?

Forum for posting problems using QxOrm library

Q_PROPERTY decls where?

Postby doulos » Wed Aug 27, 2014 2:48 pm

Hello,

we have classes generated from within EntityEditor and would like to publish certain class members as QML-accessible properties. We can do this by placing Q_PROPERTY declarations in the generated header (ourclass.gen.h), which is obviously not ideal. An attempt to put the declarations in the custom header did not work out (it compiled, but properties were not accessible). How is this to be done?

In the same context: we would like the setter methods to immediately update the database. How can that be done?

thanks,
Christian
doulos
 
Posts: 15
Joined: Mon Aug 11, 2014 1:24 pm

Re: Q_PROPERTY decls where?

Postby qxorm » Wed Aug 27, 2014 3:03 pm

Hello,

You don't need to put Q_PROPERTY declarations !
There is the QxModelView module to expose automatically all properties of registered classes into QxOrm context to QML.

Here is the doxygen page of QxModelView module : http://www.qxorm.com/doxygen/html/group ... _view.html
Here is a mini-tutorial in the FAQ : http://www.qxorm.com/qxorm_en/faq.html#faq_300
And you have a project example in the ./test/qxBlogModelView/ directory of QxOrm package.

Please let me know if you need more details.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Q_PROPERTY decls where?

Postby doulos » Wed Aug 27, 2014 3:27 pm

at first sight, QxModelView looks like overkill to me, and I am not quite sure how to use it at all.

Heres my usecase: I have one persistent class, call it "ProjectDefaults", of which there exists only one instance, of which I already have a valid ProjectDefaults_ptr. I would like to put this into the QML context to be able to edit it. How would QxModel help me here?

also, kindly adress the question about property setters directly accessing the database (i.e., no "save" button)

thanks,
Christian
doulos
 
Posts: 15
Joined: Mon Aug 11, 2014 1:24 pm

Re: Q_PROPERTY decls where?

Postby qxorm » Wed Aug 27, 2014 3:38 pm

I have one persistent class, call it "ProjectDefaults", of which there exists only one instance, of which I already have a valid ProjectDefaults_ptr.

One instance, so I assume that there is only 1 row into your database (qxFetchAll() will return only 1 instance).
So, with the QxModelView module, you could write exactly as the FAQ :
Code: Select all
// Create a model and fetch all data from database
qx::IxModel * pModel = new qx::QxModel<ProjectDefaults>();
pModel->qxFetchAll();

// Associate the model to a QML view and display it
QQuickView qmlView;
qmlView.rootContext()->setContextProperty("myModel", pModel);
qmlView.setSource(QUrl("qrc:/documents/main.qml"));
qmlView.show();

Then, in the QML view, all properties of your ProjectDefaults class are available !

the question about property setters directly accessing the database (i.e., no "save" button)

To do this kind of things, I would recommend to create your own template class wich inherits from qx::QxModel<T>.
Then, in your template class, you just have to override the "virtual bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole)" method.

I write it quickly but your template class could be something like this :
Code: Select all
template <class T>
class MyModelSaveOnSetter : public qx::QxModel<T>
{
   virtual bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole)
   {
      bool bSetDataOk = qx::QxModel<T>::setData(index, value, role); // call base class setter
      if (bSetDataOk) { this->qxSave(); }
      return bSetDataOk;
   }
};


Then, to create your model :
Code: Select all
qx::IxModel * pModel = new MyModelSaveOnSetter<ProjectDefaults>();
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Q_PROPERTY decls where?

Postby doulos » Wed Aug 27, 2014 4:05 pm

One instance, so I assume that there is only 1 row into your database (qxFetchAll() will return only 1 instance).


there is none, initially. I need to create one programmatically. Call me hard of understanding, but I cannnot figure out how to do this with QxModel. I already have the code in place that does this with plain QObject classes (ProjectDefaults and ProjectDefaults_ptr)

thanks,
C.
doulos
 
Posts: 15
Joined: Mon Aug 11, 2014 1:24 pm

Re: Q_PROPERTY decls where?

Postby qxorm » Wed Aug 27, 2014 4:20 pm

there is none, initially. I need to create one programmatically.

You can check if there is something with the qx::QxModel<T>::qxCount() method.
If there is nothing in the model, you can add an instance with the qx::QxModel<T>::insertRows() method.

I already have the code in place that does this with plain QObject classes (ProjectDefaults and ProjectDefaults_ptr).

So what is your problem exactly ?
I would recommend to use the Qt model/view framework (so the QxModelView module), but if you really want to add the Q_PROPERTY macro in the QxEntityEditor generated files, then : you can do that with QxEntityEditor 1.1.6 and the new javascript engine : with the javascript engine, you can customize generated files, so you can add the Q_PROPERTY macro where you want.
There is a javascript example file in the ./samples/ directory of QxEntityEditor package.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Q_PROPERTY decls where?

Postby doulos » Wed Aug 27, 2014 4:34 pm

So what is your problem exactly ?


my problem is that I cannot make sense of that model stuff. All I hear is talk of rows and columns while I would like to use the simple domain API of my entity classes. I guess I will have to read up on QAbstractItemModel, and I fear it will not be fun at all.

After calling insertRows(), how do I set the values for the individual properties?

So I will try to make up my mind between using the model stuff, mainpulating generated classes by hand and customizing the generator.

thanks so far,
C.
doulos
 
Posts: 15
Joined: Mon Aug 11, 2014 1:24 pm

Re: Q_PROPERTY decls where?

Postby qxorm » Wed Aug 27, 2014 5:26 pm

I guess I will have to read up on QAbstractItemModel, and I fear it will not be fun at all.

Yes, QxModelView module is just an implementation of QAbstractItemModel class.
So you should start to read and try to understand how Qt model/view framework works.
Then my advice would be to manipulate the sample project qxBlogModelView in the ./test/ directory of QxOrm package : this is a working project, with classes registered into QxOrm context, and a QML view where you can get/set properties of C++ classes => you could try to modify the code to do what you want exactly, or tell me what you want to do and I will try to send you a modified qxBlogModelView project.

So I will try to make up my mind between using the model stuff, mainpulating generated classes by hand and customizing the generator.

About customizing the generator with the javascript engine, I will try to provide a tutorial to explain step by step how to do that...
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Q_PROPERTY decls where?

Postby doulos » Wed Aug 27, 2014 5:57 pm

About customizing the generator with the javascript engine, I will try to provide a tutorial to explain step by step how to do that...


I would really appreciate that. Right now, my feeling is that I would rather avoid the Model way, because we only have a few classes and no tabular or list views (but lots of calculations and graphs). Additionally, we're on a very tright schedule, so no time to investigate yet another new concept.

thanks,
C.
doulos
 
Posts: 15
Joined: Mon Aug 11, 2014 1:24 pm

Re: Q_PROPERTY decls where?

Postby qxorm » Thu Aug 28, 2014 7:39 am

I would really appreciate that

Here is a copy of an e-mail I sent recently : http://www.qxorm.com/temp/custom_qxee_w ... script.pdf
I will write a better tutorial but it should be sufficient for now in your case (this mini-tutorial is for the model/view plugin, but it is exactly the same thing for the C++ export plugin).

we're on a very tright schedule

I understand that your are working on a commercial product : if your product is based on QxOrm library, then your product must be GPL.
Please remember that you have to purchase a QXPL QxOrm license to sell your product without the restrictions of the GPL license.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Next

Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 5 guests

cron