Chart Model-View
Using Qt's Model-View
What are the pros and cons of using Qt's model-view to implement the charting widgets?
The main benefit of using Qt's model-view architecture is that is is already designed. This benefit can also be viewed as a stumbling block. Qt's model-view architecture is a little complicated. Unwanted behavior can be built in too. Qt uses private classes to do much of the work. These private classes make it difficult to override behavior. I ran into this a few times when building the flat tree view. The selection highlighting is still unresolved. Qt doesn't honor all the item flags when selecting items. Items can be made the current item even if they are not selectable.
--Mark Richardson 19:03, 10 Aug 2006 (EDT)
Another pro for using Qt's Model-View is that, when appropriate, we can use the same model with chart widgets and widgets that come with Qt. For example, if the x-y plot chart accepted values in a Qt model 2 column table, that same data could be put in a QTableView, which could be handy. If we were able to use the Qt selection classes, the selection could be easily linked, too.
--Ken 09:16, 11 Aug 2006 (EDT)
- Qt views always ask for the data as a string. The call will convert a number to a string, but doesn't give us an option of how to convert it. We would have to make our own delegate class to be able to format the numbers how we want them. The delegate could most likely be derived from Qt's concrete delegate class to provide most of the functionality. This isn't a show stopper, but something to be aware of.
- --Mark Richardson 11:49, 11 Aug 2006 (EDT)
Creating a New Model-View
What are the pros and cons of creating a new model-view architecture for the charting widgets?
Building our own model-view architecture will take time. It's unclear which path will take less time though. The main benefit of designing our own architecture is that it will behave exactly how we want it too. The interface can be tailored to fit PGraph. I think we can make the interaction between the model and the view simpler than Qt's without losing any functionality. The models in Qt are nice and simple, but the views are a little tangled. Our own design can be made more efficient than Qt's implementation as well.
--Mark Richardson 19:03, 10 Aug 2006 (EDT)
Another reason to write our own is the model complexity. The histogram widget has two layers: a histogram and a line plot. The two plot types share the bottom axis and use their own vertical axis. The Qt model would have to look something like:
root + Histogram | + Values | | + 1, 12, 5, etc. | + Range | + min, max + Line Chart + Line1 | + x1, x2, etc. | + y1, y2, etc. + Line2 + x1, x2, etc. + y1, y2, etc.
We would need to make a special subclass of Qt's model in order to ensure the data was formatted correctly. The model would not be easily viewed by other Qt views. We would need special code to get the correct root to display in the view. There would be a small sliver of time that the root would be the model root before it could be set to the correct root due to the way Qt handles this. It would be cleaner to have a custom model for other views that would just show the relavent portion of the larger model. It could even be used to combine two lines into one model.
Qt would also expect each piece of the model to be rendered. What would that mean for the axes? How would selection interact with the model? Using single selection, we would only be able to select one index, say x1 of line1. How would that look on the chart? we would have to use multiple selection to select x1 and y1 to select an entire point. The selection model would be difficult to use by other components in the system. We could combine the coordinates into one index, but then everyone needs to know about the special data type. The view would not be able to use the model's data() method to get the data. It would have to get the data in a special way. The same would be true of any component using the selection model.
The Qt model data type is qvariant, which allows for more types than the chart can render. Our model subclass would have to restrict what types are set.
All these complications in using the Qt model could be avoided by writing our own.
--Mark Richardson 17:16, 11 Aug 2006 (EDT)