macOS: Improve QDebug output for QNSView and QCocoaWindow

By printing the corresponding QPlatformWindow and QWindow for a given
QNSView we make it easier to track issues regardless of which of the
views/windows are being logged.

Change-Id: I4a42eff7f87cf3c8e722cd6ad8baccd4eeab8eb3
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
bb10
Tor Arne Vestbø 2017-07-12 15:18:45 +02:00
parent 5477537327
commit 3bac08c00f
3 changed files with 42 additions and 0 deletions

View File

@ -54,6 +54,11 @@
#include "qt_mac_p.h"
QT_BEGIN_NAMESPACE
#ifndef QT_NO_DEBUG_STREAM
class QDebug;
#endif
// QCocoaWindow
//
// QCocoaWindow is an NSView (not an NSWindow!) in the sense
@ -287,6 +292,10 @@ public: // for QNSView
bool m_hasWindowFilePath;
};
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug debug, const QCocoaWindow *window);
#endif
QT_END_NAMESPACE
#endif // QCOCOAWINDOW_H

View File

@ -62,6 +62,8 @@
#include <vector>
QT_BEGIN_NAMESPACE
enum {
defaultWindowWidth = 160,
defaultWindowHeight = 160
@ -1776,4 +1778,19 @@ void QCocoaWindow::setFrameStrutEventsEnabled(bool enabled)
m_frameStrutEventsEnabled = enabled;
}
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug debug, const QCocoaWindow *window)
{
QDebugStateSaver saver(debug);
debug.nospace();
debug << "QCocoaWindow(" << (const void *)window;
if (window)
debug << ", window=" << window->window();
debug << ')';
return debug;
}
#endif // !QT_NO_DEBUG_STREAM
#include "moc_qcocoawindow.cpp"
QT_END_NAMESPACE

View File

@ -221,6 +221,22 @@ static QTouchDevice *touchDevice = 0;
return self;
}
- (NSString *)description
{
NSMutableString *description = [NSMutableString stringWithString:[super description]];
#ifndef QT_NO_DEBUG_STREAM
QString platformWindowDescription;
QDebug debug(&platformWindowDescription);
debug.nospace() << "; " << m_platformWindow << ">";
NSRange lastCharacter = [description rangeOfComposedCharacterSequenceAtIndex:description.length - 1];
[description replaceCharactersInRange:lastCharacter withString:platformWindowDescription.toNSString()];
#endif
return description;
}
#ifndef QT_NO_OPENGL
- (void) setQCocoaGLContext:(QCocoaGLContext *)context
{