Loading...
Searching...
No Matches
qwt_polar_itemdict.cpp
/******************************************************************************
* QwtPolar Widget Library
* Copyright (C) 2008 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_polar_itemdict.h"
class QwtPolarItemDict::PrivateData
{
public:
class ItemList : public QList< QwtPolarItem* >
{
public:
void insertItem( QwtPolarItem* item )
{
if ( item == NULL )
return;
// Unfortunately there is no inSort operation
// for lists in Qt4. The implementation below
// is slow, but there shouldn't be many plot items.
QList< QwtPolarItem* >::Iterator it;
for ( it = begin(); it != end(); ++it )
{
if ( *it == item )
return;
if ( ( *it )->z() > item->z() )
{
insert( it, item );
return;
}
}
append( item );
}
void removeItem( QwtPolarItem* item )
{
if ( item == NULL )
return;
int i = 0;
QList< QwtPolarItem* >::Iterator it;
for ( it = begin(); it != end(); ++it )
{
if ( item == *it )
{
removeAt( i );
return;
}
i++;
}
}
};
ItemList itemList;
bool autoDelete;
};
QwtPolarItemDict::QwtPolarItemDict()
{
m_data = new QwtPolarItemDict::PrivateData;
m_data->autoDelete = true;
}
QwtPolarItemDict::~QwtPolarItemDict()
{
detachItems( QwtPolarItem::Rtti_PolarItem, m_data->autoDelete );
delete m_data;
}
void QwtPolarItemDict::setAutoDelete( bool autoDelete )
{
m_data->autoDelete = autoDelete;
}
bool QwtPolarItemDict::autoDelete() const
{
return m_data->autoDelete;
}
void QwtPolarItemDict::insertItem( QwtPolarItem* item )
{
m_data->itemList.insertItem( item );
}
void QwtPolarItemDict::removeItem( QwtPolarItem* item )
{
m_data->itemList.removeItem( item );
}
void QwtPolarItemDict::detachItems( int rtti, bool autoDelete )
{
PrivateData::ItemList list = m_data->itemList;
QwtPolarItemIterator it = list.constBegin();
while ( it != list.constEnd() )
{
QwtPolarItem* item = *it;
++it; // increment before removing item from the list
if ( rtti == QwtPolarItem::Rtti_PolarItem || item->rtti() == rtti )
{
item->attach( NULL );
if ( autoDelete )
delete item;
}
}
}
const QwtPolarItemList& QwtPolarItemDict::itemList() const
{
return m_data->itemList;
}
QList
Definition qwt_abstract_legend.h:17
QwtPolarItemDict::autoDelete
bool autoDelete() const
Definition qwt_polar_itemdict.cpp:106
QwtPolarItemDict::setAutoDelete
void setAutoDelete(bool)
Definition qwt_polar_itemdict.cpp:97
QwtPolarItemDict::itemList
const QwtPolarItemList & itemList() const
A QwtPolarItemList of all attached plot items.
Definition qwt_polar_itemdict.cpp:168
QwtPolarItemDict::QwtPolarItemDict
QwtPolarItemDict()
Definition qwt_polar_itemdict.cpp:71
QwtPolarItemDict::insertItem
void insertItem(QwtPolarItem *)
Definition qwt_polar_itemdict.cpp:117
QwtPolarItemDict::detachItems
void detachItems(int rtti=QwtPolarItem::Rtti_PolarItem, bool autoDelete=true)
Definition qwt_polar_itemdict.cpp:140
QwtPolarItemDict::~QwtPolarItemDict
~QwtPolarItemDict()
Definition qwt_polar_itemdict.cpp:83
QwtPolarItemDict::removeItem
void removeItem(QwtPolarItem *)
Definition qwt_polar_itemdict.cpp:128
QwtPolarItem
Base class for items on a polar plot.
Definition qwt_polar_item.h:38
QwtPolarItem::z
double z() const
Definition qwt_polar_item.cpp:129
QwtPolarItem::Rtti_PolarItem
@ Rtti_PolarItem
Unspecific value, that can be used, when it doesn't matter.
Definition qwt_polar_item.h:49
QwtPolarItem::attach
void attach(QwtPolarPlot *plot)
Attach the item to a plot.
Definition qwt_polar_item.cpp:74
QwtPolarItem::rtti
virtual int rtti() const
Definition qwt_polar_item.cpp:112