CollectionSourceModel: Avoid using sender()

Amends 6eb522f0ca
Amends 01a4f087c6

Change-Id: Ifa1be7cd2a39e6910160a4383fd9a1c1ce743731
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: Ali Kianian <ali.kianian@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
Jarek Kobus
2023-12-13 22:18:49 +01:00
parent efc63c8ffb
commit 1a07fa87fd
2 changed files with 29 additions and 30 deletions

View File

@@ -394,10 +394,10 @@ void CollectionSourceModel::updateNodeSource(const ModelNode &node)
updateCollectionList(index);
}
void CollectionSourceModel::onSelectedCollectionChanged(int collectionIndex)
void CollectionSourceModel::onSelectedCollectionChanged(CollectionListModel *collectionList,
int collectionIndex)
{
CollectionListModel *collectionList = qobject_cast<CollectionListModel *>(sender());
if (collectionIndex > -1 && collectionList) {
if (collectionIndex > -1) {
if (m_previousSelectedList && m_previousSelectedList != collectionList)
m_previousSelectedList->selectCollectionIndex(-1);
@@ -410,11 +410,9 @@ void CollectionSourceModel::onSelectedCollectionChanged(int collectionIndex)
}
}
void CollectionSourceModel::onCollectionNameChanged(const QString &oldName, const QString &newName)
void CollectionSourceModel::onCollectionNameChanged(CollectionListModel *collectionList,
const QString &oldName, const QString &newName)
{
CollectionListModel *collectionList = qobject_cast<CollectionListModel *>(sender());
QTC_ASSERT(collectionList, return);
auto emitRenameWarning = [this](const QString &msg) -> void {
emit this->warning(tr("Rename Model"), msg);
};
@@ -500,11 +498,9 @@ void CollectionSourceModel::onCollectionNameChanged(const QString &oldName, cons
}
}
void CollectionSourceModel::onCollectionsRemoved(const QStringList &removedCollections)
void CollectionSourceModel::onCollectionsRemoved(CollectionListModel *collectionList,
const QStringList &removedCollections)
{
CollectionListModel *collectionList = qobject_cast<CollectionListModel *>(sender());
QTC_ASSERT(collectionList, return);
auto emitDeleteWarning = [this](const QString &msg) -> void {
emit warning(tr("Delete Model"), msg);
};
@@ -641,25 +637,26 @@ void CollectionSourceModel::updateCollectionList(QModelIndex index)
void CollectionSourceModel::registerCollection(const QSharedPointer<CollectionListModel> &collection)
{
connect(collection.data(),
&CollectionListModel::selectedIndexChanged,
this,
&CollectionSourceModel::onSelectedCollectionChanged,
Qt::UniqueConnection);
CollectionListModel *collectionList = collection.data();
if (collectionList == nullptr)
return;
connect(collection.data(),
&CollectionListModel::collectionNameChanged,
this,
&CollectionSourceModel::onCollectionNameChanged,
Qt::UniqueConnection);
connect(collectionList, &CollectionListModel::selectedIndexChanged, this,
[this, collectionList](int idx) {
onSelectedCollectionChanged(collectionList, idx);
}, Qt::UniqueConnection);
connect(collection.data(),
&CollectionListModel::collectionsRemoved,
this,
&CollectionSourceModel::onCollectionsRemoved,
Qt::UniqueConnection);
connect(collectionList, &CollectionListModel::collectionNameChanged, this,
[this, collectionList](const QString &oldName, const QString &newName) {
onCollectionNameChanged(collectionList, oldName, newName);
}, Qt::UniqueConnection);
if (collection.data() && collection->sourceNode())
connect(collectionList, &CollectionListModel::collectionsRemoved, this,
[this, collectionList](const QStringList &removedCollections) {
onCollectionsRemoved(collectionList, removedCollections);
}, Qt::UniqueConnection);
if (collection->sourceNode())
emit collectionNamesChanged(collection->sourceNode(), collection->stringList());
}

View File

@@ -76,9 +76,11 @@ signals:
void warning(const QString &title, const QString &body);
private slots:
void onSelectedCollectionChanged(int collectionIndex);
void onCollectionNameChanged(const QString &oldName, const QString &newName);
void onCollectionsRemoved(const QStringList &removedCollections);
void onSelectedCollectionChanged(CollectionListModel *collectionList, int collectionIndex);
void onCollectionNameChanged(CollectionListModel *collectionList, const QString &oldName,
const QString &newName);
void onCollectionsRemoved(CollectionListModel *collectionList,
const QStringList &removedCollections);
private:
void setSelectedIndex(int idx);