1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
3
* Copyright (C) 1997 Josef Wilgen
4
* Copyright (C) 2002 Uwe Rathmann
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the Qwt License, Version 1.0
8
*****************************************************************************/
12
#include "qwt_plot_dict.h"
14
class QwtPlotDict::PrivateData
18
#if QT_VERSION < 0x040000
19
class ItemList: public QValueList<QwtPlotItem *>
21
class ItemList: public QList<QwtPlotItem *>
25
void insertItem(QwtPlotItem *item)
30
// Unfortunately there is no inSort operation
31
// for lists in Qt4. The implementation below
32
// is slow, but there shouldn't be many plot items.
37
#if QT_VERSION < 0x040000
38
QValueListIterator<QwtPlotItem *> it;
40
QList<QwtPlotItem *>::Iterator it;
42
for ( it = begin(); it != end(); ++it )
47
if ( (*it)->z() > item->z() )
56
void removeItem(QwtPlotItem *item)
63
#if QT_VERSION < 0x040000
64
QValueListIterator<QwtPlotItem *> it;
66
QList<QwtPlotItem *>::Iterator it;
68
for ( it = begin(); it != end(); ++it )
72
#if QT_VERSION < 0x040000
91
Auto deletion is enabled.
92
\sa setAutoDelete, attachItem
94
QwtPlotDict::QwtPlotDict()
96
d_data = new QwtPlotDict::PrivateData;
97
d_data->autoDelete = true;
103
If autoDelete is on, all attached items will be deleted
104
\sa setAutoDelete, autoDelete, attachItem
106
QwtPlotDict::~QwtPlotDict()
108
detachItems(QwtPlotItem::Rtti_PlotItem, d_data->autoDelete);
113
En/Disable Auto deletion
115
If Auto deletion is on all attached plot items will be deleted
116
in the destructor of QwtPlotDict. The default value is on.
118
\sa autoDelete, attachItem
120
void QwtPlotDict::setAutoDelete(bool autoDelete)
122
d_data->autoDelete = autoDelete;
126
\return true if auto deletion is enabled
127
\sa setAutoDelete, attachItem
129
bool QwtPlotDict::autoDelete() const
131
return d_data->autoDelete;
135
Attach/Detach a plot item
137
Attached items will be deleted in the destructor,
138
if auto deletion is enabled (default). Manually detached
139
items are not deleted.
141
\param item Plot item to attach/detach
142
\ on If true attach, else detach the item
144
\sa setAutoDelete, ~QwtPlotDict
146
void QwtPlotDict::attachItem(QwtPlotItem *item, bool on)
149
d_data->itemList.insertItem(item);
151
d_data->itemList.removeItem(item);
155
Detach items from the dictionary
157
\param rtti In case of QwtPlotItem::Rtti_PlotItem detach all items
158
otherwise only those items of the type rtti.
159
\param autoDelete If true, delete all detached items
161
void QwtPlotDict::detachItems(int rtti, bool autoDelete)
163
PrivateData::ItemList list = d_data->itemList;
164
QwtPlotItemIterator it = list.begin();
165
while ( it != list.end() )
167
QwtPlotItem *item = *it;
169
++it; // increment before removing item from the list
171
if ( rtti == QwtPlotItem::Rtti_PlotItem || item->rtti() == rtti )
180
//! \brief A QwtPlotItemList of all attached plot items.
182
/// Use caution when iterating these lists, as removing/detaching an item will
183
/// invalidate the iterator. Instead you can place pointers to objects to be
184
/// removed in a removal list, and traverse that list later.
185
//! \return List of all attached plot items.
186
const QwtPlotItemList &QwtPlotDict::itemList() const
188
return d_data->itemList;