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

Method addVariable

src/frontend/spreadsheet/FunctionValuesDialog.cpp:273–331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

271}
272
273void FunctionValuesDialog::addVariable() {
274 auto* layout{ui.gridLayoutVariables};
275 auto row{m_variableLineEdits.size()};
276 // text field for the variable name
277 auto* le{new QLineEdit};
278 le->setToolTip(i18n("Variable name can contain letters, digits and '_' only and should start with a letter"));
279 auto* validator = new QRegularExpressionValidator(QRegularExpression(QLatin1String("[a-zA-Z][a-zA-Z0-9_]*")), le);
280 le->setValidator(validator);
281 // hardcoding size is bad. 40 is enough for three letters
282 le->setMaximumWidth(40);
283 connect(le, &QLineEdit::textChanged, this, &FunctionValuesDialog::variableNameChanged);
284 layout->addWidget(le, row, 0, 1, 1);
285 m_variableLineEdits << le;
286 auto* l{new QLabel(QStringLiteral("="))};
287 layout->addWidget(l, row, 1, 1, 1);
288 m_variableLabels << l;
289
290 // combo box for the data column
291 auto* cb{new TreeViewComboBox()};
292 cb->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred));
293 connect(cb, &TreeViewComboBox::currentModelIndexChanged, this, &FunctionValuesDialog::variableColumnChanged);
294 layout->addWidget(cb, row, 2, 1, 1);
295 m_variableDataColumns << cb;
296
297 cb->setTopLevelClasses(TreeViewComboBox::plotColumnTopLevelClasses());
298 cb->setModel(m_aspectTreeModel.get());
299
300 // don't allow to select columns to be calculated as variable columns (avoid circular dependencies)
301 QList<const AbstractAspect*> aspects;
302 for (auto* col : m_columns)
303 aspects << col;
304 cb->setHiddenAspects(aspects);
305
306 // for the variable column select the first non-selected column in the spreadsheet
307 for (auto* col : m_spreadsheet->children<Column>()) {
308 if (m_columns.indexOf(col) == -1) {
309 cb->setCurrentModelIndex(m_aspectTreeModel->modelIndexOfAspect(col));
310 break;
311 }
312 }
313
314 // move the add-button to the next row
315 layout->removeWidget(ui.bAddVariable);
316 layout->addWidget(ui.bAddVariable, row + 1, 3, 1, 1);
317
318 // add delete-button for the just added variable
319 if (row != 0) {
320 auto* b{new QToolButton()};
321 b->setIcon(QIcon::fromTheme(QStringLiteral("list-remove")));
322 b->setToolTip(i18n("Delete variable"));
323 layout->addWidget(b, row, 3, 1, 1);
324 m_variableDeleteButtons << b;
325 connect(b, &QToolButton::pressed, this, &FunctionValuesDialog::deleteVariable);
326 }
327
328 ui.lVariable->setText(i18n("Variables:"));
329
330 // TODO: adjust the tab-ordering after new widgets were added

Callers

nothing calls this directly

Calls 11

setToolTipMethod · 0.80
setTopLevelClassesMethod · 0.80
setHiddenAspectsMethod · 0.80
setCurrentModelIndexMethod · 0.80
modelIndexOfAspectMethod · 0.80
removeWidgetMethod · 0.80
sizeMethod · 0.45
setModelMethod · 0.45
indexOfMethod · 0.45
setIconMethod · 0.45
setTextMethod · 0.45

Tested by

no test coverage detected