I'm trying to create in GitAhead a different view of the diff files. They provide already a Treemodel which works fine. I'm trying to put a wrapper between the model and the view to show only the changed files. For the moment I would like to just forward the model, but the view does not show anything. rowCount() is called fine and then also index() is called, but data() is never called. Does anybody know why I'm not able to forward the model?
TreeWrapper.h:
#include "TreeWrapper.h"
#include "TreeModel.h"
#include "conf/Settings.h"
#include "git/Blob.h"
#include "git/Diff.h"
#include "git/RevWalk.h"
#include "git/Submodule.h"
#include <QStringBuilder>
#include <QUrl>
namespace {
const QString kLinkFmt = "<a href='%1'>%2</a>";
} // anon. namespace
TreeWrapper::TreeWrapper(TreeModel* model, QObject *parent):
mModel(model),
QAbstractItemModel(parent)
{
}
TreeWrapper::~TreeWrapper()
{
}
void TreeWrapper::setTree(const git::Tree &tree, const git::Diff &diff)
{
beginResetModel();
mModel->setTree(tree, diff);
endResetModel();
}
int TreeWrapper::rowCount(const QModelIndex &parent) const
{
int count = mModel->rowCount(parent);
return count;
}
int TreeWrapper::columnCount(const QModelIndex &parent) const
{
return mModel->columnCount(parent);
}
bool TreeWrapper::hasChildren(const QModelIndex &parent) const
{
bool children = mModel->hasChildren(parent);
return children;
}
QModelIndex TreeWrapper::parent(const QModelIndex &index) const
{
return mModel->parent(index);
}
QModelIndex TreeWrapper::index(
int row,
int column,
const QModelIndex &parent) const
{
QModelIndex index = mModel->index(row, column, parent);
bool valid = index.isValid();
return index;
}
QVariant TreeWrapper::data(const QModelIndex &index, int role) const
{
return mModel->data(index, role);
}
bool TreeWrapper::setData(
const QModelIndex &index,
const QVariant &value,
int role)
{
return mModel->setData(index, value, role);
}
Qt::ItemFlags TreeWrapper::flags(const QModelIndex &index) const
{
return mModel->flags(index);
}
TreeWrapper.h:
#ifndef TREEWRAPPER
#define TREEWRAPPER
#include "git/Diff.h"
#include "git/Index.h"
#include "git/Tree.h"
#include "git/Repository.h"
#include <QAbstractItemModel>
#include <QFileIconProvider>
class TreeModel;
class TreeWrapper : public QAbstractItemModel
{
Q_OBJECT
public:
TreeWrapper(TreeModel* model, QObject *parent = nullptr);
virtual ~TreeWrapper();
void setTree(const git::Tree &tree, const git::Diff &diff = git::Diff());
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &index) const override;
QModelIndex index(
int row,
int column,
const QModelIndex &parent = QModelIndex()) const override;
QVariant data(
const QModelIndex &index,
int role = Qt::DisplayRole) const override;
bool setData(
const QModelIndex &index,
const QVariant &value,
int role = Qt::EditRole) override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
private:
TreeModel* mModel{nullptr};
};
#endif // TREEWRAPPER
The lower treeview uses directly the Treemodel, in the upper one, I would like to put the Wrapper between the model and the view.