summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <quikee@gmail.com>2013-07-18 22:32:22 +0200
committerTomaž Vajngerl <quikee@gmail.com>2013-07-19 16:57:38 +0200
commitceefeb680b30908487388e4e4f9b3aa36d173a75 (patch)
tree46c817c0b5feb2c2435658ecef37444f7ae2e4fd
parentfa20e0dd67c1da8fe8653f163e0fc6743934e7ae (diff)
Cleanup of RNG, Sampling and Descriptive Statistics Dialogs
Change-Id: I659b4bed483fc06fa5777236d6ebec22f6c7f391
-rw-r--r--sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx33
-rw-r--r--sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.src9
-rw-r--r--sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx36
-rw-r--r--sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.src11
-rw-r--r--sc/source/ui/StatisticsDialogs/SamplingDialog.cxx186
-rw-r--r--sc/source/ui/StatisticsDialogs/SamplingDialog.src9
-rw-r--r--sc/source/ui/inc/DescriptiveStatisticsDialog.hxx4
-rw-r--r--sc/source/ui/inc/RandomNumberGeneratorDialog.hxx4
-rw-r--r--sc/source/ui/inc/SamplingDialog.hxx7
-rw-r--r--sc/uiconfig/scalc/ui/descriptivestatisticsdialog.ui17
-rw-r--r--sc/uiconfig/scalc/ui/randomnumbergenerator.ui6
-rw-r--r--sc/uiconfig/scalc/ui/samplingdialog.ui16
12 files changed, 162 insertions, 176 deletions
diff --git a/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx b/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx
index b2df789e5424..31b3a1fbb8e6 100644
--- a/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx
@@ -29,10 +29,9 @@
#include "DescriptiveStatisticsDialog.hxx"
-#define ABS_DREF3D SCA_VALID | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE | SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE | SCA_TAB2_ABSOLUTE | SCA_TAB_3D
-
namespace
{
+
struct StatisticCalculation {
const sal_Int16 aCalculationNameId;
const char* aFormula;
@@ -59,29 +58,31 @@ static const StatisticCalculation lclCalcDefinitions[] =
}
ScDescriptiveStatisticsDialog::ScDescriptiveStatisticsDialog(
- SfxBindings* pB, SfxChildWindow* pCW, Window* pParent, ScViewData* pViewData ) :
- ScAnyRefDlg ( pB, pCW, pParent, "DescriptiveStatisticsDialog", "modules/scalc/ui/descriptivestatisticsdialog.ui" ),
+ SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
+ Window* pParent, ScViewData* pViewData ) :
+ ScAnyRefDlg ( pSfxBindings, pChildWindow, pParent,
+ "DescriptiveStatisticsDialog", "modules/scalc/ui/descriptivestatisticsdialog.ui" ),
mViewData ( pViewData ),
mDocument ( pViewData->GetDocument() ),
mAddressDetails ( mDocument->GetAddressConvention(), 0, 0 ),
mCurrentAddress ( pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo() ),
mDialogLostFocus( false )
{
- get(mpInputRangeLabel, "input-range-label");
- get(mpInputRangeEdit, "input-range-edit");
- mpInputRangeEdit->SetReferences(this, mpInputRangeLabel);
+ get(mpInputRangeLabel, "input-range-label");
+ get(mpInputRangeEdit, "input-range-edit");
get(mpInputRangeButton, "input-range-button");
+ mpInputRangeEdit->SetReferences(this, mpInputRangeLabel);
mpInputRangeButton->SetReferences(this, mpInputRangeEdit);
- get(mpOutputRangeLabel, "output-range-label");
- get(mpOutputRangeEdit, "output-range-edit");
- mpOutputRangeEdit->SetReferences(this, mpOutputRangeLabel);
+ get(mpOutputRangeLabel, "output-range-label");
+ get(mpOutputRangeEdit, "output-range-edit");
get(mpOutputRangeButton, "output-range-button");
+ mpOutputRangeEdit->SetReferences(this, mpOutputRangeLabel);
mpOutputRangeButton->SetReferences(this, mpOutputRangeEdit);
get(mpButtonOk, "ok");
get(mpButtonApply, "apply");
- get(mpButtonCancel, "cancel");
+ get(mpButtonClose, "close");
Init();
GetRangeFromSelection();
@@ -90,7 +91,7 @@ ScDescriptiveStatisticsDialog::ScDescriptiveStatisticsDialog(
void ScDescriptiveStatisticsDialog::Init()
{
mpButtonOk->SetClickHdl( LINK( this, ScDescriptiveStatisticsDialog, OkClicked ) );
- mpButtonCancel->SetClickHdl( LINK( this, ScDescriptiveStatisticsDialog, CancelClicked ) );
+ mpButtonClose->SetClickHdl( LINK( this, ScDescriptiveStatisticsDialog, CloseClicked ) );
mpButtonApply->SetClickHdl( LINK( this, ScDescriptiveStatisticsDialog, ApplyClicked ) );
mpButtonOk->Enable(false);
mpButtonApply->Enable(false);
@@ -114,7 +115,7 @@ void ScDescriptiveStatisticsDialog::GetRangeFromSelection()
{
OUString aCurrentString;
mViewData->GetSimpleArea(mInputRange);
- mInputRange.Format(aCurrentString, ABS_DREF3D, mDocument, mAddressDetails);
+ mInputRange.Format(aCurrentString, SCR_ABS_3D, mDocument, mAddressDetails);
mpInputRangeEdit->SetText(aCurrentString);
}
@@ -153,7 +154,7 @@ void ScDescriptiveStatisticsDialog::SetReference( const ScRange& rReferenceRange
if ( mpActiveEdit == mpInputRangeEdit )
{
mInputRange = rReferenceRange;
- mInputRange.Format( aReferenceString, ABS_DREF3D, pDocument, mAddressDetails );
+ mInputRange.Format( aReferenceString, SCR_ABS_3D, pDocument, mAddressDetails );
mpInputRangeEdit->SetRefString( aReferenceString );
}
else if ( mpActiveEdit == mpOutputRangeEdit )
@@ -235,7 +236,7 @@ void ScDescriptiveStatisticsDialog::ApplyCalculationsFormulas( )
IMPL_LINK( ScDescriptiveStatisticsDialog, OkClicked, PushButton*, /*pButton*/ )
{
ApplyClicked(NULL);
- CancelClicked(NULL);
+ CloseClicked(NULL);
return 0;
}
@@ -246,7 +247,7 @@ IMPL_LINK( ScDescriptiveStatisticsDialog, ApplyClicked, PushButton*, /*pButton*/
return 0;
}
-IMPL_LINK( ScDescriptiveStatisticsDialog, CancelClicked, PushButton*, /*pButton*/ )
+IMPL_LINK( ScDescriptiveStatisticsDialog, CloseClicked, PushButton*, /*pButton*/ )
{
Close();
return 0;
diff --git a/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.src b/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.src
index af44357dc2db..035dab7c57ea 100644
--- a/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.src
+++ b/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.src
@@ -6,15 +6,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "globstr.hrc"
diff --git a/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx b/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx
index 06e02f5707af..779252e9bdfe 100644
--- a/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.cxx
@@ -38,8 +38,6 @@
#include "RandomNumberGeneratorDialog.hxx"
-#define ABS_DREF3D SCA_VALID | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE | SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE | SCA_TAB2_ABSOLUTE | SCA_TAB_3D
-
namespace
{
@@ -58,33 +56,35 @@ static const sal_Int64 DIGITS = 4;
}
ScRandomNumberGeneratorDialog::ScRandomNumberGeneratorDialog(
- SfxBindings* pB, SfxChildWindow* pCW, Window* pParent, ScViewData* pViewData ) :
- ScAnyRefDlg ( pB, pCW, pParent, "RandomNumberGeneratorDialog", "modules/scalc/ui/randomnumbergenerator.ui" ),
+ SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
+ Window* pParent, ScViewData* pViewData ) :
+ ScAnyRefDlg ( pSfxBindings, pChildWindow, pParent,
+ "RandomNumberGeneratorDialog", "modules/scalc/ui/randomnumbergenerator.ui" ),
mViewData ( pViewData ),
mDocument ( pViewData->GetDocument() ),
mAddressDetails ( mDocument->GetAddressConvention(), 0, 0 ),
mDialogLostFocus( false )
{
- get(mpInputRangeText, "cell-range-label");
- get(mpInputRangeEdit, "cell-range-edit");
- mpInputRangeEdit->SetReferences(this, mpInputRangeText);
+ get(mpInputRangeText, "cell-range-label");
+ get(mpInputRangeEdit, "cell-range-edit");
get(mpInputRangeButton, "cell-range-button");
+ mpInputRangeEdit->SetReferences(this, mpInputRangeText);
mpInputRangeButton->SetReferences(this, mpInputRangeEdit);
- get(mpButtonOk, "ok");
- get(mpButtonApply, "apply");
- get(mpButtonCancel, "cancel");
-
get(mpParameter1Value, "parameter1-spin");
get(mpParameter1Text, "parameter1-label");
get(mpParameter2Value, "parameter2-spin");
get(mpParameter2Text, "parameter2-label");
get(mpEnableSeed, "enable-seed-check");
- get(mpSeed, "seed-spin");
+ get(mpSeed, "seed-spin");
get(mpDistributionCombo, "distribution-combo");
+ get(mpButtonOk, "ok");
+ get(mpButtonApply, "apply");
+ get(mpButtonClose, "close");
+
Init();
GetRangeFromSelection();
}
@@ -92,7 +92,7 @@ ScRandomNumberGeneratorDialog::ScRandomNumberGeneratorDialog(
void ScRandomNumberGeneratorDialog::Init()
{
mpButtonOk->SetClickHdl( LINK( this, ScRandomNumberGeneratorDialog, OkClicked ) );
- mpButtonCancel->SetClickHdl( LINK( this, ScRandomNumberGeneratorDialog, CancelClicked ) );
+ mpButtonClose->SetClickHdl( LINK( this, ScRandomNumberGeneratorDialog, CloseClicked ) );
mpButtonApply->SetClickHdl( LINK( this, ScRandomNumberGeneratorDialog, ApplyClicked ) );
Link aLink = LINK( this, ScRandomNumberGeneratorDialog, GetFocusHandler );
@@ -118,7 +118,7 @@ void ScRandomNumberGeneratorDialog::GetRangeFromSelection()
{
OUString aCurrentString;
mViewData->GetSimpleArea(mInputRange);
- mInputRange.Format( aCurrentString, ABS_DREF3D, mDocument, mAddressDetails );
+ mInputRange.Format( aCurrentString, SCR_ABS_3D, mDocument, mAddressDetails );
mpInputRangeEdit->SetText( aCurrentString );
}
@@ -155,7 +155,7 @@ void ScRandomNumberGeneratorDialog::SetReference( const ScRange& rReferenceRange
mInputRange = rReferenceRange;
String aReferenceString;
- mInputRange.Format( aReferenceString, ABS_DREF3D, pDocument, mAddressDetails );
+ mInputRange.Format( aReferenceString, SCR_ABS_3D, pDocument, mAddressDetails );
mpInputRangeEdit->SetRefString( aReferenceString );
}
}
@@ -289,8 +289,8 @@ void ScRandomNumberGeneratorDialog::GenerateNumbers(RNG randomGenerator, OUStrin
IMPL_LINK( ScRandomNumberGeneratorDialog, OkClicked, PushButton*, /*pButton*/ )
{
- SelectGeneratorAndGenerateNumbers();
- Close();
+ ApplyClicked(NULL);
+ CloseClicked(NULL);
return 0;
}
@@ -301,7 +301,7 @@ IMPL_LINK( ScRandomNumberGeneratorDialog, ApplyClicked, PushButton*, /*pButton*/
return 0;
}
-IMPL_LINK( ScRandomNumberGeneratorDialog, CancelClicked, PushButton*, /*pButton*/ )
+IMPL_LINK( ScRandomNumberGeneratorDialog, CloseClicked, PushButton*, /*pButton*/ )
{
Close();
return 0;
diff --git a/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.src b/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.src
index b30ae232505c..afd889120a7f 100644
--- a/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.src
+++ b/sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.src
@@ -6,15 +6,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "globstr.hrc"
@@ -89,7 +80,7 @@ String STR_RNG_PARAMETER_STANDARD_PROBABILITY
};
String STR_RNG_PARAMETER_STANDARD_NUMBER_OF_TRIALS
{
- Text [ en-US ] = "Number Of Trials";
+ Text [ en-US ] = "Number of Trials";
};
String STR_RNG_PARAMETER_STANDARD_NU_VALUE
{
diff --git a/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx b/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx
index d78d901f8a13..e480112c7f25 100644
--- a/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/SamplingDialog.cxx
@@ -28,31 +28,27 @@
#include "SamplingDialog.hxx"
-#define ABS_DREF3D SCA_VALID | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE | SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE | SCA_TAB2_ABSOLUTE | SCA_TAB_3D
-
-namespace
-{
-}
-
ScSamplingDialog::ScSamplingDialog(
- SfxBindings* pB, SfxChildWindow* pCW, Window* pParent, ScViewData* pViewData ) :
- ScAnyRefDlg ( pB, pCW, pParent, "SamplingDialog", "modules/scalc/ui/samplingdialog.ui" ),
+ SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
+ Window* pParent, ScViewData* pViewData ) :
+ ScAnyRefDlg ( pSfxBindings, pChildWindow, pParent,
+ "SamplingDialog", "modules/scalc/ui/samplingdialog.ui" ),
mViewData ( pViewData ),
mDocument ( pViewData->GetDocument() ),
mAddressDetails ( mDocument->GetAddressConvention(), 0, 0 ),
mCurrentAddress ( pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo() ),
mDialogLostFocus( false )
{
- get(mpInputRangeLabel, "input-range-label");
- get(mpInputRangeEdit, "input-range-edit");
- mpInputRangeEdit->SetReferences(this, mpInputRangeLabel);
+ get(mpInputRangeLabel, "input-range-label");
+ get(mpInputRangeEdit, "input-range-edit");
get(mpInputRangeButton, "input-range-button");
+ mpInputRangeEdit->SetReferences(this, mpInputRangeLabel);
mpInputRangeButton->SetReferences(this, mpInputRangeEdit);
- get(mpOutputRangeLabel, "output-range-label");
- get(mpOutputRangeEdit, "output-range-edit");
- mpOutputRangeEdit->SetReferences(this, mpOutputRangeLabel);
+ get(mpOutputRangeLabel, "output-range-label");
+ get(mpOutputRangeEdit, "output-range-edit");
get(mpOutputRangeButton, "output-range-button");
+ mpOutputRangeEdit->SetReferences(this, mpOutputRangeLabel);
mpOutputRangeButton->SetReferences(this, mpOutputRangeEdit);
get(mpSampleSize, "sample-size-spin");
@@ -63,7 +59,7 @@ ScSamplingDialog::ScSamplingDialog(
get(mpButtonOk, "ok");
get(mpButtonApply, "apply");
- get(mpButtonCancel, "cancel");
+ get(mpButtonClose, "close");
Init();
GetRangeFromSelection();
@@ -72,7 +68,7 @@ ScSamplingDialog::ScSamplingDialog(
void ScSamplingDialog::Init()
{
mpButtonOk->SetClickHdl( LINK( this, ScSamplingDialog, OkClicked ) );
- mpButtonCancel->SetClickHdl( LINK( this, ScSamplingDialog, CancelClicked ) );
+ mpButtonClose->SetClickHdl( LINK( this, ScSamplingDialog, CloseClicked ) );
mpButtonApply->SetClickHdl( LINK( this, ScSamplingDialog, ApplyClicked ) );
mpButtonOk->Enable(false);
mpButtonApply->Enable(false);
@@ -107,7 +103,7 @@ void ScSamplingDialog::GetRangeFromSelection()
{
OUString aCurrentString;
mViewData->GetSimpleArea(mInputRange);
- mInputRange.Format(aCurrentString, ABS_DREF3D, mDocument, mAddressDetails);
+ mInputRange.Format(aCurrentString, SCR_ABS_3D, mDocument, mAddressDetails);
mpInputRangeEdit->SetText(aCurrentString);
}
@@ -146,7 +142,7 @@ void ScSamplingDialog::SetReference( const ScRange& rReferenceRange, ScDocument*
if ( mpActiveEdit == mpInputRangeEdit )
{
mInputRange = rReferenceRange;
- mInputRange.Format( aReferenceString, ABS_DREF3D, pDocument, mAddressDetails );
+ mInputRange.Format( aReferenceString, SCR_ABS_3D, pDocument, mAddressDetails );
mpInputRangeEdit->SetRefString( aReferenceString );
}
else if ( mpActiveEdit == mpOutputRangeEdit )
@@ -166,18 +162,12 @@ void ScSamplingDialog::SetReference( const ScRange& rReferenceRange, ScDocument*
// Enable OK, Cancel if output range is set
mpButtonOk->Enable(!mpOutputRangeEdit->GetText().isEmpty());
mpButtonApply->Enable(!mpOutputRangeEdit->GetText().isEmpty());
-
}
}
}
-void ScSamplingDialog::PerformSampling()
+ScRange ScSamplingDialog::PerformPeriodicSampling(ScDocShell* pDocShell)
{
- OUString aUndo(ScResId(STR_SAMPLING_UNDO_NAME));
- ScDocShell* pDocShell = mViewData->GetDocShell();
- svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
- pUndoManager->EnterListAction( aUndo, aUndo );
-
ScAddress aStart = mInputRange.aStart;
ScAddress aEnd = mInputRange.aEnd;
@@ -185,86 +175,114 @@ void ScSamplingDialog::PerformSampling()
SCCOL outCol = mOutputAddress.Col();
SCROW outRow = mOutputAddress.Row();
- if (mpRandomMethodRadio->IsChecked())
- {
- TimeValue now;
- osl_getSystemTime(&now);
- boost::mt19937 seed(now.Nanosec);
- boost::uniform_01<boost::mt19937> rng(seed);
+ sal_Int64 aPeriod = mpPeriod->GetValue();
- SCROW inRow;
-
- sal_Int64 aSampleSize = mpSampleSize->GetValue();
-
- for (SCROW inTab = aStart.Tab(); inTab <= aEnd.Tab(); inTab++)
+ for (SCROW inTab = aStart.Tab(); inTab <= aEnd.Tab(); inTab++)
+ {
+ outCol = mOutputAddress.Col();
+ for (SCCOL inCol = aStart.Col(); inCol <= aEnd.Col(); inCol++)
{
- outCol = mOutputAddress.Col();
- for (SCCOL inCol = aStart.Col(); inCol <= aEnd.Col(); inCol++)
+ sal_Int64 i = 0;
+ outRow = mOutputAddress.Row();
+ for (SCROW inRow = aStart.Row(); inRow <= aEnd.Row(); inRow++)
{
- SCROW aPopulationSize = (aEnd.Row() - aStart.Row()) + 1;
-
- outRow = mOutputAddress.Row();
- inRow = aStart.Row();
-
- double aRandomValue;
-
- while ((outRow - mOutputAddress.Row()) < aSampleSize)
+ if (i % aPeriod == aPeriod - 1 ) // Sample the last of period
{
- aRandomValue = rng();
-
- if ( (aPopulationSize - (inRow - aStart.Row())) * aRandomValue >= aSampleSize - (outRow - mOutputAddress.Row()) )
- {
- inRow++;
- }
- else
- {
- double aValue = mDocument->GetValue( ScAddress(inCol, inRow, inTab) );
- pDocShell->GetDocFunc().SetValueCell(ScAddress(outCol, outRow, outTab), aValue, true);
- inRow++;
- outRow++;
- }
+ double aValue = mDocument->GetValue(ScAddress(inCol, inRow, inTab));
+ pDocShell->GetDocFunc().SetValueCell(ScAddress(outCol, outRow, outTab), aValue, true);
+ outRow++;
}
- outCol++;
+ i++;
}
- outTab++;
+ outCol++;
}
+ outTab++;
}
- else if (mpPeriodicMethodRadio->IsChecked())
- {
- sal_Int64 aPeriod = mpPeriod->GetValue();
- for (SCROW inTab = aStart.Tab(); inTab <= aEnd.Tab(); inTab++)
+ return ScRange(mOutputAddress, ScAddress(outTab, outRow, outTab) );
+}
+
+ScRange ScSamplingDialog::PerformRandomSampling(ScDocShell* pDocShell)
+{
+ ScAddress aStart = mInputRange.aStart;
+ ScAddress aEnd = mInputRange.aEnd;
+
+ SCTAB outTab = mOutputAddress.Tab();
+ SCCOL outCol = mOutputAddress.Col();
+ SCROW outRow = mOutputAddress.Row();
+
+ TimeValue now;
+ osl_getSystemTime(&now);
+ boost::mt19937 seed(now.Nanosec);
+ boost::uniform_01<boost::mt19937> rng(seed);
+
+ SCROW inRow;
+
+ sal_Int64 aSampleSize = mpSampleSize->GetValue();
+
+ for (SCROW inTab = aStart.Tab(); inTab <= aEnd.Tab(); inTab++)
+ {
+ outCol = mOutputAddress.Col();
+ for (SCCOL inCol = aStart.Col(); inCol <= aEnd.Col(); inCol++)
{
- outCol = mOutputAddress.Col();
- for (SCCOL inCol = aStart.Col(); inCol <= aEnd.Col(); inCol++)
+ SCROW aPopulationSize = (aEnd.Row() - aStart.Row()) + 1;
+
+ outRow = mOutputAddress.Row();
+ inRow = aStart.Row();
+
+ double aRandomValue;
+
+ while ((outRow - mOutputAddress.Row()) < aSampleSize)
{
- sal_Int64 i = 0;
- outRow = mOutputAddress.Row();
- for (SCROW inRow = aStart.Row(); inRow <= aEnd.Row(); inRow++)
+ aRandomValue = rng();
+
+ if ( (aPopulationSize - (inRow - aStart.Row())) * aRandomValue >= aSampleSize - (outRow - mOutputAddress.Row()) )
+ {
+ inRow++;
+ }
+ else
{
- if (i % aPeriod == aPeriod - 1 ) // Sample the last of period
- {
- double aValue = mDocument->GetValue(ScAddress(inCol, inRow, inTab));
- pDocShell->GetDocFunc().SetValueCell(ScAddress(outCol, outRow, outTab), aValue, true);
- outRow++;
- }
- i++;
+ double aValue = mDocument->GetValue( ScAddress(inCol, inRow, inTab) );
+ pDocShell->GetDocFunc().SetValueCell(ScAddress(outCol, outRow, outTab), aValue, true);
+ inRow++;
+ outRow++;
}
- outCol++;
}
- outTab++;
+ outCol++;
}
+ outTab++;
+ }
+
+ return ScRange(mOutputAddress, ScAddress(outTab, outRow, outTab) );
+}
+
+void ScSamplingDialog::PerformSampling()
+{
+ OUString aUndo(ScResId(STR_SAMPLING_UNDO_NAME));
+ ScDocShell* pDocShell = mViewData->GetDocShell();
+ svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
+
+ ScRange aModifiedRange;
+
+ pUndoManager->EnterListAction( aUndo, aUndo );
+
+ if (mpRandomMethodRadio->IsChecked())
+ {
+ aModifiedRange = PerformRandomSampling(pDocShell);
+ }
+ else if (mpPeriodicMethodRadio->IsChecked())
+ {
+ aModifiedRange = PerformPeriodicSampling(pDocShell);
}
- ScRange aOutputRange(mOutputAddress, ScAddress(outTab, outRow, outTab) );
pUndoManager->LeaveListAction();
- pDocShell->PostPaint( aOutputRange, PAINT_GRID );
+ pDocShell->PostPaint(aModifiedRange, PAINT_GRID);
}
IMPL_LINK( ScSamplingDialog, OkClicked, PushButton*, /*pButton*/ )
{
- PerformSampling();
- Close();
+ ApplyClicked(NULL);
+ CloseClicked(NULL);
return 0;
}
@@ -275,7 +293,7 @@ IMPL_LINK( ScSamplingDialog, ApplyClicked, PushButton*, /*pButton*/ )
return 0;
}
-IMPL_LINK( ScSamplingDialog, CancelClicked, PushButton*, /*pButton*/ )
+IMPL_LINK( ScSamplingDialog, CloseClicked, PushButton*, /*pButton*/ )
{
Close();
return 0;
diff --git a/sc/source/ui/StatisticsDialogs/SamplingDialog.src b/sc/source/ui/StatisticsDialogs/SamplingDialog.src
index e7eef3ac9ccb..ddd007a2dfb4 100644
--- a/sc/source/ui/StatisticsDialogs/SamplingDialog.src
+++ b/sc/source/ui/StatisticsDialogs/SamplingDialog.src
@@ -6,15 +6,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "globstr.hrc"
diff --git a/sc/source/ui/inc/DescriptiveStatisticsDialog.hxx b/sc/source/ui/inc/DescriptiveStatisticsDialog.hxx
index edf08b6f8721..c375d27158ff 100644
--- a/sc/source/ui/inc/DescriptiveStatisticsDialog.hxx
+++ b/sc/source/ui/inc/DescriptiveStatisticsDialog.hxx
@@ -44,7 +44,7 @@ private:
PushButton* mpButtonApply;
OKButton* mpButtonOk;
- CancelButton* mpButtonCancel;
+ CloseButton* mpButtonClose;
//
formula::RefEdit* mpActiveEdit;
@@ -66,7 +66,7 @@ private:
void ApplyCalculationsFormulas();
DECL_LINK( OkClicked, PushButton* );
- DECL_LINK( CancelClicked, PushButton* );
+ DECL_LINK( CloseClicked, PushButton* );
DECL_LINK( ApplyClicked, PushButton* );
DECL_LINK( GetFocusHandler, Control* );
DECL_LINK( LoseFocusHandler, void* );
diff --git a/sc/source/ui/inc/RandomNumberGeneratorDialog.hxx b/sc/source/ui/inc/RandomNumberGeneratorDialog.hxx
index cb438c840803..377f8dc93e5a 100644
--- a/sc/source/ui/inc/RandomNumberGeneratorDialog.hxx
+++ b/sc/source/ui/inc/RandomNumberGeneratorDialog.hxx
@@ -47,7 +47,7 @@ private:
CheckBox* mpEnableSeed;
PushButton* mpButtonApply;
OKButton* mpButtonOk;
- CancelButton* mpButtonCancel;
+ CloseButton* mpButtonClose;
// Data
ScViewData* mViewData;
@@ -67,7 +67,7 @@ private:
void SelectGeneratorAndGenerateNumbers();
DECL_LINK( OkClicked, PushButton* );
- DECL_LINK( CancelClicked, PushButton* );
+ DECL_LINK( CloseClicked, PushButton* );
DECL_LINK( ApplyClicked, PushButton* );
DECL_LINK( GetFocusHandler, Control* );
DECL_LINK( LoseFocusHandler, void* );
diff --git a/sc/source/ui/inc/SamplingDialog.hxx b/sc/source/ui/inc/SamplingDialog.hxx
index c57390586013..02f07cd1ea51 100644
--- a/sc/source/ui/inc/SamplingDialog.hxx
+++ b/sc/source/ui/inc/SamplingDialog.hxx
@@ -50,7 +50,7 @@ private:
PushButton* mpButtonApply;
OKButton* mpButtonOk;
- CancelButton* mpButtonCancel;
+ CloseButton* mpButtonClose;
//
formula::RefEdit* mpActiveEdit;
@@ -71,8 +71,11 @@ private:
void GetRangeFromSelection();
void PerformSampling();
+ ScRange PerformRandomSampling(ScDocShell* pDocShell);
+ ScRange PerformPeriodicSampling(ScDocShell* pDocShell);
+
DECL_LINK( OkClicked, PushButton* );
- DECL_LINK( CancelClicked, PushButton* );
+ DECL_LINK( CloseClicked, PushButton* );
DECL_LINK( ApplyClicked, PushButton* );
DECL_LINK( GetFocusHandler, Control* );
DECL_LINK( LoseFocusHandler, void* );
diff --git a/sc/uiconfig/scalc/ui/descriptivestatisticsdialog.ui b/sc/uiconfig/scalc/ui/descriptivestatisticsdialog.ui
index b6040b42c2e6..2f7d1b8bfc6a 100644
--- a/sc/uiconfig/scalc/ui/descriptivestatisticsdialog.ui
+++ b/sc/uiconfig/scalc/ui/descriptivestatisticsdialog.ui
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <!-- interface-requires gtk+ 3.0 -->
<!-- interface-requires LibreOffice 1.0 -->
+ <!-- interface-requires gtk+ 3.0 -->
<object class="GtkDialog" id="DescriptiveStatisticsDialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
@@ -49,8 +49,8 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="cancel">
- <property name="label">gtk-cancel</property>
+ <object class="GtkButton" id="close">
+ <property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -164,15 +164,6 @@
<property name="height">1</property>
</packing>
</child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
</object>
<packing>
<property name="expand">False</property>
@@ -185,7 +176,7 @@
<action-widgets>
<action-widget response="0">apply</action-widget>
<action-widget response="0">ok</action-widget>
- <action-widget response="0">cancel</action-widget>
+ <action-widget response="0">close</action-widget>
</action-widgets>
</object>
</interface>
diff --git a/sc/uiconfig/scalc/ui/randomnumbergenerator.ui b/sc/uiconfig/scalc/ui/randomnumbergenerator.ui
index e4a14b305824..dcd54ce5eda1 100644
--- a/sc/uiconfig/scalc/ui/randomnumbergenerator.ui
+++ b/sc/uiconfig/scalc/ui/randomnumbergenerator.ui
@@ -49,8 +49,8 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="cancel">
- <property name="label">gtk-cancel</property>
+ <object class="GtkButton" id="close">
+ <property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -307,7 +307,7 @@
<action-widgets>
<action-widget response="0">apply</action-widget>
<action-widget response="0">ok</action-widget>
- <action-widget response="0">cancel</action-widget>
+ <action-widget response="0">close</action-widget>
</action-widgets>
</object>
<object class="GtkListStore" id="distribution-liststore">
diff --git a/sc/uiconfig/scalc/ui/samplingdialog.ui b/sc/uiconfig/scalc/ui/samplingdialog.ui
index cd6bd2155a25..3aa0f64518d1 100644
--- a/sc/uiconfig/scalc/ui/samplingdialog.ui
+++ b/sc/uiconfig/scalc/ui/samplingdialog.ui
@@ -9,6 +9,11 @@
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
+ <object class="GtkAdjustment" id="sample-size-adjustment">
+ <property name="upper">100</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
<object class="GtkDialog" id="SamplingDialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
@@ -56,8 +61,8 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="cancel">
- <property name="label">gtk-cancel</property>
+ <object class="GtkButton" id="close">
+ <property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -325,12 +330,7 @@
<action-widgets>
<action-widget response="0">apply</action-widget>
<action-widget response="0">ok</action-widget>
- <action-widget response="0">cancel</action-widget>
+ <action-widget response="0">close</action-widget>
</action-widgets>
</object>
- <object class="GtkAdjustment" id="sample-size-adjustment">
- <property name="upper">100</property>
- <property name="step_increment">1</property>
- <property name="page_increment">10</property>
- </object>
</interface>