Add Dive issue

Grace Karanja gracie.karanja89 at gmail.com
Wed Aug 19 08:45:26 PDT 2015


On Tue, Aug 18, 2015 at 9:51 PM, Tomaz Canabrava <tcanabrava at kde.org> wrote:

>
>
> On Tue, Aug 18, 2015 at 4:25 AM, Grace Karanja <gracie.karanja89 at gmail.com
> > wrote:
>
>> Hi Tomaz,
>>
>> I am a bit stuck here:
>>
>> Check my code here:
>> https://github.com/gracie89/subsurface/tree/devel/qt-mobile
>>
>> When the user clicks on Add Dive, I want to add a new dive to the model.
>> This is working. But how do I tell QML to go the the new empty dive?
>>
>> This file:
>> https://github.com/gracie89/subsurface/blob/devel/qt-models/divelistmodel.cpp
>>
>> on line
>> 341
>>
>> Is where I am adding the dive
>> struct dive *d;d = alloc_dive();add_single_dive(get_divenr(d), d);addDive
>> (d);
>>
>>
>> This works ok, but now I want to tell the model to go to the last item :(
>>
>
> Grace,
>
> a Model, in Qt, doesn't have the notion of 'current', so the thing you
> should look at is "how can I manage to get the ListView to select the last
> item added on the model"
>
> the ListView has a 'count' property ( and this will work for all
> properties, so you already know how to deal with anything after this )
> each property has a 'on___changed', so: onCountChanged will work, also the
> current selected thing on ListView is set by the currentIndex, that is just
> a int, so you just need to pass your correct index when count changes:
>
> ListView {
>
> ...
> ...
>     onCountChanged: {
>           currentIndex = count-1;
>     }
> }
>

Thanks, Tomaz.

This has helped!



>
>
>
>
>
>> --
>> --
>> Grace K
>>
>
>


-- 
--
Grace K
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.subsurface-divelog.org/pipermail/subsurface/attachments/20150819/8676f804/attachment.html>


More information about the subsurface mailing list