Marble/ModelView

From KDE Community Wiki
Revision as of 23:55, 14 August 2010 by Tgridel (talk | contribs)

ModelView framework in Marble

Marble uses Qt's Model/View framework as a way to signal updates to a model to interested parts. In that respect, a Model class can wrap any possible data.

The multiple models in Marble each fit the purpose of feeding some GeoData classes to interested widgets. The way those models are fed could be improved however:

Model and Data Location

  • At the moment, each Model contains the list/vector/tree of data it presents. This is not a problem per se, unless all those models present the same data, and retain their own copies. We should ensure that we do not make copies of data throughout models, but use pointers to the same data instead.

The solution to this is twofold:

    • keep data unique in one store (wherever that is, a Model class or a list in one Manager)
    • Try and manipulate references to the data in the Models in such a case: with one change to the central data, multiple models can be notified and each react differently for the views they feed.

Model or not Model

  • The Model-View framework is designed to hide the details of the model content, and to present it in a standardised way to views. The advantage of this solution is that the View need not know much about the data it presents.

This solution however is not a one size fit all, because an interested class with some knowledge of the GeoDataTypes for example would be far better off manipulating the methods of GeoData classes.

As a consequence, a choice should be made whether to access GeoData through the model-view framework (nice for a List Widget or for a generic presentation of 'data as a tree', really not so nice for a class which for example would like to calculate the bounding box of all geometric data of a GeoDataDocument, or even for the File read/write, as the knowledge of data types is really known).

State of the Model

There are multiple models with various levels of implementation. Some are needed, others should die...

Here is the list of Model class, and a description of how they are used.

QAbstractItemModel

It represents the list of all GeoDataDocument registered through the FileManager.

It has signals/slots to react to files being added or removed in the FileManager.

It is used by the GeometryLayer which renders all GeoDataGeometry related placemarks.

It represents a data file, parsed into a GeoDataDocument tree structure.

It is used by the DataViewPlugin debug plugin (and is broken atm)

QAbstractListModel

It represents the list of opened files. The FileManager appends the documents it opens.

It is used by the FileViewFloatItem and manipulated by the FileManager.

It represents the list of all Placemarks of all opened files. the PlaceMarkManager appends all the placemarks after reading a file.

It is used by the MarbleControlBox to provide the list of placemarks to search for, and by the PlacemarkLayout to determine layouting on the map.

It should be replaced by a more generic model, which would hold all open documents and provide both features and geometries. It could also be replaced with a ProxyModel around this new model.