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 : index_(parentId, index),
00137 treeObject_(object)
00138 { }
00139
00144 int parentId() const { return index_.parentId; }
00145
00150 int index() const { return index_.index; }
00151
00154 const Git::ObjectId& treeObject() const { return treeObject_; }
00155
00156 private:
00157 ChildIndex index_;
00158 Git::ObjectId treeObject_;
00159 };
00160
00161 typedef std::map<ChildIndex, int> ChildPointerMap;
00162
00175 mutable std::vector<Tree> treeData_;
00176
00185 mutable ChildPointerMap childPointer_;
00186
00193 int getTreeId(int parentId, int childIndex) const;
00194
00197 Git::Object getObject(const Wt::WModelIndex& index) const;
00198 };
00199
00202 #endif // GIT_MODEL_H_