Feature #456

WSharedProxyModel: share abstract item models between applications

Added by Anonymous over 12 years ago. Updated over 10 years ago.

Target version:
Start date:
Due date:
% Done:


Estimated time:


IWSharedProxyModel needs to do two things:

  • protected access to the source model
  • propagate signals to connected views while holding the update lock (and correct WApplication::instance()) for that view's application.

The implementation in my previous email will probably not work, since it cannot avoid a dead-lock situation: one app tries to modify the model, while another app is busy reading from the model: the writing operation would block further reads until it is done (including signal propagation), but it would not be able to get the update lock for the application that is being blocked trying to read from the model.

The implementation should do:

  • when writing:
    1) grab update locks for all registered applications
    2) do the write operation in the source model
    3) for the signals emitted from the source model:
    • app->attachThread()
    • propagate to app

<!-- -->

  • when reading:
    no (additional) lock needed - writing will take the update lock of all registered applications, so it cannot happen concurrently with readers.
    reading is allow concurrently

<!-- -->

  • We make the calls to the signal accessor methods of WAbstractItemModel (such as changed()) virtual to have something like this:


typedef std::map<WApplication *app, Signal<WModelIndex, WModelIndex>> ChangedSignalsMap;
ChangedSignalsMap changedSignals_;

we could reimplement changed():

Signal<WModelIndex, WModelIndex>& WSharedProxyModel::changed()
  WApplication *app = WApplication::instance();
  return changedSignals_[app];

and the method that propagates the change from the source model:

void WSharedProxyModel::sourceModelChanged(const WModelIndex& m1, const WModelIndex& m2)
  for (ChangedSignalsMap::const_iterator i = changedSignals_.begin(); i != changedSignals_.end(); ++i) {
    i->first->attachThread(); // we already have the update lock cfr supra
    i->second.emit(m1, m2);

Updated by Koen Deforche over 10 years ago


Just a good idea on this.

We should be able to share the main body of logic in WBatchEditProxyModel here, to shield changes from the source model to the views until we have the lock. This will simplify the implementation of this class significantly !




Updated by Стойчо Стефанов Stoycho Stefanov over 10 years ago


I need this feature as well!


Updated by Niko Weh over 10 years ago

This functionality would be really helpful.

(Sorry should there be a "vote button" somewhere, i couldn't find it)

Also available in: Atom PDF