forked from qt-creator/qt-creator
QmlDesigner: Apply rename and delete collection on CollectionDetails
Fixes: QDS-11656 Change-Id: I0e5cec47395f8f531285041111b73686c4c858d4 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> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -557,6 +557,14 @@ void CollectionDetails::swap(CollectionDetails &other)
|
|||||||
d.swap(other.d);
|
d.swap(other.d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CollectionDetails::resetReference(const CollectionReference &reference)
|
||||||
|
{
|
||||||
|
if (d->reference != reference) {
|
||||||
|
d->reference = reference;
|
||||||
|
markChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CollectionDetails::registerDeclarativeType()
|
void CollectionDetails::registerDeclarativeType()
|
||||||
{
|
{
|
||||||
typedef CollectionDetails::DataType DataType;
|
typedef CollectionDetails::DataType DataType;
|
||||||
|
@@ -103,6 +103,7 @@ public:
|
|||||||
bool markSaved();
|
bool markSaved();
|
||||||
|
|
||||||
void swap(CollectionDetails &other);
|
void swap(CollectionDetails &other);
|
||||||
|
void resetReference(const CollectionReference &reference);
|
||||||
QString getCollectionAsJsonString() const;
|
QString getCollectionAsJsonString() const;
|
||||||
QString getCollectionAsCsvString() const;
|
QString getCollectionAsCsvString() const;
|
||||||
|
|
||||||
|
@@ -458,6 +458,42 @@ void CollectionDetailsModel::loadCollection(const ModelNode &sourceNode, const Q
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CollectionDetailsModel::removeCollection(const ModelNode &sourceNode, const QString &collection)
|
||||||
|
{
|
||||||
|
CollectionReference collectionRef{sourceNode, collection};
|
||||||
|
if (!m_openedCollections.contains(collectionRef))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (m_currentCollection.reference() == collectionRef)
|
||||||
|
loadCollection({}, {});
|
||||||
|
|
||||||
|
m_openedCollections.remove(collectionRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CollectionDetailsModel::removeAllCollections()
|
||||||
|
{
|
||||||
|
loadCollection({}, {});
|
||||||
|
m_openedCollections.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CollectionDetailsModel::renameCollection(const ModelNode &sourceNode,
|
||||||
|
const QString &oldName,
|
||||||
|
const QString &newName)
|
||||||
|
{
|
||||||
|
CollectionReference oldRef{sourceNode, oldName};
|
||||||
|
if (!m_openedCollections.contains(oldRef))
|
||||||
|
return;
|
||||||
|
|
||||||
|
CollectionReference newReference{sourceNode, newName};
|
||||||
|
bool collectionIsSelected = m_currentCollection.reference() == oldRef;
|
||||||
|
CollectionDetails collection = m_openedCollections.take(oldRef);
|
||||||
|
collection.resetReference(newReference);
|
||||||
|
m_openedCollections.insert(newReference, collection);
|
||||||
|
|
||||||
|
if (collectionIsSelected)
|
||||||
|
setCollectionName(newName);
|
||||||
|
}
|
||||||
|
|
||||||
bool CollectionDetailsModel::saveDataStoreCollections()
|
bool CollectionDetailsModel::saveDataStoreCollections()
|
||||||
{
|
{
|
||||||
const ModelNode node = m_currentCollection.reference().node;
|
const ModelNode node = m_currentCollection.reference().node;
|
||||||
|
@@ -61,6 +61,9 @@ public:
|
|||||||
static Q_INVOKABLE QStringList typesList();
|
static Q_INVOKABLE QStringList typesList();
|
||||||
|
|
||||||
void loadCollection(const ModelNode &sourceNode, const QString &collection);
|
void loadCollection(const ModelNode &sourceNode, const QString &collection);
|
||||||
|
void removeCollection(const ModelNode &sourceNode, const QString &collection);
|
||||||
|
void removeAllCollections();
|
||||||
|
void renameCollection(const ModelNode &sourceNode, const QString &oldName, const QString &newName);
|
||||||
|
|
||||||
Q_INVOKABLE bool saveDataStoreCollections();
|
Q_INVOKABLE bool saveDataStoreCollections();
|
||||||
Q_INVOKABLE bool exportCollection(const QUrl &url);
|
Q_INVOKABLE bool exportCollection(const QUrl &url);
|
||||||
|
@@ -498,8 +498,21 @@ void CollectionSourceModel::onCollectionNameChanged(CollectionListModel *collect
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CollectionListModel *list = m_collectionList.at(nodeIndex.row()).data();
|
||||||
|
bool updateSelectedNames = list && list == m_previousSelectedList.data();
|
||||||
emit collectionRenamed(oldName, newName);
|
emit collectionRenamed(oldName, newName);
|
||||||
updateCollectionList(nodeIndex);
|
updateCollectionList(nodeIndex);
|
||||||
|
|
||||||
|
if (updateSelectedNames) {
|
||||||
|
list = m_collectionList.at(nodeIndex.row()).data();
|
||||||
|
if (m_selectedCollectionName == oldName) {
|
||||||
|
list->selectCollectionName(newName);
|
||||||
|
setSelectedCollectionName(newName);
|
||||||
|
} else {
|
||||||
|
// reselect to update ID if it's changed due to renaming and order changes
|
||||||
|
list->selectCollectionName(m_selectedCollectionName);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -48,7 +48,11 @@ CollectionView::CollectionView(ExternalDependenciesInterface &externalDependenci
|
|||||||
connect(ProjectExplorer::ProjectManager::instance(),
|
connect(ProjectExplorer::ProjectManager::instance(),
|
||||||
&ProjectExplorer::ProjectManager::startupProjectChanged,
|
&ProjectExplorer::ProjectManager::startupProjectChanged,
|
||||||
this,
|
this,
|
||||||
&CollectionView::resetDataStoreNode);
|
[=] {
|
||||||
|
resetDataStoreNode();
|
||||||
|
if (m_widget.get())
|
||||||
|
m_widget->collectionDetailsModel()->removeAllCollections();
|
||||||
|
});
|
||||||
resetDataStoreNode();
|
resetDataStoreNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,6 +95,9 @@ QmlDesigner::WidgetInfo CollectionView::widgetInfo()
|
|||||||
this,
|
this,
|
||||||
[this](const QString &oldName, const QString &newName) {
|
[this](const QString &oldName, const QString &newName) {
|
||||||
m_dataStore->renameCollection(oldName, newName);
|
m_dataStore->renameCollection(oldName, newName);
|
||||||
|
m_widget->collectionDetailsModel()->renameCollection(dataStoreNode(),
|
||||||
|
oldName,
|
||||||
|
newName);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(sourceModel,
|
connect(sourceModel,
|
||||||
@@ -98,6 +105,8 @@ QmlDesigner::WidgetInfo CollectionView::widgetInfo()
|
|||||||
this,
|
this,
|
||||||
[this](const QString &collectionName) {
|
[this](const QString &collectionName) {
|
||||||
m_dataStore->removeCollection(collectionName);
|
m_dataStore->removeCollection(collectionName);
|
||||||
|
m_widget->collectionDetailsModel()->removeCollection(dataStoreNode(),
|
||||||
|
collectionName);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user