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 <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2024-02-01 17:04:09 +01:00
parent 8f2d0dbcc9
commit c22d6b501b
7 changed files with 28 additions and 32 deletions

View File

@@ -47,7 +47,7 @@ static Manager *managerInstance = nullptr;
*/
/*!
\fn void ClassView::Internal::Manager::treeDataUpdate(QSharedPointer<QStandardItem> result)
\fn void ClassView::Internal::Manager::treeDataUpdate(std::shared_ptr<QStandardItem> 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<QStandardItem> >("QSharedPointer<QStandardItem>");
qRegisterMetaType<std::shared_ptr<QStandardItem>>("std::shared_ptr<QStandardItem>");
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<QStandardItem> rootItem(new QStandardItem());
d->m_root->fetchMore(rootItem.data());
std::shared_ptr<QStandardItem> rootItem(new QStandardItem());
d->m_root->fetchMore(rootItem.get());
emit treeDataUpdate(rootItem);
}, Qt::QueuedConnection);

View File

@@ -4,7 +4,6 @@
#pragma once
#include <QObject>
#include <QSharedPointer>
#include <QStandardItem>
namespace Utils { class FilePath; }
@@ -32,7 +31,7 @@ public:
void onWidgetVisibilityIsChanged(bool visibility);
signals:
void treeDataUpdate(QSharedPointer<QStandardItem> result);
void treeDataUpdate(std::shared_ptr<QStandardItem> result);
private:
void initialize();

View File

@@ -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<QStandardItem> result)
void NavigationWidget::onDataUpdate(std::shared_ptr<QStandardItem> result)
{
if (result.isNull())
if (!result)
return;
QElapsedTimer timer;
@@ -223,9 +223,9 @@ void NavigationWidget::onDataUpdate(QSharedPointer<QStandardItem> 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;

View File

@@ -7,7 +7,6 @@
#include <QList>
#include <QPointer>
#include <QSharedPointer>
#include <QStandardItem>
#include <QToolButton>
#include <QWidget>
@@ -42,7 +41,7 @@ public:
void onItemActivated(const QModelIndex &index);
void onItemDoubleClicked(const QModelIndex &index);
void onDataUpdate(QSharedPointer<QStandardItem> result);
void onDataUpdate(std::shared_ptr<QStandardItem> result);
void onFullProjectsModeToggled(bool state);

View File

@@ -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<FilePath> &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;
}

View File

@@ -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);
}
}

View File

@@ -8,8 +8,6 @@
#include <cplusplus/CppDocument.h>
#include <QSharedPointer>
QT_BEGIN_NAMESPACE
template <typename K, typename T>
class QHash;
@@ -24,7 +22,7 @@ class ParserTreeItemPrivate;
class ParserTreeItem
{
public:
using ConstPtr = QSharedPointer<const ParserTreeItem>;
using ConstPtr = std::shared_ptr<const ParserTreeItem>;
public:
ParserTreeItem();