Use double underscores instead of single ones in QML

Also, fixed some QML errors -- they didn't have any real consequence,
so they could be considered warnings. Also, AssetsView._modelIndex()
was being called with two arguments instead of one -- this didn't
result in any warnings.

Change-Id: I08274a49531a4082fa94fb89e4230fdac5b1b658
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Samuel Ghinet
2022-11-23 15:47:34 +02:00
parent afc7cd2c98
commit 056165d071
5 changed files with 130 additions and 127 deletions

View File

@@ -18,17 +18,17 @@ TreeViewDelegate {
readonly property bool isEffect: root.suffix === ".qep"
property bool currFileSelected: false
property int initialDepth: -1
property bool _isDirectory: assetsModel.isDirectory(model.filePath)
property int _currentRow: model.index
property string _itemPath: model.filePath
property bool __isDirectory: assetsModel.isDirectory(model.filePath)
property int __currentRow: model.index
property string __itemPath: model.filePath
readonly property int _fileItemHeight: thumbnailImage.height
readonly property int _dirItemHeight: 21
readonly property int __fileItemHeight: thumbnailImage.height
readonly property int __dirItemHeight: 21
implicitHeight: root._isDirectory ? root._dirItemHeight : root._fileItemHeight
implicitHeight: root.__isDirectory ? root.__dirItemHeight : root.__fileItemHeight
implicitWidth: root.assetsView.width > 0 ? root.assetsView.width : 10
leftMargin: root._isDirectory ? 0 : thumbnailImage.width
leftMargin: root.__isDirectory ? 0 : thumbnailImage.width
Component.onCompleted: {
// the depth of the root path will become available before we get to the actual
@@ -36,7 +36,7 @@ TreeViewDelegate {
// tree items (below the root) will have the indentation (basically, depth) adjusted.
if (model.filePath === assetsModel.rootPath()) {
root.assetsView.rootPathDepth = root.depth
root.assetsView.rootPathRow = root._currentRow
root.assetsView.rootPathRow = root.__currentRow
} else if (model.filePath.includes(assetsModel.rootPath())) {
root.depth -= root.assetsView.rootPathDepth
root.initialDepth = root.depth
@@ -45,7 +45,7 @@ TreeViewDelegate {
// workaround for a bug -- might be fixed by https://codereview.qt-project.org/c/qt/qtdeclarative/+/442721
onYChanged: {
if (root._currentRow === root.assetsView.firstRow) {
if (root.__currentRow === root.assetsView.firstRow) {
if (root.y > root.assetsView.contentY) {
let item = root.assetsView.itemAtCell(0, root.assetsView.rootPathRow)
if (!item)
@@ -74,16 +74,16 @@ TreeViewDelegate {
id: bg
color: {
if (root._isDirectory && (root.isHoveringDrop || root.hasChildWithDropHover))
if (root.__isDirectory && (root.isHoveringDrop || root.hasChildWithDropHover))
return StudioTheme.Values.themeInteraction
if (!root._isDirectory && root.assetsView.selectedAssets[root._itemPath])
if (!root.__isDirectory && root.assetsView.selectedAssets[root.__itemPath])
return StudioTheme.Values.themeInteraction
if (mouseArea.containsMouse)
return StudioTheme.Values.themeSectionHeadBackground
return root._isDirectory
return root.__isDirectory
? StudioTheme.Values.themeSectionHeadBackground
: "transparent"
}
@@ -104,15 +104,15 @@ TreeViewDelegate {
contentItem: Text {
id: assetLabel
text: assetLabel._computeText()
text: assetLabel.__computeText()
color: StudioTheme.Values.themeTextColor
font.pixelSize: 14
anchors.verticalCenter: parent.verticalCenter
verticalAlignment: Qt.AlignVCenter
function _computeText()
function __computeText()
{
return root._isDirectory
return root.__isDirectory
? (root.hasChildren
? model.display.toUpperCase()
: model.display.toUpperCase() + qsTr(" (empty)"))
@@ -130,14 +130,14 @@ TreeViewDelegate {
root.assetsRoot.updateDropExtFiles(drag)
root.isHoveringDrop = drag.accepted && root.assetsRoot.dropSimpleExtFiles.length > 0
if (root.isHoveringDrop)
root.assetsView.startDropHoverOver(root._currentRow)
root.assetsView.startDropHoverOver(root.__currentRow)
}
onDropped: (drag) => {
root.isHoveringDrop = false
root.assetsView.endDropHover(root._currentRow)
root.assetsView.endDropHover(root.__currentRow)
let dirPath = root._isDirectory
let dirPath = root.__isDirectory
? model.filePath
: assetsModel.parentDirPath(model.filePath);
@@ -149,7 +149,7 @@ TreeViewDelegate {
onExited: {
if (root.isHoveringDrop) {
root.isHoveringDrop = false
root.assetsView.endDropHover(root._currentRow)
root.assetsView.endDropHover(root.__currentRow)
}
}
}
@@ -178,25 +178,25 @@ TreeViewDelegate {
mouseArea.allowTooltip = false
tooltipBackend.hideTooltip()
if (root._isDirectory)
if (root.__isDirectory)
return
var ctrlDown = mouse.modifiers & Qt.ControlModifier
if (mouse.button === Qt.LeftButton) {
if (!root.assetsView.isAssetSelected(root._itemPath) && !ctrlDown)
if (!root.assetsView.isAssetSelected(root.__itemPath) && !ctrlDown)
root.assetsView.clearSelectedAssets()
root.currFileSelected = ctrlDown ? !root.assetsView.isAssetSelected(root._itemPath) : true
root.assetsView.setAssetSelected(root._itemPath, root.currFileSelected)
root.currFileSelected = ctrlDown ? !root.assetsView.isAssetSelected(root.__itemPath) : true
root.assetsView.setAssetSelected(root.__itemPath, root.currFileSelected)
if (root.currFileSelected) {
let selectedPaths = root.assetsView.selectedPathsAsList()
rootView.startDragAsset(selectedPaths, mapToGlobal(mouse.x, mouse.y))
}
} else {
if (!root.assetsView.isAssetSelected(root._itemPath) && !ctrlDown)
if (!root.assetsView.isAssetSelected(root.__itemPath) && !ctrlDown)
root.assetsView.clearSelectedAssets()
root.currFileSelected = root.assetsView.isAssetSelected(root._itemPath) || !ctrlDown
root.assetsView.setAssetSelected(root._itemPath, root.currFileSelected)
root.currFileSelected = root.assetsView.isAssetSelected(root.__itemPath) || !ctrlDown
root.assetsView.setAssetSelected(root.__itemPath, root.currFileSelected)
}
}
@@ -206,7 +206,7 @@ TreeViewDelegate {
if (mouse.button === Qt.LeftButton) {
if (!(mouse.modifiers & Qt.ControlModifier))
root.assetsView.selectedAssets = {}
root.assetsView.selectedAssets[root._itemPath] = root.currFileSelected
root.assetsView.selectedAssets[root.__itemPath] = root.currFileSelected
root.assetsView.selectedAssetsChanged()
}
}
@@ -239,28 +239,28 @@ TreeViewDelegate {
onClicked: (mouse) => {
if (mouse.button === Qt.LeftButton)
root._toggleExpandCurrentRow()
root.__toggleExpandCurrentRow()
else
root._openContextMenuForCurrentRow()
root.__openContextMenuForCurrentRow()
}
} // MouseArea
function _openContextMenuForCurrentRow()
function __openContextMenuForCurrentRow()
{
let modelIndex = assetsModel.indexForPath(model.filePath)
if (root._isDirectory) {
var row = root.assetsView.rowAtIndex(modelIndex)
var expanded = root.assetsView.isExpanded(row)
var allExpandedState = root.assetsView.computeAllExpandedState()
function onFolderCreated(path) {
root.assetsView.addCreatedFolder(path)
}
if (root.__isDirectory) {
var row = root.assetsView.rowAtIndex(modelIndex)
var expanded = root.assetsView.isExpanded(row)
var allExpandedState = root.assetsView.computeAllExpandedState()
function onFolderRenamed() {
if (expanded)
root.assetsView.rowToExpand = row
@@ -272,40 +272,40 @@ TreeViewDelegate {
let parentDirIndex = assetsModel.parentDirIndex(model.filePath)
let selectedPaths = root.assetsView.selectedPathsAsList()
root.assetsView.contextMenu.openContextMenuForFile(modelIndex, parentDirIndex,
selectedPaths)
selectedPaths, onFolderCreated)
}
}
function _toggleExpandCurrentRow()
function __toggleExpandCurrentRow()
{
if (!root._isDirectory)
if (!root.__isDirectory)
return
let index = root.assetsView._modelIndex(root._currentRow, 0)
let index = root.assetsView.__modelIndex(root.__currentRow)
// if the user manually clicked on a directory, then this is definitely not a
// an automatic request to expand all.
root.assetsView.requestedExpandAll = false
if (root.assetsView.isExpanded(root._currentRow)) {
if (root.assetsView.isExpanded(root.__currentRow)) {
root.assetsView.requestedExpandAll = false
root.assetsView.collapse(root._currentRow)
root.assetsView.collapse(root.__currentRow)
} else {
root.assetsView.expand(root._currentRow)
root.assetsView.expand(root.__currentRow)
}
}
function reloadImage()
{
if (root._isDirectory)
if (root.__isDirectory)
return
thumbnailImage.source = ""
thumbnailImage.source = thumbnailImage._computeSource()
thumbnailImage.source = thumbnailImage.__computeSource()
}
Image {
id: thumbnailImage
visible: !root._isDirectory
visible: !root.__isDirectory
x: root.depth * root.indentation
width: 48
height: 48
@@ -314,11 +314,11 @@ TreeViewDelegate {
sourceSize.height: 48
asynchronous: true
fillMode: Image.PreserveAspectFit
source: thumbnailImage._computeSource()
source: thumbnailImage.__computeSource()
function _computeSource()
function __computeSource()
{
return root._isDirectory
return root.__isDirectory
? ""
: "image://qmldesigner_assets/" + model.filePath
}

View File

@@ -16,7 +16,7 @@ Item {
property var dropComplexExtFiles: []
readonly property int qtVersionAtLeast6_4: rootView.qtVersionIsAtLeast6_4()
property bool _searchBoxEmpty: true
property bool __searchBoxEmpty: true
AssetsContextMenu {
id: contextMenu
@@ -136,10 +136,10 @@ Item {
rootView.handleSearchFilterChanged(searchBox.text)
assetsView.expandAll()
if (root._searchBoxEmpty && searchBox.text)
root._searchBoxEmpty = false
else if (!root._searchBoxEmpty && !searchBox.text)
root._searchBoxEmpty = true
if (root.__searchBoxEmpty && searchBox.text)
root.__searchBoxEmpty = false
else if (!root.__searchBoxEmpty && !searchBox.text)
root.__searchBoxEmpty = true
}
}
@@ -159,13 +159,13 @@ Item {
leftPadding: 10
color: StudioTheme.Values.themeTextColor
font.pixelSize: 12
visible: !assetsModel.haveFiles && !root._searchBoxEmpty
visible: !assetsModel.haveFiles && !root.__searchBoxEmpty
}
Item { // placeholder when the assets library is empty
width: parent.width
height: parent.height - searchRow.height
visible: !assetsModel.haveFiles && root._searchBoxEmpty
visible: !assetsModel.haveFiles && root.__searchBoxEmpty
clip: true
DropArea { // handles external drop (goes into default folder based on suffix)

View File

@@ -11,84 +11,85 @@ StudioControls.Menu {
required property Item assetsView
property bool _isDirectory: false
property var _fileIndex: null
property string _dirPath: ""
property string _dirName: ""
property var _onFolderCreated: null
property var _onFolderRenamed: null
property var _dirIndex: null
property string _allExpandedState: ""
property var _selectedAssetPathsList: null
property bool __isDirectory: false
property var __fileIndex: null
property string __dirPath: ""
property string __dirName: ""
property var __onFolderCreated: null
property var __onFolderRenamed: null
property var __dirIndex: null
property string __allExpandedState: ""
property var __selectedAssetPathsList: null
closePolicy: Popup.CloseOnPressOutside | Popup.CloseOnEscape
function openContextMenuForRoot(rootModelIndex, dirPath, dirName, onFolderCreated)
{
root._onFolderCreated = onFolderCreated
root._fileIndex = ""
root._dirPath = dirPath
root._dirName = dirName
root._dirIndex = rootModelIndex
root._isDirectory = false
root.__onFolderCreated = onFolderCreated
root.__fileIndex = ""
root.__dirPath = dirPath
root.__dirName = dirName
root.__dirIndex = rootModelIndex
root.__isDirectory = false
root.popup()
}
function openContextMenuForDir(dirModelIndex, dirPath, dirName, allExpandedState,
onFolderCreated, onFolderRenamed)
{
root._onFolderCreated = onFolderCreated
root._onFolderRenamed = onFolderRenamed
root._dirPath = dirPath
root._dirName = dirName
root._fileIndex = ""
root._dirIndex = dirModelIndex
root._isDirectory = true
root._allExpandedState = allExpandedState
root.__onFolderCreated = onFolderCreated
root.__onFolderRenamed = onFolderRenamed
root.__dirPath = dirPath
root.__dirName = dirName
root.__fileIndex = ""
root.__dirIndex = dirModelIndex
root.__isDirectory = true
root.__allExpandedState = allExpandedState
root.popup()
}
function openContextMenuForFile(fileIndex, dirModelIndex, selectedAssetPathsList)
function openContextMenuForFile(fileIndex, dirModelIndex, selectedAssetPathsList, onFolderCreated)
{
var numSelected = selectedAssetPathsList.filter(p => p).length
deleteFileItem.text = numSelected > 1 ? qsTr("Delete Files") : qsTr("Delete File")
root._selectedAssetPathsList = selectedAssetPathsList
root._fileIndex = fileIndex
root._dirIndex = dirModelIndex
root._dirPath = assetsModel.filePath(dirModelIndex)
root._isDirectory = false
root.__onFolderCreated = onFolderCreated
root.__selectedAssetPathsList = selectedAssetPathsList
root.__fileIndex = fileIndex
root.__dirIndex = dirModelIndex
root.__dirPath = assetsModel.filePath(dirModelIndex)
root.__isDirectory = false
root.popup()
}
StudioControls.MenuItem {
text: qsTr("Expand All")
enabled: root._allExpandedState !== "all_expanded"
visible: root._isDirectory
enabled: root.__allExpandedState !== "all_expanded"
visible: root.__isDirectory
height: visible ? implicitHeight : 0
onTriggered: root.assetsView.expandAll()
}
StudioControls.MenuItem {
text: qsTr("Collapse All")
enabled: root._allExpandedState !== "all_collapsed"
visible: root._isDirectory
enabled: root.__allExpandedState !== "all_collapsed"
visible: root.__isDirectory
height: visible ? implicitHeight : 0
onTriggered: root.assetsView.collapseAll()
}
StudioControls.MenuSeparator {
visible: root._isDirectory
visible: root.__isDirectory
height: visible ? StudioTheme.Values.border : 0
}
StudioControls.MenuItem {
id: deleteFileItem
text: qsTr("Delete File")
visible: root._fileIndex
visible: root.__fileIndex
height: deleteFileItem.visible ? deleteFileItem.implicitHeight : 0
onTriggered: {
let deleted = assetsModel.requestDeleteFiles(root._selectedAssetPathsList)
let deleted = assetsModel.requestDeleteFiles(root.__selectedAssetPathsList)
if (!deleted)
confirmDeleteFiles.open()
}
@@ -96,30 +97,30 @@ StudioControls.Menu {
ConfirmDeleteFilesDialog {
id: confirmDeleteFiles
parent: root.assetsView
files: root._selectedAssetPathsList
files: root.__selectedAssetPathsList
onAccepted: root.assetsView.selectedAssets = {}
}
}
StudioControls.MenuSeparator {
visible: root._fileIndex
visible: root.__fileIndex
height: visible ? StudioTheme.Values.border : 0
}
StudioControls.MenuItem {
text: qsTr("Rename Folder")
visible: root._isDirectory
visible: root.__isDirectory
height: visible ? implicitHeight : 0
onTriggered: renameFolderDialog.open()
RenameFolderDialog {
id: renameFolderDialog
parent: root.assetsView
dirPath: root._dirPath
dirName: root._dirName
dirPath: root.__dirPath
dirName: root.__dirName
onAccepted: root._onFolderRenamed()
onAccepted: root.__onFolderRenamed()
}
}
@@ -129,9 +130,9 @@ StudioControls.Menu {
NewFolderDialog {
id: newFolderDialog
parent: root.assetsView
dirPath: root._dirPath
dirPath: root.__dirPath
onAccepted: root._onFolderCreated(newFolderDialog.createdDirPath)
onAccepted: root.__onFolderCreated(newFolderDialog.createdDirPath)
}
onTriggered: newFolderDialog.open()
@@ -139,22 +140,22 @@ StudioControls.Menu {
StudioControls.MenuItem {
text: qsTr("Delete Folder")
visible: root._isDirectory
visible: root.__isDirectory
height: visible ? implicitHeight : 0
ConfirmDeleteFolderDialog {
id: confirmDeleteFolderDialog
parent: root.assetsView
dirName: root._dirName
dirIndex: root._dirIndex
dirName: root.__dirName
dirIndex: root.__dirIndex
}
onTriggered: {
if (!assetsModel.hasChildren(root._dirIndex)) {
if (!assetsModel.hasChildren(root.__dirIndex)) {
// NOTE: the folder may still not be empty -- it doesn't have files visible to the
// user, but that doesn't mean that there are no other files (e.g. files of unknown
// types) on disk in this directory.
assetsModel.deleteFolderRecursively(root._dirIndex)
assetsModel.deleteFolderRecursively(root.__dirIndex)
} else {
confirmDeleteFolderDialog.open()
}

View File

@@ -30,7 +30,7 @@ TreeView {
// i.e. first child of the root path
readonly property int firstRow: root.rootPathRow + 1
property int rowToExpand: -1
property var _createdDirectories: []
property var __createdDirectories: []
rowHeightProvider: (row) => {
if (row <= root.rootPathRow)
@@ -70,7 +70,7 @@ TreeView {
function onDirectoryCreated(path)
{
root._createdDirectories.push(path)
root.__createdDirectories.push(path)
updateRowsTimer.restart()
}
@@ -120,7 +120,7 @@ TreeView {
function addCreatedFolder(path)
{
root._createdDirectories.push(path)
root.__createdDirectories.push(path)
}
function selectedPathsAsList()
@@ -140,8 +140,8 @@ TreeView {
if (root.rows <= 0)
return
while (root._createdDirectories.length > 0) {
let dirPath = root._createdDirectories.pop()
while (root.__createdDirectories.length > 0) {
let dirPath = root.__createdDirectories.pop()
let index = assetsModel.indexForPath(dirPath)
let row = root.rowAtIndex(index)
@@ -168,7 +168,7 @@ TreeView {
if (expanding) {
if (root.requestedExpandAll)
root._doExpandAll()
root.__doExpandAll()
} else {
if (root.rowToExpand > 0) {
root.expand(root.rowToExpand)
@@ -182,11 +182,11 @@ TreeView {
root.lastRowCount = root.rows
}
function _doExpandAll()
function __doExpandAll()
{
let expandedAny = false
for (let nRow = 0; nRow < root.rows; ++nRow) {
let index = root._modelIndex(nRow, 0)
let index = root.__modelIndex(nRow)
if (assetsModel.isDirectory(index) && !root.isExpanded(nRow)) {
root.expand(nRow);
expandedAny = true
@@ -199,10 +199,10 @@ TreeView {
function expandAll()
{
// In order for _doExpandAll() to be called repeatedly (every time a new node is
// In order for __doExpandAll() to be called repeatedly (every time a new node is
// loaded, and then, expanded), we need to set requestedExpandAll to true.
root.requestedExpandAll = true
root._doExpandAll()
root.__doExpandAll()
}
function collapseAll()
@@ -211,7 +211,7 @@ TreeView {
// collapse all, except for the root path - from the last item (leaves) up to the root
for (let nRow = root.rows - 1; nRow >= 0; --nRow) {
let index = root._modelIndex(nRow, 0)
let index = root.__modelIndex(nRow)
// we don't want to collapse the root path, because doing so will hide the contents
// of the tree.
if (assetsModel.filePath(index) === assetsModel.rootPath())
@@ -233,7 +233,7 @@ TreeView {
function computeAllExpandedState()
{
var dirsWithChildren = [...Array(root.rows).keys()].filter(row => {
let index = root._modelIndex(row, 0)
let index = root.__modelIndex(row)
return assetsModel.isDirectory(index) && assetsModel.hasChildren(index)
})
@@ -249,21 +249,23 @@ TreeView {
function startDropHoverOver(row)
{
let index = root._modelIndex(row, 0)
let index = root.__modelIndex(row)
if (assetsModel.isDirectory(index))
return
let parentItem = root._getDelegateParentForIndex(index)
let parentItem = root.__getDelegateParentForIndex(index)
if (parentItem)
parentItem.hasChildWithDropHover = true
}
function endDropHover(row)
{
let index = root._modelIndex(row, 0)
let index = root.__modelIndex(row)
if (assetsModel.isDirectory(index))
return
let parentItem = root._getDelegateParentForIndex(index)
let parentItem = root.__getDelegateParentForIndex(index)
if (parentItem)
parentItem.hasChildWithDropHover = false
}
@@ -283,14 +285,14 @@ TreeView {
root.selectedAssetsChanged()
}
function _getDelegateParentForIndex(index)
function __getDelegateParentForIndex(index)
{
let parentIndex = assetsModel.parentDirIndex(index)
let parentCell = root.cellAtIndex(parentIndex)
return root.itemAtCell(parentCell)
}
function _modelIndex(row)
function __modelIndex(row)
{
// The modelIndex() function exists since 6.3. In Qt 6.3, this modelIndex() function was a
// member of the TreeView, while in Qt6.4 it was moved to TableView. In Qt6.4, the order of

View File

@@ -17,7 +17,7 @@ Dialog {
required property string dirPath
property string createdDirPath: ""
readonly property int _maxPath: 260
readonly property int __maxPath: 260
HelperWidgets.RegExpValidator {
id: folderNameValidator
@@ -67,7 +67,7 @@ Dialog {
text: qsTr("Folder path is too long.")
color: "#ff0000"
anchors.right: parent.right
visible: root.createdDirPath.length > root._maxPath
visible: root.createdDirPath.length > root.__maxPath
}
Item { // spacer
@@ -82,7 +82,7 @@ Dialog {
id: btnCreate
text: qsTr("Create")
enabled: folderName.text !== "" && root.createdDirPath.length <= root._maxPath
enabled: folderName.text !== "" && root.createdDirPath.length <= root.__maxPath
onClicked: {
root.createdDirPath = root.dirPath + '/' + folderName.text
if (assetsModel.addNewFolder(root.createdDirPath))