Commit 4d6d4d8b1eb93a6b3931e68fb6c790352af61a96

Authored by David Mayerich
1 parent 4d9fea5b

fixed an error in band line rendering

Showing 3 changed files with 14 additions and 9 deletions   Show diff stats
main.cpp
... ... @@ -13,8 +13,5 @@ int main(int argc, char *argv[])
13 13 w.loadImage(fileName);
14 14 w.show();
15 15  
16   - //SpectrumWindow s(&w);
17   - //s.show();
18   -
19 16 return a.exec();
20 17 }
... ...
spectrumwindow.cpp
... ... @@ -15,9 +15,6 @@ SpectrumWindow::SpectrumWindow(QWidget *parent) :
15 15 //create a line for the current band
16 16 bandline = new QCPItemStraightLine(ui->spectrumPlot);
17 17 ui->spectrumPlot->addItem(bandline);
18   -
19   -
20   -
21 18 }
22 19  
23 20 SpectrumWindow::~SpectrumWindow()
... ... @@ -39,11 +36,13 @@ void SpectrumWindow::plotSpectrum(QVector<double> x, QVector<double> y){
39 36 ui->spectrumPlot->yAxis->setRange(y_min, y_max);
40 37  
41 38 //add the graph to the plot
42   - ui->spectrumPlot->addGraph();
43 39 ui->spectrumPlot->graph(0)->setData(x, y);
44 40  
45 41 //redraw the plot
46 42 ui->spectrumPlot->replot();
  43 +
  44 + std::cout<<"Items in the plot: "<<ui->spectrumPlot->itemCount()<<std::endl;
  45 + std::cout<<bandline->point1->coords().x()<<", "<<bandline->point1->coords().y()<<std::endl;
47 46 }
48 47  
49 48 void SpectrumWindow::initPlot(double x_min, double x_max, double y_min, double y_max, QString x_title, QString y_title){
... ... @@ -54,6 +53,9 @@ void SpectrumWindow::initPlot(double x_min, double x_max, double y_min, double y
54 53 ui->spectrumPlot->xAxis->setRange(x_min, x_max);
55 54 ui->spectrumPlot->yAxis->setRange(y_min, y_max);
56 55  
  56 + //add a graph to the plot
  57 + ui->spectrumPlot->addGraph();
  58 +
57 59 //set the initial position of the band line
58 60 double xmid = (x_max + x_min) / 2;
59 61 std::cout<<"xmid: "<<xmid<<std::endl;
... ... @@ -78,7 +80,7 @@ void SpectrumWindow::resizeEvent(QResizeEvent* event){
78 80 bool SpectrumWindow::eventFilter(QObject *target, QEvent *event)
79 81 {
80 82  
81   - if(target == ui->spectrumPlot && event->type() == QEvent::MouseMove)
  83 + /*if(target == ui->spectrumPlot && event->type() == QEvent::MouseMove)
82 84 {
83 85 QMouseEvent *_mouseEvent = static_cast<QMouseEvent*>(event);
84 86  
... ... @@ -93,8 +95,10 @@ bool SpectrumWindow::eventFilter(QObject *target, QEvent *event)
93 95 //set the position of the band line
94 96 bandline->point1->setCoords(x, 0);
95 97 bandline->point2->setCoords(x, 1);
  98 + std::cout<<"coords set to: "<<x<<std::endl;
96 99 }
97   - else if(target == ui->spectrumPlot && event->type() == QEvent::MouseButtonPress)
  100 + else */
  101 + if(target == ui->spectrumPlot && event->type() == QEvent::MouseButtonPress)
98 102 {
99 103 QMouseEvent *_mouseEvent = static_cast<QMouseEvent*>(event);
100 104  
... ... @@ -112,6 +116,10 @@ bool SpectrumWindow::eventFilter(QObject *target, QEvent *event)
112 116 //set the position of the band line
113 117 bandline->point1->setCoords(x, 0);
114 118 bandline->point2->setCoords(x, 1);
  119 + std::cout<<"coords set to: "<<x<<std::endl;
  120 +
  121 + //replot the spectrum with the new band line position
  122 + ui->spectrumPlot->replot();
115 123 }
116 124  
117 125  
... ...
win32/hsiview.exe
No preview for this file type