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
00045 GitModel(Wt::WObject *parent = 0);
00046
00049 void setRepositoryPath(const std::string& repositoryPath);
00050
00056 void loadRevision(const std::string& revName);
00057
00062 virtual Wt::WModelIndex parent(const Wt::WModelIndex& index) const;
00063
00068 virtual int columnCount(const Wt::WModelIndex& parent = Wt::WModelIndex())
00069 const;
00070
00076 virtual int rowCount(const Wt::WModelIndex& parent = Wt::WModelIndex()) const;
00077
00084 virtual Wt::WModelIndex
00085 index(int row, int column, const Wt::WModelIndex& parent = Wt::WModelIndex())
00086 const;
00087
00092 virtual boost::any
00093 data(const Wt::WModelIndex& index, int role = Wt::DisplayRole) const;
00094
00097 virtual boost::any
00098 headerData(int section, Wt::Orientation orientation = Wt::Horizontal,
00099 int role = Wt::DisplayRole) const;
00100
00101 using WAbstractItemModel::data;
00102
00103 private:
00105 Git git_;
00106
00111 struct ChildIndex {
00112 int parentId;
00113 int index;
00114
00115 ChildIndex(int aParent, int anIndex)
00116 : parentId(aParent), index(anIndex) { }
00117
00118 bool operator< (const ChildIndex& other) const {
00119 if (parentId < other.parentId)
00120 return true;
00121 else if (parentId > other.parentId)
00122 return false;
00123 else return index < other.index;
00124 }
00125 };
00126
00130 class Tree {
00131 public:
00134 Tree(int parentId, int index, const Git::ObjectId& object)
00135 : index_(parentId, index),
00136 treeObject_(object)
00137 { }
00138
00143 int parentId() const { return index_.parentId; }
00144
00149 int index() const { return index_.index; }
00150
00153 const Git::ObjectId& treeObject() const { return treeObject_; }
00154
00155 private:
00156 ChildIndex index_;
00157 Git::ObjectId treeObject_;
00158 };
00159
00160 typedef std::map<ChildIndex, int> ChildPointerMap;
00161
00174 mutable std::vector<Tree> treeData_;
00175
00184 mutable ChildPointerMap childPointer_;
00185
00192 int getTreeId(int parentId, int childIndex) const;
00193
00196 Git::Object getObject(const Wt::WModelIndex& index) const;
00197 };
00198
00201 #endif // GIT_MODEL_H_