3535#include < QFileDialog>
3636#include < QStandardPaths>
3737#include < QLabel>
38+ #include < QMessageBox>
3839#include < QDebug>
3940
4041#include < vector>
5152// This class method runs a plot options dialog, and then produces a haplotype plot with a progress panel as it is being constructed
5253void QtSLiMHaplotypeManager::CreateHaplotypePlot (QtSLiMChromosomeWidgetController *controller)
5354{
55+ QtSLiMWindow *slimWindow = controller->slimWindow ();
56+
57+ if (!slimWindow)
58+ return ;
59+
5460 Species *displaySpecies = controller->focalDisplaySpecies ();
61+
62+ if (!displaySpecies)
63+ {
64+ QMessageBox messageBox (slimWindow);
65+ messageBox.setText (" Haplotype Plot" );
66+ messageBox.setInformativeText (" A single species must be chosen to create a haplotype plot; the plot will be based upon the selected species." );
67+ messageBox.setIcon (QMessageBox::Warning);
68+ messageBox.setWindowModality (Qt::WindowModal);
69+ messageBox.exec ();
70+ return ;
71+ }
72+
73+ // We need a single chromosome to work with; QtSLiMHaplotypeManager creates a haplotype
74+ // plot for one chromosome, which makes sense since haplosomes assort independently.
75+ // If we can't get a single chromosome, then we tell the user to select a chromosome.
76+ Chromosome *chromosome = slimWindow->focalChromosome ();
77+
78+ if (!chromosome)
79+ {
80+ QMessageBox messageBox (slimWindow);
81+ messageBox.setText (" Haplotype Plot" );
82+ messageBox.setInformativeText (" A single chromosome must be chosen to create a haplotype plot; the plot will be based upon the selected chromosome." );
83+ messageBox.setIcon (QMessageBox::Warning);
84+ messageBox.setWindowModality (Qt::WindowModal);
85+ messageBox.exec ();
86+ return ;
87+ }
88+
5589 QtSLiMHaplotypeOptions optionsPanel (controller->slimWindow ());
5690
5791 int result = optionsPanel.exec ();
@@ -63,9 +97,6 @@ void QtSLiMHaplotypeManager::CreateHaplotypePlot(QtSLiMChromosomeWidgetControlle
6397 QtSLiMHaplotypeManager::ClusteringOptimization clusteringOptimization = optionsPanel.clusteringOptimization ();
6498
6599 // First generate the haplotype plot data, with a progress panel
66- // FIXME MULTICHROM this code path should work with all of the chromosomes, probably...
67- Chromosome *chromosome = &displaySpecies->TheChromosome ();
68-
69100 QtSLiMHaplotypeManager *haplotypeManager = new QtSLiMHaplotypeManager (nullptr , clusteringMethod, clusteringOptimization, controller,
70101 displaySpecies, chromosome, QtSLiMRange (0 ,0 ), haplosomeSampleSize, true );
71102
@@ -214,6 +245,9 @@ QtSLiMHaplotypeManager::QtSLiMHaplotypeManager(QObject *p_parent, ClusteringMeth
214245
215246 title.append (QString (" , tick %1" ).arg (community->Tick ()));
216247
248+ if (displaySpecies->Chromosomes ().size () > 1 )
249+ title.append (QString (" , chromosome '%2'" ).arg (QString::fromStdString (chromosome->Symbol ())));
250+
217251 titleString = title;
218252 subpopCount = static_cast <int >(selected_subpops.size ());
219253
0 commit comments