Wt examples 3.3.12
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{
38public:
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
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
104private:
107
112 struct ChildIndex {
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)
138 treeObject_(object),
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_
Used to uniquely locate a folder within the folder hierarchy.
Definition GitModel.h:131
Tree(int parentId, int index, const Git::ObjectId &object, int rowCount)
Constructor.
Definition GitModel.h:135
int parentId() const
Returns the parent id.
Definition GitModel.h:146
int index() const
Returns the child index within the parent folder.
Definition GitModel.h:152
int rowCount() const
Returns the (cached) row count.
Definition GitModel.h:160
const Git::ObjectId & treeObject() const
Returns the SHA1 id for the git tree object.
Definition GitModel.h:156
ChildIndex index_
Definition GitModel.h:163
Git::ObjectId treeObject_
Definition GitModel.h:164
A model that retrieves revision trees from a git repository.
Definition GitModel.h:37
virtual int rowCount(const Wt::WModelIndex &parent=Wt::WModelIndex()) const
Returns the row count.
Definition GitModel.C:103
virtual int columnCount(const Wt::WModelIndex &parent=Wt::WModelIndex()) const
Returns the column count.
Definition GitModel.C:97
static const int ContentsRole
The role which may be used on a file to retrieve its contents.
Definition GitModel.h:41
Git::Object getObject(const Wt::WModelIndex &index) const
Get the Git::Object that corresponds to an index.
Definition GitModel.C:177
ChildPointerMap childPointer_
Maps child indexes to tree indexes.
Definition GitModel.h:192
int getTreeId(int parentId, int childIndex) const
Get or allocate an id for a folder.
Definition GitModel.C:76
std::vector< Tree > treeData_
List of folder objects.
Definition GitModel.h:182
std::map< ChildIndex, int > ChildPointerMap
Definition GitModel.h:168
virtual boost::any data(const Wt::WModelIndex &index, int role=Wt::DisplayRole) const
Returns data.
Definition GitModel.C:135
static const int FilePathRole
Definition GitModel.h:42
void setRepositoryPath(const std::string &repositoryPath)
Set the repository and load its 'master' revision.
Definition GitModel.C:15
virtual Wt::WModelIndex index(int row, int column, const Wt::WModelIndex &parent=Wt::WModelIndex()) const
Returns a child index.
Definition GitModel.C:56
virtual boost::any headerData(int section, Wt::Orientation orientation=Wt::Horizontal, int role=Wt::DisplayRole) const
Returns header data.
Definition GitModel.C:168
void loadRevision(const std::string &revName)
Load a particular revision.
Definition GitModel.C:21
Git git_
The git repository.
Definition GitModel.h:106
Git object Id.
Definition Git.h:39
Git utility class for browsing git archives.
Definition Git.h:24
WObject * parent() const
DisplayRole
UserRole
Orientation
Horizontal
Index usable as a key to a map, that identifies a child/row within a tree.
Definition GitModel.h:112
bool operator<(const ChildIndex &other) const
Definition GitModel.h:119
ChildIndex(int aParent, int anIndex)
Definition GitModel.h:116
Git object.
Definition Git.h:63

Generated on Fri May 17 2024 for the C++ Web Toolkit (Wt) by doxygen 1.9.8