Qt 4.8
Public Functions | Protected Functions | Private Types | Private Functions | Properties | List of all members
QPatternist::ColoringMessageHandler Class Reference

#include <qcoloringmessagehandler_p.h>

Inheritance diagram for QPatternist::ColoringMessageHandler:
QAbstractMessageHandler QPatternist::ColorOutput QObject

Public Functions

 ColoringMessageHandler (QObject *parent=0)
 
- Public Functions inherited from QAbstractMessageHandler
void message (QtMsgType type, const QString &description, const QUrl &identifier=QUrl(), const QSourceLocation &sourceLocation=QSourceLocation())
 Sends a message to this message handler. More...
 
 QAbstractMessageHandler (QObject *parent=0)
 Constructs a QAbstractMessageHandler. More...
 
virtual ~QAbstractMessageHandler ()
 Destructs this QAbstractMessageHandler. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

virtual void handleMessage (QtMsgType type, const QString &description, const QUrl &identifier, const QSourceLocation &sourceLocation)
 This function must be implemented by the sub-class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Private Types

enum  ColorType {
  RunningText, Location, ErrorCode, Keyword,
  Data
}
 
- Private Types inherited from QPatternist::ColorOutput
typedef QFlags< ColorCodeComponentColorCode
 
enum  ColorCodeComponent {
  BlackForeground = 1 << ForegroundShift, BlueForeground = 2 << ForegroundShift, GreenForeground = 3 << ForegroundShift, CyanForeground = 4 << ForegroundShift,
  RedForeground = 5 << ForegroundShift, PurpleForeground = 6 << ForegroundShift, BrownForeground = 7 << ForegroundShift, LightGrayForeground = 8 << ForegroundShift,
  DarkGrayForeground = 9 << ForegroundShift, LightBlueForeground = 10 << ForegroundShift, LightGreenForeground = 11 << ForegroundShift, LightCyanForeground = 12 << ForegroundShift,
  LightRedForeground = 13 << ForegroundShift, LightPurpleForeground = 14 << ForegroundShift, YellowForeground = 15 << ForegroundShift, WhiteForeground = 16 << ForegroundShift,
  BlackBackground = 1 << BackgroundShift, BlueBackground = 2 << BackgroundShift, GreenBackground = 3 << BackgroundShift, CyanBackground = 4 << BackgroundShift,
  RedBackground = 5 << BackgroundShift, PurpleBackground = 6 << BackgroundShift, BrownBackground = 7 << BackgroundShift, DefaultColor = 1 << SpecialShift
}
 
typedef QHash< int, ColorCodeColorMapping
 

Private Functions

QString colorifyDescription (const QString &in) const
 
- Private Functions inherited from QPatternist::ColorOutput
QString colorify (const QString &message, int color=-1) const
 Treats message and colorID identically to write(), but instead of writing message to stderr, it is prepared for being written to stderr, but is then returned. More...
 
ColorMapping colorMapping () const
 Returns the color mappings in use. More...
 
 ColorOutput ()
 Constructs a ColorOutput instance, ready for use. More...
 
void insertMapping (int colorID, const ColorCode colorCode)
 Adds a color mapping from colorID to colorCode, for this ColorOutput instance. More...
 
void setColorMapping (const ColorMapping &cMapping)
 Sets the color mapping to be cMapping. More...
 
void write (const QString &message, int color=-1)
 Sends message to stderr, using the color looked up in colorMapping() using colorID. More...
 
void writeUncolored (const QString &message)
 Writes message to stderr as if for instance QTextStream would have been used, and adds a line ending at the end. More...
 
 ~ColorOutput ()
 Destructs this ColorOutput instance. More...
 

Properties

QHash< QString, ColorTypem_classToColor
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 66 of file qcoloringmessagehandler_p.h.

Enumerations

◆ ColorType

Constructors and Destructors

◆ ColoringMessageHandler()

ColoringMessageHandler::ColoringMessageHandler ( QObject parent = 0)

Definition at line 51 of file qcoloringmessagehandler.cpp.

