Discussion:
How can I populate a QTreeView from a "flat" QAbstractItemModel
Josh Highley
2012-02-07 19:41:25 UTC
Permalink
The Jambi tree examples that I've found use the file system as the model
and relies on the filesystem to provide the parent-child relationship,
which doesn't help me.

I have a flat list of objects in a QAbstractItemModel. I use this model
with other views so I can't just extend QTreeModel instead. For my tree
view, I just want to use a property of each object to group the objects in
a simple 2 level tree. Based on the parameters passed to the abstract
methods in QAbstractItemModel, I can't figure out how I can determine what
the view is requesting. By extending QDirModel and putting print
statements in the data method, I found, for example, the (row,column) - aka
QModelIndex - for the first level in the tree is (0,0), (1,0), (2,0), etc.
If I choose one of those levels, then the children also have the same index
rows and columns: (0,0), (1,0), (2,0). So, in the method data(QModelIndex
index, int role), how can I know what index is referring to? Same goes for
the parent(QModelIndex child) and rowCount(QModelIndex parent) methods.
The parameters seem too vague to figure out exactly which tree item the
view is requesting: one of the groups or one of the objects in the group.

Thanks,

Josh
Poalo Pacussi
2012-02-08 09:38:22 UTC
Permalink
Hi,

have a look here :
http://developer.qt.nokia.com/doc/qt-4.8/model-view-programming.html#model-classes

AFAIR jambi breaks with the c++ in some points concerning the modelindex.
But the structure is still the same.

If I understand you correctly, you want to change the internat structure of
your "flat list", in a way that it is displayable in a tree model but still
use the original flat list.
For this have a look at Proxymodels. These support to transform the
internal model structure without changing the original model, think of them
as an additional adapting layer between the original model and the view.
http://developer.qt.nokia.com/doc/qt-4.8/model-view-programming.html#proxy-models

Regards
Post by Josh Highley
The Jambi tree examples that I've found use the file system as the model
and relies on the filesystem to provide the parent-child relationship,
which doesn't help me.
I have a flat list of objects in a QAbstractItemModel. I use this model
with other views so I can't just extend QTreeModel instead. For my tree
view, I just want to use a property of each object to group the objects in
a simple 2 level tree. Based on the parameters passed to the abstract
methods in QAbstractItemModel, I can't figure out how I can determine what
the view is requesting. By extending QDirModel and putting print
statements in the data method, I found, for example, the (row,column) - aka
QModelIndex - for the first level in the tree is (0,0), (1,0), (2,0), etc.
If I choose one of those levels, then the children also have the same index
rows and columns: (0,0), (1,0), (2,0). So, in the method data(QModelIndex
index, int role), how can I know what index is referring to? Same goes for
the parent(QModelIndex child) and rowCount(QModelIndex parent) methods.
The parameters seem too vague to figure out exactly which tree item the
view is requesting: one of the groups or one of the objects in the group.
Thanks,
Josh
_______________________________________________
Qt-jambi-interest mailing list
http://lists.qt.nokia.com/mailman/listinfo/qt-jambi-interest
j***@gmail.com
2012-02-08 20:30:16 UTC
Permalink
Yes, I've read the documentation several times but it's too high level. I
forgot to mention in my original email that I am already using a proxy
model. I think I have most of it figured out, except for how to implement
the parent(QModelIndex child) method. I can't determine what the child's
parent is without being able to traverse up the tree with child.parent(),
but calling child.parent() just recursively calls the proxy model's parent
method that I'm trying to implement: it eventually throws a stack overflow
exception.
Post by Poalo Pacussi
Hi,
http://developer.qt.nokia.com/doc/qt-4.8/model-view-programming.html#model-classes
AFAIR jambi breaks with the c++ in some points concerning the modelindex.
But the structure is still the same.
If I understand you correctly, you want to change the internat structure
of your "flat list", in a way that it is displayable in a tree model but
still use the original flat list.
For this have a look at Proxymodels. These support to transform the
internal model structure without changing the original model, think of
them as an additional adapting layer between the original model and the
view.
http://developer.qt.nokia.com/doc/qt-4.8/model-view-programming.html#proxy-models
Regards
The Jambi tree examples that I've found use the file system as the model
and relies on the filesystem to provide the parent-child relationship,
which doesn't help me.
I have a flat list of objects in a QAbstractItemModel. I use this model
with other views so I can't just extend QTreeModel instead. For my tree
view, I just want to use a property of each object to group the objects
in a simple 2 level tree. Based on the parameters passed to the abstract
methods in QAbstractItemModel, I can't figure out how I can determine
what the view is requesting. By extending QDirModel and putting print
statements in the data method, I found, for example, the (row,column) -
aka QModelIndex - for the first level in the tree is (0,0), (1,0), (2,0),
etc. If I choose one of those levels, then the children also have the
same index rows and columns: (0,0), (1,0), (2,0). So, in the method
data(QModelIndex index, int role), how can I know what index is referring
to? Same goes for the parent(QModelIndex child) and rowCount(QModelIndex
parent) methods. The parameters seem too vague to figure out exactly
which tree item the view is requesting: one of the groups or one of the
objects in the group.
Thanks,
Josh
_______________________________________________
Qt-jambi-interest mailing list
http://lists.qt.nokia.com/mailman/listinfo/qt-jambi-interest
Poalo Pacussi
2012-02-09 00:00:42 UTC
Permalink
You'll have to do the bookkeeping about hierarchy yourself, as nearly all
of qmodelindex's methods will access the model again. The problem is that
the c++ implementation (of the qtreemodel) uses
QModelIndex::internalPointer to retrieve the information which internal
object is linked to that specific qmodelindex, which does not work that way
in jambi.

