Unity 8
ScopeSettingsWidgetFactory.qml
1 /*
2  * Copyright (C) 2014 Canonical, Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 import QtQuick 2.4
18 
19 //! \brief This component loads the widgets based on type.
20 
21 Loader {
22  id: root
23 
24  //! The ScopeStyle component.
25  property var scopeStyle: null
26 
27  //! Variable used to contain widget's data
28  property var widgetData: null
29 
30  //! Triggered signal forwarded from the widgets.
31  signal updated(var value)
32 
33  //! makeSureVisible signal forwarded from the widgets.
34  signal makeSureVisible(var item)
35 
36  source: widgetSource
37 
38  //! \cond private
39  property url widgetSource: {
40  switch (widgetData.type) {
41  case "boolean": return "ScopeSettingBoolean.qml";
42  case "list": return "ScopeSettingList.qml";
43  case "number": return "ScopeSettingNumber.qml";
44  case "string": return "ScopeSettingString.qml";
45  default: return "";
46  }
47  }
48  //! \endcond
49 
50  onLoaded: {
51  if (item.hasOwnProperty("initialValue")) item.initialValue = root.widgetData.value;
52  item.widgetData = Qt.binding(function() { return root.widgetData; } )
53  item.scopeStyle = Qt.binding(function() { return root.scopeStyle; } )
54  }
55 
56  Connections {
57  target: root.item
58  onUpdated: if (value !== widgetData.value) root.updated(value)
59  onMakeSureVisible: root.makeSureVisible(item)
60  }
61 }