Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #ifndef GIT_MODEL_H_
00008 #define GIT_MODEL_H_
00009
00010 #include <Wt/WAbstractItemModel>
00011
00012 #include "Git.h"
00013
00018
00036 class GitModel : public Wt::WAbstractItemModel
00037 {
00038 public:
00041 static const int ContentsRole = Wt::UserRole;
00042 static const int FilePathRole = Wt::UserRole + 1;
00043
00046 GitModel(Wt::WObject *parent = 0);
00047
00050 void setRepositoryPath(const std::string& repositoryPath);
00051
00057 void loadRevision(const std::string& revName);
00058
00063 virtual Wt::WModelIndex parent(const Wt::WModelIndex& index) const;
00064
00069 virtual int columnCount(const Wt::WModelIndex& parent = Wt::WModelIndex())
00070 const;
00071
00077 virtual int rowCount(const Wt::WModelIndex& parent = Wt::WModelIndex()) const;
00078
00085 virtual Wt::WModelIndex
00086 index(int row, int column, const Wt::WModelIndex& parent = Wt::WModelIndex())
00087 const;
00088
00093 virtual boost::any
00094 data(const Wt::WModelIndex& index, int role = Wt::DisplayRole) const;
00095
00098 virtual boost::any
00099 headerData(int section, Wt::Orientation orientation = Wt::Horizontal,
00100 int role = Wt::DisplayRole) const;
00101
00102 using WAbstractItemModel::data;
00103
00104 private:
00106 Git git_;
00107
00112 struct ChildIndex {
00113 int parentId;
00114 int index;
00115
00116 ChildIndex(int aParent, int anIndex)
00117 : parentId(aParent), index(anIndex) { }
00118
00119 bool operator< (const ChildIndex& other) const {
00120 if (parentId < other.parentId)
00121 return true;
00122 else if (parentId > other.parentId)
00123 return false;
00124 else return index < other.index;
00125 }
00126 };
00127
00131 class Tree {
00132 public:
00135 Tree(int parentId, int index, const Git::ObjectId& object,
00136 int rowCount)
00137 : index_(parentId, index),
00138 treeObject_(object),
00139 rowCount_(rowCount)
00140 { }
00141
00146 int parentId() const { return index_.parentId; }
00147
00152 int index() const { return index_.index; }
00153
00156 const Git::ObjectId& treeObject() const { return treeObject_; }
00157
00160 int rowCount() const { return rowCount_; }
00161
00162 private:
00163 ChildIndex index_;
00164 Git::ObjectId treeObject_;
00165 int rowCount_;
00166 };
00167
00168 typedef std::map<ChildIndex, int> ChildPointerMap;
00169
00182 mutable std::vector<Tree> treeData_;
00183
00192 mutable ChildPointerMap childPointer_;
00193
00200 int getTreeId(int parentId, int childIndex) const;
00201
00204 Git::Object getObject(const Wt::WModelIndex& index) const;
00205 };
00206
00209 #endif // GIT_MODEL_H_