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)));
93 SIGNAL (rowsInserted (QModelIndex,
int,
int)),
95 SLOT (handleRowsInserted (QModelIndex,
int,
int)));
97 SIGNAL (rowsAboutToBeRemoved (QModelIndex,
int,
int)),
99 SLOT (handleRowsAboutRemoved (QModelIndex,
int,
int)));
101 SIGNAL (dataChanged (QModelIndex, QModelIndex)),
103 SLOT (handleDataChanged (QModelIndex, QModelIndex)));
111 void FlattenFilterModel::handleDataChanged (
const QModelIndex& top,
const QModelIndex& bottom)
113 const auto&
parent = top.parent ();
114 for (
int i = top.row (); i <= bottom.row (); ++i)
121 const auto& ourIdx =
index (pos, 0);
122 emit dataChanged (ourIdx, ourIdx);
126 void FlattenFilterModel::handleRowsInserted (
const QModelIndex&
parent,
int start,
int end)
128 for (
int i = start; i <= end; ++i)
130 const auto& child =
Source_->index (i, 0, parent);
138 if (
int rc =
Source_->rowCount (child))
139 handleRowsInserted (child, 0, rc - 1);
143 void FlattenFilterModel::handleRowsAboutRemoved (
const QModelIndex& parent,
int start,
int end)
145 for (
int i = start; i <= end; ++i)
147 const auto& child =
Source_->index (i, 0, parent);
152 beginRemoveRows (QModelIndex (), pos, pos);
157 if (
int rc =
Source_->rowCount (child))
158 handleRowsAboutRemoved (child, 0, rc - 1);
QList< QPersistentModelIndex > SourceIndexes_
detail::ExprTree< detail::ExprType::LeafStaticPlaceholder, boost::mpl::int_< Idx >> pos
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.