ctkEvent.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #ifndef CTKEVENT_H
  16. #define CTKEVENT_H
  17. #include "ctkPluginFrameworkExport.h"
  18. #include <QMap>
  19. #include <QVariant>
  20. #include <QStringList>
  21. #include <ctkLDAPSearchFilter.h>
  22. class ctkEventPrivate;
  23. /**
  24. * A CTK event.
  25. *
  26. * <code>ctkEvent</code> objects are delivered to <code>ctkEventHandler</code>
  27. * or Qt slots which subscribe to the topic of the event.
  28. */
  29. class CTK_PLUGINFW_EXPORT ctkEvent {
  30. public:
  31. /**
  32. * Constructs an event.
  33. *
  34. * @param topic The topic of the event.
  35. * @param properties The event's properties (may be empty).
  36. * @throws std::invalid_argument If topic is not a valid topic name.
  37. */
  38. ctkEvent(const QString& topic, const ctkDictionary& properties = ctkDictionary());
  39. ctkEvent(const ctkEvent& event);
  40. ~ctkEvent();
  41. /**
  42. * Compares this <code>ctkEvent</code> object to another object.
  43. *
  44. * <p>
  45. * An event is considered to be <b>equal to</b> another event if the topic
  46. * is equal and the properties are equal.
  47. *
  48. * @param object The <code>ctkEvent</code> object to be compared.
  49. * @return <code>true</code> if <code>other</code> is equal to
  50. * this object; <code>false</code> otherwise.
  51. */
  52. bool operator==(const ctkEvent& other) const;
  53. /**
  54. * Retrieve the value of an event property. The event topic may be retrieved
  55. * with the property name &quot;event.topics&quot;.
  56. *
  57. * @param name the name of the property to retrieve
  58. * @return The value of the property, or an invalid QVariant if not found.
  59. */
  60. QVariant getProperty(const QString& name) const;
  61. /**
  62. * Indicate the presence of an event property. The event topic is present
  63. * using the property name &quot;event.topics&quot;.
  64. *
  65. * @param name The name of the property.
  66. * @return <code>true</code> if a property with the specified name is in the
  67. * event. This property may have an invalid QVariant value.
  68. * <code>false</code> otherwise.
  69. */
  70. bool containsProperty(const QString& name) const;
  71. /**
  72. * Returns a list of this event's property names. The list will include the
  73. * event topic property name &quot;event.topics&quot;.
  74. *
  75. * @return A non-empty list with one element per property.
  76. */
  77. QStringList getPropertyNames() const;
  78. /**
  79. * Returns the topic of this event.
  80. *
  81. * @return The topic of this event.
  82. */
  83. const QString& getTopic() const;
  84. /**
  85. * Tests this event's properties against the given filter using a case
  86. * sensitive match.
  87. *
  88. * @param filter The filter to test.
  89. * @return true If this event's properties match the filter, false
  90. * otherwise.
  91. */
  92. bool matches(const ctkLDAPSearchFilter& filter) const;
  93. protected:
  94. ctkEventPrivate * const d;
  95. };
  96. #endif // CTKEVENT_H