desktop/source/lib/init.cxx | 2 sc/inc/colorscale.hxx | 6 +- sc/sdi/scalc.sdi | 2 sc/source/core/data/colorscale.cxx | 4 - sc/source/ui/view/cellsh1.cxx | 92 ++++++++++++++++++++++++++----------- 5 files changed, 73 insertions(+), 33 deletions(-)
New commits: commit 5e3365e88c94450e6db687eb46425e07db6997f5 Author: Jan Holesovsky <ke...@collabora.com> Date: Mon Jun 25 22:58:30 2018 +0200 Conditional formatting: Allow to set the icon set CF via .uno: command. When .uno:IconSetFormatDialog gets a parameter, it directly creates the icon set conditional formatting with pre-selected values. Change-Id: I75dda90e5ea9c191254acc24c564cda7b27243a5 Reviewed-on: https://gerrit.libreoffice.org/56429 Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk> Tested-by: Miklos Vajna <vmik...@collabora.co.uk> diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index b0079d0f5f16..c8593b96859b 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -335,6 +335,8 @@ std::vector<beans::PropertyValue> desktop::jsonToPropertyValuesVector(const char aValue.Value <<= OString(rValue.c_str()).toFloat(); else if (rType == "long") aValue.Value <<= OString(rValue.c_str()).toInt32(); + else if (rType == "short") + aValue.Value <<= static_cast<sal_Int16>(OString(rValue.c_str()).toInt32()); else if (rType == "unsigned short") aValue.Value <<= static_cast<sal_uInt16>(OString(rValue.c_str()).toUInt32()); else if (rType == "[]any") diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx index 840b6824963d..8ae03f419b18 100644 --- a/sc/inc/colorscale.hxx +++ b/sc/inc/colorscale.hxx @@ -51,7 +51,7 @@ private: ScColorScaleEntryType meType; public: - ScColorScaleEntry(double nVal, const Color& rCol); + ScColorScaleEntry(double nVal, const Color& rCol, ScColorScaleEntryType eType = COLORSCALE_VALUE); ScColorScaleEntry(); ScColorScaleEntry(const ScColorScaleEntry& rEntry); ScColorScaleEntry(ScDocument* pDoc, const ScColorScaleEntry& rEntry); @@ -329,8 +329,8 @@ struct ScIconSetFormatData // std..pair::second == -1 means no image std::vector<std::pair<ScIconSetType, sal_Int32> > maCustomVector; - ScIconSetFormatData(): - eIconSetType(IconSet_3Arrows), + ScIconSetFormatData(ScIconSetType eType = IconSet_3Arrows): + eIconSetType(eType), mbShowValue(true), mbReverse(false), mbCustom(false) diff --git a/sc/sdi/scalc.sdi b/sc/sdi/scalc.sdi index 544655e5fe4f..56d68d0799fd 100644 --- a/sc/sdi/scalc.sdi +++ b/sc/sdi/scalc.sdi @@ -829,7 +829,7 @@ SfxVoidItem DataBarFormatDialog SID_OPENDLG_DATABAR SfxVoidItem IconSetFormatDialog SID_OPENDLG_ICONSET -() +(SfxInt16Item IconSet FN_PARAM_1) [ AutoUpdate = FALSE, FastCall = FALSE, diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx index cb7599e0db53..7c6bb46aa8a2 100644 --- a/sc/source/core/data/colorscale.cxx +++ b/sc/source/core/data/colorscale.cxx @@ -158,10 +158,10 @@ ScColorScaleEntry::ScColorScaleEntry(): { } -ScColorScaleEntry::ScColorScaleEntry(double nVal, const Color& rCol): +ScColorScaleEntry::ScColorScaleEntry(double nVal, const Color& rCol, ScColorScaleEntryType eType): mnVal(nVal), maColor(rCol), - meType(COLORSCALE_VALUE) + meType(eType) { } diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx index e8a5fecaf609..efe07dbccd94 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -48,6 +48,7 @@ #include <editeng/editview.hxx> #include "cellsh.hxx" +#include <ftools.hxx> #include "sc.hrc" #include "document.hxx" #include "patattr.hxx" @@ -77,6 +78,7 @@ #include "cliputil.hxx" #include "markdata.hxx" #include "docpool.hxx" +#include <colorscale.hxx> #include "condformatdlg.hxx" #include "attrib.hxx" #include "condformatdlgitem.hxx" @@ -100,6 +102,7 @@ #include <com/sun/star/i18n/TransliterationModules.hpp> #include <com/sun/star/i18n/TransliterationModulesExtra.hpp> +#include <o3tl/make_unique.hxx> #include <memory> using namespace ::com::sun::star; @@ -1984,15 +1987,16 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) aRangeList.push_back(pRange); } + // try to find an existing conditional format const ScConditionalFormat* pCondFormat = nullptr; const ScPatternAttr* pPattern = pDoc->GetPattern(aPos.Col(), aPos.Row(), aPos.Tab()); + ScConditionalFormatList* pList = pDoc->GetCondFormList(aPos.Tab()); const std::vector<sal_uInt32>& rCondFormats = static_cast<const ScCondFormatItem&>(pPattern->GetItem(ATTR_CONDITIONAL)).GetCondFormatData(); bool bContainsCondFormat = !rCondFormats.empty(); bool bCondFormatDlg = false; + bool bContainsExistingCondFormat = false; if(bContainsCondFormat) { - bool bContainsExistingCondFormat = false; - ScConditionalFormatList* pList = pDoc->GetCondFormList(aPos.Tab()); for (std::vector<sal_uInt32>::const_iterator itr = rCondFormats.begin(), itrEnd = rCondFormats.end(); itr != itrEnd; ++itr) { @@ -2011,39 +2015,73 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) break; } } + } + + // do we have a parameter with the conditional formatting type? + const SfxInt16Item* pParam = rReq.GetArg<SfxInt16Item>(FN_PARAM_1); + if (pParam && nSlot == SID_OPENDLG_ICONSET) + { + ScConditionalFormat* pFormat = new ScConditionalFormat(0, pDoc); + pFormat->SetRange(aRangeList); + + ScIconSetType eIconSetType = limit_cast<ScIconSetType>(pParam->GetValue(), IconSet_3Arrows, IconSet_5Boxes); + int nSteps = 3; + if (eIconSetType >= IconSet_4Arrows && eIconSetType < IconSet_5Arrows) + nSteps = 4; + else if (eIconSetType >= IconSet_5Arrows) + nSteps = 5; + + ScIconSetFormat* pEntry = new ScIconSetFormat(pDoc); + ScIconSetFormatData* pIconSetFormatData = new ScIconSetFormatData(eIconSetType); + + pIconSetFormatData->m_Entries.push_back(o3tl::make_unique<ScColorScaleEntry>(0, COL_RED, COLORSCALE_PERCENT)); + pIconSetFormatData->m_Entries.push_back(o3tl::make_unique<ScColorScaleEntry>(round(100. / nSteps), COL_BROWN, COLORSCALE_PERCENT)); + pIconSetFormatData->m_Entries.push_back(o3tl::make_unique<ScColorScaleEntry>(round(200. / nSteps), COL_YELLOW, COLORSCALE_PERCENT)); + if (nSteps > 3) + pIconSetFormatData->m_Entries.push_back(o3tl::make_unique<ScColorScaleEntry>(round(300. / nSteps), COL_WHITE, COLORSCALE_PERCENT)); + if (nSteps > 4) + pIconSetFormatData->m_Entries.push_back(o3tl::make_unique<ScColorScaleEntry>(round(400. / nSteps), COL_GREEN, COLORSCALE_PERCENT)); - // if not found a conditional format ask whether we should edit one of the existing - // or should create a new overlapping conditional format - if(!bCondFormatDlg && bContainsExistingCondFormat) + pEntry->SetIconSetData(pIconSetFormatData); + pFormat->AddEntry(pEntry); + + // use the new conditional formatting + GetViewData()->GetDocShell()->GetDocFunc().ReplaceConditionalFormat(nIndex, pFormat, aPos.Tab(), aRangeList); + + break; + } + + // if not found a conditional format ask whether we should edit one of the existing + // or should create a new overlapping conditional format + if(bContainsCondFormat && !bCondFormatDlg && bContainsExistingCondFormat) + { + ScopedVclPtrInstance<QueryBox> aBox( pTabViewShell->GetDialogParent(), WinBits( WB_YES_NO | WB_DEF_YES ), + ScGlobal::GetRscString(STR_EDIT_EXISTING_COND_FORMATS) ); + bool bEditExisting = aBox->Execute() == RET_YES; + if(bEditExisting) { - ScopedVclPtrInstance<QueryBox> aBox( pTabViewShell->GetDialogParent(), WinBits( WB_YES_NO | WB_DEF_YES ), - ScGlobal::GetRscString(STR_EDIT_EXISTING_COND_FORMATS) ); - bool bEditExisting = aBox->Execute() == RET_YES; - if(bEditExisting) + // differentiate between ranges where one conditional format is defined + // and several formats are defined + // if we have only one => open the cond format dlg to edit it + // otherwise open the manage cond format dlg + if(rCondFormats.size() == 1) { - // differentiate between ranges where one conditional format is defined - // and several formats are defined - // if we have only one => open the cond format dlg to edit it - // otherwise open the manage cond format dlg - if(rCondFormats.size() == 1) - { - pCondFormat = pList->GetFormat(rCondFormats[0]); - assert(pCondFormat); - bCondFormatDlg = true; - } - else - { - // Queue message to open Conditional Format Manager Dialog. - GetViewData()->GetDispatcher().Execute( SID_OPENDLG_CONDFRMT_MANAGER, SfxCallMode::ASYNCHRON ); - break; - } + pCondFormat = pList->GetFormat(rCondFormats[0]); + assert(pCondFormat); + bCondFormatDlg = true; } else { - // define an overlapping conditional format - // does not need to be handled here + // Queue message to open Conditional Format Manager Dialog. + GetViewData()->GetDispatcher().Execute( SID_OPENDLG_CONDFRMT_MANAGER, SfxCallMode::ASYNCHRON ); + break; } } + else + { + // define an overlapping conditional format + // does not need to be handled here + } } condformat::dialog::ScCondFormatDialogType eType = condformat::dialog::NONE; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits