Address API review comments for QInput/QPointingDevice

- Give default constructor an optional parent, as is standard for QObjects
- remove default for QObject parent from inheritance constructor
- make QPointingDeviceUniqueId comparison inline, remove superfluous
inline of hidden friends
- mark read only properties as CONSTANT
- remove bit-size from enum types; they are stored in the private,
and there are just a few instances; no need to save a few bytes at the
expense of performance and code cleanliness

Change-Id: Ie7d4a587362714e9d3bc41447cef786bbdb382c6
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
bb10
Volker Hilsheimer 2020-11-02 14:58:31 +01:00
parent a31dde22db
commit 742de50c5e
6 changed files with 27 additions and 37 deletions

View File

@ -5327,14 +5327,6 @@ qint64 QPointingDeviceUniqueId::numericId() const noexcept
(\c true) or not (\c false).
*/
/*!
\internal
*/
bool QPointingDeviceUniqueId::equals(QPointingDeviceUniqueId other) const noexcept
{
return numericId() == other.numericId();
}
/*!
\relates QPointingDeviceUniqueId
\since 5.8

View File

@ -129,10 +129,10 @@ Q_DECLARE_LOGGING_CATEGORY(lcQpaInputDevices)
*/
/*!
Creates a new invalid input device instance.
Creates a new invalid input device instance as a child of \a parent.
*/
QInputDevice::QInputDevice()
: QObject(*(new QInputDevicePrivate(QString(), -1, QInputDevice::DeviceType::Unknown)), nullptr)
QInputDevice::QInputDevice(QObject *parent)
: QObject(*(new QInputDevicePrivate(QString(), -1, QInputDevice::DeviceType::Unknown)), parent)
{
}

View File

@ -61,7 +61,7 @@ class Q_GUI_EXPORT QInputDevice : public QObject
Q_PROPERTY(QRect availableVirtualGeometry READ availableVirtualGeometry NOTIFY availableVirtualGeometryChanged)
public:
enum class DeviceType : qint16 {
enum class DeviceType {
Unknown = 0x0000,
Mouse = 0x0001,
TouchScreen = 0x0002,
@ -70,12 +70,12 @@ public:
Stylus = 0x0010,
Airbrush = 0x0020,
Keyboard = 0x1000,
AllDevices = 0x7FFF
AllDevices = 0x7FFFFFFF
};
Q_DECLARE_FLAGS(DeviceTypes, DeviceType)
Q_FLAG(DeviceTypes)
enum class Capability : qint32 {
enum class Capability {
None = 0,
Position = 0x0001,
Area = 0x0002,
@ -95,7 +95,7 @@ public:
Q_DECLARE_FLAGS(Capabilities, Capability)
Q_FLAG(Capabilities)
QInputDevice();
QInputDevice(QObject *parent = nullptr);
~QInputDevice();
QInputDevice(const QString &name, qint64 systemId, DeviceType type,
const QString &seatName = QString(), QObject *parent = nullptr);
@ -117,7 +117,7 @@ Q_SIGNALS:
void availableVirtualGeometryChanged(QRect area);
protected:
QInputDevice(QInputDevicePrivate &d, QObject *parent = nullptr);
QInputDevice(QInputDevicePrivate &d, QObject *parent);
Q_DISABLE_COPY_MOVE(QInputDevice)
};

View File

@ -65,7 +65,7 @@ public:
QInputDevice::Capabilities caps = QInputDevice::Capability::None,
const QString &seatName = QString())
: name(name), seatName(seatName), systemId(winSysId), capabilities(caps),
deviceType(type), pointingDeviceType(false)
deviceType(type)
{
// if the platform doesn't provide device IDs, make one up,
// but try to avoid clashing with OS-provided 32-bit IDs
@ -80,9 +80,9 @@ public:
QRect availableVirtualGeometry;
void *qqExtra = nullptr; // Qt Quick can store arbitrary device-specific data here
qint64 systemId = 0;
qint32 capabilities = static_cast<qint32>(QInputDevice::Capability::None);
QInputDevice::Capabilities capabilities = QInputDevice::Capability::None;
QInputDevice::DeviceType deviceType = QInputDevice::DeviceType::Unknown;
qint16 pointingDeviceType : 1; // actually bool, but pack with deviceType
bool pointingDeviceType = false;
static void registerDevice(const QInputDevice *dev);
static void unregisterDevice(const QInputDevice *dev);
@ -95,7 +95,7 @@ public:
return;
availableVirtualGeometry = a;
capabilities |= qint32(QInputDevice::Capability::NormalizedPosition);
capabilities |= QInputDevice::Capability::NormalizedPosition;
Q_Q(QInputDevice);
Q_EMIT q->availableVirtualGeometryChanged(availableVirtualGeometry);
}

View File

@ -144,12 +144,12 @@ Q_DECLARE_LOGGING_CATEGORY(lcPointerGrab)
*/
/*!
Creates a new invalid pointing device instance.
Creates a new invalid pointing device instance as a child of \a parent.
*/
QPointingDevice::QPointingDevice()
QPointingDevice::QPointingDevice(QObject *parent)
: QInputDevice(*(new QPointingDevicePrivate(QLatin1String("unknown"), -1,
DeviceType::Unknown, PointerType::Unknown,
Capability::None, 0, 0)))
Capability::None, 0, 0)), parent)
{
}

