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

Method addKeyword

src/frontend/widgets/FITSHeaderEditWidget.cpp:313–367  ·  view source on GitHub ↗

! * \brief Shows a FITSHeaderEditNewKeywordDialog and decides whether the new keyword provided in the dialog * can be added to the new keywords or not. Updates the tablewidget if it's needed. */

Source from the content-addressed store, hash-verified

311 * can be added to the new keywords or not. Updates the tablewidget if it's needed.
312 */
313void FITSHeaderEditWidget::addKeyword() {
314 auto* newKeywordDialog = new FITSHeaderEditNewKeywordDialog;
315 m_initializingTable = true;
316 if (newKeywordDialog->exec() == QDialog::Accepted) {
317 FITSFilter::Keyword newKeyWord = newKeywordDialog->newKeyword();
318 QList<FITSFilter::Keyword> currentKeywords = m_extensionData[m_seletedExtension].keywords;
319
320 for (const FITSFilter::Keyword& keyword : currentKeywords) {
321 if (keyword.operator==(newKeyWord)) {
322 KMessageBox::information(this, i18n("Cannot add keyword, keyword already added"), i18n("Cannot Add Keyword"));
323 return;
324 }
325 }
326
327 for (const FITSFilter::Keyword& keyword : m_extensionData[m_seletedExtension].updates.newKeywords) {
328 if (keyword.operator==(newKeyWord)) {
329 KMessageBox::information(this, i18n("Cannot add keyword, keyword already added"), i18n("Cannot Add Keyword"));
330 return;
331 }
332 }
333
334 for (const QString& keyword : mandatoryKeywords()) {
335 if (!keyword.compare(newKeyWord.key)) {
336 KMessageBox::information(this, i18n("Cannot add mandatory keyword, they are already present"), i18n("Cannot Add Keyword"));
337 return;
338 }
339 }
340
341 /*
342 - Column related keyword (TFIELDS, TTYPEn,TFORMn, etc.) in an image
343 - SIMPLE, EXTEND, or BLOCKED keyword in any extension
344 - BSCALE, BZERO, BUNIT, BLANK, DATAMAX, DATAMIN keywords in a table
345 - Keyword name contains illegal character
346 */
347
348 m_extensionData[m_seletedExtension].updates.newKeywords.append(newKeyWord);
349
350 const int lastRow = ui->twKeywordsTable->rowCount();
351 ui->twKeywordsTable->setRowCount(lastRow + 1);
352 auto* newKeyWordItem = new QTableWidgetItem(newKeyWord.key);
353 newKeyWordItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
354 ui->twKeywordsTable->setItem(lastRow, 0, newKeyWordItem);
355
356 newKeyWordItem = new QTableWidgetItem(newKeyWord.value);
357 newKeyWordItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
358 ui->twKeywordsTable->setItem(lastRow, 1, newKeyWordItem);
359
360 newKeyWordItem = new QTableWidgetItem(newKeyWord.comment);
361 newKeyWordItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
362 ui->twKeywordsTable->setItem(lastRow, 2, newKeyWordItem);
363 Q_EMIT changed(true);
364 }
365 m_initializingTable = false;
366 delete newKeywordDialog;
367}
368
369/*!
370 * \brief Shows a messagebox whether we want to remove the keyword or not.

Callers

nothing calls this directly

Calls 6

execMethod · 0.80
newKeywordMethod · 0.80
appendMethod · 0.80
operator==Method · 0.45
rowCountMethod · 0.45
setRowCountMethod · 0.45

Tested by

no test coverage detected