Changeset - edd8b66ead8e
[Not reviewed]
Hasan Yavuz ÖZDERYA - 9 years ago 2017-01-02 11:01:33
hy@ozderya.net
plotmanager somewhat integrated into the new channelinfomodel
4 files changed with 53 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/channelmanager.cpp
Show inline comments
 
@@ -126,7 +126,6 @@ void ChannelManager::onChannelInfoChange
 
                                          const QModelIndex & bottomRight,
 
                                          const QVector<int> & roles)
 
{
 
    Q_UNUSED(roles);
 
    int start = topLeft.row();
 
    int end = bottomRight.row();
 
    int col = topLeft.column();
src/mainwindow.cpp
Show inline comments
 
@@ -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);
 
    }
 
}
 

	
src/plotmanager.cpp
Show inline comments
 
/*
 
  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<bool>::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<int> &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<QColor>();
 
        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;
src/plotmanager.h
Show inline comments
 
/*
 
  Copyright © 2016 Hasan Yavuz Özderya
 
  Copyright © 2017 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
@@ -30,13 +30,14 @@
 
#include <qwt_plot_curve.h>
 
#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<QwtPlotCurve*> curves;
 
    QList<Plot*> 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<int> & roles = QVector<int> ());
 
};
 

	
 
#endif // PLOTMANAGER_H
0 comments (0 inline, 0 general)