# HG changeset patch # User Hasan Yavuz ÖZDERYA # Date 2017-01-02 11:01:33 # Node ID edd8b66ead8e0668bbad630d698fb2324b4e0a3d # Parent 601fe4ade58bcc03975134f7459347290028c94a plotmanager somewhat integrated into the new channelinfomodel diff --git a/src/channelmanager.cpp b/src/channelmanager.cpp --- a/src/channelmanager.cpp +++ b/src/channelmanager.cpp @@ -126,7 +126,6 @@ void ChannelManager::onChannelInfoChange const QModelIndex & bottomRight, const QVector & roles) { - Q_UNUSED(roles); int start = topLeft.row(); int end = bottomRight.row(); int col = topLeft.column(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -66,7 +66,7 @@ MainWindow::MainWindow(QWidget *parent) { ui->setupUi(this); - plotMan = new PlotManager(ui->plotArea); + plotMan = new PlotManager(ui->plotArea, channelMan.infoModel()); ui->tabWidget->insertTab(0, &portControl, "Port"); ui->tabWidget->insertTab(1, &dataFormatPanel, "Data Format"); @@ -376,7 +376,7 @@ void MainWindow::onChannelNameChanged(un // since `onNumOfChannelsChanged` slot will update curve list. if (channel < plotMan->numOfCurves()) // check if channel exists in curve list { - plotMan->setTitle(channel, name); + // plotMan->setTitle(channel, name); } } 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; diff --git a/src/plotmanager.h b/src/plotmanager.h --- a/src/plotmanager.h +++ b/src/plotmanager.h @@ -1,5 +1,5 @@ /* - Copyright © 2016 Hasan Yavuz Özderya + Copyright © 2017 Hasan Yavuz Özderya This file is part of serialplot. @@ -30,13 +30,14 @@ #include #include "plot.h" #include "framebufferseries.h" +#include "channelinfomodel.h" class PlotManager : public QObject { Q_OBJECT public: - explicit PlotManager(QWidget* plotArea, QObject *parent = 0); + explicit PlotManager(QWidget* plotArea, ChannelInfoModel* infoModel = NULL, QObject *parent = 0); ~PlotManager(); /// Add a new curve with title and buffer. A color is /// automatically chosen for curve. @@ -77,6 +78,7 @@ private: QScrollArea* scrollArea; QList curves; QList plotWidgets; + ChannelInfoModel* _infoModel; bool isDemoShown; bool _autoScaled; double _yMin; @@ -104,6 +106,10 @@ private slots: void showLegend(bool show = true); void unzoom(); void darkBackground(bool enabled = true); + + void onChannelInfoChanged(const QModelIndex & topLeft, + const QModelIndex & bottomRight, + const QVector & roles = QVector ()); }; #endif // PLOTMANAGER_H