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

Re: [SailfishDevel] QSqlTableModel and running several remorses

2015-12-30 Thread Peter Kovacs

Hi Francoise,

Yeah, sorry about that. I'm not used to working in team and I also avoid variable names 
that can look like keywords (i.e. "list").
I also always use "r" for the variable that is returned.

I see. I use Longer Names to avoid the keywords stuff, like remorseList. IDE 
will always offer you the long names so it is not an issue for me.
Thanks that you added some more comments.

Hmm, However I would not say that this is neccessary for team effort. It is a 
Maintenance thing. Even you will forget what you have done today.
Maybe you remeber it in the next 3 years, but in 10 years you will not know 
what you had in mind. I think it is best to routinly think of speakable names. 
I never use one digit Variables.
So in you own interest I would recommend to think in longer terms in general - 
I mean we live in a time where everything last shorter and shorter. I think 
this is not something we should aim at in general.

Well it's seems pretty obvious : I want to remove several items from the list, 
one after the other.
When you do this quickly, several remorses can run at the same time.

I would use slot and actions to use with the QML. And what I would do I 
would first let the user collect what he want to delete and then have a a menue or 
gesture to execute.

I personly very much like the youtube tutorials from voidrealms. Even they are 
for Desktop Programming he shows all the tools that you need to know for gui 
Programming with QT. They should be the same base then for Silica.;)

Check these out:
Signal & slots   -> https://youtu.be/JtyCM4BTbYo?list=PL2D1942A4688E9D63
Actions  -> https://youtu.be/uLF9KWUR9ro?list=PL2D1942A4688E9D63
threads create   -> https://youtu.be/JaGqGhRW5Ks?list=PL2D1942A4688E9D63
threads priority -> https://youtu.be/JaGqGhRW5Ks?list=PL2D1942A4688E9D63
threads deadlock -> https://youtu.be/5WEiQ3VJfxc?list=PL2D1942A4688E9D63
threads gui  -> https://youtu.be/PR6wVy7Et1A?list=PL2D1942A4688E9D63


Sorry, I am working (currently) as software architect, and this is just to much 
my job ... :P

Have fun!
Peter

___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org


Re: [SailfishDevel] QSqlTableModel and running several remorses

2015-12-30 Thread jollailija
François K. kirjoitti ke joulukuuta 30 00:07:29 2015 GMT+0200:

> How would you make such a thing ? Use the destructor of the proxy to update 
> the database ?

The remorse would just delete the item from the QML list model, and then you 
could have a update timer (to prevent updating the whole list at db every time 
the user changes the proxy list) that starts running when the list's count has 
changed (for example. Doesn't work when you do something else than add/remove). 
The timer would then execute a loop like this:

function saveListToDB()  {
dbOpenConnection()
dbDropTable() // the risky part
var i = 0
for (i I have to admit that I don't really like this approach, it sounds kinda risky 
> to me. 

The second one is pretty safe :)

> And it also means that I have to add extra loops for something that shouldn't 
> require it.

Efficiency-wice it doesn't really matter, after all your QSQLModel must read 
the database as well.

I am also working on something that has a modifiable list stored with SQL. I'll 
link you the code after I'm done with it.
 
> Thanks again :)

No problem, I might accidentally learn something while doing this.
 
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

2015-12-29 Thread François K .
Hi Peter, hi guys,

First, thanks for your answer and ideas :)

> I find your code a bit hard to read. It would be nice if you use full
> names like list instead of l. I know it is annoying, but makes live
> easier in the long run.

Yeah, sorry about that. I'm not used to working in team and I also avoid 
variable names that can look like keywords (i.e. "list").
I also always use "r" for the variable that is returned.

I have uploaded a new version of the code with "l" replaced with "list" and 
some more comments.
If you have other remarks, please tell me, I'll try to improve that :)


> Why do you have more then one Remorse? This is not clear to me. Maybe
> you can explain?

Well it's seems pretty obvious : I want to remove several items from the list, 
one after the other.
When you do this quickly, several remorses can run at the same time.


