16 return QModelIndex ();
18 return createIndex (row, column);
23 return QModelIndex ();
33 return parent.isValid () ? 0 : 1;
54 &QAbstractItemModel::rowsInserted,
56 &FlattenFilterModel::HandleRowsInserted);
58 &QAbstractItemModel::rowsAboutToBeRemoved,
60 &FlattenFilterModel::HandleRowsAboutRemoved);
62 &QAbstractItemModel::dataChanged,
64 &FlattenFilterModel::HandleDataChanged);
72 void FlattenFilterModel::HandleDataChanged (
const QModelIndex& top,
const QModelIndex& bottom)
74 const auto&
parent = top.parent ();
75 for (
int i = top.row (); i <= bottom.row (); ++i)
82 const auto& ourIdx =
index (pos, 0);
83 emit dataChanged (ourIdx, ourIdx);
87 void FlattenFilterModel::HandleRowsInserted (
const QModelIndex& parent,
int start,
int end)
89 for (
int i = start; i <= end; ++i)
99 if (
int rc =
Source_->rowCount (child))
100 HandleRowsInserted (child, 0, rc - 1);
104 void FlattenFilterModel::HandleRowsAboutRemoved (
const QModelIndex& parent,
int start,
int end)
106 for (
int i = start; i <= end; ++i)
113 beginRemoveRows (QModelIndex (), pos, pos);
118 if (
int rc =
Source_->rowCount (child))
119 HandleRowsAboutRemoved (child, 0, rc - 1);
QModelIndex index(int, int, const QModelIndex &={}) const override
Reimplemented from QAbstractItemModel.
QList< QPersistentModelIndex > SourceIndexes_
void SetSource(QAbstractItemModel *model)
Sets the source model to model.
QAbstractItemModel * Source_
int rowCount(const QModelIndex &parent={}) const override
Reimplemented from QAbstractItemModel.
QModelIndex parent(const QModelIndex &) const override
Reimplemented from QAbstractItemModel.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Reimplemented from QAbstractItemModel.
virtual bool IsIndexAccepted(const QModelIndex &index) const
Checks whether the given index should be included in the model.
int columnCount(const QModelIndex &parent={}) const override
Reimplemented from QAbstractItemModel.