DataGridView.qml 3.45 KB
Newer Older
1
/*
Matthieu Gallien's avatar
Matthieu Gallien committed
2 3 4
   SPDX-FileCopyrightText: 2018 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr>

   SPDX-License-Identifier: LGPL-3.0-or-later
5 6 7 8
 */

import QtQuick 2.10
import QtQuick.Controls 2.3
9
import org.kde.kirigami 2.5 as Kirigami
10 11
import org.kde.elisa 1.0

12
FocusScope {
13
    id: viewHeader
14

15
    property var filterType
16
    property alias mainTitle: gridView.mainTitle
17
    property alias secondaryTitle: gridView.secondaryTitle
18
    property alias image: gridView.image
19
    property var modelType
20 21
    property AbstractItemModel realModel
    property AbstractProxyModel proxyModel
22 23 24
    property alias defaultIcon: gridView.defaultIcon
    property alias showRating: gridView.showRating
    property alias delegateDisplaySecondaryText: gridView.delegateDisplaySecondaryText
25
    property alias isSubPage: gridView.isSubPage
26
    property alias expandedFilterView: gridView.expandedFilterView
27
    property alias haveTreeModel: gridView.haveTreeModel
28
    property var filter
29 30 31 32 33
    property alias sortRole: gridView.sortRole
    property alias sortRoles: gridView.sortRoles
    property alias sortRoleNames: gridView.sortRoleNames
    property alias sortOrderNames: gridView.sortOrderNames
    property alias sortOrder: gridView.sortOrder
34
    property bool modelIsInitialized: false
35
    property alias viewManager: gridView.viewManager
36

37
    focus: true
38

39 40 41
    Accessible.role: Accessible.Pane
    Accessible.name: mainTitle

42 43
    function initializeModel()
    {
44 45 46
        if (!proxyModel) {
            return
        }
47

48 49 50
        if (!realModel) {
            return
        }
51

52
        if (!ElisaApplication.musicManager) {
53 54
            return
        }
55

56 57 58 59 60 61
        if (modelIsInitialized) {
            return
        }

        proxyModel.sourceModel = realModel
        proxyModel.dataType = modelType
62
        proxyModel.playList = Qt.binding(function() { return ElisaApplication.mediaPlayListProxyModel })
63 64
        gridView.contentModel = proxyModel

65 66
        proxyModel.sortModel(sortOrder)

67
        realModel.initializeByData(ElisaApplication.musicManager, ElisaApplication.musicManager.viewDatabase,
68
                                   modelType, filterType, filter)
69 70

        modelIsInitialized = true
71 72
    }

73 74 75 76
    function goToBack() {
        gridView.goToBack()
    }

77 78
    GridBrowserView {
        id: gridView
79 80 81

        focus: true

82 83
        anchors.fill: parent

84 85 86
        onEnqueue: proxyModel.enqueue(fullData, name,
                                      ElisaUtils.AppendPlayList,
                                      ElisaUtils.DoNotTriggerPlay)
87

88 89 90
        onReplaceAndPlay: proxyModel.enqueue(fullData, name,
                                             ElisaUtils.ReplacePlayList,
                                             ElisaUtils.TriggerPlay)
91

92
        onOpen: viewManager.openChildView(fullData)
93

94 95
        suppressNoDataPlaceholderMessage: busyIndicatorLoader.active

96 97 98
        onGoBackRequested: {
            viewManager.goBack()
        }
99 100

        Loader {
101
            id: busyIndicatorLoader
102 103 104
            anchors.centerIn: parent
            height: Kirigami.Units.gridUnit * 5
            width: height
105

Matthieu Gallien's avatar
Matthieu Gallien committed
106 107
            visible: realModel ? realModel.isBusy : true
            active: realModel ? realModel.isBusy : true
108 109

            sourceComponent: BusyIndicator {
110
                anchors.centerIn: parent
111 112
            }
        }
113
    }
114 115

    Connections {
116
        target: ElisaApplication
117

118 119 120
        function onMusicManagerChanged() {
            initializeModel()
        }
121 122 123
    }

    Component.onCompleted: {
124
        initializeModel()
125
    }
126
}