forked from qt-creator/qt-creator
Add/remove the simulink component when the import is added/removed
Task-number: QDS-2122 Change-Id: Ib4e2ff14ed9cfef1534f9c3edb0a8279fbabfd6a Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -122,8 +122,15 @@ void ImportsWidget::removePossibleImports()
|
||||
|
||||
void ImportsWidget::setUsedImports(const QList<Import> &usedImports)
|
||||
{
|
||||
const QStringList excludeList = {"SimulinkConnector"};
|
||||
|
||||
// exclude imports in the excludeList from being readonly (i.e. always enable their x button)
|
||||
QList<Import> filteredImports = Utils::filtered(usedImports, [excludeList](const Import &import) {
|
||||
return !excludeList.contains(import.url());
|
||||
});
|
||||
|
||||
foreach (ImportLabel *importLabel, m_importLabels)
|
||||
importLabel->setReadOnly(usedImports.contains(importLabel->import()));
|
||||
importLabel->setReadOnly(filteredImports.contains(importLabel->import()));
|
||||
}
|
||||
|
||||
void ImportsWidget::removeUsedImports()
|
||||
|
@@ -29,6 +29,10 @@
|
||||
#include <importmanagerview.h>
|
||||
#include <qmlitemnode.h>
|
||||
#include <rewriterview.h>
|
||||
#include <bindingproperty.h>
|
||||
#include <nodelistproperty.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include "metainfo.h"
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
@@ -82,9 +86,35 @@ void ItemLibraryView::modelAboutToBeDetached(Model *model)
|
||||
m_widget->setModel(nullptr);
|
||||
}
|
||||
|
||||
void ItemLibraryView::importsChanged(const QList<Import> &/*addedImports*/, const QList<Import> &/*removedImports*/)
|
||||
void ItemLibraryView::importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports)
|
||||
{
|
||||
updateImports();
|
||||
|
||||
// TODO: generalize the logic below to allow adding/removing any Qml component when its import is added/removed
|
||||
bool simulinkImportAdded = std::any_of(addedImports.cbegin(), addedImports.cend(), [](const Import &import) {
|
||||
return import.url() == "SimulinkConnector";
|
||||
});
|
||||
if (simulinkImportAdded) {
|
||||
// add SLConnector component when SimulinkConnector import is added
|
||||
ModelNode node = createModelNode("SLConnector", 1, 0);
|
||||
node.bindingProperty("root").setExpression(rootModelNode().validId());
|
||||
rootModelNode().defaultNodeListProperty().reparentHere(node);
|
||||
} else {
|
||||
bool simulinkImportRemoved = std::any_of(removedImports.cbegin(), removedImports.cend(), [](const Import &import) {
|
||||
return import.url() == "SimulinkConnector";
|
||||
});
|
||||
|
||||
if (simulinkImportRemoved) {
|
||||
// remove SLConnector component when SimulinkConnector import is removed
|
||||
const QList<ModelNode> slConnectors = Utils::filtered(rootModelNode().directSubModelNodes(),
|
||||
[](const ModelNode &node) {
|
||||
return node.type() == "SLConnector" || node.type() == "SimulinkConnector.SLConnector";
|
||||
});
|
||||
|
||||
for (ModelNode node : slConnectors)
|
||||
node.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ItemLibraryView::setResourcePath(const QString &resourcePath)
|
||||
|
@@ -98,7 +98,6 @@ public:
|
||||
|
||||
QList<ItemLibraryEntry> entries() const;
|
||||
QList<ItemLibraryEntry> entriesForType(const QByteArray &typeName, int majorVersion, int minorVersion) const;
|
||||
ItemLibraryEntry entry(const QString &name) const;
|
||||
|
||||
void addEntries(const QList<ItemLibraryEntry> &entries, bool overwriteDuplicate = false);
|
||||
bool containsEntry(const ItemLibraryEntry &entry);
|
||||
|
@@ -272,17 +272,6 @@ QList<ItemLibraryEntry> ItemLibraryInfo::entriesForType(const QByteArray &typeNa
|
||||
return entries;
|
||||
}
|
||||
|
||||
ItemLibraryEntry ItemLibraryInfo::entry(const QString &name) const
|
||||
{
|
||||
if (m_nameToEntryHash.contains(name))
|
||||
return m_nameToEntryHash.value(name);
|
||||
|
||||
if (m_baseInfo)
|
||||
return m_baseInfo->entry(name);
|
||||
|
||||
return ItemLibraryEntry();
|
||||
}
|
||||
|
||||
QList<ItemLibraryEntry> ItemLibraryInfo::entries() const
|
||||
{
|
||||
QList<ItemLibraryEntry> list = m_nameToEntryHash.values();
|
||||
|
Reference in New Issue
Block a user