2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2010-07-16 11:18:30 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 Denis Mingulov
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-07-16 11:18:30 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-07-16 11:18:30 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-07-16 11:18:30 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-07-16 11:18:30 +02:00
|
|
|
|
|
|
|
|
#include "classviewmanager.h"
|
2013-03-12 12:25:16 +01:00
|
|
|
#include "classviewsymbollocation.h"
|
2010-07-16 11:18:30 +02:00
|
|
|
#include "classviewnavigationwidgetfactory.h"
|
|
|
|
|
#include "classviewparser.h"
|
|
|
|
|
#include "classviewutils.h"
|
|
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
|
#include <projectexplorer/session.h>
|
2014-09-15 00:12:27 +02:00
|
|
|
#include <cpptools/cppmodelmanager.h>
|
2010-07-16 11:18:30 +02:00
|
|
|
#include <cpptools/cpptoolsconstants.h>
|
|
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
2015-02-26 13:38:54 +01:00
|
|
|
#include <coreplugin/idocument.h>
|
2014-09-26 09:14:03 +02:00
|
|
|
#include <texteditor/texteditor.h>
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QThread>
|
|
|
|
|
#include <QMutex>
|
|
|
|
|
#include <QMutexLocker>
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2013-08-30 09:22:42 +02:00
|
|
|
using namespace Core;
|
2020-06-26 13:59:38 +02:00
|
|
|
using namespace Utils;
|
2013-08-30 09:22:42 +02:00
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
namespace ClassView {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
///////////////////////////////// ManagerPrivate //////////////////////////////////
|
|
|
|
|
|
2011-07-06 17:40:54 +02:00
|
|
|
// static variable initialization
|
2018-11-04 22:40:59 +01:00
|
|
|
static Manager *managerInstance = nullptr;
|
2011-07-06 17:40:54 +02:00
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
/*!
|
2013-05-24 17:35:14 +02:00
|
|
|
\class ClassView::Internal::Manager
|
|
|
|
|
|
|
|
|
|
\brief The Manager class implements a class view manager that interacts with
|
|
|
|
|
other \QC plugins and acts as a proxy between them and the parser.
|
|
|
|
|
|
|
|
|
|
The parser is moved to a separate thread and is connected to the manager by
|
|
|
|
|
using signals and slots. Manager's signals starting with 'request' are for
|
|
|
|
|
the parser.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn explicit ClassView::Internal::Manager(QObject *parent = 0)
|
|
|
|
|
|
|
|
|
|
Creates a shared instance of a \a parent object.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn void ClassView::Internal::Manager::treeDataUpdate(QSharedPointer<QStandardItem> result)
|
|
|
|
|
|
|
|
|
|
Emits a signal about a tree data update (to tree view). \a result holds the
|
|
|
|
|
item with the current tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\class ManagerPrivate
|
2011-01-07 08:07:35 +01:00
|
|
|
\internal
|
2013-05-24 17:35:14 +02:00
|
|
|
\brief The ManagerPrivate class contains private class data for the Manager
|
|
|
|
|
class.
|
2010-07-16 11:18:30 +02:00
|
|
|
\sa Manager
|
2013-05-24 17:35:14 +02:00
|
|
|
*/
|
|
|
|
|
|
2011-07-06 17:40:54 +02:00
|
|
|
class ManagerPrivate
|
2010-07-16 11:18:30 +02:00
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
public:
|
2010-07-16 11:18:30 +02:00
|
|
|
//! code state/changes parser
|
|
|
|
|
Parser parser;
|
|
|
|
|
|
|
|
|
|
//! separate thread for the parser
|
|
|
|
|
QThread parserThread;
|
|
|
|
|
|
2011-01-07 08:07:35 +01:00
|
|
|
//! Internal manager state. \sa Manager::state
|
2018-11-04 22:40:59 +01:00
|
|
|
bool state = false;
|
2011-01-07 08:07:35 +01:00
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
//! there is some massive operation ongoing so temporary we should wait
|
2018-11-04 22:40:59 +01:00
|
|
|
bool disableCodeParser = false;
|
2010-07-16 11:18:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
///////////////////////////////// Manager //////////////////////////////////
|
|
|
|
|
|
|
|
|
|
Manager::Manager(QObject *parent)
|
|
|
|
|
: QObject(parent),
|
2011-07-06 17:40:54 +02:00
|
|
|
d(new ManagerPrivate())
|
2010-07-16 11:18:30 +02:00
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
managerInstance = this;
|
2010-07-16 11:18:30 +02:00
|
|
|
|
|
|
|
|
// register - to be able send between signal/slots
|
|
|
|
|
qRegisterMetaType<QSharedPointer<QStandardItem> >("QSharedPointer<QStandardItem>");
|
|
|
|
|
|
|
|
|
|
initialize();
|
|
|
|
|
|
|
|
|
|
// start a separate thread for the parser
|
2011-07-06 17:40:54 +02:00
|
|
|
d->parser.moveToThread(&d->parserThread);
|
|
|
|
|
d->parserThread.start();
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Manager::~Manager()
|
|
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
d->parserThread.quit();
|
|
|
|
|
d->parserThread.wait();
|
|
|
|
|
delete d;
|
2018-11-04 22:40:59 +01:00
|
|
|
managerInstance = nullptr;
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-06 17:40:54 +02:00
|
|
|
Manager *Manager::instance()
|
2010-07-16 11:18:30 +02:00
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
return managerInstance;
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Checks \a item for lazy data population of a QStandardItemModel.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-12-04 13:46:12 +01:00
|
|
|
bool Manager::canFetchMore(QStandardItem *item, bool skipRoot) const
|
2010-07-16 11:18:30 +02:00
|
|
|
{
|
2013-12-04 13:46:12 +01:00
|
|
|
return d->parser.canFetchMore(item, skipRoot);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Checks \a item for lazy data population of a QStandardItemModel.
|
|
|
|
|
\a skipRoot item is needed for the manual update, call not from model.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void Manager::fetchMore(QStandardItem *item, bool skipRoot)
|
|
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
d->parser.fetchMore(item, skipRoot);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-12-04 13:46:12 +01:00
|
|
|
bool Manager::hasChildren(QStandardItem *item) const
|
|
|
|
|
{
|
|
|
|
|
return d->parser.hasChildren(item);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void Manager::initialize()
|
|
|
|
|
{
|
2016-05-29 00:07:28 +03:00
|
|
|
using ProjectExplorer::SessionManager;
|
|
|
|
|
|
2010-10-30 21:54:23 +02:00
|
|
|
// connections to enable/disable navi widget factory
|
2016-05-29 00:07:28 +03:00
|
|
|
SessionManager *sessionManager = SessionManager::instance();
|
|
|
|
|
connect(sessionManager, &SessionManager::projectAdded,
|
2021-02-08 12:22:21 +01:00
|
|
|
this, &Manager::onProjectListChanged);
|
2016-05-29 00:07:28 +03:00
|
|
|
connect(sessionManager, &SessionManager::projectRemoved,
|
2021-02-08 12:22:21 +01:00
|
|
|
this, &Manager::onProjectListChanged);
|
2010-07-16 11:18:30 +02:00
|
|
|
|
|
|
|
|
// connect to the progress manager for signals about Parsing tasks
|
2016-05-29 00:07:28 +03:00
|
|
|
connect(ProgressManager::instance(), &ProgressManager::taskStarted,
|
2021-02-08 12:22:21 +01:00
|
|
|
this, [this](Id type) {
|
|
|
|
|
if (type != CppTools::Constants::TASK_INDEX)
|
|
|
|
|
return;
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2021-02-08 12:22:21 +01:00
|
|
|
// disable tree updates to speed up
|
|
|
|
|
d->disableCodeParser = true;
|
|
|
|
|
});
|
|
|
|
|
connect(ProgressManager::instance(), &ProgressManager::allTasksFinished,
|
|
|
|
|
this, [this](Id type) {
|
|
|
|
|
if (type != CppTools::Constants::TASK_INDEX)
|
|
|
|
|
return;
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2021-02-08 12:22:21 +01:00
|
|
|
// parsing is finished, enable tree updates
|
|
|
|
|
d->disableCodeParser = false;
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2021-02-08 12:22:21 +01:00
|
|
|
// do nothing if Manager is disabled
|
|
|
|
|
if (!state())
|
|
|
|
|
return;
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2021-02-08 12:22:21 +01:00
|
|
|
// any document might be changed, clear parser's cache
|
|
|
|
|
QMetaObject::invokeMethod(&d->parser, &Parser::clearCache, Qt::QueuedConnection);
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2021-02-08 12:22:21 +01:00
|
|
|
// request to update a tree to the current state
|
|
|
|
|
resetParser();
|
|
|
|
|
});
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2021-02-08 12:22:21 +01:00
|
|
|
// translate data update from the parser to listeners
|
|
|
|
|
connect(&d->parser, &Parser::treeDataUpdate,
|
|
|
|
|
this, &Manager::onTreeDataUpdate, Qt::QueuedConnection);
|
2011-01-06 18:34:06 +01:00
|
|
|
|
|
|
|
|
// connect to the cpp model manager for signals about document updates
|
2015-02-15 23:13:28 +02:00
|
|
|
CppTools::CppModelManager *codeModelManager = CppTools::CppModelManager::instance();
|
2011-01-06 18:34:06 +01:00
|
|
|
|
|
|
|
|
// when code manager signals that document is updated - handle it by ourselves
|
2016-05-29 00:07:28 +03:00
|
|
|
connect(codeModelManager, &CppTools::CppModelManager::documentUpdated,
|
2021-02-08 12:22:21 +01:00
|
|
|
this, [this](CPlusPlus::Document::Ptr doc) {
|
|
|
|
|
// do nothing if Manager is disabled
|
|
|
|
|
if (!state())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// do nothing if updates are disabled
|
|
|
|
|
if (d->disableCodeParser)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QMetaObject::invokeMethod(&d->parser, [this, doc]() {
|
|
|
|
|
d->parser.parseDocument(doc); }, Qt::QueuedConnection);
|
|
|
|
|
}, Qt::QueuedConnection);
|
2011-01-06 18:34:06 +01:00
|
|
|
//
|
2016-05-29 00:07:28 +03:00
|
|
|
connect(codeModelManager, &CppTools::CppModelManager::aboutToRemoveFiles,
|
|
|
|
|
&d->parser, &Parser::removeFiles, Qt::QueuedConnection);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Gets the internal manager state. If it is disabled, does not emit signals
|
|
|
|
|
about parsing requests. If enabled, does parsing in the background even if
|
|
|
|
|
the navigation pane is not visible. Returns true if the manager is enabled,
|
|
|
|
|
false otherwise.
|
|
|
|
|
|
|
|
|
|
\sa setState, stateChanged
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
bool Manager::state() const
|
|
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
return d->state;
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Sets the internal manager \a state to \c true if the manager has to be
|
|
|
|
|
enabled, otherwise sets it to \c false.
|
|
|
|
|
|
|
|
|
|
\sa state, stateChanged
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void Manager::setState(bool state)
|
|
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
if (state == d->state)
|
2010-07-16 11:18:30 +02:00
|
|
|
return;
|
|
|
|
|
|
2011-07-06 17:40:54 +02:00
|
|
|
d->state = state;
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2021-02-08 12:22:21 +01:00
|
|
|
if (state) // enabled - request a current snapshots etc?..
|
|
|
|
|
resetParser();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Manager::resetParser()
|
|
|
|
|
{
|
|
|
|
|
QMetaObject::invokeMethod(&d->parser, &Parser::resetDataToCurrentState, Qt::QueuedConnection);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Reacts to the \a visibility of one navigation pane widget being changed
|
|
|
|
|
(there might be a lot of them).
|
|
|
|
|
|
|
|
|
|
\sa setState, state
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void Manager::onWidgetVisibilityIsChanged(bool visibility)
|
|
|
|
|
{
|
|
|
|
|
// activate data handling - when 1st time 'Class View' will be open
|
2021-02-08 12:22:21 +01:00
|
|
|
if (!visibility)
|
|
|
|
|
return;
|
|
|
|
|
setState(true);
|
|
|
|
|
onProjectListChanged();
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Reacts to the project list being changed by updating the navigation pane
|
|
|
|
|
visibility if necessary.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void Manager::onProjectListChanged()
|
|
|
|
|
{
|
|
|
|
|
// do nothing if Manager is disabled
|
|
|
|
|
if (!state())
|
|
|
|
|
return;
|
|
|
|
|
|
2021-02-08 12:22:21 +01:00
|
|
|
QMetaObject::invokeMethod(&d->parser, &Parser::requestCurrentState, Qt::QueuedConnection);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Opens the text editor for the file \a fileName on \a line (1-based) and
|
2018-11-02 14:17:12 +01:00
|
|
|
\a column (0-based).
|
2013-05-24 17:35:14 +02:00
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void Manager::gotoLocation(const QString &fileName, int line, int column)
|
|
|
|
|
{
|
2013-08-30 09:22:42 +02:00
|
|
|
EditorManager::openEditorAt(fileName, line, column);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Opens the text editor for any of the symbol locations in the \a list.
|
|
|
|
|
|
|
|
|
|
\sa Manager::gotoLocations
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void Manager::gotoLocations(const QList<QVariant> &list)
|
|
|
|
|
{
|
2019-11-15 18:42:11 +01:00
|
|
|
QSet<SymbolLocation> locations = Internal::roleToLocations(list);
|
2014-10-17 09:32:17 +02:00
|
|
|
if (locations.size() == 0)
|
2010-07-16 11:18:30 +02:00
|
|
|
return;
|
|
|
|
|
|
2014-10-17 09:32:17 +02:00
|
|
|
// Default to first known location
|
|
|
|
|
SymbolLocation loc = *locations.constBegin();
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2014-10-17 09:32:17 +02:00
|
|
|
if (locations.size() > 1) {
|
|
|
|
|
// The symbol has multiple locations. Check if we are already at one location,
|
|
|
|
|
// and if so, cycle to the "next" one
|
|
|
|
|
auto textEditor = qobject_cast<TextEditor::BaseTextEditor *>(EditorManager::currentEditor());
|
2010-07-16 11:18:30 +02:00
|
|
|
if (textEditor) {
|
2014-10-17 09:32:17 +02:00
|
|
|
// check if current cursor position is a known location of the symbol
|
2014-12-21 21:54:30 +02:00
|
|
|
const QString fileName = textEditor->document()->filePath().toString();
|
2014-10-17 09:32:17 +02:00
|
|
|
int line;
|
|
|
|
|
int column;
|
|
|
|
|
textEditor->convertPosition(textEditor->position(), &line, &column);
|
|
|
|
|
SymbolLocation current(fileName, line, column);
|
2017-10-20 15:48:31 +02:00
|
|
|
QSet<SymbolLocation>::const_iterator it = locations.constFind(current);
|
2014-10-17 09:32:17 +02:00
|
|
|
QSet<SymbolLocation>::const_iterator end = locations.constEnd();
|
|
|
|
|
if (it != end) {
|
|
|
|
|
// we already are at the symbol, cycle to next location
|
|
|
|
|
++it;
|
|
|
|
|
if (it == end)
|
2017-10-20 15:48:31 +02:00
|
|
|
it = locations.constBegin();
|
2014-10-17 09:32:17 +02:00
|
|
|
loc = *it;
|
|
|
|
|
}
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
}
|
2018-11-02 14:17:12 +01:00
|
|
|
// line is 1-based, column is 0-based
|
|
|
|
|
gotoLocation(loc.fileName(), loc.line(), loc.column() - 1);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Switches to flat mode (without subprojects) if \a flat is set to \c true.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void Manager::setFlatMode(bool flat)
|
|
|
|
|
{
|
2021-02-08 12:22:21 +01:00
|
|
|
QMetaObject::invokeMethod(&d->parser, [this, flat]() {
|
|
|
|
|
d->parser.setFlatMode(flat);
|
|
|
|
|
}, Qt::QueuedConnection);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Sends a new tree data update to a tree view. \a result holds the item with
|
|
|
|
|
the current tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void Manager::onTreeDataUpdate(QSharedPointer<QStandardItem> result)
|
|
|
|
|
{
|
|
|
|
|
// do nothing if Manager is disabled
|
|
|
|
|
if (!state())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
emit treeDataUpdate(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ClassView
|