@@ -70,12 +70,12 @@ void QtSLiMGraphView_CustomPlot::freeData(void)
7070 for (std::vector<QColor> *colorbuffer : color_)
7171 delete colorbuffer;
7272
73- for (std::vector<double > *alphabuffer : alpha_)
74- delete alphabuffer;
75-
7673 for (std::vector<QColor> *borderbuffer : border_)
7774 delete borderbuffer;
7875
76+ for (std::vector<double > *alphabuffer : alpha_)
77+ delete alphabuffer;
78+
7979 for (std::vector<double > *lwdbuffer : line_width_)
8080 delete lwdbuffer;
8181
@@ -89,12 +89,13 @@ void QtSLiMGraphView_CustomPlot::freeData(void)
8989 labels_.clear ();
9090 symbol_.clear ();
9191 color_.clear ();
92- alpha_.clear ();
9392 border_.clear ();
93+ alpha_.clear ();
9494 line_width_.clear ();
9595 size_.clear ();
9696 xadj_.clear ();
9797 yadj_.clear ();
98+ image_.clear ();
9899
99100 // reset the legend state
100101 legend_added_ = false ;
@@ -385,6 +386,7 @@ void QtSLiMGraphView_CustomPlot::addABLineData(double *a_values, double *b_value
385386 size_.push_back (nullptr ); // unused for abline
386387 xadj_.push_back (-1 ); // unused for abline
387388 yadj_.push_back (-1 ); // unused for abline
389+ image_.push_back (QImage ()); // unused for abline
388390
389391 // rescaleAxesForDataRange(); // not needed for abline
390392 update ();
@@ -407,6 +409,7 @@ void QtSLiMGraphView_CustomPlot::addLineData(double *x_values, double *y_values,
407409 size_.push_back (nullptr ); // unused for lines
408410 xadj_.push_back (-1 ); // unused for lines
409411 yadj_.push_back (-1 ); // unused for lines
412+ image_.push_back (QImage ()); // unused for lines
410413
411414 rescaleAxesForDataRange ();
412415 update ();
@@ -429,6 +432,7 @@ void QtSLiMGraphView_CustomPlot::addPointData(double *x_values, double *y_values
429432 size_.push_back (size);
430433 xadj_.push_back (-1 ); // unused for points
431434 yadj_.push_back (-1 ); // unused for points
435+ image_.push_back (QImage ()); // unused for points
432436
433437 rescaleAxesForDataRange ();
434438 update ();
@@ -451,6 +455,29 @@ void QtSLiMGraphView_CustomPlot::addTextData(double *x_values, double *y_values,
451455 size_.push_back (size);
452456 xadj_.push_back (adj[0 ]);
453457 yadj_.push_back (adj[1 ]);
458+ image_.push_back (QImage ()); // unused for text
459+
460+ rescaleAxesForDataRange ();
461+ update ();
462+ }
463+
464+ void QtSLiMGraphView_CustomPlot::addImageData (double *x_values, double *y_values, int data_count,
465+ QImage image, std::vector<double > *alpha)
466+ {
467+ plot_type_.push_back (QtSLiM_CustomPlotType::kImage );
468+ xdata_.push_back (x_values);
469+ ydata_.push_back (y_values);
470+ labels_.push_back (nullptr ); // unused for image
471+ data_count_.push_back (data_count);
472+ symbol_.push_back (nullptr ); // unused for image
473+ color_.push_back (nullptr ); // unused for image
474+ border_.push_back (nullptr ); // unused for image
475+ alpha_.push_back (alpha);
476+ line_width_.push_back (nullptr ); // unused for image
477+ size_.push_back (nullptr ); // unused for image
478+ xadj_.push_back (-1 ); // unused for image
479+ yadj_.push_back (-1 ); // unused for image
480+ image_.push_back (image);
454481
455482 rescaleAxesForDataRange ();
456483 update ();
@@ -532,6 +559,9 @@ void QtSLiMGraphView_CustomPlot::drawGraph(QPainter &painter, QRect interiorRect
532559 case QtSLiM_CustomPlotType::kVLines :
533560 drawVLines (painter, interiorRect, i);
534561 break ;
562+ case QtSLiM_CustomPlotType::kImage :
563+ drawImage (painter, interiorRect, i);
564+ break ;
535565 }
536566 }
537567}
@@ -850,6 +880,39 @@ void QtSLiMGraphView_CustomPlot::drawText(QPainter &painter, QRect interiorRect,
850880 }
851881}
852882
883+ void QtSLiMGraphView_CustomPlot::drawImage (QPainter &painter, QRect interiorRect, int dataIndex)
884+ {
885+ double *xdata = xdata_[dataIndex];
886+ double *ydata = ydata_[dataIndex];
887+ std::vector<double > &imageAlphas = *alpha_[dataIndex];
888+ double alpha = imageAlphas[0 ];
889+
890+ double user_x1 = xdata[0 ], user_y1 = ydata[0 ];
891+ double user_x2 = xdata[1 ], user_y2 = ydata[1 ];
892+
893+ double x1 = plotToDeviceX (user_x1, interiorRect);
894+ double y1 = plotToDeviceY (user_y1, interiorRect);
895+ double x2 = plotToDeviceX (user_x2, interiorRect);
896+ double y2 = plotToDeviceY (user_y2, interiorRect);
897+
898+ // the coordinates are absolute, but Qt wants them as width/height
899+ double target_width = x2 - x1;
900+ double target_height = y2 - y1;
901+
902+ // get the image data
903+ const QImage &image = image_[dataIndex];
904+
905+ QRectF target (x1, y1, target_width, target_height);
906+
907+ if (alpha != 1.0 )
908+ painter.setOpacity (alpha);
909+
910+ painter.drawImage (target, image);
911+
912+ if (alpha != 1.0 )
913+ painter.setOpacity (1.0 );
914+ }
915+
853916
854917
855918
0 commit comments