diff options
author | Pranam Lashkari <lpranam@collabora.com> | 2024-06-26 00:43:54 +0100 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-08-15 14:53:59 +0200 |
commit | 8090d7a54f71ccf897d725bbae3f55eb346a240a (patch) | |
tree | 7ae75af9fe4c7d15bf15a1a76e283dabbdc819cd /sc/source/ui/condformat | |
parent | 367c2319a8067e6929a4df5c199698db9b07cc56 (diff) |
tdf#162475 sc: display all the conditions of same ranges in conditional format manager
Change-Id: I775f96f4cea19e8da34c2d64ac601e5ea3fc5c43
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169482
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170914
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Diffstat (limited to 'sc/source/ui/condformat')
-rw-r--r-- | sc/source/ui/condformat/condformathelper.cxx | 97 | ||||
-rw-r--r-- | sc/source/ui/condformat/condformatmgr.cxx | 47 |
2 files changed, 83 insertions, 61 deletions
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<const ScConditionEntry*>(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<sal_Int32>(eMode)) + " "); + if (eMode == ScConditionMode::Between || eMode == ScConditionMode::NotBetween) { - const ScConditionEntry* pEntry = static_cast<const ScConditionEntry*>(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<sal_Int32>(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<sal_Int32>(static_cast<const ScCondDateFormatEntry*>(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<sal_Int32>( + static_cast<const ScCondDateFormatEntry*>(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 <svl/intitem.hxx> #include <svl/stritem.hxx> #include <unotools/viewoptions.hxx> -#include <iostream> +#include <o3tl/string_view.hxx> + +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(); |