Sophie

Sophie

distrib > Fedora > 18 > x86_64 > by-pkgid > b3a1f4d91c26f535919e39e25606614a > files > 95

wt-doc-3.2.3-1.fc18.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Wt examples: /home/koen/project/wt/public-git/wt/examples/gitmodel/GitModel.C Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Wt examples
   &#160;<span id="projectnumber">3.2.3</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">/home/koen/project/wt/public-git/wt/examples/gitmodel/GitModel.C</div>  </div>
</div>
<div class="contents">
<a href="GitModel_8C.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * See the LICENSE file for terms of use.</span>
<a name="l00005"></a>00005 <span class="comment"> */</span>
<a name="l00006"></a>00006 
<a name="l00007"></a>00007 <span class="preprocessor">#include &quot;<a class="code" href="GitModel_8h.html">GitModel.h</a>&quot;</span>
<a name="l00008"></a>00008 
<a name="l00009"></a>00009 <span class="keyword">using namespace </span>Wt;
<a name="l00010"></a>00010 
<a name="l00011"></a><a class="code" href="classGitModel.html#a056f5d6c45226ca08ada28e72eed294a">00011</a> <a class="code" href="classGitModel.html#a056f5d6c45226ca08ada28e72eed294a" title="Constructor.">GitModel::GitModel</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WObject.html">WObject</a> *parent)
<a name="l00012"></a>00012   : <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemModel.html">WAbstractItemModel</a>(parent)
<a name="l00013"></a>00013 { }
<a name="l00014"></a>00014 
<a name="l00015"></a><a class="code" href="classGitModel.html#aac776e532822827e59a2233645995e65">00015</a> <span class="keywordtype">void</span> <a class="code" href="classGitModel.html#aac776e532822827e59a2233645995e65" title="Set the repository and load its &#39;master&#39; revision.">GitModel::setRepositoryPath</a>(<span class="keyword">const</span> std::string&amp; gitRepositoryPath)
<a name="l00016"></a>00016 {
<a name="l00017"></a>00017   <a class="code" href="classGitModel.html#afc8ff43e47ae51ce2af04d63a162be8e" title="The git repository.">git_</a>.<a class="code" href="classGit.html#ab21f8d442557b07321a274b5e976f1ac" title="Set the git repository path.">setRepositoryPath</a>(gitRepositoryPath);
<a name="l00018"></a>00018   <a class="code" href="classGitModel.html#af78bddbae2d7b76ec1e49d8626dc7526" title="Load a particular revision.">loadRevision</a>(<span class="stringliteral">&quot;master&quot;</span>);
<a name="l00019"></a>00019 }
<a name="l00020"></a>00020 
<a name="l00021"></a><a class="code" href="classGitModel.html#af78bddbae2d7b76ec1e49d8626dc7526">00021</a> <span class="keywordtype">void</span> <a class="code" href="classGitModel.html#af78bddbae2d7b76ec1e49d8626dc7526" title="Load a particular revision.">GitModel::loadRevision</a>(<span class="keyword">const</span> std::string&amp; revName)
<a name="l00022"></a>00022 {
<a name="l00023"></a>00023   <a class="code" href="classGit_1_1ObjectId.html" title="Git object Id.">Git::ObjectId</a> treeRoot = <a class="code" href="classGitModel.html#afc8ff43e47ae51ce2af04d63a162be8e" title="The git repository.">git_</a>.<a class="code" href="classGit.html#a521bba51875ea14c9e39a14fcde01e04" title="Get the tree for a particular revision.">getCommitTree</a>(revName);
<a name="l00024"></a>00024 
<a name="l00025"></a>00025   <span class="comment">// You need to call this method before invalidating all existing</span>
<a name="l00026"></a>00026   <span class="comment">// model indexes. Anyone listening for this event could temporarily</span>
<a name="l00027"></a>00027   <span class="comment">// convert some model indexes to a raw index pointer, but this model</span>
<a name="l00028"></a>00028   <span class="comment">// does not reimplement these methods.</span>
<a name="l00029"></a>00029   <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemModel.html#ab377ac2fcb9de9d191bd1353665d1389">layoutAboutToBeChanged</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Signal.html#a8d9cf8a1e83634462fe2b492b3beb1c5">emit</a>();
<a name="l00030"></a>00030 
<a name="l00031"></a>00031   <a class="code" href="classGitModel.html#a59307dfceb1f5712914e0754144422e4" title="List of folder objects.">treeData_</a>.clear();
<a name="l00032"></a>00032   <a class="code" href="classGitModel.html#a4f3e07cf6dddd098c4c4f0978be0fe90" title="Maps child indexes to tree indexes.">childPointer_</a>.clear();
<a name="l00033"></a>00033 
<a name="l00034"></a>00034   <span class="comment">// Store the tree root as treeData_[0]</span>
<a name="l00035"></a>00035   <a class="code" href="classGitModel.html#a59307dfceb1f5712914e0754144422e4" title="List of folder objects.">treeData_</a>.push_back(<a class="code" href="classGitModel_1_1Tree.html" title="Used to uniquely locate a folder within the folder hierarchy.">Tree</a>(-1, -1, treeRoot, <a class="code" href="classGitModel.html#afc8ff43e47ae51ce2af04d63a162be8e" title="The git repository.">git_</a>.<a class="code" href="classGit.html#abe86381afbbab0adb0680ae268752f1f" title="Return the number of objects inside a tree object.">treeSize</a>(treeRoot)));
<a name="l00036"></a>00036 
<a name="l00037"></a>00037   <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemModel.html#afe7cb1d5186881f83aa8f0e452aaef66">layoutChanged</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Signal.html#a8d9cf8a1e83634462fe2b492b3beb1c5">emit</a>();
<a name="l00038"></a>00038 }
<a name="l00039"></a>00039 
<a name="l00040"></a><a class="code" href="classGitModel.html#ad707c92d586f8232f5e452b2b3cecc1b">00040</a> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html">WModelIndex</a> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WObject.html#a2af8f7ec8d3807d434e1f70d1245c6b4">GitModel::parent</a>(<span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html">WModelIndex</a>&amp; index)<span class="keyword"> const</span>
<a name="l00041"></a>00041 <span class="keyword"></span>{
<a name="l00042"></a>00042   <span class="comment">// treeData_[0] indicates the top-level parent.</span>
<a name="l00043"></a>00043   <span class="keywordflow">if</span> (!index.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html#a1d4b05ee51c5c6961d6123565fd77c82">isValid</a>() || index.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html#a7ae49c4d0edaf9a520e6f5e8a62c3904">internalId</a>() == 0)
<a name="l00044"></a>00044     <span class="keywordflow">return</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html">WModelIndex</a>();
<a name="l00045"></a>00045   <span class="keywordflow">else</span> {
<a name="l00046"></a>00046     <span class="comment">// get the item that corresponds to the parent ...</span>
<a name="l00047"></a>00047     <span class="keyword">const</span> <a class="code" href="classGitModel_1_1Tree.html" title="Used to uniquely locate a folder within the folder hierarchy.">Tree</a>&amp; item = <a class="code" href="classGitModel.html#a59307dfceb1f5712914e0754144422e4" title="List of folder objects.">treeData_</a>[index.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html#a7ae49c4d0edaf9a520e6f5e8a62c3904">internalId</a>()];
<a name="l00048"></a>00048 
<a name="l00049"></a>00049     <span class="comment">// ... and construct that identifies the parent:</span>
<a name="l00050"></a>00050     <span class="comment">//   row = child index in the grand parent</span>
<a name="l00051"></a>00051     <span class="comment">//   internalId = id of the grand parent</span>
<a name="l00052"></a>00052     <span class="keywordflow">return</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemModel.html#ac837a73fe423255035ffb076946de122">createIndex</a>(item.<a class="code" href="classGitModel_1_1Tree.html#a116166e6c25a27f7d63346f3f6f89e74" title="Returns the child index within the parent folder.">index</a>(), 0, item.<a class="code" href="classGitModel_1_1Tree.html#a83d9cb3d07454c2e4ab4364c4522d431" title="Returns the parent id.">parentId</a>()); 
<a name="l00053"></a>00053   }
<a name="l00054"></a>00054 }
<a name="l00055"></a>00055 
<a name="l00056"></a><a class="code" href="classGitModel.html#a47f5ebf88be96b003b4bf31bfafff141">00056</a> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html">WModelIndex</a> <a class="code" href="classGitModel.html#a47f5ebf88be96b003b4bf31bfafff141" title="Returns a child index.">GitModel::index</a>(<span class="keywordtype">int</span> row, <span class="keywordtype">int</span> column,
<a name="l00057"></a>00057                             <span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html">WModelIndex</a>&amp; parent)<span class="keyword"> const</span>
<a name="l00058"></a>00058 <span class="keyword"></span>{
<a name="l00059"></a>00059   <span class="keywordtype">int</span> parentId;
<a name="l00060"></a>00060 
<a name="l00061"></a>00061   <span class="comment">// the top-level parent has id=0.</span>
<a name="l00062"></a>00062   <span class="keywordflow">if</span> (!parent.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html#a1d4b05ee51c5c6961d6123565fd77c82">isValid</a>())
<a name="l00063"></a>00063     parentId = 0;
<a name="l00064"></a>00064   <span class="keywordflow">else</span> {
<a name="l00065"></a>00065     <span class="comment">// the internal id of the parent identifies the grand parent</span>
<a name="l00066"></a>00066     <span class="keywordtype">int</span> grandParentId = parent.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html#a7ae49c4d0edaf9a520e6f5e8a62c3904">internalId</a>();
<a name="l00067"></a>00067 
<a name="l00068"></a>00068     <span class="comment">// lookup the parent id for the parent himself, based on grand parent</span>
<a name="l00069"></a>00069     <span class="comment">// and child-index (=row) within the grand parent</span>
<a name="l00070"></a>00070     parentId = <a class="code" href="classGitModel.html#ab2efe3ae663dfbd670dc41dd3cb8d2a0" title="Get or allocate an id for a folder.">getTreeId</a>(grandParentId, parent.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html#aa4f1385223391c46ee200a57672f6046">row</a>());
<a name="l00071"></a>00071   }
<a name="l00072"></a>00072 
<a name="l00073"></a>00073   <span class="keywordflow">return</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemModel.html#ac837a73fe423255035ffb076946de122">createIndex</a>(row, column, parentId);
<a name="l00074"></a>00074 }
<a name="l00075"></a>00075 
<a name="l00076"></a><a class="code" href="classGitModel.html#ab2efe3ae663dfbd670dc41dd3cb8d2a0">00076</a> <span class="keywordtype">int</span> <a class="code" href="classGitModel.html#ab2efe3ae663dfbd670dc41dd3cb8d2a0" title="Get or allocate an id for a folder.">GitModel::getTreeId</a>(<span class="keywordtype">int</span> parentId, <span class="keywordtype">int</span> childIndex)<span class="keyword"> const</span>
<a name="l00077"></a>00077 <span class="keyword"></span>{
<a name="l00078"></a>00078   <a class="code" href="structGitModel_1_1ChildIndex.html" title="Index usable as a key to a map, that identifies a child/row within a tree.">ChildIndex</a> <a class="code" href="classGitModel.html#a47f5ebf88be96b003b4bf31bfafff141" title="Returns a child index.">index</a>(parentId, childIndex);
<a name="l00079"></a>00079 
<a name="l00080"></a>00080   ChildPointerMap::const_iterator i = <a class="code" href="classGitModel.html#a4f3e07cf6dddd098c4c4f0978be0fe90" title="Maps child indexes to tree indexes.">childPointer_</a>.find(index);
<a name="l00081"></a>00081   <span class="keywordflow">if</span> (i == <a class="code" href="classGitModel.html#a4f3e07cf6dddd098c4c4f0978be0fe90" title="Maps child indexes to tree indexes.">childPointer_</a>.end()) {
<a name="l00082"></a>00082     <span class="comment">// no tree object was already allocated, so do that now.</span>
<a name="l00083"></a>00083 
<a name="l00084"></a>00084     <span class="comment">// lookup the git SHA1 object Id (within the parent)</span>
<a name="l00085"></a>00085     <span class="keyword">const</span> <a class="code" href="classGitModel_1_1Tree.html" title="Used to uniquely locate a folder within the folder hierarchy.">Tree</a>&amp; parentItem = <a class="code" href="classGitModel.html#a59307dfceb1f5712914e0754144422e4" title="List of folder objects.">treeData_</a>[parentId];
<a name="l00086"></a>00086     <a class="code" href="structGit_1_1Object.html" title="Git object.">Git::Object</a> o = <a class="code" href="classGitModel.html#afc8ff43e47ae51ce2af04d63a162be8e" title="The git repository.">git_</a>.<a class="code" href="classGit.html#a910f3a6123b494897cdedf7ba4ef648b" title="Get some info on a tree object.">treeGetObject</a>(parentItem.<a class="code" href="classGitModel_1_1Tree.html#a963ec0ca3e067d01ba9fd98359c44216" title="Returns the SHA1 id for the git tree object.">treeObject</a>(), childIndex);
<a name="l00087"></a>00087 
<a name="l00088"></a>00088     <span class="comment">// and add to treeData_ and childPointer_ data structures</span>
<a name="l00089"></a>00089     <a class="code" href="classGitModel.html#a59307dfceb1f5712914e0754144422e4" title="List of folder objects.">treeData_</a>.push_back(<a class="code" href="classGitModel_1_1Tree.html" title="Used to uniquely locate a folder within the folder hierarchy.">Tree</a>(parentId, childIndex, o.<a class="code" href="structGit_1_1Object.html#a2e3989983524516e4a936714b55736ff">id</a>, <a class="code" href="classGitModel.html#afc8ff43e47ae51ce2af04d63a162be8e" title="The git repository.">git_</a>.<a class="code" href="classGit.html#abe86381afbbab0adb0680ae268752f1f" title="Return the number of objects inside a tree object.">treeSize</a>(o.<a class="code" href="structGit_1_1Object.html#a2e3989983524516e4a936714b55736ff">id</a>)));
<a name="l00090"></a>00090     <span class="keywordtype">int</span> result = <a class="code" href="classGitModel.html#a59307dfceb1f5712914e0754144422e4" title="List of folder objects.">treeData_</a>.size() - 1;
<a name="l00091"></a>00091     <a class="code" href="classGitModel.html#a4f3e07cf6dddd098c4c4f0978be0fe90" title="Maps child indexes to tree indexes.">childPointer_</a>[<a class="code" href="classGitModel.html#a47f5ebf88be96b003b4bf31bfafff141" title="Returns a child index.">index</a>] = result;
<a name="l00092"></a>00092     <span class="keywordflow">return</span> result;
<a name="l00093"></a>00093   } <span class="keywordflow">else</span>
<a name="l00094"></a>00094     <span class="keywordflow">return</span> i-&gt;second;
<a name="l00095"></a>00095 }
<a name="l00096"></a>00096 
<a name="l00097"></a><a class="code" href="classGitModel.html#a78b52d35048396dc60aa660b1d5bcf55">00097</a> <span class="keywordtype">int</span> <a class="code" href="classGitModel.html#a78b52d35048396dc60aa660b1d5bcf55" title="Returns the column count.">GitModel::columnCount</a>(<span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html">WModelIndex</a>&amp; index)<span class="keyword"> const</span>
<a name="l00098"></a>00098 <span class="keyword"></span>{
<a name="l00099"></a>00099   <span class="comment">// currently only one column</span>
<a name="l00100"></a>00100   <span class="keywordflow">return</span> 1;
<a name="l00101"></a>00101 }
<a name="l00102"></a>00102 
<a name="l00103"></a><a class="code" href="classGitModel.html#aa5f75edbb291d0b03c22fc8a608a3171">00103</a> <span class="keywordtype">int</span> <a class="code" href="classGitModel.html#aa5f75edbb291d0b03c22fc8a608a3171" title="Returns the row count.">GitModel::rowCount</a>(<span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html">WModelIndex</a>&amp; index)<span class="keyword"> const</span>
<a name="l00104"></a>00104 <span class="keyword"></span>{
<a name="l00105"></a>00105   <span class="comment">// we are looking for the git SHA1 id of a tree object (since only folders</span>
<a name="l00106"></a>00106   <span class="comment">// may contain children).</span>
<a name="l00107"></a>00107   <a class="code" href="classGit_1_1ObjectId.html" title="Git object Id.">Git::ObjectId</a> objectId;
<a name="l00108"></a>00108   <span class="keywordtype">int</span> treeId;
<a name="l00109"></a>00109 
<a name="l00110"></a>00110   <span class="keywordflow">if</span> (index.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html#a1d4b05ee51c5c6961d6123565fd77c82">isValid</a>()) {
<a name="l00111"></a>00111     <span class="comment">// only column 0 items may contain children</span>
<a name="l00112"></a>00112     <span class="keywordflow">if</span> (index.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html#a0e6568dd7113662c3c378e2084729581">column</a>() != 0)
<a name="l00113"></a>00113       <span class="keywordflow">return</span> 0;
<a name="l00114"></a>00114 
<a name="l00115"></a>00115     <a class="code" href="structGit_1_1Object.html" title="Git object.">Git::Object</a> o = <a class="code" href="classGitModel.html#a0eec46284e84c7deeb1a39eb7185d1d1" title="Get the Git::Object that corresponds to an index.">getObject</a>(index);
<a name="l00116"></a>00116     <span class="keywordflow">if</span> (o.<a class="code" href="structGit_1_1Object.html#a2ea77791af4fa6012b350469654332cc">type</a> == <a class="code" href="classGit.html#ab282f46c36a47ddff9bc7be7c993041aae94d3a7ff6594f6b3b0dc121fbd01564">Git::Tree</a>) {
<a name="l00117"></a>00117       objectId = o.<a class="code" href="structGit_1_1Object.html#a2e3989983524516e4a936714b55736ff">id</a>;
<a name="l00118"></a>00118       treeId = <a class="code" href="classGitModel.html#ab2efe3ae663dfbd670dc41dd3cb8d2a0" title="Get or allocate an id for a folder.">getTreeId</a>(index.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html#a7ae49c4d0edaf9a520e6f5e8a62c3904">internalId</a>(), index.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html#aa4f1385223391c46ee200a57672f6046">row</a>());
<a name="l00119"></a>00119     } <span class="keywordflow">else</span>
<a name="l00120"></a>00120       <span class="comment">// not a folder: no children</span>
<a name="l00121"></a>00121       <span class="keywordflow">return</span> 0;
<a name="l00122"></a>00122   } <span class="keywordflow">else</span> {
<a name="l00123"></a>00123     treeId = 0;
<a name="l00124"></a>00124     <span class="comment">// the index corresponds to the root object</span>
<a name="l00125"></a>00125     <span class="keywordflow">if</span> (<a class="code" href="classGitModel.html#a59307dfceb1f5712914e0754144422e4" title="List of folder objects.">treeData_</a>.empty())
<a name="l00126"></a>00126       <span class="comment">// model not yet loaded !</span>
<a name="l00127"></a>00127       <span class="keywordflow">return</span> 0;
<a name="l00128"></a>00128     <span class="keywordflow">else</span>
<a name="l00129"></a>00129       objectId = <a class="code" href="classGitModel.html#a59307dfceb1f5712914e0754144422e4" title="List of folder objects.">treeData_</a>[0].treeObject();
<a name="l00130"></a>00130   }
<a name="l00131"></a>00131 
<a name="l00132"></a>00132   <span class="keywordflow">return</span> <a class="code" href="classGitModel.html#a59307dfceb1f5712914e0754144422e4" title="List of folder objects.">treeData_</a>[treeId].rowCount();
<a name="l00133"></a>00133 }
<a name="l00134"></a>00134 
<a name="l00135"></a><a class="code" href="classGitModel.html#a6e30f8cddbb1039d7d749eaafa1120a8">00135</a> boost::any <a class="code" href="classGitModel.html#a6e30f8cddbb1039d7d749eaafa1120a8" title="Returns data.">GitModel::data</a>(<span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html">WModelIndex</a>&amp; index, <span class="keywordtype">int</span> role)<span class="keyword"> const</span>
<a name="l00136"></a>00136 <span class="keyword"></span>{
<a name="l00137"></a>00137   <span class="keywordflow">if</span> (!index.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html#a1d4b05ee51c5c6961d6123565fd77c82">isValid</a>())
<a name="l00138"></a>00138     <span class="keywordflow">return</span> boost::any();
<a name="l00139"></a>00139 
<a name="l00140"></a>00140   <span class="comment">/* Only 3 data roles on column 0 data are supported:</span>
<a name="l00141"></a>00141 <span class="comment">   * - DisplayRole: the file name</span>
<a name="l00142"></a>00142 <span class="comment">   * - DecorationRole: an icon (folder or file)</span>
<a name="l00143"></a>00143 <span class="comment">   * - ContentsRole: the file contents</span>
<a name="l00144"></a>00144 <span class="comment">   */</span>
<a name="l00145"></a>00145   <span class="keywordflow">if</span> (index.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html#a0e6568dd7113662c3c378e2084729581">column</a>() == 0) {
<a name="l00146"></a>00146     <a class="code" href="structGit_1_1Object.html" title="Git object.">Git::Object</a> <span class="keywordtype">object</span> = <a class="code" href="classGitModel.html#a0eec46284e84c7deeb1a39eb7185d1d1" title="Get the Git::Object that corresponds to an index.">getObject</a>(index);
<a name="l00147"></a>00147     <span class="keywordflow">if</span> (role == <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/group__modelview.html#gga0ae864e12320f9f89172735e075ed068a5ed17aded8a0e3b712698cf85a218f1f">DisplayRole</a>) {
<a name="l00148"></a>00148       <span class="keywordflow">if</span> (<span class="keywordtype">object</span>.type == <a class="code" href="classGit.html#ab282f46c36a47ddff9bc7be7c993041aae94d3a7ff6594f6b3b0dc121fbd01564">Git::Tree</a>)
<a name="l00149"></a>00149         <span class="keywordflow">return</span> <span class="keywordtype">object</span>.name + <span class="charliteral">&#39;/&#39;</span>;
<a name="l00150"></a>00150       <span class="keywordflow">else</span>
<a name="l00151"></a>00151         <span class="keywordflow">return</span> <span class="keywordtype">object</span>.name;
<a name="l00152"></a>00152     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (role == <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/group__modelview.html#gga0ae864e12320f9f89172735e075ed068aab6678fc176854f7990d6cff4eed779e">DecorationRole</a>) {
<a name="l00153"></a>00153       <span class="keywordflow">if</span> (<span class="keywordtype">object</span>.type == <a class="code" href="classGit.html#ab282f46c36a47ddff9bc7be7c993041aa64c3a7b641cdc0cb2c4203fc0bef1a4a">Git::Blob</a>)
<a name="l00154"></a>00154         <span class="keywordflow">return</span> <span class="keyword">static_cast&lt;</span><span class="keyword">const </span><span class="keywordtype">char</span>*<span class="keyword">&gt;</span>(<span class="stringliteral">&quot;icons/git-blob.png&quot;</span>);
<a name="l00155"></a>00155       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<span class="keywordtype">object</span>.type == <a class="code" href="classGit.html#ab282f46c36a47ddff9bc7be7c993041aae94d3a7ff6594f6b3b0dc121fbd01564">Git::Tree</a>)
<a name="l00156"></a>00156         <span class="keywordflow">return</span> <span class="keyword">static_cast&lt;</span><span class="keyword">const </span><span class="keywordtype">char</span>*<span class="keyword">&gt;</span>(<span class="stringliteral">&quot;icons/git-tree.png&quot;</span>);
<a name="l00157"></a>00157     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (role == <a class="code" href="classGitModel.html#a49c30024f0241738b30cf4cec589b292" title="The role which may be used on a file to retrieve its contents.">ContentsRole</a>) {
<a name="l00158"></a>00158       <span class="keywordflow">if</span> (<span class="keywordtype">object</span>.type == <a class="code" href="classGit.html#ab282f46c36a47ddff9bc7be7c993041aa64c3a7b641cdc0cb2c4203fc0bef1a4a">Git::Blob</a>)
<a name="l00159"></a>00159         <span class="keywordflow">return</span> <a class="code" href="classGitModel.html#afc8ff43e47ae51ce2af04d63a162be8e" title="The git repository.">git_</a>.<a class="code" href="classGit.html#acf2d699d9f9bdfb42afb0f61e85b2f88" title="Return the raw contents of a git object.">catFile</a>(<span class="keywordtype">object</span>.<span class="keywordtype">id</span>);
<a name="l00160"></a>00160     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (role == <a class="code" href="classGitModel.html#a9419f872ce68506009748f0595400ef7">FilePathRole</a>) {
<a name="l00161"></a>00161       <span class="keywordflow">return</span> boost::any();
<a name="l00162"></a>00162     }
<a name="l00163"></a>00163   }
<a name="l00164"></a>00164 
<a name="l00165"></a>00165   <span class="keywordflow">return</span> boost::any();
<a name="l00166"></a>00166 }
<a name="l00167"></a>00167 
<a name="l00168"></a><a class="code" href="classGitModel.html#a23fb9ef292e416fbdf20790a2a93c016">00168</a> boost::any <a class="code" href="classGitModel.html#a23fb9ef292e416fbdf20790a2a93c016" title="Returns header data.">GitModel::headerData</a>(<span class="keywordtype">int</span> section, <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#a2a8d45559e16a0185bf61bfad0a67912">Orientation</a> orientation,
<a name="l00169"></a>00169                                 <span class="keywordtype">int</span> role)<span class="keyword"> const</span>
<a name="l00170"></a>00170 <span class="keyword"></span>{
<a name="l00171"></a>00171   <span class="keywordflow">if</span> (orientation == <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#a2a8d45559e16a0185bf61bfad0a67912ac2ebf22b096a22b18eef23e736aa2e28">Horizontal</a> &amp;&amp; role == <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/group__modelview.html#gga0ae864e12320f9f89172735e075ed068a5ed17aded8a0e3b712698cf85a218f1f">DisplayRole</a>)
<a name="l00172"></a>00172     <span class="keywordflow">return</span> <span class="keyword">static_cast&lt;</span><span class="keyword">const </span><span class="keywordtype">char</span>*<span class="keyword">&gt;</span>(<span class="stringliteral">&quot;File&quot;</span>);
<a name="l00173"></a>00173   <span class="keywordflow">else</span>
<a name="l00174"></a>00174     <span class="keywordflow">return</span> boost::any();
<a name="l00175"></a>00175 }
<a name="l00176"></a>00176 
<a name="l00177"></a><a class="code" href="classGitModel.html#a0eec46284e84c7deeb1a39eb7185d1d1">00177</a> <a class="code" href="structGit_1_1Object.html" title="Git object.">Git::Object</a> <a class="code" href="classGitModel.html#a0eec46284e84c7deeb1a39eb7185d1d1" title="Get the Git::Object that corresponds to an index.">GitModel::getObject</a>(<span class="keyword">const</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html">WModelIndex</a>&amp; index)<span class="keyword"> const</span>
<a name="l00178"></a>00178 <span class="keyword"></span>{
<a name="l00179"></a>00179   <span class="keywordtype">int</span> parentId = index.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html#a7ae49c4d0edaf9a520e6f5e8a62c3904">internalId</a>();
<a name="l00180"></a>00180   <span class="keyword">const</span> <a class="code" href="classGitModel_1_1Tree.html" title="Used to uniquely locate a folder within the folder hierarchy.">Tree</a>&amp; parentItem = <a class="code" href="classGitModel.html#a59307dfceb1f5712914e0754144422e4" title="List of folder objects.">treeData_</a>[parentId];
<a name="l00181"></a>00181   <span class="keywordflow">return</span> <a class="code" href="classGitModel.html#afc8ff43e47ae51ce2af04d63a162be8e" title="The git repository.">git_</a>.<a class="code" href="classGit.html#a910f3a6123b494897cdedf7ba4ef648b" title="Get some info on a tree object.">treeGetObject</a>(parentItem.<a class="code" href="classGitModel_1_1Tree.html#a963ec0ca3e067d01ba9fd98359c44216" title="Returns the SHA1 id for the git tree object.">treeObject</a>(), index.<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html#aa4f1385223391c46ee200a57672f6046">row</a>());
<a name="l00182"></a>00182 }
</pre></div></div>
</div>
<hr size="1"><address style="text-align: right; margin: 3px"><small>
Generated on Thu Nov 1 2012 for <a href="http://www.webtoolkit.eu/wt">the
C++ Web Toolkit (Wt)</a> by&nbsp;<a
href="http://www.doxygen.org/index.html"><img src="doxygen.png"
alt="doxygen" border="0" style="vertical-align: middle; display:
inline-block; height: 2em"></a> 1.7.5.1</small></address>
</body>
</html>