From c22d6b501b5f09da05a7c05373ba4afbfbed5c73 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 1 Feb 2024 17:04:09 +0100 Subject: [PATCH] ClassView: Replace QSharedPointer with std::shared_ptr According to https://wiki.qt.io/Things_To_Look_Out_For_In_Reviews QSharedPointer impl is poor and it's going to be removed from Qt 7. Change-Id: I46a556c6ab558b4b86c7f9d767cac5b16302f326 Reviewed-by: hjk --- src/plugins/classview/classviewmanager.cpp | 16 ++++++++-------- src/plugins/classview/classviewmanager.h | 3 +-- .../classview/classviewnavigationwidget.cpp | 8 ++++---- .../classview/classviewnavigationwidget.h | 3 +-- src/plugins/classview/classviewparser.cpp | 8 ++++---- .../classview/classviewparsertreeitem.cpp | 18 +++++++++--------- .../classview/classviewparsertreeitem.h | 4 +--- 7 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/plugins/classview/classviewmanager.cpp b/src/plugins/classview/classviewmanager.cpp index 522b039a5bd..9f62de9e09a 100644 --- a/src/plugins/classview/classviewmanager.cpp +++ b/src/plugins/classview/classviewmanager.cpp @@ -47,7 +47,7 @@ static Manager *managerInstance = nullptr; */ /*! - \fn void ClassView::Internal::Manager::treeDataUpdate(QSharedPointer result) + \fn void ClassView::Internal::Manager::treeDataUpdate(std::shared_ptr result) Emits a signal about a tree data update (to tree view). \a result holds the item with the current tree. @@ -128,7 +128,7 @@ ParserTreeItem::ConstPtr ManagerPrivate::findItemByRoot(const QStandardItem *ite uiList.removeLast(); const SymbolInformation &inf = Internal::symbolInformationFromItem(cur); internal = internal->child(inf); - if (internal.isNull()) + if (!internal) break; } @@ -147,7 +147,7 @@ Manager::Manager(QObject *parent) managerInstance = this; // register - to be able send between signal/slots - qRegisterMetaType >("QSharedPointer"); + qRegisterMetaType>("std::shared_ptr"); initialize(); @@ -174,7 +174,7 @@ Manager *Manager::instance() bool Manager::canFetchMore(QStandardItem *item, bool skipRoot) const { ParserTreeItem::ConstPtr ptr = d->findItemByRoot(item, skipRoot); - if (ptr.isNull()) + if (!ptr) return false; return ptr->canFetchMore(item); } @@ -186,7 +186,7 @@ bool Manager::canFetchMore(QStandardItem *item, bool skipRoot) const void Manager::fetchMore(QStandardItem *item, bool skipRoot) { ParserTreeItem::ConstPtr ptr = d->findItemByRoot(item, skipRoot); - if (ptr.isNull()) + if (!ptr) return; ptr->fetchMore(item); } @@ -194,7 +194,7 @@ void Manager::fetchMore(QStandardItem *item, bool skipRoot) bool Manager::hasChildren(QStandardItem *item) const { ParserTreeItem::ConstPtr ptr = d->findItemByRoot(item); - if (ptr.isNull()) + if (!ptr) return false; return ptr->childCount(); } @@ -255,8 +255,8 @@ void Manager::initialize() if (!state()) return; - QSharedPointer rootItem(new QStandardItem()); - d->m_root->fetchMore(rootItem.data()); + std::shared_ptr rootItem(new QStandardItem()); + d->m_root->fetchMore(rootItem.get()); emit treeDataUpdate(rootItem); }, Qt::QueuedConnection); diff --git a/src/plugins/classview/classviewmanager.h b/src/plugins/classview/classviewmanager.h index a9bebc7a342..0df20995270 100644 --- a/src/plugins/classview/classviewmanager.h +++ b/src/plugins/classview/classviewmanager.h @@ -4,7 +4,6 @@ #pragma once #include -#include #include namespace Utils { class FilePath; } @@ -32,7 +31,7 @@ public: void onWidgetVisibilityIsChanged(bool visibility); signals: - void treeDataUpdate(QSharedPointer result); + void treeDataUpdate(std::shared_ptr result); private: void initialize(); diff --git a/src/plugins/classview/classviewnavigationwidget.cpp b/src/plugins/classview/classviewnavigationwidget.cpp index 22ae6e2bb7d..9a7b57d767a 100644 --- a/src/plugins/classview/classviewnavigationwidget.cpp +++ b/src/plugins/classview/classviewnavigationwidget.cpp @@ -211,9 +211,9 @@ void NavigationWidget::onItemDoubleClicked(const QModelIndex &index) model root item. The function does nothing if null is passed. */ -void NavigationWidget::onDataUpdate(QSharedPointer result) +void NavigationWidget::onDataUpdate(std::shared_ptr result) { - if (result.isNull()) + if (!result) return; QElapsedTimer timer; @@ -223,9 +223,9 @@ void NavigationWidget::onDataUpdate(QSharedPointer result) // might be just a root - if a lazy data population is enabled. // so expanded items must be parsed and 'fetched' - fetchExpandedItems(result.data(), treeModel->invisibleRootItem()); + fetchExpandedItems(result.get(), treeModel->invisibleRootItem()); - treeModel->moveRootToTarget(result.data()); + treeModel->moveRootToTarget(result.get()); // expand top level projects QModelIndex sessionIndex; diff --git a/src/plugins/classview/classviewnavigationwidget.h b/src/plugins/classview/classviewnavigationwidget.h index 5e1832ae090..9ee3ca26f13 100644 --- a/src/plugins/classview/classviewnavigationwidget.h +++ b/src/plugins/classview/classviewnavigationwidget.h @@ -7,7 +7,6 @@ #include #include -#include #include #include #include @@ -42,7 +41,7 @@ public: void onItemActivated(const QModelIndex &index); void onItemDoubleClicked(const QModelIndex &index); - void onDataUpdate(QSharedPointer result); + void onDataUpdate(std::shared_ptr result); void onFullProjectsModeToggled(bool state); diff --git a/src/plugins/classview/classviewparser.cpp b/src/plugins/classview/classviewparser.cpp index 2906504eb7c..4ebcca5e7dc 100644 --- a/src/plugins/classview/classviewparser.cpp +++ b/src/plugins/classview/classviewparser.cpp @@ -122,7 +122,7 @@ ParserTreeItem::ConstPtr Parser::parse() const FilePath projectPath = it.key(); const SymbolInformation projectInfo = { projectCache.projectName, projectPath.toString() }; ParserTreeItem::ConstPtr item = getCachedOrParseProjectTree(projectPath, projectCache.fileNames); - if (item.isNull()) + if (!item) continue; projectTrees.insert(projectInfo, item); } @@ -159,7 +159,7 @@ ParserTreeItem::ConstPtr Parser::getParseProjectTree(const FilePath &projectPath revision += doc->revision(); const ParserTreeItem::ConstPtr docTree = getCachedOrParseDocumentTree(doc); - if (docTree.isNull()) + if (!docTree) continue; docTrees.append(docTree); } @@ -185,7 +185,7 @@ ParserTreeItem::ConstPtr Parser::getCachedOrParseProjectTree(const FilePath &pro const QSet &filesInProject) { const auto it = d->m_projectCache.constFind(projectPath); - if (it != d->m_projectCache.constEnd() && !it.value().tree.isNull()) { + if (it != d->m_projectCache.constEnd() && it.value().tree) { // calculate project's revision unsigned revision = 0; for (const FilePath &fileInProject : filesInProject) { @@ -236,7 +236,7 @@ ParserTreeItem::ConstPtr Parser::getCachedOrParseDocumentTree(const CPlusPlus::D return ParserTreeItem::ConstPtr(); const auto it = d->m_documentCache.constFind(doc->filePath()); - if (it != d->m_documentCache.constEnd() && !it.value().tree.isNull() + if (it != d->m_documentCache.constEnd() && it.value().tree && it.value().treeRevision == doc->revision()) { return it.value().tree; } diff --git a/src/plugins/classview/classviewparsertreeitem.cpp b/src/plugins/classview/classviewparsertreeitem.cpp index 787b63b3c84..415064df4ee 100644 --- a/src/plugins/classview/classviewparsertreeitem.cpp +++ b/src/plugins/classview/classviewparsertreeitem.cpp @@ -44,7 +44,7 @@ public: void ParserTreeItemPrivate::mergeWith(const ParserTreeItem::ConstPtr &target) { - if (target.isNull()) + if (!target) return; m_symbolLocations.unite(target->d->m_symbolLocations); @@ -56,11 +56,11 @@ void ParserTreeItemPrivate::mergeWith(const ParserTreeItem::ConstPtr &target) const ParserTreeItem::ConstPtr &targetChild = it.value(); ParserTreeItem::ConstPtr child = m_symbolInformations.value(inf); - if (!child.isNull()) { + if (child) { child->d->mergeWith(targetChild); } else { - const ParserTreeItem::ConstPtr clone = targetChild.isNull() ? ParserTreeItem::ConstPtr() - : targetChild->d->cloneTree(); + const ParserTreeItem::ConstPtr clone = targetChild ? targetChild->d->cloneTree() + : ParserTreeItem::ConstPtr(); m_symbolInformations.insert(inf, clone); } } @@ -99,7 +99,7 @@ void ParserTreeItemPrivate::mergeSymbol(const CPlusPlus::Symbol *symbol) // Better to improve qHash timing ParserTreeItem::ConstPtr childItem = m_symbolInformations.value(information); - if (childItem.isNull()) + if (!childItem) childItem = ParserTreeItem::ConstPtr(new ParserTreeItem()); // locations have 1-based column in Symbol, use the same here. @@ -139,7 +139,7 @@ ParserTreeItem::ConstPtr ParserTreeItemPrivate::cloneTree() const for (auto it = m_symbolInformations.cbegin(); it != m_symbolInformations.cend(); ++it) { ParserTreeItem::ConstPtr child = it.value(); - if (child.isNull()) + if (!child) continue; newItem->d->m_symbolInformations.insert(it.key(), child->d->cloneTree()); } @@ -281,7 +281,7 @@ void ParserTreeItem::fetchMore(QStandardItem *item) const add->setData(inf.type(), Constants::SymbolTypeRole); add->setData(inf.iconType(), Constants::IconTypeRole); - if (!ptr.isNull()) { + if (ptr) { // icon const Utils::FilePath &filePath = ptr->projectFilePath(); if (!filePath.isEmpty()) { @@ -311,8 +311,8 @@ void ParserTreeItem::debugDump(int indent) const const SymbolInformation &inf = it.key(); const ConstPtr &child = it.value(); qDebug() << QString(2 * indent, QLatin1Char(' ')) << inf.iconType() << inf.name() - << inf.type() << child.isNull(); - if (!child.isNull()) + << inf.type() << bool(child); + if (child) child->debugDump(indent + 1); } } diff --git a/src/plugins/classview/classviewparsertreeitem.h b/src/plugins/classview/classviewparsertreeitem.h index 49fee18d061..7fa72540580 100644 --- a/src/plugins/classview/classviewparsertreeitem.h +++ b/src/plugins/classview/classviewparsertreeitem.h @@ -8,8 +8,6 @@ #include -#include - QT_BEGIN_NAMESPACE template class QHash; @@ -24,7 +22,7 @@ class ParserTreeItemPrivate; class ParserTreeItem { public: - using ConstPtr = QSharedPointer; + using ConstPtr = std::shared_ptr; public: ParserTreeItem();