forked from qt-creator/qt-creator
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:
@@ -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
|
Emits a signal about a tree data update (to tree view). \a result holds the
|
||||||
item with the current tree.
|
item with the current tree.
|
||||||
@@ -128,7 +128,7 @@ ParserTreeItem::ConstPtr ManagerPrivate::findItemByRoot(const QStandardItem *ite
|
|||||||
uiList.removeLast();
|
uiList.removeLast();
|
||||||
const SymbolInformation &inf = Internal::symbolInformationFromItem(cur);
|
const SymbolInformation &inf = Internal::symbolInformationFromItem(cur);
|
||||||
internal = internal->child(inf);
|
internal = internal->child(inf);
|
||||||
if (internal.isNull())
|
if (!internal)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ Manager::Manager(QObject *parent)
|
|||||||
managerInstance = this;
|
managerInstance = this;
|
||||||
|
|
||||||
// register - to be able send between signal/slots
|
// register - to be able send between signal/slots
|
||||||
qRegisterMetaType<QSharedPointer<QStandardItem> >("QSharedPointer<QStandardItem>");
|
qRegisterMetaType<std::shared_ptr<QStandardItem>>("std::shared_ptr<QStandardItem>");
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
@@ -174,7 +174,7 @@ Manager *Manager::instance()
|
|||||||
bool Manager::canFetchMore(QStandardItem *item, bool skipRoot) const
|
bool Manager::canFetchMore(QStandardItem *item, bool skipRoot) const
|
||||||
{
|
{
|
||||||
ParserTreeItem::ConstPtr ptr = d->findItemByRoot(item, skipRoot);
|
ParserTreeItem::ConstPtr ptr = d->findItemByRoot(item, skipRoot);
|
||||||
if (ptr.isNull())
|
if (!ptr)
|
||||||
return false;
|
return false;
|
||||||
return ptr->canFetchMore(item);
|
return ptr->canFetchMore(item);
|
||||||
}
|
}
|
||||||
@@ -186,7 +186,7 @@ bool Manager::canFetchMore(QStandardItem *item, bool skipRoot) const
|
|||||||
void Manager::fetchMore(QStandardItem *item, bool skipRoot)
|
void Manager::fetchMore(QStandardItem *item, bool skipRoot)
|
||||||
{
|
{
|
||||||
ParserTreeItem::ConstPtr ptr = d->findItemByRoot(item, skipRoot);
|
ParserTreeItem::ConstPtr ptr = d->findItemByRoot(item, skipRoot);
|
||||||
if (ptr.isNull())
|
if (!ptr)
|
||||||
return;
|
return;
|
||||||
ptr->fetchMore(item);
|
ptr->fetchMore(item);
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ void Manager::fetchMore(QStandardItem *item, bool skipRoot)
|
|||||||
bool Manager::hasChildren(QStandardItem *item) const
|
bool Manager::hasChildren(QStandardItem *item) const
|
||||||
{
|
{
|
||||||
ParserTreeItem::ConstPtr ptr = d->findItemByRoot(item);
|
ParserTreeItem::ConstPtr ptr = d->findItemByRoot(item);
|
||||||
if (ptr.isNull())
|
if (!ptr)
|
||||||
return false;
|
return false;
|
||||||
return ptr->childCount();
|
return ptr->childCount();
|
||||||
}
|
}
|
||||||
@@ -255,8 +255,8 @@ void Manager::initialize()
|
|||||||
if (!state())
|
if (!state())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QSharedPointer<QStandardItem> rootItem(new QStandardItem());
|
std::shared_ptr<QStandardItem> rootItem(new QStandardItem());
|
||||||
d->m_root->fetchMore(rootItem.data());
|
d->m_root->fetchMore(rootItem.get());
|
||||||
emit treeDataUpdate(rootItem);
|
emit treeDataUpdate(rootItem);
|
||||||
}, Qt::QueuedConnection);
|
}, Qt::QueuedConnection);
|
||||||
|
|
||||||
|
@@ -4,7 +4,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSharedPointer>
|
|
||||||
#include <QStandardItem>
|
#include <QStandardItem>
|
||||||
|
|
||||||
namespace Utils { class FilePath; }
|
namespace Utils { class FilePath; }
|
||||||
@@ -32,7 +31,7 @@ public:
|
|||||||
void onWidgetVisibilityIsChanged(bool visibility);
|
void onWidgetVisibilityIsChanged(bool visibility);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void treeDataUpdate(QSharedPointer<QStandardItem> result);
|
void treeDataUpdate(std::shared_ptr<QStandardItem> result);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initialize();
|
void initialize();
|
||||||
|
@@ -211,9 +211,9 @@ void NavigationWidget::onItemDoubleClicked(const QModelIndex &index)
|
|||||||
model root item. The function does nothing if null is passed.
|
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;
|
return;
|
||||||
|
|
||||||
QElapsedTimer timer;
|
QElapsedTimer timer;
|
||||||
@@ -223,9 +223,9 @@ void NavigationWidget::onDataUpdate(QSharedPointer<QStandardItem> result)
|
|||||||
// might be just a root - if a lazy data population is enabled.
|
// might be just a root - if a lazy data population is enabled.
|
||||||
// so expanded items must be parsed and 'fetched'
|
// 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
|
// expand top level projects
|
||||||
QModelIndex sessionIndex;
|
QModelIndex sessionIndex;
|
||||||
|
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QSharedPointer>
|
|
||||||
#include <QStandardItem>
|
#include <QStandardItem>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
@@ -42,7 +41,7 @@ public:
|
|||||||
void onItemActivated(const QModelIndex &index);
|
void onItemActivated(const QModelIndex &index);
|
||||||
void onItemDoubleClicked(const QModelIndex &index);
|
void onItemDoubleClicked(const QModelIndex &index);
|
||||||
|
|
||||||
void onDataUpdate(QSharedPointer<QStandardItem> result);
|
void onDataUpdate(std::shared_ptr<QStandardItem> result);
|
||||||
|
|
||||||
void onFullProjectsModeToggled(bool state);
|
void onFullProjectsModeToggled(bool state);
|
||||||
|
|
||||||
|
@@ -122,7 +122,7 @@ ParserTreeItem::ConstPtr Parser::parse()
|
|||||||
const FilePath projectPath = it.key();
|
const FilePath projectPath = it.key();
|
||||||
const SymbolInformation projectInfo = { projectCache.projectName, projectPath.toString() };
|
const SymbolInformation projectInfo = { projectCache.projectName, projectPath.toString() };
|
||||||
ParserTreeItem::ConstPtr item = getCachedOrParseProjectTree(projectPath, projectCache.fileNames);
|
ParserTreeItem::ConstPtr item = getCachedOrParseProjectTree(projectPath, projectCache.fileNames);
|
||||||
if (item.isNull())
|
if (!item)
|
||||||
continue;
|
continue;
|
||||||
projectTrees.insert(projectInfo, item);
|
projectTrees.insert(projectInfo, item);
|
||||||
}
|
}
|
||||||
@@ -159,7 +159,7 @@ ParserTreeItem::ConstPtr Parser::getParseProjectTree(const FilePath &projectPath
|
|||||||
revision += doc->revision();
|
revision += doc->revision();
|
||||||
|
|
||||||
const ParserTreeItem::ConstPtr docTree = getCachedOrParseDocumentTree(doc);
|
const ParserTreeItem::ConstPtr docTree = getCachedOrParseDocumentTree(doc);
|
||||||
if (docTree.isNull())
|
if (!docTree)
|
||||||
continue;
|
continue;
|
||||||
docTrees.append(docTree);
|
docTrees.append(docTree);
|
||||||
}
|
}
|
||||||
@@ -185,7 +185,7 @@ ParserTreeItem::ConstPtr Parser::getCachedOrParseProjectTree(const FilePath &pro
|
|||||||
const QSet<FilePath> &filesInProject)
|
const QSet<FilePath> &filesInProject)
|
||||||
{
|
{
|
||||||
const auto it = d->m_projectCache.constFind(projectPath);
|
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
|
// calculate project's revision
|
||||||
unsigned revision = 0;
|
unsigned revision = 0;
|
||||||
for (const FilePath &fileInProject : filesInProject) {
|
for (const FilePath &fileInProject : filesInProject) {
|
||||||
@@ -236,7 +236,7 @@ ParserTreeItem::ConstPtr Parser::getCachedOrParseDocumentTree(const CPlusPlus::D
|
|||||||
return ParserTreeItem::ConstPtr();
|
return ParserTreeItem::ConstPtr();
|
||||||
|
|
||||||
const auto it = d->m_documentCache.constFind(doc->filePath());
|
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()) {
|
&& it.value().treeRevision == doc->revision()) {
|
||||||
return it.value().tree;
|
return it.value().tree;
|
||||||
}
|
}
|
||||||
|
@@ -44,7 +44,7 @@ public:
|
|||||||
|
|
||||||
void ParserTreeItemPrivate::mergeWith(const ParserTreeItem::ConstPtr &target)
|
void ParserTreeItemPrivate::mergeWith(const ParserTreeItem::ConstPtr &target)
|
||||||
{
|
{
|
||||||
if (target.isNull())
|
if (!target)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_symbolLocations.unite(target->d->m_symbolLocations);
|
m_symbolLocations.unite(target->d->m_symbolLocations);
|
||||||
@@ -56,11 +56,11 @@ void ParserTreeItemPrivate::mergeWith(const ParserTreeItem::ConstPtr &target)
|
|||||||
const ParserTreeItem::ConstPtr &targetChild = it.value();
|
const ParserTreeItem::ConstPtr &targetChild = it.value();
|
||||||
|
|
||||||
ParserTreeItem::ConstPtr child = m_symbolInformations.value(inf);
|
ParserTreeItem::ConstPtr child = m_symbolInformations.value(inf);
|
||||||
if (!child.isNull()) {
|
if (child) {
|
||||||
child->d->mergeWith(targetChild);
|
child->d->mergeWith(targetChild);
|
||||||
} else {
|
} else {
|
||||||
const ParserTreeItem::ConstPtr clone = targetChild.isNull() ? ParserTreeItem::ConstPtr()
|
const ParserTreeItem::ConstPtr clone = targetChild ? targetChild->d->cloneTree()
|
||||||
: targetChild->d->cloneTree();
|
: ParserTreeItem::ConstPtr();
|
||||||
m_symbolInformations.insert(inf, clone);
|
m_symbolInformations.insert(inf, clone);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,7 +99,7 @@ void ParserTreeItemPrivate::mergeSymbol(const CPlusPlus::Symbol *symbol)
|
|||||||
// Better to improve qHash timing
|
// Better to improve qHash timing
|
||||||
ParserTreeItem::ConstPtr childItem = m_symbolInformations.value(information);
|
ParserTreeItem::ConstPtr childItem = m_symbolInformations.value(information);
|
||||||
|
|
||||||
if (childItem.isNull())
|
if (!childItem)
|
||||||
childItem = ParserTreeItem::ConstPtr(new ParserTreeItem());
|
childItem = ParserTreeItem::ConstPtr(new ParserTreeItem());
|
||||||
|
|
||||||
// locations have 1-based column in Symbol, use the same here.
|
// 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) {
|
for (auto it = m_symbolInformations.cbegin(); it != m_symbolInformations.cend(); ++it) {
|
||||||
ParserTreeItem::ConstPtr child = it.value();
|
ParserTreeItem::ConstPtr child = it.value();
|
||||||
if (child.isNull())
|
if (!child)
|
||||||
continue;
|
continue;
|
||||||
newItem->d->m_symbolInformations.insert(it.key(), child->d->cloneTree());
|
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.type(), Constants::SymbolTypeRole);
|
||||||
add->setData(inf.iconType(), Constants::IconTypeRole);
|
add->setData(inf.iconType(), Constants::IconTypeRole);
|
||||||
|
|
||||||
if (!ptr.isNull()) {
|
if (ptr) {
|
||||||
// icon
|
// icon
|
||||||
const Utils::FilePath &filePath = ptr->projectFilePath();
|
const Utils::FilePath &filePath = ptr->projectFilePath();
|
||||||
if (!filePath.isEmpty()) {
|
if (!filePath.isEmpty()) {
|
||||||
@@ -311,8 +311,8 @@ void ParserTreeItem::debugDump(int indent) const
|
|||||||
const SymbolInformation &inf = it.key();
|
const SymbolInformation &inf = it.key();
|
||||||
const ConstPtr &child = it.value();
|
const ConstPtr &child = it.value();
|
||||||
qDebug() << QString(2 * indent, QLatin1Char(' ')) << inf.iconType() << inf.name()
|
qDebug() << QString(2 * indent, QLatin1Char(' ')) << inf.iconType() << inf.name()
|
||||||
<< inf.type() << child.isNull();
|
<< inf.type() << bool(child);
|
||||||
if (!child.isNull())
|
if (child)
|
||||||
child->debugDump(indent + 1);
|
child->debugDump(indent + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
#include <cplusplus/CppDocument.h>
|
#include <cplusplus/CppDocument.h>
|
||||||
|
|
||||||
#include <QSharedPointer>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
template <typename K, typename T>
|
template <typename K, typename T>
|
||||||
class QHash;
|
class QHash;
|
||||||
@@ -24,7 +22,7 @@ class ParserTreeItemPrivate;
|
|||||||
class ParserTreeItem
|
class ParserTreeItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using ConstPtr = QSharedPointer<const ParserTreeItem>;
|
using ConstPtr = std::shared_ptr<const ParserTreeItem>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ParserTreeItem();
|
ParserTreeItem();
|
||||||
|
Reference in New Issue
Block a user