SMTK
@SMTK_VERSION@
Simulation Modeling Tool Kit
|
Hold and maintain a descriptive phrase hierarchy. More...
#include <PhraseModel.h>
Classes | |
struct | Source |
Public Types | |
using | Observer = PhraseModelObserver |
Events that alter the phrase model trigger callbacks of this type. | |
using | Observers = PhraseModelObservers |
A collection of observers with runtime-modifiable call behaviors. | |
using | PhraseDecorator = std::function< void(smtk::view::DescriptivePhrasePtr)> |
Applications may have a model decorate its phrases by providing a method with this signature. | |
using | SourceVisitor = std::function< bool(const smtk::resource::ManagerPtr &, const smtk::operation::ManagerPtr &, const smtk::view::ManagerPtr &, const smtk::view::SelectionPtr &)> |
Subclasses (and others) may wish to invoke functions on the sources of data for the phrases. More... | |
using | SourceVisitorFunction = std::function< smtk::common::Visit(const smtk::resource::ManagerPtr &, const smtk::operation::ManagerPtr &, const smtk::view::ManagerPtr &, const smtk::view::SelectionPtr &)> |
Subclasses (and others) may wish to invoke functions on the sources of data for the phrases. More... | |
using | Operation = smtk::operation::Operation |
using | OperationPtr = smtk::operation::Operation::Ptr |
using | ComponentItemPtr = smtk::attribute::ComponentItemPtr |
using | Resource = smtk::resource::Resource |
Public Member Functions | |
smtkTypeMacroBase (smtk::view::PhraseModel) | |
smtkCreateMacro (smtk::view::PhraseModel) | |
virtual DescriptivePhrasePtr | root () const |
Return the root phrase of the hierarchy. | |
virtual void | updateChildren (smtk::view::DescriptivePhrasePtr plist, DescriptivePhrases &next, const std::vector< int > &idx) |
Infer changes between sets of subphrases; affect these changes; and notify observers. | |
virtual void | triggerDataChanged () |
Manually specify that all rows should be updated (but to keep the expanded/collapsed state). | |
virtual void | triggerDataChangedFor (smtk::resource::ComponentPtr comp) |
Manually specify that all rows with their relatedComponent() == comp should be updated. | |
Observers & | observers () |
Return the observers associated with this phrase model. | |
const Observers & | observers () const |
smtk::operation::ManagerPtr | operationManager () const |
Return the operationManager for the first Source registered. | |
void | setMutableAspects (int mutableAspects) |
Set what aspects of top-level phrases should be user-editable. More... | |
int | mutableAspects () const |
Get what aspects of top-level phrases should be user-editable. More... | |
ManagerPtr | manager () const |
PhraseModels that are managed have a non-null pointer to their manager. | |
const BadgeSet & | badges () const |
Return the badges that may apply to phrases in this model. | |
BadgeSet & | badges () |
const UUIDsToPhrasesMap & | uuidPhraseMap () const |
Return the map between persistent object IDs and Descriptive Phrases. | |
smtk::common::ThreadPool< DescriptivePhrases > & | threadPool () |
Static Public Member Functions | |
static SubphraseGeneratorPtr | configureSubphraseGenerator (const Configuration *, Manager *) |
A method subclasses may call to prepare a subphrase generator. More... | |
static std::multimap< std::string, std::string > | configureFilterStrings (const Configuration *config, Manager *manager) |
A method subclasses may call to obtain filter strings. | |
Public Attributes | |
friend | Manager |
Protected Member Functions | |
PhraseModel (const Configuration *config, Manager *manager) | |
virtual void | handleSelectionEvent (const std::string &src, smtk::view::SelectionPtr seln) |
A method called when a selection is modified. | |
virtual void | handleResourceEvent (const Resource &, smtk::resource::EventType) |
A method called when a resource manager adds or removes a resource. More... | |
virtual int | handleOperationEvent (const Operation &op, operation::EventType e, const Operation::Result &res) |
A method called when operators have modified one or more resources. More... | |
virtual void | processResource (const std::shared_ptr< smtk::resource::Resource > &resource, bool adding) |
This is invoked from within handleOperationEvent when a resource is being added or removed. More... | |
void | removeChildren (const std::vector< int > &parentIdx, int childRange[2]) |
Given the index of parent phrase and a range of its children, delete them. More... | |
void | setPhraseParent (const DescriptivePhrasePtr &phrase, const DescriptivePhrasePtr &parent) const |
Set the Parent of a Descriptive Phrase. | |
virtual void | handleExpunged (const smtk::resource::PersistentObjectSet &expungedObjects) |
Called to deal with resources/components being removed as a result of an operation. | |
virtual void | handleModified (const smtk::resource::PersistentObjectSet &modifiedObjects) |
Called to deal with resources/components marked as modified by the operation. | |
virtual void | handleCreated (const smtk::resource::PersistentObjectSet &createdObjects) |
Called to deal with resources/components being created as a result of an operation. | |
virtual void | redecorate () |
Un-decorate and re-decorate every phrase in the current hierarchy. More... | |
virtual void | trigger (DescriptivePhrasePtr phr, PhraseModelEvent e, const std::vector< int > &src, const std::vector< int > &dst, const std::vector< int > &refs) |
Make changes to the phrase hierarchy. More... | |
void | recursiveTrigger (DescriptivePhrasePtr phr, std::vector< int > &tl, std::vector< int > &br) |
This is an utility called by triggerDataChanged() that repeatedly calls trigger for every phrase that has children (in order to effect a redraw of the entire model, but without rows being inserted/removed/repositioned). More... | |
void | removeFromMap (const DescriptivePhrasePtr &phr) |
Remove the Descriptive Phrase and its descendants from the Persistent Object / Phrases Map. | |
void | insertIntoMap (const DescriptivePhrasePtr &phrase) |
Insert the Descriptive Phrase and its descendants into the Persistent Object / Phrases Map. | |
Protected Attributes | |
std::list< Source > | m_sources |
UUIDsToPhrasesMap | m_objectMap |
Observers | m_observers |
PhraseDecorator | m_decorator |
BadgeSet | m_badges |
int | m_mutableAspects { PhraseContent::EVERYTHING } |
WeakManagerPtr | m_manager |
bool | m_updatingChildren = false |
smtk::common::ThreadPool< DescriptivePhrases > | m_pool |
std::atomic< bool > | m_pending { false } |
virtual bool | addSource (const smtk::common::TypeContainer &managers) |
Manage sources of information to display as phrases. More... | |
virtual bool | removeSource (const smtk::common::TypeContainer &managers) |
Indicate managers that should no longer be monitored for changes. | |
virtual bool | resetSources () |
Stop listening for changes from all sources. | |
virtual void | visitSources (SourceVisitorFunction visitor) |
Invoke the visitor function on each source that has been added to the model. | |
static smtk::operation::Observers::Priority | operationObserverPriority () |
The priority used for observing operation results. More... | |
Hold and maintain a descriptive phrase hierarchy.
This class holds the root descriptive phrase in a hierarchy and tracks changes in SMTK resources in order to keep the hierarchy up to date.
In the model-view-controller pattern, this class is a model – hence its name. It is a model that maintains a descriptive phrase hierarchy for some particular purpose: subclasses will determine that purpose, whether it be to illustrate the entire set of resources in memory, to show the current selection, to preview changes associated with an operation, etc.
This class accepts observers for events that result in changes to the hierarchy so that user-interface-specific code can present data in this model.
using smtk::view::PhraseModel::SourceVisitor = std::function<bool( const smtk::resource::ManagerPtr&, const smtk::operation::ManagerPtr&, const smtk::view::ManagerPtr&, const smtk::view::SelectionPtr&)> |
Subclasses (and others) may wish to invoke functions on the sources of data for the phrases.
Note that this is an old format that is being deprecated.
using smtk::view::PhraseModel::SourceVisitorFunction = std::function<smtk::common::Visit( const smtk::resource::ManagerPtr&, const smtk::operation::ManagerPtr&, const smtk::view::ManagerPtr&, const smtk::view::SelectionPtr&)> |
Subclasses (and others) may wish to invoke functions on the sources of data for the phrases.
Note that this is an current format that is being supported.
|
virtual |
Manage sources of information to display as phrases.
These methods provide a way for the phrase model to stay informed of changes to resources in SMTK. Adding sources results in callbacks being registered; then, when SMTK resources are modified, the different handleXXX() methods are invoked so that subclasses of PhraseModel can update the phrase hierarcy as required. Indicate the managers that should be monitored for changes.
|
static |
A method subclasses may call to prepare a subphrase generator.
PhraseModel's constructor does not call it since it does not create the root DescriptivePhrase to which the subphrase generator is attached.
|
protectedvirtual |
A method called when operators have modified one or more resources.
You may subclass this method or, perhaps preferrably, one of the specific methods that this method invokes (handleExpunged, handleModified, handleCreated). The only case where overriding this method is required (as opposed to those listed above) is when you wish to respond to events other than Operation::DID_OPERATE.
Reimplemented in smtk::view::ResourcePhraseModel.
|
inlineprotectedvirtual |
A method called when a resource manager adds or removes a resource.
By default, this does nothing. Subclasses may override it if needed, but most resource events should be handled by observing operations that act on resources rather than by observing the resource manager.
|
inline |
Get what aspects of top-level phrases should be user-editable.
Valid bits are from the PhraseContent::ContentType enum.
|
static |
The priority used for observing operation results.
Since other application UI elements may need to observe operations and modify the phrase model (e.g., to change the selection or expand/collapse subtrees), this class uses a priority that is higher than the default. Your application can then ensure its observer(s) run at a lower priority if it needs phrases updated before it runs.
|
protectedvirtual |
This is invoked from within handleOperationEvent when a resource is being added or removed.
The base implementation does nothing; it is up to subclasses to implement this as needed.
When adding is true, an operation has created resource and indicated it should be managed by inserting it into the result's "resource" ResourceItem. When adding is false, an operation has requested that resource should be removed from its resource manager by inserting it into the result's "resourcesToExpunge" ResourceItem.
|
protected |
This is an utility called by triggerDataChanged() that repeatedly calls trigger for every phrase that has children (in order to effect a redraw of the entire model, but without rows being inserted/removed/repositioned).
This is undesirable, but Qt provides no other documented method to achieve the effect.
|
protectedvirtual |
Un-decorate and re-decorate every phrase in the current hierarchy.
This is called by setDecorator() to ensure that phrases which were prepared before the current decorator are properly prepared.
To un-decorate, all but the final PhraseContent object are popped from each phrase. Then, the phrase-model's current decorator is invoked on every phrase.
This process assumes that if you have multiple decorator functions, they chain each other.
|
protected |
Given the index of parent phrase and a range of its children, delete them.
This properly signals any observers as it removes the specified children. It is called from handleExpunged.
|
inline |
Set what aspects of top-level phrases should be user-editable.
Note that this does not specify the means by which the editing will occur; it is merely a guide that the UI layers which own/use instances of this class may use to determine which editing actions to make available.
Valid bits are from the PhraseContent::ContentType enum. By default, this is PhraseContent::EVERYTHING.
|
protectedvirtual |
Make changes to the phrase hierarchy.
These methods may be used inside your subclass's overrides of the handleXXX() calls in order to trigger the proper events for GUI elements watching the PhraseModel. Modify the children of plist to be next; plist is located at idx in the hierarchy. "Emit" an event (by calling all observers with the given parameters)