comparison layer/TimeValueLayer.cpp @ 1362:d79e21855aef

Add mechanism for saving/loading colour maps by name/id rather than by numerical index, for future compatibility when adding to or changing the supported colour maps. Add two new colour maps (and one old one). Write out backward-compatible numerical indices for use when reloading in older versions. Also add a mechanism to invert the colour map, though I don't think it turns out useful enough to include in the UI.
author Chris Cannam
date Thu, 18 Oct 2018 13:21:56 +0100
parents 1d7921b1852f
children a1393b4384a5
comparison
equal deleted inserted replaced
1361:2e3b3fadba27 1362:d79e21855aef
58 m_editing(false), 58 m_editing(false),
59 m_originalPoint(0, 0.0, tr("New Point")), 59 m_originalPoint(0, 0.0, tr("New Point")),
60 m_editingPoint(0, 0.0, tr("New Point")), 60 m_editingPoint(0, 0.0, tr("New Point")),
61 m_editingCommand(0), 61 m_editingCommand(0),
62 m_colourMap(0), 62 m_colourMap(0),
63 m_colourInverted(false),
63 m_plotStyle(PlotConnectedPoints), 64 m_plotStyle(PlotConnectedPoints),
64 m_verticalScale(AutoAlignScale), 65 m_verticalScale(AutoAlignScale),
65 m_drawSegmentDivisions(true), 66 m_drawSegmentDivisions(true),
66 m_derivative(false), 67 m_derivative(false),
67 m_scaleMinimum(0), 68 m_scaleMinimum(0),
221 QString 222 QString
222 TimeValueLayer::getPropertyValueLabel(const PropertyName &name, 223 TimeValueLayer::getPropertyValueLabel(const PropertyName &name,
223 int value) const 224 int value) const
224 { 225 {
225 if (name == "Colour" && m_plotStyle == PlotSegmentation) { 226 if (name == "Colour" && m_plotStyle == PlotSegmentation) {
226 return ColourMapper::getColourMapName(value); 227 return ColourMapper::getColourMapLabel(value);
227 } else if (name == "Plot Type") { 228 } else if (name == "Plot Type") {
228 switch (value) { 229 switch (value) {
229 default: 230 default:
230 case 0: return tr("Points"); 231 case 0: return tr("Points");
231 case 1: return tr("Stems"); 232 case 1: return tr("Stems");
894 #ifdef DEBUG_TIME_VALUE_LAYER 895 #ifdef DEBUG_TIME_VALUE_LAYER
895 cerr << "TimeValueLayer::getColourForValue: min " << min << ", max " 896 cerr << "TimeValueLayer::getColourForValue: min " << min << ", max "
896 << max << ", log " << log << ", value " << val << endl; 897 << max << ", log " << log << ", value " << val << endl;
897 #endif 898 #endif
898 899
899 QColor solid = ColourMapper(m_colourMap, min, max).map(val); 900 QColor solid = ColourMapper(m_colourMap, m_colourInverted, min, max).map(val);
900 return QColor(solid.red(), solid.green(), solid.blue(), 120); 901 return QColor(solid.red(), solid.green(), solid.blue(), 120);
901 } 902 }
902 903
903 int 904 int
904 TimeValueLayer::getDefaultColourHint(bool darkbg, bool &impose) 905 TimeValueLayer::getDefaultColourHint(bool darkbg, bool &impose)
1905 1906
1906 void 1907 void
1907 TimeValueLayer::toXml(QTextStream &stream, 1908 TimeValueLayer::toXml(QTextStream &stream,
1908 QString indent, QString extraAttributes) const 1909 QString indent, QString extraAttributes) const
1909 { 1910 {
1910 SingleColourLayer::toXml(stream, indent, 1911 QString s;
1911 extraAttributes + 1912
1912 QString(" colourMap=\"%1\" plotStyle=\"%2\" verticalScale=\"%3\" scaleMinimum=\"%4\" scaleMaximum=\"%5\" drawDivisions=\"%6\" derivative=\"%7\" ") 1913 s += QString("plotStyle=\"%1\" "
1913 .arg(m_colourMap) 1914 "verticalScale=\"%2\" "
1914 .arg(m_plotStyle) 1915 "scaleMinimum=\"%3\" "
1915 .arg(m_verticalScale) 1916 "scaleMaximum=\"%4\" "
1916 .arg(m_scaleMinimum) 1917 "drawDivisions=\"%5\" "
1917 .arg(m_scaleMaximum) 1918 "derivative=\"%6\" ")
1918 .arg(m_drawSegmentDivisions ? "true" : "false") 1919 .arg(m_plotStyle)
1919 .arg(m_derivative ? "true" : "false")); 1920 .arg(m_verticalScale)
1921 .arg(m_scaleMinimum)
1922 .arg(m_scaleMaximum)
1923 .arg(m_drawSegmentDivisions ? "true" : "false")
1924 .arg(m_derivative ? "true" : "false");
1925
1926 // New-style colour map attribute, by string id rather than by
1927 // number
1928
1929 s += QString("fillColourMap=\"%1\" ")
1930 .arg(ColourMapper::getColourMapId(m_colourMap));
1931
1932 // Old-style colour map attribute
1933
1934 s += QString("colourMap=\"%1\" ")
1935 .arg(ColourMapper::getBackwardCompatibilityColourMap(m_colourMap));
1936
1937 SingleColourLayer::toXml(stream, indent, extraAttributes + " " + s);
1920 } 1938 }
1921 1939
1922 void 1940 void
1923 TimeValueLayer::setProperties(const QXmlAttributes &attributes) 1941 TimeValueLayer::setProperties(const QXmlAttributes &attributes)
1924 { 1942 {
1925 SingleColourLayer::setProperties(attributes); 1943 SingleColourLayer::setProperties(attributes);
1926 1944
1927 bool ok, alsoOk; 1945 bool ok, alsoOk;
1928 1946
1929 int cmap = attributes.value("colourMap").toInt(&ok); 1947 QString colourMapId = attributes.value("fillColourMap");
1930 if (ok) setFillColourMap(cmap); 1948 int colourMap = ColourMapper::getColourMapById(colourMapId);
1949 if (colourMap >= 0) {
1950 setFillColourMap(colourMap);
1951 } else {
1952 colourMap = attributes.value("colourMap").toInt(&ok);
1953 if (ok && colourMap < ColourMapper::getColourMapCount()) {
1954 setFillColourMap(colourMap);
1955 }
1956 }
1931 1957
1932 PlotStyle style = (PlotStyle) 1958 PlotStyle style = (PlotStyle)
1933 attributes.value("plotStyle").toInt(&ok); 1959 attributes.value("plotStyle").toInt(&ok);
1934 if (ok) setPlotStyle(style); 1960 if (ok) setPlotStyle(style);
1935 1961