2
KDChart - a multi-platform charting engine
5
/****************************************************************************
6
** Copyright (C) 2001-2003 Klarälvdalens Datakonsult AB. All rights reserved.
8
** This file is part of the KDChart library.
10
** This file may be used under the terms of the GNU General Public
11
** License versions 2.0 or 3.0 as published by the Free Software
12
** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
13
** included in the packaging of this file. Alternatively you may (at
14
** your option) use any later version of the GNU General Public
15
** License if such license has been publicly approved by
16
** Klarälvdalens Datakonsult AB (or its successors, if any).
18
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
19
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
20
** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights
21
** not expressly granted herein.
23
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
24
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26
**********************************************************************/
28
#include <KDChartIdMapper.h>
29
#include <KDChartIdMapper_p.h>
35
using namespace KDChart;
37
IdMapper::Private::Private( IdMapper* qq )
42
IdMapper::Private::~Private() {}
45
: _d( new Private( this ) )
47
d->m_counterTag = QString::fromLatin1( "::C_O_U_N_T_E_R" );
60
void IdMapper::clear()
62
// this space left empty intentionally
65
IdMapper* IdMapper::instance()
67
static IdMapper instance;
71
QString IdMapper::findOrMakeName(
73
const QString& baseName,
75
bool useMapOfKnownElements )
77
QString name = findName( id, useMapOfKnownElements );
78
wasFound = ! name.isNull();
81
QMap<const void*, QString>& map = useMapOfKnownElements ? d->m_mapOfKnownElements : d->m_unresolvedMap;
82
// check if we have a counter stored already - if not we add one
84
QString counterName( baseName + d->m_counterTag );
85
QMapIterator<const void*, QString> i( map );
86
while( i.hasNext() ) {
88
if( i.value() == counterName ){
89
// we may cast away constness, since this is not
90
// an external pointer but our own auxiliary counter entry
91
int* storedCount = const_cast<int*>( static_cast<const int*>( i.key() ) );
93
counter = *storedCount;
99
map[ p ] = counterName;
102
// store a new name using the counter value, and return it
103
name = baseName + ":" + QString::number( counter );
110
QString IdMapper::findName( const void* id,
111
bool useMapOfKnownElements )const
113
const QMap<const void*, QString>& map = useMapOfKnownElements ? d->m_mapOfKnownElements : d->m_unresolvedMap;
114
if( map.contains( id ) )
115
return map.value( id );
121
const void* IdMapper::findId( const QString& name,
122
bool useMapOfKnownElements )const
124
const QMap<const void*, QString>& map = useMapOfKnownElements ? d->m_mapOfKnownElements : d->m_unresolvedMap;
125
QMapIterator<const void*, QString> i( map );
126
while( i.hasNext() ) {
128
if( i.value() == name )
134
const QMap<const void*, QString> IdMapper::unresolvedMap()const
136
return d->m_unresolvedMap;
139
void IdMapper::debugOut()const
141
qDebug() << "IdMapper::debugOut():";
142
qDebug() << "map of known elements:";
143
QMapIterator<const void*, QString> i( d->m_mapOfKnownElements );
144
while( i.hasNext() ) {
146
qDebug() << "key:" << i.key() << "pointer:" << i.value();
148
qDebug() << "unresolved map:";
149
QMapIterator<const void*, QString> i2( d->m_unresolvedMap );
150
while( i2.hasNext() ) {
152
qDebug() << "key:" << i2.key() << "pointer:" << i2.value();