Re: QML question

2016-04-27 Thread Tomaz Canabrava
On Wed, Apr 27, 2016 at 2:15 PM, Joakim Bygdell  wrote:

>
> > On 27 Apr 2016, at 18:55, Tomaz Canabrava  wrote:
> >
> > Please, please:
> >
> > don't add more stuff to the QMLManager, it's a huge beast already :)
> > crete something like this:
> >
> > Q_INVOKABLE QStringListModel : DiveObjectHelper::buddies() {
> >static QStringListModel buddies = new QStringListModel();
> > QStringList temp;
> >   for_each_dive (i, d) {
> > temp << d->buddy;
> >   }
> >temp.removeDuplicates();
> >buddies.setStringList(temp);
> >qDebug() << temp;
> >return buddies;
> > }
> >
> > What can be happening is that a QStringList will not tell QML that it
> changed, and thus, it wont update it's contents.
> > a Model will.
> Fully understandable.
>
> But why do I get data in my combobox if I do this: buddies << “foo” <<
> “bar”
> and not this: buddies << d->buddy.
>
> If I add
> buddies << “foo” << “bar”;
> before the return statement, the combobox will have two entries, “foo” and
> “bar".
>
> If i replace the combobox with a label where the text is a QString
> generated by joining the QStringList
> I get all buddies displayed on one line. “Buddy A, Buddy B, foo, bar"
>

I have *no* idea, really.
can you create a branch where I can try this?
currently I'm in the middle of a subsurface refactor for 5.0 (
tcanabrava/subsurface:new_ui )
with almost 100 commits, I need to speed things there too.



>
>
>
>
> >
> >
>
> /Jocke
>
>
___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


Re: QML question

2016-04-27 Thread Joakim Bygdell

> On 27 Apr 2016, at 18:55, Tomaz Canabrava  wrote:
> 
> Please, please:
> 
> don't add more stuff to the QMLManager, it's a huge beast already :)
> crete something like this:
> 
> Q_INVOKABLE QStringListModel : DiveObjectHelper::buddies() {
>static QStringListModel buddies = new QStringListModel();
> QStringList temp;
>   for_each_dive (i, d) {
> temp << d->buddy;
>   }
>temp.removeDuplicates();
>buddies.setStringList(temp);
>qDebug() << temp;
>return buddies;
> }
> 
> What can be happening is that a QStringList will not tell QML that it 
> changed, and thus, it wont update it's contents.
> a Model will. 
Fully understandable.

But why do I get data in my combobox if I do this: buddies << “foo” << “bar”
and not this: buddies << d->buddy.

If I add 
buddies << “foo” << “bar”; 
before the return statement, the combobox will have two entries, “foo” and 
“bar".

If i replace the combobox with a label where the text is a QString generated by 
joining the QStringList
I get all buddies displayed on one line. “Buddy A, Buddy B, foo, bar"




> 
> 

/Jocke

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


Re: QML question

2016-04-27 Thread Tomaz Canabrava
Please, please:

don't add more stuff to the QMLManager, it's a huge beast already :)
crete something like this:

Q_INVOKABLE QStringListModel : DiveObjectHelper::buddies() {
   static QStringListModel buddies = new QStringListModel();
QStringList temp;
for_each_dive (i, d) {
temp << d->buddy;
}
   temp.removeDuplicates();
   buddies.setStringList(temp);
   qDebug() << temp;
   return buddies;
}

What can be happening is that a QStringList will not tell QML that it
changed, and thus, it wont update it's contents.
a Model will.
___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


Re: QML question

2016-04-27 Thread Joakim Bygdell

> On 27 Apr 2016, at 18:27, Thiago Macieira  wrote:
> 
> On quarta-feira, 27 de abril de 2016 17:40:53 PDT Joakim Bygdell wrote:
>> Thomas or Thiago can you explain what’s going on here?
>> 
>> I have a combobox that gets populated from a QStringList.
>> 
>> If I generate the QStringList on the C++ side like so,
>>  list << “foo” << “bar << “baz"
>> my combobox contains 3 elements as expected.
>> 
>> If I populate the QStringList with data from the dive struct,
>>  list << dive.buddy << dive.divemaster
>> the combobox is empty.
>> 
>> In the later example the QStringList contains the expected data as I can
>> join the QStringList into a QString  that displays correctly on the QML
>> side.
> 
> The source of the data is not the issue here. That's a red herring. The 
> problem is something else.
> 
> 1) are you sure dive.buddy and dive.divemasters are non-empty strings?

Yes as I can concatenate the list to a single string that is displayed on 
the QML side with the correct content.

> 
> 2) is there anything special about the content of those strings?

Nope, just normal names.

> 
> 3) can you show the code after that?

QML side:

Combobox {
id: buddyBox
model: buddyList
}



C++ side:

QStringList QMLManger::buddyList() const
{
QStringList buddies;
struct dive *d;
int i = 0;
for_each_dive (i, d) {
buddies << d->buddy;
}
buddies.removeDuplicates();
return buddies;
}

> 
> -- 
> Thiago Macieira - thiago (AT) macieira.info  - thiago 
> (AT) kde.org 
>   Software Architect - Intel Open Source Technology Center
> 
> ___
> subsurface mailing list
> subsurface@subsurface-divelog.org 
> http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface 
> 
/Jocke

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


Re: QML question

2016-04-27 Thread Thiago Macieira
On quarta-feira, 27 de abril de 2016 17:40:53 PDT Joakim Bygdell wrote:
> Thomas or Thiago can you explain what’s going on here?
> 
> I have a combobox that gets populated from a QStringList.
> 
> If I generate the QStringList on the C++ side like so,
>   list << “foo” << “bar << “baz"
> my combobox contains 3 elements as expected.
> 
> If I populate the QStringList with data from the dive struct,
>   list << dive.buddy << dive.divemaster
> the combobox is empty.
> 
> In the later example the QStringList contains the expected data as I can
> join the QStringList into a QString  that displays correctly on the QML
> side.

The source of the data is not the issue here. That's a red herring. The 
problem is something else.

1) are you sure dive.buddy and dive.divemasters are non-empty strings?

2) is there anything special about the content of those strings?

3) can you show the code after that?

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


QML question

2016-04-27 Thread Joakim Bygdell
Thomas or Thiago can you explain what’s going on here?

I have a combobox that gets populated from a QStringList.

If I generate the QStringList on the C++ side like so,
list << “foo” << “bar << “baz"
my combobox contains 3 elements as expected.

If I populate the QStringList with data from the dive struct,
list << dive.buddy << dive.divemaster
the combobox is empty.

In the later example the QStringList contains the expected data as I can 
join the QStringList into a QString  that displays correctly on the QML side.

/Jocke

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface