forked from qt-creator/qt-creator
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:
@@ -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
|
||||
|
@@ -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 {
|
||||
|
@@ -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)
|
||||
|
@@ -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;
|
||||
if (m_isEmpty != value) {
|
||||
m_isEmpty = value;
|
||||
emit isEmptyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void AssetsLibraryModel::setHasFiles(bool value)
|
||||
void AssetsLibraryModel::syncIsEmpty()
|
||||
{
|
||||
if (m_hasFiles != value) {
|
||||
m_hasFiles = value;
|
||||
emit hasFilesChanged();
|
||||
}
|
||||
}
|
||||
QModelIndex rootIdx = indexForPath(m_rootPath);
|
||||
|
||||
bool AssetsLibraryModel::checkHasFiles() const
|
||||
{
|
||||
auto rootIdx = indexForPath(m_rootPath);
|
||||
return checkHasFiles(rootIdx);
|
||||
}
|
||||
|
||||
void AssetsLibraryModel::syncHasFiles()
|
||||
{
|
||||
setHasFiles(checkHasFiles());
|
||||
bool hasContent = rowCount(rootIdx);
|
||||
setIsEmpty(!hasContent);
|
||||
}
|
||||
|
||||
void AssetsLibraryModel::setRootPath(const QString &newPath)
|
||||
|
@@ -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;
|
||||
};
|
||||
|
||||
|
@@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user