! \class FunctionValuesDialog \brief Dialog for generating values from a mathematical function. \ingroup frontend */
| 37 | \ingroup frontend |
| 38 | */ |
| 39 | FunctionValuesDialog::FunctionValuesDialog(Spreadsheet* s, QWidget* parent) |
| 40 | : QDialog(parent) |
| 41 | , m_spreadsheet(s) { |
| 42 | Q_ASSERT(s); |
| 43 | setWindowTitle(i18nc("@title:window", "Function Values")); |
| 44 | |
| 45 | ui.setupUi(this); |
| 46 | setAttribute(Qt::WA_DeleteOnClose); |
| 47 | ui.tbConstants->setIcon(QIcon::fromTheme(QStringLiteral("format-text-symbol"))); |
| 48 | ui.tbFunctions->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-font"))); |
| 49 | |
| 50 | ui.teEquation->setMaximumHeight(QLineEdit().sizeHint().height() * 2); |
| 51 | ui.teEquation->setFocus(); |
| 52 | |
| 53 | // needed for buggy compiler |
| 54 | #if __cplusplus < 201103L |
| 55 | m_aspectTreeModel = std::auto_ptr<AspectTreeModel>(new AspectTreeModel(m_spreadsheet->project())); |
| 56 | #else |
| 57 | m_aspectTreeModel = std::unique_ptr<AspectTreeModel>(new AspectTreeModel(m_spreadsheet->project())); |
| 58 | #endif |
| 59 | m_aspectTreeModel->setSelectableAspects({AspectType::Column}); |
| 60 | m_aspectTreeModel->enableNumericColumnsOnly(true); |
| 61 | |
| 62 | ui.bAddVariable->setIcon(QIcon::fromTheme(QStringLiteral("list-add"))); |
| 63 | ui.bAddVariable->setToolTip(i18n("Add new variable")); |
| 64 | |
| 65 | ui.chkAutoUpdate->setToolTip(i18n("Automatically update the calculated values in the target column on changes in the variable columns")); |
| 66 | ui.chkAutoResize->setToolTip(i18n("Automatically resize the target column to fit the size of the variable columns")); |
| 67 | |
| 68 | auto* btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); |
| 69 | ui.verticalLayout->addWidget(btnBox); |
| 70 | m_okButton = btnBox->button(QDialogButtonBox::Ok); |
| 71 | |
| 72 | connect(btnBox, &QDialogButtonBox::accepted, this, &FunctionValuesDialog::accept); |
| 73 | connect(btnBox, &QDialogButtonBox::rejected, this, &FunctionValuesDialog::reject); |
| 74 | m_okButton->setText(i18n("&Generate")); |
| 75 | |
| 76 | connect(ui.bAddVariable, &QPushButton::pressed, this, &FunctionValuesDialog::addVariable); |
| 77 | connect(ui.teEquation, &ExpressionTextEdit::expressionChanged, this, &FunctionValuesDialog::checkValues); |
| 78 | connect(ui.tbConstants, &QToolButton::clicked, this, &FunctionValuesDialog::showConstants); |
| 79 | connect(ui.tbFunctions, &QToolButton::clicked, this, &FunctionValuesDialog::showFunctions); |
| 80 | connect(m_okButton, &QPushButton::clicked, this, &FunctionValuesDialog::generate); |
| 81 | |
| 82 | // restore saved settings if available |
| 83 | create(); // ensure there's a window created |
| 84 | KConfigGroup conf = Settings::group(QStringLiteral("FunctionValuesDialog")); |
| 85 | if (conf.exists()) { |
| 86 | KWindowConfig::restoreWindowSize(windowHandle(), conf); |
| 87 | resize(windowHandle()->size()); // workaround for QTBUG-40584 |
| 88 | } else |
| 89 | resize(QSize(300, 0).expandedTo(minimumSize())); |
| 90 | } |
| 91 | |
| 92 | FunctionValuesDialog::~FunctionValuesDialog() { |
| 93 | KConfigGroup conf = Settings::group(QStringLiteral("FunctionValuesDialog")); |
nothing calls this directly
no test coverage detected