ctkTrackedPlugin.tpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. //----------------------------------------------------------------------------
  16. template<class T>
  17. ctkTrackedPlugin<T>::ctkTrackedPlugin(ctkPluginTracker<T>* pluginTracker,
  18. ctkPluginTrackerCustomizer<T>* customizer)
  19. : pluginTracker(pluginTracker), customizer(customizer)
  20. {
  21. }
  22. //----------------------------------------------------------------------------
  23. template<class T>
  24. void ctkTrackedPlugin<T>::pluginChanged(const ctkPluginEvent& event)
  25. {
  26. /*
  27. * Check if we had a delayed call (which could happen when we
  28. * close).
  29. */
  30. if (this->closed)
  31. {
  32. return;
  33. }
  34. QSharedPointer<ctkPlugin> plugin = event.getPlugin();
  35. ctkPlugin::State state = plugin->getState();
  36. if (pluginTracker->d_func()->DEBUG)
  37. {
  38. qDebug() << "ctkTrackedPlugin<T>::pluginChanged[" << state << "]: " << *plugin;
  39. }
  40. if (pluginTracker->d_func()->mask & state)
  41. {
  42. this->track(plugin, event);
  43. /*
  44. * If the customizer throws an exception, it is safe
  45. * to let it propagate
  46. */
  47. }
  48. else
  49. {
  50. this->untrack(plugin, event);
  51. /*
  52. * If the customizer throws an exception, it is safe
  53. * to let it propagate
  54. */
  55. }
  56. }
  57. //----------------------------------------------------------------------------
  58. template<class T>
  59. T ctkTrackedPlugin<T>::customizerAdding(QSharedPointer<ctkPlugin> item,
  60. const ctkPluginEvent& related)
  61. {
  62. return customizer->addingPlugin(item, related);
  63. }
  64. //----------------------------------------------------------------------------
  65. template<class T>
  66. void ctkTrackedPlugin<T>::customizerModified(QSharedPointer<ctkPlugin> item,
  67. const ctkPluginEvent& related,
  68. T object)
  69. {
  70. customizer->modifiedPlugin(item, related, object);
  71. }
  72. //----------------------------------------------------------------------------
  73. template<class T>
  74. void ctkTrackedPlugin<T>::customizerRemoved(QSharedPointer<ctkPlugin> item,
  75. const ctkPluginEvent& related,
  76. T object)
  77. {
  78. customizer->removedPlugin(item, related, object);
  79. }