1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
/*
* KDevelop Class Browser
*
* Copyright 2007-2008 Hamish Rodda <rodda@kde.org>
* Copyright 2009 Lior Mualem <lior.m.kde@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KDEVPLATFORM_CLASSMODEL_H
#define KDEVPLATFORM_CLASSMODEL_H
#include <QAbstractItemModel>
#include "classmodelnode.h"
#include <language/languageexport.h>
class ClassBrowserPlugin;
namespace KDevelop {
class TopDUContext;
class IDocument;
class DUContext;
class IProject;
class DUChainBase;
class IndexedQualifiedIdentifier;
}
namespace ClassModelNodes {
class Node;
class FilteredAllClassesFolder;
class FilteredProjectFolder;
class FolderNode;
class IdentifierNode;
}
/// The model interface accessible from the nodes.
class NodesModelInterface
{
public:
virtual ~NodesModelInterface();
public:
enum Feature {
AllProjectsClasses = 0x1,
BaseAndDerivedClasses = 0x2,
ClassInternals = 0x4
};
Q_DECLARE_FLAGS(Features, Feature)
virtual void nodesLayoutAboutToBeChanged(ClassModelNodes::Node* a_parent) = 0;
virtual void nodesLayoutChanged(ClassModelNodes::Node* a_parent) = 0;
virtual void nodesAboutToBeRemoved(ClassModelNodes::Node* a_parent, int a_first, int a_last) = 0;
virtual void nodesRemoved(ClassModelNodes::Node* a_parent) = 0;
virtual void nodesAboutToBeAdded(ClassModelNodes::Node* a_parent, int a_pos, int a_size) = 0;
virtual void nodesAdded(ClassModelNodes::Node* a_parent) = 0;
virtual Features features() const = 0;
};
/**
* @short A model that holds a convenient representation of the defined class in the project
*
* This model doesn't have much code in it, it mostly acts as a glue between the different
* nodes and the tree view.
*
* The nodes are defined in the namespace @ref ClassModelNodes
*/
class KDEVPLATFORMLANGUAGE_EXPORT ClassModel
: public QAbstractItemModel
, public NodesModelInterface
{
Q_OBJECT
public:
ClassModel();
~ClassModel() override;
public:
/// Retrieve the DU object related to the specified index.
/// @note DUCHAINS READER LOCK MUST BE TAKEN!
KDevelop::DUChainBase* duObjectForIndex(const QModelIndex& a_index);
/// Call this to retrieve the index for the node associated with the specified id.
QModelIndex indexForIdentifier(const KDevelop::IndexedQualifiedIdentifier& a_id);
/// Return the model index associated with the given node.
QModelIndex index(ClassModelNodes::Node* a_node) const;
inline void setFeatures(NodesModelInterface::Features features);
inline NodesModelInterface::Features features() const override { return m_features; }
public Q_SLOTS:
/// Call this to update the filter string for the search results folder.
void updateFilterString(const QString& a_newFilterString);
/// removes the project-specific node
void removeProjectNode(KDevelop::IProject* project);
/// adds the project-specific node
void addProjectNode(KDevelop::IProject* project);
private: // NodesModelInterface overrides
void nodesLayoutAboutToBeChanged(ClassModelNodes::Node* a_parent) override;
void nodesLayoutChanged(ClassModelNodes::Node* a_parent) override;
void nodesAboutToBeRemoved(ClassModelNodes::Node* a_parent, int a_first, int a_last) override;
void nodesRemoved(ClassModelNodes::Node* a_parent) override;
void nodesAboutToBeAdded(ClassModelNodes::Node* a_parent, int a_pos, int a_size) override;
void nodesAdded(ClassModelNodes::Node* a_parent) override;
private:
/// Main level node - it's usually invisible.
ClassModelNodes::Node* m_topNode;
ClassModelNodes::FilteredAllClassesFolder* m_allClassesNode;
QMap<KDevelop::IProject*, ClassModelNodes::FilteredProjectFolder*> m_projectNodes;
NodesModelInterface::Features m_features;
public Q_SLOTS:
/// This slot needs to be attached to collapsed signal in the tree view.
void collapsed(const QModelIndex& index);
/// This slot needs to be attached to expanded signal in the tree view.
void expanded(const QModelIndex& index);
public: // QAbstractItemModel overrides
QFlags<Qt::ItemFlag> flags(const QModelIndex&) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
bool hasChildren(const QModelIndex& parent = QModelIndex()) const override;
QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex& child) const override;
};
inline void ClassModel::setFeatures(Features features)
{ m_features = features; }
Q_DECLARE_OPERATORS_FOR_FLAGS(NodesModelInterface::Features)
#endif
|