-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathMMLayersController.qml
More file actions
215 lines (174 loc) · 5.39 KB
/
MMLayersController.qml
File metadata and controls
215 lines (174 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
import QtQuick
import QtQuick.Controls
import mm 1.0 as MM
import MMInput
import "../components"
import "../inputs"
Item {
id: root
signal close()
signal addFeature( var targetLayer )
signal selectFeature( var featurePair )
MM.LayerTreeSortFilterModel {
id: layerTreeProxyModel
layerTreeModel: MM.LayerTreeModel {
id: layerTreeModel
qgsProject: __activeProject.qgsProject
}
}
MM.LayerTreeFlatSortFilterModel {
id: layerTreeFlatSortFilterModel
layerTreeFlatModel: MM.LayerTreeFlatModel {
id: layerTreeFlatModel
qgsProject: __activeProject.qgsProject
}
}
MMStackView {
id: pagesStackView
anchors.fill: parent
}
Keys.onReleased: function( event ) {
if (event.key === Qt.Key_Back || event.key === Qt.Key_Escape) {
event.accepted = true
if ( pagesStackView.depth === 1 ) {
root.close()
}
else {
pagesStackView.pop( StackView.PopTransition )
}
}
}
Component {
id: layersListPage
MMLayersListPage {
model: layerTreeProxyModel
onNodeClicked: function ( node, nodeType, nodeName ) {
if ( nodeType === "group" )
{
let index = layerTreeProxyModel.node2index( node )
const props = {
parentNodeIndex: index,
pageTitle: layerTreeProxyModel.data(index, nodeName)
}
let item = pagesStackView.push( layersListPage, props , StackView.PushTransition )
item.forceActiveFocus()
}
else if ( nodeType === "layer" )
{
const props = {
layerTreeNode: node
}
let item = pagesStackView.push( layerDetailsPage, props, StackView.PushTransition )
item.forceActiveFocus()
}
}
onNodeVisibilityClicked: function( node ) {
__activeProject.switchLayerTreeNodeVisibility( node )
}
onBackClicked: function() {
if (pagesStackView.depth > 1) {
pagesStackView.pop( StackView.PopTransition )
}
else {
root.close()
}
}
onSearchBarClicked: function() {
let item = pagesStackView.push( searchLayersPage, {}, StackView.Immediate )
item.forceActiveFocus()
}
}
}
Component {
id: layerDetailsPage
MMLayerDetailPage {
onClose: function() {
if (pagesStackView.depth > 1) {
pagesStackView.pop( StackView.PopTransition )
}
else {
root.close()
}
}
onFeatureClicked: function( featurePair ) {
root.selectFeature( featurePair )
}
onAddFeatureClicked: function( targetLayer ) {
root.addFeature( targetLayer )
}
}
}
Component {
id: searchLayersPage
MMLayersListSearchPage {
model: layerTreeFlatSortFilterModel
onNodeClicked: function( node, nodeType, nodeName ) {
if ( nodeType === "group" )
{
// convert to layersListSortFilterModel index
const index = layerTreeProxyModel.node2index( node )
const props = {
parentNodeIndex: index,
pageTitle: nodeName
}
let item = pagesStackView.push( layersListPage, props , StackView.PushTransition )
item.forceActiveFocus()
}
else if ( nodeType === "layer" )
{
const props = {
layerTreeNode: node
}
let item = pagesStackView.push( layerDetailsPage, props, StackView.PushTransition )
item.forceActiveFocus()
}
}
onSearchTextChanged: function( searchText ) {
layerTreeFlatSortFilterModel.searchExpression = searchText
}
onNodeVisibilityClicked: function( node ) {
__activeProject.switchLayerTreeNodeVisibility( node )
}
onBackClicked: function() {
if (pagesStackView.depth > 1) {
pagesStackView.pop( StackView.Immediate )
}
else {
root.close()
}
}
}
}
Connections {
target: __activeProject
function onProjectWillBeReloaded() {
layerTreeModel.reset()
layerTreeFlatModel.reset()
}
function onProjectReloaded( qgsProject ) {
layerTreeModel.qgsProject = __activeProject.qgsProject
layerTreeFlatModel.qgsProject = __activeProject.qgsProject
}
}
Component.onCompleted: {
//
// We need to initialize pixmap providers so that it knows where to look for icons
//
__layerTreeModelPixmapProvider.setModel( layerTreeModel )
__layerTreeFlatModelPixmapProvider.setModel( layerTreeFlatModel )
let item = pagesStackView.push( layersListPage, {}, StackView.Immediate )
item.forceActiveFocus()
}
Component.onDestruction: {
__layerTreeModelPixmapProvider.reset()
__layerTreeFlatModelPixmapProvider.reset()
}
}