sc/inc/colorscale.hxx | 6 +++--- sc/inc/conditio.hxx | 18 +++++++++--------- sc/inc/fillinfo.hxx | 3 ++- sc/qa/unit/ucalc_condformat.cxx | 3 +-- sc/source/core/data/colorscale.cxx | 19 +++++++++---------- sc/source/core/data/conditio.cxx | 12 ++++++++++-- sc/source/core/data/fillinfo.cxx | 12 ++++++------ sc/source/ui/view/output.cxx | 18 +++++++++--------- ucb/source/ucp/gio/gio_datasupplier.cxx | 12 +----------- ucb/source/ucp/gio/gio_datasupplier.hxx | 3 ++- 10 files changed, 52 insertions(+), 54 deletions(-)
New commits: commit 1cc24fe3be7221940c3bb6c4812d01a0f356f971 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Fri Sep 28 10:32:44 2018 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Oct 1 08:17:17 2018 +0200 loplugin:useuniqueptr in gio::DataSupplier Change-Id: Ie0633d26d858c25e355f49597352d6b29c8c6c0f Reviewed-on: https://gerrit.libreoffice.org/61115 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/ucb/source/ucp/gio/gio_datasupplier.cxx b/ucb/source/ucp/gio/gio_datasupplier.cxx index d459ec12ff85..1d4acbdf3b42 100644 --- a/ucb/source/ucp/gio/gio_datasupplier.cxx +++ b/ucb/source/ucp/gio/gio_datasupplier.cxx @@ -35,8 +35,6 @@ using namespace gio; namespace gio { -typedef std::vector< ResultListEntry* > ResultList; - DataSupplier::DataSupplier( const rtl::Reference< ::gio::Content >& rContent, sal_Int32 nOpenMode ) : mxContent(rContent), mnOpenMode(nOpenMode), mbCountFinal(false) { @@ -73,7 +71,7 @@ bool DataSupplier::getData() break; } - maResults.push_back( new ResultListEntry( pInfo ) ); + maResults.emplace_back( new ResultListEntry( pInfo ) ); g_object_unref(pInfo); } @@ -85,14 +83,6 @@ bool DataSupplier::getData() DataSupplier::~DataSupplier() { - ResultList::const_iterator it = maResults.begin(); - ResultList::const_iterator end = maResults.end(); - - while ( it != end ) - { - delete *it; - ++it; - } } OUString DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex ) diff --git a/ucb/source/ucp/gio/gio_datasupplier.hxx b/ucb/source/ucp/gio/gio_datasupplier.hxx index c2558d0e8f67..75fd66f35634 100644 --- a/ucb/source/ucp/gio/gio_datasupplier.hxx +++ b/ucb/source/ucp/gio/gio_datasupplier.hxx @@ -22,6 +22,7 @@ #include <ucbhelper/resultset.hxx> #include "gio_content.hxx" +#include <memory> #include <vector> namespace gio @@ -48,7 +49,7 @@ struct ResultListEntry } }; -typedef std::vector< ResultListEntry* > ResultList; +typedef std::vector< std::unique_ptr<ResultListEntry> > ResultList; class DataSupplier : public ucbhelper::ResultSetDataSupplier { commit 30e0a64209f11ee596bcdd9eda1a320217ef31cd Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Fri Sep 28 10:17:04 2018 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Oct 1 08:17:07 2018 +0200 loplugin:useuniqueptr in ScCondFormatData Change-Id: I93c906bfb84143ff101577e8e1ef8f5ffb07a0a7 Reviewed-on: https://gerrit.libreoffice.org/61114 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx index 90889484ab07..fcfa3fa3966d 100644 --- a/sc/inc/colorscale.hxx +++ b/sc/inc/colorscale.hxx @@ -268,7 +268,7 @@ public: virtual void SetParent(ScConditionalFormat* pParent) override; - Color* GetColor(const ScAddress& rAddr) const; + boost::optional<Color> GetColor(const ScAddress& rAddr) const; void AddEntry(ScColorScaleEntry* pEntry); virtual void UpdateReference( sc::RefUpdateContext& rCxt ) override; @@ -303,7 +303,7 @@ public: virtual void SetParent(ScConditionalFormat* pParent) override; - ScDataBarInfo* GetDataBarInfo(const ScAddress& rAddr) const; + std::unique_ptr<ScDataBarInfo> GetDataBarInfo(const ScAddress& rAddr) const; void SetDataBarData( ScDataBarFormatData* pData ); const ScDataBarFormatData* GetDataBarData() const; @@ -365,7 +365,7 @@ public: virtual void SetParent(ScConditionalFormat* pParent) override; - ScIconSetInfo* GetIconSetInfo(const ScAddress& rAddr) const; + std::unique_ptr<ScIconSetInfo> GetIconSetInfo(const ScAddress& rAddr) const; void SetIconSetData( ScIconSetFormatData* pData ); const ScIconSetFormatData* GetIconSetData() const; diff --git a/sc/inc/conditio.hxx b/sc/inc/conditio.hxx index be9c1362742c..e1bda2ba71d7 100644 --- a/sc/inc/conditio.hxx +++ b/sc/inc/conditio.hxx @@ -22,6 +22,7 @@ #include "global.hxx" #include <tools/solar.h> +#include <tools/color.hxx> #include "address.hxx" #include <formula/grammar.hxx> #include "scdllapi.h" @@ -36,6 +37,7 @@ #include <tools/date.hxx> #include <tools/link.hxx> +#include <boost/optional.hpp> #include <map> #include <memory> #include <set> @@ -43,7 +45,6 @@ class ScFormulaCell; class ScTokenArray; struct ScRefCellValue; -class Color; namespace sc { @@ -211,14 +212,13 @@ struct ScIconSetInfo; struct ScCondFormatData { - ScCondFormatData(): - pColorScale(nullptr), - pDataBar(nullptr), - pIconSet(nullptr) {} - - Color* pColorScale; - ScDataBarInfo* pDataBar; - ScIconSetInfo* pIconSet; + ScCondFormatData(); + ScCondFormatData(ScCondFormatData&&); + ~ScCondFormatData(); + + boost::optional<Color> mxColorScale; + std::unique_ptr<ScDataBarInfo> pDataBar; + std::unique_ptr<ScIconSetInfo> pIconSet; OUString aStyleName; }; diff --git a/sc/inc/fillinfo.hxx b/sc/inc/fillinfo.hxx index 41cac93beae9..6b9ff623bf6a 100644 --- a/sc/inc/fillinfo.hxx +++ b/sc/inc/fillinfo.hxx @@ -28,6 +28,7 @@ #include "colorscale.hxx" #include "cellvalue.hxx" #include <o3tl/typed_flags_set.hxx> +#include <boost/optional.hpp> class SfxItemSet; class SvxBrushItem; @@ -133,7 +134,7 @@ struct CellInfo const ScPatternAttr* pPatternAttr; const SfxItemSet* pConditionSet; - std::unique_ptr<const Color> pColorScale; + boost::optional<Color> mxColorScale; std::unique_ptr<const ScDataBarInfo> pDataBar; std::unique_ptr<const ScIconSetInfo> pIconSet; diff --git a/sc/qa/unit/ucalc_condformat.cxx b/sc/qa/unit/ucalc_condformat.cxx index d2bf5d23c6df..5adf22ec57ae 100644 --- a/sc/qa/unit/ucalc_condformat.cxx +++ b/sc/qa/unit/ucalc_condformat.cxx @@ -574,9 +574,8 @@ void Test::testIconSet() for(size_t i = 0; i < SAL_N_ELEMENTS(aTests); ++i) { m_pDoc->SetValue(0,0,0,aTests[i].nVal); - ScIconSetInfo* pInfo = pEntry->GetIconSetInfo(ScAddress(0,0,0)); + std::unique_ptr<ScIconSetInfo> pInfo = pEntry->GetIconSetInfo(ScAddress(0,0,0)); CPPUNIT_ASSERT_EQUAL(aTests[i].nIndex, pInfo->nIconIndex); - delete pInfo; } delete pEntry; diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx index 7b79ec56beb8..da205819e895 100644 --- a/sc/source/core/data/colorscale.cxx +++ b/sc/source/core/data/colorscale.cxx @@ -585,17 +585,17 @@ double ScColorScaleFormat::CalcValue(double nMin, double nMax, const ScColorScal return (*itr)->GetValue(); } -Color* ScColorScaleFormat::GetColor( const ScAddress& rAddr ) const +boost::optional<Color> ScColorScaleFormat::GetColor( const ScAddress& rAddr ) const { ScRefCellValue rCell(*mpDoc, rAddr); if(!rCell.hasNumeric()) - return nullptr; + return boost::optional<Color>(); // now we have for sure a value double nVal = rCell.getValue(); if (maColorScales.size() < 2) - return nullptr; + return boost::optional<Color>(); double nMin = std::numeric_limits<double>::max(); double nMax = std::numeric_limits<double>::min(); @@ -603,7 +603,7 @@ Color* ScColorScaleFormat::GetColor( const ScAddress& rAddr ) const // this check is for safety if(nMin >= nMax) - return nullptr; + return boost::optional<Color>(); ScColorScaleEntries::const_iterator itr = begin(); double nValMin = CalcValue(nMin, nMax, itr); @@ -624,7 +624,7 @@ Color* ScColorScaleFormat::GetColor( const ScAddress& rAddr ) const Color aColor = CalcColor(nVal, nValMin, rColMin, nValMax, rColMax); - return new Color(aColor); + return aColor; } void ScColorScaleFormat::UpdateReference( sc::RefUpdateContext& rCxt ) @@ -832,7 +832,7 @@ double ScDataBarFormat::getMax(double nMin, double nMax) const return mpFormatData->mpUpperLimit->GetValue(); } -ScDataBarInfo* ScDataBarFormat::GetDataBarInfo(const ScAddress& rAddr) const +std::unique_ptr<ScDataBarInfo> ScDataBarFormat::GetDataBarInfo(const ScAddress& rAddr) const { ScRefCellValue rCell(*mpDoc, rAddr); if(!rCell.hasNumeric()) @@ -849,7 +849,7 @@ ScDataBarInfo* ScDataBarFormat::GetDataBarInfo(const ScAddress& rAddr) const double nValue = rCell.getValue(); - ScDataBarInfo* pInfo = new ScDataBarInfo; + std::unique_ptr<ScDataBarInfo> pInfo(new ScDataBarInfo); if(mpFormatData->meAxisPosition == databar::NONE) { if(nValue <= nMin) @@ -1023,7 +1023,7 @@ const ScIconSetFormatData* ScIconSetFormat::GetIconSetData() const return mpFormatData.get(); } -ScIconSetInfo* ScIconSetFormat::GetIconSetInfo(const ScAddress& rAddr) const +std::unique_ptr<ScIconSetInfo> ScIconSetFormat::GetIconSetInfo(const ScAddress& rAddr) const { ScRefCellValue rCell(*mpDoc, rAddr); if(!rCell.hasNumeric()) @@ -1054,7 +1054,7 @@ ScIconSetInfo* ScIconSetFormat::GetIconSetInfo(const ScAddress& rAddr) const if(nVal >= nValMax) ++nIndex; - ScIconSetInfo* pInfo = new ScIconSetInfo; + std::unique_ptr<ScIconSetInfo> pInfo(new ScIconSetInfo); if(mpFormatData->mbReverse) { @@ -1068,7 +1068,6 @@ ScIconSetInfo* ScIconSetFormat::GetIconSetInfo(const ScAddress& rAddr) const sal_Int32 nCustomIndex = mpFormatData->maCustomVector[nIndex].second; if (nCustomIndex == -1) { - delete pInfo; return nullptr; } diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx index 546953c0dfd8..f2799f366005 100644 --- a/sc/source/core/data/conditio.cxx +++ b/sc/source/core/data/conditio.cxx @@ -42,6 +42,7 @@ #include <cellvalue.hxx> #include <editutil.hxx> #include <tokenarray.hxx> +#include <fillinfo.hxx> #include <refupdatecontext.hxx> #include <formula/errorcodes.hxx> #include <svl/sharedstring.hxx> @@ -1824,10 +1825,10 @@ ScCondFormatData ScConditionalFormat::GetData( ScRefCellValue& rCell, const ScAd if (rEntry.IsCellValid(rCell, rPos)) aData.aStyleName = rEntry.GetStyle(); } - else if((*itr)->GetType() == ScFormatEntry::Type::Colorscale && !aData.pColorScale) + else if((*itr)->GetType() == ScFormatEntry::Type::Colorscale && !aData.mxColorScale) { const ScColorScaleFormat& rEntry = static_cast<const ScColorScaleFormat&>(**itr); - aData.pColorScale = rEntry.GetColor(rPos); + aData.mxColorScale = rEntry.GetColor(rPos); } else if((*itr)->GetType() == ScFormatEntry::Type::Databar && !aData.pDataBar) { @@ -2299,4 +2300,11 @@ void ScConditionalFormatList::CalcAll() } +ScCondFormatData::ScCondFormatData() {} + +ScCondFormatData::ScCondFormatData(ScCondFormatData&&) = default; + +ScCondFormatData::~ScCondFormatData() {} + + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/data/fillinfo.cxx b/sc/source/core/data/fillinfo.cxx index 7c78d4dd5dc6..3a06da0b7c0d 100644 --- a/sc/source/core/data/fillinfo.cxx +++ b/sc/source/core/data/fillinfo.cxx @@ -327,21 +327,21 @@ bool handleConditionalFormat(ScConditionalFormatList& rCondFormList, const std:: // if style is not there, treat like no condition } - if(aData.pColorScale) + if(aData.mxColorScale) { - pInfo->pColorScale.reset(aData.pColorScale); + pInfo->mxColorScale = aData.mxColorScale; bFound = true; } if(aData.pDataBar) { - pInfo->pDataBar.reset(aData.pDataBar); + pInfo->pDataBar = std::move(aData.pDataBar); bFound = true; } if(aData.pIconSet) { - pInfo->pIconSet.reset(aData.pIconSet); + pInfo->pIconSet = std::move(aData.pIconSet); bFound = true; } } @@ -700,10 +700,10 @@ void ScDocument::FillInfo( bAnyShadow = true; } } - if( bAnyCondition && pInfo->pColorScale) + if( bAnyCondition && pInfo->mxColorScale) { pRowInfo[nArrRow].bEmptyBack = false; - pInfo->pBackground = new SvxBrushItem(*pInfo->pColorScale, ATTR_BACKGROUND); + pInfo->pBackground = new SvxBrushItem(*pInfo->mxColorScale, ATTR_BACKGROUND); } } } diff --git a/sc/source/ui/view/output.cxx b/sc/source/ui/view/output.cxx index 95303e7e7664..9555b8f72b97 100644 --- a/sc/source/ui/view/output.cxx +++ b/sc/source/ui/view/output.cxx @@ -784,8 +784,8 @@ static bool lcl_EqualBack( const RowInfo& rFirst, const RowInfo& rOther, for ( nX=nX1; nX<=nX2; nX++ ) { - const Color* pCol1 = rFirst.pCellInfo[nX+1].pColorScale.get(); - const Color* pCol2 = rOther.pCellInfo[nX+1].pColorScale.get(); + boost::optional<Color> const & pCol1 = rFirst.pCellInfo[nX+1].mxColorScale; + boost::optional<Color> const & pCol2 = rOther.pCellInfo[nX+1].mxColorScale; if( (pCol1 && !pCol2) || (!pCol1 && pCol2) ) return false; @@ -919,7 +919,7 @@ void drawIconSets(vcl::RenderContext& rRenderContext, const ScIconSetInfo* pOldI rRenderContext.DrawBitmapEx( Point( rRect.Left() + 2 * nOneX, rRect.Top() + 2 * nOneY), Size(aOrigSize, aOrigSize), rIcon ); } -void drawCells(vcl::RenderContext& rRenderContext, const Color* pColor, const SvxBrushItem* pBackground, const Color*& pOldColor, const SvxBrushItem*& pOldBackground, +void drawCells(vcl::RenderContext& rRenderContext, boost::optional<Color> const & pColor, const SvxBrushItem* pBackground, boost::optional<Color>& pOldColor, const SvxBrushItem*& pOldBackground, tools::Rectangle& rRect, long nPosX, long nLayoutSign, long nOneX, long nOneY, const ScDataBarInfo* pDataBarInfo, const ScDataBarInfo*& pOldDataBarInfo, const ScIconSetInfo* pIconSetInfo, const ScIconSetInfo*& pOldIconSetInfo, sc::IconSetBitmapMap & rIconSetBitmapMap) @@ -981,7 +981,7 @@ void drawCells(vcl::RenderContext& rRenderContext, const Color* pColor, const Sv else if(pBackground) { pOldBackground = pBackground; - pOldColor = nullptr; + pOldColor.reset(); } if(pDataBarInfo) @@ -1069,7 +1069,7 @@ void ScOutputData::DrawBackground(vcl::RenderContext& rRenderContext) const SvxBrushItem* pOldBackground = nullptr; const SvxBrushItem* pBackground = nullptr; - const Color* pOldColor = nullptr; + boost::optional<Color> pOldColor; const ScDataBarInfo* pOldDataBarInfo = nullptr; const ScIconSetInfo* pOldIconSetInfo = nullptr; SCCOL nMergedCols = 1; @@ -1114,7 +1114,7 @@ void ScOutputData::DrawBackground(vcl::RenderContext& rRenderContext) pBackground = lcl_FindBackground( mpDoc, nX, nY, nTab ); } - const Color* pColor = pInfo->pColorScale.get(); + boost::optional<Color> const & pColor = pInfo->mxColorScale; const ScDataBarInfo* pDataBarInfo = pInfo->pDataBar.get(); const ScIconSetInfo* pIconSetInfo = pInfo->pIconSet.get(); @@ -1146,7 +1146,7 @@ void ScOutputData::DrawBackground(vcl::RenderContext& rRenderContext) if (bWorksInPixels) nPosXLogic = rRenderContext.PixelToLogic(Point(nPosX, 0)).X(); - drawCells(rRenderContext, nullptr, nullptr, pOldColor, pOldBackground, aRect, nPosXLogic, nLayoutSign, nOneXLogic, nOneYLogic, nullptr, pOldDataBarInfo, nullptr, pOldIconSetInfo, mpDoc->GetIconSetBitmapMap()); + drawCells(rRenderContext, boost::optional<Color>(), nullptr, pOldColor, pOldBackground, aRect, nPosXLogic, nLayoutSign, nOneXLogic, nOneYLogic, nullptr, pOldDataBarInfo, nullptr, pOldIconSetInfo, mpDoc->GetIconSetBitmapMap()); nArrY += nSkip; } @@ -1632,7 +1632,7 @@ void ScOutputData::DrawRotatedFrame(vcl::RenderContext& rRenderContext) // high contrast for cell borders and backgrounds -> empty background pBackground = ScGlobal::GetEmptyBrushItem(); } - if (!pInfo->pColorScale) + if (!pInfo->mxColorScale) { const Color& rColor = pBackground->GetColor(); if (rColor.GetTransparency() != 255) @@ -1660,7 +1660,7 @@ void ScOutputData::DrawRotatedFrame(vcl::RenderContext& rRenderContext) else { tools::Polygon aPoly(4, aPoints); - const Color* pColor = pInfo->pColorScale.get(); + boost::optional<Color> const & pColor = pInfo->mxColorScale; // for DrawPolygon, whitout Pen one pixel is left out // to the right and below... _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits