8 #include "ui_colormap_editor.h"
11 #include <QInputDialog>
12 #include <QMessageBox>
17 : QDialog(parent), ui(new
Ui::colormap_editor)
26 auto theme = settings.value(
"StyleSheet::theme",
"light").toString();
31 ui->listWidget->addItem(it.first);
43 ui->buttonDelete->setIcon(
LoadSvg(
":/resources/svg/trash.svg", theme));
51 auto colormap = std::make_shared<ColorMap>();
53 auto res = colormap->setScrip(
ui->functionText->toPlainText());
56 QMessageBox::warning(
this,
"Error in the Lua Script", colormap->getError(res),
62 auto selected =
ui->listWidget->selectedItems();
63 if (selected.size() == 1)
65 default_name = selected.front()->text();
69 QInputDialog::getText(
this, tr(
"ColorMap Name"), tr(
"Name of the function:"),
70 QLineEdit::Normal, default_name, &
ok);
71 if (!
ok || name.isEmpty())
75 bool overwrite =
false;
77 if (!
ui->listWidget->findItems(name, Qt::MatchExactly).empty())
79 auto reply = QMessageBox::question(
this,
"Confirm overwrite",
80 "A ColorMap with the same name exist already. "
81 "Do you want to overwrite it?",
82 QMessageBox::Yes | QMessageBox::No);
83 if (reply == QMessageBox::No)
94 ui->listWidget->addItem(name);
101 for (
auto item :
ui->listWidget->selectedItems())
106 if (!it->second->script().isEmpty())
108 auto reply = QMessageBox::question(
this,
"Delete ColorMap",
"Are you sure?",
109 QMessageBox::Yes | QMessageBox::No);
110 if (reply == QMessageBox::No)
117 delete ui->listWidget->takeItem(
ui->listWidget->row(item));
123 ui->listWidget->clearSelection();
124 ui->listWidget->selectionModel()->setCurrentIndex(
125 ui->listWidget->model()->index(row, 0), QItemSelectionModel::SelectionFlag::Select);
133 auto colormap = it->second;
134 ui->functionText->setText(colormap->script());