Wt examples  3.3.0
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 bvba, Kessel-Lo, 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 
193 
200  int getTreeId(int parentId, int childIndex) const;
201 
205 };
206 
209 #endif // GIT_MODEL_H_

Generated on Fri May 31 2013 for the C++ Web Toolkit (Wt) by doxygen 1.8.3.1