37 : QAbstractItemModel (parent)
44 if (parent.isValid ())
45 return QModelIndex ();
47 return createIndex (row, column);
52 return QModelIndex ();
62 return parent.isValid () ? 0 : 1;
75 SIGNAL (rowsInserted (QModelIndex,
int,
int)),
77 SLOT (handleRowsInserted (QModelIndex,
int,
int)));
79 SIGNAL (rowsAboutToBeRemoved (QModelIndex,
int,
int)),
81 SLOT (handleRowsAboutRemoved (QModelIndex,
int,
int)));
83 SIGNAL (dataChanged (QModelIndex, QModelIndex)),
85 SLOT (handleDataChanged (QModelIndex, QModelIndex)));
92 SIGNAL (rowsInserted (QModelIndex,
int,
int)),
94 SLOT (handleRowsInserted (QModelIndex,
int,
int)));
96 SIGNAL (rowsAboutToBeRemoved (QModelIndex,
int,
int)),
98 SLOT (handleRowsAboutRemoved (QModelIndex,
int,
int)));
100 SIGNAL (dataChanged (QModelIndex, QModelIndex)),
102 SLOT (handleDataChanged (QModelIndex, QModelIndex)));
110 void FlattenFilterModel::handleDataChanged (
const QModelIndex& top,
const QModelIndex& bottom)
112 const auto&
parent = top.parent ();
113 for (
int i = top.row (); i <= bottom.row (); ++i)
120 const auto& ourIdx =
index (pos, 0);
121 emit dataChanged (ourIdx, ourIdx);
125 void FlattenFilterModel::handleRowsInserted (
const QModelIndex& parent,
int start,
int end)
127 for (
int i = start; i <= end; ++i)
129 const auto& child =
Source_->index (i, 0, parent);
137 if (
int rc =
Source_->rowCount (child))
138 handleRowsInserted (child, 0, rc - 1);
142 void FlattenFilterModel::handleRowsAboutRemoved (
const QModelIndex& parent,
int start,
int end)
144 for (
int i = start; i <= end; ++i)
146 const auto& child =
Source_->index (i, 0, parent);
151 beginRemoveRows (QModelIndex (), pos, pos);
156 if (
int rc =
Source_->rowCount (child))
157 handleRowsAboutRemoved (child, 0, rc - 1);
QList< QPersistentModelIndex > SourceIndexes_
FlattenFilterModel(QObject *parent=0)
Constructs the model with the given parent.
void SetSource(QAbstractItemModel *model)
Sets the source model to model.
QModelIndex index(int, int, const QModelIndex &=QModelIndex()) const
Reimplemented from QAbstractItemModel.
QAbstractItemModel * Source_
int rowCount(const QModelIndex &parent=QModelIndex()) const
Reimplemented from QAbstractItemModel.
int columnCount(const QModelIndex &parent=QModelIndex()) const
Reimplemented from QAbstractItemModel.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Reimplemented from QAbstractItemModel.
QModelIndex parent(const QModelIndex &) const
Reimplemented from QAbstractItemModel.
virtual bool IsIndexAccepted(const QModelIndex &index) const
Checks whether the given index should be included in the model.