forked from qt-creator/qt-creator
QmlDesigner: Add imports to subcomponent manager whenever they change
Possible imports were never added to subcomponent manager after initial design mode activation, and imports added manually via text editor were also not added to subcomponent manager. The old implementation also added duplicate imports to subcomponent manager if imports were removed and readded to the document via item library. Fixes: QDS-5345 Change-Id: If45884f50b68282630af1d472af2816640b81c04 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -31,7 +31,6 @@
|
||||
|
||||
#include <nodeinstanceview.h>
|
||||
#include <designeractionmanager.h>
|
||||
#include <qmldesignerplugin.h>
|
||||
#include <designersettings.h>
|
||||
#include <qmldesignerconstants.h>
|
||||
#include <viewmanager.h>
|
||||
@@ -324,10 +323,6 @@ void Edit3DView::addQuick3DImport()
|
||||
} else {
|
||||
model()->changeImports({import}, {});
|
||||
}
|
||||
|
||||
// Subcomponent manager update needed to make item library entries appear
|
||||
QmlDesignerPlugin::instance()->currentDesignDocument()
|
||||
->updateSubcomponentManagerImport(import);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -388,9 +388,9 @@ void DesignDocument::updateSubcomponentManager()
|
||||
currentModel()->imports() + currentModel()->possibleImports());
|
||||
}
|
||||
|
||||
void DesignDocument::updateSubcomponentManagerImport(const Import &import)
|
||||
void DesignDocument::addSubcomponentManagerImport(const Import &import)
|
||||
{
|
||||
m_subComponentManager->updateImport(import);
|
||||
m_subComponentManager->addAndParseImport(import);
|
||||
}
|
||||
|
||||
void DesignDocument::deleteSelected()
|
||||
|
@@ -69,7 +69,7 @@ public:
|
||||
void attachRewriterToModel();
|
||||
void close();
|
||||
void updateSubcomponentManager();
|
||||
void updateSubcomponentManagerImport(const Import &import);
|
||||
void addSubcomponentManagerImport(const Import &import);
|
||||
|
||||
bool isUndoAvailable() const;
|
||||
bool isRedoAvailable() const;
|
||||
|
@@ -686,8 +686,6 @@ void ItemLibraryAssetImporter::finalizeQuick3DImport()
|
||||
|
||||
model->changeImports(newImportsToAdd, {});
|
||||
transaction.commit();
|
||||
for (const Import &import : qAsConst(newImportsToAdd))
|
||||
doc->updateSubcomponentManagerImport(import);
|
||||
}
|
||||
} catch (const RewritingException &e) {
|
||||
addError(tr("Failed to update imports: %1").arg(e.description()));
|
||||
|
@@ -132,6 +132,10 @@ void ItemLibraryView::modelAboutToBeDetached(Model *model)
|
||||
|
||||
void ItemLibraryView::importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports)
|
||||
{
|
||||
DesignDocument *document = QmlDesignerPlugin::instance()->currentDesignDocument();
|
||||
for (const auto &import : addedImports)
|
||||
document->addSubcomponentManagerImport(import);
|
||||
|
||||
updateImports();
|
||||
|
||||
// TODO: generalize the logic below to allow adding/removing any Qml component when its import is added/removed
|
||||
@@ -165,6 +169,10 @@ void ItemLibraryView::importsChanged(const QList<Import> &addedImports, const QL
|
||||
|
||||
void ItemLibraryView::possibleImportsChanged(const QList<Import> &possibleImports)
|
||||
{
|
||||
DesignDocument *document = QmlDesignerPlugin::instance()->currentDesignDocument();
|
||||
for (const auto &import : possibleImports)
|
||||
document->addSubcomponentManagerImport(import);
|
||||
|
||||
m_widget->updatePossibleImports(possibleImports);
|
||||
}
|
||||
|
||||
|
@@ -357,7 +357,6 @@ void ItemLibraryWidget::handleAddImport(int index)
|
||||
|
||||
auto document = QmlDesignerPlugin::instance()->currentDesignDocument();
|
||||
document->documentModel()->changeImports({import}, {});
|
||||
document->updateSubcomponentManagerImport(import);
|
||||
|
||||
m_stackedWidget->setCurrentIndex(0); // switch to the Components view after import is added
|
||||
updateSearch();
|
||||
|
@@ -879,7 +879,6 @@ void NavigatorTreeModel::addImport(const QString &importName)
|
||||
if (possImport.url() == import.url()) {
|
||||
import = possImport;
|
||||
m_view->model()->changeImports({import}, {});
|
||||
QmlDesignerPlugin::instance()->currentDesignDocument()->updateSubcomponentManagerImport(import);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -49,7 +49,7 @@ public:
|
||||
explicit SubComponentManager(Model *model, QObject *parent = nullptr);
|
||||
|
||||
void update(const QUrl &fileUrl, const QList<Import> &imports);
|
||||
void updateImport(const Import &import);
|
||||
void addAndParseImport(const Import &import);
|
||||
|
||||
QStringList qmlFiles() const;
|
||||
QStringList directories() const;
|
||||
@@ -59,7 +59,7 @@ private: // functions
|
||||
void parseFile(const QString &canonicalFilePath, bool addToLibrary, const QString&);
|
||||
void parseFile(const QString &canonicalFilePath);
|
||||
|
||||
void addImport(const Import &import, int index = -1);
|
||||
bool addImport(const Import &import, int index = -1);
|
||||
void removeImport(int index);
|
||||
void parseDirectories();
|
||||
QFileInfoList watchedFiles(const QString &canonicalDirPath);
|
||||
|
@@ -69,16 +69,18 @@ SubComponentManager::SubComponentManager(Model *model, QObject *parent)
|
||||
this, [this](const QString &path) { parseDirectory(path); });
|
||||
}
|
||||
|
||||
void SubComponentManager::addImport(const Import &import, int index)
|
||||
bool SubComponentManager::addImport(const Import &import, int index)
|
||||
{
|
||||
if (debug)
|
||||
qDebug() << Q_FUNC_INFO << index << import.file().toUtf8();
|
||||
|
||||
bool importExists = false;
|
||||
if (import.isFileImport()) {
|
||||
QFileInfo dirInfo = QFileInfo(m_filePath.resolved(import.file()).toLocalFile());
|
||||
if (dirInfo.exists() && dirInfo.isDir()) {
|
||||
const QString canonicalDirPath = dirInfo.canonicalFilePath();
|
||||
m_watcher.addPath(canonicalDirPath);
|
||||
importExists = true;
|
||||
//m_dirToQualifier.insertMulti(canonicalDirPath, import.qualifier()); ### todo: proper support for import as
|
||||
}
|
||||
} else {
|
||||
@@ -91,18 +93,23 @@ void SubComponentManager::addImport(const Import &import, int index)
|
||||
if (dirInfo.exists() && dirInfo.isDir()) {
|
||||
const QString canonicalDirPath = dirInfo.canonicalFilePath();
|
||||
m_watcher.addPath(canonicalDirPath);
|
||||
importExists = true;
|
||||
//m_dirToQualifier.insertMulti(canonicalDirPath, import.qualifier()); ### todo: proper support for import as
|
||||
}
|
||||
}
|
||||
// TODO: QDeclarativeDomImport::Library
|
||||
}
|
||||
|
||||
if (importExists) {
|
||||
if (index == -1)
|
||||
m_imports.append(import);
|
||||
else
|
||||
m_imports.insert(index, import);
|
||||
}
|
||||
|
||||
return importExists;
|
||||
}
|
||||
|
||||
void SubComponentManager::removeImport(int index)
|
||||
{
|
||||
const Import import = m_imports.takeAt(index);
|
||||
@@ -544,9 +551,15 @@ void SubComponentManager::update(const QUrl &filePath, const QList<Import> &impo
|
||||
parseDirectories();
|
||||
}
|
||||
|
||||
void SubComponentManager::updateImport(const Import &import)
|
||||
void SubComponentManager::addAndParseImport(const Import &import)
|
||||
{
|
||||
addImport(import);
|
||||
for (const auto &existingImport : std::as_const(m_imports)) {
|
||||
if (import == existingImport)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!addImport(import))
|
||||
return;
|
||||
|
||||
if (import.isFileImport()) {
|
||||
QFileInfo dirInfo = QFileInfo(m_filePath.resolved(import.file()).toLocalFile());
|
||||
|
Reference in New Issue
Block a user