qwt_plot_dict.cpp
Go to the documentation of this file.
1 /******************************************************************************
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 
59  ItemList itemList;
60  bool autoDelete;
61 };
62 
70 {
72  m_data->autoDelete = true;
73 }
74 
82 {
84  delete m_data;
85 }
86 
95 void QwtPlotDict::setAutoDelete( bool autoDelete )
96 {
98 }
99 
105 {
106  return m_data->autoDelete;
107 }
108 
116 {
117  m_data->itemList.insertItem( item );
118 }
119 
127 {
128  m_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 m_data->itemList;
169 }
170 
177 {
178  if ( rtti == QwtPlotItem::Rtti_PlotItem )
179  return m_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 }
QwtPlotDict::itemList
const QwtPlotItemList & itemList() const
A QwtPlotItemList of all attached plot items.
Definition: qwt_plot_dict.cpp:166
QwtPlotDict::removeItem
void removeItem(QwtPlotItem *)
Definition: qwt_plot_dict.cpp:126
qwt_plot_dict.h
QwtPlotDict::PrivateData::ItemList::LessZThan
Definition: qwt_plot_dict.cpp:62
QwtPlotDict::PrivateData::ItemList
Definition: qwt_plot_dict.cpp:24
QwtPlotDict::autoDelete
bool autoDelete() const
Definition: qwt_plot_dict.cpp:104
QwtPlotDict::PrivateData::autoDelete
bool autoDelete
Definition: qwt_plot_dict.cpp:67
QwtPlotDict::insertItem
void insertItem(QwtPlotItem *)
Definition: qwt_plot_dict.cpp:115
QList
Definition: qwt_abstract_legend.h:17
QwtPlotDict::PrivateData::ItemList::removeItem
void removeItem(QwtPlotItem *item)
Definition: qwt_plot_dict.cpp:44
QwtPlotDict::PrivateData::itemList
ItemList itemList
Definition: qwt_plot_dict.cpp:66
QwtPlotItem::Rtti_PlotItem
@ Rtti_PlotItem
Unspecific value, that can be used, when it doesn't matter.
Definition: qwt_plot_item.h:78
QwtPlotDict::setAutoDelete
void setAutoDelete(bool)
Definition: qwt_plot_dict.cpp:95
QwtPlotItem
Base class for items on the plot canvas.
Definition: qwt_plot_item.h:66
QwtPlotDict::PrivateData::ItemList::insertItem
void insertItem(QwtPlotItem *item)
Definition: qwt_plot_dict.cpp:34
QwtPlotDict::PrivateData::ItemList::LessZThan::operator()
bool operator()(const QwtPlotItem *item1, const QwtPlotItem *item2) const
Definition: qwt_plot_dict.cpp:65
QwtPlotDict::QwtPlotDict
QwtPlotDict()
Definition: qwt_plot_dict.cpp:69
QwtPlotDict::PrivateData
Definition: qwt_plot_dict.cpp:13
QwtPlotItemIterator
QList< QwtPlotItem * >::ConstIterator QwtPlotItemIterator
Definition: qwt_plot_dict.h:19
QwtPlotDict::detachItems
void detachItems(int rtti=QwtPlotItem::Rtti_PlotItem, bool autoDelete=true)
Definition: qwt_plot_dict.cpp:138
QwtPlotDict::~QwtPlotDict
virtual ~QwtPlotDict()
Definition: qwt_plot_dict.cpp:81
QwtPlotItem::attach
void attach(QwtPlot *plot)
Attach the item to a plot.
Definition: qwt_plot_item.cpp:98
QwtPlotItem::rtti
virtual int rtti() const
Definition: qwt_plot_item.cpp:136
QwtPlotDict::m_data
PrivateData * m_data
Definition: qwt_plot_dict.h:52
QwtPlotItem::z
double z() const
Definition: qwt_plot_item.cpp:152


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45