5#include <private/qabstractitemmodel_p.h>
49 using ConnArray = std::array<QMetaObject::Connection, 13>;
59 auto byModelPtr = [
m](
const auto &modInfo) {
return modInfo.model ==
m; };
133 if (!sourceIndex.isValid())
136 if (!
d->containsSourceModel(sourceModel)) {
137 qWarning(
"QConcatenateTablesProxyModel: index from wrong model passed to mapFromSource");
138 Q_ASSERT(!
"QConcatenateTablesProxyModel: index from wrong model passed to mapFromSource");
141 if (sourceIndex.column() >=
d->m_columnCount)
143 int rowsPrior = d_func()->computeRowsPrior(sourceModel);
144 return createIndex(rowsPrior + sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer());
154 if (!proxyIndex.isValid())
156 if (proxyIndex.model() !=
this) {
157 qWarning(
"QConcatenateTablesProxyModel: index from wrong model passed to mapToSource");
158 Q_ASSERT(!
"QConcatenateTablesProxyModel: index from wrong model passed to mapToSource");
161 const int row = proxyIndex.row();
162 const auto result =
d->sourceModelForRow(
row);
165 return result.sourceModel->index(
result.sourceRow, proxyIndex.column());
175 if (!sourceIndex.isValid())
177 return sourceIndex.data(role);
200 return sourceIndex.model()->itemData(sourceIndex);
212 return sourceModel->
setItemData(sourceIndex, roles);
224 if (
d->m_models.isEmpty())
227 if (!
index.isValid())
228 return d->m_models.at(0).model->flags(
index);
231 return sourceIndex.model()->flags(sourceIndex);
242 if (
d->m_models.isEmpty())
244 switch (orientation) {
246 return d->m_models.at(0).model->headerData(section, orientation, role);
248 const auto result =
d->sourceModelForRow(section);
250 return result.sourceModel->headerData(
result.sourceRow, orientation, role);
265 return d->m_columnCount;
278 const auto result =
d->sourceModelForRow(
row);
300 return d->m_rowCount;
310 if (
d->m_models.isEmpty())
312 return d->m_models.at(0).model->mimeTypes();
333 const auto result =
d->sourceModelForRow(firstIndex.
row());
339 sourceIndexes.append(sourceIndex);
341 return result.sourceModel->mimeData(sourceIndexes);
354 *sourceModel =
m_models.constLast().model;
360 *sourceRow =
result.sourceRow;
361 *sourceModel =
result.sourceModel;
367 const int targetRow =
parent.row();
372 *sourceParent = sourceIndex;
373 *sourceModel =
result.sourceModel;
384 if (
d->m_models.isEmpty())
407 if (
d->m_models.isEmpty())
425 if (
d->m_models.isEmpty() || !
index.isValid())
429 return sourceIndex.model()->span(sourceIndex);
440 QList<QAbstractItemModel *>
ret;
441 ret.reserve(
d->m_models.size());
442 for (
const auto &
info :
d->m_models)
458 Q_ASSERT(!
d->containsSourceModel(sourceModel));
460 const int newRows = sourceModel->
rowCount();
463 d->m_rowCount += newRows;
464 d->m_models.emplace_back(sourceModel, std::array{
497 d->updateColumnCount();
509 auto it =
d->findSourceModel(sourceModel);
511 for (
auto &
c :
it->connections)
515 const int rowsPrior =
d->computeRowsPrior(sourceModel);
519 d->m_models.erase(
it);
524 d->updateColumnCount();
577 Q_ASSERT(newColCount >= oldColCount);
578 if (newColCount > oldColCount)
595 q->endInsertColumns();
608 Q_ASSERT(newColCount <= oldColCount);
609 if (newColCount < oldColCount)
624 q->endRemoveColumns();
630 const QList<int> &roles)
644 emit q->dataChanged(myFrom, myTo, roles);
652 if (!sourceParents.isEmpty() && !sourceParents.contains(
QModelIndex()))
655 emit q->layoutAboutToBeChanged({},
hint);
661 for (
const QModelIndex &proxyPersistentIndex : persistentIndexList) {
663 Q_ASSERT(proxyPersistentIndex.isValid());
665 Q_ASSERT(srcPersistentIndex.isValid());
674 if (!sourceParents.isEmpty() && !sourceParents.contains(
QModelIndex()))
679 q->changePersistentIndex(proxyIdx, newProxyIdx);
692 q->beginResetModel();
712 auto byColumnCount = [](
const auto &
a,
const auto &
b) {
713 return a.model->columnCount() <
b.model->columnCount();
716 return it->model->columnCount();
724 if (columnDiff > 0) {
727 q->endInsertColumns();
728 }
else if (columnDiff < 0) {
730 q->beginRemoveColumns(
QModelIndex(), lastColumn + columnDiff + 1, lastColumn);
732 q->endRemoveColumns();
738 int newColumnCount = 0;
743 newColumnCount = colCount;
745 newColumnCount =
qMin(colCount, newColumnCount);
747 return newColumnCount;
754 if (
model == sourceModel)
767 if (rowCount + subRowCount >
row) {
771 rowCount += subRowCount;
779#include "moc_qconcatenatetablesproxymodel.cpp"
Q_INVOKABLE int const QModelIndex & parent
Returns the parent of the model item with the given index.
void modelAboutToBeReset(QPrivateSignal)
virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
Returns {true} if a model can accept a drop of the data.
void columnsRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted after columns have been removed from the model.
LayoutChangeHint
This enum describes the way the model changes layout.
void rowsAboutToBeInserted(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted just before rows are inserted into the model.
void columnsAboutToBeInserted(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted just before columns are inserted into the model.
Q_INVOKABLE bool hasIndex(int row, int column, const QModelIndex &parent=QModelIndex()) const
Returns {true} if the model returns a valid QModelIndex for row and column with parent,...
void modelReset(QPrivateSignal)
void endRemoveRows()
Ends a row removal operation.
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
Handles the data supplied by a drag and drop operation that ended with the given action.
void layoutAboutToBeChanged(const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
This signal is emitted whenever the data in an existing item changes.
virtual Q_INVOKABLE int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
void columnsAboutToBeRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted just before columns are removed from the model.
void layoutChanged(const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
bool checkIndex(const QModelIndex &index, CheckIndexOptions options=CheckIndexOption::NoOption) const
Q_INVOKABLE int sourceRow
virtual Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Sets the role data for the item at index to value.
void rowsAboutToBeRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted just before rows are removed from the model.
void endInsertRows()
Ends a row insertion operation.
virtual bool setItemData(const QModelIndex &index, const QMap< int, QVariant > &roles)
Sets the role data for the item at index to the associated value in roles, for every Qt::ItemDataRole...
void rowsInserted(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted after rows have been inserted into the model.
Q_INVOKABLE int sourceColumn
QModelIndex createIndex(int row, int column, const void *data=nullptr) const
Creates a model index for the given row and column with the internal pointer ptr.
void columnsInserted(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted after columns have been inserted into the model.
void beginRemoveRows(const QModelIndex &parent, int first, int last)
Begins a row removal operation.
void beginInsertRows(const QModelIndex &parent, int first, int last)
Begins a row insertion operation.
void rowsRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted after rows have been removed from the model.
QList< QPersistentModelIndex > layoutChangePersistentIndexes
QConcatenateTablesProxyModelPrivate()
void slotSourceLayoutAboutToBeChanged(const QList< QPersistentModelIndex > &sourceParents, QAbstractItemModel::LayoutChangeHint hint)
bool containsSourceModel(const QAbstractItemModel *m) const
void slotRowsAboutToBeRemoved(const QModelIndex &, int start, int end)
void slotDataChanged(const QModelIndex &from, const QModelIndex &to, const QList< int > &roles)
SourceModelForRowResult sourceModelForRow(int row) const
QList< QModelIndex > layoutChangeProxyIndexes
void slotColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
QList< ModelInfo >::const_iterator findSourceModel(const QAbstractItemModel *m) const
void slotColumnsRemoved(const QModelIndex &parent, int, int)
int columnCountAfterChange(const QAbstractItemModel *model, int newCount) const
void slotRowsAboutToBeInserted(const QModelIndex &, int start, int end)
bool mapDropCoordinatesToSource(int row, int column, const QModelIndex &parent, int *sourceRow, int *sourceColumn, QModelIndex *sourceParent, QAbstractItemModel **sourceModel) const
void slotColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end)
void slotRowsInserted(const QModelIndex &, int start, int end)
void slotColumnsInserted(const QModelIndex &parent, int, int)
void slotModelAboutToBeReset()
void slotSourceLayoutChanged(const QList< QPersistentModelIndex > &sourceParents, QAbstractItemModel::LayoutChangeHint hint)
int computeRowsPrior(const QAbstractItemModel *sourceModel) const
int calculatedColumnCount() const
QList< ModelInfo > m_models
void slotRowsRemoved(const QModelIndex &, int start, int end)
The QConcatenateTablesProxyModel class proxies multiple source models, concatenating their rows.
QStringList mimeTypes() const override
This method returns the mime types for the first source model.
QMap< int, QVariant > itemData(const QModelIndex &proxyIndex) const override
\reimp
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
\reimp
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
\reimp
Q_SCRIPTABLE void addSourceModel(QAbstractItemModel *sourceModel)
Adds a source model sourceModel, below all previously added source models.
QList< QAbstractItemModel * > sourceModels() const
Returns a list of models that were added as source models for this proxy model.
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Returns the source index for a given proxyIndex.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
\reimp
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
Returns the proxy index for a given sourceIndex, which can be from any of the source models.
QConcatenateTablesProxyModel(QObject *parent=nullptr)
Constructs a concatenate-rows proxy model with the given parent.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
This method returns the horizontal header data for the first source model, and the vertical header da...
bool setItemData(const QModelIndex &index, const QMap< int, QVariant > &roles) override
\reimp
~QConcatenateTablesProxyModel()
Destroys this proxy model.
Qt::ItemFlags flags(const QModelIndex &index) const override
Returns the flags for the given index.
QMimeData * mimeData(const QModelIndexList &indexes) const override
The call is forwarded to the source model of the first index in the list of indexes.
Q_SCRIPTABLE void removeSourceModel(QAbstractItemModel *sourceModel)
Removes the source model sourceModel, which was previously added to this proxy.
QSize span(const QModelIndex &index) const override
\reimp
int columnCount(const QModelIndex &parent=QModelIndex()) const override
This method returns the column count of the source model with the smallest number of columns.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
QConcatenateTablesProxyModel handles dropping onto an item, between items, and after the last item.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
\reimp
int rowCount(const QModelIndex &parent=QModelIndex()) const override
\reimp
qsizetype size() const noexcept
bool isEmpty() const noexcept
const_reference at(qsizetype i) const noexcept
void reserve(qsizetype size)
void append(parameter_type t)
QModelIndex siblingAtColumn(int column) const
Returns the sibling at column for the current row.
constexpr int row() const noexcept
Returns the row this model index refers to.
constexpr int column() const noexcept
Returns the column this model index refers to.
constexpr bool isValid() const noexcept
Returns {true} if this model index is valid; otherwise returns {false}.
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
const_iterator cend() const noexcept
int rowCount(const QModelIndex &parent=QModelIndex()) const override
If the database supports returning the size of a query (see QSqlDriver::hasFeature()),...
int columnCount(const QModelIndex &parent=QModelIndex()) const override
\reimp
QSet< QString >::iterator it
Combined button and popup list for selecting options.
QList< QString > QStringList
Constructs a string list that contains the given string, str.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
[7]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLenum GLsizei void GLsizei void * column
GLdouble GLdouble GLdouble GLdouble q
GLenum GLenum GLsizei void * row
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
QSqlQueryModel * model
[16]
myObject disconnect()
[26]
QAbstractItemModel * model
std::array< QMetaObject::Connection, 13 > ConnArray
ModelInfo(QAbstractItemModel *m, ConnArray &&con)
SourceModelForRowResult()
QAbstractItemModel * sourceModel