Re: [SailfishDevel] QSqlTableModel and running several remorses

2016-01-18 Thread jollailija
François K. kirjoitti ma tammikuuta 18 12:35:14 2016 GMT+0200:
> 
> PS: I haven't investigated the proxy approach yet. I'll probably give it a 
> try in the next few days.
> 
You can see my proxy list implementation from 
https://github.com/jollailija/nettiradio (fav manager + fav dialog). It's a bit 
messy, since I ran out of time and had to finish it quickly. For example the 
entry multiplies at proxy level after saving edited station. It's easy to fix, 
I just don't have the time.

Cheers, 
jollailija
-- 
Lähetetty Jollastani
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

Re: [SailfishDevel] QSqlTableModel and running several remorses

2016-01-18 Thread François K .
Hi,

Allright, I've done some further testing and I also read some parts of the 
QSqlTableModel source code to understand what's going on.

I've finally managed to get something working. For people that might be 
interested in it, I figured out that :
  - You have to emit the `beginRemoveRows` and `endRemoveRows` signals when 
removing an item from the model. The provided implementation of `removeRows` 
doesn't do it for you (that was my main issue) ;
  - You have to use `OnManualSubmit` strategy. Using `OnFieldChange` strategy 
has some side-effects that will cause either a segfault or wrong data being 
manipulated (when several remorses are running at the same time) ;
  - Since you have to use `OnManualSubmit`, you also have to call `submitAll` 
at some point to "commit" the changes made on the model. If you don't call it 
or if your app crashes before, all the changes will be lost (which, IMHO, is a 
major drawback).

If someone knows an app that uses a QSqlTableModel, I'd be interested in 
reading the source code to see if there is another solution.

Feel free to add whatever you want that could help me :)


PS: I haven't investigated the proxy approach yet. I'll probably give it a try 
in the next few days.


Cheers,

-- 
François



- Mail original -
> Hi,
> 
> I've stumbled upon something very annoying :
> 
> I have a model that inherits from QSqlTableModel. A SilicaListView
> shows the data. This is very easy to do, thanks to Qt/QML :)
> 
> Each list item has a ContextMenu with a "Delete" entry that allows
> the user to delete the item. It runs a remorse, and, at the end of
> the remorse, the item is deleted from the model (and the database).
> Again, this works quite well... until you try to delete several items
> at the same time
> 
> A QSqlTableModel can have 3 different edit strategies :
> OnManualSubmit, OnRowChange or OnFieldChange.
> 
> If I set it to "OnManualSubmit", the item is deleted from the model,
> but it remains in the view and in the database until I call
> QSqlTableModel::submitAll(). This method actually commits the
> changes to the database, and resets the model by calling
> QSqlTableModel::select(). Since the model is resetted, it loses all
> other running remorses and causes a segfault.
> 
> If I set it to "OnFieldChanged", the item is deleted from the model
> and from the database, but it will still remain visible in the view.
> According to the Qt doc, I should call select() to update the view.
> But, as we've seen before, this destroys the other running remorses
> and also causes a segfault.
> 
> 
> I've made a very small app to demonstrate the problem, you can get it
> here and try it in your emulator : git clone
> https://github.com/Frzk/dummy.git
> You can use the PullDownMenu to switch between OnManualSubmit and
> OnFieldChanged strategies.
> 
> 
> 
> How should I deal with this ? This is a very simple case, yet I can't
> seem to find a solution :(
> 
> 
> 
> All the best,
> 
> --
> François
> 
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org