Kaydet (Commit) 9c20b037 authored tarafından Jan Holesovsky's avatar Jan Holesovsky Kaydeden (comit) Miklos Vajna

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/56429Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Reviewed-on: https://gerrit.libreoffice.org/61660
üst 9ba9307e
...@@ -322,6 +322,8 @@ std::vector<beans::PropertyValue> desktop::jsonToPropertyValuesVector(const char ...@@ -322,6 +322,8 @@ std::vector<beans::PropertyValue> desktop::jsonToPropertyValuesVector(const char
aValue.Value <<= OString(rValue.c_str()).toFloat(); aValue.Value <<= OString(rValue.c_str()).toFloat();
else if (rType == "long") else if (rType == "long")
aValue.Value <<= OString(rValue.c_str()).toInt32(); 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") else if (rType == "unsigned short")
aValue.Value <<= static_cast<sal_uInt16>(OString(rValue.c_str()).toUInt32()); aValue.Value <<= static_cast<sal_uInt16>(OString(rValue.c_str()).toUInt32());
else if (rType == "[]any") else if (rType == "[]any")
......
...@@ -52,7 +52,7 @@ private: ...@@ -52,7 +52,7 @@ private:
ScConditionalFormat* mpFormat; ScConditionalFormat* mpFormat;
public: public:
ScColorScaleEntry(double nVal, const Color& rCol); ScColorScaleEntry(double nVal, const Color& rCol, ScColorScaleEntryType eType = COLORSCALE_VALUE);
ScColorScaleEntry(); ScColorScaleEntry();
ScColorScaleEntry(const ScColorScaleEntry& rEntry); ScColorScaleEntry(const ScColorScaleEntry& rEntry);
ScColorScaleEntry(ScDocument* pDoc, const ScColorScaleEntry& rEntry); ScColorScaleEntry(ScDocument* pDoc, const ScColorScaleEntry& rEntry);
...@@ -343,8 +343,8 @@ struct ScIconSetFormatData ...@@ -343,8 +343,8 @@ struct ScIconSetFormatData
// std..pair::second == -1 means no image // std..pair::second == -1 means no image
std::vector<std::pair<ScIconSetType, sal_Int32> > maCustomVector; std::vector<std::pair<ScIconSetType, sal_Int32> > maCustomVector;
ScIconSetFormatData(): ScIconSetFormatData(ScIconSetType eType = IconSet_3Arrows):
eIconSetType(IconSet_3Arrows), eIconSetType(eType),
mbShowValue(true), mbShowValue(true),
mbReverse(false), mbReverse(false),
mbCustom(false) mbCustom(false)
......
...@@ -739,7 +739,7 @@ SfxVoidItem DataBarFormatDialog SID_OPENDLG_DATABAR ...@@ -739,7 +739,7 @@ SfxVoidItem DataBarFormatDialog SID_OPENDLG_DATABAR
SfxVoidItem IconSetFormatDialog SID_OPENDLG_ICONSET SfxVoidItem IconSetFormatDialog SID_OPENDLG_ICONSET
() (SfxInt16Item IconSet FN_PARAM_1)
[ [
AutoUpdate = FALSE, AutoUpdate = FALSE,
FastCall = FALSE, FastCall = FALSE,
......
...@@ -136,10 +136,10 @@ ScColorScaleEntry::ScColorScaleEntry(): ...@@ -136,10 +136,10 @@ ScColorScaleEntry::ScColorScaleEntry():
{ {
} }
ScColorScaleEntry::ScColorScaleEntry(double nVal, const Color& rCol): ScColorScaleEntry::ScColorScaleEntry(double nVal, const Color& rCol, ScColorScaleEntryType eType):
mnVal(nVal), mnVal(nVal),
maColor(rCol), maColor(rCol),
meType(COLORSCALE_VALUE), meType(eType),
mpFormat(nullptr) mpFormat(nullptr)
{ {
} }
......
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include <svtools/cliplistener.hxx> #include <svtools/cliplistener.hxx>
#include <cellsh.hxx> #include <cellsh.hxx>
#include <ftools.hxx>
#include <sc.hrc> #include <sc.hrc>
#include <document.hxx> #include <document.hxx>
#include <patattr.hxx> #include <patattr.hxx>
...@@ -80,6 +81,7 @@ ...@@ -80,6 +81,7 @@
#include <cliputil.hxx> #include <cliputil.hxx>
#include <markdata.hxx> #include <markdata.hxx>
#include <docpool.hxx> #include <docpool.hxx>
#include <colorscale.hxx>
#include <condformatdlg.hxx> #include <condformatdlg.hxx>
#include <attrib.hxx> #include <attrib.hxx>
#include <condformatdlgitem.hxx> #include <condformatdlgitem.hxx>
...@@ -101,6 +103,7 @@ ...@@ -101,6 +103,7 @@
#include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertySet.hpp>
#include <cppuhelper/bootstrap.hxx> #include <cppuhelper/bootstrap.hxx>
#include <o3tl/make_unique.hxx>
#include <memory> #include <memory>
using namespace ::com::sun::star; using namespace ::com::sun::star;
...@@ -2007,15 +2010,16 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) ...@@ -2007,15 +2010,16 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
aRangeList.push_back(pRange); aRangeList.push_back(pRange);
} }
// try to find an existing conditional format
const ScConditionalFormat* pCondFormat = nullptr; const ScConditionalFormat* pCondFormat = nullptr;
const ScPatternAttr* pPattern = pDoc->GetPattern(aPos.Col(), aPos.Row(), aPos.Tab()); const ScPatternAttr* pPattern = pDoc->GetPattern(aPos.Col(), aPos.Row(), aPos.Tab());
ScConditionalFormatList* pList = pDoc->GetCondFormList(aPos.Tab());
const std::vector<sal_uInt32>& rCondFormats = pPattern->GetItem(ATTR_CONDITIONAL).GetCondFormatData(); const std::vector<sal_uInt32>& rCondFormats = pPattern->GetItem(ATTR_CONDITIONAL).GetCondFormatData();
bool bContainsCondFormat = !rCondFormats.empty(); bool bContainsCondFormat = !rCondFormats.empty();
bool bCondFormatDlg = false; bool bCondFormatDlg = false;
bool bContainsExistingCondFormat = false;
if(bContainsCondFormat) if(bContainsCondFormat)
{ {
bool bContainsExistingCondFormat = false;
ScConditionalFormatList* pList = pDoc->GetCondFormList(aPos.Tab());
for (std::vector<sal_uInt32>::const_iterator itr = rCondFormats.begin(), itrEnd = rCondFormats.end(); for (std::vector<sal_uInt32>::const_iterator itr = rCondFormats.begin(), itrEnd = rCondFormats.end();
itr != itrEnd; ++itr) itr != itrEnd; ++itr)
{ {
...@@ -2034,39 +2038,73 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) ...@@ -2034,39 +2038,73 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
break; 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 pEntry->SetIconSetData(pIconSetFormatData);
// or should create a new overlapping conditional format pFormat->AddEntry(pEntry);
if(!bCondFormatDlg && bContainsExistingCondFormat)
// 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(), MessBoxStyle::YesNo | MessBoxStyle::DefaultYes,
ScGlobal::GetRscString(STR_EDIT_EXISTING_COND_FORMATS));
bool bEditExisting = aBox->Execute() == RET_YES;
if (bEditExisting)
{ {
ScopedVclPtrInstance<QueryBox> aBox( pTabViewShell->GetDialogParent(), MessBoxStyle::YesNo | MessBoxStyle::DefaultYes, // differentiate between ranges where one conditional format is defined
ScGlobal::GetRscString(STR_EDIT_EXISTING_COND_FORMATS) ); // and several formats are defined
bool bEditExisting = aBox->Execute() == RET_YES; // if we have only one => open the cond format dlg to edit it
if(bEditExisting) // otherwise open the manage cond format dlg
if (rCondFormats.size() == 1)
{ {
// differentiate between ranges where one conditional format is defined pCondFormat = pList->GetFormat(rCondFormats[0]);
// and several formats are defined assert(pCondFormat);
// if we have only one => open the cond format dlg to edit it bCondFormatDlg = true;
// 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;
}
} }
else else
{ {
// define an overlapping conditional format // Queue message to open Conditional Format Manager Dialog.
// does not need to be handled here 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; condformat::dialog::ScCondFormatDialogType eType = condformat::dialog::NONE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment