title: Qt Data Model With Two Different Views
body: <p>All, I am having trouble determining a good way to handle this.  I have a Data Model, which we will call <code>MyData</code>.  I have modelled my data as a <code>QObject</code> and thus it has signals and slots.</p>
  
  <p>To modify any data in the model, you can either connect to its slots, or directly call the slots.  When that modification occurs, the model signals that its data has changed. eg:</p>
  
  <pre><code>class MyData : public QObject
  {
     ...
  public slots:
       void AddPoint(QPointF);
  
  signals:
       void AddedPoint(QPointF);
  };
  
  void MyData::AddPoint(QPointF p)
  {
      //added the point
      emit AddedPoint(p);
  }
  </code></pre>
  
  <p>Now my views are two seperate things:</p>
  
  <ol>
  <li>I have a <code>QGraphicsView</code>which represents the point using <code>QGraphicsEllipseItem</code></li>
  <li>I have a <code>QListView</code> which uses a <code>QAbstractItemModel</code> to list the points.</li>
  </ol>
  
  <p>I sync these two graphical views using signals and slots (I subclasses QGraphicsItem to inherit from QObject).</p>
  
  <p><strong>The question:</strong> When a table makes the change, it signals <code>MyData</code>, which in turn signals <code>AddedPoint</code> which is connected to the QGraphicsView.  <strong>However</strong>, <code>MyData::AddedPoint</code> is also connected to the table, and thus two identical points are added when it attempts to sync.  Could anyone offer any advice on how to proceed?</p>
  
  <hr>
  
  <p>My thoughts and ideas so far:</p>
  
  <ul>
  <li>I could check if the point exists, and prevent repeats.  Works great for insertions, not so great for removal and updating.</li>
  <li><strong>What I think is best the best approach:</strong> In the <code>MyData</code> slots, block the sender() for a second, then unblock.</li>
  </ul>
  
  <hr>
  
  <p><strong>Edit:</strong> <code>MyData</code> is really a "controller/interface" class, the real model uses OpenCV types and as thus I would like to keep it separated from the Qt architecture.</p>