View File

@ -69,12 +69,10 @@ public:
qint64 numericId() const noexcept;
private:
bool equals(QPointingDeviceUniqueId other) const noexcept;
friend inline bool operator==(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept
{ return lhs.equals(rhs); }
friend inline bool operator!=(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept
{ return !operator==(lhs, rhs); }
friend bool operator==(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept
{ return lhs.numericId() == rhs.numericId(); }
friend bool operator!=(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept
{ return lhs.numericId() != rhs.numericId(); }
// TODO: for TUIO 2, or any other type of complex token ID, an internal
// array (or hash) can be added to hold additional properties.
@ -89,13 +87,13 @@ class Q_GUI_EXPORT QPointingDevice : public QInputDevice
{
Q_OBJECT
Q_DECLARE_PRIVATE(QPointingDevice)
Q_PROPERTY(PointerType pointerType READ pointerType)
Q_PROPERTY(int maximumPoints READ maximumPoints)
Q_PROPERTY(int buttonCount READ buttonCount)
Q_PROPERTY(QPointingDeviceUniqueId uniqueId READ uniqueId)
Q_PROPERTY(PointerType pointerType READ pointerType CONSTANT)
Q_PROPERTY(int maximumPoints READ maximumPoints CONSTANT)
Q_PROPERTY(int buttonCount READ buttonCount CONSTANT)
Q_PROPERTY(QPointingDeviceUniqueId uniqueId READ uniqueId CONSTANT)
public:
enum class PointerType : qint16 {
enum class PointerType {
Unknown = 0,
Generic = 0x0001, // mouse or similar
Finger = 0x0002, // touchscreen or pad
@ -107,7 +105,7 @@ public:
Q_DECLARE_FLAGS(PointerTypes, PointerType)
Q_FLAG(PointerTypes)
enum GrabTransition : quint8 {
enum GrabTransition {
GrabPassive = 0x01,
UngrabPassive = 0x02,
CancelGrabPassive = 0x03,
@ -118,7 +116,7 @@ public:
};
Q_ENUM(GrabTransition)
QPointingDevice();
QPointingDevice(QObject *parent = nullptr);
~QPointingDevice();
QPointingDevice(const QString &name, qint64 systemId, QInputDevice::DeviceType devType,
PointerType pType, Capabilities caps, int maxPoints, int buttonCount,
@ -148,7 +146,7 @@ Q_SIGNALS:
void grabChanged(QObject *grabber, GrabTransition transition, const QPointerEvent *event, const QEventPoint &point) const;
protected:
QPointingDevice(QPointingDevicePrivate &d, QObject *parent = nullptr);
QPointingDevice(QPointingDevicePrivate &d, QObject *parent);
Q_DISABLE_COPY_MOVE(QPointingDevice)
};