qwt_plot_dict.cpp
Go to the documentation of this file.
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 #include <algorithm>
12 
14 {
15 public:
16 
17  class ItemList: public QList<QwtPlotItem *>
18  {
19  public:
20  void insertItem( QwtPlotItem *item )
21  {
22  if ( item == NULL )
23  return;
24 
26  std::upper_bound( begin(), end(), item, LessZThan() );
27  insert( it, item );
28  }
29 
30  void removeItem( QwtPlotItem *item )
31  {
32  if ( item == NULL )
33  return;
34 
36  std::lower_bound( begin(), end(), item, LessZThan() );
37 
38  for ( ; it != end(); ++it )
39  {
40  if ( item == *it )
41  {
42  erase( it );
43  break;
44  }
45  }
46  }
47  private:
48  class LessZThan
49  {
50  public:
51  inline bool operator()( const QwtPlotItem *item1,
52  const QwtPlotItem *item2 ) const
53  {
54  return item1->z() < item2->z();
55  }
56  };
57  };
58 
60  bool autoDelete;
61 };
62 
70 {
72  d_data->autoDelete = true;
73 }
74 
82 {
84  delete d_data;
85 }
86 
96 {
98 }
99 
105 {
106  return d_data->autoDelete;
107 }
108 
116 {
117  d_data->itemList.insertItem( item );
118 }
119 
127 {
128  d_data->itemList.removeItem( item );
129 }
130 
138 void QwtPlotDict::detachItems( int rtti, bool autoDelete )
139 {
141  QwtPlotItemIterator it = list.constBegin();
142  while ( it != list.constEnd() )
143  {
144  QwtPlotItem *item = *it;
145 
146  ++it; // increment before removing item from the list
147 
148  if ( rtti == QwtPlotItem::Rtti_PlotItem || item->rtti() == rtti )
149  {
150  item->attach( NULL );
151  if ( autoDelete )
152  delete item;
153  }
154  }
155 }
156 
167 {
168  return d_data->itemList;
169 }
170 
177 {
178  if ( rtti == QwtPlotItem::Rtti_PlotItem )
179  return d_data->itemList;
180 
181  QwtPlotItemList items;
182 
184  for ( QwtPlotItemIterator it = list.constBegin(); it != list.constEnd(); ++it )
185  {
186  QwtPlotItem *item = *it;
187  if ( item->rtti() == rtti )
188  items += item;
189  }
190 
191  return items;
192 }
virtual int rtti() const
void insertItem(QwtPlotItem *)
const QwtPlotItemList & itemList() const
A QwtPlotItemList of all attached plot items.
PrivateData * d_data
Definition: qwt_plot_dict.h:52
QList< QwtPlotItem * >::ConstIterator QwtPlotItemIterator
Definition: qwt_plot_dict.h:19
void insertItem(QwtPlotItem *item)
bool autoDelete() const
void detachItems(int rtti=QwtPlotItem::Rtti_PlotItem, bool autoDelete=true)
double z() const
void setAutoDelete(bool)
void attach(QwtPlot *plot)
Attach the item to a plot.
bool operator()(const QwtPlotItem *item1, const QwtPlotItem *item2) const
void removeItem(QwtPlotItem *item)
virtual ~QwtPlotDict()
Base class for items on the plot canvas.
Definition: qwt_plot_item.h:65
void removeItem(QwtPlotItem *)
Unspecific value, that can be used, when it doesn&#39;t matter.
Definition: qwt_plot_item.h:77


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10