18#include <compiler.hxx>
21#include <document.hxx>
27#include <tokenarray.hxx>
39 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
57 mvCondFormatData.erase(std::remove_if(mvCondFormatData.begin(), mvCondFormatData.end(),
58 [pFormat](CondFormatData& r){ return r.mpFormat == pFormat; }),
59 mvCondFormatData.end());
70 SAL_WARN_IF(bDeleted,
"sc",
"conditional formats have been deleted because they contained empty range info");
88 for (
auto &aIter : *rAttrList)
90 switch (aIter.getToken())
93 sRange = aIter.toString();
112 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
150 switch(
t->GetType() )
180 switch(
t->GetOpCode() )
210 switch(
t->GetType() )
240 std::unique_ptr<ScConditionalFormat> pFormat(std::move(
mxFormat));
242 bool bEligibleForCache =
true;
243 bool bSingleRelativeReference =
false;
245 std::unique_ptr<ScTokenArray> pTokens;
246 for (
size_t nFormatEntryIx = 0; nFormatEntryIx < pFormat->size(); ++nFormatEntryIx)
248 auto pFormatEntry = pFormat->GetEntry(nFormatEntryIx);
251 if (pCondFormatEntry ==
nullptr ||
255 bEligibleForCache =
false;
260 OUString aSrcString = pCondFormatEntry->GetSrcString();
261 if ( !aSrcString.isEmpty() )
262 aSrcPos.
Parse( aSrcString, *pDoc );
265 pTokens = aComp.
CompileString( pCondFormatEntry->GetExpression(aSrcPos, 0),
"" );
272 if (pFormat->size() == 1 &&
273 pFormat->GetRange().size() == 1 &&
274 pFormat->GetRange()[0].aStart == aSrcPos &&
277 bSingleRelativeReference =
true;
281 bEligibleForCache =
false;
287 if (bEligibleForCache)
295 if (!aCacheEntry.mpFormat)
298 if (aCacheEntry.mpFormat->size() != pFormat->size())
302 for (
size_t nFormatEntryIx = 0; nFormatEntryIx < pFormat->size(); ++nFormatEntryIx)
304 auto pCacheFormatEntry = aCacheEntry.mpFormat->GetEntry(nFormatEntryIx);
305 auto pFormatEntry = pFormat->GetEntry(nFormatEntryIx);
306 if (pCacheFormatEntry->GetType() != pFormatEntry->GetType() ||
310 auto pCacheCondFormatEntry =
static_cast<const ScCondFormatEntry*
>(pCacheFormatEntry);
313 if (pCacheCondFormatEntry->GetStyle() != pCondFormatEntry->GetStyle())
319 if (bSingleRelativeReference)
321 if (aCacheEntry.mbSingleRelativeReference &&
322 pTokens->EqualTokens(aCacheEntry.mpTokens.get()))
327 else if (!pCacheCondFormatEntry->IsEqual(*pCondFormatEntry,
true))
332 if (nFormatEntryIx == pFormat->size() - 1)
335 aCacheEntry.mnAge = 0;
336 for (
size_t k = 0; k < pFormat->GetRange().size(); ++k)
337 aCacheEntry.mpFormat->GetRangeList().Join(pFormat->GetRange()[k]);
346 assert(pInsertedFormat && pInsertedFormat->
GetKey() ==
nIndex);
350 if (!bEligibleForCache)
354 sal_Int64 nOldestAge = -1;
355 size_t nIndexOfOldest = 0;
358 if (aCacheEntry.mnAge > nOldestAge)
360 nOldestAge = aCacheEntry.mnAge;
365 mrParent.
maCache[nIndexOfOldest].mbSingleRelativeReference = bSingleRelativeReference;
377 pColorScaleFormat(nullptr)
384 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
406 mpFormatData(nullptr),
410 OUString sPositiveColor;
411 OUString sNegativeColor;
413 OUString sAxisPosition;
419 if ( rAttrList.is() )
421 for (
auto &aIter : *rAttrList)
423 switch (aIter.getToken())
426 sPositiveColor = aIter.toString();
429 sGradient = aIter.toString();
432 sNegativeColor = aIter.toString();
435 sAxisPosition = aIter.toString();
438 sShowValue = aIter.toString();
441 sAxisColor = aIter.toString();
444 sMinLength = aIter.toString();
447 sMaxLength = aIter.toString();
458 if(!sGradient.isEmpty())
460 bool bGradient =
true;
465 if(!sPositiveColor.isEmpty())
470 if(!sNegativeColor.isEmpty())
480 if(!sAxisPosition.isEmpty())
482 if(sAxisPosition ==
"middle")
484 else if (sAxisPosition ==
"none")
488 if(!sAxisColor.isEmpty())
493 if(!sShowValue.isEmpty())
495 bool bShowValue =
true;
500 if (!sMinLength.isEmpty())
502 double nVal = sMinLength.toDouble();
506 if (!sMaxLength.isEmpty())
508 double nVal = sMaxLength.toDouble();
518 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
561 OUString aIconSetType, sShowValue;
562 if ( rAttrList.is() )
564 for (
auto &aIter : *rAttrList)
566 switch (aIter.getToken())
569 aIconSetType = aIter.toString();
572 sShowValue = aIter.toString();
582 for(; pMap->
pName; ++pMap)
584 OUString
aName = OUString::createFromAscii(pMap->
pName);
585 if(
aName ==aIconSetType)
595 if(!sShowValue.isEmpty())
597 bool bShowValue =
true;
610 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
635void GetConditionData(
const OUString& rValue,
ScConditionMode& eMode, OUString& rExpr1, OUString& rExpr2)
637 if(rValue.startsWith(
"unique"))
641 else if(rValue.startsWith(
"duplicate"))
645 else if(rValue.startsWith(
"between"))
649 const sal_Unicode* pEnd = pStr + rValue.getLength();
654 else if(rValue.startsWith(
"not-between"))
658 const sal_Unicode* pEnd = pStr + rValue.getLength();
663 else if(rValue.startsWith(
"<="))
665 rExpr1 = rValue.copy(2);
668 else if(rValue.startsWith(
">="))
670 rExpr1 = rValue.copy(2);
673 else if(rValue.startsWith(
"!="))
675 rExpr1 = rValue.copy(2);
678 else if(rValue.startsWith(
"<"))
680 rExpr1 = rValue.copy(1);
683 else if(rValue.startsWith(
"="))
685 rExpr1 = rValue.copy(1);
688 else if(rValue.startsWith(
">"))
690 rExpr1 = rValue.copy(1);
693 else if(rValue.startsWith(
"formula-is"))
697 const sal_Unicode* pEnd = pStr + rValue.getLength();
701 else if(rValue.startsWith(
"top-elements"))
705 const sal_Unicode* pEnd = pStr + rValue.getLength();
709 else if(rValue.startsWith(
"bottom-elements"))
713 const sal_Unicode* pEnd = pStr + rValue.getLength();
717 else if(rValue.startsWith(
"top-percent"))
721 const sal_Unicode* pEnd = pStr + rValue.getLength();
725 else if(rValue.startsWith(
"bottom-percent"))
729 const sal_Unicode* pEnd = pStr + rValue.getLength();
733 else if(rValue.startsWith(
"above-average"))
737 else if(rValue.startsWith(
"below-average"))
741 else if(rValue.startsWith(
"above-equal-average"))
745 else if(rValue.startsWith(
"below-equal-average"))
749 else if(rValue.startsWith(
"is-error"))
753 else if(rValue.startsWith(
"is-no-error"))
757 else if(rValue.startsWith(
"begins-with"))
762 const sal_Unicode* pEnd = pStr + rValue.getLength();
765 else if(rValue.startsWith(
"ends-with"))
770 const sal_Unicode* pEnd = pStr + rValue.getLength();
773 else if(rValue.startsWith(
"contains-text"))
778 const sal_Unicode* pEnd = pStr + rValue.getLength();
781 else if(rValue.startsWith(
"not-contains-text"))
786 const sal_Unicode* pEnd = pStr + rValue.getLength();
800 OUString sExpression;
804 if ( rAttrList.is() )
806 for (
auto &aIter : *rAttrList)
808 switch (aIter.getToken())
811 sExpression = aIter.toString();
817 sAddress = aIter.toString();
828 GetConditionData(sExpression,
eMode, aExpr1, aExpr2);
839void setColorEntryType(std::u16string_view rType,
ScColorScaleEntry* pEntry,
const OUString& rFormula,
842 if(rType == u
"minimum")
844 else if(rType == u
"maximum")
846 else if(rType == u
"percentile")
848 else if(rType == u
"percent")
850 else if(rType == u
"formula")
856 else if(rType == u
"auto-minimum")
858 else if(rType == u
"auto-maximum")
876 if ( rAttrList.is() )
878 for (
auto &aIter : *rAttrList)
880 switch (aIter.getToken())
883 sType = aIter.toString();
886 sVal = aIter.toString();
889 sColor = aIter.toString();
915 if ( rAttrList.is() )
917 for (
auto &aIter : *rAttrList)
919 switch (aIter.getToken())
922 sType = aIter.toString();
925 sVal = aIter.toString();
945 if(rString ==
"today")
947 else if(rString ==
"yesterday")
949 else if(rString ==
"tomorrow")
951 else if(rString ==
"last-7-days")
953 else if(rString ==
"this-week")
955 else if(rString ==
"last-week")
957 else if(rString ==
"next-week")
959 else if(rString ==
"this-month")
961 else if(rString ==
"last-month")
963 else if(rString ==
"next-month")
965 else if(rString ==
"this-year")
967 else if(rString ==
"last-year")
969 else if(rString ==
"next-year")
972 SAL_WARN(
"sc",
"unknown date type: " << rString);
983 OUString sDateType, sStyle;
984 if ( rAttrList.is() )
986 for (
auto &aIter : *rAttrList)
988 switch (aIter.getToken())
991 sDateType = aIter.toString();
1004 pFormatEntry->
SetDateType(getDateFromString(sDateType));
BaseContainerNodeSharedPtr & mrParent
SC_DLLPUBLIC ScRefFlags Parse(const OUString &, const ScDocument &, const Details &rDetails=detailsOOOa1, ExternalInfo *pExtInfo=nullptr, const css::uno::Sequence< css::sheet::ExternalLinkInfo > *pExternalLinks=nullptr, sal_Int32 *pSheetEndPos=nullptr, const OUString *pErrRef=nullptr)
void SetType(ScColorScaleEntryType eType)
void SetRepaintCallback(ScConditionalFormat *pParent)
void SetFormula(const OUString &rFormula, ScDocument &rDoc, const ScAddress &rAddr, formula::FormulaGrammar::Grammar eGrammar=formula::FormulaGrammar::GRAM_DEFAULT)
void SetGrammar(const formula::FormulaGrammar::Grammar eGrammar)
std::unique_ptr< ScTokenArray > CompileString(const OUString &rFormula)
Tokenize formula expression string into an array of tokens.
void SetDateType(condformat::ScCondFormatDateType eType)
void SetStyleName(const OUString &rStyleName)
void SetSrcString(const OUString &rNew)
ScRangeData * FindRangeNameBySheetAndIndex(SCTAB nTab, sal_uInt16 nIndex) const
Find a named expression / range name in either global or a local scope.
void SetCondFormList(ScConditionalFormatList *pList, SCTAB nTab)
SC_DLLPUBLIC void AddCondFormatData(const ScRangeList &rRange, SCTAB nTab, sal_uInt32 nIndex)
SC_DLLPUBLIC ScConditionalFormatList * GetCondFormList(SCTAB nTab) const
SC_DLLPUBLIC sal_uLong AddCondFormat(std::unique_ptr< ScConditionalFormat > pNew, SCTAB nTab)
SCTAB GetCurrentSheet() const
static bool GetRangeListFromString(ScRangeList &rRangeList, std::u16string_view rRangeListStr, const ScDocument &rDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Unicode cSeparator=' ', sal_Unicode cQuote='\'')
static SC_DLLPUBLIC OUString ProgrammaticToDisplayName(const OUString &rProgName, SfxStyleFamily nType)
ScXMLColorScaleFormatContext(ScXMLImport &rImport, ScConditionalFormat *pFormat)
ScColorScaleFormat * pColorScaleFormat
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
ScXMLColorScaleFormatEntryContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, ScColorScaleFormat *pFormat)
ScXMLCondContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, ScConditionalFormat *pFormat)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
ScXMLConditionalFormatContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, ScXMLConditionalFormatsContext &rParent)
std::unique_ptr< ScConditionalFormat > mxFormat
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
ScXMLConditionalFormatsContext & mrParent
virtual ~ScXMLConditionalFormatContext() override
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
std::vector< CondFormatData > mvCondFormatData
ScXMLConditionalFormatsContext(ScXMLImport &rImport)
std::array< CacheEntry, 4 > maCache
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
ScXMLDataBarFormatContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, ScConditionalFormat *pFormat)
ScDataBarFormatData * mpFormatData
ScConditionalFormat * mpParent
ScXMLDateContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, ScConditionalFormat *pFormat)
ScXMLFormattingEntryContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, ScColorScaleEntry *&pData)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
ScConditionalFormat * mpParent
ScIconSetFormatData * mpFormatData
ScXMLIconSetFormatContext(ScXMLImport &rImport, const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList, ScConditionalFormat *pFormat)
This class exists only to provide GetScImport() to its derived classes.
ScXMLImport & GetScImport()
ScDocument * GetDocument()
void SetNewCondFormatData()
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
static bool convertColor(sal_Int32 &rColor, std::u16string_view rValue)
static bool convertBool(bool &rBool, std::u16string_view rString)
constexpr OUStringLiteral sColor
RegionData_Impl * mpParent
#define LINK(Instance, Class, Member)
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
OUString getExpression(const sal_Unicode *&rpcString, const sal_Unicode *pcEnd, sal_Unicode cEndChar)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Single reference (one address) into the sheet.
#define XML_ELEMENT(prefix, name)