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>
31 #include <language/duchain/duchainbase.h>
32 #include <language/duchain/duchainobserver.h>
34 class DUChainViewPlugin
;
42 class ProxyObject
: public KDevelop::DUChainBase
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
58 DUChainModel(DUChainViewPlugin
* parent
);
59 virtual ~DUChainModel();
61 void setTopContext(KDevelop::TopDUContextPointer context
);
63 KDevelop::DUChainBasePointer
* objectForIndex(const QModelIndex
& index
) const;
66 void documentActivated(KDevelop::IDocument
* document
);
67 void parseJobFinished(KDevelop::ParseJob
* job
);
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;
78 void doubleClicked ( const QModelIndex
& index
);
80 // Watch definition use chain changes
81 void branchAdded(KDevelop::DUContextPointer context
);
84 DUChainViewPlugin
* plugin() const;
86 int findInsertIndex(QList
<KDevelop::DUChainBasePointer
*>& list
, KDevelop::DUChainBase
* object
) const;
88 QModelIndex
createParentIndex(KDevelop::DUChainBasePointer
* type
) const;
91 KTextEditor::Cursor
nextItem(QVectorIterator
<T
*>& it
, bool initialise
) const
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();
111 // Make hasPrevious return false
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
));
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
;
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
;
140 // kate: space-indent on; indent-width 2; tab-width 4; replace-tabs on; auto-insert-doxygen on