You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
182 lines
0 B
182 lines
0 B
15 years ago
|
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
|
||
|
* 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
|
||
|
*****************************************************************************/
|
||
|
|
||
|
// vim: expandtab
|
||
|
|
||
|
#include "qwt_plot_dict.h"
|
||
|
|
||
|
class QwtPlotDict::PrivateData
|
||
|
{
|
||
|
public:
|
||
|
|
||
|
#if QT_VERSION < 0x040000
|
||
|
class ItemList: public QValueList<QwtPlotItem *>
|
||
|
#else
|
||
|
class ItemList: public QList<QwtPlotItem *>
|
||
|
#endif
|
||
|
{
|
||
|
public:
|
||
14 years ago
|
void insertItem(QwtPlotItem *item) {
|
||
15 years ago
|
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.
|
||
|
|
||
|
#ifdef __GNUC__
|
||
|
#endif
|
||
|
|
||
|
#if QT_VERSION < 0x040000
|
||
|
QValueListIterator<QwtPlotItem *> it;
|
||
|
#else
|
||
|
QList<QwtPlotItem *>::Iterator it;
|
||
|
#endif
|
||
14 years ago
|
for ( it = begin(); it != end(); ++it ) {
|
||
15 years ago
|
if ( *it == item )
|
||
|
return;
|
||
|
|
||
14 years ago
|
if ( (*it)->z() > item->z() ) {
|
||
15 years ago
|
insert(it, item);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
append(item);
|
||
|
}
|
||
|
|
||
14 years ago
|
void removeItem(QwtPlotItem *item) {
|
||
15 years ago
|
if ( item == NULL )
|
||
|
return;
|
||
|
|
||
|
int i = 0;
|
||
|
|
||
|
#if QT_VERSION < 0x040000
|
||
|
QValueListIterator<QwtPlotItem *> it;
|
||
|
#else
|
||
|
QList<QwtPlotItem *>::Iterator it;
|
||
|
#endif
|
||
14 years ago
|
for ( it = begin(); it != end(); ++it ) {
|
||
|
if ( item == *it ) {
|
||
15 years ago
|
#if QT_VERSION < 0x040000
|
||
|
remove(it);
|
||
|
#else
|
||
|
removeAt(i);
|
||
|
#endif
|
||
|
return;
|
||
|
}
|
||
|
i++;
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
ItemList itemList;
|
||
|
bool autoDelete;
|
||
|
};
|
||
|
|
||
14 years ago
|
/*!
|
||
|
Constructor
|
||
15 years ago
|
|
||
|
Auto deletion is enabled.
|
||
|
\sa setAutoDelete, attachItem
|
||
|
*/
|
||
|
QwtPlotDict::QwtPlotDict()
|
||
|
{
|
||
|
d_data = new QwtPlotDict::PrivateData;
|
||
|
d_data->autoDelete = true;
|
||
|
}
|
||
|
|
||
14 years ago
|
/*!
|
||
15 years ago
|
Destructor
|
||
|
|
||
|
If autoDelete is on, all attached items will be deleted
|
||
|
\sa setAutoDelete, autoDelete, attachItem
|
||
|
*/
|
||
|
QwtPlotDict::~QwtPlotDict()
|
||
|
{
|
||
|
detachItems(QwtPlotItem::Rtti_PlotItem, d_data->autoDelete);
|
||
|
delete d_data;
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
En/Disable Auto deletion
|
||
|
|
||
|
If Auto deletion is on all attached plot items will be deleted
|
||
|
in the destructor of QwtPlotDict. The default value is on.
|
||
|
|
||
|
\sa autoDelete, attachItem
|
||
|
*/
|
||
|
void QwtPlotDict::setAutoDelete(bool autoDelete)
|
||
|
{
|
||
|
d_data->autoDelete = autoDelete;
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
\return true if auto deletion is enabled
|
||
|
\sa setAutoDelete, attachItem
|
||
|
*/
|
||
|
bool QwtPlotDict::autoDelete() const
|
||
|
{
|
||
|
return d_data->autoDelete;
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
Attach/Detach a plot item
|
||
|
|
||
|
Attached items will be deleted in the destructor,
|
||
|
if auto deletion is enabled (default). Manually detached
|
||
|
items are not deleted.
|
||
|
|
||
|
\param item Plot item to attach/detach
|
||
|
\ on If true attach, else detach the item
|
||
|
|
||
|
\sa setAutoDelete, ~QwtPlotDict
|
||
|
*/
|
||
|
void QwtPlotDict::attachItem(QwtPlotItem *item, bool on)
|
||
|
{
|
||
|
if ( on )
|
||
|
d_data->itemList.insertItem(item);
|
||
|
else
|
||
|
d_data->itemList.removeItem(item);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
Detach items from the dictionary
|
||
|
|
||
14 years ago
|
\param rtti In case of QwtPlotItem::Rtti_PlotItem detach all items
|
||
15 years ago
|
otherwise only those items of the type rtti.
|
||
|
\param autoDelete If true, delete all detached items
|
||
|
*/
|
||
|
void QwtPlotDict::detachItems(int rtti, bool autoDelete)
|
||
|
{
|
||
|
PrivateData::ItemList list = d_data->itemList;
|
||
|
QwtPlotItemIterator it = list.begin();
|
||
14 years ago
|
while ( it != list.end() ) {
|
||
15 years ago
|
QwtPlotItem *item = *it;
|
||
|
|
||
|
++it; // increment before removing item from the list
|
||
|
|
||
14 years ago
|
if ( rtti == QwtPlotItem::Rtti_PlotItem || item->rtti() == rtti ) {
|
||
15 years ago
|
item->attach(NULL);
|
||
|
if ( autoDelete )
|
||
|
delete item;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//! \brief A QwtPlotItemList of all attached plot items.
|
||
|
///
|
||
|
/// Use caution when iterating these lists, as removing/detaching an item will
|
||
|
/// invalidate the iterator. Instead you can place pointers to objects to be
|
||
|
/// removed in a removal list, and traverse that list later.
|
||
|
//! \return List of all attached plot items.
|
||
|
const QwtPlotItemList &QwtPlotDict::itemList() const
|
||
|
{
|
||
|
return d_data->itemList;
|
||
|
}
|