PDA

View Full Version : Hierarchical Chart



fruzzo
2nd May 2011, 14:35
Hi,
I'm trying to create a chart like the following one, where I can expand/contrat horizontal lines:
http://www.kdab.com/images/stories/software/chart/gantt2.png

My idea is to implement the chart by a customized qtreeview...
You have some other idea?

d_stranz
3rd May 2011, 03:49
My idea is to implement the chart by a customized qtreeview...

You can probably get that to work, but it wouldn't be easy. QTreeView has protected virtual methods drawRow(), and drawBranches() that you could override to draw the bars and connectors. You would need a column in your tree model for every day in the Gantt chart.

QTreeView and the QAbstractItemModel it uses are designed to handle simple hierarchies where only column 0 of each row is allowed to have children. Is that how Gantt chart dependencies work? What happens for the case where you have a task that depends on two or more earlier tasks (that is Task3 cannot be started until Task1 and Task2 are both done)? I don't think you can display that in a QTreeView, although a customized QAbstractItemModel can handle almost any kind of graph-structured data.

You might be better off if you started with QAbstractItemView and QAbstractItemModel and wrote the drawing code yourself instead of try to hack away at QTreeView.

Edit: I think in graph-theory terms, the dependencies in a Gantt chart are modeled as a "directed acyclic graph" (DAG). It is "directed" in that the dependencies flow in one direction only (a later task can depend only on earlier ones) and "acyclic" in that there can't be any loops (which would mean an earlier task couldn't start until a later task was finished, which is impossible unless you have a time machine). There are lots of algorithms out there for manipulating DAGs, including such useful things as finding the shortest path between two nodes (which tells you the minimum time required to complete Task B starting at Task A), determining whether there are cycles (which aren't allowed in a Gantt chart), etc.

fruzzo
3rd May 2011, 08:37
Thanks for the suggestion...however I don't need of a Gantt chart but something that look like it...My work is simplified by absence of connectors, I have to draw only bars mapped over a timeline (h:m:s) without a subdivision in days so I haven't the requirement one column for every day.