Changeset - 70f83253cf6c
[Not reviewed]
default
0 2 0
Hasan Yavuz ÖZDERYA - 10 years ago 2015-04-28 16:19:06
hy@ozderya.net
implemented automatic coloring of different channels with auto color selection
2 files changed with 37 insertions and 0 deletions:
0 comments (0 inline, 0 general)
mainwindow.cpp
Show inline comments
 
@@ -24,6 +24,7 @@
 
#include <QtDebug>
 
#include <qwt_plot.h>
 
#include <limits.h>
 
#include <cmath>
 
#include "utils.h"
 

	
 
MainWindow::MainWindow(QWidget *parent) :
 
@@ -167,6 +168,7 @@ MainWindow::MainWindow(QWidget *parent) 
 
        channelsData.append(DataArray(numOfSamples, 0.0));
 
        curves.append(new QwtPlotCurve());
 
        curves[i]->setSamples(dataX, channelsData[i]);
 
        curves[i]->setPen(makeColor(i));
 
        curves[i]->attach(ui->plot);
 
    }
 

	
 
@@ -528,6 +530,7 @@ void MainWindow::onNumOfChannelsChanged(
 
            channelsData.append(DataArray(numOfSamples, 0.0));
 
            curves.append(new QwtPlotCurve());
 
            curves.last()->setSamples(dataX, channelsData.last());
 
            curves.last()->setPen(makeColor(curves.length()-1));
 
            curves.last()->attach(ui->plot);
 
        }
 
    }
 
@@ -655,3 +658,34 @@ void MainWindow::enableDemo(bool enabled
 
        ui->actionDemoMode->setChecked(false);
 
    }
 
}
 

	
 
/*
 
  Below crude drawing demostrates how color selection occurs for
 
  given channel index
 

	
 
  0°                     <--Hue Value-->                           360°
 
  |* . o . + . o . * . o . + . o . * . o . + . o . * . o . + . o . |
 

	
 
  * -> 0-3
 
  + -> 4-7
 
  o -> 8-15
 
  . -> 16-31
 

	
 
 */
 

	
 
QColor MainWindow::makeColor(unsigned int channelIndex)
 
{
 
    auto i = channelIndex;
 

	
 
    if (i < 4)
 
    {
 
        return QColor::fromHsv(360*i/4, 255, 255);
 
    }
 
    else
 
    {
 
        double p = floor(log2(i));
 
        double n = pow(2, p);
 
        i = i - n;
 
        return QColor::fromHsv(360*i/n + 360/pow(2,p+1), 255, 255);
 
    }
 
}
mainwindow.h
Show inline comments
 
@@ -28,6 +28,7 @@
 
#include <QSerialPort>
 
#include <QSignalMapper>
 
#include <QTimer>
 
#include <QColor>
 
#include <qwt_plot_curve.h>
 

	
 
#include "ui_about_dialog.h"
 
@@ -92,6 +93,8 @@ private:
 
    int demoCount;
 
    bool isDemoRunning();
 

	
 
    QColor makeColor(unsigned int channelIndex);
 

	
 
private slots:
 
    void loadPortList();
 
    void loadBaudRateList();
0 comments (0 inline, 0 general)