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);
|
QStringList removedCollections = stringList().mid(row, count);
|
||||||
|
|
||||||
bool itemsRemoved = Super::removeRows(row, count, parent);
|
bool itemsRemoved = Super::removeRows(row, count, parent);
|
||||||
if (itemsRemoved)
|
if (itemsRemoved) {
|
||||||
emit collectionsRemoved(removedCollections);
|
emit collectionsRemoved(removedCollections);
|
||||||
|
if (m_selectedIndex >= row)
|
||||||
|
selectCollectionIndex(m_selectedIndex - count, true);
|
||||||
|
}
|
||||||
|
|
||||||
return itemsRemoved;
|
return itemsRemoved;
|
||||||
}
|
}
|
||||||
|
@@ -327,6 +327,7 @@ bool CollectionSourceModel::addCollectionToSource(const ModelNode &node,
|
|||||||
return returnError(tr("No model is available for the JSON model group."));
|
return returnError(tr("No model is available for the JSON model group."));
|
||||||
|
|
||||||
collections->selectCollectionName(collectionName);
|
collections->selectCollectionName(collectionName);
|
||||||
|
setSelectedCollectionName(collectionName);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return returnError(tr("JSON document type should be an object containing models."));
|
return returnError(tr("JSON document type should be an object containing models."));
|
||||||
@@ -405,9 +406,11 @@ void CollectionSourceModel::onSelectedCollectionChanged(CollectionListModel *col
|
|||||||
|
|
||||||
m_previousSelectedList = collectionList;
|
m_previousSelectedList = collectionList;
|
||||||
|
|
||||||
emit collectionSelected(collectionList->collectionNameAt(collectionIndex));
|
setSelectedCollectionName(collectionList->collectionNameAt(collectionIndex));
|
||||||
|
|
||||||
selectSourceIndex(sourceIndex(collectionList->sourceNode()));
|
selectSourceIndex(sourceIndex(collectionList->sourceNode()));
|
||||||
|
} else {
|
||||||
|
setSelectedCollectionName({});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,7 +418,7 @@ void CollectionSourceModel::onCollectionNameChanged(CollectionListModel *collect
|
|||||||
const QString &oldName, const QString &newName)
|
const QString &oldName, const QString &newName)
|
||||||
{
|
{
|
||||||
auto emitRenameWarning = [this](const QString &msg) -> void {
|
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();
|
const ModelNode node = collectionList->sourceNode();
|
||||||
@@ -577,9 +580,11 @@ void CollectionSourceModel::onCollectionsRemoved(CollectionListModel *collection
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const QString &collectionName : std::as_const(collectionsRemovedFromDocument))
|
for (const QString &collectionName : std::as_const(collectionsRemovedFromDocument))
|
||||||
emit this->collectionRemoved(collectionName);
|
emit collectionRemoved(collectionName);
|
||||||
|
|
||||||
updateCollectionList(nodeIndex);
|
updateCollectionList(nodeIndex);
|
||||||
|
if (m_previousSelectedList == collectionList)
|
||||||
|
onSelectedCollectionChanged(collectionList, collectionList->selectedIndex());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -609,12 +614,20 @@ void CollectionSourceModel::setSelectedIndex(int idx)
|
|||||||
} else if (m_previousSelectedList) {
|
} else if (m_previousSelectedList) {
|
||||||
m_previousSelectedList->selectCollectionIndex(-1);
|
m_previousSelectedList->selectCollectionIndex(-1);
|
||||||
m_previousSelectedList = {};
|
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()
|
void CollectionSourceModel::updateEmpty()
|
||||||
{
|
{
|
||||||
bool isEmptyNow = m_collectionSources.isEmpty();
|
bool isEmptyNow = m_collectionSources.isEmpty();
|
||||||
|
@@ -87,6 +87,7 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void setSelectedIndex(int idx);
|
void setSelectedIndex(int idx);
|
||||||
|
void setSelectedCollectionName(const QString &collectionName);
|
||||||
void updateEmpty();
|
void updateEmpty();
|
||||||
void updateCollectionList(QModelIndex index);
|
void updateCollectionList(QModelIndex index);
|
||||||
void registerCollection(const QSharedPointer<CollectionListModel> &collection);
|
void registerCollection(const QSharedPointer<CollectionListModel> &collection);
|
||||||
@@ -98,6 +99,7 @@ private:
|
|||||||
QHash<qint32, int> m_sourceIndexHash; // internalId -> index
|
QHash<qint32, int> m_sourceIndexHash; // internalId -> index
|
||||||
QList<QSharedPointer<CollectionListModel>> m_collectionList;
|
QList<QSharedPointer<CollectionListModel>> m_collectionList;
|
||||||
QPointer<CollectionListModel> m_previousSelectedList;
|
QPointer<CollectionListModel> m_previousSelectedList;
|
||||||
|
QString m_selectedCollectionName;
|
||||||
int m_selectedIndex = -1;
|
int m_selectedIndex = -1;
|
||||||
bool m_isEmpty = true;
|
bool m_isEmpty = true;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user