forked from qt-creator/qt-creator
QmlDesigner: Synchronize the selected collection with collectionDetails
Fixes: QDS-11643 Fixes: QDS-11654 Change-Id: Icf43d2f68b1c4fb4a6ffeb80651b2339b268ccd6 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -87,8 +87,11 @@ bool CollectionListModel::removeRows(int row, int count, const QModelIndex &pare
|
||||
QStringList removedCollections = stringList().mid(row, count);
|
||||
|
||||
bool itemsRemoved = Super::removeRows(row, count, parent);
|
||||
if (itemsRemoved)
|
||||
if (itemsRemoved) {
|
||||
emit collectionsRemoved(removedCollections);
|
||||
if (m_selectedIndex >= row)
|
||||
selectCollectionIndex(m_selectedIndex - count, true);
|
||||
}
|
||||
|
||||
return itemsRemoved;
|
||||
}
|
||||
|
@@ -327,6 +327,7 @@ bool CollectionSourceModel::addCollectionToSource(const ModelNode &node,
|
||||
return returnError(tr("No model is available for the JSON model group."));
|
||||
|
||||
collections->selectCollectionName(collectionName);
|
||||
setSelectedCollectionName(collectionName);
|
||||
return true;
|
||||
} else {
|
||||
return returnError(tr("JSON document type should be an object containing models."));
|
||||
@@ -405,9 +406,11 @@ void CollectionSourceModel::onSelectedCollectionChanged(CollectionListModel *col
|
||||
|
||||
m_previousSelectedList = collectionList;
|
||||
|
||||
emit collectionSelected(collectionList->collectionNameAt(collectionIndex));
|
||||
setSelectedCollectionName(collectionList->collectionNameAt(collectionIndex));
|
||||
|
||||
selectSourceIndex(sourceIndex(collectionList->sourceNode()));
|
||||
} else {
|
||||
setSelectedCollectionName({});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,7 +418,7 @@ void CollectionSourceModel::onCollectionNameChanged(CollectionListModel *collect
|
||||
const QString &oldName, const QString &newName)
|
||||
{
|
||||
auto emitRenameWarning = [this](const QString &msg) -> void {
|
||||
emit this->warning(tr("Rename Model"), msg);
|
||||
emit warning(tr("Rename Model"), msg);
|
||||
};
|
||||
|
||||
const ModelNode node = collectionList->sourceNode();
|
||||
@@ -577,9 +580,11 @@ void CollectionSourceModel::onCollectionsRemoved(CollectionListModel *collection
|
||||
}
|
||||
|
||||
for (const QString &collectionName : std::as_const(collectionsRemovedFromDocument))
|
||||
emit this->collectionRemoved(collectionName);
|
||||
emit collectionRemoved(collectionName);
|
||||
|
||||
updateCollectionList(nodeIndex);
|
||||
if (m_previousSelectedList == collectionList)
|
||||
onSelectedCollectionChanged(collectionList, collectionList->selectedIndex());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -609,12 +614,20 @@ void CollectionSourceModel::setSelectedIndex(int idx)
|
||||
} else if (m_previousSelectedList) {
|
||||
m_previousSelectedList->selectCollectionIndex(-1);
|
||||
m_previousSelectedList = {};
|
||||
emit this->collectionSelected({});
|
||||
setSelectedCollectionName({});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CollectionSourceModel::setSelectedCollectionName(const QString &collectionName)
|
||||
{
|
||||
if (m_selectedCollectionName != collectionName) {
|
||||
m_selectedCollectionName = collectionName;
|
||||
emit collectionSelected(m_selectedCollectionName);
|
||||
}
|
||||
}
|
||||
|
||||
void CollectionSourceModel::updateEmpty()
|
||||
{
|
||||
bool isEmptyNow = m_collectionSources.isEmpty();
|
||||
|
@@ -87,6 +87,7 @@ private slots:
|
||||
|
||||
private:
|
||||
void setSelectedIndex(int idx);
|
||||
void setSelectedCollectionName(const QString &collectionName);
|
||||
void updateEmpty();
|
||||
void updateCollectionList(QModelIndex index);
|
||||
void registerCollection(const QSharedPointer<CollectionListModel> &collection);
|
||||
@@ -98,6 +99,7 @@ private:
|
||||
QHash<qint32, int> m_sourceIndexHash; // internalId -> index
|
||||
QList<QSharedPointer<CollectionListModel>> m_collectionList;
|
||||
QPointer<CollectionListModel> m_previousSelectedList;
|
||||
QString m_selectedCollectionName;
|
||||
int m_selectedIndex = -1;
|
||||
bool m_isEmpty = true;
|
||||
};
|
||||
|
Reference in New Issue
Block a user