From c120ed0ac6363e57ca0d17f67695f896a6d2ba6a Mon Sep 17 00:00:00 2001 From: Shrief Gabr Date: Wed, 9 Oct 2024 20:43:31 +0300 Subject: [PATCH] QmlDesigner: Fix missing Assets on folder drag & drop Fixes: QDS-13784 Change-Id: I86c3f0c9b476a3945219e6be155831c795bdd9da Reviewed-by: Miikka Heikkinen Reviewed-by: Mahmoud Badri --- .../assetsLibraryQmlSources/Assets.qml | 6 +-- .../AssetsContextMenu.qml | 2 +- .../assetsLibraryQmlSources/AssetsView.qml | 8 ++-- .../assetslibrary/assetslibrarymodel.cpp | 39 +++++-------------- .../assetslibrary/assetslibrarymodel.h | 14 +++---- .../assetslibrary/assetslibrarywidget.cpp | 2 +- 6 files changed, 24 insertions(+), 47 deletions(-) diff --git a/share/qtcreator/qmldesigner/assetsLibraryQmlSources/Assets.qml b/share/qtcreator/qmldesigner/assetsLibraryQmlSources/Assets.qml index 0514f3dfaef..60beacfe6e2 100644 --- a/share/qtcreator/qmldesigner/assetsLibraryQmlSources/Assets.qml +++ b/share/qtcreator/qmldesigner/assetsLibraryQmlSources/Assets.qml @@ -101,7 +101,7 @@ Item { anchors.fill: parent acceptedButtons: Qt.RightButton onClicked: { - if (assetsModel.hasFiles) { + if (!assetsModel.isEmpty) { function onFolderCreated(path) { assetsView.addCreatedFolder(path) } @@ -189,13 +189,13 @@ Item { leftPadding: 10 color: StudioTheme.Values.themeTextColor font.pixelSize: StudioTheme.Values.baseFont - visible: !assetsModel.hasFiles && !root.__searchBoxEmpty + visible: assetsModel.isEmpty && !root.__searchBoxEmpty } Item { // placeholder when the assets library is empty width: parent.width height: parent.height - toolbar.height - column.spacing - visible: !assetsModel.hasFiles && root.__searchBoxEmpty + visible: assetsModel.isEmpty && root.__searchBoxEmpty clip: true MouseArea { // right clicking the empty area of the view diff --git a/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetsContextMenu.qml b/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetsContextMenu.qml index 40cdac85bbb..08f6c0a990f 100644 --- a/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetsContextMenu.qml +++ b/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetsContextMenu.qml @@ -192,7 +192,7 @@ StudioControls.Menu { StudioControls.MenuItem { text: qsTr("New Folder") - visible: root.assetsModel.hasFiles + visible: !root.assetsModel.isEmpty height: visible ? implicitHeight : 0 NewFolderDialog { diff --git a/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetsView.qml b/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetsView.qml index 307d3637521..df45bc32487 100644 --- a/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetsView.qml +++ b/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetsView.qml @@ -70,9 +70,9 @@ TreeView { model: assetsModel onRowsChanged: { - if (root.rows > root.rootPathRow + 1 && !assetsModel.hasFiles || - root.rows <= root.rootPathRow + 1 && assetsModel.hasFiles) { - assetsModel.syncHasFiles() + if (root.rows > root.rootPathRow + 1 && assetsModel.isEmpty || + root.rows <= root.rootPathRow + 1 && !assetsModel.isEmpty) { + assetsModel.syncIsEmpty() } root.updateRows() @@ -328,7 +328,7 @@ TreeView { function moveSelection(amount) { - if (!assetsModel.hasFiles || !amount) + if (assetsModel.isEmpty || !amount) return let index = root.currentFilePath ? assetsModel.indexForPath(root.currentFilePath) diff --git a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp index d12d824ddc8..febf11a9176 100644 --- a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp +++ b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp @@ -41,7 +41,7 @@ void AssetsLibraryModel::createBackendModel() QObject::connect(m_sourceFsModel, &QFileSystemModel::directoryLoaded, this, [this]([[maybe_unused]] const QString &dir) { - syncHasFiles(); + syncIsEmpty(); }); m_fileWatcher = new Utils::FileSystemWatcher(parent()); @@ -224,41 +224,20 @@ bool AssetsLibraryModel::filterAcceptsRow(int sourceRow, const QModelIndex &sour } } -bool AssetsLibraryModel::checkHasFiles(const QModelIndex &parentIdx) const +void AssetsLibraryModel::setIsEmpty(bool value) { - if (!parentIdx.isValid()) - return false; - - const int rowCount = this->rowCount(parentIdx); - for (int i = 0; i < rowCount; ++i) { - auto newIdx = this->index(i, 0, parentIdx); - if (!isDirectory(newIdx)) - return true; - - if (checkHasFiles(newIdx)) - return true; - } - - return false; -} - -void AssetsLibraryModel::setHasFiles(bool value) -{ - if (m_hasFiles != value) { - m_hasFiles = value; - emit hasFilesChanged(); + if (m_isEmpty != value) { + m_isEmpty = value; + emit isEmptyChanged(); } } -bool AssetsLibraryModel::checkHasFiles() const +void AssetsLibraryModel::syncIsEmpty() { - auto rootIdx = indexForPath(m_rootPath); - return checkHasFiles(rootIdx); -} + QModelIndex rootIdx = indexForPath(m_rootPath); -void AssetsLibraryModel::syncHasFiles() -{ - setHasFiles(checkHasFiles()); + bool hasContent = rowCount(rootIdx); + setIsEmpty(!hasContent); } void AssetsLibraryModel::setRootPath(const QString &newPath) diff --git a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.h b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.h index 27b5eb77f27..5b5525a01bf 100644 --- a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.h +++ b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.h @@ -23,7 +23,7 @@ public: void setRootPath(const QString &newPath); void setSearchText(const QString &searchText); - Q_PROPERTY(bool hasFiles READ hasFiles NOTIFY hasFilesChanged) + Q_PROPERTY(bool isEmpty READ isEmpty NOTIFY isEmptyChanged) Q_INVOKABLE QString rootPath() const; Q_INVOKABLE QString filePath(const QModelIndex &index) const; @@ -36,7 +36,7 @@ public: Q_INVOKABLE QModelIndex parentDirIndex(const QString &path) const; Q_INVOKABLE QModelIndex parentDirIndex(const QModelIndex &index) const; Q_INVOKABLE QString parentDirPath(const QString &path) const; - Q_INVOKABLE void syncHasFiles(); + Q_INVOKABLE void syncIsEmpty(); Q_INVOKABLE QList parentIndices(const QModelIndex &index) const; Q_INVOKABLE bool indexIsValid(const QModelIndex &index) const; @@ -58,29 +58,27 @@ public: return std::min(result, 1); } - bool hasFiles() const { return m_hasFiles; } + bool isEmpty() const { return m_isEmpty; } signals: void directoryLoaded(const QString &path); void rootPathChanged(); - void hasFilesChanged(); + void isEmptyChanged(); void fileChanged(const QString &path); void effectsDeleted(const QStringList &effectNames); private: - void setHasFiles(bool value); + void setIsEmpty(bool value); bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; void resetModel(); void createBackendModel(); void destroyBackendModel(); - bool checkHasFiles(const QModelIndex &parentIdx) const; - bool checkHasFiles() const; QString m_searchText; QString m_rootPath; QFileSystemModel *m_sourceFsModel = nullptr; - bool m_hasFiles = false; + bool m_isEmpty = true; Utils::FileSystemWatcher *m_fileWatcher = nullptr; }; diff --git a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp index e7d1e431633..1ccda93b130 100644 --- a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp +++ b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp @@ -436,7 +436,7 @@ QList AssetsLibraryWidget::createToolBarWidgets() void AssetsLibraryWidget::handleSearchFilterChanged(const QString &filterText) { - if (filterText == m_filterText || (!m_assetsModel->hasFiles() + if (filterText == m_filterText || (m_assetsModel->isEmpty() && filterText.contains(m_filterText, Qt::CaseInsensitive))) return;