RegionLayer.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006-2008 Chris Cannam and QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef SV_REGION_LAYER_H
17 #define SV_REGION_LAYER_H
18 
19 #include "SingleColourLayer.h"
20 #include "VerticalScaleLayer.h"
21 #include "ColourScaleLayer.h"
22 
23 #include "data/model/RegionModel.h"
24 
25 #include <QObject>
26 #include <QColor>
27 
28 #include <map>
29 
30 class View;
31 class QPainter;
32 
34  public VerticalScaleLayer,
35  public ColourScaleLayer
36 {
37  Q_OBJECT
38 
39 public:
40  RegionLayer();
41 
42  void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override;
43 
44  int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const override;
45  void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const override;
46 
47  QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override;
48  QString getLabelPreceding(sv_frame_t) const override;
49 
50  bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
51  int &resolution,
52  SnapType snap, int ycoord) const override;
53  bool snapToSimilarFeature(LayerGeometryProvider *v, sv_frame_t &frame,
54  int &resolution,
55  SnapType snap) const override;
56 
57  void drawStart(LayerGeometryProvider *v, QMouseEvent *) override;
58  void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override;
59  void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override;
60 
61  void eraseStart(LayerGeometryProvider *v, QMouseEvent *) override;
62  void eraseDrag(LayerGeometryProvider *v, QMouseEvent *) override;
63  void eraseEnd(LayerGeometryProvider *v, QMouseEvent *) override;
64 
65  void editStart(LayerGeometryProvider *v, QMouseEvent *) override;
66  void editDrag(LayerGeometryProvider *v, QMouseEvent *) override;
67  void editEnd(LayerGeometryProvider *v, QMouseEvent *) override;
68 
69  bool editOpen(LayerGeometryProvider *v, QMouseEvent *) override;
70 
71  void moveSelection(Selection s, sv_frame_t newStartFrame) override;
72  void resizeSelection(Selection s, Selection newSize) override;
73  void deleteSelection(Selection s) override;
74 
75  void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override;
76  bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset,
77  bool interactive) override;
78 
79  ModelId getModel() const override { return m_model; }
80  void setModel(ModelId model); // a RegionModel
81 
82  PropertyList getProperties() const override;
83  QString getPropertyLabel(const PropertyName &) const override;
84  PropertyType getPropertyType(const PropertyName &) const override;
85  QString getPropertyGroupName(const PropertyName &) const override;
86  int getPropertyRangeAndValue(const PropertyName &,
87  int *min, int *max, int *deflt) const override;
88  QString getPropertyValueLabel(const PropertyName &,
89  int value) const override;
90  void setProperty(const PropertyName &, int value) override;
91 
92  void setFillColourMap(int);
93  int getFillColourMap() const { return m_colourMap; }
94 
100  };
101 
102  void setVerticalScale(VerticalScale scale);
104 
105  enum PlotStyle {
108  };
109 
110  void setPlotStyle(PlotStyle style);
111  PlotStyle getPlotStyle() const { return m_plotStyle; }
112 
113  bool isLayerScrollable(const LayerGeometryProvider *v) const override;
114 
115  bool isLayerEditable() const override { return true; }
116 
117  int getCompletion(LayerGeometryProvider *) const override;
118 
119  bool getValueExtents(double &min, double &max,
120  bool &log, QString &unit) const override;
121 
122  bool getDisplayExtents(double &min, double &max) const override;
123 
124  void toXml(QTextStream &stream, QString indent = "",
125  QString extraAttributes = "") const override;
126 
127  void setProperties(const QXmlAttributes &attributes) override;
128 
130  int getYForValue(LayerGeometryProvider *v, double value) const override;
131  double getValueForY(LayerGeometryProvider *v, int y) const override;
132  QString getScaleUnits() const override;
133  QColor getColourForValue(LayerGeometryProvider *v, double value) const override;
134 
135 protected slots:
136  void recalcSpacing();
137 
138 protected:
139  double getValueForY(LayerGeometryProvider *v, int y, int avoid) const;
140  void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const;
141 
142  int getDefaultColourHint(bool dark, bool &impose) override;
143 
144  EventVector getLocalPoints(LayerGeometryProvider *v, int x) const;
145 
146  bool getPointToDrag(LayerGeometryProvider *v, int x, int y, Event &) const;
147 
148  ModelId m_model;
149  bool m_editing;
156  ChangeEventsCommand *m_editingCommand;
161 
162  typedef std::map<double, int> SpacingMap;
163 
164  // region value -> ordering
165  SpacingMap m_spacingMap;
166 
167  // region value -> number of regions with this value
168  SpacingMap m_distributionMap;
169 
170  int spacingIndexToY(LayerGeometryProvider *v, int i) const;
171  double yToSpacingIndex(LayerGeometryProvider *v, int y) const;
172 
173  void finish(ChangeEventsCommand *command) {
174  Command *c = command->finish();
175  if (c) CommandHistory::getInstance()->addCommand(c, false);
176  }
177 };
178 
179 #endif
180 
bool m_colourInverted
Definition: RegionLayer.h:159
int getCompletion(LayerGeometryProvider *) const override
Return the proportion of background work complete in drawing this view, as a percentage – in most ca...
Definition: RegionLayer.cpp:66
double getValueForY(LayerGeometryProvider *v, int y) const override
void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override
void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override
void setPlotStyle(PlotStyle style)
QString getPropertyGroupName(const PropertyName &) const override
int getFillColourMap() const
Definition: RegionLayer.h:93
QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override
void setModel(ModelId model)
Definition: RegionLayer.cpp:74
void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const
bool isLayerEditable() const override
This should return true if the layer can be edited by the user.
Definition: RegionLayer.h:115
ModelId m_model
Definition: RegionLayer.h:148
void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override
void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const override
void editStart(LayerGeometryProvider *v, QMouseEvent *) override
int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const override
ModelId getModel() const override
Return the ID of the model represented in this layer.
Definition: RegionLayer.h:79
VerticalScale getVerticalScale() const
Definition: RegionLayer.h:103
QColor getColourForValue(LayerGeometryProvider *v, double value) const override
int spacingIndexToY(LayerGeometryProvider *v, int i) const
bool getPointToDrag(LayerGeometryProvider *v, int x, int y, Event &) const
int m_dragStartX
Definition: RegionLayer.h:152
void addCommand(Command *command)
Add a command to the command history.
bool m_editing
Definition: RegionLayer.h:149
int m_dragStartY
Definition: RegionLayer.h:153
bool isLayerScrollable(const LayerGeometryProvider *v) const override
This should return true if the layer can safely be scrolled automatically by a given view (simply cop...
QString getPropertyLabel(const PropertyName &) const override
int m_dragPointX
Definition: RegionLayer.h:150
PropertyType getPropertyType(const PropertyName &) const override
void setProperties(const QXmlAttributes &attributes) override
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
void setVerticalScale(VerticalScale scale)
void moveSelection(Selection s, sv_frame_t newStartFrame) override
void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override
Paint the given rectangle of this layer onto the given view using the given painter, superimposing it on top of any existing material in that view.
void setProperty(const PropertyName &, int value) override
QString getPropertyValueLabel(const PropertyName &, int value) const override
Interface for classes that provide geometry information (such as size, start frame, and a large number of other properties) about the disposition of a layer.
double yToSpacingIndex(LayerGeometryProvider *v, int y) const
Interface for layers in which the Y axis represents (or can sometimes represent, depending on the dis...
EventVector getLocalPoints(LayerGeometryProvider *v, int x) const
VerticalScale m_verticalScale
Definition: RegionLayer.h:157
void deleteSelection(Selection s) override
int m_dragPointY
Definition: RegionLayer.h:151
void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const override
Interface for layers in which a colour scale represents (or can sometimes represent, depending on the display mode) the sample value.
PropertyList getProperties() const override
bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap, int ycoord) const override
Adjust the given frame to snap to the nearest feature, if possible.
Event m_originalPoint
Definition: RegionLayer.h:154
SnapType
Definition: Layer.h:195
int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const override
bool editOpen(LayerGeometryProvider *v, QMouseEvent *) override
Open an editor on the item under the mouse (e.g.
bool getDisplayExtents(double &min, double &max) const override
Return the minimum and maximum values within the visible area for the y axis of this layer...
static CommandHistory * getInstance()
void editEnd(LayerGeometryProvider *v, QMouseEvent *) override
Event m_editingPoint
Definition: RegionLayer.h:155
SpacingMap m_distributionMap
Definition: RegionLayer.h:168
PlotStyle getPlotStyle() const
Definition: RegionLayer.h:111
void resizeSelection(Selection s, Selection newSize) override
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:55
QString getScaleUnits() const override
void eraseStart(LayerGeometryProvider *v, QMouseEvent *) override
PlotStyle m_plotStyle
Definition: RegionLayer.h:160
void eraseEnd(LayerGeometryProvider *v, QMouseEvent *) override
void recalcSpacing()
int getYForValue(LayerGeometryProvider *v, double value) const override
VerticalScaleLayer and ColourScaleLayer methods.
void setFillColourMap(int)
void editDrag(LayerGeometryProvider *v, QMouseEvent *) override
void drawStart(LayerGeometryProvider *v, QMouseEvent *) override
QString getLabelPreceding(sv_frame_t) const override
bool snapToSimilarFeature(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const override
Adjust the given frame to snap to the next feature that has "effectively" the same value as the featu...
ChangeEventsCommand * m_editingCommand
Definition: RegionLayer.h:156
SpacingMap m_spacingMap
Definition: RegionLayer.h:165
void eraseDrag(LayerGeometryProvider *v, QMouseEvent *) override
int getDefaultColourHint(bool dark, bool &impose) override
std::map< double, int > SpacingMap
Definition: RegionLayer.h:162
void finish(ChangeEventsCommand *command)
Definition: RegionLayer.h:173
bool getValueExtents(double &min, double &max, bool &log, QString &unit) const override
Return the minimum and maximum values for the y axis of the model in this layer, as well as whether t...
bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset, bool interactive) override
Paste from the given clipboard onto the layer at the given frame offset.