00001 /*************************************************************************** 00002 ** 00003 ** This file is part of SciFigs. 00004 ** 00005 ** This library is free software; you can redistribute it and/or 00006 ** modify it under the terms of the GNU Lesser General Public 00007 ** License as published by the Free Software Foundation; either 00008 ** version 2.1 of the License, or (at your option) any later version. 00009 ** 00010 ** This file is distributed in the hope that it will be useful, but WITHOUT 00011 ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00013 ** License for more details. 00014 ** 00015 ** You should have received a copy of the GNU Lesser General Public 00016 ** License along with this library; if not, write to the Free Software 00017 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 ** 00019 ** See http://www.geopsy.org for more information. 00020 ** 00021 ** Created : 2008-11-03 00022 ** Authors : 00023 ** Marc Wathelet 00024 ** Marc Wathelet (LGIT, Grenoble, France) 00025 ** 00026 ***************************************************************************/ 00027 00028 #ifndef GRAPHICOBJECTFACTORY_H 00029 #define GRAPHICOBJECTFACTORY_H 00030 00031 #include <QGpCoreTools.h> 00032 00033 #include "SciFigsDLLExport.h" 00034 #include "GraphicObject.h" 00035 00036 namespace SciFigs { 00037 00038 #define REGISTER_GRAPHICOBJECT(_className_, _tagName_, \ 00039 _userName_, _menuTitle_, \ 00040 _shortcut_, _toolTip_) \ 00041 XMLREGISTER_HEAD(GraphicObjectFactory, GraphicObjectCreator, _className_, _tagName_) \ 00042 virtual QString userName() const {return _userName_;} \ 00043 virtual QString menuTitle() const {return _menuTitle_;} \ 00044 virtual QString shortcut() const {return _shortcut_;} \ 00045 virtual QString toolTip() const {return _toolTip_;} \ 00046 virtual QIcon icon() const {return QIcon(":/images/" # _className_ ".png");} \ 00047 virtual QString tagName() const {return _tagName_;} \ 00048 XMLREGISTER_TAIL(_className_) 00049 00050 class GraphicObjectFactory; 00051 00052 class SCIFIGS_EXPORT GraphicObjectCreator : public XMLClassCreator 00053 { 00054 public: 00055 virtual QString userName() const=0; 00056 virtual QString menuTitle() const=0; 00057 virtual QString shortcut() const=0; 00058 virtual QString toolTip() const=0; 00059 virtual QIcon icon() const=0; 00060 virtual QString tagName() const=0; 00061 }; 00062 00063 class SCIFIGS_EXPORT GraphicObjectFactory : public XMLClassFactory 00064 { 00065 public: 00066 inline GraphicObject * create(int id) const; 00067 inline GraphicObject * create(const QString& tag) const; 00068 inline GraphicObjectCreator * creator(const QString& tag) const; 00069 00070 static void init(); 00071 static GraphicObjectFactory * instance() {init(); return _self;} 00072 private: 00073 static GraphicObjectFactory * _self; 00074 }; 00075 00076 inline GraphicObject * GraphicObjectFactory::create(int id) const 00077 { 00078 return static_cast<GraphicObject *>(XMLClassFactory::create(id)); 00079 } 00080 00081 inline GraphicObject * GraphicObjectFactory::create(const QString& tag) const 00082 { 00083 return static_cast<GraphicObject *>(XMLClassFactory::create(tag)); 00084 } 00085 00086 inline GraphicObjectCreator * GraphicObjectFactory::creator(const QString& tag) const 00087 { 00088 return static_cast<GraphicObjectCreator *>(XMLClassFactory::creator(tag)); 00089 } 00090 00091 } // namespace SciFigs 00092 00093 #endif // GRAPHICOBJECTFACTORY_H