Przeglądaj źródła

ENH: Added virtual function fileNameToKey to ctkAbstractPluginFactory

This virtual function can be overloaded in sub-class to return an identifier
different from (or based on) the plugin filename.
Jean-Christophe Fillion-Robin 15 lat temu
rodzic
commit
2ab8172fc3

+ 8 - 1
Libs/Core/ctkAbstractPluginFactory.h

@@ -56,8 +56,15 @@ public:
   explicit ctkAbstractPluginFactory();
   virtual ~ctkAbstractPluginFactory();
 
-  /// 
+  ///
+  /// Return a name allowing to uniquely identify the plugin
+  /// By default, it return \a fileName 
+  virtual QString fileNameToKey(const QString& fileName);
+
+  ///
   /// Register a plugin in the factory
+  /// The parameter \a key passed by reference will be updated with the
+  /// associated object name obtained using ::fileNameToKey()
   virtual bool registerLibrary(const QFileInfo& file, QString& key);
 
 private:

+ 9 - 1
Libs/Core/ctkAbstractPluginFactory.tpp

@@ -92,11 +92,19 @@ ctkAbstractPluginFactory<BaseClassType, FactoryItemType>::~ctkAbstractPluginFact
 {
 }
 
+//-----------------------------------------------------------------------------
+template<typename BaseClassType, typename FactoryItemType>
+QString ctkAbstractPluginFactory<BaseClassType, FactoryItemType>::fileNameToKey(
+  const QString& fileName)
+{
+  return fileName; 
+}
+
 //----------------------------------------------------------------------------
 template<typename BaseClassType, typename FactoryItemType>
 bool ctkAbstractPluginFactory<BaseClassType, FactoryItemType>::registerLibrary(const QFileInfo& file, QString& key)
 {
-  key = file.fileName();
+  key = this->fileNameToKey(file.fileName());
   // Check if already registered
   if (this->item(key))
     {