1
#ifndef oxygendatamap_h
2
#define oxygendatamap_h
4
//////////////////////////////////////////////////////////////////////////////
6
// stores event filters and maps widgets to timelines for animations
9
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
11
// Permission is hereby granted, free of charge, to any person obtaining a copy
12
// of this software and associated documentation files (the "Software"), to
13
// deal in the Software without restriction, including without limitation the
14
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
15
// sell copies of the Software, and to permit persons to whom the Software is
16
// furnished to do so, subject to the following conditions:
18
// The above copyright notice and this permission notice shall be included in
19
// all copies or substantial portions of the Software.
21
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28
//////////////////////////////////////////////////////////////////////////////
30
#include <QtCore/QObject>
31
#include <QtCore/QMap>
32
#include <QtCore/QWeakPointer>
34
#include <QtGui/QPaintDevice>
40
/*! it maps templatized data object to associated object */
41
template< typename K, typename T > class BaseDataMap: public QMap< const K*, QWeakPointer<T> >
47
typedef QWeakPointer<T> Value;
57
virtual ~BaseDataMap( void )
61
virtual typename QMap< Key, Value >::iterator insert( const Key& key, const Value& value, bool enabled = true )
63
if( value ) value.data()->setEnabled( enabled );
64
return QMap< Key, Value >::insert( key, value );
70
if( !( enabled() && key ) ) return Value();
71
if( key == _lastKey ) return _lastValue;
74
typename QMap<Key, Value>::iterator iter( QMap<Key, Value>::find( key ) );
75
if( iter != QMap<Key, Value>::end() ) out = iter.value();
83
bool unregisterWidget( Key key )
87
if( !key ) return false;
89
// clear last value if needed
93
if( _lastValue ) _lastValue.clear();
99
typename QMap<Key, Value>::iterator iter( QMap<Key, Value>::find( key ) );
100
if( iter == QMap<Key, Value>::end() ) return false;
102
// delete value from map if found
103
if( iter.value() ) iter.value().data()->deleteLater();
104
QMap<Key, Value>::erase( iter );
111
void setEnabled( bool enabled )
114
foreach( const Value& value, *this )
115
{ if( value ) value.data()->setEnabled( enabled ); }
119
bool enabled( void ) const
123
void setDuration( int duration ) const
125
foreach( const Value& value, *this )
126
{ if( value ) value.data()->setDuration( duration ); }
142
//! standard data map, using QObject as a key
143
template< typename T > class DataMap: public BaseDataMap< QObject, T >
153
virtual ~DataMap( void )
158
//! QPaintDevice based dataMap
159
template< typename T > class PaintDeviceDataMap: public BaseDataMap< QPaintDevice, T >
165
PaintDeviceDataMap( void )
169
virtual ~PaintDeviceDataMap( void )