diff --git a/mainwindow.cpp b/mainwindow.cpp index 737f8e9..f2defed 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -41,6 +41,4 @@ void MainWindow::openFile(QString fileName) this->setWindowTitle(title.arg(QApplication::applicationName(),fileName.section('/',-1,-1))); // TODO: error check, ownership plots->inputSourceChanged(new InputSource(fileName.toUtf8().constData())); - // TODO: don't hardcode this - plots->viewChanged(0, 102400); } diff --git a/plotview.cpp b/plotview.cpp index 7f8fca4..6fd9d4d 100644 --- a/plotview.cpp +++ b/plotview.cpp @@ -20,6 +20,7 @@ #include "plotview.h" #include #include +#include #include #include #include @@ -89,13 +90,9 @@ void PlotView::inputSourceChanged(AbstractSampleSource *src) mainSampleSource = derived; refreshSources(); -} -void PlotView::viewChanged(off_t firstSample, off_t lastSample) -{ - this->firstSample = firstSample; - this->lastSample = lastSample; - update(); + horizontalScrollBar()->setMinimum(0); + horizontalScrollBar()->setMaximum(mainSampleSource->count()); } void PlotView::selectionChanged(std::pair selectionTime, std::pair selectionFreq) @@ -114,7 +111,10 @@ void PlotView::selectionCleared() void PlotView::paintEvent(QPaintEvent *event) { - if (lastSample - firstSample <= 0) return; + if (mainSampleSource == nullptr) return; + off_t firstSample = horizontalScrollBar()->value(); + // TODO: don't hardcode width + off_t lastSample = firstSample + 10240; QRect rect = QRect(0, 0, width(), height()); QPainter painter(viewport()); diff --git a/plotview.h b/plotview.h index 2600ade..72ead19 100644 --- a/plotview.h +++ b/plotview.h @@ -33,7 +33,6 @@ public: public slots: void inputSourceChanged(AbstractSampleSource *input); - void viewChanged(off_t firstSample, off_t lastSample); void selectionChanged(std::pair selectionTime, std::pair selectionFreq); void selectionCleared(); @@ -43,8 +42,6 @@ protected: private: SampleSource> *mainSampleSource = nullptr; std::vector> plots; - off_t firstSample = 0; - off_t lastSample = 0; bool selection = false; std::pair selectionTime; std::pair selectionFreq;