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
@@ -13,8 +13,5 @@ int main(int argc, char *argv[]) @@ -13,8 +13,5 @@ int main(int argc, char *argv[])
13 w.loadImage(fileName); 13 w.loadImage(fileName);
14 w.show(); 14 w.show();
15 15
16 - //SpectrumWindow s(&w);  
17 - //s.show();  
18 -  
19 return a.exec(); 16 return a.exec();
20 } 17 }
spectrumwindow.cpp
@@ -15,9 +15,6 @@ SpectrumWindow::SpectrumWindow(QWidget *parent) : @@ -15,9 +15,6 @@ SpectrumWindow::SpectrumWindow(QWidget *parent) :
15 //create a line for the current band 15 //create a line for the current band
16 bandline = new QCPItemStraightLine(ui->spectrumPlot); 16 bandline = new QCPItemStraightLine(ui->spectrumPlot);
17 ui->spectrumPlot->addItem(bandline); 17 ui->spectrumPlot->addItem(bandline);
18 -  
19 -  
20 -  
21 } 18 }
22 19
23 SpectrumWindow::~SpectrumWindow() 20 SpectrumWindow::~SpectrumWindow()
@@ -39,11 +36,13 @@ void SpectrumWindow::plotSpectrum(QVector<double> x, QVector<double> y){ @@ -39,11 +36,13 @@ void SpectrumWindow::plotSpectrum(QVector<double> x, QVector<double> y){
39 ui->spectrumPlot->yAxis->setRange(y_min, y_max); 36 ui->spectrumPlot->yAxis->setRange(y_min, y_max);
40 37
41 //add the graph to the plot 38 //add the graph to the plot
42 - ui->spectrumPlot->addGraph();  
43 ui->spectrumPlot->graph(0)->setData(x, y); 39 ui->spectrumPlot->graph(0)->setData(x, y);
44 40
45 //redraw the plot 41 //redraw the plot
46 ui->spectrumPlot->replot(); 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 void SpectrumWindow::initPlot(double x_min, double x_max, double y_min, double y_max, QString x_title, QString y_title){ 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,6 +53,9 @@ void SpectrumWindow::initPlot(double x_min, double x_max, double y_min, double y
54 ui->spectrumPlot->xAxis->setRange(x_min, x_max); 53 ui->spectrumPlot->xAxis->setRange(x_min, x_max);
55 ui->spectrumPlot->yAxis->setRange(y_min, y_max); 54 ui->spectrumPlot->yAxis->setRange(y_min, y_max);
56 55
  56 + //add a graph to the plot
  57 + ui->spectrumPlot->addGraph();
  58 +
57 //set the initial position of the band line 59 //set the initial position of the band line
58 double xmid = (x_max + x_min) / 2; 60 double xmid = (x_max + x_min) / 2;
59 std::cout<<"xmid: "<<xmid<<std::endl; 61 std::cout<<"xmid: "<<xmid<<std::endl;
@@ -78,7 +80,7 @@ void SpectrumWindow::resizeEvent(QResizeEvent* event){ @@ -78,7 +80,7 @@ void SpectrumWindow::resizeEvent(QResizeEvent* event){
78 bool SpectrumWindow::eventFilter(QObject *target, QEvent *event) 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 QMouseEvent *_mouseEvent = static_cast<QMouseEvent*>(event); 85 QMouseEvent *_mouseEvent = static_cast<QMouseEvent*>(event);
84 86
@@ -93,8 +95,10 @@ bool SpectrumWindow::eventFilter(QObject *target, QEvent *event) @@ -93,8 +95,10 @@ bool SpectrumWindow::eventFilter(QObject *target, QEvent *event)
93 //set the position of the band line 95 //set the position of the band line
94 bandline->point1->setCoords(x, 0); 96 bandline->point1->setCoords(x, 0);
95 bandline->point2->setCoords(x, 1); 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 QMouseEvent *_mouseEvent = static_cast<QMouseEvent*>(event); 103 QMouseEvent *_mouseEvent = static_cast<QMouseEvent*>(event);
100 104
@@ -112,6 +116,10 @@ bool SpectrumWindow::eventFilter(QObject *target, QEvent *event) @@ -112,6 +116,10 @@ bool SpectrumWindow::eventFilter(QObject *target, QEvent *event)
112 //set the position of the band line 116 //set the position of the band line
113 bandline->point1->setCoords(x, 0); 117 bandline->point1->setCoords(x, 0);
114 bandline->point2->setCoords(x, 1); 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