[Smtk-developers] Qt model tree changes

David Thompson david.thompson at kitware.com
Tue Mar 10 16:13:53 EDT 2015


Hi Yumin et al.,

I think the following should get the tree view updating properly after operators are applied:

1. The smtk::model::SubphraseGenerator class should have a new pure virtual method:

    virtual void updateWithOperatorResult(
      DescriptivePhrase::Ptr treeRoot, OperatorResult result) = 0;

   The implementation should be in the SimpleModelSubphrases class (or a new
   subclass of it). The method would find the owning model and session of each
   entity listed in the result and (being careful to call areSubphrasesBuilt()
   before calling subphrases() on each descriptive phrase) descend the root
   until it finds the item's proper place in the tree. At that point,
   updateWithOperatorResult() would trigger callbacks before and after inserting
   new DescriptivePhrase(s) into the tree. It would trigger these callbacks
   like so:

2. The SimpleModelSubphrases class should provide a callback
   mechanism for indicating when phrases are being changed.
   The callback observers would be stored in the SimpleModelSubphrases
   class in a new protected ivar:

   std::set<smtk::model::PhraseTrigger> m_phraseTriggers;

   and new methods added mirroring the model Manager and Operator
   classes so that users can register for notifications:

     void observe(PhraseEventType event, PhraseCallback functionHandle, void* callData);
     void unobserve(PhraseEventType event, PhraseCallback functionHandle, void* callData);
     void trigger(PhraseEventType event, const smtk::model::DescriptivePhrasePtr src);

   The PhraseEventType, PhraseCallback, and PhraseTrigger types would mirror the
   ConditionCallback types in smtk/model/Event.h. So, inside updateWithOperatorResult(),
   it would look like:

     this->trigger(
       std::make_pair(WILL_ADD_CHILD, ENTITY_PHRASE),
       parentPhrasePtr, childIndex, numberOfChildren);
     // Create new DescriptivePhrase(s) here
     this->trigger(
       std::make_pair(DID_ADD_CHILD, ENTITY_PHRASE),
       parentPhrasePtr, childIndex, numberOfChildren);     


3. The owner/creator of the QEntityItemModel and SimpleModelSubphrases
   instances (the pqSMTKModelPanel in CMBv4) should register callbacks
   for the above triggers (i.e., call simpleModelSubphrases->observe()
   for {WILL,DID}_{ADD,DEL,MOD}_CHILD events) and have the callback
   methods invoke new methods on QEntityItemModel that do the following
   (for addition in this example):

    void QEntityItemModel::willAddSubphrases(...)
    {
      this->beginInsertRows(qidx, 0, nrows);
    }
    void QEntityItemModel::didAddSubphrases(...)
    {
      this->endInsertRows();
      emit dataChanged(qidx, qidx);
    }

   These callbacks are registered just once when the delegate and
   QEntityItemModel are created. I do not think modified items need
   a before+after callback... just running "emit dataChanged" on the
   Qt index of the descriptive phrase should be enough. But both addition
   and deletion need the 2-phase will{Add,Del} and did{Add,Del} calls.

4. Whenever the application creates an Operator, it should call

   smtk::model::OperatorPtr op;
   pqSMTKModelPanel* panel;
   op->observe(DID_OPERATE, pqSMTKModelPanel::processOperatorResult, panel);

   and implement pqSMTKModelPanel::processOperatorResult() to invoke
   the simpleModelSubphrases->updateWithOperatorResult() method with the
   operator result.

5. Change the Operator::operate method to add items to the OperatorResult
   attribute that indicate which entries in the "entities" item were added
   and which were just modified. Having this done automatically by the
   operator instead of by operation-specific subclasses greatly reduces
   the maintenance cost of the operator classes. The list of "expunged"
   entities is already separate from those modified and added.

	David


More information about the Smtk-developers mailing list