qwt_plot_dict.cpp
Go to the documentation of this file.
00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
00002  * Qwt Widget Library
00003  * Copyright (C) 1997   Josef Wilgen
00004  * Copyright (C) 2002   Uwe Rathmann
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the Qwt License, Version 1.0
00008  *****************************************************************************/
00009 
00010 #include "qwt_plot_dict.h"
00011 
00012 class QwtPlotDict::PrivateData
00013 {
00014 public:
00015 
00016     class ItemList: public QList<QwtPlotItem *>
00017     {
00018     public:
00019         void insertItem( QwtPlotItem *item )
00020         {
00021             if ( item == NULL )
00022                 return;
00023 
00024             QList<QwtPlotItem *>::iterator it =
00025                 qUpperBound( begin(), end(), item, LessZThan() );
00026             insert( it, item );
00027         }
00028 
00029         void removeItem( QwtPlotItem *item )
00030         {
00031             if ( item == NULL )
00032                 return;
00033 
00034             QList<QwtPlotItem *>::iterator it =
00035                 qLowerBound( begin(), end(), item, LessZThan() );
00036 
00037             for ( ; it != end(); ++it )
00038             {
00039                 if ( item == *it )
00040                 {
00041                     erase( it );
00042                     break;
00043                 }
00044             }
00045         }
00046     private:
00047         class LessZThan
00048         {
00049         public:
00050             inline bool operator()( const QwtPlotItem *item1,
00051                 const QwtPlotItem *item2 ) const
00052             {
00053                 return item1->z() < item2->z();
00054             }
00055         };
00056     };
00057 
00058     ItemList itemList;
00059     bool autoDelete;
00060 };
00061 
00068 QwtPlotDict::QwtPlotDict()
00069 {
00070     d_data = new QwtPlotDict::PrivateData;
00071     d_data->autoDelete = true;
00072 }
00073 
00080 QwtPlotDict::~QwtPlotDict()
00081 {
00082     detachItems( QwtPlotItem::Rtti_PlotItem, d_data->autoDelete );
00083     delete d_data;
00084 }
00085 
00094 void QwtPlotDict::setAutoDelete( bool autoDelete )
00095 {
00096     d_data->autoDelete = autoDelete;
00097 }
00098 
00103 bool QwtPlotDict::autoDelete() const
00104 {
00105     return d_data->autoDelete;
00106 }
00107 
00114 void QwtPlotDict::insertItem( QwtPlotItem *item )
00115 {
00116     d_data->itemList.insertItem( item );
00117 }
00118 
00125 void QwtPlotDict::removeItem( QwtPlotItem *item )
00126 {
00127     d_data->itemList.removeItem( item );
00128 }
00129 
00137 void QwtPlotDict::detachItems( int rtti, bool autoDelete )
00138 {
00139     PrivateData::ItemList list = d_data->itemList;
00140     QwtPlotItemIterator it = list.begin();
00141     while ( it != list.end() )
00142     {
00143         QwtPlotItem *item = *it;
00144 
00145         ++it; // increment before removing item from the list
00146 
00147         if ( rtti == QwtPlotItem::Rtti_PlotItem || item->rtti() == rtti )
00148         {
00149             item->attach( NULL );
00150             if ( autoDelete )
00151                 delete item;
00152         }
00153     }
00154 }
00155 
00165 const QwtPlotItemList &QwtPlotDict::itemList() const
00166 {
00167     return d_data->itemList;
00168 }
00169 
00175 QwtPlotItemList QwtPlotDict::itemList( int rtti ) const
00176 {
00177     if ( rtti == QwtPlotItem::Rtti_PlotItem )
00178         return d_data->itemList;
00179 
00180     QwtPlotItemList items;
00181 
00182     PrivateData::ItemList list = d_data->itemList;
00183     for ( QwtPlotItemIterator it = list.begin(); it != list.end(); ++it )
00184     {
00185         QwtPlotItem *item = *it;
00186         if ( item->rtti() == rtti )
00187             items += item;
00188     }
00189 
00190     return items;
00191 }


plotjuggler
Author(s): Davide Faconti
autogenerated on Fri Sep 1 2017 02:41:56