MCPcopy Create free account
hub / github.com/KDE/labplot / RandomValuesDialog

Method RandomValuesDialog

src/frontend/spreadsheet/RandomValuesDialog.cpp:41–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39 */
40
41RandomValuesDialog::RandomValuesDialog(Spreadsheet* s, QWidget* parent)
42 : QDialog(parent)
43 , m_spreadsheet(s) {
44 setWindowTitle(i18nc("@title:window", "Random Values"));
45
46 auto* mainWidget = new QWidget(this);
47 ui.setupUi(mainWidget);
48 auto* layout = new QVBoxLayout(this);
49
50 auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
51 m_okButton = buttonBox->button(QDialogButtonBox::Ok);
52 m_okButton->setDefault(true);
53 m_okButton->setToolTip(i18n("Generate random values according to the selected distribution"));
54 m_okButton->setText(i18n("&Generate"));
55
56 connect(buttonBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked, this, &RandomValuesDialog::close);
57 connect(buttonBox, &QDialogButtonBox::accepted, this, &RandomValuesDialog::accept);
58 connect(buttonBox, &QDialogButtonBox::rejected, this, &RandomValuesDialog::reject);
59
60 layout->addWidget(mainWidget);
61 layout->addWidget(buttonBox);
62 setLayout(layout);
63 setAttribute(Qt::WA_DeleteOnClose);
64
65 QVector<QPair<QString, int>> distros;
66 for (int i = 0; i < NSL_SF_STATS_DISTRIBUTION_COUNT; i++)
67 if (nsl_sf_stats_distribution_supports_RNG(nsl_sf_stats_distribution(i)))
68 distros << QPair<QString, int>(i18n(nsl_sf_stats_distribution_name[i]), i);
69 std::sort(std::begin(distros), std::end(distros));
70 for (const auto& d : distros)
71 ui.cbDistribution->addItem(d.first, d.second);
72 const int defaultDist = (int)nsl_sf_stats_gaussian; // default dist
73
74 ui.leParameter1->setClearButtonEnabled(true);
75 ui.leParameter2->setClearButtonEnabled(true);
76 ui.leParameter3->setClearButtonEnabled(true);
77 ui.leSeed->setClearButtonEnabled(true);
78
79 ui.leParameter1->setValidator(new QDoubleValidator(ui.leParameter1));
80 ui.leParameter2->setValidator(new QDoubleValidator(ui.leParameter2));
81 ui.leParameter3->setValidator(new QDoubleValidator(ui.leParameter3));
82 ui.leSeed->setValidator(new QIntValidator(ui.leSeed));
83
84 QString info = i18n(
85 "Seed number to initialize the random number generator.\n"
86 "If the generator is seeded with the same value, the same stream of random numbers will be generated by successive calls.\n"
87 "If no value is specified, the current timestamp will be used to seed the generator.");
88 ui.lSeed->setToolTip(info);
89 ui.leSeed->setToolTip(info);
90
91 info = i18n("Random number distributions as defined in <a href=\"https://www.gnu.org/software/gsl/doc/html/randist.html\">GSL documentation</a>");
92 ui.cbDistribution->setWhatsThis(info);
93
94 connect(ui.cbDistribution, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &RandomValuesDialog::distributionChanged);
95 connect(ui.leParameter1, &QLineEdit::textChanged, this, &RandomValuesDialog::checkValues);
96 connect(ui.leParameter2, &QLineEdit::textChanged, this, &RandomValuesDialog::checkValues);
97 connect(ui.leParameter3, &QLineEdit::textChanged, this, &RandomValuesDialog::checkValues);
98 connect(buttonBox, &QDialogButtonBox::accepted, this, &RandomValuesDialog::generate);

Callers

nothing calls this directly

Calls 14

distributionChangedMethod · 0.95
groupFunction · 0.85
buttonMethod · 0.80
setDefaultMethod · 0.80
setToolTipMethod · 0.80
setClearButtonEnabledMethod · 0.80
existsMethod · 0.80
QStringClass · 0.50
setTextMethod · 0.45
setCurrentIndexMethod · 0.45
currentIndexMethod · 0.45

Tested by

no test coverage detected