| 1905 | } |
| 1906 | |
| 1907 | void CartesianPlot::addHistogramFit(Histogram* hist, nsl_sf_stats_distribution type) { |
| 1908 | if (!hist) |
| 1909 | return; |
| 1910 | |
| 1911 | beginMacro(i18n("%1: distribution fit to '%2'", name(), hist->name())); |
| 1912 | auto* curve = new XYFitCurve(i18n("Distribution Fit to '%1'", hist->name())); |
| 1913 | // curve->setCoordinateSystemIndex(defaultCoordinateSystemIndex()); |
| 1914 | curve->setDataSourceType(XYAnalysisCurve::DataSourceType::Histogram); |
| 1915 | curve->setDataSourceHistogram(hist); |
| 1916 | |
| 1917 | // set fit model category and type and initialize fit |
| 1918 | XYFitCurve::FitData fitData = curve->fitData(); |
| 1919 | fitData.modelCategory = nsl_fit_model_distribution; |
| 1920 | fitData.modelType = (int)type; |
| 1921 | DEBUG("TYPE = " << type) |
| 1922 | fitData.algorithm = nsl_fit_algorithm_ml; // ML distribution fit |
| 1923 | DEBUG("INITFITDATA:") |
| 1924 | XYFitCurve::initFitData(fitData); |
| 1925 | DEBUG("SETFITDATA:") |
| 1926 | curve->setFitData(fitData); |
| 1927 | |
| 1928 | DEBUG("RECALCULATE:") |
| 1929 | curve->recalculate(); |
| 1930 | |
| 1931 | // add the child after the fit was calculated so the dock widgets gets the fit results |
| 1932 | // and call retransform() after this to calculate and to paint the data points of the fit-curve |
| 1933 | DEBUG("ADDCHILD:") |
| 1934 | this->addChild(curve); |
| 1935 | DEBUG("RETRANSFORM:") |
| 1936 | curve->retransform(); |
| 1937 | DEBUG("DONE:") |
| 1938 | |
| 1939 | endMacro(); |
| 1940 | } |
| 1941 | |
| 1942 | /*! |
| 1943 | * returns the first selected XYCurve in the plot |