00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "metainfo.h"
00021 #include "gluonobject.h"
00022
00023 using namespace GluonCore;
00024
00025 class MetaInfo::MetaInfoPrivate
00026 {
00027 public:
00028 MetaInfoPrivate() {};
00029 ~MetaInfoPrivate() {};
00030
00031 QHash<QString, qreal> propertyRangeMin;
00032 QHash<QString, qreal> propertyRangeMax;
00033 QHash<QString, quint32> propertySteps;
00034 };
00035
00036 MetaInfo::MetaInfo( GluonObject* parent )
00037 : QObject( parent )
00038 , d( new MetaInfoPrivate() )
00039 {
00040 }
00041
00042 MetaInfo::MetaInfo( const GluonCore::MetaInfo& other )
00043 {
00044 delete d;
00045 }
00046
00047 MetaInfo::~MetaInfo()
00048 {
00049 }
00050
00051 void
00052 MetaInfo::setPropertyRange( const QString& property, qreal min, qreal max )
00053 {
00054 d->propertyRangeMin.insert( property, min );
00055 d->propertyRangeMax.insert( property, max );
00056 }
00057
00058 bool
00059 MetaInfo::hasPropertyRange( const QString& property ) const
00060 {
00061 return d->propertyRangeMin.keys().contains( property );
00062 }
00063
00064 qreal
00065 MetaInfo::propertyRangeMin( const QString& property ) const
00066 {
00067
00068
00069 return d->propertyRangeMin.value( property );
00070 }
00071
00072 qreal
00073 MetaInfo::propertyRangeMax( const QString& property ) const
00074 {
00075
00076
00077 return d->propertyRangeMax.value( property );
00078 }
00079
00080 void
00081 MetaInfo::removePropertyRange( const QString& property )
00082 {
00083 d->propertyRangeMin.remove( property );
00084 d->propertyRangeMax.remove( property );
00085 }
00086
00087 qreal
00088 MetaInfo::applyRange( const QString& property, qreal newValue ) const
00089 {
00090 if( !hasPropertyRange( property ) )
00091 return newValue;
00092 qBound( d->propertyRangeMin[property], newValue, d->propertyRangeMax[property] );
00093 return 0;
00094 }
00095
00096 void
00097 MetaInfo::setPropertySteps( const QString& property, quint32 steps )
00098 {
00099 d->propertySteps.insert( property, steps );
00100 }
00101
00102 bool
00103 MetaInfo::hasPropertySteps( const QString& property ) const
00104 {
00105 return d->propertySteps.keys().contains( property );
00106 }
00107
00108 quint32
00109 MetaInfo::propertySteps( const QString& property ) const
00110 {
00111
00112
00113 return d->propertySteps.value( property );
00114 }
00115
00116 void
00117 MetaInfo::removePropertySteps( const QString& property )
00118 {
00119 d->propertySteps.remove( property );
00120 }
00121
00122 qreal
00123 MetaInfo::applySteps( const QString& property, qreal newValue ) const
00124 {
00125 if( !hasPropertySteps( property ) || !hasPropertyRange( property ) )
00126 return newValue;
00127
00128
00129 const qreal step = ( d->propertyRangeMax.value( property ) - d->propertyRangeMin.value( property ) ) / d->propertySteps.value( property );
00130 return qRound64( newValue / step ) * step;
00131 }
00132
00133 qreal
00134 MetaInfo::applyRangeAndStep( const QString& property, qreal newValue ) const
00135 {
00136 if( !hasPropertySteps( property ) || !hasPropertyRange( property ) )
00137 return newValue;
00138
00139
00140 const qreal step = ( d->propertyRangeMax.value( property ) - d->propertyRangeMin.value( property ) ) / d->propertySteps.value( property );
00141 return qRound64( qBound( d->propertyRangeMin[property], newValue, d->propertyRangeMax[property] ) / step ) * step;
00142 }
00143
00144 #include "metainfo.moc"