title: Qt 5.2 Model-View-Pattern: How to inform model object about changes in underlying data structure
body: <p>I have a class used for permanent storage of some item that are organized in a table-like manner. This class is totally unrelated to Qt and comes from a different library. Lets call this class <code>DataContainer</code> for the rest of this question. It provides std-c++ compatible iterators to access and manipulate the content.</p>
  
  <p>I need to display and modify that data through a Qt GUI. My idea was to create a class <code>DataContainerQtAdaptor</code> that inherits from <code>QAbstractTableModel</code> and stores a pointer to the <code>DataContainer</code> object. The <code>DataContainerQtAdaptor</code> serves as an adaptor to the <code>DataContainer</code> object and all manipulation from inside of my Qt app is done through this adaptor. Then I use a <code>QTableView</code> widget to display the information.</p>
  
  <p>Unfortunately the <code>DataContainer</code> might be changed by threads/processes. (For example think of <code>DataContainer</code> as some C++ class that encapsulates a database connection and that database might be changed by someone else.)</p>
  
  <p>Questions:</p>
  
  <p>1) Assume I have a function that is called everytime the internal structur of the <code>DataContainer</code> object has been changed. What is the correct function of the <code>QAbstractTableModel</code> that must be called to inform the model of the underlying change? I need something like "Dear Model, your persistent storage backend changed. Please, update yourself and emit a signal to every attached view in order to reflect this change".</p>
  
  <p>2) Lets say 1) is solved. What is the best way to avoid a "double" GUI update in case the change was triggered through the GUI? E.g: User clicks on a cell in the table widget -> table widget calls <code>setData</code> of the model -> model pushes change to backend -> backend triggers its own "onUpdate" function -> model re-reads complete backend (although it already knows the change) -> GUI is updated a second time</p>
  
  <p>3) The user should be able to insert new rows/columns through the GUI and put data into it. But the position is detemined by this data, because the backend keeps the data sorted. Hence, I have the following problem: The user decides to create a new row at the end and the new data is pushed to the backend. When the backend/model is re-read this data is normally not at the last position, but has been inserted somewhere in the middle and all other data has been moved forward. Ho do I keep all the properties of the the table view widget like "selection of a cell" in sync?</p>
  
  <p>I believe, there must be some simple standard solution to all these question, because it is the same way as <code>QFileSystemModel</code> works. The user selects a file and some other process creates a new file. The new file is displayed in the view and all subsequent rows move forward. The selection moves forward, too.</p>
  
  <p>Matthias</p>