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
 
@@ -123,13 +123,12 @@ QStringList ChannelManager::channelNames
 
}
 

	
 
void ChannelManager::onChannelInfoChanged(const QModelIndex & topLeft,
 
                                          const QModelIndex & bottomRight,
 
                                          const QVector<int> & roles)
 
{
 
    Q_UNUSED(roles);
 
    int start = topLeft.row();
 
    int end = bottomRight.row();
 
    int col = topLeft.column();
 

	
 
    for (int ci = start; ci <= end; ci++)
 
    {
src/mainwindow.cpp
Show inline comments
 
@@ -63,13 +63,13 @@ MainWindow::MainWindow(QWidget *parent) 
 
    snapshotMan(this, &channelMan),
 
    commandPanel(&serialPort),
 
    dataFormatPanel(&serialPort, &channelMan)
 
{
 
    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");
 
    ui->tabWidget->insertTab(2, &plotControlPanel, "Plot");
 
    ui->tabWidget->insertTab(3, &commandPanel, "Commands");
 
    ui->tabWidget->setCurrentIndex(0);
 
@@ -373,13 +373,13 @@ void MainWindow::onChannelNameChanged(un
 
{
 
    // This slot is triggered also when a new channel is added, in
 
    // this case curve list doesn't contain said channel. No worries,
 
    // 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);
 
    }
 
}
 

	
 
void MainWindow::onSpsChanged(unsigned sps)
 
{
 
    spsLabel.setText(QString::number(sps) + "sps");
src/plotmanager.cpp
Show inline comments
 
/*
 
  Copyright © 2016 Hasan Yavuz Özderya
 
  Copyright © 2017 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
  serialplot is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
@@ -21,13 +21,13 @@
 

	
 
#include "plot.h"
 
#include "plotmanager.h"
 
#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),
 
    showMinorGridAction("&Minor Grid", this),
 
    unzoomAction("&Unzoom", this),
 
    darkBackgroundAction("&Dark Background", this),
 
@@ -35,12 +35,13 @@ PlotManager::PlotManager(QWidget* plotAr
 
    showMultiAction("Multi &Plot", this)
 
{
 
    _autoScaled = true;
 
    _yMin = 0;
 
    _yMax = 1;
 
    isDemoShown = false;
 
    _infoModel = infoModel;
 

	
 
    // initalize layout and single widget
 
    isMulti = false;
 
    scrollArea = NULL;
 
    setupLayout(isMulti);
 
    addPlotWidget();
 
@@ -82,12 +83,19 @@ PlotManager::PlotManager(QWidget* plotAr
 
    connect(&showLegendAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
 
            this, &PlotManager::showLegend);
 
    connect(&showLegendAction, SELECT<bool>::OVERLOAD_OF(&QAction::triggered),
 
            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()
 
{
 
    while (curves.size())
 
    {
 
@@ -100,12 +108,45 @@ PlotManager::~PlotManager()
 
        delete plotWidgets.takeLast();
 
    }
 

	
 
    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;
 

	
 
    isMulti = enabled;
 

	
src/plotmanager.h
Show inline comments
 
/*
 
  Copyright © 2016 Hasan Yavuz Özderya
 
  Copyright © 2017 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
  serialplot is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
@@ -27,19 +27,20 @@
 
#include <QList>
 
#include <QSettings>
 

	
 
#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.
 
    void addCurve(QString title, FrameBuffer* buffer);
 
    /// Alternative of `addCurve` for static curve data (snapshots).
 
    void addCurve(QString title, QVector<QPointF> data);
 
@@ -74,12 +75,13 @@ private:
 
    bool isMulti;
 
    QWidget* _plotArea;
 
    QVBoxLayout* layout; ///< layout of the `plotArea`
 
    QScrollArea* scrollArea;
 
    QList<QwtPlotCurve*> curves;
 
    QList<Plot*> plotWidgets;
 
    ChannelInfoModel* _infoModel;
 
    bool isDemoShown;
 
    bool _autoScaled;
 
    double _yMin;
 
    double _yMax;
 

	
 
    // menu actions
 
@@ -101,9 +103,13 @@ private:
 
private slots:
 
    void showGrid(bool show = true);
 
    void showMinorGrid(bool show = true);
 
    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)