Marble/GraphicsViewGeoParser

    From KDE TechBase
    Revision as of 14:01, 9 July 2009 by Mansona (talk | contribs) (Created page with '== GeoParser and the GeoGraphicsView == The current GeoData XML Parser ( aka. GeoParser ) has been implemented to specifically deal with our current GeoData data structure. If y...')
    (diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
    The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

    GeoParser and the GeoGraphicsView

    The current GeoData XML Parser ( aka. GeoParser ) has been implemented to specifically deal with our current GeoData data structure. If you want to see a more complete documentation of the GeoData library you can see the GeoData Library documentation. I will only describe the particular problem to the GeoGraphicsView implementation here.

    Parsing GeoData

    The GeoParser is an implementation of the QXMLStreamReader class in Qt, more information can be found here. There are other things built into this implementation that simplify the creation of a parser for new XML format document, namely:

    • The Concept of a TagHandler class that deals with only one tag
    • A Stack Item class that implements the Structural parts of the XML document
    • The collection class where the results of the XML parsing will be placed
    • A element dictionary that prevents the need for string comparison everywere

    To implement a new XML parser you need to

    1. compile an element dictionary of all of the available tags in the namespace
    2. implement a tag handler for each of these elements
    3. register that tag handler with the GeoParser

    Implementing a tag handler

    Each tag handler is called when the relevant XML tag is reached by the GeoParser ( which knows what tags to call by its registered tag list ). Each tag can access the stack data structure of the GeoParser as well as the Collection Data Structure of the GeoParser. This allows the tag handler to access items from the stack and allows root elements of the XML to add themselves to the collection data structure.

    Down Casting

    The unfortunate thing about the current implementation of the GeoParser is that when any item is added to the Collection Data Structure it is effectively downcast to the collection's type and removes any ability for 3rd party developers to add parsing capability to marble with functionality other than that which marble provides. This is not in line with the design of the QGraphicsItem implementation and something that is a current development effort to fix. What needs to happen is that an extra data model needs to be added to the GeoParser that is more in line with the idea of passing pointers around and that way we can conserve the typing information at run time.