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
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")
......
......@@ -52,7 +52,7 @@ private:
ScConditionalFormat* mpFormat;
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);
......@@ -343,8 +343,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)
......
......@@ -739,7 +739,7 @@ SfxVoidItem DataBarFormatDialog SID_OPENDLG_DATABAR
SfxVoidItem IconSetFormatDialog SID_OPENDLG_ICONSET
()
(SfxInt16Item IconSet FN_PARAM_1)
[
AutoUpdate = FALSE,
FastCall = FALSE,
......
......@@ -136,10 +136,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),
mpFormat(nullptr)
{
}
......
......@@ -51,6 +51,7 @@
#include <svtools/cliplistener.hxx>
#include <cellsh.hxx>
#include <ftools.hxx>
#include <sc.hrc>
#include <document.hxx>
#include <patattr.hxx>
......@@ -80,6 +81,7 @@
#include <cliputil.hxx>
#include <markdata.hxx>
#include <docpool.hxx>
#include <colorscale.hxx>
#include <condformatdlg.hxx>
#include <attrib.hxx>
#include <condformatdlgitem.hxx>
......@@ -101,6 +103,7 @@
#include <com/sun/star/beans/XPropertySet.hpp>
#include <cppuhelper/bootstrap.hxx>
#include <o3tl/make_unique.hxx>
#include <memory>
using namespace ::com::sun::star;
......@@ -2007,15 +2010,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 = 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)
{
......@@ -2034,21 +2038,56 @@ 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));
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(!bCondFormatDlg && bContainsExistingCondFormat)
if(bContainsCondFormat && !bCondFormatDlg && bContainsExistingCondFormat)
{
ScopedVclPtrInstance<QueryBox> aBox( pTabViewShell->GetDialogParent(), MessBoxStyle::YesNo | MessBoxStyle::DefaultYes,
ScGlobal::GetRscString(STR_EDIT_EXISTING_COND_FORMATS) );
ScopedVclPtrInstance<QueryBox> aBox(pTabViewShell->GetDialogParent(), MessBoxStyle::YesNo | MessBoxStyle::DefaultYes,
ScGlobal::GetRscString(STR_EDIT_EXISTING_COND_FORMATS));
bool bEditExisting = aBox->Execute() == RET_YES;
if(bEditExisting)
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)
if (rCondFormats.size() == 1)
{
pCondFormat = pList->GetFormat(rCondFormats[0]);
assert(pCondFormat);
......@@ -2067,7 +2106,6 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
// does not need to be handled here
}
}
}
condformat::dialog::ScCondFormatDialogType eType = condformat::dialog::NONE;
switch(nSlot)
......
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