Commit ae8192ad authored by Denis Mingulov's avatar Denis Mingulov Committed by Kai Koehne

ClassView: Initial implementation

Merge-request: 2167
Reviewed-by: default avatarKai Koehne <kai.koehne@nokia.com>
parent 915ba478
<plugin name="ClassView" version="2.1.80" compatVersion="2.1.80">
<vendor>Nokia Corporation</vendor>
<copyright>(C) 2010 Denis Mingulov</copyright>
<license>
Commercial Usage
Licensees holding valid Qt Commercial licenses may use this plugin in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Nokia.
GNU Lesser General Public License Usage
Alternatively, this plugin may be used under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. Please review the following information to ensure the GNU Lesser General Public License version 2.1 requirements will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
</license>
<category>Qt Creator</category>
<description>Class View component.</description>
<url>http://qt.nokia.com</url>
<dependencyList>
<dependency name="Core" version="2.1.80"/>
<dependency name="CppTools" version="2.1.80"/>
<dependency name="ProjectExplorer" version="2.1.80"/>
<dependency name="TextEditor" version="2.1.80"/>
</dependencyList>
</plugin>
TEMPLATE = lib
TARGET = ClassView
include(classview_dependencies.pri)
HEADERS += \
classviewplugin.h \
classviewnavigationwidgetfactory.h \
classviewconstants.h \
classviewnavigationwidget.h \
classviewparser.h \
classviewmanager.h \
classviewsymbollocation.h \
classviewsymbolinformation.h \
classviewparsertreeitem.h \
classviewutils.h \
classviewtreeitemmodel.h
SOURCES += \
classviewplugin.cpp \
classviewnavigationwidgetfactory.cpp \
classviewnavigationwidget.cpp \
classviewparser.cpp \
classviewmanager.cpp \
classviewsymbollocation.cpp \
classviewsymbolinformation.cpp \
classviewparsertreeitem.cpp \
classviewutils.cpp \
classviewtreeitemmodel.cpp
OTHER_FILES += \
ClassView.pluginspec
FORMS += \
classviewnavigationwidget.ui
RESOURCES += \
classview.qrc
<RCC>
<qresource prefix="/classview">
<file>images/hierarchicalmode.png</file>
</qresource>
</RCC>
include(../../qtcreatorplugin.pri)
include(../../libs/utils/utils.pri)
include(../../plugins/coreplugin/coreplugin.pri)
include(../../plugins/cpptools/cpptools.pri)
include(../../plugins/projectexplorer/projectexplorer.pri)
include(../../libs/cplusplus/cplusplus.pri)
include(../../plugins/texteditor/texteditor.pri)
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Denis Mingulov.
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef CLASSVIEWCONSTANTS_H
#define CLASSVIEWCONSTANTS_H
namespace ClassView {
namespace Constants {
//! Navi Widget Factory id
const char * const CLASSVIEWNAVIGATION_ID = "Class View";
//! Settings' group
const char * const CLASSVIEW_SETTINGS_GROUP = "ClassView";
//! Settings' prefix for the tree widget
const char * const CLASSVIEW_SETTINGS_TREEWIDGET_PREFIX = "TreeWidget.";
//! Flat mode settings
const char * const CLASSVIEW_SETTINGS_FLATMODE = "FlatMode";
//! Delay in msecs before an update
const int CLASSVIEW_EDITINGTREEUPDATE_DELAY = 400;
//! QStandardItem roles
enum ItemRole {
SymbolLocationsRole = Qt::UserRole + 1, //!< Symbol locations
IconTypeRole, //!< Icon type (integer)
SymbolNameRole, //!< Symbol name
SymbolTypeRole //!< Symbol type
};
} // namespace Constants
} // namespace ClassView
#endif // CLASSVIEWCONSTANTS_H
This diff is collapsed.
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Denis Mingulov.
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef CLASSVIEWMANAGER_H
#define CLASSVIEWMANAGER_H
#include <QtCore/QObject>
#include <QtCore/QScopedPointer>
#include <QtCore/QSharedPointer>
#include <QtGui/QStandardItem>
#include <cplusplus/CppDocument.h>
namespace ClassView {
namespace Internal {
class NavigationWidgetFactory;
/*!
\class Manager
\brief Class View manager
Class View Manager. Interacts with other Qt Creator plugins - this is a proxy between them and
parser.
\a Parser is moved to a separate thread and is connected to \a Manager by signal/slots.
Manager's signals starting with 'request' are for Parser.
*/
class Manager : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(Manager)
public:
/*!
\brief
\param widgetFactory NavigationWidgetFactory
\param parent Parent object
*/
virtual ~Manager();
//! Get an instance of Manager
static Manager *instance(QObject *parent = 0);
/*!
\brief Lazy data population for a \a QStandardItemModel
\param item Item with has to be checked
*/
bool canFetchMore(QStandardItem *item) const;
/*!
\brief Lazy data population for a \a QStandardItemModel
\param item Item with has to be checked
\param skipRoot Skip root item (is needed for the manual update, call not from model)
*/
void fetchMore(QStandardItem *item, bool skipRoot = false);
signals:
/*!
\brief Internal Manager state is changed.
\param state true if Manager is enabled, false otherwise
\sa setState, state
*/
void stateChanged(bool state);
/*!
\brief Signal about a tree data update (to tree view).
\param result Item with the current tree
*/
void treeDataUpdate(QSharedPointer<QStandardItem> result);
/*!
\brief Signal that a request for sending tree view has to be handled by listeners (parser).
\sa onRequestTreeDataUpdate
*/
void requestTreeDataUpdate();
/*!
\brief Signal that document is updated (and has to be reparsed)
\param doc Updated document
\sa onDocumentUpdated
*/
void requestDocumentUpdated(CPlusPlus::Document::Ptr doc);
/*!
\brief Signal that parser has to reset its internal state to the current (from code manager).
*/
void requestResetCurrentState();
/*!
\brief Request to clear a cache by parser.
*/
void requestClearCache();
/*!
\brief Request to clear a full cache by parser.
*/
void requestClearCacheAll();
/*!
\brief Request to set the flat mode (without subprojects)
\param flat True to enable flat mode, false to disable
*/
void requestSetFlatMode(bool flat);
public slots:
/*!
\brief Open text editor for file \a fileName on line \a lineNumber and column \a column.
\param fileName File which has to be open
\param lineNumber Line
\param column Column
*/
void gotoLocation(const QString &fileName, int line = 0, int column = 0);
/*!
\brief Open text editor for any of location in the list (correctly)
\param locations Symbol locations
\sa Manager::gotoLocations
*/
void gotoLocations(const QList<QVariant> &locations);
/*!
\brief If somebody wants to receive the latest tree info, if a parsing is enabled then
a signal \a requestTreeDataUpdate will be emitted.
\sa requestTreeDataUpdate, NavigationWidget::requestDataUpdate
*/
void onRequestTreeDataUpdate();
/*!
\brief Switch to flat mode (without subprojects)
\param flat True to enable flat mode, false to disable
*/
void setFlatMode(bool flat);
protected slots:
/*!
\brief Widget factory creates a widget, handle this situation.
\sa setState, state
*/
void onWidgetIsCreated();
/*!
\brief Widget visibility is changed
\param visibility Visibility (for just 1 navi pane widget, there might be a lot of them)
\sa setState, state
*/
void onWidgetVisibilityIsChanged(bool visibility);
/*!
\brief Reacts to the state changed signal, e.g. request currect code snapshot if needed etc.
\param state Current Manager state
\sa setState, state, stateChanged
*/
void onStateChanged(bool state);
/*!
\brief Project list is changed (navigation pane visibility might be needed to update).
*/
void onProjectListChanged();
/*!
\brief This slot should called when the code model manager state is changed for \a doc.
It will emit a signal \a documentUpdated if
\param doc Updated document.
\sa documentUpdated
*/
void onDocumentUpdated(CPlusPlus::Document::Ptr doc);
/*!
\brief Progress manager started a task. Do what is needed if it is a parse task.
\param type Task index, should be CppTools::Constants::TASK_INDEX for us
\sa CppTools::Constants::TASK_INDEX
*/
void onTaskStarted(const QString &type);
/*!
\brief Progress manager finished all task with specified type.
Do what is needed if it is a parse task.
\param type Task index, should be CppTools::Constants::TASK_INDEX for us
\sa CppTools::Constants::TASK_INDEX
*/
void onAllTasksFinished(const QString &type);
/*!
\brief New tree data update (has to be sent to a tree view).
\param result Item with the current tree
*/
void onTreeDataUpdate(QSharedPointer<QStandardItem> result);
protected:
//! Perform an initialization
void initialize();
/*!
\brief Get internal Manager state. If it is disabled, signals about parsing request has not
to be emitted at all, if enabled - do parsing in the background even if navi pane
is not visible.
\return true if Manager is enabled, false otherwise
\sa setState, stateChanged
*/
inline bool state() const;
/*!
\brief Set internal Manager state.
\param true if Manager has to be enabled, false otherwise
\sa state, stateChanged
*/
void setState(bool state);
private:
explicit Manager(QObject *parent = 0);
private:
//! private class data pointer
QScopedPointer<struct ManagerPrivate> d_ptr;
};
} // namespace Internal
} // namespace ClassView
#endif // CLASSVIEWMANAGER_H
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Denis Mingulov.
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "classviewnavigationwidget.h"
#include "ui_classviewnavigationwidget.h"
#include "classviewtreeitemmodel.h"
#include "classviewmanager.h"
#include "classviewsymbollocation.h"
#include "classviewsymbolinformation.h"
#include "classviewutils.h"
#include "classviewconstants.h"
#include <utils/qtcassert.h>
#include <QtCore/QDebug>
#include <QtCore/QPointer>
enum { debug = false };
namespace ClassView {
namespace Internal {
///////////////////////////////// NavigationWidgetPrivate //////////////////////////////////
/*!
\struct NavigationWidgetPrivate
\brief Internal data structures / methods for NavigationWidget
*/
struct NavigationWidgetPrivate
{
NavigationWidgetPrivate() : ui(0) {}
//! Ui generated by Designer
Ui::NavigationWidget *ui;
//! current tree model
QPointer<TreeItemModel> treeModel;
//! full projects mode
QPointer<QToolButton> fullProjectsModeButton;
};
///////////////////////////////// NavigationWidget //////////////////////////////////
NavigationWidget::NavigationWidget(QWidget *parent) :
QWidget(parent),
d_ptr(new NavigationWidgetPrivate())
{
d_ptr->ui = new Ui::NavigationWidget;
d_ptr->ui->setupUi(this);
d_ptr->ui->treeView->setIndentation(d_ptr->ui->treeView->indentation() * 9/10);
// tree model
d_ptr->treeModel = new TreeItemModel(this);
d_ptr->ui->treeView->setModel(d_ptr->treeModel);
// connect signal/slots
// selected item
connect(d_ptr->ui->treeView, SIGNAL(activated(QModelIndex)), SLOT(onItemActivated(QModelIndex)));
// connections to the manager
Manager *manager = Manager::instance();
connect(this, SIGNAL(visibilityChanged(bool)),
manager, SLOT(onWidgetVisibilityIsChanged(bool)));
connect(this, SIGNAL(requestGotoLocation(QString,int,int)),
manager, SLOT(gotoLocation(QString,int,int)));
connect(this, SIGNAL(requestGotoLocations(QList<QVariant>)),
manager, SLOT(gotoLocations(QList<QVariant>)));
connect(manager, SIGNAL(treeDataUpdate(QSharedPointer<QStandardItem>)),
this, SLOT(onDataUpdate(QSharedPointer<QStandardItem>)));
connect(this, SIGNAL(requestTreeDataUpdate()),
manager, SLOT(onRequestTreeDataUpdate()));
}
NavigationWidget::~NavigationWidget()
{
delete d_ptr->fullProjectsModeButton;
delete d_ptr->ui;
}
void NavigationWidget::hideEvent(QHideEvent *event)
{
emit visibilityChanged(false);
QWidget::hideEvent(event);
}
void NavigationWidget::showEvent(QShowEvent *event)
{
emit visibilityChanged(true);
// request to update to the current state - to be sure
emit requestTreeDataUpdate();
QWidget::showEvent(event);
}
QList<QToolButton *> NavigationWidget::createToolButtons()
{
QList<QToolButton *> list;
// full projects mode
if (!d_ptr->fullProjectsModeButton) {
// create a button
d_ptr->fullProjectsModeButton = new QToolButton();
d_ptr->fullProjectsModeButton->setIcon(
QIcon(QLatin1String(":/classview/images/hierarchicalmode.png")));
d_ptr->fullProjectsModeButton->setCheckable(true);
d_ptr->fullProjectsModeButton->setToolTip(tr("Show subprojects"));
// by default - not a flat mode
setFlatMode(false);
// connections
connect(d_ptr->fullProjectsModeButton, SIGNAL(toggled(bool)),
this, SLOT(onFullProjectsModeToggled(bool)));
}
list << d_ptr->fullProjectsModeButton;
return list;
}
bool NavigationWidget::flatMode() const
{
QTC_ASSERT(d_ptr->fullProjectsModeButton, return false);
// button is 'full projects mode' - so it has to be inverted
return !d_ptr->fullProjectsModeButton->isChecked();
}
void NavigationWidget::setFlatMode(bool flatMode)
{
QTC_ASSERT(d_ptr->fullProjectsModeButton, return);
// button is 'full projects mode' - so it has to be inverted
d_ptr->fullProjectsModeButton->setChecked(!flatMode);
}
void NavigationWidget::onFullProjectsModeToggled(bool state)
{
// button is 'full projects mode' - so it has to be inverted
Manager::instance()->setFlatMode(!state);
}
void NavigationWidget::onItemActivated(const QModelIndex &index)
{
if (!index.isValid())
return;
QList<QVariant> list = d_ptr->treeModel->data(index, Constants::SymbolLocationsRole).toList();
emit requestGotoLocations(list);
}
void NavigationWidget::onDataUpdate(QSharedPointer<QStandardItem> result)
{
if (result.isNull())
return;
// if this is 1st call
bool expandRootItems = false;
if (d_ptr->treeModel->invisibleRootItem()->rowCount() == 0)
expandRootItems = true;
QTime timer;
if (debug)
timer.start();
// update is received. root item must be updated - and received information
// might be just a root - if a lazy data population is enabled.
// so expanded items must be parsed and 'fetched'
fetchExpandedItems(result.data(), d_ptr->treeModel->invisibleRootItem());
d_ptr->treeModel->moveRootToTarget(result.data());
// expand top level projects
QModelIndex sessionIndex;
for (int i = 0; i < d_ptr->treeModel->rowCount(sessionIndex); ++i)
d_ptr->ui->treeView->expand(d_ptr->treeModel->index(i, 0, sessionIndex));
if (debug)
qDebug() << "Class View:" << QDateTime::currentDateTime().toString()
<< "TreeView is updated in" << timer.elapsed() << "msecs";
}
void NavigationWidget::fetchExpandedItems(QStandardItem *item, const QStandardItem *target) const
{
if (!item || !target)
return;
const QModelIndex &parent = d_ptr->treeModel->indexFromItem(target);
if (d_ptr->ui->treeView->isExpanded(parent))
Manager::instance()->fetchMore(item, true);
int itemIndex = 0;
int targetIndex = 0;
int itemRows = item->rowCount();
int targetRows = target->rowCount();
while (itemIndex < itemRows && targetIndex < targetRows) {
QStandardItem *itemChild = item->child(itemIndex);
const QStandardItem *targetChild = target->child(targetIndex);
const SymbolInformation &itemInf = Utils::symbolInformationFromItem(itemChild);
const SymbolInformation &targetInf = Utils::symbolInformationFromItem(targetChild);
if (itemInf < targetInf) {
++itemIndex;
} else if (itemInf == targetInf) {
fetchExpandedItems(itemChild, targetChild);
++itemIndex;
++targetIndex;
} else {
++targetIndex;
}
}
}
} // namespace Internal
} // namespace ClassView
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Denis Mingulov.
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**