source: ntrip/trunk/BNC/qwt/qwt_plot_dict.cpp@ 10230

Last change on this file since 10230 was 9383, checked in by stoecker, 4 years ago

update to qwt verion 6.1.1 to fix build with newer Qt5

File size: 4.4 KB
Line 
1/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
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 *****************************************************************************/
9
10#include "qwt_plot_dict.h"
11
12class QwtPlotDict::PrivateData
13{
14public:
15
16 class ItemList: public QList<QwtPlotItem *>
17 {
18 public:
19 void insertItem( QwtPlotItem *item )
20 {
21 if ( item == NULL )
22 return;
23
24 QList<QwtPlotItem *>::iterator it =
25 qUpperBound( begin(), end(), item, LessZThan() );
26 insert( it, item );
27 }
28
29 void removeItem( QwtPlotItem *item )
30 {
31 if ( item == NULL )
32 return;
33
34 QList<QwtPlotItem *>::iterator it =
35 qLowerBound( begin(), end(), item, LessZThan() );
36
37 for ( ; it != end(); ++it )
38 {
39 if ( item == *it )
40 {
41 erase( it );
42 break;
43 }
44 }
45 }
46 private:
47 class LessZThan
48 {
49 public:
50 inline bool operator()( const QwtPlotItem *item1,
51 const QwtPlotItem *item2 ) const
52 {
53 return item1->z() < item2->z();
54 }
55 };
56 };
57
58 ItemList itemList;
59 bool autoDelete;
60};
61
62/*!
63 Constructor
64
65 Auto deletion is enabled.
66 \sa setAutoDelete(), QwtPlotItem::attach()
67*/
68QwtPlotDict::QwtPlotDict()
69{
70 d_data = new QwtPlotDict::PrivateData;
71 d_data->autoDelete = true;
72}
73
74/*!
75 Destructor
76
77 If autoDelete() is on, all attached items will be deleted
78 \sa setAutoDelete(), autoDelete(), QwtPlotItem::attach()
79*/
80QwtPlotDict::~QwtPlotDict()
81{
82 detachItems( QwtPlotItem::Rtti_PlotItem, d_data->autoDelete );
83 delete d_data;
84}
85
86/*!
87 En/Disable Auto deletion
88
89 If Auto deletion is on all attached plot items will be deleted
90 in the destructor of QwtPlotDict. The default value is on.
91
92 \sa autoDelete(), insertItem()
93*/
94void QwtPlotDict::setAutoDelete( bool autoDelete )
95{
96 d_data->autoDelete = autoDelete;
97}
98
99/*!
100 \return true if auto deletion is enabled
101 \sa setAutoDelete(), insertItem()
102*/
103bool QwtPlotDict::autoDelete() const
104{
105 return d_data->autoDelete;
106}
107
108/*!
109 Insert a plot item
110
111 \param item PlotItem
112 \sa removeItem()
113 */
114void QwtPlotDict::insertItem( QwtPlotItem *item )
115{
116 d_data->itemList.insertItem( item );
117}
118
119/*!
120 Remove a plot item
121
122 \param item PlotItem
123 \sa insertItem()
124 */
125void QwtPlotDict::removeItem( QwtPlotItem *item )
126{
127 d_data->itemList.removeItem( item );
128}
129
130/*!
131 Detach items from the dictionary
132
133 \param rtti In case of QwtPlotItem::Rtti_PlotItem detach all items
134 otherwise only those items of the type rtti.
135 \param autoDelete If true, delete all detached items
136*/
137void QwtPlotDict::detachItems( int rtti, bool autoDelete )
138{
139 PrivateData::ItemList list = d_data->itemList;
140 QwtPlotItemIterator it = list.constBegin();
141 while ( it != list.constEnd() )
142 {
143 QwtPlotItem *item = *it;
144
145 ++it; // increment before removing item from the list
146
147 if ( rtti == QwtPlotItem::Rtti_PlotItem || item->rtti() == rtti )
148 {
149 item->attach( NULL );
150 if ( autoDelete )
151 delete item;
152 }
153 }
154}
155
156/*!
157 \brief A QwtPlotItemList of all attached plot items.
158
159 Use caution when iterating these lists, as removing/detaching an item will
160 invalidate the iterator. Instead you can place pointers to objects to be
161 removed in a removal list, and traverse that list later.
162
163 \return List of all attached plot items.
164*/
165const QwtPlotItemList &QwtPlotDict::itemList() const
166{
167 return d_data->itemList;
168}
169
170/*!
171 \return List of all attached plot items of a specific type.
172 \param rtti See QwtPlotItem::RttiValues
173 \sa QwtPlotItem::rtti()
174*/
175QwtPlotItemList QwtPlotDict::itemList( int rtti ) const
176{
177 if ( rtti == QwtPlotItem::Rtti_PlotItem )
178 return d_data->itemList;
179
180 QwtPlotItemList items;
181
182 PrivateData::ItemList list = d_data->itemList;
183 for ( QwtPlotItemIterator it = list.constBegin(); it != list.constEnd(); ++it )
184 {
185 QwtPlotItem *item = *it;
186 if ( item->rtti() == rtti )
187 items += item;
188 }
189
190 return items;
191}
Note: See TracBrowser for help on using the repository browser.