changeset 36:935a2419a77c

* Refactor Layer classes so as no longer to store a single View pointer; instead they need to be able to draw themselves on any View on demand. Layers with caches (e.g. spectrogram) will need to be further refactored so as to maintain a per-View cache * Begin refactoring MainWindow by pulling out the document stuff (set of layers, models etc) into a Document class. Not yet in use. This revision is fairly unstable.
author Chris Cannam
date Thu, 02 Mar 2006 16:58:49 +0000
parents 0164c8d3023b
children 838652cc31e6
files base/Layer.cpp base/Layer.h base/Selection.cpp base/Selection.h base/View.cpp base/View.h base/ViewManager.cpp base/ViewManager.h
diffstat 8 files changed, 55 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/base/Layer.cpp	Wed Mar 01 18:13:01 2006 +0000
+++ b/base/Layer.cpp	Thu Mar 02 16:58:49 2006 +0000
@@ -15,10 +15,10 @@
 #include "layer/LayerFactory.h" //!!! shouldn't be including this here -- does that suggest we need to move this into layer/ ?
 #include "PlayParameterRepository.h"
 
-Layer::Layer(View *w) :
+Layer::Layer() :
     m_dormant(false)
 {
-    m_view = w;
+//    m_view = w;
 
     // Subclass must call this:
 //    w->addLayer(this);
@@ -26,7 +26,7 @@
 
 Layer::~Layer()
 {
-    m_view->removeLayer(this);
+//    m_view->removeLayer(this);
 }
 
 QString
@@ -42,7 +42,7 @@
     QObject::setObjectName(name);
     emit layerNameChanged();
 }
-
+/*
 int
 Layer::getXForFrame(long frame) const
 {
@@ -56,7 +56,7 @@
     if (m_view) return m_view->getFrameForX(x);
     else return 0;
 }
-
+*/
 QString
 Layer::toXmlString(QString indent, QString extraAttributes) const
 {
@@ -87,9 +87,9 @@
 }
 
 void
-Layer::showLayer(bool show)
+Layer::showLayer(View *view, bool show)
 {
-    setLayerDormant(!show);
+    setLayerDormant(view, !show);
     emit layerParametersChanged();
 }
 
--- a/base/Layer.h	Wed Mar 01 18:13:01 2006 +0000
+++ b/base/Layer.h	Thu Mar 02 16:58:49 2006 +0000
@@ -37,13 +37,12 @@
     Q_OBJECT
 
 public:
-    Layer(View *w);
+    Layer();
     virtual ~Layer();
 
     virtual const Model *getModel() const = 0;
-    virtual const View *getView() const { return m_view; }
     virtual const ZoomConstraint *getZoomConstraint() const { return 0; }
-    virtual void paint(QPainter &, QRect) const = 0;   
+    virtual void paint(View *, QPainter &, QRect) const = 0;   
 
     enum VerticalPosition {
 	PositionTop, PositionMiddle, PositionBottom
@@ -61,10 +60,10 @@
 	return objectName();
     }
 
-    virtual int getVerticalScaleWidth(QPainter &) const { return 0; }
-    virtual void paintVerticalScale(QPainter &, QRect) const { }
+    virtual int getVerticalScaleWidth(View *, QPainter &) const { return 0; }
+    virtual void paintVerticalScale(View *, QPainter &, QRect) const { }
 
