diff --git a/src/plotmanager.cpp b/src/plotmanager.cpp --- a/src/plotmanager.cpp +++ b/src/plotmanager.cpp @@ -1,5 +1,5 @@ /* - Copyright © 2016 Hasan Yavuz Özderya + Copyright © 2017 Hasan Yavuz Özderya This file is part of serialplot. @@ -24,7 +24,7 @@ #include "utils.h" #include "setting_defines.h" -PlotManager::PlotManager(QWidget* plotArea, QObject *parent) : +PlotManager::PlotManager(QWidget* plotArea, ChannelInfoModel* infoModel, QObject *parent) : QObject(parent), _plotArea(plotArea), showGridAction("&Grid", this), @@ -38,6 +38,7 @@ PlotManager::PlotManager(QWidget* plotAr _yMin = 0; _yMax = 1; isDemoShown = false; + _infoModel = infoModel; // initalize layout and single widget isMulti = false; @@ -85,6 +86,13 @@ PlotManager::PlotManager(QWidget* plotAr this, &PlotManager::showLegend); connect(&showMultiAction, SELECT::OVERLOAD_OF(&QAction::triggered), this, &PlotManager::setMulti); + + // connect to channel info model + if (_infoModel != NULL) // TODO: remove when snapshots have infomodel + { + connect(_infoModel, &QAbstractItemModel::dataChanged, + this, &PlotManager::onChannelInfoChanged); + } } PlotManager::~PlotManager() @@ -103,6 +111,39 @@ PlotManager::~PlotManager() if (scrollArea != NULL) delete scrollArea; } +void PlotManager::onChannelInfoChanged(const QModelIndex &topLeft, + const QModelIndex &bottomRight, + const QVector &roles) +{ + int start = topLeft.row(); + int end = bottomRight.row(); + + for (int ci = start; ci <= end; ci++) + { + qDebug() << "ci:" << ci << "curves.size:" << curves.size() << "plotWidgets.size:" << plotWidgets.size(); + + QString name = topLeft.sibling(ci, ChannelInfoModel::COLUMN_NAME).data(Qt::EditRole).toString(); + QColor color = topLeft.sibling(ci, ChannelInfoModel::COLUMN_NAME).data(Qt::ForegroundRole).value(); + bool visible = topLeft.sibling(ci, ChannelInfoModel::COLUMN_VISIBILITY).data(Qt::CheckStateRole).toBool(); + + curves[ci]->setTitle(name); + curves[ci]->setPen(color); + curves[ci]->setVisible(visible); + + // replot only updated widgets + if (isMulti) + { + plotWidgets[ci]->replot(); + } + } + + // replot single widget + if (!isMulti) + { + replot(); + } +} + void PlotManager::setMulti(bool enabled) { if (enabled == isMulti) return;