diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2021-02-16 14:01:16 +0100 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2021-02-16 15:13:31 +0000 |
commit | a513f25c39df21930e823100563553db2a2b65a9 (patch) | |
tree | a6a54639f2421c5c7048bed2c2290b008a5138fb /src/plugins/classview/classviewmanager.cpp | |
parent | ab7560bec47bd20e0bdc05018e09a6ac3070a1b5 (diff) |
ClassView: Move the GUI related code out of Parser
Don't create QStandardItem objects inside the non-gui thread,
as it was in case of requestCurrentState() which is always
called in parser's thread. As a result of parsing send a root's
ParserTreeItem::ConstPtr now instead. Store the generated
root inside Manager instead of inside Parser. Remove rootItemLocker
as it's not needed now anymore. Move the implementation of
canFetchMore(), fetchMore() and hasChildren() into Manager class.
Now all the API of Parser class is used only in parser's thread
(with the exception of constructor and destructor).
Task-number: QTCREATORBUG-25317
Change-Id: I2b3c49918bf58266e6bea8acf65c975e19f7d9cb
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/classview/classviewmanager.cpp')
-rw-r--r-- | src/plugins/classview/classviewmanager.cpp | 65 |
1 files changed, 54 insertions, 11 deletions
diff --git a/src/plugins/classview/classviewmanager.cpp b/src/plugins/classview/classviewmanager.cpp index 338c1eb357..53ff9ee142 100644 --- a/src/plugins/classview/classviewmanager.cpp +++ b/src/plugins/classview/classviewmanager.cpp @@ -96,6 +96,8 @@ public: //! separate thread for the parser QThread parserThread; + ParserTreeItem::ConstPtr m_root; + //! Internal manager state. \sa Manager::state bool state = false; @@ -136,27 +138,67 @@ Manager *Manager::instance() } /*! - Checks \a item for lazy data population of a QStandardItemModel. + Returns the internal tree item for \a item. \a skipRoot skips the root + item. */ +ParserTreeItem::ConstPtr Manager::findItemByRoot(const QStandardItem *item, bool skipRoot) const +{ + if (!item) + return ParserTreeItem::ConstPtr(); + + // go item by item to the root + QList<const QStandardItem *> uiList; + const QStandardItem *cur = item; + while (cur) { + uiList.append(cur); + cur = cur->parent(); + } + + if (skipRoot && uiList.count() > 0) + uiList.removeLast(); + + ParserTreeItem::ConstPtr internal = d->m_root; + while (uiList.count() > 0) { + cur = uiList.last(); + uiList.removeLast(); + const SymbolInformation &inf = Internal::symbolInformationFromItem(cur); + internal = internal->child(inf); + if (internal.isNull()) + break; + } + + return internal; +} +/*! + Checks \a item for lazy data population of a QStandardItemModel. +*/ bool Manager::canFetchMore(QStandardItem *item, bool skipRoot) const { - return d->parser.canFetchMore(item, skipRoot); + ParserTreeItem::ConstPtr ptr = findItemByRoot(item, skipRoot); + if (ptr.isNull()) + return false; + return ptr->canFetchMore(item); } /*! Checks \a item for lazy data population of a QStandardItemModel. \a skipRoot item is needed for the manual update, call not from model. */ - void Manager::fetchMore(QStandardItem *item, bool skipRoot) { - d->parser.fetchMore(item, skipRoot); + ParserTreeItem::ConstPtr ptr = findItemByRoot(item, skipRoot); + if (ptr.isNull()) + return; + ptr->fetchMore(item); } bool Manager::hasChildren(QStandardItem *item) const { - return d->parser.hasChildren(item); + ParserTreeItem::ConstPtr ptr = findItemByRoot(item); + if (ptr.isNull()) + return false; + return ptr->childCount() != 0; } void Manager::initialize() @@ -195,15 +237,16 @@ void Manager::initialize() resetParser(); }); - // translate data update from the parser to listeners - connect(&d->parser, &Parser::treeDataUpdate, - this, [this](QSharedPointer<QStandardItem> result) { - // do nothing if Manager is disabled + connect(&d->parser, &Parser::treeRegenerated, + this, [this](const ParserTreeItem::ConstPtr &root) { + d->m_root = root; + if (!state()) return; - emit treeDataUpdate(result); - + QSharedPointer<QStandardItem> rootItem(new QStandardItem()); + d->m_root->convertTo(rootItem.data()); + emit treeDataUpdate(rootItem); }, Qt::QueuedConnection); // connect to the cpp model manager for signals about document updates |