summaryrefslogtreecommitdiffstats
path: root/parts/classview/classtoolwidget.cpp
blob: 5aefe6e502220b06f0b8f735709bfc102c1abe24 (plain)
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
/***************************************************************************
 *   Copyright (C) 1999 by Jonas Nordin                                    *
 *   jonas.nordin@syncom.se                                                *
 *   Copyright (C) 2000-2001 by Bernd Gehrmann                             *
 *   bernd@kdevelop.org                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "classtoolwidget.h"

#include <kconfig.h>
#include <klocale.h>
#include <kglobal.h>
#include <kpopupmenu.h>
#include "classstore.h"


ClassToolWidget::ClassToolWidget(ClassViewPart *part, TQWidget *parent)
    : ClassTreeBase(part, parent, "class tool widget")
{}


ClassToolWidget::~ClassToolWidget()
{}


KPopupMenu *ClassToolWidget::createPopup()
{
    KPopupMenu *popup = contextItem? contextItem->createPopup() : 0;
    if (!popup) {
        popup = new KPopupMenu(this);
	popup->insertTitle(i18n("Class Tool"));
    }

    return popup;
}


void ClassToolWidget::insertClassAndClasses(ParsedClass *parsedClass, TQValueList<ParsedClass*> classList)
{
    ClassTreeItem *root = new ClassTreeClassItem(this, 0, parsedClass);
    
    ClassTreeItem *lastItem = 0;

    TQValueList<ParsedClass*>::ConstIterator it;
    for (it = classList.begin(); it != classList.end(); ++it) {
        lastItem = new ClassTreeClassItem(root, lastItem, *it);
        lastItem->setExpandable(false);
    }
    
    if (!root->firstChild())
        root->setExpandable(false);
    else
        root->setOpen(true);
}


void ClassToolWidget::insertClassAndClasses(ParsedClass *parsedClass, const TQPtrList<ParsedParent> &parentList)
{
    ClassTreeItem *root = new ClassTreeClassItem(this, 0, parsedClass);
    
    ClassTreeItem *lastItem = 0;

    TQPtrListIterator<ParsedParent> it(parentList);
    for (; it.current(); ++it) {
        ParsedClass *parentClass = m_part->classStore()->getClassByName((*it)->name());
        lastItem = new ClassTreeClassItem(root, lastItem, parentClass);
        lastItem->setExpandable(false);
    }
    
    if (!root->firstChild())
        root->setExpandable(false);
    else
        root->setOpen(true);
}


void ClassToolWidget::addClassAndAttributes(ParsedClass *parsedClass, PIAccess filter, ClassTreeItem **lastItem)
{
    *lastItem = new ClassTreeClassItem(this, *lastItem, parsedClass);

    ClassTreeItem *ilastItem = 0;
    
    TQValueList<ParsedAttribute*> attrList = parsedClass->getSortedAttributeList();
    TQValueList<ParsedAttribute*>::ConstIterator it;
    for (it = attrList.begin(); it != attrList.end(); ++it) {
        if (filter == (PIAccess)-1 || filter == (*it)->access())
            ilastItem = new ClassTreeAttrItem(*lastItem, ilastItem, *it);
    }

    if (!(*lastItem)->firstChild())
        (*lastItem)->setExpandable(false);
    else
        (*lastItem)->setOpen(true);
}


void ClassToolWidget::addClassAndMethods(ParsedClass *parsedClass, PIAccess filter, ClassTreeItem **lastItem)
{
    *lastItem = new ClassTreeClassItem(this, *lastItem, parsedClass);
    
    ClassTreeItem *ilastItem = 0;
    
    TQValueList<ParsedMethod*> methodList = parsedClass->getSortedMethodList();
    TQValueList<ParsedMethod*>::ConstIterator it;
    for (it = methodList.begin(); it != methodList.end(); ++it) {
        if (filter == (PIAccess)-1 || filter == (*it)->access())
            ilastItem = new ClassTreeMethodItem(*lastItem, ilastItem, *it);
    }
    
    if (!(*lastItem)->firstChild())
        (*lastItem)->setExpandable(false);
    else
        (*lastItem)->setOpen(true);
}


void ClassToolWidget::insertAllClassMethods(ParsedClass *parsedClass, PIAccess filter)
{
    ClassTreeItem *lastItem = 0;
    
    // First treat all parents.
    for ( ParsedParent *pParent = parsedClass->parents.first();
          pParent != 0;
          pParent = parsedClass->parents.next() )
        {
            ParsedClass *parentClass = m_part->classStore()->getClassByName(pParent->name());
            if (parentClass)
                addClassAndMethods(parentClass, filter, &lastItem);
        }
    
    // Add the current class
    addClassAndMethods(parsedClass, filter, &lastItem);
}


void ClassToolWidget::insertAllClassAttributes(ParsedClass *parsedClass, PIAccess filter)
{
    ClassTreeItem *lastItem = 0;
    // First treat all parents.
    for ( ParsedParent *pParent = parsedClass->parents.first();
          pParent != 0;
          pParent = parsedClass->parents.next() )
        {
            ParsedClass *parentClass = m_part->classStore()->getClassByName(pParent->name());
            if (parentClass)
                addClassAndAttributes(parentClass, filter, &lastItem);
        }
    
    // Add the current class
    addClassAndAttributes(parsedClass, filter, &lastItem);
}

#include "classtoolwidget.moc"