sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx |   48 
++++++++++
 sc/source/ui/inc/TableFillingAndNavigationTools.hxx               |    2 
 sc/source/ui/miscdlgs/optsolver.cxx                               |   24 ++++-
 3 files changed, 72 insertions(+), 2 deletions(-)

New commits:
commit 6a0997547a4e506742841ca89cca4e9c3625b3f9
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Sat Jan 18 11:17:45 2025 +0000
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Mon Jan 20 09:34:52 2025 +0100

    cid#1640469 Dereference null return value
    
    Change-Id: Ib115c3ee73a0124d9d6a3c895722c89158da2d22
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180435
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180484

diff --git a/sc/source/ui/miscdlgs/optsolver.cxx 
b/sc/source/ui/miscdlgs/optsolver.cxx
index 8adb033b3cac..cde2774153bc 100644
--- a/sc/source/ui/miscdlgs/optsolver.cxx
+++ b/sc/source/ui/miscdlgs/optsolver.cxx
@@ -1355,10 +1355,13 @@ bool ScOptSolverDlg::CallSolver()       // return true 
-> close dialog after cal
             }
 
             // Disable grid lines in the sensitivity report
-            ScViewData& aData = 
ScTabViewShell::GetActiveViewShell()->GetViewData();
-            aData.SetTabNo(nReportTab);
-            aData.SetShowGrid(false);
-            aData.SetTabNo(mnCurTab);
+            if (ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell())
+            {
+                ScViewData& rData = pViewSh->GetViewData();
+                rData.SetTabNo(nReportTab);
+                rData.SetShowGrid(false);
+                rData.SetTabNo(mnCurTab);
+            }
         }
     }
 
commit 1e3d15ddd582fbe6f74dbe621f7eb62743121f1d
Author:     Rafael Lima <rafael.palma.l...@gmail.com>
AuthorDate: Wed Jan 15 22:08:20 2025 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Mon Jan 20 09:34:40 2025 +0100

    tdf#157519 Make solver's Sensitivity Report prettier
    
    Currently the sensitivity report has no formatting whatsoever. This patch 
formats the report using table headers and adds a line delimiter at the table's 
end.
    
    The new formatting capabilities were added into AddressWalkerWriter so that 
it can also be used to improve other statistics reports (such as the features 
in Data - Statistics).
    
    Change-Id: I80da3c673fec457e3d5de07c5f7a09904412d01f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180305
    Tested-by: Jenkins
    Reviewed-by: Heiko Tietze <heiko.tie...@documentfoundation.org>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180483

diff --git a/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx 
b/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
index be843112859a..d109fb537fbd 100644
--- a/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
+++ b/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
@@ -13,6 +13,9 @@
 #include <editeng/editobj.hxx>
 #include <editeng/wghtitem.hxx>
 #include <editeng/eeitem.hxx>
+#include <editeng/boxitem.hxx>
+#include <editeng/borderline.hxx>
+#include <editeng/justifyitem.hxx>
 
 #include <editutil.hxx>
 
@@ -21,6 +24,8 @@
 #include <docfunc.hxx>
 #include <docsh.hxx>
 
+using namespace ::editeng;
+
 FormulaTemplate::FormulaTemplate(ScDocument* pDoc)
     : mpDoc(pDoc)
     , mbUse3D(true)
@@ -213,7 +218,9 @@ void AddressWalkerWriter::writeBoldString(const OUString& 
aString)
     rEngine.SetTextCurrentDefaults(aString);
     SfxItemSet aItemSet = rEngine.GetEmptyItemSet();
     SvxWeightItem aWeight(WEIGHT_BOLD, EE_CHAR_WEIGHT);
+    SvxHorJustifyItem aJustify(SvxCellHorJustify::Center, ATTR_HOR_JUSTIFY);
     aItemSet.Put(aWeight);
+    aItemSet.Put(aJustify);
     rEngine.QuickSetAttribs(aItemSet, ESelection(0, 0, 0, aString.getLength()) 
);
     std::unique_ptr<EditTextObject> pEditText(rEngine.CreateTextObject());
     mpDocShell->GetDocFunc().SetEditCell(mCurrentAddress, *pEditText, true);
@@ -224,6 +231,47 @@ void AddressWalkerWriter::writeValue(double aValue)
     mpDocShell->GetDocFunc().SetValueCell(mCurrentAddress, aValue, true);
 }
 
