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 "classviewparsertreeitem.h"
|
|
|
|
|
#include "classviewsymbollocation.h"
|
|
|
|
|
#include "classviewsymbolinformation.h"
|
|
|
|
|
#include "classviewconstants.h"
|
|
|
|
|
#include "classviewutils.h"
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QHash>
|
|
|
|
|
#include <QPair>
|
|
|
|
|
#include <QIcon>
|
|
|
|
|
#include <QStandardItem>
|
|
|
|
|
#include <QMutex>
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
2010-07-16 11:18:30 +02:00
|
|
|
|
|
|
|
|
namespace ClassView {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
///////////////////////////////// ParserTreeItemPrivate //////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-05-24 17:35:14 +02:00
|
|
|
\class ParserTreeItemPrivate
|
|
|
|
|
\brief The ParserTreeItemPrivate class defines private class data for
|
|
|
|
|
the ParserTreeItem class.
|
2010-07-16 11:18:30 +02:00
|
|
|
\sa ParserTreeItem
|
|
|
|
|
*/
|
2011-07-06 17:40:54 +02:00
|
|
|
class ParserTreeItemPrivate
|
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
|
|
|
//! symbol locations
|
|
|
|
|
QSet<SymbolLocation> symbolLocations;
|
|
|
|
|
|
2010-10-30 21:54:23 +02:00
|
|
|
//! symbol information
|
2010-07-16 11:18:30 +02:00
|
|
|
QHash<SymbolInformation, ParserTreeItem::Ptr> symbolInformations;
|
|
|
|
|
|
|
|
|
|
//! An icon
|
|
|
|
|
QIcon icon;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
///////////////////////////////// ParserTreeItem //////////////////////////////////
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
\class ParserTreeItem
|
|
|
|
|
\brief The ParserTreeItem class is an item for the internal Class View tree.
|
|
|
|
|
|
|
|
|
|
Not virtual - to speed up its work.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
ParserTreeItem::ParserTreeItem() :
|
2011-07-06 17:40:54 +02:00
|
|
|
d(new ParserTreeItemPrivate())
|
2010-07-16 11:18:30 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ParserTreeItem::~ParserTreeItem()
|
|
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
delete d;
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ParserTreeItem &ParserTreeItem::operator=(const ParserTreeItem &other)
|
|
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
d->symbolLocations = other.d->symbolLocations;
|
|
|
|
|
d->icon = other.d->icon;
|
|
|
|
|
d->symbolInformations.clear();
|
2010-07-16 11:18:30 +02:00
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Copies a parser tree item from the location specified by \a from to this
|
|
|
|
|
item.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void ParserTreeItem::copy(const ParserTreeItem::ConstPtr &from)
|
|
|
|
|
{
|
|
|
|
|
if (from.isNull())
|
|
|
|
|
return;
|
|
|
|
|
|
2011-07-06 17:40:54 +02:00
|
|
|
d->symbolLocations = from->d->symbolLocations;
|
|
|
|
|
d->icon = from->d->icon;
|
|
|
|
|
d->symbolInformations = from->d->symbolInformations;
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
\fn void copyTree(const ParserTreeItem::ConstPtr &from)
|
|
|
|
|
Copies a parser tree item with children from the location specified by
|
|
|
|
|
\a from to this item.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void ParserTreeItem::copyTree(const ParserTreeItem::ConstPtr &target)
|
|
|
|
|
{
|
|
|
|
|
if (target.isNull())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// copy content
|
2011-07-06 17:40:54 +02:00
|
|
|
d->symbolLocations = target->d->symbolLocations;
|
|
|
|
|
d->icon = target->d->icon;
|
|
|
|
|
d->symbolInformations.clear();
|
2010-07-16 11:18:30 +02:00
|
|
|
|
|
|
|
|
// reserve memory
|
|
|
|
|
// int amount = qMin(100 , target->d_ptr->symbolInformations.count() * 2);
|
|
|
|
|
// d_ptr->symbolInformations.reserve(amount);
|
|
|
|
|
|
|
|
|
|
// every child
|
2013-12-04 13:46:12 +01:00
|
|
|
CitSymbolInformations cur = target->d->symbolInformations.constBegin();
|
|
|
|
|
CitSymbolInformations end = target->d->symbolInformations.constEnd();
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2014-05-19 23:31:23 +03:00
|
|
|
for (; cur != end; ++cur) {
|
2010-07-16 11:18:30 +02:00
|
|
|
ParserTreeItem::Ptr item(new ParserTreeItem());
|
|
|
|
|
item->copyTree(cur.value());
|
|
|
|
|
appendChild(item, cur.key());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Adds information about symbol location from a \location.
|
|
|
|
|
\sa SymbolLocation, removeSymbolLocation, symbolLocations
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void ParserTreeItem::addSymbolLocation(const SymbolLocation &location)
|
|
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
d->symbolLocations.insert(location);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Adds information about symbol locations from \a locations.
|
|
|
|
|
\sa SymbolLocation, removeSymbolLocation, symbolLocations
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void ParserTreeItem::addSymbolLocation(const QSet<SymbolLocation> &locations)
|
|
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
d->symbolLocations.unite(locations);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Removes information about \a location.
|
|
|
|
|
\sa SymbolLocation, addSymbolLocation, symbolLocations
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void ParserTreeItem::removeSymbolLocation(const SymbolLocation &location)
|
|
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
d->symbolLocations.remove(location);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Removes information about \a locations.
|
|
|
|
|
\sa SymbolLocation, addSymbolLocation, symbolLocations
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void ParserTreeItem::removeSymbolLocations(const QSet<SymbolLocation> &locations)
|
|
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
d->symbolLocations.subtract(locations);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Gets information about symbol positions.
|
|
|
|
|
\sa SymbolLocation, addSymbolLocation, removeSymbolLocation
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
QSet<SymbolLocation> ParserTreeItem::symbolLocations() const
|
|
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
return d->symbolLocations;
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Appends the child item \a item to \a inf symbol information.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void ParserTreeItem::appendChild(const ParserTreeItem::Ptr &item, const SymbolInformation &inf)
|
|
|
|
|
{
|
|
|
|
|
// removeChild must be used to remove an item
|
|
|
|
|
if (item.isNull())
|
|
|
|
|
return;
|
|
|
|
|
|
2011-07-06 17:40:54 +02:00
|
|
|
d->symbolInformations[inf] = item;
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Removes the \a inf symbol information.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void ParserTreeItem::removeChild(const SymbolInformation &inf)
|
|
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
d->symbolInformations.remove(inf);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Returns the child item specified by \a inf symbol information.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
ParserTreeItem::Ptr ParserTreeItem::child(const SymbolInformation &inf) const
|
|
|
|
|
{
|
2013-12-04 13:46:12 +01:00
|
|
|
return d->symbolInformations.value(inf);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Returns the amount of children of the tree item.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
int ParserTreeItem::childCount() const
|
|
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
return d->symbolInformations.count();
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
\property QIcon::icon
|
|
|
|
|
\brief the icon assigned to the tree item
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
QIcon ParserTreeItem::icon() const
|
|
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
return d->icon;
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Sets the \a icon for the tree item.
|
|
|
|
|
*/
|
2010-07-16 11:18:30 +02:00
|
|
|
void ParserTreeItem::setIcon(const QIcon &icon)
|
|
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
d->icon = icon;
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Adds an internal state with \a target, which contains the correct current
|
|
|
|
|
state.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void ParserTreeItem::add(const ParserTreeItem::ConstPtr &target)
|
|
|
|
|
{
|
|
|
|
|
if (target.isNull())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// add locations
|
2011-07-06 17:40:54 +02:00
|
|
|
d->symbolLocations = d->symbolLocations.unite(target->d->symbolLocations);
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2010-10-30 21:54:23 +02:00
|
|
|
// add children
|
2010-07-16 11:18:30 +02:00
|
|
|
// every target child
|
2013-12-04 13:46:12 +01:00
|
|
|
CitSymbolInformations cur = target->d->symbolInformations.constBegin();
|
|
|
|
|
CitSymbolInformations end = target->d->symbolInformations.constEnd();
|
2012-11-28 20:44:03 +02:00
|
|
|
while (cur != end) {
|
2010-07-16 11:18:30 +02:00
|
|
|
const SymbolInformation &inf = cur.key();
|
|
|
|
|
const ParserTreeItem::Ptr &targetChild = cur.value();
|
2013-12-04 13:46:12 +01:00
|
|
|
|
|
|
|
|
ParserTreeItem::Ptr child = d->symbolInformations.value(inf);
|
|
|
|
|
if (!child.isNull()) {
|
|
|
|
|
child->add(targetChild);
|
2010-07-16 11:18:30 +02:00
|
|
|
} else {
|
|
|
|
|
ParserTreeItem::Ptr add(new ParserTreeItem());
|
|
|
|
|
add->copyTree(targetChild);
|
2011-07-06 17:40:54 +02:00
|
|
|
d->symbolInformations[inf] = add;
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
// next item
|
|
|
|
|
++cur;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Appends this item to the QStandardIten item \a item.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-12-04 13:46:12 +01:00
|
|
|
void ParserTreeItem::convertTo(QStandardItem *item) const
|
2010-07-16 11:18:30 +02:00
|
|
|
{
|
|
|
|
|
if (!item)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QMap<SymbolInformation, ParserTreeItem::Ptr> map;
|
|
|
|
|
|
|
|
|
|
// convert to map - to sort it
|
2013-12-04 13:46:12 +01:00
|
|
|
CitSymbolInformations curHash = d->symbolInformations.constBegin();
|
|
|
|
|
CitSymbolInformations endHash = d->symbolInformations.constEnd();
|
2012-11-28 20:44:03 +02:00
|
|
|
while (curHash != endHash) {
|
2010-07-16 11:18:30 +02:00
|
|
|
map.insert(curHash.key(), curHash.value());
|
|
|
|
|
++curHash;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-04 13:46:12 +01:00
|
|
|
typedef QMap<SymbolInformation, ParserTreeItem::Ptr>::const_iterator MapCitSymbolInformations;
|
2010-07-16 11:18:30 +02:00
|
|
|
// add to item
|
2013-12-04 13:46:12 +01:00
|
|
|
MapCitSymbolInformations cur = map.constBegin();
|
|
|
|
|
MapCitSymbolInformations end = map.constEnd();
|
2012-11-28 20:44:03 +02:00
|
|
|
while (cur != end) {
|
2010-07-16 11:18:30 +02:00
|
|
|
const SymbolInformation &inf = cur.key();
|
|
|
|
|
ParserTreeItem::Ptr ptr = cur.value();
|
|
|
|
|
|
|
|
|
|
QStandardItem *add = new QStandardItem();
|
|
|
|
|
Utils::setSymbolInformationToItem(inf, add);
|
|
|
|
|
if (!ptr.isNull()) {
|
|
|
|
|
// icon
|
|
|
|
|
add->setIcon(ptr->icon());
|
|
|
|
|
|
2014-10-17 10:22:26 +02:00
|
|
|
// draggable
|
|
|
|
|
if (!ptr->symbolLocations().isEmpty())
|
|
|
|
|
add->setFlags(add->flags() | Qt::ItemIsDragEnabled);
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
// locations
|
|
|
|
|
add->setData(Utils::locationsToRole(ptr->symbolLocations()),
|
|
|
|
|
Constants::SymbolLocationsRole);
|
|
|
|
|
}
|
|
|
|
|
item->appendRow(add);
|
|
|
|
|
++cur;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Checks \a item in a QStandardItemModel for lazy data population.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
bool ParserTreeItem::canFetchMore(QStandardItem *item) const
|
|
|
|
|
{
|
|
|
|
|
if (!item)
|
|
|
|
|
return false;
|
|
|
|
|
|
2013-12-04 13:46:12 +01:00
|
|
|
int storedChildren = item->rowCount();
|
|
|
|
|
int internalChildren = d->symbolInformations.count();
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2012-11-28 20:44:03 +02:00
|
|
|
if (storedChildren < internalChildren)
|
2010-07-16 11:18:30 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Performs lazy data population for \a item in a QStandardItemModel if needed.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void ParserTreeItem::fetchMore(QStandardItem *item) const
|
|
|
|
|
{
|
|
|
|
|
if (!item)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-12-04 13:46:12 +01:00
|
|
|
convertTo(item);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Debug dump.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void ParserTreeItem::debugDump(int ident) const
|
|
|
|
|
{
|
2013-12-04 13:46:12 +01:00
|
|
|
CitSymbolInformations curHash = d->symbolInformations.constBegin();
|
|
|
|
|
CitSymbolInformations endHash = d->symbolInformations.constEnd();
|
2012-11-28 20:44:03 +02:00
|
|
|
while (curHash != endHash) {
|
2010-07-16 11:18:30 +02:00
|
|
|
const SymbolInformation &inf = curHash.key();
|
2012-01-20 15:13:56 +01:00
|
|
|
qDebug() << QString(2*ident, QLatin1Char(' ')) << inf.iconType() << inf.name() << inf.type()
|
2010-07-16 11:18:30 +02:00
|
|
|
<< curHash.value().isNull();
|
|
|
|
|
if (!curHash.value().isNull())
|
|
|
|
|
curHash.value()->debugDump(ident + 1);
|
|
|
|
|
|
|
|
|
|
++curHash;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ClassView
|
|
|
|
|
|