[vlc-commits] [Git][videolan/vlc][master] 2 commits: qml: replace usage of Helpers.get with coalescence operator
Steve Lhomme (@robUx4)
gitlab at videolan.org
Sat Apr 20 16:09:43 UTC 2024
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
ee771cd6 by Pierre Lamot at 2024-04-20T15:05:00+00:00
qml: replace usage of Helpers.get with coalescence operator
- - - - -
d78eb68e by Pierre Lamot at 2024-04-20T15:05:00+00:00
qml: remove Helpers.get method
- - - - -
13 changed files:
- modules/gui/qt/maininterface/qml/MainViewLoader.qml
- modules/gui/qt/medialibrary/qml/MusicAlbums.qml
- modules/gui/qt/medialibrary/qml/MusicAlbumsGridExpandDelegate.qml
- modules/gui/qt/medialibrary/qml/MusicAllArtists.qml
- modules/gui/qt/medialibrary/qml/MusicGenres.qml
- modules/gui/qt/medialibrary/qml/PlaylistMediaList.qml
- modules/gui/qt/medialibrary/qml/VideoAll.qml
- modules/gui/qt/network/qml/BrowseTreeDisplay.qml
- modules/gui/qt/util/qml/Helpers.js
- modules/gui/qt/util/qml/MLContextMenu.qml
- modules/gui/qt/widgets/qml/ExpandGridView.qml
- modules/gui/qt/widgets/qml/FadingEdgeForListView.qml
- modules/gui/qt/widgets/qml/ViewHeader.qml
Changes:
=====================================
modules/gui/qt/maininterface/qml/MainViewLoader.qml
=====================================
@@ -80,9 +80,7 @@ Widgets.StackViewExt {
property int initialIndex: -1
// used in custom focus management for explicit "focusReason" transfer
- property var setCurrentItemFocus: {
- return Helpers.get(currentItem, "setCurrentItemFocus", setCurrentItemFocusDefault)
- }
+ property var setCurrentItemFocus: currentItem?.setCurrentItemFocus ?? setCurrentItemFocusDefault
// NOTE: We have to use a Component here. When using a var the onCurrentComponentChanged event
// gets called multiple times even when the currentComponent stays the same.
=====================================
modules/gui/qt/medialibrary/qml/MusicAlbums.qml
=====================================
@@ -31,15 +31,15 @@ MainInterface.MainViewLoader {
// Properties
- property var gridViewRowX: Helpers.get(currentItem, "rowX", 0)
+ property var gridViewRowX: currentItem?.rowX ?? 0
- readonly property var currentIndex: Helpers.get(currentItem, "currentIndex", - 1)
+ readonly property var currentIndex: currentItem?.currentIndex ?? - 1
property Component header: null
- readonly property Item headerItem: Helpers.get(currentItem, "headerItem", null)
+ readonly property Item headerItem: currentItem?.headerItem ?? null
- readonly property int contentLeftMargin: Helpers.get(currentItem, "contentLeftMargin", 0)
- readonly property int contentRightMargin: Helpers.get(currentItem, "contentRightMargin", 0)
+ readonly property int contentLeftMargin: currentItem?.contentLeftMargin ?? 0
+ readonly property int contentRightMargin: currentItem?.contentRightMargin ?? 0
property alias parentId: albumModelId.parentId
property alias searchPattern: albumModelId.searchPattern
=====================================
modules/gui/qt/medialibrary/qml/MusicAlbumsGridExpandDelegate.qml
=====================================
@@ -63,7 +63,7 @@ FocusScope {
}
function _getStringTrack() {
- const count = Helpers.get(model, "nb_tracks", 0);
+ const count = model?.nb_tracks ?? 0;
if (count < 2)
return qsTr("%1 track").arg(count);
@@ -240,7 +240,7 @@ FocusScope {
Widgets.SubtitleLabel {
id: expand_infos_title_id
- text: Helpers.get(root.model, "title", qsTr("Unknown title"))
+ text: root.model?.title ?? qsTr("Unknown title")
color: theme.fg.primary
@@ -265,10 +265,10 @@ FocusScope {
width: parent.width
text: qsTr("%1 - %2 - %3 - %4")
- .arg(Helpers.get(root.model, "main_artist", qsTr("Unknown artist")))
- .arg(Helpers.get(root.model, "release_year", ""))
+ .arg(root.model?.main_artist ?? qsTr("Unknown artist"))
+ .arg(root.model?.release_year ?? "")
.arg(_getStringTrack())
- .arg((root.model && root.model.duration) ? root.model.duration.formatHMS() : 0)
+ .arg(root.model?.duration?.formatHMS() ?? 0)
}
}
}
=====================================
modules/gui/qt/medialibrary/qml/MusicAllArtists.qml
=====================================
@@ -32,12 +32,12 @@ MainInterface.MainViewLoader {
// Properties
- readonly property int currentIndex: Helpers.get(currentItem, "currentIndex", - 1)
+ readonly property int currentIndex: currentItem?.currentIndex ?? - 1
property Component header: null
- readonly property int contentLeftMargin: Helpers.get(currentItem, "contentLeftMargin", 0)
- readonly property int contentRightMargin: Helpers.get(currentItem, "contentRightMargin", 0)
+ readonly property int contentLeftMargin: currentItem?.contentLeftMargin ?? 0
+ readonly property int contentRightMargin: currentItem?.contentRightMargin ?? 0
property alias parentId: artistModel.parentId
property alias searchPattern: artistModel.searchPattern
=====================================
modules/gui/qt/medialibrary/qml/MusicGenres.qml
=====================================
@@ -33,12 +33,12 @@ MainInterface.MainViewLoader {
id: root
// Properties
- readonly property var currentIndex: Helpers.get(currentItem, "currentIndex", - 1)
+ readonly property var currentIndex: currentItem?.currentIndex ?? - 1
property Component header: null
- readonly property int contentLeftMargin: Helpers.get(currentItem, "contentLeftMargin", 0)
- readonly property int contentRightMargin: Helpers.get(currentItem, "contentRightMargin", 0)
+ readonly property int contentLeftMargin: currentItem?.contentLeftMargin ?? 0
+ readonly property int contentRightMargin: currentItem?.contentRightMargin ?? 0
property alias searchPattern: genreModel.searchPattern
property alias sortOrder: genreModel.sortOrder
=====================================
modules/gui/qt/medialibrary/qml/PlaylistMediaList.qml
=====================================
@@ -41,12 +41,12 @@ MainInterface.MainViewLoader {
property bool isMusic: false
- readonly property int currentIndex: Helpers.get(currentItem, "currentIndex", -1)
+ readonly property int currentIndex: currentItem?.currentIndex ?? -1
property Component header: null
- readonly property int contentLeftMargin: Helpers.get(currentItem, "contentLeftMargin", 0)
- readonly property int contentRightMargin: Helpers.get(currentItem, "contentRightMargin", 0)
+ readonly property int contentLeftMargin: currentItem?.contentLeftMargin ?? 0
+ readonly property int contentRightMargin: currentItem?.contentRightMargin ?? 0
property alias searchPattern: playlistModel.searchPattern
property alias sortOrder: playlistModel.sortOrder
=====================================
modules/gui/qt/medialibrary/qml/VideoAll.qml
=====================================
@@ -35,19 +35,19 @@ MainInterface.MainViewLoader {
// Properties
- readonly property int contentLeftMargin: Helpers.get(currentItem, "contentLeftMargin", 0)
- readonly property int contentRightMargin: Helpers.get(currentItem, "contentRightMargin", 0)
+ readonly property int contentLeftMargin: currentItem?.contentLeftMargin ?? 0
+ readonly property int contentRightMargin: currentItem?.contentRightMargin ?? 0
property bool fadingEdgeList: true
// NOTE: Specify an optional header for the view.
property Component header: null
- property Item headerItem: Helpers.get(currentItem, "headerItem", null)
+ property Item headerItem: currentItem?.headerItem ?? null
property int headerPositioning: ListView.OverlayHeader
- readonly property int currentIndex: Helpers.get(currentItem, "currentIndex", -1)
+ readonly property int currentIndex: currentItem?.currentIndex ?? -1
// 'role' used for tableview's section text
/* required */ property string sectionProperty
=====================================
modules/gui/qt/network/qml/BrowseTreeDisplay.qml
=====================================
@@ -35,11 +35,11 @@ MainInterface.MainViewLoader {
readonly property var currentIndex: _currentView.currentIndex
- readonly property int contentLeftMargin: Helpers.get(currentItem, "contentLeftMargin", 0)
- readonly property int contentRightMargin: Helpers.get(currentItem, "contentRightMargin", 0)
+ readonly property int contentLeftMargin: currentItem?.contentLeftMargin ?? 0
+ readonly property int contentRightMargin: currentItem?.contentRightMargin ?? 0
// 'loading' property is not available with NetworkDevicesModel
- readonly property bool loading: Helpers.get(model, "loading", false)
+ readonly property bool loading: model?.loading ?? false
// fixme remove this
property Item _currentView: currentItem
=====================================
modules/gui/qt/util/qml/Helpers.js
=====================================
@@ -26,14 +26,6 @@ function isValidInstanceOf(object, type) {
return (!!object && (object instanceof type))
}
-// Returns the value associated with the key.
-// If the hash contains no item with the key,
-// or the value is invalid, returns defaultValue
-function get(dict, key, defaultValue) {
- var v = typeof dict !== "undefined" && !!dict ? dict[key] : undefined
- return typeof v === "undefined" ? defaultValue : v
-}
-
// NOTE: This allows us to force another 'reason' even when the item has activeFocus.
function enforceFocus(item, reason) {
if (item.activeFocus && item.focusReason === reason)
=====================================
modules/gui/qt/util/qml/MLContextMenu.qml
=====================================
@@ -147,7 +147,7 @@ NativeMenu {
function showInformationAvailable(dataList, options, indexes) {
return indexes.length === 1
- && Helpers.isInteger(Helpers.get(options, "information", null))
+ && Helpers.isInteger(options?.["information"] ?? null)
}
// Private
@@ -187,13 +187,13 @@ NativeMenu {
}
function _signalShowInformation(dataList, options) {
- const index = Helpers.get(options, "information", null)
+ const index = options?.["information"] ?? null
console.assert(Helpers.isInteger(index))
showMediaInformation(index)
}
function _playerOptions(options, extraOptions) {
- const playerOpts = Helpers.get(options, "player-options", [])
+ const playerOpts = options?.["player-options"] ?? []
return playerOpts.concat(extraOptions)
}
=====================================
modules/gui/qt/widgets/qml/ExpandGridView.qml
=====================================
@@ -621,7 +621,7 @@ FocusScope {
}
function _shouldDelayRemove(item) {
- return Helpers.get(item, "delayRemove", false)
+ return item?.delayRemove ??false
}
function _delayRemove(id, item) {
=====================================
modules/gui/qt/widgets/qml/FadingEdgeForListView.qml
=====================================
@@ -95,14 +95,14 @@ FadingEdge {
: !listView.atXBeginning) &&
(!firstVisibleItem ||
(!firstVisibleItem.activeFocus &&
- !Helpers.get(firstVisibleItem, "hovered", true)))
+ !(firstVisibleItem?.hovered ?? true)))
enableEndFade: _fadeRectEnoughSize &&
(orientation === Qt.Vertical ? !listView.atYEnd
: !listView.atXEnd) &&
(!lastVisibleItem ||
(!lastVisibleItem.activeFocus &&
- !Helpers.get(lastVisibleItem, "hovered", true)))
+ !(lastVisibleItem?.hovered ?? true)))
Binding on enableBeginningFade {
when: !!listView.headerItem && (listView.headerPositioning !== ListView.InlineHeader)
=====================================
modules/gui/qt/widgets/qml/ViewHeader.qml
=====================================
@@ -34,8 +34,8 @@ T.Pane {
/* required */ property var view
- leftPadding: Helpers.get(view, "contentLeftMargin", 0)
- rightPadding: Helpers.get(view, "contentRightMargin", 0)
+ leftPadding: view?.contentLeftMargin ?? 0
+ rightPadding: view?.contentRightMargin ?? 0
bottomPadding: VLCStyle.layoutTitle_bottom_padding
topPadding: VLCStyle.layoutTitle_top_padding
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/f833a6edd31c7b79c33d1d115c5ec0136a41a0bc...d78eb68e141e9f11ba19a6717f9b9f7b60bfbae1
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/f833a6edd31c7b79c33d1d115c5ec0136a41a0bc...d78eb68e141e9f11ba19a6717f9b9f7b60bfbae1
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list