summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-05-07 10:36:28 +0200
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-05-15 19:51:04 +0200
commit2067d03f8ad7e58ae0ac1387a51858f012e8c7f1 (patch)
tree32d015e49a2fbff331f7178550b93c30af69b1c3
parent858232e3c78d5d8f013324887e29a74ea2f21bab (diff)
fdo#76718 Rounding for "fill > random number.." option
Change-Id: Idb4b6442be7ddb08875c6b59f54a887399385be7
-rw-r--r--sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx64
-rw-r--r--sc/source/ui/inc/RandomNumberGeneratorDialog.hxx16
-rw-r--r--sc/uiconfig/scalc/ui/randomnumbergenerator.ui65
3 files changed, 111 insertions, 34 deletions
diff --git a/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx b/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx
index 4a2fd8aacc74..b58d34ab8b7a 100644
--- a/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx
@@ -11,6 +11,7 @@
#include <sfx2/dispatch.hxx>
#include <svl/zforlist.hxx>
#include <svl/undo.hxx>
+#include <rtl/math.hxx>
#include "rangelst.hxx"
#include "scitems.hxx"
@@ -36,7 +37,8 @@
#include "RandomNumberGeneratorDialog.hxx"
-namespace {
+namespace
+{
const sal_Int64 DIST_UNIFORM = 0;
const sal_Int64 DIST_NORMAL = 1;
@@ -76,11 +78,14 @@ ScRandomNumberGeneratorDialog::ScRandomNumberGeneratorDialog(
get(mpEnableSeed, "enable-seed-check");
get(mpSeed, "seed-spin");
+ get(mpEnableRounding, "enable-rounding-check");
+ get(mpDecimalPlaces, "decimal-places-spin");
+
get(mpDistributionCombo, "distribution-combo");
get(mpButtonOk, "ok");
get(mpButtonApply, "apply");
- get(mpButtonClose, "close");
+ get(mpButtonClose, "close");
Init();
GetRangeFromSelection();
@@ -105,10 +110,11 @@ void ScRandomNumberGeneratorDialog::Init()
mpDistributionCombo->SetSelectHdl( LINK( this, ScRandomNumberGeneratorDialog, DistributionChanged ));
- mpEnableSeed->SetToggleHdl( LINK( this, ScRandomNumberGeneratorDialog, SeedCheckChanged ));
+ mpEnableSeed->SetToggleHdl( LINK( this, ScRandomNumberGeneratorDialog, CheckChanged ));
+ mpEnableRounding->SetToggleHdl( LINK( this, ScRandomNumberGeneratorDialog, CheckChanged ));
DistributionChanged(NULL);
- SeedCheckChanged(NULL);
+ CheckChanged(NULL);
}
void ScRandomNumberGeneratorDialog::GetRangeFromSelection()
@@ -181,78 +187,85 @@ void ScRandomNumberGeneratorDialog::SelectGeneratorAndGenerateNumbers()
double parameter1 = parameterInteger1 / static_cast<double>(PERCISION);
double parameter2 = parameterInteger2 / static_cast<double>(PERCISION);
+ boost::optional<sal_Int8> aDecimalPlaces;
+ if (mpEnableRounding->IsChecked())
+ {
+ aDecimalPlaces = static_cast<sal_Int8>(mpDecimalPlaces->GetValue());
+ }
+
switch(aSelectedId)
{
case DIST_UNIFORM:
{
boost::random::uniform_real_distribution<> distribution(parameter1, parameter2);
boost::variate_generator<boost::mt19937&, boost::random::uniform_real_distribution<> > rng(seed, distribution);
- GenerateNumbers(rng, SC_STRLOAD( RID_STATISTICS_DLGS, STR_DISTRIBUTION_UNIFORM_REAL));
+ GenerateNumbers(rng, STR_DISTRIBUTION_UNIFORM_REAL, aDecimalPlaces);
break;
}
case DIST_UNIFORM_INTEGER:
{
boost::random::uniform_int_distribution<> distribution(parameterInteger1, parameterInteger2);
boost::variate_generator<boost::mt19937&, boost::random::uniform_int_distribution<> > rng(seed, distribution);
- GenerateNumbers(rng, SC_STRLOAD( RID_STATISTICS_DLGS, STR_DISTRIBUTION_UNIFORM_INTEGER));
+ GenerateNumbers(rng, STR_DISTRIBUTION_UNIFORM_INTEGER, aDecimalPlaces);
break;
}
case DIST_NORMAL:
{
boost::random::normal_distribution<> distribution(parameter1, parameter2);
boost::variate_generator<boost::mt19937&, boost::random::normal_distribution<> > rng(seed, distribution);
- GenerateNumbers(rng, SC_STRLOAD( RID_STATISTICS_DLGS, STR_DISTRIBUTION_NORMAL));
+ GenerateNumbers(rng, STR_DISTRIBUTION_NORMAL, aDecimalPlaces);
break;
}
case DIST_CAUCHY:
{
boost::random::cauchy_distribution<> distribution(parameter1);
boost::variate_generator<boost::mt19937&, boost::random::cauchy_distribution<> > rng(seed, distribution);
- GenerateNumbers(rng, SC_STRLOAD( RID_STATISTICS_DLGS, STR_DISTRIBUTION_CAUCHY));
+ GenerateNumbers(rng, STR_DISTRIBUTION_CAUCHY, aDecimalPlaces);
break;
}
case DIST_BERNOULLI:
{
boost::random::bernoulli_distribution<> distribution(parameter1);
boost::variate_generator<boost::mt19937&, boost::random::bernoulli_distribution<> > rng(seed, distribution);
- GenerateNumbers(rng, SC_STRLOAD( RID_STATISTICS_DLGS, STR_DISTRIBUTION_BERNOULLI));
+ GenerateNumbers(rng, STR_DISTRIBUTION_BERNOULLI, aDecimalPlaces);
break;
}
case DIST_BINOMIAL:
{
boost::random::binomial_distribution<> distribution(parameterInteger2, parameter1);
boost::variate_generator<boost::mt19937&, boost::random::binomial_distribution<> > rng(seed, distribution);
- GenerateNumbers(rng, SC_STRLOAD( RID_STATISTICS_DLGS, STR_DISTRIBUTION_BINOMIAL));
+ GenerateNumbers(rng, STR_DISTRIBUTION_BINOMIAL, aDecimalPlaces);
break;
}
case DIST_NEGATIVE_BINOMIAL:
{
boost::random::negative_binomial_distribution<> distribution(parameterInteger2, parameter1);
boost::variate_generator<boost::mt19937&, boost::random::negative_binomial_distribution<> > rng(seed, distribution);
- GenerateNumbers(rng, SC_STRLOAD( RID_STATISTICS_DLGS, STR_DISTRIBUTION_NEGATIVE_BINOMIAL));
+ GenerateNumbers(rng, STR_DISTRIBUTION_NEGATIVE_BINOMIAL, aDecimalPlaces);
break;
}
case DIST_CHI_SQUARED:
{
boost::random::chi_squared_distribution<> distribution(parameter1);
boost::variate_generator<boost::mt19937&, boost::random::chi_squared_distribution<> > rng(seed, distribution);
- GenerateNumbers(rng, SC_STRLOAD( RID_STATISTICS_DLGS, STR_DISTRIBUTION_CHI_SQUARED));
+ GenerateNumbers(rng, STR_DISTRIBUTION_CHI_SQUARED, aDecimalPlaces);
break;
}
case DIST_GEOMETRIC:
{
boost::random::geometric_distribution<> distribution(parameter1);
boost::variate_generator<boost::mt19937&, boost::random::geometric_distribution<> > rng(seed, distribution);
- GenerateNumbers(rng, SC_STRLOAD( RID_STATISTICS_DLGS, STR_DISTRIBUTION_GEOMETRIC));
+ GenerateNumbers(rng, STR_DISTRIBUTION_GEOMETRIC, aDecimalPlaces);
break;
}
}
}
template<class RNG>
-void ScRandomNumberGeneratorDialog::GenerateNumbers(RNG randomGenerator, const OUString& aDistributionName)
+void ScRandomNumberGeneratorDialog::GenerateNumbers(RNG randomGenerator, const sal_Int16 aDistributionStringId, boost::optional<sal_Int8> aDecimalPlaces)
{
- OUString aUndo = SC_STRLOAD( RID_STATISTICS_DLGS, STR_UNDO_DISTRIBUTION_TEMPLATE);
+ OUString aUndo = SC_STRLOAD(RID_STATISTICS_DLGS, STR_UNDO_DISTRIBUTION_TEMPLATE);
+ OUString aDistributionName = SC_STRLOAD(RID_STATISTICS_DLGS, aDistributionStringId);
aUndo = aUndo.replaceAll("$(DISTRIBUTION)", aDistributionName);
ScDocShell* pDocShell = mpViewData->GetDocShell();
@@ -267,7 +280,7 @@ void ScRandomNumberGeneratorDialog::GenerateNumbers(RNG randomGenerator, const O
SCTAB nTabEnd = maInputRange.aEnd.Tab();
std::vector<double> aVals;
- aVals.reserve(nRowEnd-nRowStart+1);
+ aVals.reserve(nRowEnd - nRowStart + 1);
for (SCROW nTab = nTabStart; nTab <= nTabEnd; ++nTab)
{
@@ -277,7 +290,13 @@ void ScRandomNumberGeneratorDialog::GenerateNumbers(RNG randomGenerator, const O
ScAddress aPos(nCol, nRowStart, nTab);
for (SCROW nRow = nRowStart; nRow <= nRowEnd; ++nRow)
- aVals.push_back(randomGenerator());
+ {
+
+ if (aDecimalPlaces)
+ aVals.push_back(rtl::math::round(randomGenerator(), *aDecimalPlaces));
+ else
+ aVals.push_back(randomGenerator());
+ }
pDocShell->GetDocFunc().SetValueCells(aPos, aVals, true);
}
@@ -361,9 +380,10 @@ IMPL_LINK_NOARG(ScRandomNumberGeneratorDialog, Parameter2ValueModified)
return 0;
}
-IMPL_LINK_NOARG(ScRandomNumberGeneratorDialog, SeedCheckChanged)
+IMPL_LINK_NOARG(ScRandomNumberGeneratorDialog, CheckChanged)
{
mpSeed->Enable(mpEnableSeed->IsChecked());
+ mpDecimalPlaces->Enable(mpEnableRounding->IsChecked());
return 0;
}
@@ -372,10 +392,10 @@ IMPL_LINK_NOARG(ScRandomNumberGeneratorDialog, DistributionChanged)
sal_Int16 aSelectedIndex = mpDistributionCombo-> GetSelectEntryPos();
sal_Int64 aSelectedId = (sal_Int64) mpDistributionCombo->GetEntryData(aSelectedIndex);
- mpParameter1Value->SetMin( SAL_MIN_INT64 );
- mpParameter1Value->SetMax( SAL_MAX_INT64 );
- mpParameter2Value->SetMin( SAL_MIN_INT64 );
- mpParameter2Value->SetMax( SAL_MAX_INT64 );
+ mpParameter1Value->SetMin(SAL_MIN_INT64);
+ mpParameter1Value->SetMax(SAL_MAX_INT64);
+ mpParameter2Value->SetMin(SAL_MIN_INT64);
+ mpParameter2Value->SetMax(SAL_MAX_INT64);
mpParameter1Value->SetDecimalDigits(DIGITS);
mpParameter1Value->SetSpinSize(PERCISION);
diff --git a/sc/source/ui/inc/RandomNumberGeneratorDialog.hxx b/sc/source/ui/inc/RandomNumberGeneratorDialog.hxx
index 2146ebb852ce..ffb95d57bdfa 100644
--- a/sc/source/ui/inc/RandomNumberGeneratorDialog.hxx
+++ b/sc/source/ui/inc/RandomNumberGeneratorDialog.hxx
@@ -15,11 +15,12 @@
#include "address.hxx"
#include "anyrefdg.hxx"
-
#include <vcl/fixed.hxx>
#include <vcl/group.hxx>
#include <vcl/lstbox.hxx>
+#include <boost/optional.hpp>
+
class ScRandomNumberGeneratorDialog : public ScAnyRefDlg
{
public:
@@ -29,9 +30,9 @@ public:
virtual ~ScRandomNumberGeneratorDialog();
- virtual void SetReference( const ScRange& rRef, ScDocument* pDoc ) SAL_OVERRIDE;
- virtual void SetActive() SAL_OVERRIDE;
- virtual bool Close() SAL_OVERRIDE;
+ virtual void SetReference( const ScRange& rRef, ScDocument* pDoc ) SAL_OVERRIDE;
+ virtual void SetActive() SAL_OVERRIDE;
+ virtual bool Close() SAL_OVERRIDE;
private:
// Widgets
@@ -45,6 +46,8 @@ private:
NumericField* mpParameter2Value;
NumericField* mpSeed;
CheckBox* mpEnableSeed;
+ NumericField* mpDecimalPlaces;
+ CheckBox* mpEnableRounding;
PushButton* mpButtonApply;
OKButton* mpButtonOk;
CloseButton* mpButtonClose;
@@ -61,7 +64,8 @@ private:
void GetRangeFromSelection();
template<class RNG>
- void GenerateNumbers(RNG randomGenerator, const OUString& aDistributionName);
+
+ void GenerateNumbers(RNG randomGenerator, const sal_Int16 aDistributionStringId, const boost::optional<sal_Int8> aDecimalPlaces);
void SelectGeneratorAndGenerateNumbers();
@@ -74,7 +78,7 @@ private:
DECL_LINK( Parameter1ValueModified, void* );
DECL_LINK( Parameter2ValueModified, void* );
DECL_LINK( DistributionChanged, void* );
- DECL_LINK( SeedCheckChanged, void* );
+ DECL_LINK( CheckChanged, void* );
};
diff --git a/sc/uiconfig/scalc/ui/randomnumbergenerator.ui b/sc/uiconfig/scalc/ui/randomnumbergenerator.ui
index e1e7f2ac9152..cd7b8b9f8c95 100644
--- a/sc/uiconfig/scalc/ui/randomnumbergenerator.ui
+++ b/sc/uiconfig/scalc/ui/randomnumbergenerator.ui
@@ -1,7 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.16.1 -->
<interface>
- <!-- interface-requires gtk+ 3.0 -->
+ <requires lib="gtk+" version="3.0"/>
<!-- interface-requires LibreOffice 1.0 -->
+ <object class="GtkAdjustment" id="decimal-places-adjustment">
+ <property name="lower">1</property>
+ <property name="upper">255</property>
+ <property name="value">1</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
<object class="GtkListStore" id="distribution-liststore">
<columns>
<!-- column-name value -->
@@ -157,7 +165,6 @@
<property name="hexpand">True</property>
<property name="invisible_char">•</property>
<property name="width_chars">30</property>
- <property name="invisible_char_set">True</property>
</object>
<packing>
<property name="left_attach">1</property>
@@ -213,7 +220,6 @@
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="invisible_char">•</property>
- <property name="invisible_char_set">True</property>
</object>
<packing>
<property name="left_attach">1</property>
@@ -298,7 +304,6 @@
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="invisible_char">•</property>
- <property name="invisible_char_set">True</property>
<property name="adjustment">parameter2-adjustment</property>
<property name="digits">4</property>
</object>
@@ -315,7 +320,6 @@
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="invisible_char">•</property>
- <property name="invisible_char_set">True</property>
<property name="adjustment">parameter1-adjustment</property>
<property name="digits">4</property>
</object>
@@ -340,7 +344,7 @@
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">4</property>
+ <property name="top_attach">6</property>
<property name="width">3</property>
<property name="height">1</property>
</packing>
@@ -361,6 +365,55 @@
<property name="height">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkCheckButton" id="enable-rounding-check">
+ <property name="label" translatable="yes">Enable Rounding</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">4</property>
+ <property name="width">3</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="decimal-places-label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Decimal Places</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">decimal-places-spin</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">5</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="decimal-places-spin">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hexpand">True</property>
+ <property name="invisible_char">•</property>
+ <property name="adjustment">decimal-places-adjustment</property>
+ <property name="value">1</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">5</property>
+ <property name="width">2</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>