diff options
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/conditio.hxx | 4 | ||||
-rw-r--r-- | sc/source/core/data/conditio.cxx | 42 |
2 files changed, 46 insertions, 0 deletions
diff --git a/sc/inc/conditio.hxx b/sc/inc/conditio.hxx index 51b3dba67c87..cebb8f421fe8 100644 --- a/sc/inc/conditio.hxx +++ b/sc/inc/conditio.hxx @@ -74,6 +74,8 @@ enum ScConditionMode SC_COND_BOTTOM10, SC_COND_TOP_PERCENT, SC_COND_BOTTOM_PERCENT, + SC_COND_ABOVE_AVERAGE, + SC_COND_BELOW_AVERAGE, SC_COND_NONE }; @@ -257,6 +259,8 @@ private: bool IsTopNPercent( double nArg, const ScRangeList& rRanges ) const; bool IsBottomNElement( double nArg, const ScRangeList& rRanges ) const; bool IsBottomNPercent( double nArg, const ScRangeList& rRanges ) const; + bool IsAboveAverage( double nArg, const ScRangeList& rRanges ) const; + bool IsBelowAverage( double nArg, const ScRangeList& rRanges ) const; void FillCache(const ScRangeList& rRanges) const; diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx index 6e7724c47536..c0403f1d50f8 100644 --- a/sc/source/core/data/conditio.cxx +++ b/sc/source/core/data/conditio.cxx @@ -934,6 +934,40 @@ bool ScConditionEntry::IsBottomNPercent( double nArg, const ScRangeList& rRanges return true; } +bool ScConditionEntry::IsBelowAverage( double nArg, const ScRangeList& rRanges ) const +{ + FillCache( rRanges ); + + double nSum = 0; + for(ScConditionEntryCache::ValueCacheType::const_iterator itr = mpCache->maValues.begin(), + itrEnd = mpCache->maValues.end(); itr != itrEnd; ++itr) + { + nSum += itr->first * itr->second; + } + + if(nVal1) + return (nArg <= nSum/mpCache->nValueItems); + else + return (nArg < nSum/mpCache->nValueItems); +} + +bool ScConditionEntry::IsAboveAverage( double nArg, const ScRangeList& rRanges ) const +{ + FillCache( rRanges ); + + double nSum = 0; + for(ScConditionEntryCache::ValueCacheType::const_iterator itr = mpCache->maValues.begin(), + itrEnd = mpCache->maValues.end(); itr != itrEnd; ++itr) + { + nSum += itr->first * itr->second; + } + + if(nVal1) + return (nArg >= nSum/mpCache->nValueItems); + else + return (nArg > nSum/mpCache->nValueItems); +} + bool ScConditionEntry::IsValid( double nArg ) const { // Interpret muss schon gerufen sein @@ -1017,6 +1051,12 @@ bool ScConditionEntry::IsValid( double nArg ) const case SC_COND_BOTTOM_PERCENT: bValid = IsBottomNPercent( nArg, pCondFormat->GetRange() ); break; + case SC_COND_ABOVE_AVERAGE: + bValid = IsAboveAverage( nArg, pCondFormat->GetRange() ); + break; + case SC_COND_BELOW_AVERAGE: + bValid = IsBelowAverage( nArg, pCondFormat->GetRange() ); + break; default: OSL_FAIL("unbekannte Operation bei ScConditionEntry"); break; @@ -1077,6 +1117,8 @@ bool ScConditionEntry::IsValidStr( const String& rArg ) const case SC_COND_BOTTOM_PERCENT: case SC_COND_TOP10: case SC_COND_BOTTOM10: + case SC_COND_ABOVE_AVERAGE: + case SC_COND_BELOW_AVERAGE: return false; default: { |