00001
00002
00003
00004
00005
00006
00007 #include "Logger.h"
00008 #include <QHash>
00009 #include <QLocale>
00010 #include <QTransform>
00011 #include "QtToString.h"
00012
00013 static QHash<Qt::CursorShape, QString> cursorShapesLookupTable;
00014 static QHash<int, QString> rolesAsStringsLookupTable;
00015 static QHash<QXmlStreamReader::TokenType, QString> xmlTokenTypeLookupTable;
00016
00017 QString QPointFToString (const QPointF &pos)
00018 {
00019 QString str = QString ("(%1, %2)")
00020 .arg (pos.x ())
00021 .arg (pos.y ());
00022
00023 return str;
00024 }
00025
00026 QString QRectFToString (const QRectF &rectF)
00027 {
00028 QString str = QString ("(%1x%2+%3+%4)")
00029 .arg (rectF.width())
00030 .arg (rectF.height())
00031 .arg (rectF.x())
00032 .arg (rectF.y());
00033
00034 return str;
00035 }
00036
00037 QString QtCursorToString (Qt::CursorShape cursorShape)
00038 {
00039 if (cursorShapesLookupTable.count () == 0) {
00040
00041
00042 cursorShapesLookupTable [Qt::ArrowCursor] = "Qt::ArrowCursor";
00043 cursorShapesLookupTable [Qt::BitmapCursor] = "Qt::BitmapCursor";
00044 cursorShapesLookupTable [Qt::CrossCursor] = "Qt::CrossCursor";
00045 cursorShapesLookupTable [Qt::WaitCursor] = "Qt::WaitCursor";
00046 }
00047
00048 if (cursorShapesLookupTable.contains (cursorShape)) {
00049
00050 return cursorShapesLookupTable [cursorShape];
00051
00052 } else {
00053
00054 return "Qt::<unknown>";
00055
00056 }
00057 }
00058
00059 QString QLocaleToString (const QLocale &locale)
00060 {
00061 return QString ("%1/%2")
00062 .arg (QLocale::languageToString (locale.language()))
00063 .arg (QLocale::countryToString(locale.country()));
00064 }
00065
00066 QString QTransformToString (const QTransform &transform)
00067 {
00068 const int FIELD_WIDTH = 12;
00069
00070 QString str = QString ("%1 %2 %3 %4\n"
00071 "%5 %6 %7 %8\n"
00072 "%9 %10 %11 %12")
00073 .arg (INDENTATION_PAST_TIMESTAMP)
00074 .arg (transform.m11 (), FIELD_WIDTH)
00075 .arg (transform.m12 (), FIELD_WIDTH)
00076 .arg (transform.m13 (), FIELD_WIDTH)
00077 .arg (INDENTATION_PAST_TIMESTAMP)
00078 .arg (transform.m21 (), FIELD_WIDTH)
00079 .arg (transform.m22 (), FIELD_WIDTH)
00080 .arg (transform.m23 (), FIELD_WIDTH)
00081 .arg (INDENTATION_PAST_TIMESTAMP)
00082 .arg (transform.m31 (), FIELD_WIDTH)
00083 .arg (transform.m32 (), FIELD_WIDTH)
00084 .arg (transform.m33 (), FIELD_WIDTH);
00085
00086 return str;
00087 }
00088
00089 QString QXmlStreamReaderTokenTypeToString (QXmlStreamReader::TokenType tokenType)
00090 {
00091 if (xmlTokenTypeLookupTable.count () == 0) {
00092
00093
00094 xmlTokenTypeLookupTable [QXmlStreamReader::Characters] = "Characters";
00095 xmlTokenTypeLookupTable [QXmlStreamReader::Comment] = "Comment";
00096 xmlTokenTypeLookupTable [QXmlStreamReader::DTD] = "DTD";
00097 xmlTokenTypeLookupTable [QXmlStreamReader::EndDocument] = "EndDocument";
00098 xmlTokenTypeLookupTable [QXmlStreamReader::EndElement] = "EndElement";
00099 xmlTokenTypeLookupTable [QXmlStreamReader::EntityReference] = "EntityReference";
00100 xmlTokenTypeLookupTable [QXmlStreamReader::Invalid] = "Invalid";
00101 xmlTokenTypeLookupTable [QXmlStreamReader::NoToken] = "NoToken";
00102 xmlTokenTypeLookupTable [QXmlStreamReader::ProcessingInstruction] = "ProcessingInstruction";
00103 xmlTokenTypeLookupTable [QXmlStreamReader::StartDocument] = "StartDocument";
00104 xmlTokenTypeLookupTable [QXmlStreamReader::StartElement] = "StartElement";
00105 }
00106
00107 if (xmlTokenTypeLookupTable.contains (tokenType)) {
00108
00109 return xmlTokenTypeLookupTable [tokenType];
00110
00111 } else {
00112
00113 return "<Unknown>";
00114
00115 }
00116 }
00117
00118 QString roleAsString (int role)
00119 {
00120 if (rolesAsStringsLookupTable.count () == 0) {
00121
00122
00123 rolesAsStringsLookupTable [Qt::AccessibleDescriptionRole] = "AccessibleDescriptionRole";
00124 rolesAsStringsLookupTable [Qt::AccessibleTextRole] = "AccessibleTextRole";
00125 rolesAsStringsLookupTable [Qt::BackgroundRole] = "BackgroundRole";
00126 rolesAsStringsLookupTable [Qt::BackgroundColorRole] = "BackgroundColorRole";
00127 rolesAsStringsLookupTable [Qt::CheckStateRole] = "CheckStateRole";
00128 rolesAsStringsLookupTable [Qt::DecorationRole] = "DecorationRole";
00129 rolesAsStringsLookupTable [Qt::DisplayRole] = "DisplayRole";
00130 rolesAsStringsLookupTable [Qt::EditRole] = "EditRole";
00131 rolesAsStringsLookupTable [Qt::FontRole] = "FontRole";
00132 rolesAsStringsLookupTable [Qt::ForegroundRole] = "ForegroundRole";
00133 rolesAsStringsLookupTable [Qt::InitialSortOrderRole] = "InitialSortOrderRole";
00134 rolesAsStringsLookupTable [Qt::SizeHintRole] = "SizeHintRole";
00135 rolesAsStringsLookupTable [Qt::StatusTipRole] = "StatusTipRole";
00136 rolesAsStringsLookupTable [Qt::TextAlignmentRole] = "TextAlignmentRole";
00137 rolesAsStringsLookupTable [Qt::TextColorRole] = "TextColorRole";
00138 rolesAsStringsLookupTable [Qt::ToolTipRole] = "ToolTipRole";
00139 rolesAsStringsLookupTable [Qt::UserRole] = "UserRole";
00140 rolesAsStringsLookupTable [Qt::WhatsThisRole] = "WhatsThisRole";
00141 }
00142
00143 if (rolesAsStringsLookupTable.contains (role)) {
00144
00145 return rolesAsStringsLookupTable [role];
00146
00147 } else {
00148
00149 return QString ("%1?").arg (role);
00150
00151 }
00152 }
00153
00154 QString rolesAsString (const QVector<int> &roles)
00155 {
00156 QString str;
00157
00158 for (int i = 0; i < roles.count (); i++) {
00159 if (i > 0) {
00160 str += ",";
00161 }
00162 str += roleAsString (roles [i]);
00163 }
00164
00165 return str;
00166 }