8 #include "ui_plotwidget_editor.h"
10 #include <QVBoxLayout>
12 #include <QListWidgetItem>
14 #include <QMouseEvent>
15 #include <QPushButton>
16 #include <QDialogButtonBox>
20 const double MAX_DOUBLE = std::numeric_limits<double>::max() / 2;
23 : QDialog(parent), ui(new
Ui::PlotWidgetEditor), _plotwidget_origin(plotwidget)
27 installEventFilter(
this);
43 auto layout =
new QVBoxLayout();
44 ui->framePlotPreview->setLayout(layout);
53 restoreGeometry(settings.value(
"PlotwidgetEditor.geometry").toByteArray());
57 ui->radioLines->setChecked(
true);
61 ui->radioPoints->setChecked(
true);
65 ui->radioSticks->setChecked(
true);
69 ui->radioSteps->setChecked(
true);
73 ui->radioStepsInv->setChecked(
true);
77 ui->radioBoth->setChecked(
true);
80 ui->lineLimitMax->setValidator(
new QDoubleValidator(
this));
81 ui->lineLimitMin->setValidator(
new QDoubleValidator(
this));
89 ui->checkBoxMin->setChecked(
true);
90 ui->lineLimitMin->setText(QString::number(ylimits.min));
94 ui->lineLimitMin->setText(QString::number(suggested_limits.
min));
99 ui->checkBoxMax->setChecked(
true);
100 ui->lineLimitMax->setText(QString::number(ylimits.max));
104 ui->lineLimitMax->setText(QString::number(suggested_limits.
max));
110 if (
ui->listWidget->count() != 0)
112 ui->listWidget->item(0)->setSelected(
true);
119 settings.setValue(
"PlotwidgetEditor.geometry", saveGeometry());
127 auto selected =
ui->listWidget->selectedItems();
128 if (selected.size() != 1)
132 auto item = selected.front();
135 auto row_widget =
dynamic_cast<EditorRowWidget*
>(
ui->listWidget->itemWidget(item));
136 auto name = row_widget->text();
137 if (row_widget->color() != c)
139 row_widget->setColor(c);
148 auto wheel_layout =
new QVBoxLayout();
149 wheel_layout->setMargin(0);
150 wheel_layout->setSpacing(5);
151 ui->widgetWheel->setLayout(wheel_layout);
168 QSignalBlocker
block(
ui->editColotText);
169 ui->editColotText->setText(col.name());
177 int row_count =
ui->listWidget->count();
178 for (
int row = 0; row < row_count; row++)
180 auto item =
ui->listWidget->item(row);
181 auto widget =
ui->listWidget->itemWidget(item);
186 ui->listWidget->takeItem(row);
188 widget->deleteLater();
202 ui->widgetColor->setEnabled(
false);
206 ui->frameLimits->setEnabled(
false);
207 ui->frameStyle->setEnabled(
false);
215 for (
auto& it : colors)
217 auto alias = it.first;
218 auto color = it.second;
219 auto item =
new QListWidgetItem();
221 item->setData(Qt::UserRole, it.first);
223 ui->listWidget->addItem(item);
225 item->setSizeHint(plot_row->sizeHint());
226 ui->listWidget->setItemWidget(item, plot_row);
243 if (
ui->checkBoxMax->isChecked() && !
ui->lineLimitMax->text().isEmpty())
246 double val =
ui->lineLimitMax->text().toDouble(&
ok);
253 if (
ui->checkBoxMin->isChecked() && !
ui->lineLimitMin->text().isEmpty())
256 double val =
ui->lineLimitMin->text().toDouble(&
ok);
266 ui->lineLimitMin->setText(QString::number(ymax));
267 ui->lineLimitMax->setText(QString::number(ymin));
279 if (text.size() == 7 && text[0] ==
'#' && QColor::isValidColor(text))
337 ui->lineLimitMax->setEnabled(checked);
343 ui->lineLimitMin->setEnabled(checked);
358 ui->lineLimitMin->setText(QString::number(limits.
min));
359 ui->lineLimitMax->setText(QString::number(limits.
max));
388 setMouseTracking(
true);
389 const QSize button_size(20, 20);
391 auto layout =
new QHBoxLayout();
402 auto icon = QIcon(
":/resources/svg/trash.svg");
403 _delete_button->setStyleSheet(
"QPushButton:hover{ border: 0px;}");
410 layout->addWidget(
_text);
432 return _text->text();
437 setStyleSheet(QString(
"color: %1;").
arg(
color.name()));
448 auto selected =
ui->listWidget->selectedItems();
449 if (selected.size() == 0 ||
ui->listWidget->count() == 0)
451 ui->widgetColor->setEnabled(
false);
452 ui->editColotText->setText(
"#000000");
456 ui->widgetColor->setEnabled(
true);
458 if (selected.size() != 1)
463 auto item = selected.front();
464 auto row_widget =
dynamic_cast<EditorRowWidget*
>(
ui->listWidget->itemWidget(item));
467 ui->editColotText->setText(row_widget->color().name());