From b52c0dafd826d8bf1b769484260e0ca387d10929 Mon Sep 17 00:00:00 2001 From: Dheerendra Purohit Date: Fri, 6 Jun 2025 16:47:02 +0530 Subject: [PATCH] Doc: Modernize QSharedDataPointer Example for Rule of Compliance Replaced the manually defined copy constructor with = default to improve clarity and maintainability.Added a default copy assignment operator to ensure consistency,as copy constructor and copy assignment should be defined as a pair.Also included defaulted move constructor and move assignment operator in accordance with the rule of 6,ensuring the example is modern,complete,and suitable for educational purposes. Fixes: QTBUG-111392 Change-Id: Ia7cfccfc46182d8d9102868fc93dc0ebd9649a32 Reviewed-by: Axel Spoerl --- .../doc/snippets/sharedemployee/employee.h | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/corelib/doc/snippets/sharedemployee/employee.h b/src/corelib/doc/snippets/sharedemployee/employee.h index c44f71499e0..28f68887caf 100644 --- a/src/corelib/doc/snippets/sharedemployee/employee.h +++ b/src/corelib/doc/snippets/sharedemployee/employee.h @@ -6,15 +6,16 @@ //! [0] #include +#include #include class EmployeeData : public QSharedData { - public: - EmployeeData() : id(-1) { } +public: + EmployeeData() : id(-1) {} EmployeeData(const EmployeeData &other) - : QSharedData(other), id(other.id), name(other.name) { } - ~EmployeeData() { } + : QSharedData(other), id(other.id), name(other.name) {} + ~EmployeeData() = default; int id; QString name; @@ -22,34 +23,38 @@ class EmployeeData : public QSharedData class Employee { - public: -//! [1] +public: + //! [1] Employee() { d = new EmployeeData; } -//! [1] //! [2] + //! [1] //! [2] Employee(int id, const QString &name) { d = new EmployeeData; setId(id); setName(name); } -//! [2] //! [7] - Employee(const Employee &other) - : d (other.d) - { - } -//! [7] -//! [3] + //! [2] //! [7] + Employee(const Employee &other) = default; + Employee &operator=(const Employee &other) = default; + + Employee(Employee &&other) = default; + Employee &operator=(Employee &&other) = default; + + ~Employee() = default; + + //! [7] + //! [3] void setId(int id) { d->id = id; } -//! [3] //! [4] + //! [3] //! [4] void setName(const QString &name) { d->name = name; } -//! [4] + //! [4] -//! [5] + //! [5] int id() const { return d->id; } -//! [5] //! [6] + //! [5] //! [6] QString name() const { return d->name; } -//! [6] + //! [6] - private: +private: QSharedDataPointer d; }; //! [0]