Results 1 to 2 of 2

Thread: Tricky model/view data adapter design...

  1. #1
    Join Date
    May 2013
    Posts
    35
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Tricky model/view data adapter design...

    I have a rather tricky data adapter I'm trying to design for an applications user settings view...

    The Model / View architecture


    Config File -> Source Model -> Group Filter -> Setting Filter -> Adapter -> Setting View


    Config File


    Contains all settings (listed in their corresponding groups).
    A group with a multi-valued setting may appear as:


    [Library Group]
    Libraries = LibA
    Libraries = LibB
    Libraries = LibC


    Setting Model


    Directly represents the settings as they are shown in the config file, with each record representing one setting's value.


    Group Filter


    Filters the source model settings by each setting's group.


    Setting Filter


    Filters the group filter's results by the setting name. In the example above, the group filter (for "Library Group") and the setting filter ("Libraries") would both return three records.


    Adapter


    Manages the records returned by the setting filter, converting them into meaningful data to be displayed in the setting view.


    Setting View


    Widgets used to manage / represent the setting. In the example above, there are only four available values, LibA, LibB, LibC, and LibD. A checkbox view of the setting may look like:


    [X} LibA
    [X] LibB
    [X] LibC
    [ ] LibD


    Since a checkbox only understands "true / false", I need to convert the source model values into corresponding true/false values. (I could use bitflags here and dodge the whole issue, but it defeats the purpose of the example).
    Anyway, the data adapter step provides that conversion between the values available in the setting filter and the widgets.


    The Problem


    I've pulled it off without using the QDataWidgetMapper or any means that makes the view aware of changes in the model.

    I need to do that somehow.

    QDataWidgetMapper seems the most reasonable way to accomplish that, but doing so means I need to create a submodel which contains a fixed row for each checkbox in the view.

    So if the source model adds / deletes a value (apart from a user interaction with the view), is it just a matter of trapping the layoutChanged() signal from the source model, making the corresponding updates in the submodel, and signalling dataChanged() for the sake of the QDataWidgetMappers attached to the view widgets?

    I ask because I have to create a framework that manages different view types, which will require various custom adapters and I want to make sure my atomic structure is sufficient to manage that.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Tricky model/view data adapter design...

    Hmm... what exactly is the problem? Your "The Problem" section specifies what you didn't do and not what the problem is

    If the problem is making the view aware of the changes in the model then it is done by making the model emit proper signals (dataChanged, rowsInserted, rowsRemoved, etc.) when its contents change. Then the next layer can make use of those signals to emit its own, etc.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. model/view design advice appreciated
    By zaphod.b in forum Qt Programming
    Replies: 7
    Last Post: 3rd June 2013, 16:32
  2. Qt delegate model data and view
    By giusepped in forum Qt Programming
    Replies: 0
    Last Post: 27th July 2011, 11:30
  3. Replies: 1
    Last Post: 24th February 2011, 05:54
  4. Model / View - Design Question
    By antarctic in forum Qt Programming
    Replies: 8
    Last Post: 8th June 2009, 07:39
  5. Table view->model->set data
    By tulsi in forum Qt Programming
    Replies: 3
    Last Post: 21st April 2009, 08:36

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.