<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://www.shadoware.org/feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
  <title>Shadoware.Org - Mot-clé - article</title>
  <link>http://www.shadoware.org/</link>
  <atom:link href="http://www.shadoware.org/index.php/feed/tag/article/rss2" rel="self" type="application/rss+xml"/>
  <description>Moi, mes idées, mes logiciels ...</description>
  <language>fr</language>
  <pubDate>Mon, 06 Feb 2012 15:38:11 +0100</pubDate>
  <copyright>Ulrich VANDENHEKKE</copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>Quelques soucis de Liens morts</title>
    <link>http://www.shadoware.org/post/Quelques-soucis-de-Liens-morts</link>
    <guid isPermaLink="false">urn:md5:89de840814e85dbc9ab91db012545649</guid>
    <pubDate>Fri, 28 Jan 2011 08:14:00 +0100</pubDate>
    <dc:creator>Ulrich Van Den Hekke</dc:creator>
        <category>Ma Vie</category>
        <category>article</category><category>blog</category><category>bug</category><category>lienmort</category><category>stats</category>    
    <description>    &lt;p&gt;Bonjour à tous,&lt;/p&gt;


&lt;p&gt;Je viens de remarquer et de corriger une série de lien mort sur mon site :(.&lt;/p&gt;


&lt;p&gt;En effet, j'ai changé récemment les chemins de mon site (pour ne plus afficher le &lt;code&gt;index.php&lt;/code&gt; dans mon site et aussi le &lt;code&gt;/shadoware&lt;/code&gt; pour l'accès au fichiers) et cela à pourris tout mes liens &lt;img src=&quot;/dotclear/themes/default/smilies/sad.png&quot; alt=&quot;:(&quot; class=&quot;smiley&quot; /&gt; . Du coup beaucoup de téléchargement était HS. Bon la situation est rétabli (sauf pour toute images se trouvant dans la galerie, celle-ci n'existant plus pour l'instant, je déplace cette partie sur une galerie &lt;a href=&quot;http://piwigo.org/&quot; hreflang=&quot;en&quot; title=&quot;Piwigo is a photo gallery ...&quot;&gt;piwigo&lt;/a&gt;).&lt;/p&gt;


&lt;p&gt;Bref quelques modifications, et les billets sont à nouveau a peu prés propre mais si vous avez une quelconque remarque, n'hésitez pas.&lt;/p&gt;


&lt;p&gt;J'en profite aussi pour tester &lt;a href=&quot;http://piwik.org/&quot; hreflang=&quot;en&quot; title=&quot;Web analytics - Open source&quot;&gt;Piwik&lt;/a&gt;, en plus de mon ancien logiciel de stat &lt;a href=&quot;http://www.mrunix.net/webalizer/&quot; hreflang=&quot;en&quot;&gt;Webalizer.&lt;/a&gt; afin de voir le genre d'information qu'il nous donne sa pertinence et de comparer les deux logiciels de stats.&lt;/p&gt;</description>
    
    
    
          <comments>http://www.shadoware.org/post/Quelques-soucis-de-Liens-morts#comment-form</comments>
      <wfw:comment>http://www.shadoware.org/post/Quelques-soucis-de-Liens-morts#comment-form</wfw:comment>
      <wfw:commentRss>http://www.shadoware.org/feed/atom/comments/629</wfw:commentRss>
      </item>
    
  <item>
    <title>[Qt] Transformation d'une vue tableau en une vue hiérarchique</title>
    <link>http://www.shadoware.org/post/2009/09/10/%5BQt%5D-Transformation-d-une-vue-tableau-en-une-vue-hi%C3%A9rarchique</link>
    <guid isPermaLink="false">urn:md5:a2b92942f5d31facf73b6df365c09893</guid>
    <pubDate>Mon, 21 Sep 2009 13:50:00 +0200</pubDate>
    <dc:creator>Ulrich Van Den Hekke</dc:creator>
        <category>C++</category>
        <category>article</category><category>libre</category><category>model</category><category>nokia</category><category>planet</category><category>qt</category><category>trolltech</category>    
    <description>&lt;p&gt;Pour visualiser des données internes à l'écran, Nokia/Qt nous propose l'architecture MVC à l'aide des classes QAbstractItemModel et de ses sous classes (QAbstractListModel, QAbstractTableModel, ...). Le but de l'architecture MVC est de séparer la représentation mémoire des données, de l'affichage qu'elles auront.&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://www.shadoware.org/public/billets/qt/table2tree/mvc1.png&quot; alt=&quot;mvc1.png&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;mvc1.png, sept. 2009&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Si les données sont par exemple issue d'une requête SQL, le modèle QSqlQueryModel permet de représenter la sélection SQL, à l'écran dans un composant QTableView. Ces données sont alors représentées sous forme d'un tableau deux dimensions.&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://www.shadoware.org/public/billets/qt/table2tree/tableau.png&quot; alt=&quot;tableau.png&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;tableau.png, sept. 2009&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Si l'on veut représenter les dossiers de l'ordinateur, le modèle QDirView permet d'afficher les données de façon hiérarchique.&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://www.shadoware.org/public/billets/qt/table2tree/qdirview.png&quot; alt=&quot;qdirview.png&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;qdirview.png, sept. 2009&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Il est également possible d'écrire nos propres modèles pour représenter nos propres données.&lt;/p&gt;


&lt;p&gt;Le but de cet article est de présenter l'écriture d'un modèle, transformant une vue plane (tableau deux dimensions) en vue hiérarchique. Pour cela nous allons prendre l'exemple de l'affichage d'une liste de catégorie&lt;sup&gt;[&lt;a href=&quot;http://www.shadoware.org/post/2009/09/10/%5BQt%5D-Transformation-d-une-vue-tableau-en-une-vue-hi%C3%A9rarchique#pnote-623-1&quot; id=&quot;rev-pnote-623-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt;.&lt;/p&gt;
&lt;div class=&quot;footnotes&quot;&gt;&lt;h4&gt;Notes&lt;/h4&gt;
&lt;p&gt;[&lt;a href=&quot;http://www.shadoware.org/post/2009/09/10/%5BQt%5D-Transformation-d-une-vue-tableau-en-une-vue-hi%C3%A9rarchique#rev-pnote-623-1&quot; id=&quot;pnote-623-1&quot;&gt;1&lt;/a&gt;] La construction de notre objet s'est basé sur l'analyse de l'objet QSortFilterProxyModel de Nokia.&lt;/p&gt;&lt;/div&gt;
    &lt;h3&gt;Présentation de l'exemple&lt;/h3&gt;


&lt;p&gt;Nous allons voir ci-dessous comment transformer une vue plane en une vue hiérarchique. Pour cela nous allons prendre l'exemple d'une liste de catégorie. Ces catégories seront stockées dans une base de données Sqlite. Ceci n'a pas d'importance mais permet d'expliquer pourquoi les données en mémoire ne sont pas déjà sous forme hiérarchique.&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://www.shadoware.org/public/billets/qt/table2tree/proxymodel.png&quot; alt=&quot;proxymodel.png&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;proxymodel.png, sept. 2009&quot; /&gt;&lt;/p&gt;


&lt;p&gt;La description d'une catégorie passe donc par&amp;nbsp;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;un identifiant unique appelé &lt;em&gt;id&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;un nom de catégorie&lt;/li&gt;
&lt;li&gt;un lien vers la catégorie parente appelé &lt;em&gt;parent_id&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;C'est le champ &lt;em&gt;parent_id&lt;/em&gt; qui permettra de déterminer dans quelle catégorie notre sous-catégorie se trouve. Dans notre cas, &lt;em&gt;test3&lt;/em&gt; a comme &lt;em&gt;parent_id&lt;/em&gt; l'identifiant 11 qui est la catégorie &lt;em&gt;test&lt;/em&gt;.&lt;/p&gt;


&lt;p&gt;Dans notre exemple, nous allons nous conditionner à un modèle en lecture seul. Il est également possible de faire un modèle en lecture/écriture mais nous n'en parlerons pas dans cet article. Nous nous cantonnerons donc à un modèle lecture seul sur un modèle source de type &lt;em&gt;QSqlTableView&lt;/em&gt;. (Un modèle en lecture/écriture peut nécessiter de mettre à jour notre structure, ce qui peut être assez compliqué, par exemple en cas de changement de la catégorie parente).&lt;/p&gt;


&lt;h3&gt;Déclaration d'un modèle&lt;/h3&gt;


&lt;h4&gt;Qu'est qu'un proxy&amp;nbsp;?&lt;/h4&gt;


&lt;p&gt;Notre interface se basera sur la classe &lt;em&gt;QAbstractProxyModel&lt;/em&gt;. Le but de cette classe est de permettre de faire une transposition entre un premier modèle et une vue. Elle peut par exemple (à l'aide de &lt;em&gt;QSortFilterProxyModel&lt;/em&gt;) permettre de filtrer ou trier les données d'une vue.&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://www.shadoware.org/public/billets/qt/table2tree/mvc.png&quot; alt=&quot;mvc.png&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;mvc.png, sept. 2009&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Cette vue nous permettra de faire la transposition entre un modèle tableau et une vue arborescente.&lt;/p&gt;


&lt;h4&gt;Interface du proxy&lt;/h4&gt;


&lt;p&gt;Les méthodes à ré-implémenter pour faire fonctionner une proxy, sont les suivantes&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;virtual QModelIndex index&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;int&lt;/span&gt; row&lt;span style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;int&lt;/span&gt; column&lt;span style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;const&lt;/span&gt; QModelIndex &lt;span style=&quot;color: #339933;&quot;&gt;&amp;amp;&lt;/span&gt; parent &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
virtual QModelIndex parent&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;const&lt;/span&gt; QModelIndex &lt;span style=&quot;color: #339933;&quot;&gt;&amp;amp;&lt;/span&gt; index &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
virtual &lt;span style=&quot;color: #993333;&quot;&gt;int&lt;/span&gt; rowCount&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;const&lt;/span&gt; QModelIndex &lt;span style=&quot;color: #339933;&quot;&gt;&amp;amp;&lt;/span&gt; parent &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; QModelIndex&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
virtual &lt;span style=&quot;color: #993333;&quot;&gt;int&lt;/span&gt; columnCount&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;const&lt;/span&gt; QModelIndex &lt;span style=&quot;color: #339933;&quot;&gt;&amp;amp;&lt;/span&gt; parent &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; QModelIndex&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
virtual QModelIndex mapFromSource &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;const&lt;/span&gt; QModelIndex &lt;span style=&quot;color: #339933;&quot;&gt;&amp;amp;&lt;/span&gt; sourceIndex &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
virtual QModelIndex mapToSource &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;const&lt;/span&gt; QModelIndex &lt;span style=&quot;color: #339933;&quot;&gt;&amp;amp;&lt;/span&gt; proxyIndex &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Les quatre premières méthodes appartiennent à l'objet &lt;em&gt;QAbstractItemModel&lt;/em&gt; et seront questionnées par la vue (liste, arbre, …) pour connaître la représentation à l'écran.&lt;/p&gt;


&lt;p&gt;Les méthodes &lt;em&gt;mapFromSource()&lt;/em&gt;, et &lt;em&gt;mapToSource()&lt;/em&gt; sont à implémenter pour l'objet &lt;em&gt;QAbstractProxyModel&lt;/em&gt;. Elles permettent de faire la liaison entre les indexes (&lt;em&gt;QModelIndex&lt;/em&gt;) du modèle d'origine et les indexes du nouveau modèle.&lt;/p&gt;


&lt;p&gt;Les méthodes &lt;em&gt;data()&lt;/em&gt;, &lt;em&gt;headerData()&lt;/em&gt;, &lt;em&gt;flags()&lt;/em&gt; sont réimplémentées par l'objet &lt;em&gt;QAbstractProxyModel&lt;/em&gt; et utilisent les méthodes &lt;em&gt;mapFromSource()&lt;/em&gt; et &lt;em&gt;mapToSource()&lt;/em&gt; pour, lors de l'appel d'une de ces méthodes, récupérer les informations stockées sur le modèle d'origine.&lt;/p&gt;


&lt;p&gt;Des méthodes &lt;em&gt;sourceModel()&lt;/em&gt; et &lt;em&gt;setSourceModel()&lt;/em&gt; permettent de spécifier le modèle d'origine.&lt;/p&gt;


&lt;h3&gt;Implémentation de notre modèle&lt;/h3&gt;


&lt;h4&gt;Structure interne&lt;/h4&gt;


&lt;p&gt;Nous allons, dans cette partie, parler de la structure interne utilisée par notre objet.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #993333;&quot;&gt;struct&lt;/span&gt; Mapping &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span style=&quot;color: #993333;&quot;&gt;int&lt;/span&gt; id&lt;span style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt; parrentId&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
	&lt;span style=&quot;color: #993333;&quot;&gt;int&lt;/span&gt; index&lt;span style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt; parentIndex&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
	QVector&lt;span style=&quot;color: #339933;&quot;&gt;&amp;lt;&lt;/span&gt;int&lt;span style=&quot;color: #339933;&quot;&gt;&amp;gt;&lt;/span&gt; source_rows&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #993333;&quot;&gt;typedef&lt;/span&gt; QMap&lt;span style=&quot;color: #339933;&quot;&gt;&amp;lt;&lt;/span&gt;int&lt;span style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;Mapping&lt;span style=&quot;color: #339933;&quot;&gt;*&amp;gt;&lt;/span&gt; IndexMap&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
IndexMap m_sourcesIndexMapping&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
QHash&lt;span style=&quot;color: #339933;&quot;&gt;&amp;lt;&lt;/span&gt;int&lt;span style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt;int&lt;span style=&quot;color: #339933;&quot;&gt;&amp;gt;&lt;/span&gt; m_categoryIdMapping&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Nous allons créer une structure &lt;em&gt;Mapping&lt;/em&gt; qui associera pour une ligne dans le modèle source, les informations concernant&amp;nbsp;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;l'identifiant de la ligne.&lt;/li&gt;
&lt;li&gt;l'identifiant de la ligne parente.&lt;/li&gt;
&lt;li&gt;l'index dans  le modèle source.&lt;/li&gt;
&lt;li&gt;l'index du parent dans le modèle source.&lt;/li&gt;
&lt;li&gt;la liste des indexes dans le modèle source des enfants dans notre modèle.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Une table de hashage permettra de retrouver à partir d'un identifiant (id), la ligne dans le modèle source correspondante. On ne gardera que la seconde colonne (le nom de la catégorie), on ne fera donc l'association qu'entre le nom de la colonne de notre modèle et le modèle source en dure dans le programme.&lt;/p&gt;


&lt;h4&gt;createMapping()&lt;/h4&gt;


&lt;p&gt;Le but de cette méthode est de générer l'arborescence qui sera ensuite utilisée dans la suite des méthodes. Cette arborescence étant générée une fois pour toute (ou à chaque fois que le modèle source sera réinitialisé), il faudra parcourir l'ensemble des lignes du modèle source pour construire notre arbre. Parcourir l'ensemble des lignes du modèle source peut prendre du temps si ce dernier contient beaucoup de ligne.&lt;/p&gt;


&lt;p&gt;Nous allons considérer dans la suite, que l'identifiant de ligne 1 (id) correspond à la catégorie de plus haut niveau (ci-dessus du nom de &lt;em&gt;Categories&lt;/em&gt;). Nous allons créer une catégorie fictive 0 qui correspondra à la racine de notre modèle. Cette catégorie sera donc la catégorie parente de celle à l'identifiant 1.
Dans notre modèle source, la catégorie 0 n'a pas d'équivalence parmi les lignes du modèle source. Nous allons donc lui associer la ligne -1 dans le modèle source.&lt;/p&gt;


&lt;p&gt;Maintenant voyons la génération de la structure interne.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;qDeleteAll&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; m_sourcesIndexMapping &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
m_sourcesIndexMapping.&lt;span style=&quot;color: #202020;&quot;&gt;clear&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
m_categoryIdMapping.&lt;span style=&quot;color: #202020;&quot;&gt;clear&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Nous commençons ci-dessous par nettoyer les différentes structures afin de les régénérer. Il faudra à la suite de la création du mapping appeler la méthode &lt;em&gt;reset()&lt;/em&gt; afin de prévenir la vue que l'ensemble des indexes du modèle sont obsolètes.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #993333;&quot;&gt;int&lt;/span&gt; source_rows &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; m_sourceModel&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;rowCount&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #b1b100;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;int&lt;/span&gt; i &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt; i &lt;span style=&quot;color: #339933;&quot;&gt;&amp;lt;&lt;/span&gt; source_rows&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;++&lt;/span&gt;i &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#123;&lt;/span&gt;
	Mapping &lt;span style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt; m &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; new Mapping&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
	IndexMap&lt;span style=&quot;color: #339933;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #202020;&quot;&gt;const_iterator&lt;/span&gt; it &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; IndexMap&lt;span style=&quot;color: #339933;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #202020;&quot;&gt;const_iterator&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; m_sourcesIndexMapping.&lt;span style=&quot;color: #202020;&quot;&gt;insert&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; i&lt;span style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt; m &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
	m&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;index &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; i&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
	m&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;parrentId &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
	m&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;parentIndex &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; i &lt;span style=&quot;color: #339933;&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#123;&lt;/span&gt;
		QSqlRecord record &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; m_sourceModel&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;record&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; i &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
		m_categoryIdMapping&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#91;&lt;/span&gt; record.&lt;span style=&quot;color: #202020;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; list_id &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #202020;&quot;&gt;toInt&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; i&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
		m&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;id &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; record.&lt;span style=&quot;color: #202020;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; list_id &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #202020;&quot;&gt;toInt&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
	&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #666666; font-style: italic;&quot;&gt;// Create the root Item&lt;/span&gt;
		m&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;id &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
		m_categoryIdMapping&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
	&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Nous récupérons le nombre de ligne dans le modèle source et commençons à initialiser notre structure. Le but de cette boucle est surtout d'initialiser dans notre correspondance identifiant/index (&lt;em&gt;m_categoryIdMapping&lt;/em&gt;), l'emplacement des identifiants dans notre tableau. Ainsi dans la suite lorsque l'on essaiera d'associer une ligne à son parent, nous pourrons savoir à quel emplacement retrouver notre id dans la structure &lt;em&gt;m_sourcesIndexMapping&lt;/em&gt;.&lt;/p&gt;


&lt;p&gt;Nous profitons également de cette boucle pour initialiser les différents champs de notre structure comme l'index (qui correspond à la ligne dans le modèle source), et l'id qui correspond à un identifiant unique dans notre liste.&lt;/p&gt;


&lt;p&gt;Nous n'oublions pas notre cas particulier que représente notre racine (ligne source -1 inexistante).&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;int&lt;/span&gt; i &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt; i &lt;span style=&quot;color: #339933;&quot;&gt;&amp;lt;&lt;/span&gt; source_rows&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;++&lt;/span&gt;i &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#123;&lt;/span&gt;
	QSqlRecord record &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; m_sourceModel&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;record&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; i &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	&lt;span style=&quot;color: #993333;&quot;&gt;int&lt;/span&gt; parentCategoryId &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; record.&lt;span style=&quot;color: #202020;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; list_parentid &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #202020;&quot;&gt;toInt&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
	&lt;span style=&quot;color: #993333;&quot;&gt;int&lt;/span&gt; parentCategoryIndex &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; m_categoryIdMapping.&lt;span style=&quot;color: #202020;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; parentCategoryId&lt;span style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;2&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
	Q_ASSERT&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; parentCategoryIndex &lt;span style=&quot;color: #339933;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;2&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
	Mapping &lt;span style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt; mapping &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; m_sourcesIndexMapping.&lt;span style=&quot;color: #202020;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; i &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
	mapping&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;parentIndex &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; parentCategoryIndex&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
	mapping&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;parrentId   &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; parentCategoryId&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	Mapping &lt;span style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt; categoryMapping &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; m_sourcesIndexMapping.&lt;span style=&quot;color: #202020;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; parentCategoryIndex &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
	categoryMapping&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;source_rows.&lt;span style=&quot;color: #202020;&quot;&gt;append&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; i &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Enfin pour chaque enregistrement de notre modèle source, nous récupérons l'identifiant du parent et   recherchons dans la structure que nous venons de créer l'index dans le modèle source de la  catégorie parente.&lt;/p&gt;


&lt;p&gt;Ces valeurs sont alors renseignées dans le modèle. Nos ajoutons également dans la structure de &lt;em&gt;mapping&lt;/em&gt; de la catégorie parent, notre ligne dans la liste des enfants.&lt;/p&gt;


&lt;p&gt;Notre structure est ainsi complètement initialisé. Un identifiant connaît donc son parent, et la liste de ses enfants. C'est sur cette structure que se basera le reste des méthodes de notre modèle.&lt;/p&gt;


&lt;h4&gt;mapFromSource()&lt;/h4&gt;


&lt;p&gt;Le but de cette méthode est de convertir notre index venant du modèle source vers un index de notre modèle à nous.&lt;/p&gt;


&lt;p&gt;L'index du modèle source nous donne l'emplacement de la donnée dans le modèle source sous forme (ligne, colonne) alors que l'index de notre modèle doit donner l'emplacement dans notre modèle sous la forme (ligne, colonne, pointeur indiquant le parent).&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;!&lt;/span&gt; sourceIndex.&lt;span style=&quot;color: #202020;&quot;&gt;isValid&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; QModelIndex&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; sourceIndex.&lt;span style=&quot;color: #202020;&quot;&gt;model&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;!=&lt;/span&gt; m_sourceModel &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#123;&lt;/span&gt;
	qWarning&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;CategoryItemModel: index from wrong model passed to mapFromSource&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
	&lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; QModelIndex&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Il faut donc d'abord vérifier que l'index du modèle source est valide. S'il n'est pas valide, alors il ne sera pas valide non plus dans notre modèle à nous.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #993333;&quot;&gt;int&lt;/span&gt; row &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; sourceIndex.&lt;span style=&quot;color: #202020;&quot;&gt;row&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
IndexMap&lt;span style=&quot;color: #339933;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #202020;&quot;&gt;const_iterator&lt;/span&gt; it &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; m_sourcesIndexMapping.&lt;span style=&quot;color: #202020;&quot;&gt;constFind&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; row &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
Q_ASSERT&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; it &lt;span style=&quot;color: #339933;&quot;&gt;!=&lt;/span&gt; m_sourcesIndexMapping.&lt;span style=&quot;color: #202020;&quot;&gt;constEnd&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Nous récupérons l'index dans le modèle source, et à l'aide de notre tableau d'index source, nous allons retrouver l'objet &lt;em&gt;Mapping&lt;/em&gt; correspondant. Cette objet &lt;em&gt;Mapping&lt;/em&gt; correspondra à celui de notre index source. Ce dont nous avons besoin pour notre modèle est l'objet &lt;em&gt;Mapping&lt;/em&gt; de l'objet parent (En effet, notre index est construit sous la forme&amp;nbsp;: ligne, colonne, pointeur sur la structure &lt;em&gt;Mapping&lt;/em&gt; du parent de notre index). Nous récupérons donc l'index de la ligne source dans l'objet parent.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #993333;&quot;&gt;int&lt;/span&gt; parentRow &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; it.&lt;span style=&quot;color: #202020;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;parentIndex&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
IndexMap&lt;span style=&quot;color: #339933;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #202020;&quot;&gt;const_iterator&lt;/span&gt; parentIt &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; m_sourcesIndexMapping.&lt;span style=&quot;color: #202020;&quot;&gt;constFind&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; parentRow &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
Q_ASSERT&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; parentIt &lt;span style=&quot;color: #339933;&quot;&gt;!=&lt;/span&gt; m_sourcesIndexMapping.&lt;span style=&quot;color: #202020;&quot;&gt;constEnd&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
Mapping &lt;span style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt; m &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; parentIt.&lt;span style=&quot;color: #202020;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Cela nous permet de récupérer l'objet &lt;em&gt;Mapping&lt;/em&gt; de l'index parent.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #993333;&quot;&gt;int&lt;/span&gt; proxyRow    &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; m&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;source_rows.&lt;span style=&quot;color: #202020;&quot;&gt;indexOf&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; row &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #993333;&quot;&gt;int&lt;/span&gt; proxyColumn &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; sourceColumnToProxy&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; sourceIndex.&lt;span style=&quot;color: #202020;&quot;&gt;column&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; proxyColumn &lt;span style=&quot;color: #339933;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; QModelIndex&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;La méthode &lt;em&gt;sourceColumnToProxy()&lt;/em&gt; permet de transformer une colonne de l'objet source en une colonne de l'objet courant. Cela signifie que la colonne 2 sera convertie en colonne 1, et que les colonnes 1 et 3 ne seront pas converties (et cachées). Dans ce dernier cas, nous retournons &lt;em&gt;QModelIndex()&lt;/em&gt;.&lt;/p&gt;


&lt;p&gt;L'index de la ligne dans notre modèle sera donné par la position dans la liste &lt;em&gt;source_rows&lt;/em&gt; dans notre structure de conversion.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; createIndex&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; proxyRow&lt;span style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt; proxyColumn&lt;span style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt;parentIt &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Nous pouvons alors créer notre index.&lt;/p&gt;


&lt;h4&gt;mapToSource()&lt;/h4&gt;


&lt;p&gt;De la manière inverse à la méthode &lt;em&gt;mapFromSource()&lt;/em&gt;, cette méthode permet de convertir un index de notre objet en un index du modèle source.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;!&lt;/span&gt; proxyIndex.&lt;span style=&quot;color: #202020;&quot;&gt;isValid&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; QModelIndex&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; proxyIndex.&lt;span style=&quot;color: #202020;&quot;&gt;model&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;!=&lt;/span&gt; this &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#123;&lt;/span&gt;
	qWarning&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;CategoryItemModel: index from wrong model passed to mapToSource&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
	&lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; QModelIndex&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Si le modèle est invalide  dans notre modèle, il l'est aussi dans le modèle source. Il n'y a pas d'équivalent dans le modèle source de l'index racine.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;Mapping &lt;span style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt; m &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; static_cast&lt;span style=&quot;color: #339933;&quot;&gt;&amp;lt;&lt;/span&gt;Mapping&lt;span style=&quot;color: #339933;&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; proxyIndex.&lt;span style=&quot;color: #202020;&quot;&gt;internalPointer&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Nous récupérons la structure dans le pointeur interne de notre index.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #993333;&quot;&gt;int&lt;/span&gt; sourceColumn &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; proxyColumnToSource&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; proxyIndex.&lt;span style=&quot;color: #202020;&quot;&gt;column&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; sourceColumn &lt;span style=&quot;color: #339933;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; QModelIndex&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Nous récupérons également les informations sur notre colonne (Soit, conversion de la colonne 0 dans notre modèle, en la colonne 1 dans le modèle source).&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #993333;&quot;&gt;int&lt;/span&gt; sourceRow &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; m&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;source_rows.&lt;span style=&quot;color: #202020;&quot;&gt;at&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; proxyIndex.&lt;span style=&quot;color: #202020;&quot;&gt;row&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Nous recherchons dans notre liste &lt;em&gt;source_rows&lt;/em&gt; la ligne dans le modèle source qui correspond à la ligne (relative au père) indiqué par notre index et nous construisons un index de type (ligne, colonne) correspondant au modèle source.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; m_sourceModel&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;index&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; sourceRow&lt;span style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt; sourceColumn &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;L'implémentation des méthodes &lt;em&gt;mapFromSource()&lt;/em&gt; et &lt;em&gt;mapToSource()&lt;/em&gt; permettent de faire fonctionner les implémentations des méthodes &lt;em&gt;data()&lt;/em&gt;, &lt;em&gt;headerData()&lt;/em&gt;, et &lt;em&gt;flags()&lt;/em&gt;. Il n'y aura donc aucun intérêt à ré-implémenter ces méthodes à moins de vouloir traiter les données de ces fonctions. Nous ne les décrirons donc pas ici, mais vous pourrez voir dans le fichier attaché, un exemple d'utilisation.&lt;/p&gt;


&lt;h4&gt;index()&lt;/h4&gt;

&lt;p&gt;Le principe de cette méthode est de générer un index pour notre modèle. L'index doit être valide et réutilisable dans les méthodes &lt;em&gt;rowCount()&lt;/em&gt;, &lt;em&gt;flags()&lt;/em&gt;, &lt;em&gt;columnCount()&lt;/em&gt;, &lt;em&gt;data()&lt;/em&gt;, &lt;em&gt;mapToSource()&lt;/em&gt;.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; row &lt;span style=&quot;color: #339933;&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;||&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; column &lt;span style=&quot;color: #339933;&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; QModelIndex&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Si la ligne ou la colonne est inférieure à 0, l'index n'est pas valide.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;IndexMap&lt;span style=&quot;color: #339933;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #202020;&quot;&gt;const_iterator&lt;/span&gt; it &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; m_sourcesIndexMapping.&lt;span style=&quot;color: #202020;&quot;&gt;constFind&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
QModelIndex sourceParent &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; mapToSource&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; parent &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; sourceParent.&lt;span style=&quot;color: #202020;&quot;&gt;isValid&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#123;&lt;/span&gt;
	it &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; m_sourcesIndexMapping.&lt;span style=&quot;color: #202020;&quot;&gt;constFind&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; sourceParent.&lt;span style=&quot;color: #202020;&quot;&gt;row&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;A partir de l'index &lt;em&gt;parent&lt;/em&gt; nous retrouvons l'index qui correspond dans le modèle source (&lt;em&gt;sourceParent').  Si l'on ne trouve pas d'index dans le modèle source, nous considérons être sur l'élément racine de notre arbre. Sinon nous recherchons dans la table de &lt;/em&gt;Mapping'' la structure qui correspond.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;Q_ASSERT&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; it &lt;span style=&quot;color: #339933;&quot;&gt;!=&lt;/span&gt; m_sourcesIndexMapping.&lt;span style=&quot;color: #202020;&quot;&gt;constEnd&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; it.&lt;span style=&quot;color: #202020;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;source_rows.&lt;span style=&quot;color: #202020;&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;&amp;lt;=&lt;/span&gt; row &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;
	&lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; QModelIndex&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Nous vérifions le nombre d'élément dans la structure et nous retournons un index non valide si l'index demandé va au delà de la taille du tableau.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; createIndex&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; row&lt;span style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt; column&lt;span style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt;it &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Finalement nous retournons l'index créé avec le pointeur vers la structure &lt;em&gt;Mapping&lt;/em&gt; du père en &lt;em&gt;internalData&lt;/em&gt;.&lt;/p&gt;


&lt;h4&gt;parent()&lt;/h4&gt;


&lt;p&gt;Cette méthode permet de retourner pour l'index donné du proxy, l'index du parent. Un index invalide n'a pas de parent.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;!&lt;/span&gt; index.&lt;span style=&quot;color: #202020;&quot;&gt;isValid&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; QModelIndex&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
Mapping &lt;span style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt; m &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; static_cast&lt;span style=&quot;color: #339933;&quot;&gt;&amp;lt;&lt;/span&gt;Mapping&lt;span style=&quot;color: #339933;&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; index.&lt;span style=&quot;color: #202020;&quot;&gt;internalPointer&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;On récupère la structure de correspondance stockée dans le pointeur interne de l'objet. Cette  structure nous donne les informations du parent (en effet dans &lt;em&gt;internalPointer()&lt;/em&gt;, on stock la structure &lt;em&gt;Mapping&lt;/em&gt; du parent), et donc l'index dans le modèle source.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #993333;&quot;&gt;int&lt;/span&gt; sourceRow &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; m&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;index&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; sourceRow &lt;span style=&quot;color: #339933;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; QModelIndex&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
QModelIndex sourceParent &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; m_sourceModel&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;index&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; sourceRow&lt;span style=&quot;color: #339933;&quot;&gt;,&lt;/span&gt; proxyColumnToSource&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
QModelIndex proxyParent &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; mapFromSource&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; sourceParent &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;On utilise alors notre méthode &lt;em&gt;mapFromSource()&lt;/em&gt; pour retrouver l'index du parent dans le référentiel du proxy.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; proxyParent&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;h4&gt;rowCount()&lt;/h4&gt;


&lt;p&gt;Le but de cette méthode est de retourner le nombre de ligne enfant pour un index. Dans le modèle source les indexes n'ont pas d'enfant.
Lorsque l'index vaut &lt;em&gt;QModelIndex()&lt;/em&gt;, cela signifie qu'il faut retourner le nombre de ligne pour notre racine.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; index.&lt;span style=&quot;color: #202020;&quot;&gt;column&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Seul la première colonne a des enfants.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;!&lt;/span&gt; index.&lt;span style=&quot;color: #202020;&quot;&gt;isValid&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#123;&lt;/span&gt;
	Mapping &lt;span style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt; rootMapping &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; m_sourcesIndexMapping.&lt;span style=&quot;color: #202020;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
	&lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; rootMapping&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;source_rows.&lt;span style=&quot;color: #202020;&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Pour l'index racine, on récupère le nombre de ligne à la ligne -1 du modèle source.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#123;&lt;/span&gt;
	Mapping &lt;span style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt; parrentMapping &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; static_cast&lt;span style=&quot;color: #339933;&quot;&gt;&amp;lt;&lt;/span&gt;Mapping&lt;span style=&quot;color: #339933;&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; index.&lt;span style=&quot;color: #202020;&quot;&gt;internalPointer&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
	&lt;span style=&quot;color: #993333;&quot;&gt;int&lt;/span&gt; sourceRowIndex &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; parrentMapping&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;source_rows.&lt;span style=&quot;color: #202020;&quot;&gt;at&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; index.&lt;span style=&quot;color: #202020;&quot;&gt;row&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
	Mapping &lt;span style=&quot;color: #339933;&quot;&gt;*&lt;/span&gt; rowMapping &lt;span style=&quot;color: #339933;&quot;&gt;=&lt;/span&gt; m_sourcesIndexMapping.&lt;span style=&quot;color: #202020;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; sourceRowIndex &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	&lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; rowMapping&lt;span style=&quot;color: #339933;&quot;&gt;-&amp;gt;&lt;/span&gt;source_rows.&lt;span style=&quot;color: #202020;&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Sinon on récupère la structure stockée dans le pointeur interne. Cette structure est celle du parent de notre objet. On récupère à l'aide de la méthode &lt;em&gt;row()&lt;/em&gt; de l'index l'emplacement de la ligne source. Cette ligne source nous permet de récupérer la structure de correspondance de notre index, et ainsi le nombre de ligne de notre index.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;h4&gt;columnCount()&lt;/h4&gt;


&lt;p&gt;Notre modèle ne possède qu'une seule colonne.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;h4&gt;proxyColumnToSource()&lt;/h4&gt;


&lt;p&gt;Si la colonne du proxy vaut 0, alors on retourne la colonne 1, sinon on retourne la colonne -1&amp;nbsp;: la colonne n'est pas convertible, elle n'existe pas dans notre proxy.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; proxyColumn &lt;span style=&quot;color: #339933;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;
	&lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; list_name&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;


&lt;h4&gt;sourceColumToProxy()&lt;/h4&gt;


&lt;p&gt;Si la colonne source est 1, alors nous convertissons celle-ci en la colonne 0. Sinon la colonne n'existe pas dans notre proxy.&lt;/p&gt;

&lt;pre class=&quot;c c&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;#40;&lt;/span&gt; sourceColumn &lt;span style=&quot;color: #339933;&quot;&gt;==&lt;/span&gt; list_name &lt;span style=&quot;color: #009900;&quot;&gt;&amp;#41;&lt;/span&gt;
	&lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000dd;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #339933;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #339933;&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;</description>
    
          <enclosure url="http://www.shadoware.org/public/billets/qt/table2tree/categoryitemmodel.cpp"
      length="8272" type="text/plain" />
          <enclosure url="http://www.shadoware.org/public/billets/qt/table2tree/categoryitemmodel.h"
      length="3018" type="text/plain" />
    
    
          <comments>http://www.shadoware.org/post/2009/09/10/%5BQt%5D-Transformation-d-une-vue-tableau-en-une-vue-hi%C3%A9rarchique#comment-form</comments>
      <wfw:comment>http://www.shadoware.org/post/2009/09/10/%5BQt%5D-Transformation-d-une-vue-tableau-en-une-vue-hi%C3%A9rarchique#comment-form</wfw:comment>
      <wfw:commentRss>http://www.shadoware.org/feed/atom/comments/623</wfw:commentRss>
      </item>
    
  <item>
    <title>Email2Trac</title>
    <link>http://www.shadoware.org/post/2008/10/21/Email2Trac</link>
    <guid isPermaLink="false">urn:md5:5ec8ea26412295d7bc4b6d2846dff997</guid>
    <pubDate>Wed, 22 Oct 2008 09:00:00 +0200</pubDate>
    <dc:creator>Ulrich Van Den Hekke</dc:creator>
        <category>Logiciels</category>
        <category>article</category><category>bug</category><category>debian</category><category>dédié</category><category>mail</category><category>planet</category><category>trac</category>    
    <description>&lt;p&gt;&lt;em&gt;Email2Trac&lt;/em&gt; est un logiciel permettant de créer un ticket sous &lt;em&gt;Trac&lt;/em&gt; en envoyant un mail au système de suivi de ticket.&lt;/p&gt;


&lt;p&gt;L'intérêt d'envoyer un mail au système de suivi plutôt que de se connecter sur le site Internet pour faire ses rapports d'anomalie, est de faciliter l'accès à de nouvelles personnes.
En effet, il est parfois plus facile d'envoyer un mail avec son client mail préféré (en considérant que le logiciel est quasiment toujours ouvert, ce qui doit être le cas en entreprise) que d'ouvrir le navigateur pour envoyer une anomalie de temps en temps (ouvrir le site, se logger, remplir tous les champs, ...).&lt;/p&gt;


&lt;p&gt;Ceci peut également être utilisé par un outil de rapport de bug, envoyant un mail automatique (avec confirmation de l'utilisateur) au crash dudit logiciel.&lt;/p&gt;    &lt;p&gt;Comme dit précédemment, &lt;em&gt;EMail2Trac&lt;/em&gt;&lt;sup&gt;[&lt;a href=&quot;http://www.shadoware.org/post/2008/10/21/Email2Trac#pnote-611-1&quot; id=&quot;rev-pnote-611-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt; permet&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;d'ajouter un ticket en envoyant un mail, avec des fichiers attachés&lt;/li&gt;
&lt;li&gt;mettre à jour un ticket (en répondant au mail du ticket par exemple)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Installation&lt;/h3&gt;


&lt;p&gt;Pour installer &lt;em&gt;Email2Trac&lt;/em&gt;, il faut télécharger le &lt;a href=&quot;ftp://ftp.sara.nl/pub/outgoing/email2trac.tar.gz&quot;&gt;source&lt;/a&gt; et le décompresser dans un dossier temporaire (ou utilisateur).&lt;/p&gt;


&lt;h4&gt;Sans gestionnaire de paquet&lt;/h4&gt;


&lt;p&gt;Ensuite la compilation se fait à l'aide des habituelles &lt;code&gt;autotools&lt;/code&gt;&lt;/p&gt;

&lt;pre class=&quot;bash bash&quot; style=&quot;font-family:inherit&quot;&gt;configure &lt;span style=&quot;color: #660033;&quot;&gt;--prefix&lt;/span&gt;=&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;usr&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #7a0874; font-weight: bold;&quot;&gt;local&lt;/span&gt; --with-mta_user=nobody --with-trac_user=www-data
&lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;make&lt;/span&gt; 
&lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;make&lt;/span&gt; &lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;install&lt;/span&gt;&lt;/pre&gt;


&lt;h4&gt;Sous Debian&lt;/h4&gt;


&lt;p&gt;Après avoir installé les paquets &lt;code&gt;cdbs&lt;/code&gt; et &lt;code&gt;autotools-dev&lt;/code&gt;, vous pouvez exécuter les commandes suivante en &lt;em&gt;root&lt;/em&gt; (ou la première à l'aide de &lt;em&gt;fakeroot&lt;/em&gt;)&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;bash bash&quot; style=&quot;font-family:inherit&quot;&gt;debian&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;rules binary
&lt;span style=&quot;color: #c20cb9; font-weight: bold;&quot;&gt;dpkg&lt;/span&gt; &lt;span style=&quot;color: #660033;&quot;&gt;-i&lt;/span&gt; ..&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;email2trac_&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;&lt;/span&gt;version&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;.deb&lt;/pre&gt;


&lt;p&gt;Pour le gestionnaire de paquets &lt;em&gt;RPM&lt;/em&gt; vous pouvez visiter la page &lt;a href=&quot;https://subtrac.sara.nl/oss/email2trac/wiki/Email2tracInstallation&quot; hreflang=&quot;en&quot;&gt;https://subtrac.sara.nl/oss/email2trac/wiki/Email2tracInstallation&lt;/a&gt;&lt;/p&gt;


&lt;h3&gt;Configuration de l'application&lt;/h3&gt;


&lt;p&gt;La deuxième étape est l'édition du fichier &lt;code&gt;/etc/email2trac.conf&lt;/code&gt;. Dans ce fichier les informations à renseigner concerne la gestion du projet Trac&lt;sup&gt;[&lt;a href=&quot;http://www.shadoware.org/post/2008/10/21/Email2Trac#pnote-611-2&quot; id=&quot;rev-pnote-611-2&quot;&gt;2&lt;/a&gt;]&lt;/sup&gt; par &lt;em&gt;Email2Trac&lt;/em&gt;.&lt;/p&gt;

&lt;pre class=&quot;ini ini&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #000066; font-weight:bold;&quot;&gt;&lt;span style=&quot;&quot;&gt;&amp;#91;&lt;/span&gt;DEFAULT&lt;span style=&quot;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;/span&gt;
project: /www/site/trac/projet1
spam_level: &lt;span style=&quot;&quot;&gt;5&lt;/span&gt;
drop_spam: &lt;span style=&quot;&quot;&gt;1&lt;/span&gt;
ticket_update: &lt;span style=&quot;&quot;&gt;1&lt;/span&gt;
strip_signature: &lt;span style=&quot;&quot;&gt;1&lt;/span&gt;
&amp;nbsp;
&lt;span style=&quot;color: #000066; font-weight:bold;&quot;&gt;&lt;span style=&quot;&quot;&gt;&amp;#91;&lt;/span&gt;projet2&lt;span style=&quot;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;/span&gt;
project: /www/site/trac/projet2
spam_level: &lt;span style=&quot;&quot;&gt;5&lt;/span&gt;
drop_spam: &lt;span style=&quot;&quot;&gt;1&lt;/span&gt;
ticket_update: &lt;span style=&quot;&quot;&gt;1&lt;/span&gt;
strip_signature: &lt;span style=&quot;&quot;&gt;1&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Les différentes options dépendent de ce que vous souhaitez avoir. Les différentes possibilités sont à l'adresse &lt;a href=&quot;https://subtrac.sara.nl/oss/email2trac/wiki/Email2tracConfiguration&quot; hreflang=&quot;en&quot;&gt;suivante&lt;/a&gt;.&lt;/p&gt;


&lt;h4&gt;Spam&lt;/h4&gt;


&lt;p&gt;La gestion du SPAM se fait à l'aide des 3 lignes&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;ini ini&quot; style=&quot;font-family:inherit&quot;&gt;spam_level: &lt;span style=&quot;&quot;&gt;5&lt;/span&gt;
drop_spam: &lt;span style=&quot;&quot;&gt;1&lt;/span&gt;
spam_header: X-Spam-Level&lt;/pre&gt;


&lt;p&gt;La ligne &lt;code&gt;spam_header&lt;/code&gt; étant à configurer suivant votre politique de gestion des spams (utilisation de &lt;em&gt;SpamAssassin&lt;/em&gt; ou d'un autre utilitaire).&lt;/p&gt;


&lt;h3&gt;Configuration de Postfix&lt;/h3&gt;


&lt;p&gt;Il faut maintenant configurer notre système de messagerie pour intégrer &lt;em&gt;Email2Trac&lt;/em&gt;. Nous allons détailler ici la mise en place de &lt;em&gt;Email2Trac&lt;/em&gt; sous &lt;em&gt;Postfix&lt;/em&gt;. Pour les autres serveurs mails vous pouvez visiter la page&amp;nbsp;: &lt;a href=&quot;http://www.shadoware.org/post/2008/10/21/en&quot;&gt;http://subtrac.sara.nl/oss/email2trac/wiki/Email2tracMta&lt;/a&gt;&lt;/p&gt;


&lt;h4&gt;Aliases&lt;/h4&gt;


&lt;p&gt;La première méthode concerne la modification du fichier des &lt;em&gt;alias&lt;/em&gt; pour une configuration standard de &lt;em&gt;postfix&lt;/em&gt;.  Nous allons commencer par modifier le fichier &lt;code&gt;/etc/aliases&lt;/code&gt; en ajoutant la ligne suivante (pour le projet 1)&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
projet1: |&amp;quot;/usr/bin/run_email2trac&amp;quot;
&lt;/pre&gt;


&lt;p&gt;Il est également possible de préciser le projet sur lequel il faut travailler (projet définit dans &lt;code&gt;/etc/email2trac.conf&lt;/code&gt;)&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
projet2: |&amp;quot;/usr/bin/run_email2trac --project=projet2 --ticket_prefix=devel&amp;quot;
&lt;/pre&gt;


&lt;p&gt;Dans le fichier &lt;code&gt;/etc/postfix/main.cf&lt;/code&gt;, il faut avoir défini l'emplacement des alias de la manière suivante&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;ini ini&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #000099;&quot;&gt;alias_maps&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight:bold;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #660066;&quot;&gt; hash:/etc/aliases&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Les commandes suivantes permettent de mettre à jour le fichier des alias et demander à &lt;em&gt;Postfix&lt;/em&gt; de recharger la configuration&amp;nbsp;:&lt;/p&gt;

&lt;pre class=&quot;bash bash&quot; style=&quot;font-family:inherit&quot;&gt;postaliases &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;etc&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;aliases
postfix reload&lt;/pre&gt;


&lt;p&gt;Une fois ceci terminé, les mails envoyé à &lt;em&gt;projet1@domain.org&lt;/em&gt; et &lt;em&gt;projet2@domaine.org&lt;/em&gt; seront automatiquement redirigés vers &lt;em&gt;email2trac&lt;/em&gt; qui s'occupera de créer le ticket dans votre système de suivi.&lt;/p&gt;


&lt;h4&gt;Transport&lt;/h4&gt;


&lt;p&gt;Cette configuration concerne les personnes qui ont une configuration plus complexe de &lt;em&gt;postfix&lt;/em&gt; par exemple en gérant des domaines virtuels. Il est alors possible de définir une redirection des tickets pour un sous domaine.&lt;/p&gt;


&lt;p&gt;Nous avons donc créé le sous-domaine &lt;em&gt;tickets.domaine.org&lt;/em&gt; et voulons que les mails envoyés à &lt;em&gt;projet1@tickets.domaine.org&lt;/em&gt; est &lt;em&gt;projet2@tickets.domaine.org&lt;/em&gt; soient redirigés vers email2trac.&lt;/p&gt;


&lt;p&gt;Pour cela nous allons créer un fichier &lt;code&gt;/etc/postfix/transport&lt;/code&gt; avec les lignes ci-dessous&amp;nbsp;:&lt;/p&gt;

&lt;pre&gt;
projet1@tickets.domaine.org      projet1:
projet2@tickets.domaine.org      projet2:
&lt;/pre&gt;


&lt;p&gt;Puis dans le fichier &lt;code&gt;/etc/postfix/main.cf&lt;/code&gt; nous allons définir que pour le sous domaine &lt;em&gt;tickets.domaine.org&lt;/em&gt;, il faut lire et utiliser le fichier des transports. (Attention il ne faut pas ajouter ce sous-domaine dans &lt;code&gt;mydestination&lt;/code&gt;.&lt;/p&gt;

&lt;pre class=&quot;ini ini&quot; style=&quot;font-family:inherit&quot;&gt;&lt;span style=&quot;color: #000099;&quot;&gt;relay_domains&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight:bold;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #660066;&quot;&gt; tickets.domaine.org&lt;/span&gt;
&lt;span style=&quot;color: #000099;&quot;&gt;transport_maps&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight:bold;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #660066;&quot;&gt; hash:/etc/postfix/transport&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Ensuite, il nous faut définir dans le fichier &lt;code&gt;/etc/postfix/master.cf&lt;/code&gt; notre nouveau mode de transport. Il n'est pas obligé d'utiliser &lt;code&gt;run_email2trac&lt;/code&gt; qui fait un changement d'utilisateur, car dans le fichier &lt;code&gt;master.cf&lt;/code&gt; on peut directement définir l'utilisateur de destination.&lt;/p&gt;

&lt;pre&gt;
projet1      unix  -       n       n       -       -       pipe
  flags=FR user=www-data argv=/usr/bin/email2trac
  ${nexthop} ${user}
projet2      unix  -       n       n       -       -       pipe
  flags=FR user=www-data argv=/usr/bin/email2trac
  ${nexthop} ${user}
&lt;/pre&gt;


&lt;p&gt;Enfin il faut redémarrer &lt;em&gt;postfix&lt;/em&gt;&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;bash bash&quot; style=&quot;font-family:inherit&quot;&gt;postmap &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;etc&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;postfix&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;/&lt;/span&gt;transport
postfix reload&lt;/pre&gt;


&lt;p&gt;Et voilà vous pouvez envoyer vos mails à &lt;em&gt;projet1@tickets.shadoware.org&lt;/em&gt;.&lt;/p&gt;



&lt;h3&gt;Tester&lt;/h3&gt;


&lt;p&gt;Pour tester il est possible d'envoyer un mail, comme ceci&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;bash bash&quot; style=&quot;font-family:inherit&quot;&gt;mail projet1&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;@&lt;/span&gt;tickets.shadoware.org &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;&lt;/span&gt; ticket.txt&lt;/pre&gt;


&lt;p&gt;En cas de problème, vous pouvez vérifier que email2trac est bien configuré avec la commande&amp;nbsp;:&lt;/p&gt;
&lt;pre class=&quot;bash bash&quot; style=&quot;font-family:inherit&quot;&gt;email2trac &lt;span style=&quot;color: #660033;&quot;&gt;--project&lt;/span&gt;=projet1 &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;&lt;/span&gt; ticket.txt&lt;/pre&gt;
&lt;div class=&quot;footnotes&quot;&gt;&lt;h4&gt;Notes&lt;/h4&gt;
&lt;p&gt;[&lt;a href=&quot;http://www.shadoware.org/post/2008/10/21/Email2Trac#rev-pnote-611-1&quot; id=&quot;pnote-611-1&quot;&gt;1&lt;/a&gt;] &lt;a href=&quot;http://subtrac.sara.nl/oss/email2trac/wiki&quot; title=&quot;http://subtrac.sara.nl/oss/email2trac/wiki&quot;&gt;http://subtrac.sara.nl/oss/email2tr...&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://www.shadoware.org/post/2008/10/21/Email2Trac#rev-pnote-611-2&quot; id=&quot;pnote-611-2&quot;&gt;2&lt;/a&gt;] &lt;a href=&quot;http://trac.edgewall.org/&quot; title=&quot;http://trac.edgewall.org/&quot;&gt;http://trac.edgewall.org/&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;
</description>
    
    
    
          <comments>http://www.shadoware.org/post/2008/10/21/Email2Trac#comment-form</comments>
      <wfw:comment>http://www.shadoware.org/post/2008/10/21/Email2Trac#comment-form</wfw:comment>
      <wfw:commentRss>http://www.shadoware.org/feed/atom/comments/611</wfw:commentRss>
      </item>
    
  <item>
    <title>Le retour du roi</title>
    <link>http://www.shadoware.org/post/2007/10/09/34-test</link>
    <guid isPermaLink="false">urn:md5:1a90e6896e3638ada525bf97d2c0bb38</guid>
    <pubDate>Tue, 09 Oct 2007 11:53:00 +0000</pubDate>
    <dc:creator>Ulrich Van Den Hekke</dc:creator>
        <category>Ma Vie</category>
        <category>article</category><category>dédié</category>    
    <description>    &lt;p&gt;Et voilà j'ai encore déménagé. Vous allez pouvoir retrouver mon site à l'adresse suivante&amp;nbsp;: http://www.shadoware.org et mon blog à http://blog.shadoware.org.&lt;/p&gt;


&lt;p&gt;N'est-ce pas que c'est beau&amp;nbsp;?&lt;/p&gt;


&lt;p&gt;J'en profite pour vous informer que j'écris un article sur l'installation d'un serveur dédié. Le serveur dédié dont je me suis inspiré, c'est le mien, et ça tombe bien. Par contre l'article en question paraitra dans un Magazine Linux &lt;img src=&quot;/dotclear/themes/default/smilies/wink.png&quot; alt=&quot;;)&quot; class=&quot;smiley&quot; /&gt;
Je vous tiendrais informé.&lt;/p&gt;


&lt;p&gt;A bientôt.&lt;/p&gt;</description>
    
    
    
          <comments>http://www.shadoware.org/post/2007/10/09/34-test#comment-form</comments>
      <wfw:comment>http://www.shadoware.org/post/2007/10/09/34-test#comment-form</wfw:comment>
      <wfw:commentRss>http://www.shadoware.org/feed/atom/comments/26</wfw:commentRss>
      </item>
    
</channel>
</rss>
