QmlDesigner: Disable Asset Library context menu when not needed

Assets Library context menus options are now enabled only when needed
and disabled otherwise. Also some renaming etc.

Task-number: QDS-4628
Change-Id: I5b2c4209f8389e51cf3f5e470bc14e5f9ffc1f29
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
Miina Puuronen
2021-06-24 14:08:40 +03:00
parent 35b169f466
commit a813897825
3 changed files with 41 additions and 7 deletions

View File

@@ -33,6 +33,7 @@ import StudioTheme 1.0 as StudioTheme
Item {
property var selectedAssets: ({})
property int allExpandedState: 0
DropArea {
id: dropArea
@@ -81,11 +82,13 @@ Item {
StudioControls.MenuItem {
text: qsTr("Expand All")
enabled: allExpandedState !== 1
onTriggered: assetsModel.toggleExpandAll(true)
}
StudioControls.MenuItem {
text: qsTr("Collapse All")
enabled: allExpandedState !== 2
onTriggered: assetsModel.toggleExpandAll(false)
}
}
@@ -118,6 +121,7 @@ Item {
dirExpanded = !dirExpanded
}
onShowContextMenu: {
allExpandedState = assetsModel.getAllExpandedState()
contextMenu.popup()
}

View File

@@ -44,14 +44,35 @@
namespace QmlDesigner {
void ItemLibraryAssetsModel::saveExpandedState(bool expanded, const QString &sectionName)
void ItemLibraryAssetsModel::saveExpandedState(bool expanded, const QString &assetPath)
{
m_expandedStateHash.insert(sectionName, expanded);
m_expandedStateHash.insert(assetPath, expanded);
}
bool ItemLibraryAssetsModel::loadExpandedState(const QString &sectionName)
bool ItemLibraryAssetsModel::loadExpandedState(const QString &assetPath)
{
return m_expandedStateHash.value(sectionName, true);
return m_expandedStateHash.value(assetPath, true);
}
ItemLibraryAssetsModel::DirExpandState ItemLibraryAssetsModel::getAllExpandedState() const
{
const auto keys = m_expandedStateHash.keys();
bool allExpanded = true;
bool allCollapsed = true;
for (const QString &assetPath : keys) {
bool expanded = m_expandedStateHash.value(assetPath);
if (expanded)
allCollapsed = false;
if (!expanded)
allExpanded = false;
if (!allCollapsed && !allExpanded)
break;
}
return allExpanded ? DirExpandState::AllExpanded : allCollapsed ? DirExpandState::AllCollapsed
: DirExpandState::SomeExpanded;
}
void ItemLibraryAssetsModel::toggleExpandAll(bool expand)
@@ -200,6 +221,7 @@ void ItemLibraryAssetsModel::setRootPath(const QString &path)
ItemLibraryAssetsDir *assetsDir = new ItemLibraryAssetsDir(subDir.path(), currDepth, loadExpandedState(subDir.path()), currAssetsDir);
currAssetsDir->addDir(assetsDir);
saveExpandedState(loadExpandedState(assetsDir->dirPath()), assetsDir->dirPath());
isEmpty &= parseDirRecursive(assetsDir, currDepth + 1);
}

View File

@@ -69,10 +69,18 @@ public:
const QSet<QString> &supportedSuffixes() const;
const QSet<QString> &previewableSuffixes() const;
static void saveExpandedState(bool expanded, const QString &sectionName);
static bool loadExpandedState(const QString &sectionName);
static void saveExpandedState(bool expanded, const QString &assetPath);
static bool loadExpandedState(const QString &assetPath);
enum class DirExpandState {
SomeExpanded,
AllExpanded,
AllCollapsed
};
Q_ENUM(DirExpandState)
Q_INVOKABLE void toggleExpandAll(bool expand);
Q_INVOKABLE DirExpandState getAllExpandedState() const;
private:
SynchronousImageCache &m_fontImageCache;
@@ -83,7 +91,7 @@ private:
ItemLibraryAssetsDir *m_assetsDir = nullptr;
QHash<int, QByteArray> m_roleNames;
inline static QHash<QString, bool> m_expandedStateHash;
inline static QHash<QString, bool> m_expandedStateHash; // <assetPath, isExpanded>
};
} // namespace QmlDesigner