Chris@127
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@127
|
2
|
Chris@127
|
3 /*
|
Chris@127
|
4 Sonic Visualiser
|
Chris@127
|
5 An audio file viewer and annotation editor.
|
Chris@127
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@182
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
Chris@127
|
8
|
Chris@127
|
9 This program is free software; you can redistribute it and/or
|
Chris@127
|
10 modify it under the terms of the GNU General Public License as
|
Chris@127
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@127
|
12 License, or (at your option) any later version. See the file
|
Chris@127
|
13 COPYING included with this distribution for more information.
|
Chris@127
|
14 */
|
Chris@127
|
15
|
Chris@1407
|
16 #ifndef SV_LAYER_H
|
Chris@1407
|
17 #define SV_LAYER_H
|
Chris@127
|
18
|
Chris@128
|
19 #include "base/PropertyContainer.h"
|
Chris@128
|
20 #include "base/XmlExportable.h"
|
Chris@128
|
21 #include "base/Selection.h"
|
Chris@127
|
22
|
Chris@1469
|
23 #include "data/model/Model.h"
|
Chris@1469
|
24
|
Chris@376
|
25 #include "widgets/CommandHistory.h"
|
Chris@376
|
26
|
Chris@523
|
27 #include "system/System.h"
|
Chris@523
|
28
|
Chris@127
|
29 #include <QObject>
|
Chris@127
|
30 #include <QRect>
|
Chris@127
|
31 #include <QXmlAttributes>
|
Chris@131
|
32 #include <QMutex>
|
Chris@299
|
33 #include <QPixmap>
|
Chris@127
|
34
|
Chris@127
|
35 #include <map>
|
Chris@268
|
36 #include <set>
|
Chris@127
|
37
|
Chris@552
|
38 #include <iostream>
|
Chris@552
|
39
|
Chris@127
|
40 class ZoomConstraint;
|
Chris@127
|
41 class QPainter;
|
Chris@127
|
42 class View;
|
Chris@916
|
43 class LayerGeometryProvider;
|
Chris@127
|
44 class QMouseEvent;
|
Chris@127
|
45 class Clipboard;
|
Chris@187
|
46 class RangeMapper;
|
Chris@127
|
47
|
Chris@127
|
48 /**
|
Chris@127
|
49 * The base class for visual representations of the data found in a
|
Chris@127
|
50 * Model. Layers are expected to be able to draw themselves onto a
|
Chris@127
|
51 * View, and may also be editable.
|
Chris@127
|
52 */
|
Chris@127
|
53
|
Chris@127
|
54 class Layer : public PropertyContainer,
|
Chris@1266
|
55 public XmlExportable
|
Chris@127
|
56 {
|
Chris@127
|
57 Q_OBJECT
|
Chris@127
|
58
|
Chris@127
|
59 public:
|
Chris@127
|
60 Layer();
|
Chris@127
|
61 virtual ~Layer();
|
Chris@127
|
62
|
Chris@1469
|
63 /**
|
Chris@1469
|
64 * Return the ID of the model represented in this layer.
|
Chris@1469
|
65 */
|
Chris@1469
|
66 virtual ModelId getModel() const = 0;
|
Chris@1489
|
67
|
Chris@1489
|
68 /**
|
Chris@1489
|
69 * Return the ID of the source model for the model represented in
|
Chris@1489
|
70 * this layer. If the model has no other source, or there is no
|
Chris@1489
|
71 * model here, return None.
|
Chris@1489
|
72 */
|
Chris@1489
|
73 ModelId getSourceModel() const;
|
Chris@1554
|
74
|
Chris@1554
|
75 /**
|
Chris@1554
|
76 * Return the ID of a model representing the contents of this
|
Chris@1554
|
77 * layer in a form suitable for export to a tabular file format
|
Chris@1554
|
78 * such as CSV.
|
Chris@1554
|
79 *
|
Chris@1554
|
80 * In most cases this will be the same as returned by
|
Chris@1554
|
81 * getModel(). The exceptions are those layers such as
|
Chris@1554
|
82 * SpectrogramLayer, that are "only" alternative views of
|
Chris@1554
|
83 * time-domain sample data. For such layers, getModel() will
|
Chris@1554
|
84 * return the backing time-domain data, for example as a
|
Chris@1554
|
85 * ReadOnlyWaveFileModel; but getExportModel() will return a
|
Chris@1554
|
86 * model, possibly "local to" the layer, which adapts this into
|
Chris@1554
|
87 * the form shown in the layer for a given view so that the export
|
Chris@1554
|
88 * matches the layer's visible contents.
|
Chris@1554
|
89 *
|
Chris@1554
|
90 * Because this is supposed to match the contents of the view
|
Chris@1554
|
91 * rather than the backing model, it's necessary to pass in a view
|
Chris@1554
|
92 * (or LayerGeometryProvider) so that the layer can retrieve its
|
Chris@1554
|
93 * vertical extents for export.
|
Chris@1554
|
94 */
|
Chris@1554
|
95 virtual ModelId getExportModel(LayerGeometryProvider *) const {
|
Chris@1554
|
96 return getModel();
|
Chris@1554
|
97 }
|
Chris@947
|
98
|
Chris@137
|
99 /**
|
Chris@137
|
100 * Return a zoom constraint object defining the supported zoom
|
Chris@137
|
101 * levels for this layer. If this returns zero, the layer will
|
Chris@137
|
102 * support any integer zoom level.
|
Chris@137
|
103 */
|
Chris@127
|
104 virtual const ZoomConstraint *getZoomConstraint() const { return 0; }
|
Chris@137
|
105
|
Chris@137
|
106 /**
|
Chris@137
|
107 * Return true if this layer can handle zoom levels other than
|
Chris@137
|
108 * those supported by its zoom constraint (presumably less
|
Chris@137
|
109 * efficiently or accurately than the officially supported zoom
|
Chris@137
|
110 * levels). If true, the layer will unenthusistically accept any
|
Chris@137
|
111 * integer zoom level from 1 to the maximum returned by its zoom
|
Chris@137
|
112 * constraint.
|
Chris@137
|
113 */
|
Chris@137
|
114 virtual bool supportsOtherZoomLevels() const { return true; }
|
Chris@137
|
115
|
Chris@389
|
116 /**
|
Chris@389
|
117 * Paint the given rectangle of this layer onto the given view
|
Chris@389
|
118 * using the given painter, superimposing it on top of any
|
Chris@916
|
119 * existing material in that view. The LayerGeometryProvider (an
|
Chris@916
|
120 * interface implemented by View) is provided here because it is
|
Chris@916
|
121 * possible for one layer to exist in more than one view, so the
|
Chris@916
|
122 * dimensions of the view may vary from one paint call to another
|
Chris@916
|
123 * (without any view having been resized).
|
Chris@389
|
124 */
|
Chris@916
|
125 virtual void paint(LayerGeometryProvider *, QPainter &, QRect) const = 0;
|
Chris@127
|
126
|
Chris@389
|
127 /**
|
Chris@389
|
128 * Enable or disable synchronous painting. If synchronous
|
Chris@389
|
129 * painting is enabled, a call to paint() must complete painting
|
Chris@389
|
130 * the entire rectangle before it returns. If synchronous
|
Chris@389
|
131 * painting is disabled (which should be the default), the paint()
|
Chris@389
|
132 * call may defer painting some regions if data is not yet
|
Chris@389
|
133 * available, by calling back on its view to schedule another
|
Chris@389
|
134 * update. Synchronous painting is necessary when rendering to an
|
Chris@389
|
135 * image. Simple layer types will always paint synchronously, and
|
Chris@389
|
136 * so may ignore this.
|
Chris@389
|
137 */
|
Chris@389
|
138 virtual void setSynchronousPainting(bool /* synchronous */) { }
|
Chris@389
|
139
|
Chris@127
|
140 enum VerticalPosition {
|
Chris@1266
|
141 PositionTop, PositionMiddle, PositionBottom
|
Chris@127
|
142 };
|
Chris@127
|
143 virtual VerticalPosition getPreferredTimeRulerPosition() const {
|
Chris@1266
|
144 return PositionMiddle;
|
Chris@127
|
145 }
|
Chris@127
|
146 virtual VerticalPosition getPreferredFrameCountPosition() const {
|
Chris@1266
|
147 return PositionBottom;
|
Chris@127
|
148 }
|
Chris@224
|
149 virtual bool hasLightBackground() const {
|
Chris@224
|
150 return true;
|
Chris@224
|
151 }
|
Chris@127
|
152
|
Chris@1406
|
153 QString getPropertyContainerIconName() const override;
|
Chris@127
|
154
|
Chris@1406
|
155 QString getPropertyContainerName() const override {
|
Chris@363
|
156 if (m_presentationName != "") return m_presentationName;
|
Chris@1266
|
157 else return objectName();
|
Chris@127
|
158 }
|
Chris@127
|
159
|
Chris@363
|
160 virtual void setPresentationName(QString name);
|
Chris@363
|
161
|
Chris@127
|
162 virtual QString getLayerPresentationName() const;
|
Chris@299
|
163 virtual QPixmap getLayerPresentationPixmap(QSize) const { return QPixmap(); }
|
Chris@127
|
164
|
Chris@916
|
165 virtual int getVerticalScaleWidth(LayerGeometryProvider *, bool detailed,
|
Chris@607
|
166 QPainter &) const = 0;
|
Chris@607
|
167
|
Chris@916
|
168 virtual void paintVerticalScale(LayerGeometryProvider *, bool /* detailed */,
|
Chris@607
|
169 QPainter &, QRect) const { }
|
Chris@127
|
170
|
Chris@1390
|
171 virtual int getHorizontalScaleHeight(LayerGeometryProvider *, QPainter &) const { return 0; }
|
Chris@1390
|
172
|
Chris@916
|
173 virtual bool getCrosshairExtents(LayerGeometryProvider *, QPainter &, QPoint /* cursorPos */,
|
Chris@127
|
174 std::vector<QRect> &) const {
|
Chris@127
|
175 return false;
|
Chris@127
|
176 }
|
Chris@916
|
177 virtual void paintCrosshairs(LayerGeometryProvider *, QPainter &, QPoint) const { }
|
Chris@127
|
178
|
Chris@916
|
179 virtual void paintMeasurementRects(LayerGeometryProvider *, QPainter &,
|
Chris@272
|
180 bool showFocus, QPoint focusPoint) const;
|
Chris@272
|
181
|
Chris@916
|
182 virtual bool nearestMeasurementRectChanged(LayerGeometryProvider *, QPoint prev,
|
Chris@272
|
183 QPoint now) const;
|
Chris@267
|
184
|
Chris@916
|
185 virtual QString getFeatureDescription(LayerGeometryProvider *, QPoint &) const {
|
Chris@1266
|
186 return "";
|
Chris@127
|
187 }
|
Chris@127
|
188
|
Chris@909
|
189 virtual QString getLabelPreceding(sv_frame_t /* frame */) const {
|
Chris@552
|
190 return "";
|
Chris@552
|
191 }
|
Chris@552
|
192
|
Chris@127
|
193 enum SnapType {
|
Chris@1266
|
194 SnapLeft,
|
Chris@1266
|
195 SnapRight,
|
Chris@1266
|
196 SnapNeighbouring
|
Chris@127
|
197 };
|
Chris@127
|
198
|
Chris@127
|
199 /**
|
Chris@127
|
200 * Adjust the given frame to snap to the nearest feature, if
|
Chris@127
|
201 * possible.
|
Chris@127
|
202 *
|
Chris@127
|
203 * If snap is SnapLeft or SnapRight, adjust the frame to match
|
Chris@127
|
204 * that of the nearest feature in the given direction regardless
|
Chris@1431
|
205 * of how far away it is. If snap is SnapNeighbouring, adjust the
|
Chris@1431
|
206 * frame to that of the nearest feature in either direction if it
|
Chris@1431
|
207 * is close, and leave it alone (returning false) otherwise.
|
Chris@1431
|
208 * SnapNeighbouring should always choose the same feature that
|
Chris@1431
|
209 * would be used in an editing operation through calls to
|
Chris@1431
|
210 * editStart etc.
|
Chris@127
|
211 *
|
Chris@1547
|
212 * If ycoord is non-negative, it contains the y coordinate at
|
Chris@1547
|
213 * which the interaction that prompts this snap is taking place
|
Chris@1547
|
214 * (e.g. of the mouse press used for a selection action). Layers
|
Chris@1547
|
215 * that have objects at multiple different heights may choose to
|
Chris@1547
|
216 * use this information. If the current action has no particular y
|
Chris@1547
|
217 * coordinate associated with it, ycoord will be passed as -1.
|
Chris@1547
|
218 *
|
Chris@127
|
219 * Return true if a suitable feature was found and frame adjusted
|
Chris@180
|
220 * accordingly. Return false if no suitable feature was available
|
Chris@517
|
221 * (and leave frame unmodified). If returning true, also return
|
Chris@517
|
222 * the resolution of the model in this layer in sample frames.
|
Chris@127
|
223 */
|
Chris@916
|
224 virtual bool snapToFeatureFrame(LayerGeometryProvider * /* v */,
|
Chris@1266
|
225 sv_frame_t & /* frame */,
|
Chris@1266
|
226 int &resolution,
|
Chris@1547
|
227 SnapType /* snap */,
|
Chris@1547
|
228 int /* ycoord */) const {
|
Chris@1266
|
229 resolution = 1;
|
Chris@1266
|
230 return false;
|
Chris@127
|
231 }
|
Chris@127
|
232
|
Chris@517
|
233 /**
|
Chris@517
|
234 * Adjust the given frame to snap to the next feature that has
|
Chris@517
|
235 * "effectively" the same value as the feature prior to the given
|
Chris@517
|
236 * frame, if possible.
|
Chris@517
|
237 *
|
Chris@517
|
238 * The snap type must be SnapLeft (snap to the time of the next
|
Chris@517
|
239 * feature prior to the one preceding the given frame that has a
|
Chris@517
|
240 * similar value to it) or SnapRight (snap to the time of the next
|
Chris@517
|
241 * feature following the given frame that has a similar value to
|
Chris@517
|
242 * the feature preceding it). Other values are not permitted.
|
Chris@517
|
243 *
|
Chris@517
|
244 * Return true if a suitable feature was found and frame adjusted
|
Chris@517
|
245 * accordingly. Return false if no suitable feature was available
|
Chris@517
|
246 * (and leave frame unmodified). If returning true, also return
|
Chris@517
|
247 * the resolution of the model in this layer in sample frames.
|
Chris@517
|
248 */
|
Chris@916
|
249 virtual bool snapToSimilarFeature(LayerGeometryProvider * /* v */,
|
Chris@904
|
250 sv_frame_t & /* source frame */,
|
Chris@805
|
251 int &resolution,
|
Chris@517
|
252 SnapType /* snap */) const {
|
Chris@1266
|
253 resolution = 1;
|
Chris@1266
|
254 return false;
|
Chris@517
|
255 }
|
Chris@517
|
256
|
Chris@335
|
257 // Draw, erase, and edit modes:
|
Chris@127
|
258 //
|
Chris@127
|
259 // Layer needs to get actual mouse events, I guess. Draw mode is
|
Chris@127
|
260 // probably the easier.
|
Chris@127
|
261
|
Chris@916
|
262 virtual void drawStart(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@916
|
263 virtual void drawDrag(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@916
|
264 virtual void drawEnd(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@127
|
265
|
Chris@916
|
266 virtual void eraseStart(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@916
|
267 virtual void eraseDrag(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@916
|
268 virtual void eraseEnd(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@335
|
269
|
Chris@916
|
270 virtual void editStart(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@916
|
271 virtual void editDrag(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@916
|
272 virtual void editEnd(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@127
|
273
|
Chris@916
|
274 virtual void splitStart(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@916
|
275 virtual void splitEnd(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@916
|
276 virtual void addNote(LayerGeometryProvider *, QMouseEvent *) { };
|
gyorgyf@635
|
277
|
Chris@267
|
278 // Measurement rectangle (or equivalent). Unlike draw and edit,
|
Chris@267
|
279 // the base Layer class can provide working implementations of
|
Chris@267
|
280 // these for most situations.
|
Chris@267
|
281 //
|
Chris@916
|
282 virtual void measureStart(LayerGeometryProvider *, QMouseEvent *);
|
Chris@916
|
283 virtual void measureDrag(LayerGeometryProvider *, QMouseEvent *);
|
Chris@916
|
284 virtual void measureEnd(LayerGeometryProvider *, QMouseEvent *);
|
Chris@916
|
285 virtual void measureDoubleClick(LayerGeometryProvider *, QMouseEvent *);
|
Chris@267
|
286
|
Chris@283
|
287 virtual bool haveCurrentMeasureRect() const {
|
Chris@283
|
288 return m_haveCurrentMeasureRect;
|
Chris@283
|
289 }
|
Chris@283
|
290 virtual void deleteCurrentMeasureRect(); // using a command
|
Chris@283
|
291
|
Chris@255
|
292 /**
|
Chris@255
|
293 * Open an editor on the item under the mouse (e.g. on
|
Chris@255
|
294 * double-click). If there is no item or editing is not
|
Chris@255
|
295 * supported, return false.
|
Chris@255
|
296 */
|
Chris@916
|
297 virtual bool editOpen(LayerGeometryProvider *, QMouseEvent *) { return false; }
|
Chris@127
|
298
|
Chris@905
|
299 virtual void moveSelection(Selection, sv_frame_t /* newStartFrame */) { }
|
Chris@127
|
300 virtual void resizeSelection(Selection, Selection /* newSize */) { }
|
Chris@127
|
301 virtual void deleteSelection(Selection) { }
|
Chris@127
|
302
|
Chris@916
|
303 virtual void copy(LayerGeometryProvider *, Selection, Clipboard & /* to */) { }
|
Chris@127
|
304
|
Chris@127
|
305 /**
|
Chris@127
|
306 * Paste from the given clipboard onto the layer at the given
|
Chris@127
|
307 * frame offset. If interactive is true, the layer may ask the
|
Chris@127
|
308 * user about paste options through a dialog if desired, and may
|
Chris@127
|
309 * return false if the user cancelled the paste operation. This
|
Chris@127
|
310 * function should return true if a paste actually occurred.
|
Chris@127
|
311 */
|
Chris@916
|
312 virtual bool paste(LayerGeometryProvider *,
|
Chris@359
|
313 const Clipboard & /* from */,
|
Chris@904
|
314 sv_frame_t /* frameOffset */,
|
Chris@127
|
315 bool /* interactive */) { return false; }
|
Chris@127
|
316
|
Chris@127
|
317 // Text mode:
|
Chris@127
|
318 //
|
Chris@127
|
319 // Label nearest feature. We need to get the feature coordinates
|
Chris@127
|
320 // and current label from the layer, and then the pane can pop up
|
Chris@127
|
321 // a little text entry dialog at the right location. Or we edit
|
Chris@127
|
322 // in place? Probably the dialog is easier.
|
Chris@127
|
323
|
Chris@127
|
324 /**
|
Chris@127
|
325 * This should return true if the layer can safely be scrolled
|
Chris@127
|
326 * automatically by a given view (simply copying the existing data
|
Chris@127
|
327 * and then refreshing the exposed area) without altering its
|
Chris@127
|
328 * meaning. For the view widget as a whole this is usually not
|
Chris@127
|
329 * possible because of invariant (non-scrolling) material
|
Chris@127
|
330 * displayed over the top, but the widget may be able to optimise
|
Chris@127
|
331 * scrolling better if it is known that individual views can be
|
Chris@127
|
332 * scrolled safely in this way.
|
Chris@127
|
333 */
|
Chris@916
|
334 virtual bool isLayerScrollable(const LayerGeometryProvider *) const { return true; }
|
Chris@127
|
335
|
Chris@127
|
336 /**
|
Chris@127
|
337 * This should return true if the layer completely obscures any
|
Chris@127
|
338 * underlying layers. It's used to determine whether the view can
|
Chris@127
|
339 * safely draw any selection rectangles under the layer instead of
|
Chris@127
|
340 * over it, in the case where the layer is not scrollable and
|
Chris@127
|
341 * therefore needs to be redrawn each time (so that the selection
|
Chris@127
|
342 * rectangle can be cached).
|
Chris@127
|
343 */
|
Chris@127
|
344 virtual bool isLayerOpaque() const { return false; }
|
Chris@127
|
345
|
Chris@287
|
346 enum ColourSignificance {
|
Chris@287
|
347 ColourAbsent,
|
Chris@287
|
348 ColourIrrelevant,
|
Chris@287
|
349 ColourDistinguishes,
|
Chris@287
|
350 ColourAndBackgroundSignificant,
|
Chris@287
|
351 ColourHasMeaningfulValue
|
Chris@287
|
352 };
|
Chris@287
|
353
|
Chris@127
|
354 /**
|
Chris@287
|
355 * This should return the degree of meaning associated with colour
|
Chris@287
|
356 * in this layer.
|
Chris@287
|
357 *
|
Chris@287
|
358 * If ColourAbsent, the layer does not use colour. If
|
Chris@287
|
359 * ColourIrrelevant, the layer is coloured and the colour may be
|
Chris@287
|
360 * set by the user, but it doesn't really matter what the colour
|
Chris@287
|
361 * is (for example, in a time ruler layer). If
|
Chris@287
|
362 * ColourDistinguishes, then the colour is used to distinguish
|
Chris@287
|
363 * this layer from other similar layers (e.g. for data layers).
|
Chris@287
|
364 * If ColourAndBackgroundSignificant, then the layer should be
|
Chris@287
|
365 * given greater weight than ColourDistinguishes layers when
|
Chris@287
|
366 * choosing a background colour (e.g. for waveforms). If
|
Chris@287
|
367 * ColourHasMeaningfulValue, colours are actually meaningful --
|
Chris@287
|
368 * the view will then show selections using unfilled rectangles
|
Chris@287
|
369 * instead of translucent filled rectangles, so as not to disturb
|
Chris@287
|
370 * the colours underneath.
|
Chris@183
|
371 */
|
Chris@287
|
372 virtual ColourSignificance getLayerColourSignificance() const = 0;
|
Chris@183
|
373
|
Chris@183
|
374 /**
|
Chris@127
|
375 * This should return true if the layer can be edited by the user.
|
Chris@127
|
376 * If this is the case, the appropriate edit tools may be made
|
Chris@127
|
377 * available by the application and the layer's drawStart/Drag/End
|
Chris@127
|
378 * and editStart/Drag/End methods should be implemented.
|
Chris@127
|
379 */
|
Chris@127
|
380 virtual bool isLayerEditable() const { return false; }
|
Chris@127
|
381
|
Chris@127
|
382 /**
|
Chris@127
|
383 * Return the proportion of background work complete in drawing
|
Chris@127
|
384 * this view, as a percentage -- in most cases this will be the
|
Chris@127
|
385 * value returned by pointer from a call to the underlying model's
|
Chris@226
|
386 * isReady(int *) call. The view may choose to show a progress
|
Chris@127
|
387 * meter if it finds that this returns < 100 at any given moment.
|
Chris@127
|
388 */
|
Chris@916
|
389 virtual int getCompletion(LayerGeometryProvider *) const { return 100; }
|
Chris@127
|
390
|
Chris@583
|
391 /**
|
Chris@583
|
392 * Return an error string if any errors have occurred while
|
Chris@583
|
393 * loading or processing data for the given view. Return the
|
Chris@583
|
394 * empty string if no error has occurred.
|
Chris@583
|
395 */
|
Chris@916
|
396 virtual QString getError(LayerGeometryProvider *) const { return ""; }
|
Chris@583
|
397
|
Chris@127
|
398 virtual void setObjectName(const QString &name);
|
Chris@127
|
399
|
Chris@127
|
400 /**
|
Chris@127
|
401 * Convert the layer's data (though not those of the model it
|
Chris@316
|
402 * refers to) into XML for file output. This class implements the
|
Chris@316
|
403 * basic name/type/model-id output; subclasses will typically call
|
Chris@316
|
404 * this superclass implementation with extra attributes describing
|
Chris@316
|
405 * their particular properties.
|
Chris@127
|
406 */
|
Chris@1406
|
407 void toXml(QTextStream &stream, QString indent = "",
|
Chris@1406
|
408 QString extraAttributes = "") const override;
|
Chris@127
|
409
|
Chris@127
|
410 /**
|
Chris@127
|
411 * Set the particular properties of a layer (those specific to the
|
Chris@127
|
412 * subclass) from a set of XML attributes. This is the effective
|
Chris@316
|
413 * inverse of the toXml method.
|
Chris@127
|
414 */
|
Chris@127
|
415 virtual void setProperties(const QXmlAttributes &) = 0;
|
Chris@127
|
416
|
Chris@127
|
417 /**
|
Chris@316
|
418 * Produce XML containing the layer's ID and type. This is used
|
Chris@316
|
419 * to refer to the layer in the display section of the SV session
|
Chris@316
|
420 * file, for a layer that has already been described in the data
|
Chris@316
|
421 * section.
|
Chris@269
|
422 */
|
Chris@316
|
423 virtual void toBriefXml(QTextStream &stream,
|
Chris@316
|
424 QString indent = "",
|
Chris@316
|
425 QString extraAttributes = "") const;
|
Chris@269
|
426
|
Chris@269
|
427 /**
|
Chris@269
|
428 * Add a measurement rectangle from the given XML attributes
|
Chris@269
|
429 * (presumably taken from a measurement element).
|
Chris@269
|
430 * Does not use a command.
|
Chris@269
|
431 */
|
Chris@269
|
432 virtual void addMeasurementRect(const QXmlAttributes &);
|
Chris@269
|
433
|
Chris@269
|
434 /**
|
Chris@127
|
435 * Indicate that a layer is not currently visible in the given
|
Chris@127
|
436 * view and is not expected to become visible in the near future
|
Chris@127
|
437 * (for example because the user has explicitly removed or hidden
|
Chris@127
|
438 * it). The layer may respond by (for example) freeing any cache
|
Chris@127
|
439 * memory it is using, until next time its paint method is called,
|
Chris@127
|
440 * when it should set itself un-dormant again.
|
Chris@131
|
441 *
|
Chris@131
|
442 * A layer class that overrides this function must also call this
|
Chris@131
|
443 * class's implementation.
|
Chris@127
|
444 */
|
Chris@916
|
445 virtual void setLayerDormant(const LayerGeometryProvider *v, bool dormant);
|
Chris@127
|
446
|
Chris@127
|
447 /**
|
Chris@127
|
448 * Return whether the layer is dormant (i.e. hidden) in the given
|
Chris@127
|
449 * view.
|
Chris@127
|
450 */
|
Chris@916
|
451 virtual bool isLayerDormant(const LayerGeometryProvider *v) const;
|
Chris@127
|
452
|
Chris@1480
|
453 /**
|
Chris@1480
|
454 * Return the play parameters for this layer, if any. The return
|
Chris@1480
|
455 * value is a shared_ptr that can be passed to (e.g.)
|
Chris@1480
|
456 * PlayParameterRepository::EditCommand to change the parameters.
|
Chris@1480
|
457 */
|
Chris@1480
|
458 std::shared_ptr<PlayParameters> getPlayParameters() override;
|
Chris@127
|
459
|
Chris@1391
|
460 /**
|
Chris@1391
|
461 * True if this layer will need to place text labels when it is
|
Chris@1391
|
462 * painted. The view will take into account how many layers are
|
Chris@1391
|
463 * requesting this, and will provide a distinct y-coord to each
|
Chris@1391
|
464 * layer on request via View::getTextLabelHeight().
|
Chris@1391
|
465 */
|
Chris@127
|
466 virtual bool needsTextLabelHeight() const { return false; }
|
Chris@127
|
467
|
Chris@1389
|
468 /**
|
Chris@1389
|
469 * Return true if the X axis on the layer is time proportional to
|
Chris@1389
|
470 * audio frames, false otherwise. Almost all layer types return
|
Chris@1389
|
471 * true here: the exceptions are spectrum and slice layers.
|
Chris@1389
|
472 */
|
Chris@217
|
473 virtual bool hasTimeXAxis() const { return true; }
|
Chris@217
|
474
|
Chris@127
|
475 /**
|
Chris@1389
|
476 * Update the X and Y axis scales, where appropriate, to focus on
|
Chris@1389
|
477 * the given rectangular region. This should *only* be overridden
|
Chris@1389
|
478 * by layers whose hasTimeXAxis() returns false - the pane handles
|
Chris@1389
|
479 * zooming appropriately in every "normal" case.
|
Chris@1389
|
480 */
|
Chris@1389
|
481 virtual void zoomToRegion(const LayerGeometryProvider *, QRect) {
|
Chris@1389
|
482 return;
|
Chris@1389
|
483 }
|
Chris@1389
|
484
|
Chris@1389
|
485 /**
|
Chris@127
|
486 * Return the minimum and maximum values for the y axis of the
|
Chris@127
|
487 * model in this layer, as well as whether the layer is configured
|
Chris@127
|
488 * to use a logarithmic y axis display. Also return the unit for
|
Chris@127
|
489 * these values if known.
|
Chris@127
|
490 *
|
Chris@127
|
491 * This function returns the "normal" extents for the layer, not
|
Chris@1537
|
492 * necessarily the extents actually in use in the display (see
|
Chris@1537
|
493 * getDisplayExtents).
|
Chris@127
|
494 */
|
Chris@904
|
495 virtual bool getValueExtents(double &min, double &max,
|
Chris@127
|
496 bool &logarithmic, QString &unit) const = 0;
|
Chris@127
|
497
|
Chris@127
|
498 /**
|
Chris@1537
|
499 * Return the minimum and maximum values within the visible area
|
Chris@1537
|
500 * for the y axis of this layer.
|
Chris@1537
|
501 *
|
Chris@1537
|
502 * Return false if the layer has no display extents of its
|
Chris@1537
|
503 * own. This could be because the layer is "auto-aligning" against
|
Chris@1537
|
504 * another layer with the same units elsewhere in the view, or
|
Chris@1537
|
505 * because the layer has no concept of a vertical scale at all.
|
Chris@127
|
506 */
|
Chris@904
|
507 virtual bool getDisplayExtents(double & /* min */,
|
Chris@904
|
508 double & /* max */) const {
|
Chris@127
|
509 return false;
|
Chris@127
|
510 }
|
Chris@127
|
511
|
Chris@127
|
512 /**
|
Chris@127
|
513 * Set the displayed minimum and maximum values for the y axis to
|
Chris@127
|
514 * the given range, if supported. Return false if not supported
|
Chris@127
|
515 * on this layer (and set nothing). In most cases, layers that
|
Chris@127
|
516 * return false for getDisplayExtents should also return false for
|
Chris@127
|
517 * this function.
|
Chris@127
|
518 */
|
Chris@904
|
519 virtual bool setDisplayExtents(double /* min */,
|
Chris@904
|
520 double /* max */) {
|
Chris@127
|
521 return false;
|
Chris@127
|
522 }
|
Chris@127
|
523
|
Chris@133
|
524 /**
|
Chris@1520
|
525 * Consider using the given value extents and units for this
|
Chris@1520
|
526 * layer. This may be called on a new layer when added, to prepare
|
Chris@1520
|
527 * it for editing, and the extents are those of the layer
|
Chris@1520
|
528 * underneath it. May not be appropriate for most layer types.
|
Chris@1520
|
529 */
|
Chris@1520
|
530 virtual bool adoptExtents(double /* min */, double /* max */,
|
Chris@1520
|
531 QString /* unit */) {
|
Chris@1520
|
532 return false;
|
Chris@1520
|
533 }
|
Chris@1520
|
534
|
Chris@1520
|
535 /**
|
Chris@260
|
536 * Return the value and unit at the given x coordinate in the
|
Chris@260
|
537 * given view. This is for descriptive purposes using the
|
Chris@260
|
538 * measurement tool. The default implementation works correctly
|
Chris@260
|
539 * if the layer hasTimeXAxis().
|
Chris@260
|
540 */
|
Chris@916
|
541 virtual bool getXScaleValue(const LayerGeometryProvider *v, int x,
|
Chris@904
|
542 double &value, QString &unit) const;
|
Chris@260
|
543
|
Chris@260
|
544 /**
|
Chris@260
|
545 * Return the value and unit at the given y coordinate in the
|
Chris@260
|
546 * given view.
|
Chris@260
|
547 */
|
Chris@916
|
548 virtual bool getYScaleValue(const LayerGeometryProvider *, int /* y */,
|
Chris@904
|
549 double &/* value */, QString &/* unit */) const {
|
Chris@260
|
550 return false;
|
Chris@260
|
551 }
|
Chris@260
|
552
|
Chris@260
|
553 /**
|
Chris@274
|
554 * Return the difference between the values at the given y
|
Chris@274
|
555 * coordinates in the given view, and the unit of the difference.
|
Chris@274
|
556 * The default implementation just calls getYScaleValue twice and
|
Chris@274
|
557 * returns the difference, with the same unit.
|
Chris@274
|
558 */
|
Chris@916
|
559 virtual bool getYScaleDifference(const LayerGeometryProvider *v, int y0, int y1,
|
Chris@904
|
560 double &diff, QString &unit) const;
|
Chris@274
|
561
|
Chris@274
|
562 /**
|
Chris@133
|
563 * Get the number of vertical zoom steps available for this layer.
|
Chris@133
|
564 * If vertical zooming is not available, return 0. The meaning of
|
Chris@133
|
565 * "zooming" is entirely up to the layer -- changing the zoom
|
Chris@133
|
566 * level may cause the layer to reset its display extents or
|
Chris@180
|
567 * change another property such as display gain. However, layers
|
Chris@180
|
568 * are advised for consistency to treat smaller zoom steps as
|
Chris@180
|
569 * "more distant" or "zoomed out" and larger ones as "closer" or
|
Chris@180
|
570 * "zoomed in".
|
Chris@180
|
571 *
|
Chris@133
|
572 * Layers that provide this facility should also emit the
|
Chris@133
|
573 * verticalZoomChanged signal if their vertical zoom changes
|
Chris@133
|
574 * due to factors other than setVerticalZoomStep being called.
|
Chris@133
|
575 */
|
Chris@248
|
576 virtual int getVerticalZoomSteps(int & /* defaultStep */) const { return 0; }
|
Chris@133
|
577
|
Chris@133
|
578 /**
|
Chris@133
|
579 * Get the current vertical zoom step. A layer may support finer
|
Chris@133
|
580 * control over ranges etc than is available through the integer
|
Chris@133
|
581 * zoom step mechanism; if this one does, it should just return
|
Chris@133
|
582 * the nearest of the available zoom steps to the current settings.
|
Chris@133
|
583 */
|
Chris@133
|
584 virtual int getCurrentVerticalZoomStep() const { return 0; }
|
Chris@133
|
585
|
Chris@133
|
586 /**
|
Chris@133
|
587 * Set the vertical zoom step. The meaning of "zooming" is
|
Chris@133
|
588 * entirely up to the layer -- changing the zoom level may cause
|
Chris@133
|
589 * the layer to reset its display extents or change another
|
Chris@133
|
590 * property such as display gain.
|
Chris@133
|
591 */
|
Chris@133
|
592 virtual void setVerticalZoomStep(int) { }
|
Chris@133
|
593
|
Chris@187
|
594 /**
|
Chris@187
|
595 * Create and return a range mapper for vertical zoom step values.
|
Chris@187
|
596 * See the RangeMapper documentation for more details. The
|
Chris@187
|
597 * returned value is allocated on the heap and will be deleted by
|
Chris@187
|
598 * the caller.
|
Chris@187
|
599 */
|
Chris@187
|
600 virtual RangeMapper *getNewVerticalZoomRangeMapper() const { return 0; }
|
Chris@187
|
601
|
Chris@947
|
602 /**
|
Chris@947
|
603 * Return true if this layer type can function without a model
|
Chris@947
|
604 * being set. If false (the default), the layer will not be loaded
|
Chris@947
|
605 * from a session if its model cannot be found.
|
Chris@947
|
606 */
|
Chris@947
|
607 virtual bool canExistWithoutModel() const { return false; }
|
Chris@947
|
608
|
Chris@127
|
609 public slots:
|
Chris@1456
|
610 /**
|
Chris@1456
|
611 * Change the visibility status (dormancy) of the layer in the
|
Chris@1456
|
612 * given view.
|
Chris@1456
|
613 */
|
Chris@916
|
614 void showLayer(LayerGeometryProvider *, bool show);
|
Chris@127
|
615
|
Chris@127
|
616 signals:
|
Chris@1481
|
617 void modelChanged(ModelId);
|
Chris@1481
|
618 void modelCompletionChanged(ModelId);
|
Chris@1481
|
619 void modelAlignmentCompletionChanged(ModelId);
|
Chris@1481
|
620 void modelChangedWithin(ModelId, sv_frame_t startFrame, sv_frame_t endFrame);
|
Chris@127
|
621 void modelReplaced();
|
Chris@127
|
622
|
Chris@127
|
623 void layerParametersChanged();
|
Chris@197
|
624 void layerParameterRangesChanged();
|
Chris@268
|
625 void layerMeasurementRectsChanged();
|
Chris@127
|
626 void layerNameChanged();
|
Chris@127
|
627
|
Chris@133
|
628 void verticalZoomChanged();
|
Chris@133
|
629
|
Chris@267
|
630 protected:
|
Chris@1469
|
631 void connectSignals(ModelId);
|
Chris@320
|
632
|
Chris@916
|
633 virtual sv_frame_t alignToReference(LayerGeometryProvider *v, sv_frame_t frame) const;
|
Chris@916
|
634 virtual sv_frame_t alignFromReference(LayerGeometryProvider *v, sv_frame_t frame) const;
|
Chris@916
|
635 bool clipboardHasDifferentAlignment(LayerGeometryProvider *v, const Clipboard &clip) const;
|
Chris@359
|
636
|
Chris@267
|
637 struct MeasureRect {
|
Chris@268
|
638
|
Chris@267
|
639 mutable QRect pixrect;
|
Chris@268
|
640 bool haveFrames;
|
Chris@905
|
641 sv_frame_t startFrame; // only valid if haveFrames
|
Chris@905
|
642 sv_frame_t endFrame; // ditto
|
Chris@273
|
643 double startY;
|
Chris@273
|
644 double endY;
|
Chris@268
|
645
|
Chris@268
|
646 bool operator<(const MeasureRect &mr) const;
|
Chris@316
|
647 void toXml(QTextStream &stream, QString indent) const;
|
Chris@267
|
648 };
|
Chris@267
|
649
|
Chris@268
|
650 class AddMeasurementRectCommand : public Command
|
Chris@268
|
651 {
|
Chris@268
|
652 public:
|
Chris@268
|
653 AddMeasurementRectCommand(Layer *layer, MeasureRect rect) :
|
Chris@268
|
654 m_layer(layer), m_rect(rect) { }
|
Chris@268
|
655
|
Chris@1406
|
656 QString getName() const override;
|
Chris@1406
|
657 void execute() override;
|
Chris@1406
|
658 void unexecute() override;
|
Chris@268
|
659
|
Chris@268
|
660 private:
|
Chris@268
|
661 Layer *m_layer;
|
Chris@268
|
662 MeasureRect m_rect;
|
Chris@268
|
663 };
|
Chris@268
|
664
|
Chris@283
|
665 class DeleteMeasurementRectCommand : public Command
|
Chris@283
|
666 {
|
Chris@283
|
667 public:
|
Chris@283
|
668 DeleteMeasurementRectCommand(Layer *layer, MeasureRect rect) :
|
Chris@283
|
669 m_layer(layer), m_rect(rect) { }
|
Chris@283
|
670
|
Chris@1406
|
671 QString getName() const override;
|
Chris@1406
|
672 void execute() override;
|
Chris@1406
|
673 void unexecute() override;
|
Chris@283
|
674
|
Chris@283
|
675 private:
|
Chris@283
|
676 Layer *m_layer;
|
Chris@283
|
677 MeasureRect m_rect;
|
Chris@283
|
678 };
|
Chris@283
|
679
|
Chris@269
|
680 void addMeasureRectToSet(const MeasureRect &r) {
|
Chris@268
|
681 m_measureRects.insert(r);
|
Chris@268
|
682 emit layerMeasurementRectsChanged();
|
Chris@268
|
683 }
|
Chris@268
|
684
|
Chris@269
|
685 void deleteMeasureRectFromSet(const MeasureRect &r) {
|
Chris@268
|
686 m_measureRects.erase(r);
|
Chris@268
|
687 emit layerMeasurementRectsChanged();
|
Chris@268
|
688 }
|
Chris@268
|
689
|
Chris@268
|
690 typedef std::set<MeasureRect> MeasureRectSet;
|
Chris@268
|
691 MeasureRectSet m_measureRects;
|
Chris@267
|
692 MeasureRect m_draggingRect;
|
Chris@267
|
693 bool m_haveDraggingRect;
|
Chris@283
|
694 mutable bool m_haveCurrentMeasureRect;
|
Chris@283
|
695 mutable QPoint m_currentMeasureRectPoint;
|
Chris@272
|
696
|
Chris@272
|
697 // Note that pixrects are only correct for a single view.
|
Chris@272
|
698 // So we should update them at the start of the paint procedure
|
Chris@272
|
699 // (painting is single threaded) and only use them after that.
|
Chris@916
|
700 void updateMeasurePixrects(LayerGeometryProvider *v) const;
|
Chris@273
|
701
|
Chris@916
|
702 virtual void updateMeasureRectYCoords(LayerGeometryProvider *v, const MeasureRect &r) const;
|
Chris@916
|
703 virtual void setMeasureRectYCoord(LayerGeometryProvider *v, MeasureRect &r, bool start, int y) const;
|
Chris@916
|
704 virtual void setMeasureRectFromPixrect(LayerGeometryProvider *v, MeasureRect &r, QRect pixrect) const;
|
Chris@272
|
705
|
Chris@272
|
706 // This assumes updateMeasurementPixrects has been called
|
Chris@272
|
707 MeasureRectSet::const_iterator findFocusedMeasureRect(QPoint) const;
|
Chris@267
|
708
|
Chris@916
|
709 void paintMeasurementRect(LayerGeometryProvider *v, QPainter &paint,
|
Chris@270
|
710 const MeasureRect &r, bool focus) const;
|
Chris@268
|
711
|
Chris@1315
|
712 bool valueExtentsMatchMine(LayerGeometryProvider *v) const;
|
Chris@1315
|
713
|
Chris@363
|
714 QString m_presentationName;
|
Chris@363
|
715
|
Chris@131
|
716 private:
|
Chris@131
|
717 mutable QMutex m_dormancyMutex;
|
Chris@127
|
718 mutable std::map<const void *, bool> m_dormancy;
|
Chris@127
|
719 };
|
Chris@127
|
720
|
Chris@127
|
721 #endif
|
Chris@127
|
722
|