13 #include <QStringList>
18 typedef QAbstractProxyModel
BASE;
35 if (!sourceIndex.isValid())
37 assert(sourceIndex.model() == sourceModel());
41 return createIndex(sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer());
45 #define ATTRIBUTE __attribute__((__may_alias__))
56 const QAbstractItemModel *m;
63 if (!proxyIndex.isValid())
65 assert(proxyIndex.model() ==
this);
68 QModelIndex sourceIndex;
69 auto *hack =
reinterpret_cast<KDPrivateModelIndex *
>(&sourceIndex);
70 hack->r = proxyIndex.row();
71 hack->c = proxyIndex.column();
72 hack->p = proxyIndex.internalPointer();
73 hack->m = sourceModel();
74 assert(sourceIndex.isValid());
85 sourceModel()->disconnect(
this);
86 BASE::setSourceModel(model);
96 connect(model, &QAbstractItemModel::dataChanged,
99 connect(model, &QAbstractItemModel::columnsAboutToBeInserted,
101 connect(model, &QAbstractItemModel::columnsInserted,
103 connect(model, &QAbstractItemModel::columnsAboutToBeRemoved,
105 connect(model, &QAbstractItemModel::columnsRemoved,
108 connect(model, &QAbstractItemModel::rowsAboutToBeInserted,
110 connect(model, &QAbstractItemModel::rowsInserted,
112 connect(model, &QAbstractItemModel::rowsAboutToBeRemoved,
114 connect(model, &QAbstractItemModel::rowsRemoved,
143 Q_EMIT layoutAboutToBeChanged();
254 return sourceModel()->columnCount(
mapToSource(idx));
278 QModelIndexList source_indexes;
279 for (
int i = 0; i < indexes.count(); ++i)
281 return sourceModel()->mimeData(source_indexes);
286 if ((row == -1) && (column == -1))
288 int source_destination_row = -1;
289 int source_destination_column = -1;
290 QModelIndex source_parent;
293 source_destination_row = sourceModel()->rowCount(source_parent);
295 QModelIndex proxy_index =
index(row, column,
parent);
296 QModelIndex source_index =
mapToSource(proxy_index);
297 source_destination_row = source_index.row();
298 source_destination_column = source_index.column();
299 source_parent = source_index.parent();
301 return sourceModel()->dropMimeData(data, action, source_destination_row, source_destination_column, source_parent);
306 return sourceModel()->mimeTypes();
311 return sourceModel()->supportedDropActions();
314 #include "moc_kdganttforwardingproxymodel.cpp"
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
Converts indexes in the source model to indexes in the proxy model.
~ForwardingProxyModel() override
QModelIndex mapToSource(const QModelIndex &proxyIndex) const override
Converts indexes in the proxy model to indexes in the source model.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
ForwardingProxyModel(QObject *parent=nullptr)
Constructor.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QModelIndex parent(const QModelIndex &idx) const override
QStringList mimeTypes() const override
virtual void sourceModelAboutToBeReset()
Called when the source model is about to be reset.
virtual void sourceRowsRemoved(const QModelIndex &, int start, int end)
Called after rows have been removed from the source model.
virtual void sourceColumnsAboutToBeInserted(const QModelIndex &idx, int start, int end)
Called just before columns are inserted into the source model.
virtual void sourceLayoutAboutToBeChanged()
Called just before the layout of the source model is changed.
virtual void sourceDataChanged(const QModelIndex &from, const QModelIndex &to)
Called when the data in an existing item in the source model changes.
Qt::DropActions supportedDropActions() const override
virtual void sourceColumnsAboutToBeRemoved(const QModelIndex &idx, int start, int end)
Called just before columns are removed from the source model.
virtual void sourceLayoutChanged()
Called when the layout of the source model has changed.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
int rowCount(const QModelIndex &idx=QModelIndex()) const override
virtual void sourceColumnsRemoved(const QModelIndex &idx, int start, int end)
Called after columns have been removed from the source model.
virtual void sourceModelReset()
Called when the source model is reset.
void setSourceModel(QAbstractItemModel *model) override
Sets the model to be used as the source model for this proxy.
virtual void sourceRowsInserted(const QModelIndex &idx, int start, int end)
Called after rows have been inserted into the source model.
int columnCount(const QModelIndex &idx=QModelIndex()) const override
virtual void sourceRowsAboutToBeRemoved(const QModelIndex &, int start, int end)
Called just before rows are removed from the source model.
virtual void sourceColumnsInserted(const QModelIndex &idx, int start, int end)
Called after columns have been inserted into the source model.
virtual void sourceRowsAboutToBeInserted(const QModelIndex &idx, int start, int end)
Called just before rows are inserted into the source model.
QMimeData * mimeData(const QModelIndexList &indexes) const override