Overview.cpp 4.35 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11
12
13
14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
con's avatar
con committed
29
30
31
32

#include "Overview.h"
#include "NamePrettyPrinter.h"
#include "TypePrettyPrinter.h"
33
34
35

#include <Control.h>
#include <CoreTypes.h>
con's avatar
con committed
36
37
38
39
40
#include <FullySpecifiedType.h>

using namespace CPlusPlus;

Overview::Overview()
41
42
43
    : _markedArgument(0),
      _markedArgumentBegin(0),
      _markedArgumentEnd(0),
con's avatar
con committed
44
45
      _showArgumentNames(false),
      _showReturnTypes(false),
46
      _showFunctionSignatures(true),
47
      _showDefaultArguments(true)
con's avatar
con committed
48
49
50
51
52
53
{ }

Overview::~Overview()
{ }

bool Overview::showArgumentNames() const
hjk's avatar
hjk committed
54
55
56
{
    return _showArgumentNames;
}
con's avatar
con committed
57
58

void Overview::setShowArgumentNames(bool showArgumentNames)
hjk's avatar
hjk committed
59
60
61
{
    _showArgumentNames = showArgumentNames;
}
con's avatar
con committed
62
63

void Overview::setShowReturnTypes(bool showReturnTypes)
hjk's avatar
hjk committed
64
65
66
{
    _showReturnTypes = showReturnTypes;
}
con's avatar
con committed
67
68

bool Overview::showReturnTypes() const
hjk's avatar
hjk committed
69
70
71
{
    return _showReturnTypes;
}
con's avatar
con committed
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
unsigned Overview::markedArgument() const
{
    return _markedArgument;
}

void Overview::setMarkedArgument(unsigned position)
{
    _markedArgument = position;
}

int Overview::markedArgumentBegin() const
{
    return _markedArgumentBegin;
}

void Overview::setMarkedArgumentBegin(int begin)
{
    _markedArgumentBegin = begin;
}

int Overview::markedArgumentEnd() const
94
{
95
    return _markedArgumentEnd;
96
97
}

98
void Overview::setMarkedArgumentEnd(int end)
hjk's avatar
hjk committed
99
{
100
    _markedArgumentEnd = end;
hjk's avatar
hjk committed
101
}
con's avatar
con committed
102
103

bool Overview::showFunctionSignatures() const
hjk's avatar
hjk committed
104
105
106
{
    return _showFunctionSignatures;
}
con's avatar
con committed
107
108

void Overview::setShowFunctionSignatures(bool showFunctionSignatures)
hjk's avatar
hjk committed
109
110
111
{
    _showFunctionSignatures = showFunctionSignatures;
}
con's avatar
con committed
112

113
114
115
116
117
118
119
120
121
122
bool Overview::showDefaultArguments() const
{
    return _showDefaultArguments;
}

void Overview::setShowDefaultArguments(bool showDefaultArguments)
{
    _showDefaultArguments = showDefaultArguments;
}

Roberto Raggi's avatar
Roberto Raggi committed
123
QString Overview::prettyName(const Name *name) const
con's avatar
con committed
124
125
126
127
128
{
    NamePrettyPrinter pp(this);
    return pp(name);
}

129
130
131
132
133
134
135
136
137
138
139
140
QString Overview::prettyName(const QList<const Name *> &fullyQualifiedName) const
{
    QString result;
    const int size = fullyQualifiedName.size();
    for (int i = 0; i < size; ++i) {
        result.append(prettyName(fullyQualifiedName.at(i)));
        if (i < size - 1)
            result.append(QLatin1String("::"));
    }
    return result;
}

Roberto Raggi's avatar
Roberto Raggi committed
141
QString Overview::prettyType(const FullySpecifiedType &ty, const Name *name) const
hjk's avatar
hjk committed
142
143
144
{
    return prettyType(ty, prettyName(name));
}
con's avatar
con committed
145
146
147
148
149
150
151

QString Overview::prettyType(const FullySpecifiedType &ty,
                             const QString &name) const
{
    TypePrettyPrinter pp(this);
    return pp(ty, name);
}
152
153
154
155
156
157
158
159
160

/**
 * Pretty-prints the given fully-specified type, but replacing the contained
 * type with the given name.
 *
 * \param type the fully-specified type to convert to string
 * \param the name for the named-type to use
 * \param the control where the name is registered
 * \return the pretty-printed name
161
162
 *
 * \todo Remove this method, and do it "for real" using the class CPlusPlus::Rewrite.
163
164
165
166
167
168
169
170
171
172
173
 */
QString Overview::prettyTypeWithName(const FullySpecifiedType &type,
                                     const Name *name,
                                     Control *control)
{
    NamedType *namedTy = control->namedType(name);
    FullySpecifiedType newTy = type;
    newTy.setType(namedTy);

    return prettyType(newTy);
}