+// Applies a column header format to the current cell and subsequent (nCols - 
1) columns
+// Header format = bold font, horizontally centered, text wrap and top/bottom 
borders
+void AddressWalkerWriter::formatAsColumnHeader(SCCOL nCols)
+{
+    ScPatternAttr aPattern(mrDocument.getCellAttributeHelper());
+    SvxHorJustifyItem aHJustify(SvxCellHorJustify::Center, ATTR_HOR_JUSTIFY);
+    SvxVerJustifyItem aVJustify(SvxCellVerJustify::Center, ATTR_VER_JUSTIFY);
+    SvxWeightItem aWeight(WEIGHT_BOLD, ATTR_FONT_WEIGHT);
+    ScLineBreakCell aWrap(true);
+    SvxBoxItem aBorderOuter(ATTR_BORDER);
+    SvxBorderLine aLine;
+    aLine.GuessLinesWidths(aLine.GetBorderLineStyle(), 
SvxBorderLineWidth::Thin);
+    aBorderOuter.SetLine(&aLine, SvxBoxItemLine::TOP);
+    aBorderOuter.SetLine(&aLine, SvxBoxItemLine::BOTTOM);
+
+    aPattern.GetItemSet().Put(aHJustify);
+    aPattern.GetItemSet().Put(aVJustify);
+    aPattern.GetItemSet().Put(aWeight);
+    aPattern.GetItemSet().Put(aWrap);
+    aPattern.GetItemSet().Put(aBorderOuter);
+
+    mrDocument.ApplyPatternAreaTab(mCurrentAddress.Col(), 
mCurrentAddress.Row(),
+                                   mCurrentAddress.Col() + nCols - 1, 
mCurrentAddress.Row(),
+                                   mCurrentAddress.Tab(), aPattern);
+}
+
+// Formats as the bottom end of a table with a bottom line
+// Starts in the current cell and formats nCols in total
+void AddressWalkerWriter::formatTableBottom(SCCOL nCols)
+{
+    ScPatternAttr aPattern(mrDocument.getCellAttributeHelper());
+    SvxBoxItem aBorderOuter(ATTR_BORDER);
+    SvxBorderLine aLine;
+    aLine.GuessLinesWidths(aLine.GetBorderLineStyle(), 
SvxBorderLineWidth::Thin);
+    aBorderOuter.SetLine(&aLine, SvxBoxItemLine::BOTTOM);
+    aPattern.GetItemSet().Put(aBorderOuter);
+    mrDocument.ApplyPatternAreaTab(mCurrentAddress.Col(), 
mCurrentAddress.Row(),
+                                   mCurrentAddress.Col() + nCols - 1, 
mCurrentAddress.Row(),
+                                   mCurrentAddress.Tab(), aPattern);
+}
+
 // DataCellIterator
 
 DataCellIterator::DataCellIterator(const ScRange& aInputRange, bool aByColumn)
diff --git a/sc/source/ui/inc/TableFillingAndNavigationTools.hxx 
b/sc/source/ui/inc/TableFillingAndNavigationTools.hxx
index ab791151180f..0e678e3f4482 100644
--- a/sc/source/ui/inc/TableFillingAndNavigationTools.hxx
+++ b/sc/source/ui/inc/TableFillingAndNavigationTools.hxx
@@ -86,6 +86,8 @@ public:
     void writeString(const char* aCharArray);
     void writeBoldString(const OUString& aString);
     void writeValue(double aValue);
+    void formatAsColumnHeader(SCCOL nCols = 1);
+    void formatTableBottom(SCCOL nCols = 1);
 };
 
 class DataCellIterator final
diff --git a/sc/source/ui/miscdlgs/optsolver.cxx 
b/sc/source/ui/miscdlgs/optsolver.cxx
index 5f75a610def8..8adb033b3cac 100644
--- a/sc/source/ui/miscdlgs/optsolver.cxx
+++ b/sc/source/ui/miscdlgs/optsolver.cxx
@@ -39,6 +39,7 @@
 #include <optsolver.hxx>
 #include <table.hxx>
 #include <TableFillingAndNavigationTools.hxx>
+#include <tabvwsh.hxx>
 
 #include <com/sun/star/beans/XPropertySetInfo.hpp>
 #include <com/sun/star/sheet/SolverConstraint.hpp>
