We want to generalize the icons shown next to descriptive phrases in various views so that plugins can customize both displays and controls based on context.
The first part of that work has now been merged to master. It is described in the sections below.
Badge and BadgeSet classes
The original DescriptivePhrase and PhraseContent classes exposed a fixed set of information with each phrase: object visibility and object color. The qtDescriptivePhraseDelegate would ask for this information via
QModelIndex::data() and add a third piece of information: a per-object-class icon to show each object’s type. One of the difficulties with this approach was that the PhraseContent class used a decorator pattern to override the visibility icon (originally, visibility was a property held on a model entity and the same across all views; now it is a per-view setting and not stored on SMTK components at all). Because each phrase had a decorator, extra memory was used and maintaining the phrases was trickier than it should have been.
Our first merge does not remove this, but adds a Badge class that functions differently. A single instance of each Badge is held by the PhraseModel in a BadgeSet. The qtDescriptivePhraseDelegate asks for an ordered vector of badges that applie to a give QModelIndex; they are returned by pointer. This means that individual phrases do not store badge information (a big space and complexity savings).
- a method to test whether they apply to a descriptive phrase or not
- a string holding an SVG icon to represent the badge (which may vary based on the content of the DescriptivePhrase)
- a tooltop string describing the badge to the user
action()method that user interfaces may invoke when users click on the badge.
A BadgeSet holds Badges in the order they should appear when rendering DescriptivePhrases. It is owned by the PhraseModel.
The second change we have made is to refactor PhraseModel a little bit to make configuration of badges (and other settings) easier. Before,
view::Manager had a lot of methods to register, unregister, and create an uninitialized PhraseModel object. Now,
view::Manager owns a PhraseModelFactory (which uses a new, generic Factory template) that exposes all those methods. It also forwards arguments to the PhraseModel constructor and all existing PhraseModel subclasses in SMTK now take a pointer to a
view::Configuration and a
view::Manager. Those constructors not only configure the PhraseModel object, they also get passed on to the BadgeSet and SubphraseGenerator classes owned by the PhraseModel.
Our next merge will use the work above to take over rendering of all icons in descriptive phrases and handling user interaction. We have the rendering code working and are implementing badges that perform the functions currently handled by fixed functions in DescriptivePhrase and PhraseContent. We will also be removing the dead code from PhraseContent and DescriptivePhrase.