forked from qt-creator/qt-creator
CollectionSourceModel: Avoid using sender()
Amends6eb522f0ca
Amends01a4f087c6
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:
@@ -394,10 +394,10 @@ void CollectionSourceModel::updateNodeSource(const ModelNode &node)
|
|||||||
updateCollectionList(index);
|
updateCollectionList(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollectionSourceModel::onSelectedCollectionChanged(int collectionIndex)
|
void CollectionSourceModel::onSelectedCollectionChanged(CollectionListModel *collectionList,
|
||||||
|
int collectionIndex)
|
||||||
{
|
{
|
||||||
CollectionListModel *collectionList = qobject_cast<CollectionListModel *>(sender());
|
if (collectionIndex > -1) {
|
||||||
if (collectionIndex > -1 && collectionList) {
|
|
||||||
if (m_previousSelectedList && m_previousSelectedList != collectionList)
|
if (m_previousSelectedList && m_previousSelectedList != collectionList)
|
||||||
m_previousSelectedList->selectCollectionIndex(-1);
|
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 {
|
auto emitRenameWarning = [this](const QString &msg) -> void {
|
||||||
emit this->warning(tr("Rename Model"), msg);
|
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 {
|
auto emitDeleteWarning = [this](const QString &msg) -> void {
|
||||||
emit warning(tr("Delete Model"), msg);
|
emit warning(tr("Delete Model"), msg);
|
||||||
};
|
};
|
||||||
@@ -641,25 +637,26 @@ void CollectionSourceModel::updateCollectionList(QModelIndex index)
|
|||||||
|
|
||||||
void CollectionSourceModel::registerCollection(const QSharedPointer<CollectionListModel> &collection)
|
void CollectionSourceModel::registerCollection(const QSharedPointer<CollectionListModel> &collection)
|
||||||
{
|
{
|
||||||
connect(collection.data(),
|
CollectionListModel *collectionList = collection.data();
|
||||||
&CollectionListModel::selectedIndexChanged,
|
if (collectionList == nullptr)
|
||||||
this,
|
return;
|
||||||
&CollectionSourceModel::onSelectedCollectionChanged,
|
|
||||||
Qt::UniqueConnection);
|
|
||||||
|
|
||||||
connect(collection.data(),
|
connect(collectionList, &CollectionListModel::selectedIndexChanged, this,
|
||||||
&CollectionListModel::collectionNameChanged,
|
[this, collectionList](int idx) {
|
||||||
this,
|
onSelectedCollectionChanged(collectionList, idx);
|
||||||
&CollectionSourceModel::onCollectionNameChanged,
|
}, Qt::UniqueConnection);
|
||||||
Qt::UniqueConnection);
|
|
||||||
|
|
||||||
connect(collection.data(),
|
connect(collectionList, &CollectionListModel::collectionNameChanged, this,
|
||||||
&CollectionListModel::collectionsRemoved,
|
[this, collectionList](const QString &oldName, const QString &newName) {
|
||||||
this,
|
onCollectionNameChanged(collectionList, oldName, newName);
|
||||||
&CollectionSourceModel::onCollectionsRemoved,
|
}, Qt::UniqueConnection);
|
||||||
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());
|
emit collectionNamesChanged(collection->sourceNode(), collection->stringList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -76,9 +76,11 @@ signals:
|
|||||||
void warning(const QString &title, const QString &body);
|
void warning(const QString &title, const QString &body);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onSelectedCollectionChanged(int collectionIndex);
|
void onSelectedCollectionChanged(CollectionListModel *collectionList, int collectionIndex);
|
||||||
void onCollectionNameChanged(const QString &oldName, const QString &newName);
|
void onCollectionNameChanged(CollectionListModel *collectionList, const QString &oldName,
|
||||||
void onCollectionsRemoved(const QStringList &removedCollections);
|
const QString &newName);
|
||||||
|
void onCollectionsRemoved(CollectionListModel *collectionList,
|
||||||
|
const QStringList &removedCollections);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setSelectedIndex(int idx);
|
void setSelectedIndex(int idx);
|
||||||
|
Reference in New Issue
Block a user