Debian Codegraph @

doc/src/serviceframework/examples/servicebrowser.qdoc

raw
1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 The Qt Company Ltd and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the documentation of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:FDL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Free Documentation License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Free
19 ** Documentation License version 1.3 as published by the Free Software
20 ** Foundation and appearing in the file included in the packaging of
21 ** this file. Please review the following information to ensure
22 ** the GNU Free Documentation License version 1.3 requirements
23 ** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
24 ** $QT_END_LICENSE$
25 **
26 ****************************************************************************/
27
28 /*!
29 \example servicebrowser
30 \title Service Browser Example
31 \brief This example demonstrates how Service Framework can register and search for
32 services and interfaces.
33
34 \ingroup serviceframework-examples
35
36 This example shows how to use the Service Framework to:
37
38 \list
39 \li Register and unregister services
40 \li Find available services
41 \li Find the interfaces that are implemented by a service
42 \li Look up the attributes for an interface implementation using the meta-object system
43 \li Set a default interface implementation
44 \endlist
45
46 \image servicebrowser.png Screenshot of the Service Browser example
47
48 The application window is split into three panes.
49
50 The top-left pane shows all the services that are registered within the
51 Service Framework.
52
53 The bottom-left pane shows the interfaces implemented by the service selected in the top-left pane. Each entry in this list shows:
54
55 \list
56 \li The name and version of the implemented interface
57 \li The service that provides this implementation (in brackets)
58 \li Whether the implementation is the default for its interface
59 \endlist
60
61 The right-hand pane shows the attributes of an interface implementation that are invokable through the Qt meta-object system. Such attributes include signals, slots, properties and methods marked with the \c Q_INVOKABLE macro. If the "Selected implementation" radio button is checked, this view shows the attributes of the selected implementation in the bottom-left pane; otherwise, it shows the attributes of the \e default implementation for the interface of the selected implementation.
62
63
64 \section1 ServiceBrowser Class Definition
65
66 The ServiceBrowser class inherits from QWidget. It has several slots for reloading the lists in the three information panes, and for changing the default implementation for an interface.
67
68 \quotefromfile servicebrowser/servicebrowser.h
69 \skipto class ServiceBrowser
70 \printuntil private:
71 \dots
72 \skipto }
73 \printline }
74
75
76 \section1 ServiceBrowser Class Implementation
77
78 \quotefromfile servicebrowser/servicebrowser.cpp
79 \skipto ServiceBrowser::ServiceBrowser
80 \printuntil }
81
82 The constructor registers the projects in
83 the \c examples/ directory. It also calls \c reloadServicesList() to show
84 these two newly registered services in the top-left pane.
85
86 \quotefromfile servicebrowser/servicebrowser.cpp
87 \skipto ServiceBrowser::reloadServicesList
88 \printuntil }
89
90 When the services list in the top-left pane needs to be refreshed, we call QServiceManager::findServices() to get a QStringList of all services that are currently registered with the service framework.
91
92 \quotefromfile servicebrowser/servicebrowser.cpp
93 \skipto ServiceBrowser::reloadInterfaceImplementationsList
94 \printuntil {
95 \skipto findInterfaces
96 \dots
97 \dots
98 \printuntil }
99 \dots
100 \skipto }
101 \printline }
102
103 To create the list of interface implementations in the bottom-left pane, we call QServiceManager::findInterfaces() to get a list of QServiceInterfaceDescriptor objects. If a particular service has been selected in the top-left pane, we call QServiceManager::findInterfaces() with the name of that service as the argument, so that it will only return the interface implementations provided by that service. Otherwise, it is called with no argument to retrieve a list of all implementations provided by all registered services.
104
105 The example maps each entry in the interface implementations list to its corresponding QServiceInterfaceDescriptor object using the QListWidgetItem::setData() method.
106
107 Note how we also call QServiceManager::defaultServiceInterface() to determine whether an interface implementation is the default for that interface.
108
109 \quotefromfile servicebrowser/servicebrowser.cpp
110 \skipto ServiceBrowser::reloadAttributesList
111 \printto attributesListWidget->clear()
112 \dots
113
114 The \c reloadAttributesList() method creates the list in the right-hand pane that shows the attributes of an interface implementation that can be invoked through the Qt meta-object system.
115
116 QServiceManager::loadInterface() is called to get an instance of the identified interface implementation. This method finds the corresponding service plugin and returns the QObject instance provided by the service plugin's QServicePluginInterface::createInstance() method.
117
118 \quotefromfile servicebrowser/servicebrowser.cpp
119 \skipto ServiceBrowser::reloadAttributesList
120 \skipto QMetaObject
121 \dots
122 \printto setDefaultInterfaceImplementation
123
124 Call QObject::metaObject() on the implementation instance to get a QMetaObject instance that reveals the dynamically invokable attributes for the instance. These attributes include properties, signals, slots, and methods marked with the Q_INVOKABLE macro. Call QMetaObject::method() to get information about a signal, slot or invokable method, and QMetaObject::property() to access a property of the instance.
125
126 When you know the name of the method you wish to invoke, call QMetaObject::invoke() or QMetaMethod::invoke() to invoke it dynamically. Similarly, QMetaProperty::read() and QMetaProperty::write() can be used to read and modify the value of a property.
127
128 */