comparison layer/RegionLayer.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 a34a2a25907c
children c39f2d439d59
comparison
equal deleted inserted replaced
1361:2e3b3fadba27 1362:d79e21855aef
55 m_originalPoint(0, 0.0, 0, tr("New Region")), 55 m_originalPoint(0, 0.0, 0, tr("New Region")),
56 m_editingPoint(0, 0.0, 0, tr("New Region")), 56 m_editingPoint(0, 0.0, 0, tr("New Region")),
57 m_editingCommand(0), 57 m_editingCommand(0),
58 m_verticalScale(EqualSpaced), 58 m_verticalScale(EqualSpaced),
59 m_colourMap(0), 59 m_colourMap(0),
60 m_colourInverted(false),
60 m_plotStyle(PlotLines) 61 m_plotStyle(PlotLines)
61 { 62 {
62 63
63 } 64 }
64 65
172 QString 173 QString
173 RegionLayer::getPropertyValueLabel(const PropertyName &name, 174 RegionLayer::getPropertyValueLabel(const PropertyName &name,
174 int value) const 175 int value) const
175 { 176 {
176 if (name == "Colour" && m_plotStyle == PlotSegmentation) { 177 if (name == "Colour" && m_plotStyle == PlotSegmentation) {
177 return ColourMapper::getColourMapName(value); 178 return ColourMapper::getColourMapLabel(value);
178 } else if (name == "Plot Type") { 179 } else if (name == "Plot Type") {
179 180
180 switch (value) { 181 switch (value) {
181 default: 182 default:
182 case 0: return tr("Bars"); 183 case 0: return tr("Bars");
852 } 853 }
853 854
854 // SVDEBUG << "RegionLayer::getColourForValue: min " << min << ", max " 855 // SVDEBUG << "RegionLayer::getColourForValue: min " << min << ", max "
855 // << max << ", log " << log << ", value " << val << endl; 856 // << max << ", log " << log << ", value " << val << endl;
856 857
857 QColor solid = ColourMapper(m_colourMap, min, max).map(val); 858 QColor solid = ColourMapper(m_colourMap, m_colourInverted, min, max).map(val);
858 return QColor(solid.red(), solid.green(), solid.blue(), 120); 859 return QColor(solid.red(), solid.green(), solid.blue(), 120);
859 } 860 }
860 861
861 int 862 int
862 RegionLayer::getDefaultColourHint(bool darkbg, bool &impose) 863 RegionLayer::getDefaultColourHint(bool darkbg, bool &impose)
1548 1549
1549 void 1550 void
1550 RegionLayer::toXml(QTextStream &stream, 1551 RegionLayer::toXml(QTextStream &stream,
1551 QString indent, QString extraAttributes) const 1552 QString indent, QString extraAttributes) const
1552 { 1553 {
1553 SingleColourLayer::toXml(stream, indent, extraAttributes + 1554 QString s;
1554 QString(" verticalScale=\"%1\" plotStyle=\"%2\"") 1555
1555 .arg(m_verticalScale) 1556 s += QString("verticalScale=\"%1\" "
1556 .arg(m_plotStyle)); 1557 "plotStyle=\"%2\" ")
1558 .arg(m_verticalScale)
1559 .arg(m_plotStyle);
1560
1561 // New-style colour map attribute, by string id rather than by
1562 // number
1563
1564 s += QString("fillColourMap=\"%1\" ")
1565 .arg(ColourMapper::getColourMapId(m_colourMap));
1566
1567 // Old-style colour map attribute
1568
1569 s += QString("colourMap=\"%1\" ")
1570 .arg(ColourMapper::getBackwardCompatibilityColourMap(m_colourMap));
1571
1572 SingleColourLayer::toXml(stream, indent, extraAttributes + " " + s);
1557 } 1573 }
1558 1574
1559 void 1575 void
1560 RegionLayer::setProperties(const QXmlAttributes &attributes) 1576 RegionLayer::setProperties(const QXmlAttributes &attributes)
1561 { 1577 {
1566 attributes.value("verticalScale").toInt(&ok); 1582 attributes.value("verticalScale").toInt(&ok);
1567 if (ok) setVerticalScale(scale); 1583 if (ok) setVerticalScale(scale);
1568 PlotStyle style = (PlotStyle) 1584 PlotStyle style = (PlotStyle)
1569 attributes.value("plotStyle").toInt(&ok); 1585 attributes.value("plotStyle").toInt(&ok);
1570 if (ok) setPlotStyle(style); 1586 if (ok) setPlotStyle(style);
1571 } 1587
1572 1588 QString colourMapId = attributes.value("fillColourMap");
1573 1589 int colourMap = ColourMapper::getColourMapById(colourMapId);
1590 if (colourMap >= 0) {
1591 setFillColourMap(colourMap);
1592 } else {
1593 colourMap = attributes.value("colourMap").toInt(&ok);
1594 if (ok && colourMap < ColourMapper::getColourMapCount()) {
1595 setFillColourMap(colourMap);
1596 }
1597 }
1598 }
1599
1600