51  : QAbstractMessageHandler(parent)
52 {
53  m_classToColor.insert(QLatin1String("XQuery-data"), Data);
54  m_classToColor.insert(QLatin1String("XQuery-expression"), Keyword);
55  m_classToColor.insert(QLatin1String("XQuery-function"), Keyword);
56  m_classToColor.insert(QLatin1String("XQuery-keyword"), Keyword);
57  m_classToColor.insert(QLatin1String("XQuery-type"), Keyword);
58  m_classToColor.insert(QLatin1String("XQuery-uri"), Data);
59  m_classToColor.insert(QLatin1String("XQuery-filepath"), Data);
60 
61  /* If you're tuning the colors, take it easy laddie. Take into account:
62  *
63  * - Get over your own taste, there's others too on this planet
64  * - Make sure it works well on black & white
65  * - Make sure it works well on white & black
66  */
72 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
void insertMapping(int colorID, const ColorCode colorCode)
Adds a color mapping from colorID to colorCode, for this ColorOutput instance.
QHash< QString, ColorType > m_classToColor
QAbstractMessageHandler(QObject *parent=0)
Constructs a QAbstractMessageHandler.

Functions

◆ colorifyDescription()

QString ColoringMessageHandler::colorifyDescription ( const QString in) const
private

Definition at line 149 of file qcoloringmessagehandler.cpp.

Referenced by handleMessage().

150 {
151  QXmlStreamReader reader(in);
152  QString result;
153  result.reserve(in.size());
154  ColorType currentColor = RunningText;
155 
156  while(!reader.atEnd())
157  {
158  reader.readNext();
159 
160  switch(reader.tokenType())
161  {
163  {
164  if(reader.name() == QLatin1String("span"))
165  {
166  Q_ASSERT(m_classToColor.contains(reader.attributes().value(QLatin1String("class")).toString()));
167  currentColor = m_classToColor.value(reader.attributes().value(QLatin1String("class")).toString());
168  }
169 
170  continue;
171  }
173  {
174  result.append(colorify(reader.text().toString(), currentColor));
175  continue;
176  }
178  {
179  currentColor = RunningText;
180  continue;
181  }
182  /* Fallthrough, */
184  /* Fallthrough, */
186  continue;
187  default:
188  Q_ASSERT_X(false, Q_FUNC_INFO,
189  "Unexpected node.");
190  }
191  }
192 
193  Q_ASSERT_X(!reader.hasError(), Q_FUNC_INFO,
194  "The output from Patternist must be well-formed.");
195  return result;
196 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QString colorify(const QString &message, int color=-1) const
Treats message and colorID identically to write(), but instead of writing message to stderr...
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
QHash< QString, ColorType > m_classToColor
QString & append(QChar c)
Definition: qstring.cpp:1777
The QXmlStreamReader class provides a fast parser for reading well-formed XML via a simple streaming ...
Definition: qxmlstream.h:290
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ handleMessage()

void ColoringMessageHandler::handleMessage ( QtMsgType  type,
const QString description,
const QUrl identifier,
const QSourceLocation sourceLocation 
)
protectedvirtual

This function must be implemented by the sub-class.

message() will call this function, passing in its parameters, type, description, identifier and sourceLocation unmodified.

Implements QAbstractMessageHandler.

Definition at line 74 of file qcoloringmessagehandler.cpp.

78 {
79  const bool hasLine = sourceLocation.line() != -1;
80 
81  switch(type)
82  {
83  case QtWarningMsg:
84  {
85  if(hasLine)
86  {
87  writeUncolored(QXmlPatternistCLI::tr("Warning in %1, at line %2, column %3: %4").arg(QString::fromLatin1(sourceLocation.uri().toEncoded()),
88  QString::number(sourceLocation.line()),
89  QString::number(sourceLocation.column()),
90  colorifyDescription(description)));
91  }
92  else
93  {
94  writeUncolored(QXmlPatternistCLI::tr("Warning in %1: %2").arg(QString::fromLatin1(sourceLocation.uri().toEncoded()),
95  colorifyDescription(description)));
96  }
97 
98  break;
99  }
100  case QtFatalMsg:
101  {
102  const QString errorCode(identifier.fragment());
103  Q_ASSERT(!errorCode.isEmpty());
104  QUrl uri(identifier);
105  uri.setFragment(QString());
106 
108 
109  if(sourceLocation.isNull())
110  location = QXmlPatternistCLI::tr("Unknown location");
111  else
112  location = QString::fromLatin1(sourceLocation.uri().toEncoded());
113 
114  QString errorId;
115  /* If it's a standard error code, we don't want to output the
116  * whole URI. */
117  if(uri.toString() == QLatin1String("http://www.w3.org/2005/xqt-errors"))
118  errorId = errorCode;
119  else
120  errorId = QString::fromLatin1(identifier.toEncoded());
121 
122  if(hasLine)
123  {
124  writeUncolored(QXmlPatternistCLI::tr("Error %1 in %2, at line %3, column %4: %5").arg(colorify(errorId, ErrorCode),
125  colorify(location, Location),
126  colorify(QString::number(sourceLocation.line()), Location),
127  colorify(QString::number(sourceLocation.column()), Location),
128  colorifyDescription(description)));
129  }
130  else
131  {
132  writeUncolored(QXmlPatternistCLI::tr("Error %1 in %2: %3").arg(colorify(errorId, ErrorCode),
133  colorify(location, Location),
134  colorifyDescription(description)));
135  }
136  break;
137  }
138  case QtCriticalMsg:
139  /* Fallthrough. */
140  case QtDebugMsg:
141  {
142  Q_ASSERT_X(false, Q_FUNC_INFO,
143  "message() is not supposed to receive QtCriticalMsg or QtDebugMsg.");
144  return;
145  }
146  }
147 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
qint64 line() const
Returns the current line number.
int type
Definition: qmetatype.cpp:239
void writeUncolored(const QString &message)
Writes message to stderr as if for instance QTextStream would have been used, and adds a line ending ...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QString colorifyDescription(const QString &in) const
QString fragment() const
Returns the fragment of the URL.
Definition: qurl.cpp:5687
QString colorify(const QString &message, int color=-1) const
Treats message and colorID identically to write(), but instead of writing message to stderr...
QUrl uri() const
Returns the resource that this QSourceLocation refers to.
bool isNull() const
Returns true if this QSourceLocation doesn&#39;t identify anything.
QByteArray toEncoded(FormattingOptions options=None) const
Returns the encoded representation of the URL if it&#39;s valid; otherwise an empty QByteArray is returne...
Definition: qurl.cpp:5949
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
static QTestResult::TestLocation location
Definition: qtestresult.cpp:63
qint64 column() const
Returns the current column number.
#define Q_FUNC_INFO
Definition: qglobal.h:1871

Properties

◆ m_classToColor

QHash<QString, ColorType> QPatternist::ColoringMessageHandler::m_classToColor
private

Definition at line 90 of file qcoloringmessagehandler_p.h.

Referenced by colorifyDescription(), and ColoringMessageHandler().


The documentation for this class was generated from the following files: