Even though the last alpha was .91 this one is going to be 82 as I'd like to have...
[kdevelopdvcssupport.git] / plugins / duchainviewer / duchainmodel.h
blobe3738e3e02831acb817fd8b9c1833f329a63f5e0
1 /*
2 * KDevelop DUChain viewer
4 * Copyright 2006 Hamish Rodda <rodda@kde.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Library General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef DUCHAINMODEL_H
23 #define DUCHAINMODEL_H
25 #include <QtCore/QAbstractItemModel>
26 #include <QtCore/QHash>
28 #include <ktexteditor/cursor.h>
29 #include <kurl.h>
31 #include <language/duchain/duchainbase.h>
32 #include <language/duchain/duchainobserver.h>
34 class DUChainViewPlugin;
36 namespace KDevelop {
37 class TopDUContext;
38 class IDocument;
39 class ParseJob;
42 class ProxyObject : public KDevelop::DUChainBase
44 public:
45 ProxyObject(KDevelop::DUChainBase* _parent, KDevelop::DUChainBase* _object);
47 virtual void preDelete() {};
49 KDevelop::DUChainBase* parent;
50 KDevelop::DUChainBase* object;
53 class DUChainModel : public QAbstractItemModel
55 Q_OBJECT
57 public:
58 DUChainModel(DUChainViewPlugin* parent);
59 virtual ~DUChainModel();
61 void setTopContext(KDevelop::TopDUContextPointer context);
63 KDevelop::DUChainBasePointer* objectForIndex(const QModelIndex& index) const;
65 public Q_SLOTS:
66 void documentActivated(KDevelop::IDocument* document);
67 void parseJobFinished(KDevelop::ParseJob* job);
69 public:
70 virtual int columnCount(const QModelIndex & parent = QModelIndex()) const;
71 virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
72 virtual QModelIndex parent(const QModelIndex & index) const;
73 virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
74 virtual int rowCount(const QModelIndex & parent = QModelIndex()) const;
75 //virtual bool hasChildren(const QModelIndex & parent = QModelIndex()) const;
77 private slots:
78 void doubleClicked ( const QModelIndex & index );
80 // Watch definition use chain changes
81 void branchAdded(KDevelop::DUContextPointer context);
83 private:
84 DUChainViewPlugin* plugin() const;
86 int findInsertIndex(QList<KDevelop::DUChainBasePointer*>& list, KDevelop::DUChainBase* object) const;
88 QModelIndex createParentIndex(KDevelop::DUChainBasePointer* type) const;
90 template <typename T>
91 KTextEditor::Cursor nextItem(QVectorIterator<T*>& it, bool initialise) const
93 if (initialise)
94 if (it.hasNext())
95 it.next();
97 if (it.hasPrevious())
98 return it.peekPrevious()->range().textRange().start();
100 return KTextEditor::Cursor::invalid();
103 template <typename T>
104 KDevelop::DUChainBase* item(QVectorIterator<T*>& it) const
106 Q_ASSERT(it.hasPrevious());
107 KDevelop::DUChainBase* item = it.peekPrevious();
108 if (it.hasNext())
109 it.next();
110 else
111 // Make hasPrevious return false
112 it.toFront();
114 return item;
117 template <typename T>
118 KDevelop::DUChainBase* proxyItem(KDevelop::DUChainBase* parent, QVectorIterator<T*>& it) const
120 KDevelop::DUChainBase* target = item(it);
121 KDevelop::DUChainBase* proxy = new ProxyObject(parent, target);
122 m_proxyObjects.insert(target, createPointerForObject(proxy));
123 return proxy;
126 QList<KDevelop::DUChainBasePointer*>* childItems(KDevelop::DUChainBasePointer* parent) const;
127 KDevelop::DUChainBasePointer* pointerForObject(KDevelop::DUChainBase* object) const;
128 KDevelop::DUChainBasePointer* createPointerForObject(KDevelop::DUChainBase* object) const;
130 KDevelop::TopDUContextPointer m_chain;
131 KUrl m_document;
132 mutable QHash<KDevelop::DUChainBase*, KDevelop::DUChainBasePointer*> m_knownObjects;
133 mutable QHash<KDevelop::DUChainBasePointer*, QList<KDevelop::DUChainBasePointer*>* > m_objectLists;
134 mutable QHash<KDevelop::DUChainBasePointer*, int > m_modelRow;
135 mutable QHash<KDevelop::DUChainBase*, KDevelop::DUChainBasePointer*> m_proxyObjects;
138 #endif
140 // kate: space-indent on; indent-width 2; tab-width 4; replace-tabs on; auto-insert-doxygen on