So to be honest, I had a look at that problem myself a while ago but didn't
find a satisfying solution. Jambi offer QModelIndex.internalId but I did
not follow that.
Post by j***@gmail.com
Yes, I've read the documentation several times but it's too high level. I
forgot to mention in my original email that I am already using a proxy
model. I think I have most of it figured out, except for how to implement
the parent(QModelIndex child) method. I can't determine what the child's
parent is without being able to traverse up the tree with child.parent(),
but calling child.parent() just recursively calls the proxy model's parent
method that I'm trying to implement: it eventually throws a stack overflow
exception.
Post by Poalo Pacussi
Hi,
http://developer.qt.nokia.com/doc/qt-4.8/model-view-programming.html#model-classes
Post by Poalo Pacussi
AFAIR jambi breaks with the c++ in some points concerning the
modelindex. But the structure is still the same.
Post by Poalo Pacussi
If I understand you correctly, you want to change the internat structure
of your "flat list", in a way that it is displayable in a tree model but
still use the original flat list.
Post by Poalo Pacussi
For this have a look at Proxymodels. These support to transform the
internal model structure without changing the original model, think of them
as an additional adapting layer between the original model and the view.
http://developer.qt.nokia.com/doc/qt-4.8/model-view-programming.html#proxy-models
Post by Poalo Pacussi
Regards
The Jambi tree examples that I've found use the file system as the model
and relies on the filesystem to provide the parent-child relationship,
which doesn't help me.
Post by Poalo Pacussi
I have a flat list of objects in a QAbstractItemModel. I use this model
with other views so I can't just extend QTreeModel instead. For my tree
view, I just want to use a property of each object to group the objects in
a simple 2 level tree. Based on the parameters passed to the abstract
methods in QAbstractItemModel, I can't figure out how I can determine what
the view is requesting. By extending QDirModel and putting print
statements in the data method, I found, for example, the (row,column) - aka
QModelIndex - for the first level in the tree is (0,0), (1,0), (2,0), etc.
If I choose one of those levels, then the children also have the same index
rows and columns: (0,0), (1,0), (2,0). So, in the method data(QModelIndex
index, int role), how can I know what index is referring to? Same goes for
the parent(QModelIndex child) and rowCount(QModelIndex parent) methods.
The parameters seem too vague to figure out exactly which tree item the
view is requesting: one of the groups or one of the objects in the group.
Post by Poalo Pacussi
Thanks,
Josh
_______________________________________________
Qt-jambi-interest mailing list
http://lists.qt.nokia.com/mailman/listinfo/qt-jambi-interest
Darryl Miles
2012-02-09 17:49:57 UTC
Permalink
Post by j***@gmail.com
Yes, I've read the documentation several times but it's too high level.
I forgot to mention in my original email that I am already using a proxy
model. I think I have most of it figured out, except for how to
implement the parent(QModelIndex child) method. I can't determine what
the child's parent is without being able to traverse up the tree with
child.parent(), but calling child.parent() just recursively calls the
proxy model's parent method that I'm trying to implement: it eventually
throws a stack overflow exception.
Please put a simple example application together. This sounds like a
bug (if the C++ API would work in that scenario).

