MessageHandler.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #ifndef MESSAGEHANDLER_H
  2. #define MESSAGEHANDLER_H
  3. #include <QAbstractMessageHandler>
  4. #include <GraphLayoutLibrary_global.h>
  5. /**
  6. * @brief The MessageHandler class
  7. *
  8. * The class provides helpers to handle messages. Inherited from QAbstractMessageHandler.
  9. */
  10. class GRAPHLAYOUTLIBRARYSHARED_EXPORT MessageHandler : public QAbstractMessageHandler
  11. {
  12. /* Adding subclass to QAbstractMessageHandler needs .pro file to be configured.
  13. * We need to add QT += xmlpatterns
  14. */
  15. public:
  16. /** @name Creators
  17. * The methods under this section are responsible for constructing
  18. * an instance of type MessageHandler.
  19. * Uses default constructor of QAbstractMessageHandler.
  20. */
  21. //@{
  22. /**
  23. Constructs new object of type MessageHandler.
  24. @pre none
  25. @param none
  26. @return none
  27. @throw none
  28. */
  29. MessageHandler() : QAbstractMessageHandler(0)
  30. {
  31. }
  32. //@}
  33. /** @name Queries
  34. * The methods under this section are responsible for accessing
  35. * an instance of type MessageHandler.
  36. */
  37. //@{
  38. /**
  39. This method returns the description from the messeage already written
  40. @pre none
  41. @param none
  42. @return message in string
  43. @throw none
  44. */
  45. QString getStatusMessage() const
  46. {
  47. return m_sDescription;
  48. }
  49. /**
  50. This method returns line number for the message.
  51. @pre none
  52. @param none
  53. @return line number
  54. @throw none
  55. */
  56. int getLineNumber() const
  57. {
  58. return m_sourceLocation.line();
  59. }
  60. /**
  61. This method returns colun number for the message.
  62. @pre none
  63. @param none
  64. @return column number
  65. @throw none
  66. */
  67. int getColumnNumber() const
  68. {
  69. return m_sourceLocation.column();
  70. }
  71. /**
  72. This method returns type of the message
  73. @pre none
  74. @param none
  75. @return message type in string
  76. @throw none
  77. */
  78. QtMsgType getMessageType() const
  79. {
  80. return m_messageType;
  81. }
  82. /**
  83. This method returns message id.
  84. @pre none
  85. @param none
  86. @return message id
  87. @throw none
  88. */
  89. QUrl getMessageId() const
  90. {
  91. return m_messageId;
  92. }
  93. //@}
  94. protected:
  95. /** @name Modifiers
  96. * The methods under this section are responsible for modifying
  97. * an instance of MessageHandler.
  98. */
  99. //@{
  100. /**
  101. This method handles the message and set its parameters.
  102. @pre none
  103. @param type
  104. type of message
  105. @param description
  106. message description
  107. @param identifier
  108. url identifier
  109. @param sourceLocation
  110. location for the source of message
  111. @return none
  112. @throw none
  113. */
  114. virtual void handleMessage(QtMsgType type, const QString &description,
  115. const QUrl &identifier, const QSourceLocation &sourceLocation)
  116. {
  117. Q_UNUSED(type);
  118. Q_UNUSED(identifier);
  119. m_messageType = type;
  120. m_sDescription = description;
  121. m_messageId = identifier;
  122. m_sourceLocation = sourceLocation;
  123. }
  124. //@}
  125. private:
  126. QtMsgType m_messageType; /*!< QtMsgType to store type of message to be handled. */
  127. QString m_sDescription; /*!< QString to store description of message. */
  128. QUrl m_messageId; /*!< QUrl to store message ID. */
  129. QSourceLocation m_sourceLocation; /*!< QSourceLocation to store location for the source of message. */
  130. };
  131. #endif // MESSAGEHANDLER_H