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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
|
/*
* KDevelop Class Browser
*
* Copyright 2007-2009 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 CLASSMODELNODE_H
#define CLASSMODELNODE_H
#include "classmodel.h"
#include <qicon.h>
#include <language/duchain/identifier.h>
#include <language/duchain/duchainpointer.h>
#include "classmodelnodescontroller.h"
class QTimer;
class NodesModelInterface;
namespace KDevelop
{
class ClassDeclaration;
class ClassFunctionDeclaration;
class ClassMemberDeclaration;
class Declaration;
}
namespace ClassModelNodes
{
/// Base node class - provides basic functionality.
class Node
{
public:
Node(const QString& a_displayName, NodesModelInterface* a_model);
virtual ~Node();
public: // Operations
/// Clear all the children from the node.
void clear();
/// Called by the model to collapse the node and remove sub-items if needed.
virtual void collapse() {};
/// Called by the model to expand the node and populate it with sub-nodes if needed.
virtual void expand() {};
/// Append a new child node to the list.
void addNode(Node* a_child);
/// Remove child node from the list and delete it.
void removeNode(Node* a_child);
/// Remove this node and delete it.
void removeSelf() { m_parentNode->removeNode(this); }
/// Called once the node has been populated to sort the entire tree / branch.
void recursiveSort();
public: // Info retrieval
/// Return the parent associated with this node.
Node* getParent() const { return m_parentNode; }
/// Get my index in the parent node
int row();
/// Return the display name for the node.
QString displayName() const { return m_displayName; }
/// Returns a list of child nodes
const QList<Node*>& getChildren() const { return m_children; }
/// Return an icon representation for the node.
/// @note It calls the internal getIcon and caches the result.
QIcon getCachedIcon();
public: // overridables
/// Return a score when sorting the nodes.
virtual int getScore() const = 0;
/// Return true if the node contains sub-nodes.
virtual bool hasChildren() const { return !m_children.empty(); }
/// We use this string when sorting items.
virtual QString getSortableString() const { return m_displayName; }
protected:
/// fill a_resultIcon with a display icon for the node.
/// @param a_resultIcon returned icon.
/// @return true if result was returned.
virtual bool getIcon(QIcon& a_resultIcon) = 0;
private:
Node* m_parentNode;
/// Called once the node has been populated to sort the entire tree / branch.
void recursiveSortInternal();
protected:
typedef QList< Node* > NodesList;
NodesList m_children;
QString m_displayName;
QIcon m_cachedIcon;
NodesModelInterface* m_model;
};
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/// Base class for nodes that generate and populate their child nodes dynamically
class DynamicNode : public Node
{
public:
DynamicNode(const QString& a_displayName, NodesModelInterface* a_model);
/// Return true if the node was populated already.
bool isPopulated() const { return m_populated; }
/// Populate the node and mark the flag - called from expand or can be used internally.
void performPopulateNode(bool a_forceRepopulate = false);
public: // Node overrides.
virtual void collapse();
virtual void expand();
virtual bool hasChildren() const;
protected: // overridables
/// Called by the framework when the node is about to be expanded
/// it should be populated with sub-nodes if applicable.
virtual void populateNode() {}
/// Called after the nodes have been removed.
/// It's for derived classes to clean cached data.
virtual void nodeCleared() {}
private:
bool m_populated;
/// Clear all the child nodes and mark flag.
void performNodeCleanup();
};
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/// Base class for nodes associated with a @ref KDevelop::QualifiedIdentifier
class IdentifierNode : public DynamicNode
{
public:
IdentifierNode(KDevelop::Declaration* a_decl, NodesModelInterface* a_model, const QString& a_displayName = QString());
public:
/// Returns the qualified identifier for this node by going through the tree
const KDevelop::IndexedQualifiedIdentifier& getIdentifier() const { return m_identifier; }
public: // Node overrides
virtual bool getIcon(QIcon& a_resultIcon);
public: // Overridables
/// Return the associated declaration
/// @note DU CHAIN MUST BE LOCKED FOR READ
virtual KDevelop::Declaration* getDeclaration();
private:
KDevelop::IndexedQualifiedIdentifier m_identifier;
KDevelop::IndexedDeclaration m_indexedDeclaration;
KDevelop::DeclarationPointer m_cachedDeclaration;
};
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/// A node that represents an enum value.
class EnumNode : public IdentifierNode
{
public:
EnumNode(KDevelop::Declaration* a_decl, NodesModelInterface* a_model);
public: // Node overrides
virtual int getScore() const { return 102; }
virtual bool getIcon(QIcon& a_resultIcon);
virtual void populateNode();
};
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/// Provides display for a single class.
class ClassNode : public IdentifierNode, public ClassModelNodeDocumentChangedInterface
{
public:
ClassNode(KDevelop::Declaration* a_decl, NodesModelInterface* a_model);
virtual ~ClassNode();
/// Lookup a contained class and return the related node.
/// @return the the node pointer or 0 if non was found.
ClassNode* findSubClass(const KDevelop::IndexedQualifiedIdentifier& a_id);
public: // Node overrides
virtual int getScore() const { return 300; }
virtual void populateNode();
virtual void nodeCleared();
virtual bool hasChildren() const { return true; }
protected: // ClassModelNodeDocumentChangedInterface overrides
virtual void documentChanged(const KDevelop::IndexedString& a_file);
private:
typedef QMap< uint, Node* > SubIdentifiersMap;
/// Set of known sub-identifiers. It's used for updates check.
SubIdentifiersMap m_subIdentifiers;
/// We use this variable to know if we've registered for change notification or not.
KDevelop::IndexedString m_cachedUrl;
/// Updates the node to reflect changes in the declaration.
/// @note DU CHAIN MUST BE LOCKED FOR READ
/// @return true if something was updated.
bool updateClassDeclarations();
/// Add "Base classes" and "Derived classes" folders, if needed
/// @return true if one of the folders was added.
bool addBaseAndDerived();
};
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/// Provides a display for a single class function.
class FunctionNode : public IdentifierNode
{
public:
FunctionNode(KDevelop::ClassFunctionDeclaration* a_decl, NodesModelInterface* a_model);
public: // Node overrides
virtual int getScore() const { return 400; }
virtual QString getSortableString() const { return m_sortableString; }
private:
QString m_sortableString;
};
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/// Provides display for a single class variable.
class ClassMemberNode : public IdentifierNode
{
public:
ClassMemberNode(KDevelop::ClassMemberDeclaration* a_decl, NodesModelInterface* a_model);
public: // Node overrides
virtual int getScore() const { return 500; }
virtual bool getIcon(QIcon& a_resultIcon);
};
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/// Provides a folder node with a static list of nodes.
class FolderNode : public Node
{
public:
FolderNode(const QString& a_displayName, NodesModelInterface* a_model);
public: // Node overrides
virtual bool getIcon(QIcon& a_resultIcon);
virtual int getScore() const { return 100; }
};
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/// Provides a folder node with a dynamic list of nodes.
class DynamicFolderNode : public DynamicNode
{
public:
DynamicFolderNode(const QString& a_displayName, NodesModelInterface* a_model);
public: // Node overrides
virtual bool getIcon(QIcon& a_resultIcon);
virtual int getScore() const { return 100; }
};
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/// Special folder - the parent is assumed to be a ClassNode.
/// It then displays the base classes for the class it sits in.
class BaseClassesFolderNode : public DynamicFolderNode
{
public:
BaseClassesFolderNode(NodesModelInterface* a_model);
public: // Node overrides
virtual void populateNode();
};
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/// Special folder - the parent is assumed to be a ClassNode.
/// It then displays list of derived classes from the parent class.
class DerivedClassesFolderNode : public DynamicFolderNode
{
public:
DerivedClassesFolderNode(NodesModelInterface* a_model);
public: // Node overrides
virtual void populateNode();
};
} // namespace classModelNodes
#endif
// kate: space-indent on; indent-width 2; tab-width 4; replace-tabs on; auto-insert-doxygen on
|