arcsabstractcomponent.h
1 /*
2  name: include/arcs/arcsabstractcomponent.h
3 
4  This file is part of ARCS - Augmented Reality Component System
5  (version 2-current), written by Jean-Yves Didier
6  for IBISC Laboratory (http://www.ibisc.univ-evry.fr)
7 
8  Copyright (C) 2013 Université d'Evry-Val d'Essonne
9 
10  This program is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program. If not, see <http://www.gnu.org/licenses/>.
22 
23 
24  Please send bugreports with examples or suggestions to
25  jean-yves.didier__at__ibisc.univ-evry.fr
26 */
27 
28 
29 #ifndef __ARCSABSTRACTCOMPONENT_H__
30 #define __ARCSABSTRACTCOMPONENT_H__
31 
32 #include <arcs/arcsdll.h>
33 
34 #include <QVariant>
35 #include <QStringList>
36 #include <QObject>
37 #include <QMetaMethod>
38 #include <QList>
39 
40 
41 typedef QList<QObject*> ObjectList;
42 class QMetaObject;
43 
102 class DLL_POINT ARCSAbstractComponent
103 {
104 public:
106  virtual ~ARCSAbstractComponent();
107 
108  // instanciation / destruction
111  bool instanciate() {
112  instanciated = genuineInstanciate(); return instanciated;
113  }
116  bool isInstanciated() { return instanciated; } // trouver un mécanisme pour épargner de coder cette fonction
119  void destroy() { if( instanciated) genuineDestroy(); instanciated = false; }
120 
122 
125  ARCSAbstractComponent* clone();
126 
127  // gestion des signaux et des slots
128 
131  virtual QStringList getSlots() = 0;
134  virtual QStringList getSignals() = 0;
135 
136 
137  // connection
151  virtual bool connect(QString sig, ARCSAbstractComponent* dst, QString slt, bool queued = false);
152 
165  bool disconnect(QString sig, ARCSAbstractComponent* dst, QString slt);
166 
174  bool init(QString slt, QVariant* var);
175 
176  // sérialisation / désérialisation
181  virtual QString toString() = 0;
182 
188  virtual bool parseString(QString s) = 0;
189 
190 
197  virtual bool loadFile(QString fn);
198 
205  virtual bool saveFile(QString fn);
206 
207  // propriétés
208 
213  void setProperty(QString name, QVariant value);
214 
219  QVariant getProperty(QString name);
220 
224  void removeProperty(QString name);
225 
228  void resetProperties();
229 
232  QStringList getProperties();
233 
234 
237  void setFamily(QString s) { family=s; }
240  QString getFamily() { return family; }
241 
244  void setType(QString s) { type =s ;}
245 
248  QString getType() { return type; }
249 
254  virtual QVariant getGenuineComponentInstance() { return QVariant(); }
255 
256 protected:
269  virtual void getProxySlot(QString slot, ObjectList & obj, QStringList & proxySlot)=0;
270 
282  virtual void getProxySignal(QString signal, ObjectList & obj, QStringList & proxySignal)=0;
283 
294  virtual bool genuineConnect(QString, ARCSAbstractComponent*, QString, bool = false) {return false;}
304  virtual bool genuineDisconnect(QString, ARCSAbstractComponent*, QString) {return false;}
305 
306 
308 
310  virtual bool genuineInstanciate() = 0;
311 
313 
315  virtual void genuineDestroy() = 0;
316 
317 
319  static void getProxySlot(ARCSAbstractComponent* cmp, QString slot,
320  ObjectList& obj, QStringList & proxySlot)
321  {
322  cmp->getProxySlot(slot, obj, proxySlot);
323  }
324 
326  static void getProxySignal(ARCSAbstractComponent* cmp, QString signal,
327  ObjectList& obj, QStringList & proxySignal)
328  {
329  cmp->getProxySignal(signal, obj, proxySignal);
330  }
331 
332 
333 
334 
335  static const QString slotPrefix;
336  static const QString signalPrefix;
337 
338 private:
339  QVariantMap properties;
340  QString family;
341  QString type;
342 
343  bool instanciated;
344 };
345 
346 
347 namespace ARCS {
357  QStringList getMethodList(const QMetaObject *object,QMetaMethod::MethodType type);
358 }
359 
360 #endif //__ARCSABSTRACTCOMPONENT_H__
361 
362 
bool instanciate()
Instanciates the real component.
void destroy()
Destroys the real component.
virtual void getProxySignal(QString signal, ObjectList &obj, QStringList &proxySignal)=0
Creates a proxy signal to interface a component to native ARCS components.
virtual QVariant getGenuineComponentInstance()
static void getProxySlot(ARCSAbstractComponent *cmp, QString slot, ObjectList &obj, QStringList &proxySlot)
Wrapper for getProxySlot()
virtual bool genuineDisconnect(QString, ARCSAbstractComponent *, QString)
This method disconnects two components by the indicated signals and slots.
virtual void getProxySlot(QString slot, ObjectList &obj, QStringList &proxySlot)=0
Creates a proxy slot to interface a component to native ARCS components.
Class handling the generic description of a component.
QStringList getMethodList(const QMetaObject *object, QMetaMethod::MethodType type)
Helper method for components.
static void getProxySignal(ARCSAbstractComponent *cmp, QString signal, ObjectList &obj, QStringList &proxySignal)
Wrapper for getProxySignal()
This namespace will contain some constant definitions.
Definition: arcs.h:38
virtual bool genuineConnect(QString, ARCSAbstractComponent *, QString, bool=false)
This method connects two components by the indicated signals and slots.
bool isInstanciated()
Determines wether the component is instanciated or not.