formatting is changed according to last astyle settings
[qtrapids] / src / plugins / PluginInterface.h
1 /***************************************************************************
2  *   Copyright (C) 2009 by Lassi Väätämöinen   *
3  *   lassi.vaatamoinen@ixonos.com   *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 #ifndef PLUGININTERFACE_H
21 #define PLUGININTERFACE_H
22
23 #include <QObject>
24 #include <QPluginLoader>
25
26 namespace qtrapids
27 {
28 <<<<<<< .mine
29
30 // Forward declaration because of co-dependency of classes.
31 class PluginInterface;
32
33 /** @class PluginHostInterface
34 * @brief Defines interface for plugins to access the host application.
35 * A Host is an application that is extended by implementing Plugins,
36 * that implement the additional functionality
37 * @note Implementing plugin host should inherit QObject.
38 */
39 class PluginHostInterface
40 {
41 public:
42
43         /// @brief Sets the plugin GUI element to host application
44         /// @note It is up to the host application to decide how to manage
45         /// and show the actual widget.
46         virtual bool setGui(PluginInterface* from, QWidget* widget) = 0;
47
48         /// @brief Adds additional plugin wigdets to the host application.
49         /// This functio can be called by the plugin recursively, i.e. when GUI events occur
50         /// The host application must handle placing the additional widgets.
51         /// @todo Could we implement this using in a more manageable way, e.g. signal-slot?
52         virtual void addPluginWidget(PluginInterface* from, QWidget* widget) = 0;
53         virtual void addToolbar(PluginInterface* from, QWidget* widget) = 0;
54         virtual void addToolItem(PluginInterface* from, QWidget* widget) = 0;
55         virtual void addMenu(PluginInterface* from, QWidget* widget) = 0;
56         virtual void addMenuItem(PluginInterface* from, QWidget* widget) = 0;
57 };
58 =======
59     >>>>>>> .r31
60     <<<<<<< .mine
61
62     =======
63
64         /** @class PluginHostInterface
65                 * @brief Defines interface for plugins to access the host application.
66                 * A Host is an application that is extended by implementing Plugins,
67                 * that implement the additional functionality
68         */
69         class PluginHostInterface : public QObject
70 {
71 public:
72
73         >>>>>>> .r31
74         /// @brief Sets the plugin GUI element to host application
75         /// @note It is up to the host application to decide how to manage
76         /// and show the actual widget.
77         virtual bool setGui(QWidget* widget) = 0;
78
79         /// @brief Adds additional plugin wigdets to the host application.
80         /// This functio can be called by the plugin recursively, i.e. when GUI events occur
81         /// The host application must handle placing the additional widgets.
82         /// @todo Could we implement this using in a more manageable way, e.g. signal-slot?
83         virtual void addPluginWidget(QWidget* widget) = 0;
84         virtual void addToolbar() = 0;
85         virtual void addToolItem() = 0;
86         virtual void addMenu() = 0;
87         virtual void addMenuItem() = 0;
88 };
89
90
91 /** @class PluginInterface
92         * @brief Defines interface for a plugin instance.
93         * The host application uses PluginInterface interface for calling the plugins
94         * that extend the Host functionality
95 */
96 class PluginInterface : public QObject
97 {
98 public:
99         /// @brief Initializes the plugin instance.
100         virtual void initialize(PluginHostInterface* host) = 0;
101         virtual QWidget* getGui() = 0;
102 };
103
104 } //namespace qtrapids
105
106
107 // Declare the interfaces for the Qt framework.
108 Q_DECLARE_INTERFACE(qtrapids::PluginInterface,
109                     "com.ixonos.qtrapids.PluginInterface/1.0")
110 Q_DECLARE_INTERFACE(qtrapids::PluginHostInterface,
111                     "com.ixonos.qtrapids.PluginHostInterface/1.0")
112
113
114 //////////////// EXAMPLE PLUGIN DECLARATION /////////////////////////
115 // A simple plugin example using the PluginInterface
116 // For more info, see Qt documentation: "How to Create Qt Plugins"
117 //
118 // namespace qtrapids
119 // {
120 //
121 //      class MyPlugin : public PluginInterface {
122 //              Q_OBJECT
123 //              // NOTE: This macro tells Qt which interfaces the plugin implements (i.e. inherits):
124 //              Q_INTERFACES(qtrapids::PluginInterface)
125 //
126 //              public:
127 //                      MyPlugin();
128 //                      virtual void initialize(PluginHostInterface* host);
129 //                      virtual QWidget* getGui();
130 //
131 // // Additional plugin-specific signals and slots.
132 //              signals:
133 //                      void searchResult(QWidget* resultwidget);
134 //
135 //              private slots:
136 //                      void on_button_clicked();
137 //                      void on_result(QWidget* resultWidget);
138 //
139 //              private:
140 //      };
141 //
142 //
143 //      MyPlugin::MyPlugin(): host_(NULL) {}
144 //
145 //              void SearchPlugin::initialize(AbstractPluginHost* host)
146 //              {
147 //                      host_ = host;
148 //
149 //                      if (host_ != NULL) {
150 //                              QWidget *pluginWidget = new QWidget;
151 //                              QVBoxLayout *vbox = new QVBoxLayout;
152 //                              QPushButton *searchButton = new QPushButton("Search");
153 //                              vbox->addWidget(searchButton);
154 //                              pluginWidget->setLayout(vbox);
155 //
156 //                              connect(searchButton, SIGNAL(clicked()), this, SLOT(on_searchButton_clicked()));
157 //                              //connect(this, SIGNAL(searchResult(QWidget*)), this, SLOT(on_searchResult(QWidget*)));
158 //
159 //                              // Call host interface function to set the plugin GUI. Host handles the setup
160 //                              // to it's own policy
161 //                              host_->setGui(pluginWidget);
162 //                      }
163 //              }
164 // } // namespace qtrapids
165 //
166 //// NOTE: Remember to export the actual plugin to be visible for Qt:
167 //// Q_EXPORT_PLUGIN2(myplugin, qtrapids::MyPlugin)
168 //
169 ///////////////// END OF EXAMPLE PLUGIN ///////////////////////////////
170
171 #endif