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
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

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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)

View File

@@ -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<QModelIndex> 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;
};

View File

@@ -436,7 +436,7 @@ QList<QToolButton *> 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;