QmlDesigner: Fix missing Assets on folder drag & drop

Fixes: QDS-13784
Change-Id: I86c3f0c9b476a3945219e6be155831c795bdd9da
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Shrief Gabr
2024-10-09 20:43:31 +03:00
parent 7df954c52b
commit c120ed0ac6
6 changed files with 24 additions and 47 deletions

View File

@@ -101,7 +101,7 @@ Item {
anchors.fill: parent anchors.fill: parent
acceptedButtons: Qt.RightButton acceptedButtons: Qt.RightButton
onClicked: { onClicked: {
if (assetsModel.hasFiles) { if (!assetsModel.isEmpty) {
function onFolderCreated(path) { function onFolderCreated(path) {
assetsView.addCreatedFolder(path) assetsView.addCreatedFolder(path)
} }
@@ -189,13 +189,13 @@ Item {
leftPadding: 10 leftPadding: 10
color: StudioTheme.Values.themeTextColor color: StudioTheme.Values.themeTextColor
font.pixelSize: StudioTheme.Values.baseFont font.pixelSize: StudioTheme.Values.baseFont
visible: !assetsModel.hasFiles && !root.__searchBoxEmpty visible: assetsModel.isEmpty && !root.__searchBoxEmpty
} }
Item { // placeholder when the assets library is empty Item { // placeholder when the assets library is empty
width: parent.width width: parent.width
height: parent.height - toolbar.height - column.spacing height: parent.height - toolbar.height - column.spacing
visible: !assetsModel.hasFiles && root.__searchBoxEmpty visible: assetsModel.isEmpty && root.__searchBoxEmpty
clip: true clip: true
MouseArea { // right clicking the empty area of the view MouseArea { // right clicking the empty area of the view

View File

@@ -192,7 +192,7 @@ StudioControls.Menu {
StudioControls.MenuItem { StudioControls.MenuItem {
text: qsTr("New Folder") text: qsTr("New Folder")
visible: root.assetsModel.hasFiles visible: !root.assetsModel.isEmpty
height: visible ? implicitHeight : 0 height: visible ? implicitHeight : 0
NewFolderDialog { NewFolderDialog {

View File

@@ -70,9 +70,9 @@ TreeView {
model: assetsModel model: assetsModel
onRowsChanged: { onRowsChanged: {
if (root.rows > root.rootPathRow + 1 && !assetsModel.hasFiles || if (root.rows > root.rootPathRow + 1 && assetsModel.isEmpty ||
root.rows <= root.rootPathRow + 1 && assetsModel.hasFiles) { root.rows <= root.rootPathRow + 1 && !assetsModel.isEmpty) {
assetsModel.syncHasFiles() assetsModel.syncIsEmpty()
} }
root.updateRows() root.updateRows()
@@ -328,7 +328,7 @@ TreeView {
function moveSelection(amount) function moveSelection(amount)
{ {
if (!assetsModel.hasFiles || !amount) if (assetsModel.isEmpty || !amount)
return return
let index = root.currentFilePath ? assetsModel.indexForPath(root.currentFilePath) let index = root.currentFilePath ? assetsModel.indexForPath(root.currentFilePath)

View File

@@ -41,7 +41,7 @@ void AssetsLibraryModel::createBackendModel()
QObject::connect(m_sourceFsModel, &QFileSystemModel::directoryLoaded, this, QObject::connect(m_sourceFsModel, &QFileSystemModel::directoryLoaded, this,
[this]([[maybe_unused]] const QString &dir) { [this]([[maybe_unused]] const QString &dir) {
syncHasFiles(); syncIsEmpty();
}); });
m_fileWatcher = new Utils::FileSystemWatcher(parent()); 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()) if (m_isEmpty != value) {
return false; m_isEmpty = value;
emit isEmptyChanged();
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();
} }
} }
bool AssetsLibraryModel::checkHasFiles() const void AssetsLibraryModel::syncIsEmpty()
{ {
auto rootIdx = indexForPath(m_rootPath); QModelIndex rootIdx = indexForPath(m_rootPath);
return checkHasFiles(rootIdx);
}
void AssetsLibraryModel::syncHasFiles() bool hasContent = rowCount(rootIdx);
{ setIsEmpty(!hasContent);
setHasFiles(checkHasFiles());
} }
void AssetsLibraryModel::setRootPath(const QString &newPath) void AssetsLibraryModel::setRootPath(const QString &newPath)

View File

@@ -23,7 +23,7 @@ public:
void setRootPath(const QString &newPath); void setRootPath(const QString &newPath);
void setSearchText(const QString &searchText); 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 rootPath() const;
Q_INVOKABLE QString filePath(const QModelIndex &index) 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 QString &path) const;
Q_INVOKABLE QModelIndex parentDirIndex(const QModelIndex &index) const; Q_INVOKABLE QModelIndex parentDirIndex(const QModelIndex &index) const;
Q_INVOKABLE QString parentDirPath(const QString &path) const; Q_INVOKABLE QString parentDirPath(const QString &path) const;
Q_INVOKABLE void syncHasFiles(); Q_INVOKABLE void syncIsEmpty();
Q_INVOKABLE QList<QModelIndex> parentIndices(const QModelIndex &index) const; Q_INVOKABLE QList<QModelIndex> parentIndices(const QModelIndex &index) const;
Q_INVOKABLE bool indexIsValid(const QModelIndex &index) const; Q_INVOKABLE bool indexIsValid(const QModelIndex &index) const;
@@ -58,29 +58,27 @@ public:
return std::min(result, 1); return std::min(result, 1);
} }
bool hasFiles() const { return m_hasFiles; } bool isEmpty() const { return m_isEmpty; }
signals: signals:
void directoryLoaded(const QString &path); void directoryLoaded(const QString &path);
void rootPathChanged(); void rootPathChanged();
void hasFilesChanged(); void isEmptyChanged();
void fileChanged(const QString &path); void fileChanged(const QString &path);
void effectsDeleted(const QStringList &effectNames); void effectsDeleted(const QStringList &effectNames);
private: private:
void setHasFiles(bool value); void setIsEmpty(bool value);
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
void resetModel(); void resetModel();
void createBackendModel(); void createBackendModel();
void destroyBackendModel(); void destroyBackendModel();
bool checkHasFiles(const QModelIndex &parentIdx) const;
bool checkHasFiles() const;
QString m_searchText; QString m_searchText;
QString m_rootPath; QString m_rootPath;
QFileSystemModel *m_sourceFsModel = nullptr; QFileSystemModel *m_sourceFsModel = nullptr;
bool m_hasFiles = false; bool m_isEmpty = true;
Utils::FileSystemWatcher *m_fileWatcher = nullptr; Utils::FileSystemWatcher *m_fileWatcher = nullptr;
}; };

View File

@@ -436,7 +436,7 @@ QList<QToolButton *> AssetsLibraryWidget::createToolBarWidgets()
void AssetsLibraryWidget::handleSearchFilterChanged(const QString &filterText) 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))) && filterText.contains(m_filterText, Qt::CaseInsensitive)))
return; return;