Doxygen
Toggle main menu visibility
Loading...
Searching...
No Matches
tooltip.cpp
Go to the documentation of this file.
1
/******************************************************************************
2
*
3
* Copyright (C) 1997-2020 by Dimitri van Heesch.
4
*
5
* Permission to use, copy, modify, and distribute this software and its
6
* documentation under the terms of the GNU General Public License is hereby
7
* granted. No representations are made about the suitability of this software
8
* for any purpose. It is provided "as is" without express or implied warranty.
9
* See the GNU General Public License for more details.
10
*
11
* Documents produced by Doxygen are derivative works derived from the
12
* input used in their production; they are not affected by this license.
13
*
14
*/
15
16
#include <map>
17
#include <memory>
18
#include <unordered_map>
19
#include <unordered_set>
20
#include <string>
21
#include <mutex>
22
23
#include "
tooltip.h
"
24
#include "
definition.h
"
25
#include "
outputlist.h
"
26
#include "
util.h
"
27
#include "
filedef.h
"
28
#include "
doxygen.h
"
29
#include "
config.h
"
30
31
static
std::mutex
g_tooltipsFileMutex
;
32
static
std::mutex
g_tooltipsTipMutex
;
33
static
std::unordered_map<int, std::unordered_set<std::string> >
g_tooltipsWrittenPerFile
;
34
35
class
TooltipManager::Private
36
{
37
public
:
38
std::map<std::string,const Definition*>
tooltipInfo
;
39
};
40
41
TooltipManager::TooltipManager
() :
p
(std::make_unique<
Private
>())
42
{
43
}
44
45
TooltipManager::~TooltipManager
()
46
{
47
}
48
49
static
QCString
escapeId
(
const
QCString
&s)
50
{
51
QCString
res=s;
52
for
(
size_t
i=0;i<res.
length
();i++)
if
(!
isId
(res[i])) res[i]=
'_'
;
53
return
res;
54
}
55
56
void
TooltipManager::addTooltip
(
const
Definition
*d)
57
{
58
bool
sourceTooltips =
Config_getBool
(SOURCE_TOOLTIPS);
59
if
(!sourceTooltips)
return
;
60
61
QCString
id
= d->
getOutputFileBase
();
62
int
i=
id
.
findRev
(
'/'
);
63
if
(i!=-1)
64
{
65
id
=
id
.right(
id
.length()-i-1);
// strip path (for CREATE_SUBDIRS=YES)
66
}
67
// In case an extension is present translate this extension to something understood by the tooltip handler
68
// otherwise extend t with a translated htmlFileExtension.
69
QCString
currentExtension =
getFileNameExtension
(
id
);
70
if
(currentExtension.
isEmpty
())
71
{
72
id
+=
escapeId
(
Doxygen::htmlFileExtension
);
73
}
74
else
75
{
76
id
=
stripExtensionGeneral
(
id
,currentExtension) +
escapeId
(currentExtension);
77
}
78
79
QCString
anc = d->
anchor
();
80
if
(!anc.
isEmpty
())
81
{
82
id
+=
"_"
+anc;
83
}
84
id
=
"a"
+ id;
85
p
->tooltipInfo.emplace(
id
.str(),d);
86
//printf("%p: addTooltip(%s)\n",this,id.data());
87
}
88
89
void
TooltipManager::writeTooltips
(
OutputCodeList
&ol)
90
{
91
std::unordered_map<int, std::unordered_set<std::string> >::iterator it;
92
// critical section
93
{
94
std::lock_guard<std::mutex> lock(
g_tooltipsFileMutex
);
95
96
int
id
= ol.
id
();
97
it =
g_tooltipsWrittenPerFile
.find(
id
);
98
if
(it==
g_tooltipsWrittenPerFile
.end())
// new file
99
{
100
it =
g_tooltipsWrittenPerFile
.emplace(
id
,std::unordered_set<std::string>()).first;
101
}
102
}
103
104
for
(
const
auto
&[name,d] :
p
->tooltipInfo)
105
{
106
bool
written =
false
;
107
108
// critical section
109
{
110
std::lock_guard<std::mutex> lock(
g_tooltipsTipMutex
);
111
written = it->second.find(name)!=it->second.end();
112
if
(!written)
// only write tooltips once
113
{
114
it->second.insert(name);
// remember we wrote this tooltip for the given file id
115
}
116
}
117
118
if
(!written)
119
{
120
//printf("%p: writeTooltips(%s) ol=%d\n",this,qPrint(name),ol.id());
121
DocLinkInfo
docInfo;
122
docInfo.
name
= d->qualifiedName();
123
docInfo.
ref
= d->getReference();
124
docInfo.
url
= d->getOutputFileBase();
125
docInfo.
anchor
= d->anchor();
126
SourceLinkInfo
defInfo;
127
if
(d->getBodyDef() && d->getStartBodyLine()!=-1)
128
{
129
defInfo.
file
= d->getBodyDef()->name();
130
defInfo.
line
= d->getStartBodyLine();
131
defInfo.
url
= d->getSourceFileBase();
132
defInfo.
anchor
= d->getSourceAnchor();
133
}
134
SourceLinkInfo
declInfo;
// TODO: fill in...
135
QCString
decl;
136
if
(d->definitionType()==
Definition::TypeMember
)
137
{
138
const
MemberDef
*md =
toMemberDef
(d);
139
if
(!md->
isAnonymous
())
140
{
141
decl = md->
declaration
();
142
}
143
}
144
ol.
writeTooltip
(name,
// id
145
docInfo,
// symName
146
decl,
// decl
147
d->briefDescriptionAsTooltip(),
// desc
148
defInfo,
149
declInfo
150
);
151
}
152
}
153
}
154
Definition
The common base class of all entity definitions found in the sources.
Definition
definition.h:77
Definition::anchor
virtual QCString anchor() const =0
Definition::isAnonymous
virtual bool isAnonymous() const =0
Definition::TypeMember
@ TypeMember
Definition
definition.h:88
Definition::getOutputFileBase
virtual QCString getOutputFileBase() const =0
Doxygen::htmlFileExtension
static QCString htmlFileExtension
Definition
doxygen.h:121
MemberDef
A model of a class/file/namespace member symbol.
Definition
memberdef.h:48
MemberDef::declaration
virtual QCString declaration() const =0
OutputCodeList
Class representing a list of different code generators.
Definition
outputlist.h:165
OutputCodeList::id
int id() const
Definition
outputlist.h:192
OutputCodeList::writeTooltip
void writeTooltip(const QCString &id, const DocLinkInfo &docInfo, const QCString &decl, const QCString &desc, const SourceLinkInfo &defInfo, const SourceLinkInfo &declInfo)
Definition
outputlist.h:260
QCString
This is an alternative implementation of QCString.
Definition
qcstring.h:101
QCString::length
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition
qcstring.h:166
QCString::isEmpty
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition
qcstring.h:163
QCString::findRev
int findRev(char c, int index=-1, bool cs=TRUE) const
Definition
qcstring.cpp:96
TooltipManager::Private
Definition
tooltip.cpp:36
TooltipManager::Private::tooltipInfo
std::map< std::string, const Definition * > tooltipInfo
Definition
tooltip.cpp:38
TooltipManager::~TooltipManager
~TooltipManager()
Definition
tooltip.cpp:45
TooltipManager::addTooltip
void addTooltip(const Definition *d)
add a tooltip for a given symbol definition
Definition
tooltip.cpp:56
TooltipManager::writeTooltips
void writeTooltips(OutputCodeList &ol)
write the list of all collected tooltip to the given outputs
Definition
tooltip.cpp:89
TooltipManager::p
std::unique_ptr< Private > p
Definition
tooltip.h:40
TooltipManager::TooltipManager
TooltipManager()
Definition
tooltip.cpp:41
config.h
Config_getBool
#define Config_getBool(name)
Definition
config.h:33
definition.h
doxygen.h
filedef.h
toMemberDef
MemberDef * toMemberDef(Definition *d)
Definition
memberdef.cpp:6521
outputlist.h
DocLinkInfo
Definition
outputgen.h:43
DocLinkInfo::anchor
QCString anchor
Definition
outputgen.h:47
DocLinkInfo::url
QCString url
Definition
outputgen.h:46
DocLinkInfo::name
QCString name
Definition
outputgen.h:44
DocLinkInfo::ref
QCString ref
Definition
outputgen.h:45
SourceLinkInfo
Definition
outputgen.h:51
SourceLinkInfo::file
QCString file
Definition
outputgen.h:52
SourceLinkInfo::anchor
QCString anchor
Definition
outputgen.h:56
SourceLinkInfo::line
int line
Definition
outputgen.h:53
SourceLinkInfo::url
QCString url
Definition
outputgen.h:55
g_tooltipsFileMutex
static std::mutex g_tooltipsFileMutex
Definition
tooltip.cpp:31
escapeId
static QCString escapeId(const QCString &s)
Definition
tooltip.cpp:49
g_tooltipsTipMutex
static std::mutex g_tooltipsTipMutex
Definition
tooltip.cpp:32
g_tooltipsWrittenPerFile
static std::unordered_map< int, std::unordered_set< std::string > > g_tooltipsWrittenPerFile
Definition
tooltip.cpp:33
tooltip.h
stripExtensionGeneral
QCString stripExtensionGeneral(const QCString &fName, const QCString &ext)
Definition
util.cpp:4914
getFileNameExtension
QCString getFileNameExtension(const QCString &fn)
Definition
util.cpp:5233
util.h
A bunch of utility functions.
isId
bool isId(int c)
Definition
util.h:207
src
tooltip.cpp
Generated by
1.17.0