Loading...
Searching...
No Matches
qwt_plot_dict.cpp
/******************************************************************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_plot_dict.h"
#include <algorithm>
class QwtPlotDict::PrivateData
{
public:
class ItemList : public QList< QwtPlotItem* >
{
public:
void insertItem( QwtPlotItem* item )
{
if ( item == NULL )
return;
QList< QwtPlotItem* >::iterator it =
std::upper_bound( begin(), end(), item, LessZThan() );
insert( it, item );
}
void removeItem( QwtPlotItem* item )
{
if ( item == NULL )
return;
QList< QwtPlotItem* >::iterator it =
std::lower_bound( begin(), end(), item, LessZThan() );
for ( ; it != end(); ++it )
{
if ( item == *it )
{
erase( it );
break;
}
}
}
private:
class LessZThan
{
public:
inline bool operator()( const QwtPlotItem* item1,
const QwtPlotItem* item2 ) const
{
return item1->z() < item2->z();
}
};
};
ItemList itemList;
bool autoDelete;
};
QwtPlotDict::QwtPlotDict()
{
m_data = new QwtPlotDict::PrivateData;
m_data->autoDelete = true;
}
QwtPlotDict::~QwtPlotDict()
{
detachItems( QwtPlotItem::Rtti_PlotItem, m_data->autoDelete );
delete m_data;
}
void QwtPlotDict::setAutoDelete( bool autoDelete )
{
m_data->autoDelete = autoDelete;
}
bool QwtPlotDict::autoDelete() const
{
return m_data->autoDelete;
}
void QwtPlotDict::insertItem( QwtPlotItem* item )
{
m_data->itemList.insertItem( item );
}
void QwtPlotDict::removeItem( QwtPlotItem* item )
{
m_data->itemList.removeItem( item );
}
void QwtPlotDict::detachItems( int rtti, bool autoDelete )
{
PrivateData::ItemList list = m_data->itemList;
QwtPlotItemIterator it = list.constBegin();
while ( it != list.constEnd() )
{
QwtPlotItem* item = *it;
++it; // increment before removing item from the list
if ( rtti == QwtPlotItem::Rtti_PlotItem || item->rtti() == rtti )
{
item->attach( NULL );
if ( autoDelete )
delete item;
}
}
}
const QwtPlotItemList& QwtPlotDict::itemList() const
{
return m_data->itemList;
}
QwtPlotItemList QwtPlotDict::itemList( int rtti ) const
{
if ( rtti == QwtPlotItem::Rtti_PlotItem )
return m_data->itemList;
QwtPlotItemList items;
PrivateData::ItemList list = m_data->itemList;
for ( QwtPlotItemIterator it = list.constBegin(); it != list.constEnd(); ++it )
{
QwtPlotItem* item = *it;
if ( item->rtti() == rtti )
items += item;
}
return items;
}
QList
Definition qwt_abstract_legend.h:17
QwtPlotDict::QwtPlotDict
QwtPlotDict()
Definition qwt_plot_dict.cpp:69
QwtPlotDict::setAutoDelete
void setAutoDelete(bool)
Definition qwt_plot_dict.cpp:95
QwtPlotDict::insertItem
void insertItem(QwtPlotItem *)
Definition qwt_plot_dict.cpp:115
QwtPlotDict::itemList
const QwtPlotItemList & itemList() const
A QwtPlotItemList of all attached plot items.
Definition qwt_plot_dict.cpp:166
QwtPlotDict::autoDelete
bool autoDelete() const
Definition qwt_plot_dict.cpp:104
QwtPlotDict::~QwtPlotDict
virtual ~QwtPlotDict()
Definition qwt_plot_dict.cpp:81
QwtPlotDict::removeItem
void removeItem(QwtPlotItem *)
Definition qwt_plot_dict.cpp:126
QwtPlotDict::detachItems
void detachItems(int rtti=QwtPlotItem::Rtti_PlotItem, bool autoDelete=true)
Definition qwt_plot_dict.cpp:138
QwtPlotItem
Base class for items on the plot canvas.
Definition qwt_plot_item.h:67
QwtPlotItem::z
double z() const
Definition qwt_plot_item.cpp:152
QwtPlotItem::rtti
virtual int rtti() const
Definition qwt_plot_item.cpp:136
QwtPlotItem::Rtti_PlotItem
@ Rtti_PlotItem
Unspecific value, that can be used, when it doesn't matter.
Definition qwt_plot_item.h:78
QwtPlotItem::attach
void attach(QwtPlot *plot)
Attach the item to a plot.
Definition qwt_plot_item.cpp:98