summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-11-02 01:47:49 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-11-02 14:58:11 +0100
commit44990c104508c889e459ea6fea3cc13da2fc34a7 (patch)
treed36d4427c77b1407d03ca5e1dfa5f543a3d7e41b /sc
parentf1fdd5adb63f84fe7c65374b1a7cf9bd96e7d6b6 (diff)
implement above/below average conditional format
Change-Id: I9ea745818552a8e2553b0de17f2e83d8b8da3d3b
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/conditio.hxx4
-rw-r--r--sc/source/core/data/conditio.cxx42
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:
{