Unity 8
 All Classes Functions
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.2
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  source: widgetSource
34 
35  //! \cond private
36  property url widgetSource: {
37  switch (widgetData.type) {
38  case "boolean": return "ScopeSettingBoolean.qml";
39  case "list": return "ScopeSettingList.qml";
40  case "number": return "ScopeSettingNumber.qml";
41  case "string": return "ScopeSettingString.qml";
42  default: return "";
43  }
44  }
45  //! \endcond
46 
47  onLoaded: {
48  if (item.hasOwnProperty("initialValue")) item.initialValue = root.widgetData.value;
49  item.widgetData = Qt.binding(function() { return root.widgetData; } )
50  item.scopeStyle = Qt.binding(function() { return root.scopeStyle; } )
51  }
52 
53  Connections {
54  target: root.item
55  onUpdated: if (value !== widgetData.value) root.updated(value)
56  }
57 }