# HG changeset patch # User Chris Cannam # Date 1302779586 -3600 # Node ID aa8117d79702e2d580c83cfa9d687565c72f6c72 # Parent 6b1eddfedfab9861bb60fa791c3b1a20519d306c Once again, avoid multiple entries in right-button Layer menu when more than one audio file loaded; fix to ensure correct model is picked up for Add Layer on this menu diff -r 6b1eddfedfab -r aa8117d79702 main/MainWindow.cpp --- a/main/MainWindow.cpp Tue Apr 12 10:54:25 2011 +0100 +++ b/main/MainWindow.cpp Thu Apr 14 12:13:06 2011 +0100 @@ -22,6 +22,7 @@ #include "view/PaneStack.h" #include "data/model/WaveFileModel.h" #include "data/model/SparseOneDimensionalModel.h" +#include "data/model/RangeSummarisableTimeValueModel.h" #include "data/model/NoteModel.h" #include "data/model/Labeller.h" #include "data/osc/OSCQueue.h" @@ -1196,7 +1197,11 @@ submenu->addAction(action); } - if (isDefault && menuType == layerMenuType) { + if (isDefault && menuType == layerMenuType && + mi == candidateModels.begin()) { + // only add for one model, one channel, one menu on + // right button -- the action itself will discover + // which model is the correct one (based on pane) action = new QAction(icon, mainText, this); action->setStatusTip(tipText); connect(action, SIGNAL(triggered()), @@ -3213,22 +3218,21 @@ Model *model = i->second.sourceModel; + cerr << "model = "<< model << endl; + if (!model) { if (type == LayerFactory::TimeRuler) { newLayer = m_document->createMainModelLayer(type); } else { // if model is unspecified and this is not a - // time-ruler layer, use the topmost plausible - // model from the current pane (if any) -- this is - // the case for right-button menu layer additions - for (int i = pane->getLayerCount(); i > 0; --i) { - Layer *el = pane->getLayer(i-1); - if (el && - el->getModel() && - dynamic_cast - (el->getModel())) { - model = el->getModel(); - } + // time-ruler layer, use any plausible model from + // the current pane -- this is the case for + // right-button menu layer additions + Pane::ModelSet ms = pane->getModels(); + foreach (Model *m, ms) { + RangeSummarisableTimeValueModel *r = + dynamic_cast(m); + if (r) model = m; } if (!model) model = getMainModel(); }