diff --git a/sc/qa/uitest/conditional_format/tdf100793.py b/sc/qa/uitest/conditional_format/tdf100793.py index 692c3c8109b2..f0d2c3854db7 100644 --- a/sc/qa/uitest/conditional_format/tdf100793.py +++ b/sc/qa/uitest/conditional_format/tdf100793.py @@ -32,7 +32,7 @@ class tdf100793(UITestCase): # check that we have exactly one conditional formats in the beginning xList = xCondFormatMgr.getChild("CONTAINER") list_state = get_state_as_dict(xList) - self.assertEqual(list_state['Children'], '1') + self.assertEqual(list_state['Children'], '3') #3) Click Edit & try to change to intended one, F18:K33 xEditBtn = xCondFormatMgr.getChild("edit") @@ -65,7 +65,7 @@ class tdf100793(UITestCase): # and still only 1 conditional format in the document xList = xCondFormatMgr.getChild("CONTAINER") list_state = get_state_as_dict(xList) - self.assertEqual(list_state['Children'], '1') + self.assertEqual(list_state['Children'], '3') self.assertEqual(conditional_format_list.getLength(), 1) diff --git a/sc/qa/uitest/conditional_format/tdf105544.py b/sc/qa/uitest/conditional_format/tdf105544.py index b172d4067a1d..3e5fd6730277 100644 --- a/sc/qa/uitest/conditional_format/tdf105544.py +++ b/sc/qa/uitest/conditional_format/tdf105544.py @@ -27,7 +27,7 @@ class tdf105544(UITestCase): # check that we have exactly four conditional formats in the beginning xList = xCondFormatMgr.getChild("CONTAINER") list_state = get_state_as_dict(xList) - self.assertEqual(list_state['Children'], '4') + self.assertEqual(list_state['Children'], '5') #select B3:B37 range and click edit, then click yes xList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "DOWN"})) #2nd position in the list @@ -41,7 +41,7 @@ class tdf105544(UITestCase): # check again that we still have 4 entry in the list xList = xCondFormatMgr.getChild("CONTAINER") list_state = get_state_as_dict(xList) - self.assertEqual(list_state['Children'], '4') + self.assertEqual(list_state['Children'], '5') # close the conditional format manager xOKBtn = xCondFormatMgr.getChild("ok") diff --git a/sc/qa/uitest/pasteSpecial/tdf86253.py b/sc/qa/uitest/pasteSpecial/tdf86253.py index 6e6e1bcd4983..c405a24ccdfe 100644 --- a/sc/qa/uitest/pasteSpecial/tdf86253.py +++ b/sc/qa/uitest/pasteSpecial/tdf86253.py @@ -44,7 +44,7 @@ class tdf86253(UITestCase): # check that we have exactly 1 conditional format and range is C1:C17 xList = xCondFormatMgr.getChild("CONTAINER") list_state = get_state_as_dict(xList) - self.assertEqual(list_state['Children'], '1') + self.assertEqual(list_state['Children'], '2') # We can now display both condition seprate on same range xTreeEntry = xList.getChild('0') self.assertEqual(get_state_as_dict(xTreeEntry)["Text"], "A1:A6,C1:C17\tCell value >= 0") diff --git a/sc/source/ui/condformat/condformathelper.cxx b/sc/source/ui/condformat/condformathelper.cxx index 29c397b4b629..03623db407d1 100644 --- a/sc/source/ui/condformat/condformathelper.cxx +++ b/sc/source/ui/condformat/condformathelper.cxx @@ -136,68 +136,67 @@ OUString getDateString(sal_Int32 nIndex) } -OUString ScCondFormatHelper::GetExpression(const ScConditionalFormat& rFormat, const ScAddress& rPos) +OUString ScCondFormatHelper::GetExpression(const ScFormatEntry* rEntry, const ScAddress& rPos) { OUStringBuffer aBuffer; - if(!rFormat.IsEmpty()) + switch (rEntry->GetType()) { - switch(rFormat.GetEntry(0)->GetType()) + case ScFormatEntry::Type::Condition: + case ScFormatEntry::Type::ExtCondition: { - case ScFormatEntry::Type::Condition: - case ScFormatEntry::Type::ExtCondition: + const ScConditionEntry* pEntry = static_cast(rEntry); + ScConditionMode eMode = pEntry->GetOperation(); + if (eMode == ScConditionMode::Direct) + { + aBuffer.append(getTextForType(FORMULA) + " " + pEntry->GetExpression(rPos, 0)); + } + else + { + aBuffer.append(getTextForType(CONDITION) + " " + + getExpression(static_cast(eMode)) + " "); + if (eMode == ScConditionMode::Between || eMode == ScConditionMode::NotBetween) { - const ScConditionEntry* pEntry = static_cast(rFormat.GetEntry(0)); - ScConditionMode eMode = pEntry->GetOperation(); - if(eMode == ScConditionMode::Direct) - { - aBuffer.append(getTextForType(FORMULA) - + " " - + pEntry->GetExpression(rPos, 0)); - } - else - { - aBuffer.append(getTextForType(CONDITION) - + " " - + getExpression(static_cast(eMode)) - + " "); - if(eMode == ScConditionMode::Between || eMode == ScConditionMode::NotBetween) - { - aBuffer.append(pEntry->GetExpression(rPos, 0) - + " " - + ScResId(STR_COND_AND) - + " " - + pEntry->GetExpression(rPos, 1)); - } - else if(eMode <= ScConditionMode::NotEqual || eMode >= ScConditionMode::BeginsWith) - { - aBuffer.append(pEntry->GetExpression(rPos, 0)); - } - } + aBuffer.append(pEntry->GetExpression(rPos, 0) + " " + ScResId(STR_COND_AND) + + " " + pEntry->GetExpression(rPos, 1)); } - - break; - case ScFormatEntry::Type::Databar: - aBuffer.append(getTextForType(DATABAR)); - break; - case ScFormatEntry::Type::Colorscale: - aBuffer.append(getTextForType(COLORSCALE)); - break; - case ScFormatEntry::Type::Iconset: - aBuffer.append(getTextForType(ICONSET)); - break; - case ScFormatEntry::Type::Date: + else if (eMode <= ScConditionMode::NotEqual || eMode >= ScConditionMode::BeginsWith) { - sal_Int32 nDateEntry = static_cast(static_cast(rFormat.GetEntry(0))->GetDateType()); - aBuffer.append(getTextForType(DATE) - + " " - + getDateString(nDateEntry)); + aBuffer.append(pEntry->GetExpression(rPos, 0)); } - break; + } } + + break; + case ScFormatEntry::Type::Databar: + aBuffer.append(getTextForType(DATABAR)); + break; + case ScFormatEntry::Type::Colorscale: + aBuffer.append(getTextForType(COLORSCALE)); + break; + case ScFormatEntry::Type::Iconset: + aBuffer.append(getTextForType(ICONSET)); + break; + case ScFormatEntry::Type::Date: + { + sal_Int32 nDateEntry = static_cast( + static_cast(rEntry)->GetDateType()); + aBuffer.append(getTextForType(DATE) + " " + getDateString(nDateEntry)); + } + break; } return aBuffer.makeStringAndClear(); } +OUString ScCondFormatHelper::GetExpression(const ScConditionalFormat& rFormat, + const ScAddress& rPos) +{ + if (!rFormat.IsEmpty()) + { + return ScCondFormatHelper::GetExpression(rFormat.GetEntry(0), rPos); + } + return ""; +} + OUString ScCondFormatHelper::GetExpression( ScCondFormatEntryType eType, sal_Int32 nIndex, std::u16string_view aStr1, std::u16string_view aStr2 ) { diff --git a/sc/source/ui/condformat/condformatmgr.cxx b/sc/source/ui/condformat/condformatmgr.cxx index 5dd7d2142b25..ff7f9889afaf 100644 --- a/sc/source/ui/condformat/condformatmgr.cxx +++ b/sc/source/ui/condformat/condformatmgr.cxx @@ -22,7 +22,19 @@ #include #include #include -#include +#include + +namespace +{ +OUString generateEntryId(sal_uInt32 key, sal_uInt32 index) +{ + return OUString::number(key) + "_" + OUString::number(index); +} + +sal_Int32 getKeyFromId(std::u16string_view id) { return o3tl::toInt32(o3tl::getToken(id, 0, '_')); } + +sal_Int32 getEntryIndexFromId(std::u16string_view id) { return o3tl::toInt32(o3tl::getToken(id, 1, '_')); } +} ScCondFormatManagerWindow::ScCondFormatManagerWindow(weld::TreeView& rTreeView, ScDocument& rDoc, ScConditionalFormatList* pFormatList) @@ -51,9 +63,14 @@ void ScCondFormatManagerWindow::Init() { const ScRangeList& aRange = rItem->GetRange(); aRange.Format(sRangeStr, ScRefFlags::VALID, mrDoc, mrDoc.GetAddressConvention()); - mrTreeView.append(OUString::number(rItem->GetKey()), sRangeStr); - mrTreeView.set_text(nRow, ScCondFormatHelper::GetExpression(*rItem, aRange.GetTopLeftCorner()), 1); - ++nRow; + for (size_t i = 0; i < rItem->size(); i++) + { + mrTreeView.append(generateEntryId(rItem->GetKey(), i), sRangeStr); + mrTreeView.set_text(nRow++, + ScCondFormatHelper::GetExpression(rItem->GetEntry(i), + aRange.GetTopLeftCorner()), + 1); + } } } @@ -81,8 +98,19 @@ ScConditionalFormat* ScCondFormatManagerWindow::GetSelection() if (nEntry == -1) return nullptr; - sal_Int32 nIndex = mrTreeView.get_id(nEntry).toInt32(); - return mpFormatList->GetFormat(nIndex); + sal_Int32 nKey = getKeyFromId(mrTreeView.get_id(nEntry)); + return mpFormatList->GetFormat(nKey); +} + +const ScFormatEntry* ScCondFormatManagerWindow::GetSelectedEntry() +{ + OUString id = mrTreeView.get_selected_id(); + if (id.isEmpty()) + return nullptr; + + sal_Int32 nKey = getKeyFromId(id); + sal_Int32 nEntryIndex = getEntryIndexFromId(id); + return mpFormatList->GetFormat(nKey)->GetEntry(nEntryIndex); } void ScCondFormatManagerWindow::setColSizes() @@ -252,12 +280,7 @@ IMPL_LINK_NOARG(ScCondFormatManagerDlg, ComboHdl, weld::ComboBox&, void) IMPL_LINK_NOARG(ScCondFormatManagerDlg, EntryFocus, weld::TreeView&, void) { - ScConditionalFormat* conditionFrmt = m_xCtrlManager->GetSelection(); - - if (!conditionFrmt) - return; - - const ScFormatEntry* entry = conditionFrmt->GetEntry(0); + const ScFormatEntry* entry = m_xCtrlManager->GetSelectedEntry(); if (!entry) return; auto type = entry->GetType(); diff --git a/sc/source/ui/inc/condformathelper.hxx b/sc/source/ui/inc/condformathelper.hxx index 35e3b5c9e9be..b1ff300b1a88 100644 --- a/sc/source/ui/inc/condformathelper.hxx +++ b/sc/source/ui/inc/condformathelper.hxx @@ -14,6 +14,7 @@ #include class ScConditionalFormat; +class ScFormatEntry; enum ScCondFormatEntryType { @@ -28,6 +29,7 @@ enum ScCondFormatEntryType class ScCondFormatHelper { public: + static SC_DLLPUBLIC OUString GetExpression(const ScFormatEntry* rEntry, const ScAddress& rPos); static SC_DLLPUBLIC OUString GetExpression(const ScConditionalFormat& rFormat, const ScAddress& rPos); static SC_DLLPUBLIC OUString GetExpression( ScCondFormatEntryType eType, sal_Int32 nIndex, diff --git a/sc/source/ui/inc/condformatmgr.hxx b/sc/source/ui/inc/condformatmgr.hxx index 26345d55894a..09b6c571e562 100644 --- a/sc/source/ui/inc/condformatmgr.hxx +++ b/sc/source/ui/inc/condformatmgr.hxx @@ -15,6 +15,7 @@ class ScDocument; class ScConditionalFormat; class ScConditionalFormatList; +class ScFormatEntry; class ScCondFormatManagerWindow { @@ -31,6 +32,7 @@ public: void DeleteSelection(); ScConditionalFormat* GetSelection(); + const ScFormatEntry* GetSelectedEntry(); }; class ScCondFormatManagerDlg : public weld::GenericDialogController diff --git a/sc/uiconfig/scalc/ui/condformatmanager.ui b/sc/uiconfig/scalc/ui/condformatmanager.ui index f6bad84e5e7c..0e143b622beb 100644 --- a/sc/uiconfig/scalc/ui/condformatmanager.ui +++ b/sc/uiconfig/scalc/ui/condformatmanager.ui @@ -139,7 +139,7 @@ True 6 - First Condition + Condition