Wt examples
3.7.1
|
A model that retrieves revision trees from a git repository. More...
#include <GitModel.h>
Classes | |
class | ChildIndex |
Index usable as a key to a map, that identifies a child/row within a tree. More... | |
class | Tree |
Used to uniquely locate a folder within the folder hierarchy. More... | |
Public Member Functions | |
GitModel (Wt::WObject *parent=0) | |
Constructor. More... | |
void | setRepositoryPath (const std::string &repositoryPath) |
Set the repository and load its 'master' revision. More... | |
void | loadRevision (const std::string &revName) |
Load a particular revision. More... | |
virtual Wt::WModelIndex | parent (const Wt::WModelIndex &index) const |
Returns the parent index. More... | |
virtual int | columnCount (const Wt::WModelIndex &parent=Wt::WModelIndex()) const |
Returns the column count. More... | |
virtual int | rowCount (const Wt::WModelIndex &parent=Wt::WModelIndex()) const |
Returns the row count. More... | |
virtual Wt::WModelIndex | index (int row, int column, const Wt::WModelIndex &parent=Wt::WModelIndex()) const |
Returns a child index. More... | |
virtual boost::any | data (const Wt::WModelIndex &index, int role=Wt::DisplayRole) const |
Returns data. More... | |
virtual boost::any | headerData (int section, Wt::Orientation orientation=Wt::Horizontal, int role=Wt::DisplayRole) const |
Returns header data. More... | |
![]() | |
WAbstractItemModel () | |
virtual WFlags< ItemFlag > | flags (const WModelIndex &index) const |
virtual WFlags< HeaderFlag > | headerFlags (int section, Orientation orientation=Orientation::Horizontal) const |
virtual bool | hasChildren (const WModelIndex &index) const |
virtual cpp17::any | data (const WModelIndex &index, ItemDataRole role=ItemDataRole::Display) const=0 |
virtual DataMap | itemData (const WModelIndex &index) const |
virtual cpp17::any | headerData (int section, Orientation orientation=Orientation::Horizontal, ItemDataRole role=ItemDataRole::Display) const |
virtual WModelIndexList | match (const WModelIndex &start, ItemDataRole role, const cpp17::any &value, int hits=-1, WFlags< MatchFlag > flags=WFlags< MatchFlag >(MatchFlag::StartsWith|MatchFlag::Wrap)) const |
cpp17::any | data (int row, int column, ItemDataRole role=ItemDataRole::Display, const WModelIndex &parent=WModelIndex()) const |
virtual bool | hasIndex (int row, int column, const WModelIndex &parent=WModelIndex()) const |
virtual bool | insertColumns (int column, int count, const WModelIndex &parent=WModelIndex()) |
virtual bool | insertRows (int row, int count, const WModelIndex &parent=WModelIndex()) |
virtual bool | removeColumns (int column, int count, const WModelIndex &parent=WModelIndex()) |
virtual bool | removeRows (int row, int count, const WModelIndex &parent=WModelIndex()) |
virtual bool | setData (const WModelIndex &index, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit) |
virtual bool | setItemData (const WModelIndex &index, const DataMap &values) |
virtual bool | setHeaderData (int section, Orientation orientation, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit) |
bool | setHeaderData (int section, const cpp17::any &value) |
virtual void | sort (int column, SortOrder order=SortOrder::Ascending) |
virtual void | expandColumn (int column) |
virtual void | collapseColumn (int column) |
virtual void * | toRawIndex (const WModelIndex &index) const |
virtual WModelIndex | fromRawIndex (void *rawIndex) const |
virtual std::string | mimeType () const |
virtual std::vector< std::string > | acceptDropMimeTypes () const |
virtual void | dropEvent (const WDropEvent &e, DropAction action, int row, int column, const WModelIndex &parent) |
bool | insertColumn (int column, const WModelIndex &parent=WModelIndex()) |
bool | insertRow (int row, const WModelIndex &parent=WModelIndex()) |
bool | removeColumn (int column, const WModelIndex &parent=WModelIndex()) |
bool | removeRow (int row, const WModelIndex &parent=WModelIndex()) |
bool | setData (int row, int column, const cpp17::any &value, ItemDataRole role=ItemDataRole::Edit, const WModelIndex &parent=WModelIndex()) |
virtual Signal< WModelIndex, int, int > & | columnsAboutToBeInserted () |
virtual Signal< WModelIndex, int, int > & | columnsAboutToBeRemoved () |
virtual Signal< WModelIndex, int, int > & | columnsInserted () |
virtual Signal< WModelIndex, int, int > & | columnsRemoved () |
virtual Signal< WModelIndex, int, int > & | rowsAboutToBeInserted () |
virtual Signal< WModelIndex, int, int > & | rowsAboutToBeRemoved () |
virtual Signal< WModelIndex, int, int > & | rowsInserted () |
virtual Signal< WModelIndex, int, int > & | rowsRemoved () |
virtual Signal< WModelIndex, WModelIndex > & | dataChanged () |
virtual Signal< Orientation, int, int > & | headerDataChanged () |
virtual Signal & | layoutAboutToBeChanged () |
virtual Signal & | layoutChanged () |
virtual Signal & | modelReset () |
![]() | |
void | addChild (std::unique_ptr< WObject > child) |
Child * | addChild (std::unique_ptr< Child > child) |
std::unique_ptr< WObject > | removeChild (WObject *child) |
std::unique_ptr< Child > | removeChild (Child *child) |
virtual const std::string | id () const |
virtual void | setObjectName (const std::string &name) |
virtual std::string | objectName () const |
void | resetLearnedSlots () |
void | resetLearnedSlot (void(T::*method)()) |
WStatelessSlot * | implementStateless (void(T::*method)()) |
WStatelessSlot * | implementStateless (void(T::*method)(), void(T::*undoMethod)()) |
void | isNotStateless () |
WStatelessSlot * | implementJavaScript (void(T::*method)(), const std::string &jsCode) |
![]() | |
observable () noexcept | |
virtual | ~observable () |
auto | bindSafe (void(C::*method)(Args...)) noexcept |
auto | bindSafe (void(C::*method)(Args...) const) const noexcept |
auto | bindSafe (const Function &function) noexcept |
Static Public Attributes | |
static const int | ContentsRole = Wt::UserRole |
The role which may be used on a file to retrieve its contents. More... | |
static const int | FilePathRole = Wt::UserRole + 1 |
Private Types | |
typedef std::map< ChildIndex, int > | ChildPointerMap |
Private Member Functions | |
int | getTreeId (int parentId, int childIndex) const |
Get or allocate an id for a folder. More... | |
Git::Object | getObject (const Wt::WModelIndex &index) const |
Get the Git::Object that corresponds to an index. More... | |
Private Attributes | |
Git | git_ |
The git repository. More... | |
std::vector< Tree > | treeData_ |
List of folder objects. More... | |
ChildPointerMap | childPointer_ |
Maps child indexes to tree indexes. More... | |
Additional Inherited Members | |
![]() | |
typedef std::map< ItemDataRole, cpp17::any > | DataMap |
![]() | |
typedef void(WObject::* | Method) () |
![]() | |
void | reset () |
WModelIndex | createIndex (int row, int column, void *ptr) const |
WModelIndex | createIndex (int row, int column, ::uint64_t id) const |
void | beginInsertColumns (const WModelIndex &parent, int first, int last) |
void | beginInsertRows (const WModelIndex &parent, int first, int last) |
void | beginRemoveColumns (const WModelIndex &parent, int first, int last) |
void | beginRemoveRows (const WModelIndex &parent, int first, int last) |
void | endInsertColumns () |
void | endInsertRows () |
void | endRemoveColumns () |
void | endRemoveRows () |
![]() | |
virtual WStatelessSlot * | getStateless (Method method) |
A model that retrieves revision trees from a git repository.
In its present form, it presents only a single column of data: the file names. Additional data could be easily added. Git "tree" objects correspond to folders, and "blob" objects to files.
The model is read-only, does not support sorting (that could be provided by using a WSortFilterProxyModel).
The model loads only minimal information in memory: to create model indexes for folders. These cannot be uniquely identified by their SHA1 id, since two identical folders at different locations would have the same SHA1 id.
The internal id of model indexes created by the model uniquely identify a containing folder for a particular file.
Definition at line 36 of file GitModel.h.
|
private |
Definition at line 168 of file GitModel.h.
GitModel::GitModel | ( | Wt::WObject * | parent = 0 | ) |
|
virtual |
Returns the column count.
Returns 1.
Implements Wt::WAbstractItemModel.
Definition at line 97 of file GitModel.C.
|
virtual |
Returns data.
Returns only data corresponding to DisplayRole and ContentsRole.
Definition at line 135 of file GitModel.C.
|
private |
Get the Git::Object that corresponds to an index.
Definition at line 177 of file GitModel.C.
|
private |
Get or allocate an id for a folder.
The folder is identified by a given childIndex within a parent folder. This method adds data to the treeData_ (and childPointer_) data structures.
Definition at line 76 of file GitModel.C.
|
virtual |
Returns header data.
Definition at line 168 of file GitModel.C.
|
virtual |
Returns a child index.
Consults the internal data structure to create a child index. If necessary, the internal data structure is expanded by adding an entry for using the parent index as a parent index.
Implements Wt::WAbstractItemModel.
Definition at line 56 of file GitModel.C.
void GitModel::loadRevision | ( | const std::string & | revName | ) |
Load a particular revision.
The revision name may be any revision accepted by git, by git-rev-parse(1).
Definition at line 21 of file GitModel.C.
|
virtual |
Returns the parent index.
Consults the internal data structure to find the parent index.
Implements Wt::WAbstractItemModel.
Definition at line 40 of file GitModel.C.
|
virtual |
Returns the row count.
Returns 0 unless the item represents a folder, in which case it returns the number of items in the tree object that corresponds to the folder.
Implements Wt::WAbstractItemModel.
Definition at line 103 of file GitModel.C.
void GitModel::setRepositoryPath | ( | const std::string & | repositoryPath | ) |
Set the repository and load its 'master' revision.
Definition at line 15 of file GitModel.C.
|
mutableprivate |
Maps child indexes to tree indexes.
This map provides a way to lookup data in treeData_. It has an entry corresponding to every entry in treeData_: it maps child indexes for folders to indexes in the treeData_ vector.
It is populated on-the-fly, as the user navigates the model.
Definition at line 192 of file GitModel.h.
|
static |
The role which may be used on a file to retrieve its contents.
Definition at line 41 of file GitModel.h.
|
static |
Definition at line 42 of file GitModel.h.
|
private |
The git repository.
Definition at line 106 of file GitModel.h.
|
mutableprivate |
List of folder objects.
This list contains folders for which a model index has been allocated.
Model indexes have an internal id that are indexes into this vector, identifying the folder that contains a particular file.
Note: only for folders this is needed, since files will never be used as a 'parent' index.
It is populated on-the-fly, as the user navigates the model.
Definition at line 182 of file GitModel.h.