Difference between QConcatenateTablesProxyModel and KConcatenateRowsProxyModel

Fusion Future qydwhotmail at gmail.com
Fri Apr 22 02:39:08 BST 2022


One major difference I have found is that KConcatenateRowsProxyModel 
will check if sourceModel exists when mapping from/to sourceModel, but 
QConcatenateTablesProxyModel won't. So if QConcatenateTablesProxyModel 
doesn't receive `rowsRemoved` signal from sourceModel, 
QConcatenateTablesProxyModel will crash the program.

For example:

# KConcatenateRowsProxyModel

```cpp
QModelIndex KConcatenateRowsProxyModel::index(int row, int column, const 
QModelIndex &parent) const
{
     if (row < 0) {
         return {};
     }
     if (column < 0) {
         return {};
     }
     int sourceRow;
     QAbstractItemModel *sourceModel = d->sourceModelForRow(row, 
&sourceRow);
     if (!sourceModel) {
         return QModelIndex();
     }
     return mapFromSource(sourceModel->index(sourceRow, column, parent));
}
```

# QConcatenateTablesProxyModel

```cpp
QModelIndex QConcatenateTablesProxyModel::index(int row, int column, 
const QModelIndex &parent) const
{
     Q_D(const QConcatenateTablesProxyModel);
     Q_ASSERT(hasIndex(row, column, parent));
     if (!hasIndex(row, column, parent))
         return QModelIndex();
     Q_ASSERT(checkIndex(parent, 
QAbstractItemModel::CheckIndexOption::ParentIsInvalid)); // flat model
     const auto result = d->sourceModelForRow(row);
     Q_ASSERT(result.sourceModel);
     return mapFromSource(result.sourceModel->index(result.sourceRow, 
column));
}
```


More information about the kde-devel mailing list