diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,6 +136,7 @@ add_executable(${PROGRAM_NAME} WIN32 src/plotmanager.cpp src/barplot.cpp src/barchart.cpp + src/barscaledraw.cpp src/numberformat.cpp src/updatechecker.cpp src/versionnumber.cpp diff --git a/src/barplot.cpp b/src/barplot.cpp --- a/src/barplot.cpp +++ b/src/barplot.cpp @@ -18,19 +18,26 @@ */ #include "barplot.h" +#include "barscaledraw.h" BarPlot::BarPlot(ChannelManager* channelMan, QWidget* parent) : QwtPlot(parent), barChart(channelMan) { _channelMan = channelMan; barChart.attach(this); + setAxisMaxMinor(QwtPlot::xBottom, 0); + setAxisScaleDraw(QwtPlot::xBottom, new BarScaleDraw(channelMan)); + update(); connect(_channelMan, &ChannelManager::dataAdded, this, &BarPlot::update); connect(_channelMan, &ChannelManager::numOfChannelsChanged, this, &BarPlot::update); + connect(_channelMan, &ChannelManager::channelNameChanged, this, &BarPlot::update); } void BarPlot::update() { + setAxisScale(QwtPlot::xBottom, 0, _channelMan->numOfChannels(), 1); + static_cast(axisScaleDraw(QwtPlot::xBottom))->updateLabels(); barChart.resample(); replot(); } diff --git a/src/barscaledraw.cpp b/src/barscaledraw.cpp new file mode 100644 --- /dev/null +++ b/src/barscaledraw.cpp @@ -0,0 +1,52 @@ +/* + 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 + (at your option) any later version. + + serialplot is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with serialplot. If not, see . +*/ + +#include "barscaledraw.h" + +#include + +BarScaleDraw::BarScaleDraw(ChannelManager* channelMan) +{ + _channelMan = channelMan; + enableComponent(Backbone, false); + setLabelRotation(-90); + setLabelAlignment(Qt::AlignLeft | Qt::AlignVCenter); +} + +QwtText BarScaleDraw::label(double value) const +{ + int index = value; + unsigned numChannels = _channelMan->numOfChannels(); + + qDebug() << index; + + if (index >=0 && index < (int) numChannels) + { + return _channelMan->channelName(index); + } + else + { + return QString(""); + } +} + +void BarScaleDraw::updateLabels() +{ + invalidateCache(); +} diff --git a/src/barscaledraw.h b/src/barscaledraw.h new file mode 100644 --- /dev/null +++ b/src/barscaledraw.h @@ -0,0 +1,42 @@ +/* + 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 + (at your option) any later version. + + serialplot is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with serialplot. If not, see . +*/ + +#ifndef BARSCALEDRAW_H +#define BARSCALEDRAW_H + +#include +#include +#include + +#include "channelmanager.h" + +class BarScaleDraw : public QwtScaleDraw +{ +public: + explicit BarScaleDraw(ChannelManager* channelMan); + QwtText label(double value) const; + +public slots: + void updateLabels(); + +private: + ChannelManager* _channelMan; +}; + +#endif // BARSCALEDRAW_H