# HG changeset patch # User Chris Cannam # Date 1562077757 -3600 # Node ID 84c4ddb38415ad787e0360e28c4217bbab06b5fd # Parent 36ad3cdabf55eb1597576fec2ca52a09eb3a469b Further layer updates diff -r 36ad3cdabf55 -r 84c4ddb38415 view/AlignmentView.cpp --- a/view/AlignmentView.cpp Tue Jul 02 14:08:44 2019 +0100 +++ b/view/AlignmentView.cpp Tue Jul 02 15:29:17 2019 +0100 @@ -147,25 +147,26 @@ return getDefaultKeyFrames(); } - SparseOneDimensionalModel *m = nullptr; + ModelId m; // get the topmost such for (int i = 0; i < m_above->getLayerCount(); ++i) { if (qobject_cast(m_above->getLayer(i))) { - SparseOneDimensionalModel *mm = - qobject_cast - (m_above->getLayer(i)->getModel()); - if (mm) m = mm; + ModelId mm = m_above->getLayer(i)->getModel(); + if (ModelById::isa(mm)) { + m = mm; + } } } - if (!m) { + auto model = ModelById::getAs(m); + if (!model) { return getDefaultKeyFrames(); } vector keyFrames; - EventVector pp = m->getAllEvents(); + EventVector pp = model->getAllEvents(); for (EventVector::const_iterator pi = pp.begin(); pi != pp.end(); ++pi) { keyFrames.push_back(pi->getFrame()); } diff -r 36ad3cdabf55 -r 84c4ddb38415 view/Overview.cpp --- a/view/Overview.cpp Tue Jul 02 14:08:44 2019 +0100 +++ b/view/Overview.cpp Tue Jul 02 15:29:17 2019 +0100 @@ -60,9 +60,8 @@ if (m_modelTestTime.elapsed() < 1000) { for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { - if ((*i)->getModel() && - (!(*i)->getModel()->isOK() || - !(*i)->getModel()->isReady())) { + auto model = ModelById::get((*i)->getModel()); + if (model && (!model->isOK() || !model->isReady())) { return; } } diff -r 36ad3cdabf55 -r 84c4ddb38415 view/Pane.cpp --- a/view/Pane.cpp Tue Jul 02 14:08:44 2019 +0100 +++ b/view/Pane.cpp Tue Jul 02 15:29:17 2019 +0100 @@ -367,23 +367,27 @@ Layer *topLayer = getTopLayer(); bool haveSomeTimeXAxis = false; - const Model *waveformModel = nullptr; // just for reporting purposes - const Model *workModel = nullptr; + std::shared_ptr waveformModel; // just for reporting purposes + std::shared_ptr workModel; for (LayerList::iterator vi = m_layerStack.end(); vi != m_layerStack.begin(); ) { --vi; if (!haveSomeTimeXAxis && (*vi)->hasTimeXAxis()) { haveSomeTimeXAxis = true; } - if (dynamic_cast(*vi)) { - waveformModel = (*vi)->getModel(); - workModel = waveformModel; - } else { - Model *m = (*vi)->getModel(); - if (dynamic_cast(m)) { - workModel = m; - } else if (m && dynamic_cast(m->getSourceModel())) { - workModel = m->getSourceModel(); + auto model = ModelById::get((*vi)->getModel()); + + if (model) { + if (dynamic_cast(*vi)) { + waveformModel = model; + workModel = waveformModel; + } else { + if (std::dynamic_pointer_cast(model)) { + workModel = model; + } else if (auto wm = ModelById::getAs + (model->getSourceModel())) { + workModel = wm; + } } } @@ -393,7 +397,7 @@ // Block off left and right extents so we can see where the main model ends if (workModel && hasTopLayerTimeXAxis()) { - drawModelTimeExtents(r, paint, workModel); + drawModelTimeExtents(r, paint, *workModel); } // Crosshairs for mouse movement in measure mode @@ -448,7 +452,7 @@ sampleRate && m_manager && m_manager->shouldShowDuration()) { - drawDurationAndRate(r, waveformModel, sampleRate, paint); + drawDurationAndRate(r, *waveformModel, sampleRate, paint); } bool haveWorkTitle = false; @@ -456,14 +460,14 @@ if (workModel && m_manager && m_manager->shouldShowWorkTitle()) { - drawWorkTitle(r, paint, workModel); + drawWorkTitle(r, paint, *workModel); haveWorkTitle = true; } if (workModel && m_manager && m_manager->getAlignMode()) { - drawAlignmentStatus(r, paint, workModel, haveWorkTitle); + drawAlignmentStatus(r, paint, *workModel, haveWorkTitle); } if (m_manager && @@ -632,6 +636,11 @@ paint.save(); + // Qt 5.13 deprecates QFontMetrics::width(), but its suggested + // replacement (horizontalAdvance) was only added in Qt 5.11 + // which is too new for us +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + int tabStop = paint.fontMetrics().width(tr("Some lengthy prefix:")); @@ -750,7 +759,7 @@ } void -Pane::drawModelTimeExtents(QRect r, QPainter &paint, const Model *model) +Pane::drawModelTimeExtents(QRect r, QPainter &paint, const Model &model) { paint.save(); @@ -764,7 +773,7 @@ paint.setPen(Qt::white); } - sv_frame_t f0 = model->getStartFrame(); + sv_frame_t f0 = model.getStartFrame(); if (f0 > getStartFrame() && f0 < getEndFrame()) { int x0 = getXForFrame(f0); @@ -774,7 +783,7 @@ } } - sv_frame_t f1 = model->getEndFrame(); + sv_frame_t f1 = model.getEndFrame(); if (f1 > getStartFrame() && f1 < getEndFrame()) { int x1 = getXForFrame(f1); @@ -788,14 +797,14 @@ } void -Pane::drawAlignmentStatus(QRect r, QPainter &paint, const Model *model, +Pane::drawAlignmentStatus(QRect r, QPainter &paint, const Model &model, bool down) { - const Model *reference = model->getAlignmentReference(); + ModelId reference = model.getAlignmentReference(); /* if (!reference) { cerr << "Pane[" << this << "]::drawAlignmentStatus: No reference" << endl; - } else if (reference == model) { + } else if (reference == model.getId()) { cerr << "Pane[" << this << "]::drawAlignmentStatus: This is the reference model" << endl; } else { cerr << "Pane[" << this << "]::drawAlignmentStatus: This is not the reference" << endl; @@ -804,12 +813,12 @@ QString text; int completion = 100; - if (reference == model) { + if (reference == model.getId()) { text = tr("Reference"); - } else if (!reference) { + } else if (reference.isNone()) { text = tr("Unaligned"); } else { - completion = model->getAlignmentCompletion(); + completion = model.getAlignmentCompletion(); if (completion == 0) { text = tr("Unaligned"); } else if (completion < 100) { @@ -848,10 +857,10 @@ } void -Pane::drawWorkTitle(QRect r, QPainter &paint, const Model *model) +Pane::drawWorkTitle(QRect r, QPainter &paint, const Model &model) { - QString title = model->getTitle(); - QString maker = model->getMaker(); + QString title = model.getTitle(); + QString maker = model.getMaker(); //SVDEBUG << "Pane::drawWorkTitle: title=\"" << title//<< "\", maker=\"" << maker << "\"" << endl; if (title == "") return; @@ -1025,7 +1034,7 @@ } void -Pane::drawDurationAndRate(QRect r, const Model *waveformModel, +Pane::drawDurationAndRate(QRect r, const Model &waveformModel, sv_samplerate_t sampleRate, QPainter &paint) { int fontHeight = paint.fontMetrics().height(); @@ -1033,8 +1042,8 @@ if (r.y() + r.height() < height() - fontHeight - 6) return; - sv_samplerate_t modelRate = waveformModel->getSampleRate(); - sv_samplerate_t nativeRate = waveformModel->getNativeRate(); + sv_samplerate_t modelRate = waveformModel.getSampleRate(); + sv_samplerate_t nativeRate = waveformModel.getNativeRate(); sv_samplerate_t playbackRate = m_manager->getPlaybackSampleRate(); QString srNote = ""; @@ -1053,7 +1062,7 @@ } QString desc = tr("%1 / %2Hz%3") - .arg(RealTime::frame2RealTime(waveformModel->getEndFrame(), + .arg(RealTime::frame2RealTime(waveformModel.getEndFrame(), sampleRate) .toText(false).c_str()) .arg(nativeRate) diff -r 36ad3cdabf55 -r 84c4ddb38415 view/Pane.h --- a/view/Pane.h Tue Jul 02 14:08:44 2019 +0100 +++ b/view/Pane.h Tue Jul 02 15:29:17 2019 +0100 @@ -129,12 +129,12 @@ void drawVerticalScale(QRect r, Layer *, QPainter &); void drawFeatureDescription(Layer *, QPainter &); void drawCentreLine(sv_samplerate_t, QPainter &, bool omitLine); - void drawModelTimeExtents(QRect, QPainter &, const Model *); - void drawDurationAndRate(QRect, const Model *, sv_samplerate_t, QPainter &); - void drawWorkTitle(QRect, QPainter &, const Model *); + void drawModelTimeExtents(QRect, QPainter &, const Model &); + void drawDurationAndRate(QRect, const Model &, sv_samplerate_t, QPainter &); + void drawWorkTitle(QRect, QPainter &, const Model &); void drawLayerNames(QRect, QPainter &); void drawEditingSelection(QPainter &); - void drawAlignmentStatus(QRect, QPainter &, const Model *, bool down); + void drawAlignmentStatus(QRect, QPainter &, const Model &, bool down); virtual bool render(QPainter &paint, int x0, sv_frame_t f0, sv_frame_t f1) override; diff -r 36ad3cdabf55 -r 84c4ddb38415 view/View.cpp --- a/view/View.cpp Tue Jul 02 14:08:44 2019 +0100 +++ b/view/View.cpp Tue Jul 02 15:29:17 2019 +0100 @@ -632,9 +632,9 @@ if (widgetLight == light) { if (widgetLight) { - return widgetbg.light(); + return widgetbg.lighter(); } else { - return widgetbg.dark(); + return widgetbg.darker(); } } else if (light) return Qt::white; @@ -924,11 +924,20 @@ void View::modelChanged() { - QObject *obj = sender(); - #ifdef DEBUG_VIEW_WIDGET_PAINT cerr << "View(" << this << ")::modelChanged()" << endl; #endif + + QObject *obj = sender(); + + ModelId model; + if (Model *modelPtr = qobject_cast(obj)) { + model = modelPtr->getId(); + } else if (Layer *layerPtr = qobject_cast(obj)) { + model = layerPtr->getModel(); + } else { + return; + } // If the model that has changed is not used by any of the cached // layers, we won't need to recreate the cache @@ -939,7 +948,7 @@ LayerList scrollables = getScrollableBackLayers(false, discard); for (LayerList::const_iterator i = scrollables.begin(); i != scrollables.end(); ++i) { - if (*i == obj || (*i)->getModel() == obj) { + if ((*i)->getModel() == model) { recreate = true; break; } @@ -960,6 +969,15 @@ View::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame) { QObject *obj = sender(); + + ModelId model; + if (Model *modelPtr = qobject_cast(obj)) { + model = modelPtr->getId(); + } else if (Layer *layerPtr = qobject_cast(obj)) { + model = layerPtr->getModel(); + } else { + return; + } sv_frame_t myStartFrame = getStartFrame(); sv_frame_t myEndFrame = getEndFrame(); @@ -986,7 +1004,7 @@ LayerList scrollables = getScrollableBackLayers(false, discard); for (LayerList::const_iterator i = scrollables.begin(); i != scrollables.end(); ++i) { - if (*i == obj || (*i)->getModel() == obj) { + if ((*i)->getModel() == model) { recreate = true; break; } @@ -1270,11 +1288,13 @@ bool first = true; sv_frame_t startFrame = 0; - for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { - - if ((*i)->getModel() && (*i)->getModel()->isOK()) { - - sv_frame_t thisStartFrame = (*i)->getModel()->getStartFrame(); + for (Layer *layer: m_layerStack) { + + auto model = ModelById::get(layer->getModel()); + + if (model && model->isOK()) { + + sv_frame_t thisStartFrame = model->getStartFrame(); if (first || thisStartFrame < startFrame) { startFrame = thisStartFrame; @@ -1282,6 +1302,7 @@ first = false; } } + return startFrame; } @@ -1291,11 +1312,13 @@ bool first = true; sv_frame_t endFrame = 0; - for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { - - if ((*i)->getModel() && (*i)->getModel()->isOK()) { - - sv_frame_t thisEndFrame = (*i)->getModel()->getEndFrame(); + for (Layer *layer: m_layerStack) { + + auto model = ModelById::get(layer->getModel()); + + if (model && model->isOK()) { + + sv_frame_t thisEndFrame = model->getEndFrame(); if (first || thisEndFrame > endFrame) { endFrame = thisEndFrame; @@ -1317,11 +1340,15 @@ //!!! nah, this wants to always return the sr of the main model! - for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { - if ((*i)->getModel() && (*i)->getModel()->isOK()) { - return (*i)->getModel()->getSampleRate(); + for (Layer *layer: m_layerStack) { + + auto model = ModelById::get(layer->getModel()); + + if (model && model->isOK()) { + return model->getSampleRate(); } } + return 0; } @@ -1338,52 +1365,49 @@ continue; } - if (layer && layer->getModel()) { - Model *model = layer->getModel(); - models.insert(model); + if (layer && !layer->getModel().isNone()) { + models.insert(layer->getModel()); } } return models; } -Model * +ModelId View::getAligningModel() const { if (!m_manager || !m_manager->getAlignMode() || !m_manager->getPlaybackModel()) { - return nullptr; + return {}; } - Model *anyModel = nullptr; - Model *alignedModel = nullptr; - Model *goodModel = nullptr; - - for (LayerList::const_iterator i = m_layerStack.begin(); - i != m_layerStack.end(); ++i) { - - Layer *layer = *i; + ModelId anyModel; + ModelId alignedModel; + ModelId goodModel; + + for (auto layer: m_layerStack) { if (!layer) continue; if (dynamic_cast(layer)) continue; - Model *model = (*i)->getModel(); + auto model = ModelById::get(layer->getModel()); if (!model) continue; - anyModel = model; - - if (model->getAlignmentReference()) { - alignedModel = model; + anyModel = model->getId(); + + if (!model->getAlignmentReference().isNone()) { + alignedModel = model->getId(); if (layer->isLayerOpaque() || - dynamic_cast(model)) { - goodModel = model; + std::dynamic_pointer_cast + (model)) { + goodModel = model->getId(); } } } - if (goodModel) return goodModel; - else if (alignedModel) return alignedModel; + if (!goodModel.isNone()) return goodModel; + else if (!alignedModel.isNone()) return alignedModel; else return anyModel; } @@ -1391,7 +1415,7 @@ View::alignFromReference(sv_frame_t f) const { if (!m_manager || !m_manager->getAlignMode()) return f; - Model *aligningModel = getAligningModel(); + auto aligningModel = ModelById::get(getAligningModel()); if (!aligningModel) return f; return aligningModel->alignFromReference(f); } @@ -1400,7 +1424,7 @@ View::alignToReference(sv_frame_t f) const { if (!m_manager->getAlignMode()) return f; - Model *aligningModel = getAligningModel(); + auto aligningModel = ModelById::get(getAligningModel()); if (!aligningModel) return f; return aligningModel->alignToReference(f); } @@ -1412,7 +1436,7 @@ sv_frame_t pf = m_manager->getPlaybackFrame(); if (!m_manager->getAlignMode()) return pf; - Model *aligningModel = getAligningModel(); + auto aligningModel = ModelById::get(getAligningModel()); if (!aligningModel) return pf; sv_frame_t af = aligningModel->alignFromReference(pf); @@ -1727,9 +1751,11 @@ if (i->second.cancel == cancel) { Layer *layer = i->first; - Model *model = layer->getModel(); - +/*!!! Model *model = layer->getModel(); + + //!!! todo: restore this behaviour if (model) model->abandon(); +*/ } } } diff -r 36ad3cdabf55 -r 84c4ddb38415 view/View.h --- a/view/View.h Tue Jul 02 14:08:44 2019 +0100 +++ b/view/View.h Tue Jul 02 15:29:17 2019 +0100 @@ -27,6 +27,8 @@ #include "base/XmlExportable.h" #include "base/BaseTypes.h" +#include "data/model/Model.h" + // #define DEBUG_VIEW_WIDGET_PAINT 1 class Layer; @@ -381,11 +383,11 @@ double scalePenWidth(double width) const override; QPen scalePen(QPen pen) const override; - typedef std::set ModelSet; + typedef std::set ModelSet; ModelSet getModels(); //!!! - Model *getAligningModel() const; + ModelId getAligningModel() const; sv_frame_t alignFromReference(sv_frame_t) const; sv_frame_t alignToReference(sv_frame_t) const; sv_frame_t getAlignedPlaybackFrame() const;