diff --git a/include/PlotJuggler/random_color.h b/include/PlotJuggler/random_color.h deleted file mode 100644 index d0ea3efbd..000000000 --- a/include/PlotJuggler/random_color.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef RANDOM_COLOR_H -#define RANDOM_COLOR_H - -#include - -inline QColor randomColorHint() -{ - static int index = 0; - QColor color; - // https://matplotlib.org/3.1.1/users/dflt_style_changes.html - switch( index%8 ) - { - case 0: color = QColor("#1f77b4"); break; - case 1: color = QColor("#d62728"); break; - case 2: color = QColor("#1ac938"); break; - case 3: color = QColor("#ff7f0e"); break; - - case 4: color = QColor("#f14cc1"); break; - case 5: color = QColor("#9467bd"); break; - case 6: color = QColor("#17becf"); break; - case 7: color = QColor("#bcbd22"); break; - } - index++; - return color; -} - -#endif // RANDOM_COLOR_H diff --git a/plotter_gui/curvecolorpick.cpp b/plotter_gui/curvecolorpick.cpp index c68b1b044..f8410380e 100644 --- a/plotter_gui/curvecolorpick.cpp +++ b/plotter_gui/curvecolorpick.cpp @@ -3,7 +3,8 @@ #include -CurveColorPick::CurveColorPick(const std::map &mapped_colors, QWidget *parent) : +CurveColorPick::CurveColorPick(const std::map &mapped_colors, + QWidget *parent) : QDialog(parent), ui(new Ui::CurveColorPick), _any_modified(false), @@ -23,16 +24,35 @@ CurveColorPick::CurveColorPick(const std::map &mapped_color _color_wheel->setMinimumWidth(150); _color_wheel->setMinimumHeight(150); + ui->verticalLayoutRight->insertWidget(1, new QLabel("Default colors", this) ); + + _color_palette = new color_widgets::Swatch(this); + ui->verticalLayoutRight->insertWidget(2, _color_palette ); + _color_palette->setMinimumWidth(150); + _color_palette->setMinimumHeight(30); + _color_palette->setMaximumHeight(30); + + ui->verticalLayoutRight->insertWidget(3, new QLabel("Preview", this) ); + _color_preview = new color_widgets::ColorPreview(this); - ui->verticalLayoutRight->insertWidget(1, _color_preview ); + ui->verticalLayoutRight->insertWidget(4, _color_preview ); _color_preview->setMinimumWidth(150); _color_preview->setMinimumHeight(100); + QVector colors = {QColor("#1f77b4"), QColor("#d62728"), QColor("#1ac938"), QColor("#ff7f0e"), + QColor("#f14cc1"), QColor("#9467bd"), QColor("#17becf"), QColor("#bcbd22")}; + + color_widgets::ColorPalette palette(colors, "default colors", 8); + _color_palette->setPalette(palette); + connect(_color_wheel, &color_widgets::ColorWheel::colorChanged, _color_preview, &color_widgets::ColorPreview::setColor ); connect(_color_wheel, &color_widgets::ColorWheel::colorChanged, this, &CurveColorPick::on_colorChanged ); + + connect(_color_palette, &color_widgets::Swatch::colorSelected, + _color_wheel, &color_widgets::ColorWheel::setColor ); } CurveColorPick::~CurveColorPick() diff --git a/plotter_gui/curvecolorpick.h b/plotter_gui/curvecolorpick.h index 9b2da9694..0db2ee10c 100644 --- a/plotter_gui/curvecolorpick.h +++ b/plotter_gui/curvecolorpick.h @@ -5,6 +5,9 @@ #include #include "color_wheel.hpp" #include "color_preview.hpp" +#include "color_palette.hpp" +#include "swatch.hpp" + namespace Ui { class CurveColorPick; @@ -15,7 +18,8 @@ class CurveColorPick : public QDialog Q_OBJECT public: - explicit CurveColorPick(const std::map& mapped_colors, QWidget *parent = 0); + explicit CurveColorPick(const std::map& mapped_colors, + QWidget *parent = 0); ~CurveColorPick(); bool anyColorModified() const ; @@ -36,6 +40,7 @@ private slots: Ui::CurveColorPick *ui; color_widgets::ColorWheel *_color_wheel; color_widgets::ColorPreview *_color_preview; + color_widgets::Swatch *_color_palette; const std::map& _mapped_colors; bool _any_modified; diff --git a/plotter_gui/curvecolorpick.ui b/plotter_gui/curvecolorpick.ui index a38d1354f..13a97ba93 100644 --- a/plotter_gui/curvecolorpick.ui +++ b/plotter_gui/curvecolorpick.ui @@ -11,7 +11,7 @@ - Dialog + Color Selector diff --git a/plotter_gui/curvelist_panel.cpp b/plotter_gui/curvelist_panel.cpp index e67d832e2..fa52feff1 100644 --- a/plotter_gui/curvelist_panel.cpp +++ b/plotter_gui/curvelist_panel.cpp @@ -276,11 +276,6 @@ void CurveListPanel::on_radioRegExp_toggled(bool checked) } } -void CurveListPanel::on_checkBoxCaseSensitive_toggled(bool ) -{ - updateFilter(); -} - void CurveListPanel::on_lineEdit_textChanged(const QString &search_string) { bool updated = false; diff --git a/plotter_gui/curvelist_panel.h b/plotter_gui/curvelist_panel.h index 79f038bf1..008d5a4ac 100644 --- a/plotter_gui/curvelist_panel.h +++ b/plotter_gui/curvelist_panel.h @@ -57,8 +57,6 @@ private slots: void on_radioRegExp_toggled(bool checked); - void on_checkBoxCaseSensitive_toggled(bool checked); - void on_lineEdit_textChanged(const QString &search_string); void on_pushButtonSettings_toggled(bool checked); diff --git a/plotter_gui/curvelist_view.cpp b/plotter_gui/curvelist_view.cpp index d8decc41b..589ee90c6 100644 --- a/plotter_gui/curvelist_view.cpp +++ b/plotter_gui/curvelist_view.cpp @@ -248,7 +248,10 @@ bool CurvesView::eventFilterBase(QObject *object, QEvent *event) QByteArray mdata; QDataStream stream(&mdata, QIODevice::WriteOnly); - for (const auto &curve_name : getSelectedNames()) + auto selected_names = getSelectedNames(); + std::sort( selected_names.begin(), selected_names.end() ); + + for (const auto &curve_name : selected_names) { stream << QString::fromStdString(curve_name); } @@ -259,9 +262,9 @@ bool CurvesView::eventFilterBase(QObject *object, QEvent *event) } else { - if (getSelectedNames().size() != 2) + if (selected_names.size() != 2) { - if (getSelectedNames().size() >= 1) + if (selected_names.size() >= 1) { QMessageBox::warning( table_widget, "New in version 2.3+", diff --git a/plotter_gui/plotwidget.cpp b/plotter_gui/plotwidget.cpp index 2446a1180..c7575b04a 100644 --- a/plotter_gui/plotwidget.cpp +++ b/plotter_gui/plotwidget.cpp @@ -33,12 +33,50 @@ #include "qwt_plot_renderer.h" #include "qwt_series_data.h" #include "qwt_date_scale_draw.h" -#include "PlotJuggler/random_color.h" #include "point_series_xy.h" #include "suggest_dialog.h" #include "transforms/custom_function.h" #include "transforms/custom_timeseries.h" +int PlotWidget::global_color_index = 0; + +QColor PlotWidget::getColorHint(PlotData* data) +{ + QSettings settings; + bool remember_color = settings.value("Preferences::remember_color", true).toBool(); + if( data && remember_color && data->getColorHint() != Qt::black ) + { + return data->getColorHint(); + } + QColor color; + bool use_plot_color_index = settings.value("Preferences::use_plot_color_index", false).toBool(); + int index = _curve_list.size(); + + if( !use_plot_color_index ) + { + index = (PlotWidget::global_color_index++); + } + + // https://matplotlib.org/3.1.1/users/dflt_style_changes.html + switch( index%8 ) + { + case 0: color = QColor("#1f77b4"); break; + case 1: color = QColor("#d62728"); break; + case 2: color = QColor("#1ac938"); break; + case 3: color = QColor("#ff7f0e"); break; + + case 4: color = QColor("#f14cc1"); break; + case 5: color = QColor("#9467bd"); break; + case 6: color = QColor("#17becf"); break; + case 7: color = QColor("#bcbd22"); break; + } + if( data ){ + data->setColorHint(color); + } + + return color; +} + class TimeScaleDraw: public QwtScaleDraw { virtual QwtText label(double v) const @@ -82,6 +120,7 @@ PlotWidget::PlotWidget(PlotDataMapRef &datamap, QWidget *parent): _xy_mode(false), _transform_select_dialog(nullptr), _use_date_time_scale(false), + _color_index(0), _zoom_enabled(true), _keep_aspect_ratio(true) { @@ -369,12 +408,8 @@ bool PlotWidget::addCurve(const std::string &name) curve->setStyle( _curve_style ); - QColor color = data.getColorHint(); - if( color == Qt::black) - { - color = randomColorHint(); - data.setColorHint(color); - } + QColor color = getColorHint(&data); + curve->setPen( color, (_curve_style == QwtPlotCurve::Dots) ? 4 : 1.0 ); curve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); @@ -443,7 +478,6 @@ bool PlotWidget::addCurveXY(std::string name_x, std::string name_y, return false; } - PlotData& data = it->second; const auto qname = QString::fromStdString( name ); auto curve = new QwtPlotCurve( qname ); @@ -463,7 +497,7 @@ bool PlotWidget::addCurveXY(std::string name_x, std::string name_y, curve->setStyle( _curve_style ); - QColor color = randomColorHint(); + QColor color = getColorHint(nullptr); curve->setPen( color, (_curve_style == QwtPlotCurve::Dots) ? 4 : 1.0 ); curve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); diff --git a/plotter_gui/plotwidget.h b/plotter_gui/plotwidget.h index a5392977f..6420d5ea9 100644 --- a/plotter_gui/plotwidget.h +++ b/plotter_gui/plotwidget.h @@ -83,6 +83,8 @@ class PlotWidget : public QwtPlot bool canvasEventFilter(QEvent *event); + QColor getColorHint(PlotData *data); + signals: void swapWidgetsRequested(PlotWidget* source, PlotWidget* destination); void rectChanged(PlotWidget* self, QRectF rect ); @@ -182,6 +184,9 @@ private slots: bool _use_date_time_scale; + int _color_index; + static int global_color_index; + PlotDataMapRef& _mapped_data; QString _default_transform; std::map _curves_transform; diff --git a/plotter_gui/preferences_dialog.cpp b/plotter_gui/preferences_dialog.cpp index 7f7a5beaf..5af7f05b4 100644 --- a/plotter_gui/preferences_dialog.cpp +++ b/plotter_gui/preferences_dialog.cpp @@ -16,6 +16,13 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) : else{ ui->comboBoxTheme->setCurrentIndex(0); } + + bool use_plot_color_index = settings.value("Preferences::use_plot_color_index", false).toBool(); + bool remember_color = settings.value("Preferences::remember_color", true).toBool(); + + ui->checkBoxRememberColor->setChecked(remember_color); + ui->radioLocalColorIndex->setChecked(use_plot_color_index); + ui->radioGlobalColorIndex->setChecked(!use_plot_color_index); } PreferencesDialog::~PreferencesDialog() @@ -29,4 +36,10 @@ void PreferencesDialog::on_buttonBox_accepted() settings.setValue("Preferences::theme", ui->comboBoxTheme->currentIndex() == 1 ? "style_dark" : "style_light"); + settings.setValue("Preferences::remember_color", + ui->checkBoxRememberColor->isChecked()); + + settings.setValue("Preferences::use_plot_color_index", + ui->radioLocalColorIndex->isChecked()); + } diff --git a/plotter_gui/preferences_dialog.ui b/plotter_gui/preferences_dialog.ui index a8dbbcfb0..d9ccb2bb0 100644 --- a/plotter_gui/preferences_dialog.ui +++ b/plotter_gui/preferences_dialog.ui @@ -6,16 +6,28 @@ 0 0 - 400 + 450 300 + + + 450 + 0 + + Dialog + + + 50 + false + + Preferences @@ -41,6 +53,55 @@ + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + + + global color sequence + + + true + + + + + + + reset color sequence in each plot area + + + + + + + remember curve color + + + true + + + + + + + + + + Curve color + + +