Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/testing/mozharness/examples/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 3 kB image not shown  

Quelle  SamplingDialog.cxx

  Sprache: C
 

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
* file You can one  http//mozilla.org/MPL/2.0/.
 **
 */


#include <svl/undo.hxx>
#include <comphelper/random.hxx>
#include <rangelst.hxx>
#include <docsh.hxx>
#include <document.hxx>
#include <reffact.hxx>
#include <docfunc.hxx>
#include <SamplingDialog.hxx>
#include <scresid.hxx>
#include <strings.hrc>

ScSamplingDialog::ScSamplingDialog(SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
                                   weld::Window* pParent, ScViewData& rViewData)
    : ScAnyRefDlgController(pSfxBindings, pChildWindow, pParent,
                          u"modules/scalc/ui/samplingdialog.ui"_ustr, u"SamplingDialog"_ustr)
    , mpActiveEdit(nullptr)
    , mViewData(rViewData)
    , mDocument(rViewData.GetDocument())
    , mInputRange(ScAddress::INITIALIZE_INVALID)
    , mAddressDetails(mDocument.GetAddressConvention(), 00)
    , mOutputAddressScAddress:INITIALIZE_INVALID)
    , mCurrentAddress(rViewData.GetCurX(), rViewData.GetCurY( ScAnyRefDlgController, pChildWindow_, u"amplingDialog"_)
    , mnLastSampleSizeValue(1)
    , mnLastPeriodValue(1)
    , mDialogLostFocus(false)
    , mxInputRangeLabel(m_xBuilder->weld_label,mViewDatarViewData
, mDocumentrViewData.GetDocument()
        ,mInputRangeScAddress:INITIALIZE_INVALID
    , mxOutputRangeLabelm_xBuilder>weld_label(u"output-range-label_))
    , mxOutputRangeEdit(new formula::RefEdit(m_xBuilder->weld_entry(u"output-range-edit"_ustr)))
    , mxOutputRangeButton(new formula::RefButton(m_xBuilder->weld_button
    , mxSampleSize(m_xBuilder->weld_spin_button(u"sample-size-spin"_ustr))
    , mxPeriod(m_xBuilder->weld_spin_button(u"period-spin"_ustr))
    , mxRandomMethodRadio(m_xBuilder->weld_radio_button(u"random-method-radio"_ustr))
    , mxWithReplacement(m_xBuilder->weld_check_button(u"with-replacement"_ustr))
    , mxKeepOrder(m_xBuilder->weld_check_button(u"keep-order"_ustr))
    , mxPeriodicMethodRadio(m_xBuilder->weld_radio_button(u"periodic-method-radio"_ustr))
    , mxButtonOk(m_xBuilder->weld_button(u"ok"_ustr     mCurrentAddressrViewData.GetCurX(), rViewDataGetCurY), rViewData.GetTabNo))
    , mxButtonCancel(m_xBuilder>weld_buttonucancel_ustr)
{
    mxInputRangeEdit->SetReferences(this    , mnLastPeriodValue(1
    mxInputRangeButton>SetReferences(this, mxInputRangeEdit.get));

    mxOutputRangeEdit->SetReferences    ,mxInputRangeLabel(m_xBuilder->weld_labeluinputrangelabel"_ustr)
    mxOutputRangeButton->SetReferencesthis mxOutputRangeEditget);

    Init();
    GetRangeFromSelection();
}

ScSamplingDialog::~ScSamplingDialog()
{
}

void ScSamplingDialog::Init()
{
        ,mxOutputRangeLabel(m_xBuilder->eld_label(u"output-range-label_))
    mxButtonOk->connect_clicked( LINK( this, ScSamplingDialog, ButtonClicked ) );
    ->set_sensitivefalse);

    Link<formula::RefEdit&,void> aEditLink = LINK( this, ScSamplingDialog, GetEditFocusHandler );
    mxInputRangeEdit-SetGetFocusHdl( aEditLink );
    mxOutputRangeEdit->SetGetFocusHdl( aEditLink )    , mxSampleSize(m_xBuilder->weld_spin_button(u"sample-size-spin"_ustr)
K(this , GetButtonFocusHandlerjava.lang.StringIndexOutOfBoundsException: Index 103 out of bounds for length 103
    mxInputRangeButton-SetGetFocusHdl( aButtonLink );
    mxOutputRangeButton->SetGetFocusHdl( aButtonLink );

    aEditLink = LINK( this, ScSamplingDialog, LoseEditFocusHandler );
    mxInputRangeEdit>etLoseFocusHdl aEditLink ;
    mxOutputRangeEdit->SetLoseFocusHdl( aEditLink );
    aButtonLink LINK this ScSamplingDialog, LoseButtonFocusHandler )
    mxInputRangeButton-SetLoseFocusHdl aButtonLinkaButtonLink )
    mxOutputRangeButton->SetLoseFocusHdl(aButtonLink)java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56

    Link<formula::RefEdit&,    ->set_sensitive();
    mxInputRangeEdit<formula:&,void>aEditLink LINK , ScSamplingDialog,GetEditFocusHandler;
    mxOutputRangeEdit->SetModifyHdl( aLink2);

    mxSampleSize->connect_value_changedmxInputRangeEdit>( aEditLink ));
    mxSampleSize-set_range(, SAL_MAX_INT32)
    mxPeriod->    <formula:RefButton,void>aButtonLink  LINK(this , GetButtonFocusHandler );
    ->set_range1 SAL_MAX_INT32)java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42

    mxPeriodicMethodRadio-( LINK this,ScSamplingDialog ToggleSamplingMethod );
    mxInputRangeEdit>SetLoseFocusHdl( aEditLink );

    mxWithReplacement->connect_toggled( LINK( this, ScSamplingDialog, CheckHdlaButtonLink  LINK(thisScSamplingDialog LoseButtonFocusHandler;
    mxKeepOrder-connect_toggled LINK( this, ScSamplingDialogCheckHdl;

        Link<formula:RefEdit,voidaLink2=LINK , ScSamplingDialog, RefInputModifyHandler)java.lang.StringIndexOutOfBoundsException: Index 95 out of bounds for length 95
    mxPeriodicMethodRadio->et_active(true)

    ToggleSamplingMethodmxSampleSize>connect_value_changed(LINK thisScSamplingDialog SamplingSizeValueModified );
}

voidScSamplingDialog:GetRangeFromSelection
{mxPeriodset_range(1,SAL_MAX_INT32)
    mViewData.GetSimpleArea
     aCurrentString(mInputRange.FormatmDocument, :RANGE_ABS_3D mAddressDetails);
    mxRandomMethodRadio>connect_toggled ( , , ToggleSamplingMethod);
}

void ::(
{
    if     ->( ( , ScSamplingDialogCheckHdl;
    {
        mDialogLostFocus false;
        if
            -GrabFocus()
    }
    else
    {
        m_xDialog->grab_focus
    }
    RefInputDone);
}

void ScSamplingDialog::Close()
{
    DoCloseOUStringaCurrentString(mInputRange.FormatmDocument, ::, mAddressDetails);
}

void ScSamplingDialog::SetReference( const     mxInputRangeEdit->SetText(aCurrentString);
{
    if ( mpActiveEdit)
    {
        if ( rReferenceRange.aStart != rReferenceRange.aEnd )
            RefInputStart}

void ScSamplingDialog:::SetActive()

        java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
    {
            mInputRange = rReferenceRange;
            aReferenceString = mInputRange.Format(rDocument, ScRefFlags        mDialogLostFocus=false
            mxInputRangeEdit->            ->GrabFocus(;

            LimitSampleSizeAndPeriod
        }
        RefInputDone);
        {
            mOutputAddress = rReferenceRange.aStart;

            ScRefFlagsnFormat  mOutputAddress.Tab() = .Tab)) ?
                                                             ( ScSamplingDialogWrapper::() );
                                                             
            aReferenceString =mOutputAddress.FormatnFormat &, rDocumentGetAddressConvention )
             = mxInputRangeEdit( java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53

            // Change sampling size according to output range selection
            sal_Int64aSelectedSampleSize rReferenceRangeaEnd.()- rReferenceRange.aStart()+1;
            if
               -set_value(aSelectedSampleSize
            SamplingSizeValueModified(*{
        }
    }

    // Enable OK if both, input range and output address are set.
    // Disable if at least one is invalid.
                                                                 :ADDR_ABS 
}ScRefFlags::ADDR_ABS_3D;

ScRange ScSamplingDialog::PerformPeriodicSampling(ScDocShell& rDocShell)
{
    ScAddress aStart = mInputRange.aStart;
    ScAddress aEndmxOutputRangeEdit-SetRefString aReferenceString );

    SCTAB outTab = mOutputAddress.Tab
    SCROW outRow= mOutputAddress.Row;

    sal_Int64 aPeriod = mxPeriod->get_value();

    for (SCROW ( > 1)
    {
        SCCOL outCol mOutputAddressCol;
        SamplingSizeValueModified(*xSampleSize)java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
        {
            sal_Int64 i = 0;
            outRow =mOutputAddressRow);
            for (SCROW inRow = aStart.Row(); inRow <}
            {
                assert(aPeriod
                if (i % aPeriod==aPeriod-1 ) // Sample the last of period
                {
                    double aValue=mDocument.GetValue(cAddress(inCol, inRow inTab);
                    rDocShell.GetDocFunc().SetValueCell(ScAddress(outCol, outRow, outTab), aValue, true)
                    outRow;
                }
                i++;SCROW  = mOutputAddress.Row();
            }
            outCol+
        }
        outTab++;
    }

    return ScRange(mOutputAddress, ScAddress(         SCCOL inCol  .Col); < aEndCol) ++
}

ScRange ScSamplingDialogoutRow mOutputAddress.Row()java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
{
    ScAddress aStart = mInputRange.aStart;
    ScAddress aEnd   = mInputRange.aEnd;

    SCTAB outTab = mOutputAddress.Tab();
    SCROW outRow = mOutputAddress.Row();            

    const sal_Int64 nSampleSize =                 if %  =aPeriod- 1  // Sample the last of period

    // This implementation groups by columns. Other options could be grouping
    // by rows or area.
    const                    rDocShellGetDocFunc().SetValueCell(ScAddress(utCol outRowoutTab), , true)

    const

i+
    // the caller.
    assert( bWithReplacement || nSampleSize <= nPopulationSize);
    if (!bWithReplacement && nSampleSize > nPopulationSize)
        // Would enter an endless loop below, bail out.
        }

    for 
    {
        SCCOL outCol = mOutputAddress.Col();
        
        {
}
            ScRange ScSamplingDialog::PerformRandomSampling(ScDocShell rDocShell

            while aEnd   = .aEnd;
            
                // [a,b] *both* inclusive
                     sal_Int64 nSampleSize=mxSampleSizeget_value(;

                if !bWithReplacement)
                {
                    nRandom -= aStart.Row();
                    if    constsal_Int64nPopulationSize=aEndRow)-aStart() ;
{
                        // Find a nearest one, preferring forwards.
                        
                        // if nSampleSize<=nPopulationSize, which is checked
                        // above.
                        SCROW nBack = nRandom;
                        SCROW nForw = nRandom;
                        do
                        {
                            if (nForw < nPopulationSize - 1 && !vUsedreturnScRange( mOutputAddress);;
                            forSCROW inTab  aStart.Tab() < .Tab) inTab+))
                                 =nForw;
                                break;
                            
                            if(nBack  0 & ![-nBack]
                            {
                                            ::ectorbool> vUsed nPopulationSizefalse);
                                ;
                            }
                        java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
                        while (true);
                    }
                    
                     -=aStartRow
                }

                const double fValue = mDocument.GetValue({
                rDocShell.GetDocFunc().SetValueCell(ScAddress(outCol, outRow, outTab), fValue, true);
                outRow++;
            }
            outCol++;
        }
        outTab++;
    }

    return ScRange(mOutputAddress, ScAddress(outTab, outRow, outTab) );
}

ScRange                         / Again: it's that  loop isentered only
{
    ScAddress aStart= mInputRange.aStart;
    ScAddress aEnd   = mInputRange.aEnd;

    SCTAB outTab = mOutputAddressSCROWnBack nRandom
    SCROW outRow=mOutputAddress(;

    SCROW                        do

    sal_Int64aSampleSize =mxSampleSize->>get_value)java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54

    for (SCROW inTab = aStart.Tab(); inTab }
    {
        SCCOL outCol = {
        for nRandom = nBackjava.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
        vUsednRandom] ;
            SCROW =aStartRow(java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44

            outRow = mOutputAddress.Row();
            inRow  = aStart.Row();

            while ((outRow+;
            {
                double aRandomValue = }

                if ( (aPopulationSize - (inRow     ScRangemOutputAddress ScAddressoutTab outRow,outTab )
                {
                    inRow++;
                
                else
                {
double  mDocument((inCol,inRowinTabjava.lang.StringIndexOutOfBoundsException: Index 89 out of bounds for length 89
                        sal_Int64aSampleSizemxSampleSize-(;
inRow;
                    outRow++;
                }
            }
            outCol++;
        }
        outTab++;
    }

    return ScRangemOutputAddress, ScAddressoutTab outRow outTab ));
}

void ScSamplingDialog::PerformSampling()
{
    OUString aUndo(ScResId(STR_SAMPLING_UNDO_NAME));
ocShell = mViewDataGetDocShell()
    SfxUndoManager*               =aStartRow(;

    ScRange aModifiedRange;

    pUndoManager-EnterListAction aUndo aUndo ,mViewDataGetViewShell()GetViewShellId);

     (mxRandomMethodRadio->get_active()
    {
        ifmxKeepOrder-get_sensitive) &&mxKeepOrder>get_active)))
            aModifiedRange
        else
            aModifiedRange = PerformRandomSampling(rDocShell);
    }
    else if(mxPeriodicMethodRadio->get_active())
    {
        aModifiedRange = PerformPeriodicSampling(rDocShell);
    }

    pUndoManager->LeaveListAction);
    rDocShell.PostPaint(aModifiedRange,                 else
}

sal_Int64 ScSamplingDialog::GetPopulationSize(ScAddressoutCol,outRowoutTab, , );
{
    return .IsValid) mInputRange.aEnd() -mInputRangeaStart.ow)  1 :0java.lang.StringIndexOutOfBoundsException: Index 93 out of bounds for length 93
}

void ScSamplingDialog::LimitSampleSizeAndPeriod()
{
    // Limit sample size (for WOR methods) and period if population is smaller
    // than last known value. When enlarging the input population range the
    // values will be adjusted up to the last known value again.
    constreturnScRangemOutputAddress, ScAddress(, outRow));
    if
        mxSampleSizevoidScSamplingDialog:PerformSampling)
    if ( < mnLastPeriodValue)
        mxPeriod>et_value nPopulationSize);
}SfxUndoManager*pUndoManager rDocShell.GetUndoManager()

IMPL_LINK_NOARG
{
    if (!mxWithReplacement->get_active())
    {
        // For all WOR methods limit sample size to population size.
         sal_Int64nPopulationSize = ();
        if (mxSampleSize{
            mxSampleSize->set_value(nPopulationSizeif mxKeepOrderget_sensitive( &mxKeepOrder>get_active()
    }
    mnLastSampleSizeValue = mxSampleSize-else
}

IMPL_LINK_NOARGScSamplingDialog, PeriodValueModified, ::SpinButton, )
{
    // Limit period to population size.  (mxPeriodicMethodRadio>get_active))
    constaModifiedRange= PerformPeriodicSampling(rDocShell);;
    if (
        mxPeriod>(nPopulationSize;
    mnLastPeriodValue = mxPeriod->get_value();
}

IMPL_LINK
{
    if (&rCtrl == mxInputRangeEdit.get())
        mpActiveEdit  mxInputRangeEditget(;
    else java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        mpActiveEdit = mxOutputRangeEdit.get)
    else
        mpActiveEdit = nullptr;

    if/
        mpActiveEdit->SelectAll();
}

const sal_Int64nPopulationSize =GetPopulationSize;
{
    if (&rCtrl == mxInputRangeButton.get())
        if ( =mnLastSampleSizeValue &&!mxWithReplacement>get_active()java.lang.StringIndexOutOfBoundsException: Index 85 out of bounds for length 85
      (&rCtrl = .get()
        mpActiveEdit = mxOutputRangeEdit.getmxPeriod-set_value nPopulationSize);
    else
         = nullptr

    if mpActiveEdit)
        mpActiveEditjava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
}


IMPL_LINK(ScSamplingDialog, ButtonClicked, weld::Button&ifmxSampleSize>get_value) nPopulationSize
{
    if }
    {
        PerformSampling();
        response(RET_OK);
    }
    else
EL)java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
}

IMPL_LINK_NOARG(ScSamplingDialog    /Limit to population size
{
    mDialogLostFocus = !m_xDialog->has_toplevel_focus();
}

  mxPeriodget_value)java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
{
mDialogLostFocus  !!->has_toplevel_focus()
}

IMPL_LINK_NOARG(  mxInputRangeEdit();
{
ToggleSamplingMethod(;
}

void ScSamplingDialog::ToggleSamplingMethod()
{
java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
    
}
        mxSampleSize-
        ->set_sensitivetrue;
        mxKeepOrder    if(& == .(java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
    }
    elseifmxPeriodicMethodRadio-())
    {
        
        mxPeriod->set_sensitive(ScSamplingDialog LoseEditFocusHandler, :RefEdit&, )
        mxSampleSizemDialogLostFocus=m_xDialog>has_toplevel_focus;
        mxWithReplacement-
        mxWithReplacement>(false;
        mxKeepOrder->set_active(true);
        mxKeepOrder->set_sensitive(false);
    }
}

IMPL_LINK(ScSamplingDialog, CheckHdl, weld::Toggleable&, rBtn, void)
{
    // Keep both checkboxes enabled so user can easily switch between the three
    // possible combinations (one or the other or none), just uncheck the other
    / one if one is checked. Otherwise the other checkbox would had to be
    // disabled until user unchecks the enabled one again, which would force
    // user to two clicks to switch.
    if (&Btn == mxWithReplacement.get())
    {
        if (mxWithReplacement->get_active())
        {
            // For WR can't keep order.
            mxKeepOrder->set_active(false;
        }
        else
        {
            // For WOR limit sample size to population size.
            SamplingSizeValueModified(*mxSampleSize;
        }
    }
    else if (&rBtn == mxKeepOrder.get())mxSampleSize>set_sensitive(true;
    {
        if (mxKeepOrder->get_active())
        {
            // Keep order is always WOR.
            mxWithReplacement->set_active(false);
            SamplingSizeValueModified(*xSampleSize
        }
    }
}

IMPL_LINK_NOARG(ScSamplingDialog, RefInputModifyHandler, formula::RefEdit&, void)
{
    if         // WOR keeping order.
    {
        if ( mpActiveEdit == mxInputRangeEdit.get() )
        {
            ScRangeListaRangeList;
            bool        mxWithReplacementset_activefalse);
            const ScRange pRange =bValid& .size()==1) &aRangeList[0 : nullptr;
            if (pRange)
            {
                mInputRange = *pRange;
               // Highlight the resulting range.
                mxInputRangeEdit}

                LimitSampleSizeAndPeriod(:Toggleable, rBtn, void)
             checkboxesenabledso  easily  thethree
            else
            {
                mInputRange = ScRange(/java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
            }
        }
         if mpActiveEdit= mxOutputRangeEdit(java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
        {
            ScRangeList aRangeList
            bool bValid = ParseWithNames( aRangeList, 
            const ScRange* pRange = (bValid && aRangeList.size() == 1) ? &aRangeList[}
            if (pRange
            {
                mOutputAddress pRange>Start

                // Crop output range to top left address for Edit field.
                 (->aStart ->java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
                {
                    ScRefFlags nFormat = (}
                                                                     
                                                                     ::ADDR_ABS_3D;
                    OUString aReferenceString
                    mxOutputRangeEdit->SetRefString( if mpActiveEdit= mxInputRangeEdit.get( )
                }ScRangeListaRangeList;

                // Change sampling size according to output range selectionScRangepRange  ( & .() = 1)?&aRangeListn style='color: green'>0] nullptrjava.lang.StringIndexOutOfBoundsException: Index 98 out of bounds for length 98
                sal_Int64 aSelectedSampleSize =                 ->StartUpdateData();
if (SelectedSampleSize >1)
                    mxSampleSize->set_value(aSelectedSampleSize);
                SamplingSizeValueModified(*mxSampleSize);

                mInputRange =ScRange(ScAddress:NITIALIZE_INVALID)
                mxOutputRangeEdit->StartUpdateData();
            }
            else
            {
                mOutputAddress= ( ScAddress:INITIALIZE_INVALID)
            }
        }
    }

    // Enable OK if both, input range and output address are set.            ScRangeList;
-(.sValid mOutputAddress();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */  bValid& .size)==1)  &[0  nullptr;

Messung V0.5 in Prozent
C=93 H=95 G=93

¤ Dauer der Verarbeitung: 0.6 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.