Question

I'm doing a character animation editor.

My character is represented in a QTreeView like this

  • Character
    • Animation 0
      • Frame 0
      • Frame 1
      • Frame 2
    • Animation 1
      • Frame 3
      • Frame 4
      • Frame 5

And etc.

There is a basic abstract Item class that Character, Animation and Frame inherits from.

The restrictions are:

  • Character items can have any number of ONLY Animation items
  • Animations items can have any number of ONLY Frame items
  • Frame items can not have any children

Now, everything that inherits from Item have a name. Then every type of item adds its own attributes (Animation can have Wrap mode, FPS; Frame can have duration).

So each level of the tree has different data set.

Now I want to add another widget that allows editing the data of each Item. The widget will be broken into 3 parts (sections): Data related to character, data related to animation and data related to frame. When the user selects an item in the tree, the widget will autofill itself according to the following rules:

  1. If selected item is Character => Fill only character section
  2. If selected item is Animation => Fill the animation section + do step 1 with the character that is the parent of this animation
  3. If selected item is Frame => Fill the frame section + do step 2 with the animation that is the parent of this frame

I can distinguish between selected items (I can tell if it either Character, Animation of Frame). I can access the parent item from the selected child.

My problem is that I don't know how to map the data between my tree's model and the editing widgets. I looked into QDataWidgetMapper but it does not help, it looks like it works on models that have the same item, while my model have different items per level.

I might have a major design flaw, or I simply don't know how to achieve what I'm trying to implement.

I'd like some guidance.

P.S.

Here is an image of the main screen hierarchy and the 3 sections dmut hierarchy and section editing

Was it helpful?

Solution

Summary, from comments:

  1. Use QDataWidgetMapper for data mapping. You may create 3 mapping. For each frame.
  2. Use QStackedWidget for editor frames
  3. On each selection change - set mapping and show necessary widget.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top