summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-12-28 08:18:39 +0100
committerMarc Mutz <marc.mutz@qt.io>2023-01-02 19:28:29 +0100
commit3d050f8f2dd53827a2a7cb594d42e60583902475 (patch)
tree8bb69d8ad3426caba86905182883b05dca634eca
parent2af5aa043da14b4b6b0d064cc59e6bfbe18231f5 (diff)
downloadqttools-3d050f8f2dd53827a2a7cb594d42e60583902475.tar.gz
Designer: port from QSharedPointer to unique_ptr
The PropertyHelper objects are never shared, so the only reason to use a shared instead of a unique pointer, apart from the code possibly predating C++11, is that the container in which they're held, QList, cannot deal with move-only types. Change the container to one that can (std::vector) and use unique_ptr instead of QSharedPointer. As a drive-by, make the createPropertyHelper() factory function return by unique_ptr directly. This removes the last user of QSharedPointer in this module, making it ready for an eventual QT_NO_SHARED_POINTER. Pick-to: 6.5 Change-Id: I7051b351c4abbd1099db46823b52b5b4b16fdab5 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
-rw-r--r--src/designer/src/components/formeditor/formwindow.cpp7
-rw-r--r--src/designer/src/lib/shared/qdesigner_propertycommand.cpp45
-rw-r--r--src/designer/src/lib/shared/qdesigner_propertycommand_p.h9
3 files changed, 32 insertions, 29 deletions
diff --git a/src/designer/src/components/formeditor/formwindow.cpp b/src/designer/src/components/formeditor/formwindow.cpp
index 2f9cc49c0..b85011508 100644
--- a/src/designer/src/components/formeditor/formwindow.cpp
+++ b/src/designer/src/components/formeditor/formwindow.cpp
@@ -1485,9 +1485,10 @@ public:
void init(QWidgetList &l, const ArrowKeyOperation &op);
protected:
- PropertyHelper *createPropertyHelper(QObject *o, SpecialProperty sp,
- QDesignerPropertySheetExtension *s, int i) const override
- { return new ArrowKeyPropertyHelper(o, sp, s, i); }
+ std::unique_ptr<PropertyHelper>
+ createPropertyHelper(QObject *o, SpecialProperty sp,
+ QDesignerPropertySheetExtension *s, int i) const override
+ { return std::make_unique<ArrowKeyPropertyHelper>(o, sp, s, i); }
QVariant mergeValue(const QVariant &newValue) override;
};
diff --git a/src/designer/src/lib/shared/qdesigner_propertycommand.cpp b/src/designer/src/lib/shared/qdesigner_propertycommand.cpp
index 4e19faedb..761024586 100644
--- a/src/designer/src/lib/shared/qdesigner_propertycommand.cpp
+++ b/src/designer/src/lib/shared/qdesigner_propertycommand.cpp
@@ -969,7 +969,7 @@ bool PropertyListCommand::add(QObject *object, const QString &propertyName)
const PropertyDescription description(propertyName, sheet, index);
- if (m_propertyHelperList.isEmpty()) {
+ if (m_propertyHelperList.empty()) {
// first entry
m_propertyDescription = description;
} else {
@@ -979,21 +979,22 @@ bool PropertyListCommand::add(QObject *object, const QString &propertyName)
return false;
}
- const PropertyHelperPtr ph(createPropertyHelper(object, m_propertyDescription.m_specialProperty, sheet, index));
- m_propertyHelperList.push_back(ph);
+ auto ph = createPropertyHelper(object, m_propertyDescription.m_specialProperty, sheet, index);
+ m_propertyHelperList.push_back(std::move(ph));
return true;
}
-PropertyHelper *PropertyListCommand::createPropertyHelper(QObject *object, SpecialProperty sp,
- QDesignerPropertySheetExtension *sheet, int sheetIndex) const
+std::unique_ptr<PropertyHelper>
+PropertyListCommand::createPropertyHelper(QObject *object, SpecialProperty sp,
+ QDesignerPropertySheetExtension *sheet, int sheetIndex) const
{
- return new PropertyHelper(object, sp, sheet, sheetIndex);
+ return std::make_unique<PropertyHelper>(object, sp, sheet, sheetIndex);
}
// Init from a list and make sure referenceObject is added first to obtain the right property group
bool PropertyListCommand::initList(const QObjectList &list, const QString &apropertyName, QObject *referenceObject)
{
- propertyHelperList().clear();
+ m_propertyHelperList.clear();
// Ensure the referenceObject (property editor) is first, so the right property group is chosen.
if (referenceObject) {
@@ -1005,26 +1006,26 @@ bool PropertyListCommand::initList(const QObjectList &list, const QString &aprop
add(o, apropertyName);
}
- return !propertyHelperList().isEmpty();
+ return !m_propertyHelperList.empty();
}
QObject* PropertyListCommand::object(int index) const
{
- Q_ASSERT(index < m_propertyHelperList.size());
- return m_propertyHelperList.at(index)->object();
+ Q_ASSERT(size_t(index) < m_propertyHelperList.size());
+ return m_propertyHelperList[index]->object();
}
QVariant PropertyListCommand::oldValue(int index) const
{
- Q_ASSERT(index < m_propertyHelperList.size());
- return m_propertyHelperList.at(index)->oldValue();
+ Q_ASSERT(size_t(index) < m_propertyHelperList.size());
+ return m_propertyHelperList[index]->oldValue();
}
void PropertyListCommand::setOldValue(const QVariant &oldValue, int index)
{
- Q_ASSERT(index < m_propertyHelperList.size());
- m_propertyHelperList.at(index)->setOldValue(oldValue);
+ Q_ASSERT(size_t(index) < m_propertyHelperList.size());
+ m_propertyHelperList[index]->setOldValue(oldValue);
}
// ----- SetValueFunction: Set a new value when applied to a PropertyHelper.
class SetValueFunction {
@@ -1084,7 +1085,7 @@ template <class PropertyListIterator, class Function>
bool updatedPropertyEditor = false;
for (PropertyListIterator it = begin; it != end; ++it) {
- PropertyHelper *ph = it->data();
+ PropertyHelper *ph = it->get();
if (QObject* object = ph->object()) { // Might have been deleted in the meantime
const PropertyHelper::Value newValue = function( *ph );
updateMask |= ph->updateMask();
@@ -1165,10 +1166,10 @@ void PropertyListCommand::undo()
// check if lists are aequivalent for command merging (same widgets and props)
bool PropertyListCommand::canMergeLists(const PropertyHelperList& other) const
{
- if (m_propertyHelperList.size() != other.size())
+ if (m_propertyHelperList.size() != other.size())
return false;
- for (qsizetype i = 0; i < m_propertyHelperList.size(); ++i) {
- if (!m_propertyHelperList.at(i)->canMerge(*other.at(i)))
+ for (size_t i = 0; i < m_propertyHelperList.size(); ++i) {
+ if (!m_propertyHelperList[i]->canMerge(*other[i]))
return false;
}
return true;
@@ -1234,9 +1235,9 @@ void SetPropertyCommand::setDescription()
{
if (propertyHelperList().size() == 1) {
setText(QApplication::translate("Command", "Changed '%1' of '%2'")
- .arg(propertyName(), propertyHelperList().at(0)->object()->objectName()));
+ .arg(propertyName(), propertyHelperList().front()->object()->objectName()));
} else {
- int count = propertyHelperList().size();
+ int count = static_cast<int>(propertyHelperList().size());
setText(QCoreApplication::translate("Command", "Changed '%1' of %n objects", "", count).arg(propertyName()));
}
}
@@ -1334,9 +1335,9 @@ void ResetPropertyCommand::setDescription()
{
if (propertyHelperList().size() == 1) {
setText(QCoreApplication::translate("Command", "Reset '%1' of '%2'")
- .arg(propertyName(), propertyHelperList().at(0)->object()->objectName()));
+ .arg(propertyName(), propertyHelperList().front()->object()->objectName()));
} else {
- int count = propertyHelperList().size();
+ int count = static_cast<int>(propertyHelperList().size());
setText(QCoreApplication::translate("Command", "Reset '%1' of %n objects", "", count).arg(propertyName()));
}
}
diff --git a/src/designer/src/lib/shared/qdesigner_propertycommand_p.h b/src/designer/src/lib/shared/qdesigner_propertycommand_p.h
index 8a335c590..b36e3b199 100644
--- a/src/designer/src/lib/shared/qdesigner_propertycommand_p.h
+++ b/src/designer/src/lib/shared/qdesigner_propertycommand_p.h
@@ -123,8 +123,8 @@ public:
void undo() override;
protected:
- using PropertyHelperPtr = QSharedPointer<PropertyHelper>;
- using PropertyHelperList = QList<PropertyHelperPtr>;
+ using PropertyHelperPtr = std::unique_ptr<PropertyHelper>;
+ using PropertyHelperList = std::vector<PropertyHelperPtr>;
// add an object
bool add(QObject *object, const QString &propertyName);
@@ -169,8 +169,9 @@ protected:
const PropertyDescription &propertyDescription() const { return m_propertyDescription; }
protected:
- virtual PropertyHelper *createPropertyHelper(QObject *o, SpecialProperty sp,
- QDesignerPropertySheetExtension *sheet, int sheetIndex) const;
+ virtual std::unique_ptr<PropertyHelper>
+ createPropertyHelper(QObject *o, SpecialProperty sp,
+ QDesignerPropertySheetExtension *sheet, int sheetIndex) const;
private:
PropertyDescription m_propertyDescription;