From 723e035e1fbafdedf7ed64b8de4c14ef0ef038ea Mon Sep 17 00:00:00 2001 From: Pranam Lashkari Date: Wed, 26 Jun 2024 00:13:54 +0100 Subject: [PATCH] tdf#162475 sc: added date condition option in conditional format manage dialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I453b4ef47bed1607f42fbb3e48303531c6f355a3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169323 Tested-by: Jenkins CollaboraOffice Reviewed-by: Szymon Kłos Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170911 Reviewed-by: Caolán McNamara Tested-by: Jenkins --- sc/inc/conditio.hxx | 56 +++++++++ sc/inc/strings.hrc | 63 ++++++---- sc/source/core/data/conditio.cxx | 16 +++ .../ui/condformat/condformatdlgentry.cxx | 79 ++++++++---- sc/source/ui/condformat/condformateasydlg.cxx | 117 +++++++++++++++++- sc/source/ui/condformat/condformatmgr.cxx | 84 ++++++++++++- sc/source/ui/inc/condformatdlgentry.hxx | 2 +- sc/source/ui/inc/condformatmgr.hxx | 4 + sc/uiconfig/scalc/ui/condformatmanager.ui | 54 +++++++- sc/uiconfig/scalc/ui/conditionaleasydialog.ui | 2 +- 10 files changed, 418 insertions(+), 59 deletions(-) diff --git a/sc/inc/conditio.hxx b/sc/inc/conditio.hxx index 24c42ffbe703..3d22a16c7d33 100644 --- a/sc/inc/conditio.hxx +++ b/sc/inc/conditio.hxx @@ -85,6 +85,20 @@ enum class ScConditionMode EndsWith, ContainsText, NotContainsText, + Formula, + Today, + Yesterday, + Tomorrow, + Last7days, + ThisWeek, + LastWeek, + NextWeek, + ThisMonth, + LastMonth, + NextMonth, + ThisYear, + LastYear, + NextYear, NONE }; @@ -169,6 +183,48 @@ inline std::basic_ostream & operator <<(std::basic_ostreamhide(); + break; + case ScConditionMode::Today: + SetDescription(ScResId(STR_CONDITION_TODAY)); + mxAllInputs->hide(); + break; + case ScConditionMode::Yesterday: + SetDescription(ScResId(STR_CONDITION_YESTERDAY)); + mxAllInputs->hide(); + break; + case ScConditionMode::Tomorrow: + SetDescription(ScResId(STR_CONDITION_TOMORROW)); + mxAllInputs->hide(); + break; + case ScConditionMode::Last7days: + SetDescription(ScResId(STR_CONDITION_LAST7DAYS)); + mxAllInputs->hide(); + break; + case ScConditionMode::ThisWeek: + SetDescription(ScResId(STR_CONDITION_THISWEEK)); + mxAllInputs->hide(); + break; + case ScConditionMode::LastWeek: + SetDescription(ScResId(STR_CONDITION_LASTWEEK)); + mxAllInputs->hide(); + break; + case ScConditionMode::NextWeek: + SetDescription(ScResId(STR_CONDITION_NEXTWEEK)); + mxAllInputs->hide(); + break; + case ScConditionMode::ThisMonth: + SetDescription(ScResId(STR_CONDITION_THISMONTH)); + mxAllInputs->hide(); + break; + case ScConditionMode::LastMonth: + SetDescription(ScResId(STR_CONDITION_LASTMONTH)); + mxAllInputs->hide(); + break; + case ScConditionMode::NextMonth: + SetDescription(ScResId(STR_CONDITION_NEXTMONTH)); + mxAllInputs->hide(); + break; + case ScConditionMode::ThisYear: + SetDescription(ScResId(STR_CONDITION_THISYEAR)); + mxAllInputs->hide(); + break; + case ScConditionMode::LastYear: + SetDescription(ScResId(STR_CONDITION_LASTYEAR)); + mxAllInputs->hide(); + break; + case ScConditionMode::NextYear: + SetDescription(ScResId(STR_CONDITION_NEXTYEAR)); + mxAllInputs->hide(); + break; default: SAL_WARN("sc", "ConditionalFormatEasyDialog::ConditionalFormatEasyDialog: invalid format"); @@ -259,9 +350,29 @@ IMPL_LINK(ConditionalFormatEasyDialog, ButtonPressed, weld::Button&, rButton, vo break; } - ScFormatEntry* pEntry - = new ScCondFormatEntry(meMode, sExpression1, sExpression2, *mpDocument, maPosition, - mxStyles->get_active_text()); + ScFormatEntry* pEntry; + if (meMode < ScConditionMode::Formula) + { + pEntry = new ScCondFormatEntry(meMode, sExpression1, sExpression2, *mpDocument, + maPosition, mxStyles->get_active_text()); + } + else if (meMode >= ScConditionMode::Today && meMode < ScConditionMode::NONE) + { + ScCondDateFormatEntry entry(mpDocument); + entry.SetDateType(GetScCondFormatDateType(meMode)); + entry.SetStyleName(mxStyles->get_active_text()); + pEntry = new ScCondDateFormatEntry(mpDocument, entry); + } + else if (meMode == ScConditionMode::Formula) + { + pEntry = new ScCondFormatEntry(ScConditionMode::Direct, "", OUString(), *mpDocument, + maPosition, mxStyles->get_active_text()); + } + else + { + DBG_ASSERT(false, "Invalid conidtion type selected."); + return; + } ScRangeList aRange; ScRefFlags nFlags diff --git a/sc/source/ui/condformat/condformatmgr.cxx b/sc/source/ui/condformat/condformatmgr.cxx index 16456d7fd7b6..f5441f4edf08 100644 --- a/sc/source/ui/condformat/condformatmgr.cxx +++ b/sc/source/ui/condformat/condformatmgr.cxx @@ -21,6 +21,7 @@ #include #include #include +#include ScCondFormatManagerWindow::ScCondFormatManagerWindow(weld::TreeView& rTreeView, ScDocument& rDoc, ScConditionalFormatList* pFormatList) @@ -98,6 +99,8 @@ ScCondFormatManagerDlg::ScCondFormatManagerDlg(weld::Window* pParent, ScDocument , m_xFormatList( pFormatList ? new ScConditionalFormatList(*pFormatList) : nullptr) , m_xConditionalType(m_xBuilder->weld_combo_box("type")) , m_xConditionalCellValue(m_xBuilder->weld_combo_box("typeis")) + , m_xConditionalFormula(m_xBuilder->weld_entry("formula")) + , m_xConditionalDate(m_xBuilder->weld_combo_box("datetype")) , m_xBtnAdd(m_xBuilder->weld_button(u"add"_ustr)) , m_xBtnRemove(m_xBuilder->weld_button(u"remove"_ustr)) , m_xBtnEdit(m_xBuilder->weld_button(u"edit"_ustr)) @@ -108,6 +111,8 @@ ScCondFormatManagerDlg::ScCondFormatManagerDlg(weld::Window* pParent, ScDocument m_xBtnEdit->connect_clicked(LINK(this, ScCondFormatManagerDlg, EditBtnClickHdl)); m_xBtnAdd->connect_clicked(LINK(this, ScCondFormatManagerDlg, AddBtnHdl)); m_xTreeView->connect_row_activated(LINK(this, ScCondFormatManagerDlg, EditBtnHdl)); + m_xTreeView->connect_changed(LINK(this, ScCondFormatManagerDlg, EntryFocus)); + m_xConditionalType->connect_changed(LINK(this, ScCondFormatManagerDlg, ComboHdl)); SvtViewOptions aDlgOpt(EViewType::Dialog, u"CondFormatDialog"_ustr); if (aDlgOpt.Exists()) @@ -148,13 +153,29 @@ void ScCondFormatManagerDlg::ShowEasyConditionalDialog() return; auto id = m_xConditionalType->get_active(); + SfxBoolItem IsManaged(FN_PARAM_2, true); switch (id) { case 0: // Cell value { SfxInt16Item FormatRule(FN_PARAM_1, m_xConditionalCellValue->get_active_id().toUInt32()); - SfxBoolItem IsManaged(FN_PARAM_2, true); + SfxViewShell::Current()->GetDispatcher()->ExecuteList( + SID_EASY_CONDITIONAL_FORMAT_DIALOG, SfxCallMode::ASYNCHRON, + { &FormatRule, &IsManaged }); + } + break; + case 1: // Formula + { + SfxInt16Item FormatRule(FN_PARAM_1, static_cast(ScConditionMode::Formula)); + SfxViewShell::Current()->GetDispatcher()->ExecuteList( + SID_EASY_CONDITIONAL_FORMAT_DIALOG, SfxCallMode::ASYNCHRON, + { &FormatRule, &IsManaged }); + } + break; + case 2: // Date + { + SfxInt16Item FormatRule(FN_PARAM_1, m_xConditionalDate->get_active_id().toUInt32()); SfxViewShell::Current()->GetDispatcher()->ExecuteList( SID_EASY_CONDITIONAL_FORMAT_DIALOG, SfxCallMode::ASYNCHRON, { &FormatRule, &IsManaged }); @@ -196,6 +217,67 @@ IMPL_LINK_NOARG(ScCondFormatManagerDlg, AddBtnHdl, weld::Button&, void) m_xDialog->response( DLG_RET_ADD ); } +IMPL_LINK_NOARG(ScCondFormatManagerDlg, ComboHdl, weld::ComboBox&, void) +{ + auto id = m_xConditionalType->get_active(); + switch (id) + { + case 0: + { + m_xConditionalCellValue->set_visible(true); + m_xConditionalFormula->set_visible(false); + m_xConditionalDate->set_visible(false); + } + break; + case 1: + { + m_xConditionalCellValue->set_visible(false); + m_xConditionalFormula->set_visible(true); + m_xConditionalDate->set_visible(false); + } + break; + case 2: + { + m_xConditionalCellValue->set_visible(false); + m_xConditionalFormula->set_visible(false); + m_xConditionalDate->set_visible(true); + } + break; + default: + break; + } +} + +IMPL_LINK_NOARG(ScCondFormatManagerDlg, EntryFocus, weld::TreeView&, void) +{ + ScConditionalFormat* conditionFrmt = m_xCtrlManager->GetSelection(); + + if (!conditionFrmt) + return; + + const ScFormatEntry* entry = conditionFrmt->GetEntry(0); + if (!entry) + return; + auto type = entry->GetType(); + + if (type == ScFormatEntry::Type::Condition) + { + const ScCondFormatEntry* conditionEntry = dynamic_cast(entry); + auto conditionType = conditionEntry->GetOperation(); + m_xConditionalType->set_active(0); + this->ComboHdl(*m_xConditionalType); + m_xConditionalCellValue->set_active(static_cast(conditionType)); + } + else if (type == ScFormatEntry::Type::Date) + { + const ScCondDateFormatEntry* dateEntry = dynamic_cast(entry); + auto dateType = dateEntry->GetDateType(); + m_xConditionalType->set_active(2); + this->ComboHdl(*m_xConditionalType); + m_xConditionalDate->set_active(dateType); + } +} + void ScCondFormatManagerDlg::SetModified() { m_bModified = true; diff --git a/sc/source/ui/inc/condformatdlgentry.hxx b/sc/source/ui/inc/condformatdlgentry.hxx index 6725ef94c940..6f024643d4b3 100644 --- a/sc/source/ui/inc/condformatdlgentry.hxx +++ b/sc/source/ui/inc/condformatdlgentry.hxx @@ -103,7 +103,7 @@ class ScConditionFrmtEntry : public ScCondFrmtEntry, public SfxListener std::unique_ptr mxWdPreview; bool mbIsInStyleCreate; - static const sal_Int32 NUM_COND_ENTRIES = 24; + static const sal_Int32 NUM_COND_ENTRIES = 38; // Lookup table from positions in maLbCondType to the condition mode enum static const ScConditionMode mpEntryToCond[NUM_COND_ENTRIES]; diff --git a/sc/source/ui/inc/condformatmgr.hxx b/sc/source/ui/inc/condformatmgr.hxx index 51a251416b27..7361fb6830c7 100644 --- a/sc/source/ui/inc/condformatmgr.hxx +++ b/sc/source/ui/inc/condformatmgr.hxx @@ -52,6 +52,8 @@ private: std::unique_ptr m_xConditionalType; std::unique_ptr m_xConditionalCellValue; + std::unique_ptr m_xConditionalFormula; + std::unique_ptr m_xConditionalDate; std::unique_ptr m_xBtnAdd; std::unique_ptr m_xBtnRemove; std::unique_ptr m_xBtnEdit; @@ -64,6 +66,8 @@ private: DECL_LINK(EditBtnClickHdl, weld::Button&, void); DECL_LINK(AddBtnHdl, weld::Button&, void); DECL_LINK(EditBtnHdl, weld::TreeView&, bool); + DECL_LINK(ComboHdl, weld::ComboBox&, void); + DECL_LINK(EntryFocus, weld::TreeView&, void); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/uiconfig/scalc/ui/condformatmanager.ui b/sc/uiconfig/scalc/ui/condformatmanager.ui index 74ea3d33bda9..b0ce20a5d756 100644 --- a/sc/uiconfig/scalc/ui/condformatmanager.ui +++ b/sc/uiconfig/scalc/ui/condformatmanager.ui @@ -224,6 +224,54 @@ 1 + + + True + True + True + False + True + + + Here you can add formula for conditional formatting. + + + + + False + True + 2 + + + + + False + False + False + True + 0 + + Today + Yesterday + Tomorrow + Last 7 days + This week + Last week + Next week + This month + Last month + Next month + This year + Last year + Next year + + + + False + True + 3 + + Add @@ -239,7 +287,7 @@ False True - 2 + @@ -257,7 +305,7 @@ False True - 3 + 5 @@ -275,7 +323,7 @@ False True - 4 + 6 diff --git a/sc/uiconfig/scalc/ui/conditionaleasydialog.ui b/sc/uiconfig/scalc/ui/conditionaleasydialog.ui index e9bf10716207..3939d49f613b 100644 --- a/sc/uiconfig/scalc/ui/conditionaleasydialog.ui +++ b/sc/uiconfig/scalc/ui/conditionaleasydialog.ui @@ -204,7 +204,7 @@ True False - Conditional formatting rule: %1 + Highlight cells if %1