Wt examples  4.2.2
GitModel.h
Go to the documentation of this file.
1 // This may look like C code, but it's really -*- C++ -*-
2 /*
3  * Copyright (C) 2008 Emweb bv, Herent, Belgium.
4  *
5  * See the LICENSE file for terms of use.
6  */
7 #ifndef GIT_MODEL_H_
8 #define GIT_MODEL_H_
9 
10 #include <Wt/WAbstractItemModel.h>
11 
12 #include "Git.h"
13 
14 using namespace Wt;
15 
20 
39 {
40 public:
43  static const ItemDataRole ContentsRole;
44  static const ItemDataRole FilePathRole;
45 
48  GitModel();
49 
52  void setRepositoryPath(const std::string& repositoryPath);
53 
59  void loadRevision(const std::string& revName);
60 
65  virtual WModelIndex parent(const WModelIndex& index) const;
66 
71  virtual int columnCount(const WModelIndex& parent = WModelIndex())
72  const;
73 
79  virtual int rowCount(const WModelIndex& parent = WModelIndex()) const;
80 
87  virtual WModelIndex
88  index(int row, int column, const WModelIndex& parent = WModelIndex())
89  const;
90 
95  virtual cpp17::any
96  data(const WModelIndex& index, ItemDataRole role = ItemDataRole::Display) const;
97 
100  virtual cpp17::any
101  headerData(int section, Orientation orientation = Orientation::Horizontal,
102  ItemDataRole role = ItemDataRole::Display) const;
103 
105 
106 private:
109 
114  struct ChildIndex {
115  int parentId;
116  int index;
117 
118  ChildIndex(int aParent, int anIndex)
119  : parentId(aParent), index(anIndex) { }
120 
121  bool operator< (const ChildIndex& other) const {
122  if (parentId < other.parentId)
123  return true;
124  else if (parentId > other.parentId)
125  return false;
126  else return index < other.index;
127  }
128  };
129 
133  class Tree {
134  public:
137  Tree(int parentId, int index, const Git::ObjectId& object,
138  int rowCount)
139  : index_(parentId, index),
140  treeObject_(object),
141  rowCount_(rowCount)
142  { }
143 
148  int parentId() const { return index_.parentId; }
149 
154  int index() const { return index_.index; }
155 
158  const Git::ObjectId& treeObject() const { return treeObject_; }
159 
162  int rowCount() const { return rowCount_; }
163 
164  private:
168  };
169 
170  typedef std::map<ChildIndex, int> ChildPointerMap;
171 
184  mutable std::vector<Tree> treeData_;
185 
195 
202  int getTreeId(int parentId, int childIndex) const;
203 
206  Git::Object getObject(const WModelIndex& index) const;
207 };
208 
211 #endif // GIT_MODEL_H_
GitModel
A model that retrieves revision trees from a git repository.
Definition: GitModel.h:38
GitModel::ChildPointerMap
std::map< ChildIndex, int > ChildPointerMap
Definition: GitModel.h:170
Wt
GitModel::Tree::treeObject_
Git::ObjectId treeObject_
Definition: GitModel.h:166
GitModel::ChildIndex::parentId
int parentId
Definition: GitModel.h:115
GitModel::ChildIndex::index
int index
Definition: GitModel.h:116
GitModel::Tree::treeObject
const Git::ObjectId & treeObject() const
Returns the SHA1 id for the git tree object.
Definition: GitModel.h:158
Git::ObjectId
Git object Id.
Definition: Git.h:39
GitModel::Tree::rowCount_
int rowCount_
Definition: GitModel.h:167
GitModel::ChildIndex
Index usable as a key to a map, that identifies a child/row within a tree.
Definition: GitModel.h:114
GitModel::Tree::rowCount
int rowCount() const
Returns the (cached) row count.
Definition: GitModel.h:162
Wt::ItemDataRole
GitModel::ContentsRole
static const ItemDataRole ContentsRole
The role which may be used on a file to retrieve its contents.
Definition: GitModel.h:43
Git
Git utility class for browsing git archives.
Definition: Git.h:24
Wt::WAbstractItemModel::data
virtual cpp17::any data(const WModelIndex &index, ItemDataRole role=ItemDataRole::Display) const=0
GitModel::Tree::index
int index() const
Returns the child index within the parent folder.
Definition: GitModel.h:154
GitModel::ChildIndex::ChildIndex
ChildIndex(int aParent, int anIndex)
Definition: GitModel.h:118
GitModel::treeData_
std::vector< Tree > treeData_
List of folder objects.
Definition: GitModel.h:184
Wt::ItemDataRole::Display
static constexpr const int Display
GitModel::childPointer_
ChildPointerMap childPointer_
Maps child indexes to tree indexes.
Definition: GitModel.h:194
Wt::WAbstractItemModel
GitModel::FilePathRole
static const ItemDataRole FilePathRole
Definition: GitModel.h:44
Git.h
GitModel::Tree::parentId
int parentId() const
Returns the parent id.
Definition: GitModel.h:148
GitModel::Tree::index_
ChildIndex index_
Definition: GitModel.h:165
Wt::Orientation::Horizontal
@ Horizontal
GitModel::Tree::Tree
Tree(int parentId, int index, const Git::ObjectId &object, int rowCount)
Constructor.
Definition: GitModel.h:137
GitModel::git_
Git git_
The git repository.
Definition: GitModel.h:108
Wt::Orientation
Orientation
Git::Object
Git object.
Definition: Git.h:63
GitModel::Tree
Used to uniquely locate a folder within the folder hierarchy.
Definition: GitModel.h:133
Wt::WModelIndex

Generated on Fri Mar 20 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.17