If you can create a C++ version of the same application (as well as Java
application), I'm sure the matter could be addressed and fixed accordingly.


Darryl
j***@gmail.com
2012-02-09 18:04:44 UTC
Permalink
I'll see what I can do. In my limited experience, Jambi is generally a very
thin wrapper on the C++ APIs. Since the child index is created by calling
the index(row,column,parent) method, I think the parent of the child
_should_ already be known and populated (but isn't in my case).

I have very little experience with C++....couldn't someone just look at the
QModelIndex parent(QModelIndex) method and quickly determine if it simply
passes the call on to child.model().parent() ?
Post by j***@gmail.com
Yes, I've read the documentation several times but it's too high level.
I forgot to mention in my original email that I am already using a proxy
model. I think I have most of it figured out, except for how to
implement the parent(QModelIndex child) method. I can't determine what
the child's parent is without being able to traverse up the tree with
child.parent(), but calling child.parent() just recursively calls the
proxy model's parent method that I'm trying to implement: it eventually
throws a stack overflow exception.
Please put a simple example application together. This sounds like a bug
(if the C++ API would work in that scenario).
If you can create a C++ version of the same application (as well as Java
application), I'm sure the matter could be addressed and fixed
accordingly.
Darryl
Samu Voutilainen
2012-02-10 14:28:45 UTC
Permalink
Hi,
Post by j***@gmail.com
I'll see what I can do. In my limited experience, Jambi is generally a very
thin wrapper on the C++ APIs. Since the child index is created by calling
the index(row,column,parent) method, I think the parent of the child
_should_ already be known and populated (but isn't in my case).
But it still works so with C++ application? Could you provide example made of
such application for us?
Post by j***@gmail.com
I have very little experience with C++....couldn't someone just look at the
QModelIndex parent(QModelIndex) method and quickly determine if it simply
passes the call on to child.model().parent() ?
You can find Qt’s source online at http://qt.gitorious.org/qt . You could also
ask at Qt’s channels if there is someone who would know about it; I don’t know
internals of Qt that well.

If you could provide simple example ( http://sscce.org/ ) using Java so we
could actually look at the matter and fix the bug in the project if such is
found, it would be wonderful.
j***@gmail.com
2012-02-10 15:40:50 UTC
Permalink
I can't create a C++ app, but I can create a simple Java app with Jambi. I
have a couple from my previous bug reports that I can modify

Just to be clear, though, and to avoid wasting everyone's time: In my proxy
model, I should be able to implement the parent() method as follows:

public QModelIndex parent(QModelIndex child)
{
return child.parent();
}

without causing recursive parent() method calls leading to a stack
overflow. Correct?

Thanks,

Josh
Post by j***@gmail.com
Post by Samu Voutilainen
Hi,
Post by j***@gmail.com
I'll see what I can do. In my limited experience, Jambi is generally
a very
Post by Samu Voutilainen
Post by j***@gmail.com
thin wrapper on the C++ APIs. Since the child index is created by
calling
Post by Samu Voutilainen
Post by j***@gmail.com
the index(row,column,parent) method, I think the parent of the child
_should_ already be known and populated (but isn't in my case).
But it still works so with C++ application? Could you provide example
made of
Post by Samu Voutilainen
such application for us?
Post by j***@gmail.com
I have very little experience with C++....couldn't someone just look
at the
Post by Samu Voutilainen
Post by j***@gmail.com
QModelIndex parent(QModelIndex) method and quickly determine if it
simply
Post by Samu Voutilainen
Post by j***@gmail.com
passes the call on to child.model().parent() ?
You can find Qt's source online at http://qt.gitorious.org/qt . You
could also
Post by Samu Voutilainen
ask at Qt's channels if there is someone who would know about it; I
don't know
Post by Samu Voutilainen
internals of Qt that well.
If you could provide simple example ( http://sscce.org/ ) using Java so
we
Post by Samu Voutilainen
could actually look at the matter and fix the bug in the project if
such is
Post by Samu Voutilainen
found, it would be wonderful.
_______________________________________________
Qt-jambi-interest mailing list
http://lists.qt.nokia.com/mailman/listinfo/qt-jambi-interest
Samu Voutilainen
2012-02-10 15:48:52 UTC
Permalink
Post by j***@gmail.com
I can't create a C++ app, but I can create a simple Java app with Jambi. I
have a couple from my previous bug reports that I can modify
Just to be clear, though, and to avoid wasting everyone's time: In my proxy
public QModelIndex parent(QModelIndex child)
{
return child.parent();
}
without causing recursive parent() method calls leading to a stack
overflow. Correct?
Nothing should make Java to crash, so that’s atleast a bug, even if the code
was wrong :)
Post by j***@gmail.com
Thanks,
Josh
Post by j***@gmail.com
Post by Samu Voutilainen
Hi,
Post by j***@gmail.com
I'll see what I can do. In my limited experience, Jambi is generally
a very
Post by Samu Voutilainen
Post by j***@gmail.com
thin wrapper on the C++ APIs. Since the child index is created by
calling
Post by Samu Voutilainen
Post by j***@gmail.com
the index(row,column,parent) method, I think the parent of the child
_should_ already be known and populated (but isn't in my case).
But it still works so with C++ application? Could you provide example
made of
Post by Samu Voutilainen
such application for us?
Post by j***@gmail.com
I have very little experience with C++....couldn't someone just look
at the
Post by Samu Voutilainen
Post by j***@gmail.com
QModelIndex parent(QModelIndex) method and quickly determine if it
simply
Post by Samu Voutilainen
Post by j***@gmail.com
passes the call on to child.model().parent() ?
You can find Qt's source online at http://qt.gitorious.org/qt . You
could also
Post by Samu Voutilainen
ask at Qt's channels if there is someone who would know about it; I
don't know
Post by Samu Voutilainen
internals of Qt that well.
If you could provide simple example ( http://sscce.org/ ) using Java so
we
Post by Samu Voutilainen
could actually look at the matter and fix the bug in the project if
such is
Post by Samu Voutilainen
found, it would be wonderful.
_______________________________________________
Qt-jambi-interest mailing list
http://lists.qt.nokia.com/mailman/listinfo/qt-jambi-interest
--
Terveisin,
Samu Voutilainen
http://smar.fi

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
Darryl Miles
2012-02-11 12:03:03 UTC
Permalink
Post by Samu Voutilainen
Post by j***@gmail.com
I can't create a C++ app, but I can create a simple Java app with Jambi. I
have a couple from my previous bug reports that I can modify
Just to be clear, though, and to avoid wasting everyone's time: In my proxy
public QModelIndex parent(QModelIndex child)
{
return child.parent();
}
without causing recursive parent() method calls leading to a stack
overflow. Correct?
I don't know. Are you asking a question, "I should be able to implement
..." does not read like a question, it would be more useful to cite your
reference to having that view first.

How would you write the same application using best-practice in C++. I
know you may not know but I am trying to lean on this question as being
a good exercise to getting you an answer for the QtJambi case. Maybe
one of the QtJambi devs can convert your Java code into C++ but you are
probably going to also need to supply a sufficiently complex real model
data as input so that every use-case can be checked. Not the blinkered
view of the use case that only shows up the problem. Also you need to
explain the non-obvious aspects of your model and also the non-obvious
aspects of how you expect the visual representation of the model to be
rendered by Qt.

So what I am getting at with the last paragraph is that; if you can't
provide C++ version then you need to provide some extra information that
might exceed that of a Java example, i.e. the specification of the model
input data (with a sufficiently contrived complex example data-set), the
specification of the rendered/interactive aspects of the output visual
representation.

The QModelIndex maybe considered an advanced Qt C++ feature, so even C++
developers can have trouble using it in the best way.



If C++ does not have the same issue and the code is an agreed equivalent
then yes this should be escalated as something QtJambi should address.

But if what you are doing is not possible in C++ in the way you are
doing it then a StackOverflow maybe an acceptable error.
Post by Samu Voutilainen
Nothing should make Java to crash, so that’s atleast a bug, even if the code
was wrong :)
Lets be clear. Java is not crashing.

A stack overflow (java.lang.StackOverflowException) is a soft-error that
the JVM detects and advises the application that is running of the
problem so a recovery scenario can be executed.

Your recovery scenario may be that the application process exits. To
some that observe this behavior they might call it an application crash.



Darryl
Pierce Krouse
2012-02-12 19:51:23 UTC
Permalink
OK, I didn't figure out why it broke, but I did manage to fix it. I created an empty workspace and pointed my eclipse installation at it and reset the path to the Qt Jambi binaries. That cured my actual installation, and now I can open Eclipse against my original workspace without problems. It's possible that just resetting the binary path location without changing workspaces would have worked directly, but my debug path led me to the fix indicated.

Thanks again Darryl, I will keep the QtDesigner information handy in case I need to migrate to a newer version of Jambi in the future.

Pierce Krouse | Synopsys | Lynx Design System | office (512)372-7522


-----Original Message-----
From: qt-jambi-interest-bounces+pkrouse=***@qt.nokia.com [mailto:qt-jambi-interest-bounces+pkrouse=***@qt.nokia.com] On Behalf Of Darryl Miles
Sent: Saturday, February 11, 2012 6:03 AM
To: ***@gmail.com
Cc: qt-jambi-***@qt.nokia.com
Subject: Re: [Qt-jambi-interest] Fwd: Re: Re: How can I populate a QTreeView from a "flat" QAbstractItemModel
Post by Samu Voutilainen
Post by j***@gmail.com
I can't create a C++ app, but I can create a simple Java app with Jambi. I
have a couple from my previous bug reports that I can modify
Just to be clear, though, and to avoid wasting everyone's time: In my proxy
public QModelIndex parent(QModelIndex child)
{
return child.parent();
}
without causing recursive parent() method calls leading to a stack
overflow. Correct?
I don't know. Are you asking a question, "I should be able to implement
..." does not read like a question, it would be more useful to cite your
reference to having that view first.

How would you write the same application using best-practice in C++. I
know you may not know but I am trying to lean on this question as being
a good exercise to getting you an answer for the QtJambi case. Maybe
one of the QtJambi devs can convert your Java code into C++ but you are
probably going to also need to supply a sufficiently complex real model
data as input so that every use-case can be checked. Not the blinkered
view of the use case that only shows up the problem. Also you need to
explain the non-obvious aspects of your model and also the non-obvious
aspects of how you expect the visual representation of the model to be
rendered by Qt.

So what I am getting at with the last paragraph is that; if you can't
provide C++ version then you need to provide some extra information that
might exceed that of a Java example, i.e. the specification of the model
input data (with a sufficiently contrived complex example data-set), the
specification of the rendered/interactive aspects of the output visual
representation.

The QModelIndex maybe considered an advanced Qt C++ feature, so even C++
developers can have trouble using it in the best way.



If C++ does not have the same issue and the code is an agreed equivalent
then yes this should be escalated as something QtJambi should address.

But if what you are doing is not possible in C++ in the way you are
doing it then a StackOverflow maybe an acceptable error.
Post by Samu Voutilainen
Nothing should make Java to crash, so that’s atleast a bug, even if the code
was wrong :)
Lets be clear. Java is not crashing.

A stack overflow (java.lang.StackOverflowException) is a soft-error that
the JVM detects and advises the application that is running of the
problem so a recovery scenario can be executed.

Your recovery scenario may be that the application process exits. To
some that observe this behavior they might call it an application crash.



Darryl
_______________________________________________
Qt-jambi-interest mailing list
Qt-jambi-***@qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-jambi-interest
Josh Highley
2012-02-13 22:10:40 UTC
Permalink
@Darryl:
My statement about "I should be able to implement ..." was looking for
verification that I should be able to do that, per other people's prior
comments that made it seem so.

I don't know how I would write this using best practices because I haven't
found any. If you can point me to some examples of using a proxy model to
morph a list style model into a tree view, I'd really like that.

I attached an example program with comments at the top with all my
questions and issues. I also found the Linux and Windows seem to store
QModelIndex internalId differently (Linux is unsigned)



On Sat, Feb 11, 2012 at 6:03 AM, Darryl Miles <
Post by Darryl Miles
Post by Samu Voutilainen
Post by j***@gmail.com
I can't create a C++ app, but I can create a simple Java app with Jambi. I
have a couple from my previous bug reports that I can modify
Just to be clear, though, and to avoid wasting everyone's time: In my proxy
public QModelIndex parent(QModelIndex child)
{
return child.parent();
}
without causing recursive parent() method calls leading to a stack
overflow. Correct?
I don't know. Are you asking a question, "I should be able to implement
..." does not read like a question, it would be more useful to cite your
reference to having that view first.
How would you write the same application using best-practice in C++. I
know you may not know but I am trying to lean on this question as being a
good exercise to getting you an answer for the QtJambi case. Maybe one of
the QtJambi devs can convert your Java code into C++ but you are probably
going to also need to supply a sufficiently complex real model data as
input so that every use-case can be checked. Not the blinkered view of the
use case that only shows up the problem. Also you need to explain the
non-obvious aspects of your model and also the non-obvious aspects of how
you expect the visual representation of the model to be rendered by Qt.
So what I am getting at with the last paragraph is that; if you can't
provide C++ version then you need to provide some extra information that
might exceed that of a Java example, i.e. the specification of the model
input data (with a sufficiently contrived complex example data-set), the
specification of the rendered/interactive aspects of the output visual
representation.
The QModelIndex maybe considered an advanced Qt C++ feature, so even C++
developers can have trouble using it in the best way.
If C++ does not have the same issue and the code is an agreed equivalent
then yes this should be escalated as something QtJambi should address.
But if what you are doing is not possible in C++ in the way you are doing
it then a StackOverflow maybe an acceptable error.
Nothing should make Java to crash, so that’s atleast a bug, even if the
Post by Samu Voutilainen
code
was wrong :)
Lets be clear. Java is not crashing.
A stack overflow (java.lang.**StackOverflowException) is a soft-error
that the JVM detects and advises the application that is running of the
problem so a recovery scenario can be executed.
Your recovery scenario may be that the application process exits. To some
that observe this behavior they might call it an application crash.
Darryl
Loading...