title: When to emit dataChanged from a QAbstractItemModel
body: <p>In Qt, I have a model subclassing <code>QAbstractItemModel</code> - it's a tree displayed in a QTreeView.</p>
  
  <p>The model supports various forms of change which all work OK.  The two of relevance are:</p>
  
  <p>1) Some data in a small number of related rows changes</p>
  
  <p>2) A visualisation change means that the majority of rows should change their formatting - in particular they have a change of background highlighting.  Their <code>DisplayRole</code> data does not change.</p>
  
  <p>The current design deals with both of these in the same way: for every row that has any change the model emits <code>dataChanged(start_of_row_index,end_of_row_index)</code>.  I emit the signal for both parent rows that change and for any of their children that have changed.</p>
  
  <p>However, this performs badly in case 2 as the model gets big: a very large number of <code>dataChanged</code> signals are emitted.</p>
  
  <p>I have changed the code so that in case 2 the model emits <code>dataChanged</code> only for the (single) row that is the parent of the entire tree.</p>
  
  <p>This still appears to work correctly but does not accord with my understanding of the responsibilities of the model.  But I suspect I may be wrong.</p>
  
  <p>Perhaps I am misunderstanding the <code>dataChanged</code> signal?  Does it actually cause the view to update all children as well as the specified range?  Or can I avoid emitting <code>dataChanged</code> when it is not the <code>DisplayRole</code> that is changing?</p>
  
  <h2>Edited with my progress so far</h2>
  
  <p>As Jan points out, I ought to emit <code>dataChanged</code> either for most or all of the rows in case 2.</p>
  
  <p>My code originally did this by emitting <code>dataChanged</code> for every changed row but this is too expensive - the view takes too long to process all these signals.</p>
  
  <p>A possible solution could be to aggregate the <code>dataChanged</code> signal for any contiguous blocks of changed rows but this will still not perform well when, for example, every other row has changed - it would still emit too many signals.</p>
  
  <p>Ideally I would like to just tell the view to consider all data as potentially changed (but all indexes still valid - the layout unchanged).  This does not seem to be possible with a single signal.</p>
  
  <p>Because of a quirk of the <code>QTreeView</code> class, it is possible (though incorrect according to the spec) to emit only one <code>dataChanged(tl,br</code>) as long as <code>tl != br</code>.  I had this working and it passed our testing but left me nervous.</p>
  
  <p>I have settled for now on a version which traverses the tree and emits a single <code>dataChanged(tl,br)</code> for every parent (with tl,br spanning all the children of that parent).  This conforms to the model/view protocol and for our models it typically reduces the number of signals by about a factor of 10.</p>
  
  <p>It does not seem ideal however.  Any other suggestions anyone?</p>