aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlmodels/qqmltreemodeltotablemodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qmlmodels/qqmltreemodeltotablemodel.cpp')
-rw-r--r--src/qmlmodels/qqmltreemodeltotablemodel.cpp87
1 files changed, 42 insertions, 45 deletions
diff --git a/src/qmlmodels/qqmltreemodeltotablemodel.cpp b/src/qmlmodels/qqmltreemodeltotablemodel.cpp
index 792fb53f56..db128761cd 100644
--- a/src/qmlmodels/qqmltreemodeltotablemodel.cpp
+++ b/src/qmlmodels/qqmltreemodeltotablemodel.cpp
@@ -26,53 +26,52 @@ QAbstractItemModel *QQmlTreeModelToTableModel::model() const
return m_model;
}
-void QQmlTreeModelToTableModel::setModel(QAbstractItemModel *arg)
+void QQmlTreeModelToTableModel::connectToModel()
{
- struct Cx {
- const char *signal;
- const char *slot;
- };
- const Cx connections[] = {
- { SIGNAL(destroyed(QObject*)),
- SLOT(modelHasBeenDestroyed()) },
- { SIGNAL(modelReset()),
- SLOT(modelHasBeenReset()) },
- { SIGNAL(dataChanged(QModelIndex,QModelIndex,QList<int>)),
- SLOT(modelDataChanged(QModelIndex,QModelIndex,QList<int>)) },
-
- { SIGNAL(layoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)),
- SLOT(modelLayoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)) },
- { SIGNAL(layoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)),
- SLOT(modelLayoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)) },
-
- { SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
- SLOT(modelRowsAboutToBeInserted(QModelIndex,int,int)) },
- { SIGNAL(rowsInserted(QModelIndex,int,int)),
- SLOT(modelRowsInserted(QModelIndex,int,int)) },
- { SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
- SLOT(modelRowsAboutToBeRemoved(QModelIndex,int,int)) },
- { SIGNAL(rowsRemoved(QModelIndex,int,int)),
- SLOT(modelRowsRemoved(QModelIndex,int,int)) },
- { SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
- SLOT(modelRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)) },
- { SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
- SLOT(modelRowsMoved(QModelIndex,int,int,QModelIndex,int)) },
-
- { SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
- SLOT(modelColumnsAboutToBeInserted(QModelIndex,int,int))},
- { SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
- SLOT(modelColumnsAboutToBeRemoved(QModelIndex,int,int))},
- { SIGNAL(columnsInserted(QModelIndex,int,int)),
- SLOT(modelColumnsInserted(QModelIndex,int,int))},
- { SIGNAL(columnsRemoved(QModelIndex,int,int)),
- SLOT(modelColumnsRemoved(QModelIndex,int,int))},
- { nullptr, nullptr }
+ m_connections = {
+ QObject::connect(m_model, &QAbstractItemModel::destroyed,
+ this, &QQmlTreeModelToTableModel::modelHasBeenDestroyed),
+ QObject::connect(m_model, &QAbstractItemModel::modelReset,
+ this, &QQmlTreeModelToTableModel::modelHasBeenReset),
+ QObject::connect(m_model, &QAbstractItemModel::dataChanged,
+ this, &QQmlTreeModelToTableModel::modelDataChanged),
+
+ QObject::connect(m_model, &QAbstractItemModel::layoutAboutToBeChanged,
+ this, &QQmlTreeModelToTableModel::modelLayoutAboutToBeChanged),
+ QObject::connect(m_model, &QAbstractItemModel::layoutChanged,
+ this, &QQmlTreeModelToTableModel::modelLayoutChanged),
+
+ QObject::connect(m_model, &QAbstractItemModel::rowsAboutToBeInserted,
+ this, &QQmlTreeModelToTableModel::modelRowsAboutToBeInserted),
+ QObject::connect(m_model, &QAbstractItemModel::rowsInserted,
+ this, &QQmlTreeModelToTableModel::modelRowsInserted),
+ QObject::connect(m_model, &QAbstractItemModel::rowsAboutToBeRemoved,
+ this, &QQmlTreeModelToTableModel::modelRowsAboutToBeRemoved),
+ QObject::connect(m_model, &QAbstractItemModel::rowsRemoved,
+ this, &QQmlTreeModelToTableModel::modelRowsRemoved),
+ QObject::connect(m_model, &QAbstractItemModel::rowsAboutToBeMoved,
+ this, &QQmlTreeModelToTableModel::modelRowsAboutToBeMoved),
+ QObject::connect(m_model, &QAbstractItemModel::rowsMoved,
+ this, &QQmlTreeModelToTableModel::modelRowsMoved),
+
+ QObject::connect(m_model, &QAbstractItemModel::columnsAboutToBeInserted,
+ this, &QQmlTreeModelToTableModel::modelColumnsAboutToBeInserted),
+ QObject::connect(m_model, &QAbstractItemModel::columnsAboutToBeRemoved,
+ this, &QQmlTreeModelToTableModel::modelColumnsAboutToBeRemoved),
+ QObject::connect(m_model, &QAbstractItemModel::columnsInserted,
+ this, &QQmlTreeModelToTableModel::modelColumnsInserted),
+ QObject::connect(m_model, &QAbstractItemModel::columnsRemoved,
+ this, &QQmlTreeModelToTableModel::modelColumnsRemoved)
};
+}
+void QQmlTreeModelToTableModel::setModel(QAbstractItemModel *arg)
+{
if (m_model != arg) {
if (m_model) {
- for (const Cx *c = &connections[0]; c->signal; c++)
- disconnect(m_model, c->signal, this, c->slot);
+ for (const auto &c : m_connections)
+ QObject::disconnect(c);
+ m_connections.fill({});
}
clearModelData();
@@ -82,9 +81,7 @@ void QQmlTreeModelToTableModel::setModel(QAbstractItemModel *arg)
m_rootIndex = QModelIndex();
if (m_model) {
- for (const Cx *c = &connections[0]; c->signal; c++)
- connect(m_model, c->signal, this, c->slot);
-
+ connectToModel();
showModelTopLevelItems();
}