> Where do you close your db connection? - May I have overlooked this
> :(

You didn't overlooked it. I don't close it in the small example I wrote.
In my real app, I have a "Storage" class that opens the database when the app 
starts and closes it when the object is destroyed.


> Could not find the method Match in the documentation or in the code
> :(.
> 
>   QModelIndexList l = this -> match ( this -> index ( 0 , 0 ),
>   MModel::IdRole, itemId, 1 , 
> Qt::MatchExactly);
> 
> I check against http://doc.qt.io/qt-5/qsqltablemodel.html What is
> your reference?

It's inherited from QAbstractItemModel : 
http://doc.qt.io/qt-5/qabstractitemmodel.html#match


> SQLLite may only support multiple readers or one writer. Maybe this
> is your Problem?

I don't think so, I'm writing (deleting) one item after another.


> I would honestly have One Data Object that knows how to read from the
> DB and open and closes the Connection for each operation with the DB
> seperatly.
> Not sure if this solves you Problem but it makes it easier to debug
> and Maintain. (Maybe Code is slower... But I rather have a rugged
> Code then a fast one.)
> 
> I would think in Layers:
> USER
> VIEW
> APPDATAMODEL
> DATABASE CONNECTOR
> DATABSE

I'm not sure that would make a difference here but I will definitely consider 
this, thanks :)


> Hope this helps you a bit.

Of course it does :)


Thanks a lot,

Cheers,

-- 
François
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

Re: [SailfishDevel] QSqlTableModel and running several remorses

2015-12-29 Thread François K .
Hi,

Thanks for your input :)

> Hi, I am a SQL noob, but here's my piece of advice:
> Use a QML list model as a "proxy" and then replace the database with
> the QML list model's data at some point, like after the user exits
> some sort of list edit mode. It might not be the most efficient way
> but it works and is really easy, you just need a loop that throws
> all the things from the QML list model into the SQL database and
> another one to do this the other way around.

How would you make such a thing ? Use the destructor of the proxy to update the 
database ?

I have to admit that I don't really like this approach, it sounds kinda risky 
to me. And it also means that I have to add extra loops for something that 
shouldn't require it.

But I'll probably give it a try if I don't get any other lead :)

Thanks again :)

-- 
François
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

Re: [SailfishDevel] QSqlTableModel and running several remorses

2015-12-28 Thread jollailija
Hi, I am a SQL noob, but here's my piece of advice:
Use a QML list model as a "proxy" and then replace the database with the QML 
list model's data at some point, like after the user exits some sort of list 
edit mode. It might not be the most efficient way but it works and is really 
easy, you just need a loop that throws all the things from the QML list model 
into the SQL database and another one to do this the other way around.

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

2015-12-28 Thread Peter Kovacs

Hello Francoise,

I find your code a bit hard to read. It would be nice if you use full 
names like list instead of l. I know it is annoying, but makes live 
easier in the long run.


Why do you have more then one Remorse? This is not clear to me. Maybe 
you can explain?

Where do you close your db connection? - May I have overlooked this :(
Could not find the method Match in the documentation or in the code :(.
QModelIndexList l = this->match( 	this->index(0, 0), 	MModel::IdRole, 
itemId, 	1, 	Qt::MatchExactly); 	



I check against http://doc.qt.io/qt-5/qsqltablemodel.html What is your 
reference?


SQLLite may only support multiple readers or one writer. Maybe this is 
your Problem?


I would honestly have One Data Object that knows how to read from the DB 
and open and closes the Connection for each operation with the DB seperatly.
Not sure if this solves you Problem but it makes it easier to debug and 
Maintain. (Maybe Code is slower... But I rather have a rugged Code then 
a fast one.)


I would think in Layers:
USER
VIEW
APPDATAMODEL
DATABASE CONNECTOR
DATABSE

Hope this helps you a bit.

All the best
Peter


On 28.12.2015 21:59, François K. wrote:

Hello,

I sent the following email a few weeks ago but got no answer. The github statistics also 
show that only one person downloaded the "dummy" project I wrote to demonstrate 
my issue... :(
With the recent announcements and the Jolla boat sailing on, I'd like to get 
this solved.

I'm even willing to pay if necessary.

Thanks a lot,
All the best,


- Mail original -
  
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 :(




___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

Re: [SailfishDevel] QSqlTableModel and running several remorses

2015-12-28 Thread François K .
Hello,

I sent the following email a few weeks ago but got no answer. The github 
statistics also show that only one person downloaded the "dummy" project I 
wrote to demonstrate my issue... :(
With the recent announcements and the Jolla boat sailing on, I'd like to get 
this solved.

I'm even willing to pay if necessary.

Thanks a lot,
All the best,


- Mail original -
>  
> 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 :(


-- 
François
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

[SailfishDevel] QSqlTableModel and running several remorses

2015-11-03 Thread François K .
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