summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2020-06-30 12:06:37 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2020-07-01 06:53:14 +0200
commit836c0b5a24f5ceb8ed7dce0129f433bf23f58c25 (patch)
treecbc0486f9f78242deff0352e5ff698c4dbe61976
parentacbe4190e9a126f48a0f7ecd6889c010ea44ce39 (diff)
Make QDebug operator<< polymorphic for QPointingDevice
At least it will look polymorphic by doing dispatch internally. Adding pointingDeviceType avoids the need for qobject_cast, and will probably also be useful in other contexts. Change-Id: I3b6d13765bdf3add9a8208de6f0e98018e40cc42 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--src/gui/kernel/qinputdevice.cpp4
-rw-r--r--src/gui/kernel/qinputdevice_p.h4
-rw-r--r--src/gui/kernel/qpointingdevice_p.h1
3 files changed, 8 insertions, 1 deletions
diff --git a/src/gui/kernel/qinputdevice.cpp b/src/gui/kernel/qinputdevice.cpp
index e70b0d61be..d64f2c4ddc 100644
--- a/src/gui/kernel/qinputdevice.cpp
+++ b/src/gui/kernel/qinputdevice.cpp
@@ -39,6 +39,7 @@
#include "qinputdevice.h"
#include "qinputdevice_p.h"
+#include "qpointingdevice.h"
#include <QCoreApplication>
#include <QDebug>
#include <QLoggingCategory>
@@ -278,6 +279,9 @@ bool QInputDevice::operator==(const QInputDevice &other) const
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug debug, const QInputDevice *device)
{
+ const QInputDevicePrivate *d = QInputDevicePrivate::get(device);
+ if (d->pointingDeviceType)
+ return operator<<(debug, static_cast<const QPointingDevice *>(device));
QDebugStateSaver saver(debug);
debug.nospace();
debug.noquote();
diff --git a/src/gui/kernel/qinputdevice_p.h b/src/gui/kernel/qinputdevice_p.h
index 899f75e7f9..3115f6bf92 100644
--- a/src/gui/kernel/qinputdevice_p.h
+++ b/src/gui/kernel/qinputdevice_p.h
@@ -64,7 +64,8 @@ public:
QInputDevicePrivate(const QString &name, qint64 id, QInputDevice::DeviceType type,
QInputDevice::Capabilities caps = QInputDevice::Capability::None,
const QString &seatName = QString())
- : name(name), seatName(seatName), id(id), capabilities(caps), deviceType(type)
+ : name(name), seatName(seatName), id(id), capabilities(caps),
+ deviceType(type), pointingDeviceType(false)
{
// if the platform doesn't provide device IDs, make one up,
// but try to avoid clashing with OS-provided 32-bit IDs
@@ -81,6 +82,7 @@ public:
qint64 id = 0;
qint32 capabilities = static_cast<qint32>(QInputDevice::Capability::None);
QInputDevice::DeviceType deviceType = QInputDevice::DeviceType::Unknown;
+ qint16 pointingDeviceType : 1; // actually bool, but pack with deviceType
static void registerDevice(const QInputDevice *dev);
static void unregisterDevice(const QInputDevice *dev);
diff --git a/src/gui/kernel/qpointingdevice_p.h b/src/gui/kernel/qpointingdevice_p.h
index 4d3cf99626..91ba0137e0 100644
--- a/src/gui/kernel/qpointingdevice_p.h
+++ b/src/gui/kernel/qpointingdevice_p.h
@@ -70,6 +70,7 @@ public:
maximumTouchPoints(qint8(maxPoints)), buttonCount(qint8(buttonCount)),
pointerType(pType)
{
+ pointingDeviceType = true;
}
void * extra = nullptr; // QPA plugins can store platform-specific stuff here