ctkEvent.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 ctkEventData;
  23. /**
  24. * \ingroup EventAdmin
  25. *
  26. * A CTK event.
  27. *
  28. * <code>ctkEvent</code> objects are delivered to <code>ctkEventHandler</code>
  29. * or Qt slots which subscribe to the topic of the event.
  30. */
  31. class CTK_PLUGINFW_EXPORT ctkEvent
  32. {
  33. QSharedDataPointer<ctkEventData> d;
  34. public:
  35. /**
  36. * Default constructor for use with the Qt meta object system.
  37. */
  38. ctkEvent();
  39. ~ctkEvent();
  40. /**
  41. * Can be used to check if this ctkEvent instance is valid,
  42. * or if it has been constructed using the default constructor.
  43. *
  44. * @return <code>true</code> if this event object is valid,
  45. * <code>false</code> otherwise.
  46. */
  47. bool isNull() const;
  48. /**
  49. * Constructs an event.
  50. *
  51. * @param topic The topic of the event.
  52. * @param properties The event's properties (may be empty).
  53. * @throws std::invalid_argument If topic is not a valid topic name.
  54. */
  55. ctkEvent(const QString& topic, const ctkDictionary& properties = ctkDictionary());
  56. ctkEvent(const ctkEvent& event);
  57. ctkEvent& operator=(const ctkEvent& other);
  58. /**
  59. * Compares this <code>ctkEvent</code> object to another object.
  60. *
  61. * <p>
  62. * An event is considered to be <b>equal to</b> another event if the topic
  63. * is equal and the properties are equal.
  64. *
  65. * @param object The <code>ctkEvent</code> object to be compared.
  66. * @return <code>true</code> if <code>other</code> is equal to
  67. * this object; <code>false</code> otherwise.
  68. */
  69. bool operator==(const ctkEvent& other) const;
  70. /**
  71. * Retrieve the value of an event property. The event topic may be retrieved
  72. * with the property name &quot;event.topics&quot;.
  73. *
  74. * @param name the name of the property to retrieve
  75. * @return The value of the property, or an invalid QVariant if not found.
  76. */
  77. QVariant getProperty(const QString& name) const;
  78. /**
  79. * Indicate the presence of an event property. The event topic is present
  80. * using the property name &quot;event.topics&quot;.
  81. *
  82. * @param name The name of the property.
  83. * @return <code>true</code> if a property with the specified name is in the
  84. * event. This property may have an invalid QVariant value.
  85. * <code>false</code> otherwise.
  86. */
  87. bool containsProperty(const QString& name) const;
  88. /**
  89. * Returns a list of this event's property names. The list will include the
  90. * event topic property name &quot;event.topics&quot;.
  91. *
  92. * @return A non-empty list with one element per property.
  93. */
  94. QStringList getPropertyNames() const;
  95. /**
  96. * Returns the topic of this event.
  97. *
  98. * @return The topic of this event.
  99. */
  100. const QString& getTopic() const;
  101. /**
  102. * Tests this event's properties against the given filter using a case
  103. * sensitive match.
  104. *
  105. * @param filter The filter to test.
  106. * @return true If this event's properties match the filter, false
  107. * otherwise.
  108. */
  109. bool matches(const ctkLDAPSearchFilter& filter) const;
  110. };
  111. #endif // CTKEVENT_H