-    virtual QString getFeatureDescription(QPoint &) const {
+    virtual QString getFeatureDescription(View *, QPoint &) const {
 	return "";
     }
 
@@ -99,7 +98,8 @@
      * available.  Also return the resolution of the model in this
      * layer in sample frames.
      */
-    virtual bool snapToFeatureFrame(int &frame,
+    virtual bool snapToFeatureFrame(View *v,
+				    int &frame,
 				    size_t &resolution,
 				    SnapType snap) const {
 	resolution = 1;
@@ -111,15 +111,15 @@
     // Layer needs to get actual mouse events, I guess.  Draw mode is
     // probably the easier.
 
-    virtual void drawStart(QMouseEvent *) { }
-    virtual void drawDrag(QMouseEvent *) { }
-    virtual void drawEnd(QMouseEvent *) { }
+    virtual void drawStart(View *, QMouseEvent *) { }
+    virtual void drawDrag(View *, QMouseEvent *) { }
+    virtual void drawEnd(View *, QMouseEvent *) { }
 
-    virtual void editStart(QMouseEvent *) { }
-    virtual void editDrag(QMouseEvent *) { }
-    virtual void editEnd(QMouseEvent *) { }
+    virtual void editStart(View *, QMouseEvent *) { }
+    virtual void editDrag(View *, QMouseEvent *) { }
+    virtual void editEnd(View *, QMouseEvent *) { }
 
-    virtual void editOpen(QMouseEvent *) { } // on double-click
+    virtual void editOpen(View *, QMouseEvent *) { } // on double-click
 
     virtual void moveSelection(Selection s, size_t newStartFrame) { }
     virtual void resizeSelection(Selection s, Selection newSize) { }
@@ -134,16 +134,16 @@
     // in place?  Probably the dialog is easier.
 
     /**
-     * This should return true if the view can safely be scrolled
-     * automatically by the widget (simply copying the existing data
+     * This should return true if the layer can safely be scrolled
+     * automatically by a given view (simply copying the existing data
      * and then refreshing the exposed area) without altering its
-     * meaning.  For the widget as a whole this is usually not
+     * meaning.  For the view widget as a whole this is usually not
      * possible because of invariant (non-scrolling) material
      * displayed over the top, but the widget may be able to optimise
      * scrolling better if it is known that individual views can be
      * scrolled safely in this way.
      */
-    virtual bool isLayerScrollable() const { return true; }
+    virtual bool isLayerScrollable(const View *) const { return true; }
 
     /**
      * This should return true if the layer completely obscures any
@@ -178,12 +178,12 @@
      * Return the pixel x-coordinate corresponding to a given sample
      * frame (which may be negative).
      */
-    int getXForFrame(long frame) const;
+//    int getXForFrame(long frame) const;
 
     /**
      * Return the closest frame to the given pixel x-coordinate.
      */
-    long getFrameForX(int x) const;
+//    long getFrameForX(int x) const;
 
     /**
      * Convert the layer's data (though not those of the model it
@@ -211,17 +211,20 @@
      * not need to remember not to draw itself; the view will handle
      * that.
      */
-    virtual void setLayerDormant(bool dormant) { m_dormant = dormant; }
+    //!!! update for multiview
+    virtual void setLayerDormant(const View *, bool dormant) { m_dormant = dormant; }
 
     /**
      * Return whether the layer is dormant (i.e. hidden).
      */
-    virtual bool isLayerDormant() const { return m_dormant; }
+    //!!! update for multiview
+    virtual bool isLayerDormant(const View *) const { return m_dormant; }
 
     virtual PlayParameters *getPlayParameters();
 
 public slots:
-    void showLayer(bool show);
+    //!!! update for multiview
+    void showLayer(View *, bool show);
 
 signals:
     void modelChanged();
@@ -233,7 +236,7 @@
     void layerNameChanged();
 
 protected:
-    View *m_view;
+//    View *m_view;
     bool m_dormant;
 };
 
--- a/base/Selection.cpp	Wed Mar 01 18:13:01 2006 +0000
+++ b/base/Selection.cpp	Thu Mar 02 16:58:49 2006 +0000
@@ -167,7 +167,7 @@
 }
 
 Selection
-MultiSelection::getContainingSelection(size_t frame, bool defaultToFollowing)
+MultiSelection::getContainingSelection(size_t frame, bool defaultToFollowing) const
 {
     // This scales very badly with the number of selections, but it's
     // more efficient for very small numbers of selections than a more
--- a/base/Selection.h	Wed Mar 01 18:13:01 2006 +0000
+++ b/base/Selection.h	Thu Mar 02 16:58:49 2006 +0000
@@ -55,7 +55,7 @@
      * selected area, return the next selection after the given frame.
      * Return the empty selection if no appropriate selection is found.
      */
-    Selection getContainingSelection(size_t frame, bool defaultToFollowing);
+    Selection getContainingSelection(size_t frame, bool defaultToFollowing) const;
 
 protected:
     SelectionList m_selections;
--- a/base/View.cpp	Wed Mar 01 18:13:01 2006 +0000
+++ b/base/View.cpp	Thu Mar 02 16:58:49 2006 +0000
@@ -52,6 +52,8 @@
 
 View::~View()
 {
+    //!!! will want to _not_ delete layers
+
     m_deleting = true;
 
     for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
@@ -411,6 +413,12 @@
     }
 }
 
+const Layer *
+View::getSelectedLayer() const
+{
+    return const_cast<const Layer *>(const_cast<View *>(this)->getSelectedLayer());
+}
+
 void
 View::setViewManager(ViewManager *manager)
 {
@@ -789,7 +797,7 @@
 {
     // True iff all views are scrollable
     for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
-	if (!(*i)->isLayerScrollable()) return false;
+	if (!(*i)->isLayerScrollable(this)) return false;
     }
     return true;
 }
@@ -801,8 +809,8 @@
 
     LayerList scrollables;
     for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
-	if ((*i)->isLayerDormant()) continue;
-	if ((*i)->isLayerScrollable()) scrollables.push_back(*i);
+	if ((*i)->isLayerDormant(this)) continue;
+	if ((*i)->isLayerScrollable(this)) scrollables.push_back(*i);
 	else {
 	    if (testChanged && scrollables != m_lastScrollableBackLayers) {
 		m_lastScrollableBackLayers = scrollables;
@@ -840,7 +848,7 @@
 
     size_t count = 0;
     for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
-	if ((*i)->isLayerDormant()) continue;
+	if ((*i)->isLayerDormant(this)) continue;
 	if (count < scrollables.size()) {
 	    ++count;
 	    continue;
@@ -1148,7 +1156,7 @@
 	for (LayerList::iterator i = scrollables.begin(); i != scrollables.end(); ++i) {
 	    paint.setRenderHint(QPainter::Antialiasing, false);
 	    paint.save();
-	    (*i)->paint(paint, cacheRect);
+	    (*i)->paint(this, paint, cacheRect);
 	    paint.restore();
 	}
 
@@ -1192,7 +1200,7 @@
     paint.setBrush(Qt::NoBrush);
 	
     for (LayerList::iterator i = nonScrollables.begin(); i != nonScrollables.end(); ++i) {
-	(*i)->paint(paint, nonCacheRect);
+	(*i)->paint(this, paint, nonCacheRect);
     }
 	
     paint.end();
--- a/base/View.h	Wed Mar 01 18:13:01 2006 +0000
+++ b/base/View.h	Thu Mar 02 16:58:49 2006 +0000
@@ -155,6 +155,7 @@
      * will also return 0 if there are no layers.
      */
     virtual Layer *getSelectedLayer();
+    virtual const Layer *getSelectedLayer() const;
 
     virtual void setViewManager(ViewManager *m);
 
@@ -167,10 +168,10 @@
     virtual void setLightBackground(bool lb) { m_lightBackground = lb; }
     virtual bool hasLightBackground() const { return m_lightBackground; }
 
-    virtual bool shouldIlluminateLocalFeatures(const Layer *, QPoint &) {
+    virtual bool shouldIlluminateLocalFeatures(const Layer *, QPoint &) const {
 	return false;
     }
-    virtual bool shouldIlluminateLocalSelection(QPoint &, bool &, bool &) {
+    virtual bool shouldIlluminateLocalSelection(QPoint &, bool &, bool &) const {
 	return false;
     }
 
--- a/base/ViewManager.cpp	Wed Mar 01 18:13:01 2006 +0000
+++ b/base/ViewManager.cpp	Thu Mar 02 16:58:49 2006 +0000
@@ -145,7 +145,7 @@
 }
 
 Selection
-ViewManager::getContainingSelection(size_t frame, bool defaultToFollowing)
+ViewManager::getContainingSelection(size_t frame, bool defaultToFollowing) const
 {
     return m_selections.getContainingSelection(frame, defaultToFollowing);
 }
--- a/base/ViewManager.h	Wed Mar 01 18:13:01 2006 +0000
+++ b/base/ViewManager.h	Thu Mar 02 16:58:49 2006 +0000
@@ -66,7 +66,7 @@
      * selected area, return the next selection after the given frame.
      * Return the empty selection if no appropriate selection is found.
      */
-    Selection getContainingSelection(size_t frame, bool defaultToFollowing);
+    Selection getContainingSelection(size_t frame, bool defaultToFollowing) const;
 
     enum ToolMode {
 	NavigateMode,