Wt examples  3.7.1
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>
11 
12 #include "Git.h"
13 
18 
37 {
38 public:
41  static const int ContentsRole = Wt::UserRole;
42  static const int FilePathRole = Wt::UserRole + 1;
43 
47 
50  void setRepositoryPath(const std::string& repositoryPath);
51 
57  void loadRevision(const std::string& revName);
58 
63  virtual Wt::WModelIndex parent(const Wt::WModelIndex& index) const;
64 
69  virtual int columnCount(const Wt::WModelIndex& parent = Wt::WModelIndex())
70  const;
71 
77  virtual int rowCount(const Wt::WModelIndex& parent = Wt::WModelIndex()) const;
78 
85  virtual Wt::WModelIndex
86  index(int row, int column, const Wt::WModelIndex& parent = Wt::WModelIndex())
87  const;
88 
93  virtual boost::any
94  data(const Wt::WModelIndex& index, int role = Wt::DisplayRole) const;
95 
98  virtual boost::any
99  headerData(int section, Wt::Orientation orientation = Wt::Horizontal,
100  int role = Wt::DisplayRole) const;
101 
102  using WAbstractItemModel::data;
103 
104 private:
107 
112  struct ChildIndex {
113  int parentId;
114  int index;
115 
116  ChildIndex(int aParent, int anIndex)
117  : parentId(aParent), index(anIndex) { }
118 
119  bool operator< (const ChildIndex& other) const {
120  if (parentId < other.parentId)
121  return true;
122  else if (parentId > other.parentId)
123  return false;
124  else return index < other.index;
125  }
126  };
127 
131  class Tree {
132  public:
135  Tree(int parentId, int index, const Git::ObjectId& object,
136  int rowCount)
137  : index_(parentId, index),
138  treeObject_(object),
139  rowCount_(rowCount)
140  { }
141 
146  int parentId() const { return index_.parentId; }
147 
152  int index() const { return index_.index; }
153 
156  const Git::ObjectId& treeObject() const { return treeObject_; }
157 
160  int rowCount() const { return rowCount_; }
161 
162  private:
166  };
167 
168  typedef std::map<ChildIndex, int> ChildPointerMap;
169 
182  mutable std::vector<Tree> treeData_;
183 
192  mutable ChildPointerMap childPointer_;
193 
200  int getTreeId(int parentId, int childIndex) const;
201 
205 };
206 
209 #endif // GIT_MODEL_H_
void setRepositoryPath(const std::string &repositoryPath)
Set the repository and load its &#39;master&#39; revision.
Definition: GitModel.C:15
Tree(int parentId, int index, const Git::ObjectId &object, int rowCount)
Constructor.
Definition: GitModel.h:135
GitModel(Wt::WObject *parent=0)
Constructor.
Definition: GitModel.C:11
Index usable as a key to a map, that identifies a child/row within a tree.
Definition: GitModel.h:112
int getTreeId(int parentId, int childIndex) const
Get or allocate an id for a folder.
Definition: GitModel.C:76
virtual boost::any data(const Wt::WModelIndex &index, int role=Wt::DisplayRole) const
Returns data.
Definition: GitModel.C:135
Git git_
The git repository.
Definition: GitModel.h:106
const Git::ObjectId & treeObject() const
Returns the SHA1 id for the git tree object.
Definition: GitModel.h:156
bool operator<(const ChildIndex &other) const
Definition: GitModel.h:119
Git object Id.
Definition: Git.h:39
Git object.
Definition: Git.h:63
virtual int rowCount(const Wt::WModelIndex &parent=Wt::WModelIndex()) const
Returns the row count.
Definition: GitModel.C:103
static const int ContentsRole
The role which may be used on a file to retrieve its contents.
Definition: GitModel.h:41
int index() const
Returns the child index within the parent folder.
Definition: GitModel.h:152
Git::ObjectId treeObject_
Definition: GitModel.h:164
Git utility class for browsing git archives.
Definition: Git.h:24
int rowCount() const
Returns the (cached) row count.
Definition: GitModel.h:160
ChildIndex(int aParent, int anIndex)
Definition: GitModel.h:116
ChildPointerMap childPointer_
Maps child indexes to tree indexes.
Definition: GitModel.h:192
virtual Wt::WModelIndex parent(const Wt::WModelIndex &index) const
Returns the parent index.
Definition: GitModel.C:40
Git::Object getObject(const Wt::WModelIndex &index) const
Get the Git::Object that corresponds to an index.
Definition: GitModel.C:177
ChildIndex index_
Definition: GitModel.h:163
Orientation
virtual boost::any headerData(int section, Wt::Orientation orientation=Wt::Horizontal, int role=Wt::DisplayRole) const
Returns header data.
Definition: GitModel.C:168
std::map< ChildIndex, int > ChildPointerMap
Definition: GitModel.h:168
static const int FilePathRole
Definition: GitModel.h:42
int parentId() const
Returns the parent id.
Definition: GitModel.h:146
A model that retrieves revision trees from a git repository.
Definition: GitModel.h:36
std::vector< Tree > treeData_
List of folder objects.
Definition: GitModel.h:182
void loadRevision(const std::string &revName)
Load a particular revision.
Definition: GitModel.C:21
virtual Wt::WModelIndex index(int row, int column, const Wt::WModelIndex &parent=Wt::WModelIndex()) const
Returns a child index.
Definition: GitModel.C:56
virtual int columnCount(const Wt::WModelIndex &parent=Wt::WModelIndex()) const
Returns the column count.
Definition: GitModel.C:97
Used to uniquely locate a folder within the folder hierarchy.
Definition: GitModel.h:131

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13