@@ -1258,10 +1259,12 @@ bool ScOptSolverDlg::CallSolver()       // return true 
-> close dialog after cal
             // Objective cell section
             aOutput.writeBoldString(ScResId(STR_SENSITIVITY_OBJCELL));
             aOutput.newLine();
+            aOutput.formatAsColumnHeader(2);
             aOutput.writeString(ScResId(STR_SENSITIVITY_CELL));
             aOutput.nextColumn();
             aOutput.writeString(ScResId(STR_SENSITIVITY_FINALVALUE));
             aOutput.newLine();
+            aOutput.formatTableBottom(2);
             aOutput.writeString(GetCellStrAddress(xSolver->getObjective()));
             aOutput.nextColumn();
             aOutput.writeValue(xSolver->getResultValue());
@@ -1271,6 +1274,7 @@ bool ScOptSolverDlg::CallSolver()       // return true -> 
close dialog after cal
             // Variable cell section
             aOutput.writeBoldString(ScResId(STR_SENSITIVITY_VARCELLS));
             aOutput.newLine();
+            aOutput.formatAsColumnHeader(6);
             aOutput.writeString(ScResId(STR_SENSITIVITY_CELL));
             aOutput.nextColumn();
             aOutput.writeString(ScResId(STR_SENSITIVITY_FINALVALUE));
@@ -1289,8 +1293,11 @@ bool ScOptSolverDlg::CallSolver()       // return true 
-> close dialog after cal
             uno::Sequence<double> aObjReducedCosts = 
aSensitivity.ObjReducedCosts;
             uno::Sequence<double> aObjAllowableDecreases = 
aSensitivity.ObjAllowableDecreases;
             uno::Sequence<double> aObjAllowableIncreases = 
aSensitivity.ObjAllowableIncreases;
-            for (sal_Int32 i = 0; i < aVariables.getLength(); i++)
+            sal_Int32 nRows = aVariables.getLength();
+            for (sal_Int32 i = 0; i < nRows; i++)
             {
+                if (i == nRows - 1)
+                    aOutput.formatTableBottom(6);
                 aOutput.writeString(GetCellStrAddress(aVariables[i]));
                 aOutput.nextColumn();
                 aOutput.writeValue(aSolution[i]);
@@ -1309,6 +1316,7 @@ bool ScOptSolverDlg::CallSolver()       // return true -> 
close dialog after cal
             // Constraints section
             aOutput.writeBoldString(ScResId(STR_SENSITIVITY_CONSTRAINTS));
             aOutput.newLine();
+            aOutput.formatAsColumnHeader(6);
             aOutput.writeString(ScResId(STR_SENSITIVITY_CELL));
             aOutput.nextColumn();
             aOutput.writeString(ScResId(STR_SENSITIVITY_FINALVALUE));
@@ -1327,8 +1335,11 @@ bool ScOptSolverDlg::CallSolver()       // return true 
-> close dialog after cal
             uno::Sequence<double> aConstrShadowPrices = 
aSensitivity.ConstrShadowPrices;
             uno::Sequence<double> aConstrAllowableDecreases = 
aSensitivity.ConstrAllowableDecreases;
             uno::Sequence<double> aConstrAllowableIncreases = 
aSensitivity.ConstrAllowableIncreases;
-            for (sal_Int32 i = 0; i < aConstraints.getLength(); i++)
+            nRows = aConstraints.getLength();
+            for (sal_Int32 i = 0; i < nRows; i++)
             {
+                if (i == nRows - 1)
+                    aOutput.formatTableBottom(6);
                 aOutput.writeString(GetCellStrAddress(aConstraints[i].Left));
                 aOutput.nextColumn();
                 aOutput.writeValue(aConstrValues[i]);
@@ -1342,6 +1353,12 @@ bool ScOptSolverDlg::CallSolver()       // return true 
-> close dialog after cal
                 aOutput.writeValue(aConstrAllowableIncreases[i]);
                 aOutput.newLine();
             }
+
+            // Disable grid lines in the sensitivity report
+            ScViewData& aData = 
ScTabViewShell::GetActiveViewShell()->GetViewData();
+            aData.SetTabNo(nReportTab);
+            aData.SetShowGrid(false);
+            aData.SetTabNo(mnCurTab);
         }
     }
 

Reply via email to