title: Overriding QAbstractItemModel::index and accessing std::map
body: <p>In my program I want to use view/model pattern with view = QListView and my own model which I subclassed from QAbstractListModel. My data class looks like</p>
  
  <pre><code>class Avtomat
  {
  ...
   map&lt;QString, State *&gt; states;
  ...
  };
  </code></pre>
  
  <p>In my model class</p>
  
  <pre><code>class AvtomatModel : public QAbstractListModel
  {
      ...
      Avtomat a;
      ...
  };
  </code></pre>
  
  <p>I'm trying to overload QAbstractItemView::index function so that I'm able to provide interface for editing data map. 
  As index function takes int row argument I solved that problem by providing the following</p>
  
  <pre><code>State* Avtomat::pStateFromIndex(int index) const
  {
      map&lt;QString, State *&gt;::const_iterator i;
      int count = 0;
      for (i = states.begin(); i != states.end() &amp;&amp; count != index; ++i)
          ++count;
      return (*i).second;
  }
  </code></pre>
  
  <p>so in my index function I do like this</p>
  
  <pre><code>return createIndex(row, column, a.pStateFromIndex(row));
  </code></pre>
  
  <p>but that seems pretty ugly because I have O(n). Can you help me to design a better way to access my map using int index?</p>