annotate layer/RegionLayer.cpp @ 1428:c9fa16e41664 single-point

Update RegionLayer to updated RegionModel
author Chris Cannam
date Fri, 15 Mar 2019 14:24:22 +0000
parents 62e908518c71
children 8a7c82282fbc
rev   line source
Chris@411 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@411 2
Chris@411 3 /*
Chris@411 4 Sonic Visualiser
Chris@411 5 An audio file viewer and annotation editor.
Chris@411 6 Centre for Digital Music, Queen Mary, University of London.
Chris@411 7 This file copyright 2006-2008 Chris Cannam and QMUL.
Chris@411 8
Chris@411 9 This program is free software; you can redistribute it and/or
Chris@411 10 modify it under the terms of the GNU General Public License as
Chris@411 11 published by the Free Software Foundation; either version 2 of the
Chris@411 12 License, or (at your option) any later version. See the file
Chris@411 13 COPYING included with this distribution for more information.
Chris@411 14 */
Chris@411 15
Chris@411 16 #include "RegionLayer.h"
Chris@411 17
Chris@411 18 #include "data/model/Model.h"
Chris@411 19 #include "base/RealTime.h"
Chris@411 20 #include "base/Profiler.h"
Chris@411 21 #include "base/LogRange.h"
Chris@1078 22
Chris@411 23 #include "ColourDatabase.h"
Chris@427 24 #include "ColourMapper.h"
Chris@701 25 #include "LinearNumericalScale.h"
Chris@701 26 #include "LogNumericalScale.h"
Chris@701 27 #include "LinearColourScale.h"
Chris@701 28 #include "LogColourScale.h"
Chris@1078 29 #include "PaintAssistant.h"
Chris@701 30
Chris@411 31 #include "view/View.h"
Chris@411 32
Chris@411 33 #include "data/model/RegionModel.h"
Chris@411 34
Chris@411 35 #include "widgets/ItemEditDialog.h"
Chris@701 36 #include "widgets/TextAbbrev.h"
Chris@411 37
Chris@411 38 #include <QPainter>
Chris@411 39 #include <QPainterPath>
Chris@411 40 #include <QMouseEvent>
Chris@411 41 #include <QTextStream>
Chris@411 42 #include <QMessageBox>
Chris@411 43
Chris@411 44 #include <iostream>
Chris@411 45 #include <cmath>
Chris@411 46
Chris@411 47 RegionLayer::RegionLayer() :
Chris@411 48 SingleColourLayer(),
Chris@1408 49 m_model(nullptr),
Chris@411 50 m_editing(false),
Chris@846 51 m_dragPointX(0),
Chris@846 52 m_dragPointY(0),
Chris@846 53 m_dragStartX(0),
Chris@846 54 m_dragStartY(0),
Chris@543 55 m_originalPoint(0, 0.0, 0, tr("New Region")),
Chris@543 56 m_editingPoint(0, 0.0, 0, tr("New Region")),
Chris@1408 57 m_editingCommand(nullptr),
Chris@433 58 m_verticalScale(EqualSpaced),
Chris@427 59 m_colourMap(0),
Chris@1362 60 m_colourInverted(false),
Chris@412 61 m_plotStyle(PlotLines)
Chris@411 62 {
Chris@411 63
Chris@411 64 }
Chris@411 65
Chris@411 66 void
Chris@411 67 RegionLayer::setModel(RegionModel *model)
Chris@411 68 {
Chris@411 69 if (m_model == model) return;
Chris@411 70 m_model = model;
Chris@411 71
Chris@411 72 connectSignals(m_model);
Chris@411 73
Chris@433 74 connect(m_model, SIGNAL(modelChanged()), this, SLOT(recalcSpacing()));
Chris@433 75 recalcSpacing();
Chris@433 76
Chris@587 77 // SVDEBUG << "RegionLayer::setModel(" << model << ")" << endl;
Chris@411 78
Chris@610 79 if (m_model && m_model->getRDFTypeURI().endsWith("Segment")) {
Chris@610 80 setPlotStyle(PlotSegmentation);
Chris@610 81 }
Chris@610 82 if (m_model && m_model->getRDFTypeURI().endsWith("Change")) {
Chris@610 83 setPlotStyle(PlotSegmentation);
Chris@610 84 }
Chris@610 85
Chris@411 86 emit modelReplaced();
Chris@411 87 }
Chris@411 88
Chris@411 89 Layer::PropertyList
Chris@411 90 RegionLayer::getProperties() const
Chris@411 91 {
Chris@411 92 PropertyList list = SingleColourLayer::getProperties();
Chris@411 93 list.push_back("Vertical Scale");
Chris@411 94 list.push_back("Scale Units");
Chris@412 95 list.push_back("Plot Type");
Chris@411 96 return list;
Chris@411 97 }
Chris@411 98
Chris@411 99 QString
Chris@411 100 RegionLayer::getPropertyLabel(const PropertyName &name) const
Chris@411 101 {
Chris@411 102 if (name == "Vertical Scale") return tr("Vertical Scale");
Chris@411 103 if (name == "Scale Units") return tr("Scale Units");
Chris@412 104 if (name == "Plot Type") return tr("Plot Type");
Chris@411 105 return SingleColourLayer::getPropertyLabel(name);
Chris@411 106 }
Chris@411 107
Chris@411 108 Layer::PropertyType
Chris@411 109 RegionLayer::getPropertyType(const PropertyName &name) const
Chris@411 110 {
Chris@411 111 if (name == "Scale Units") return UnitsProperty;
Chris@411 112 if (name == "Vertical Scale") return ValueProperty;
Chris@412 113 if (name == "Plot Type") return ValueProperty;
Chris@427 114 if (name == "Colour" && m_plotStyle == PlotSegmentation) return ValueProperty;
Chris@411 115 return SingleColourLayer::getPropertyType(name);
Chris@411 116 }
Chris@411 117
Chris@411 118 QString
Chris@411 119 RegionLayer::getPropertyGroupName(const PropertyName &name) const
Chris@411 120 {
Chris@411 121 if (name == "Vertical Scale" || name == "Scale Units") {
Chris@411 122 return tr("Scale");
Chris@411 123 }
Chris@411 124 return SingleColourLayer::getPropertyGroupName(name);
Chris@411 125 }
Chris@411 126
Chris@411 127 int
Chris@411 128 RegionLayer::getPropertyRangeAndValue(const PropertyName &name,
Chris@411 129 int *min, int *max, int *deflt) const
Chris@411 130 {
Chris@411 131 int val = 0;
Chris@411 132
Chris@427 133 if (name == "Colour" && m_plotStyle == PlotSegmentation) {
Chris@427 134
Chris@427 135 if (min) *min = 0;
Chris@427 136 if (max) *max = ColourMapper::getColourMapCount() - 1;
Chris@427 137 if (deflt) *deflt = 0;
Chris@427 138
Chris@427 139 val = m_colourMap;
Chris@427 140
Chris@427 141 } else if (name == "Plot Type") {
Chris@1266 142
Chris@1266 143 if (min) *min = 0;
Chris@1266 144 if (max) *max = 1;
Chris@412 145 if (deflt) *deflt = 0;
Chris@1266 146
Chris@1266 147 val = int(m_plotStyle);
Chris@412 148
Chris@412 149 } else if (name == "Vertical Scale") {
Chris@1266 150
Chris@1266 151 if (min) *min = 0;
Chris@1266 152 if (max) *max = 3;
Chris@433 153 if (deflt) *deflt = int(EqualSpaced);
Chris@1266 154
Chris@1266 155 val = int(m_verticalScale);
Chris@411 156
Chris@411 157 } else if (name == "Scale Units") {
Chris@411 158
Chris@411 159 if (deflt) *deflt = 0;
Chris@411 160 if (m_model) {
Chris@411 161 val = UnitDatabase::getInstance()->getUnitId
Chris@701 162 (getScaleUnits());
Chris@411 163 }
Chris@411 164
Chris@411 165 } else {
Chris@411 166
Chris@1266 167 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt);
Chris@411 168 }
Chris@411 169
Chris@411 170 return val;
Chris@411 171 }
Chris@411 172
Chris@411 173 QString
Chris@411 174 RegionLayer::getPropertyValueLabel(const PropertyName &name,
Chris@427 175 int value) const
Chris@411 176 {
Chris@427 177 if (name == "Colour" && m_plotStyle == PlotSegmentation) {
Chris@1362 178 return ColourMapper::getColourMapLabel(value);
Chris@427 179 } else if (name == "Plot Type") {
Chris@412 180
Chris@1266 181 switch (value) {
Chris@1266 182 default:
Chris@1266 183 case 0: return tr("Bars");
Chris@1266 184 case 1: return tr("Segmentation");
Chris@1266 185 }
Chris@412 186
Chris@412 187 } else if (name == "Vertical Scale") {
Chris@1266 188 switch (value) {
Chris@1266 189 default:
Chris@1266 190 case 0: return tr("Auto-Align");
Chris@1266 191 case 1: return tr("Equal Spaced");
Chris@1266 192 case 2: return tr("Linear");
Chris@1266 193 case 3: return tr("Log");
Chris@1266 194 }
Chris@411 195 }
Chris@411 196 return SingleColourLayer::getPropertyValueLabel(name, value);
Chris@411 197 }
Chris@411 198
Chris@411 199 void
Chris@411 200 RegionLayer::setProperty(const PropertyName &name, int value)
Chris@411 201 {
Chris@427 202 if (name == "Colour" && m_plotStyle == PlotSegmentation) {
Chris@427 203 setFillColourMap(value);
Chris@427 204 } else if (name == "Plot Type") {
Chris@1266 205 setPlotStyle(PlotStyle(value));
Chris@412 206 } else if (name == "Vertical Scale") {
Chris@1266 207 setVerticalScale(VerticalScale(value));
Chris@411 208 } else if (name == "Scale Units") {
Chris@411 209 if (m_model) {
Chris@411 210 m_model->setScaleUnits
Chris@411 211 (UnitDatabase::getInstance()->getUnitById(value));
Chris@411 212 emit modelChanged();
Chris@411 213 }
Chris@411 214 } else {
Chris@411 215 return SingleColourLayer::setProperty(name, value);
Chris@411 216 }
Chris@411 217 }
Chris@411 218
Chris@411 219 void
Chris@427 220 RegionLayer::setFillColourMap(int map)
Chris@427 221 {
Chris@427 222 if (m_colourMap == map) return;
Chris@427 223 m_colourMap = map;
Chris@427 224 emit layerParametersChanged();
Chris@427 225 }
Chris@427 226
Chris@427 227 void
Chris@412 228 RegionLayer::setPlotStyle(PlotStyle style)
Chris@412 229 {
Chris@412 230 if (m_plotStyle == style) return;
Chris@427 231 bool colourTypeChanged = (style == PlotSegmentation ||
Chris@427 232 m_plotStyle == PlotSegmentation);
Chris@412 233 m_plotStyle = style;
Chris@427 234 if (colourTypeChanged) {
Chris@427 235 emit layerParameterRangesChanged();
Chris@427 236 }
Chris@412 237 emit layerParametersChanged();
Chris@412 238 }
Chris@412 239
Chris@412 240 void
Chris@411 241 RegionLayer::setVerticalScale(VerticalScale scale)
Chris@411 242 {
Chris@411 243 if (m_verticalScale == scale) return;
Chris@411 244 m_verticalScale = scale;
Chris@411 245 emit layerParametersChanged();
Chris@411 246 }
Chris@411 247
Chris@411 248 bool
Chris@918 249 RegionLayer::isLayerScrollable(const LayerGeometryProvider *v) const
Chris@411 250 {
Chris@411 251 QPoint discard;
Chris@411 252 return !v->shouldIlluminateLocalFeatures(this, discard);
Chris@411 253 }
Chris@411 254
Chris@433 255 void
Chris@433 256 RegionLayer::recalcSpacing()
Chris@433 257 {
Chris@433 258 m_spacingMap.clear();
Chris@551 259 m_distributionMap.clear();
Chris@433 260 if (!m_model) return;
Chris@433 261
Chris@587 262 // SVDEBUG << "RegionLayer::recalcSpacing" << endl;
Chris@433 263
Chris@1428 264 EventVector allEvents = m_model->getAllEvents();
Chris@1428 265 for (const Event &e: allEvents) {
Chris@1428 266 m_distributionMap[e.getValue()]++;
Chris@1428 267 // SVDEBUG << "RegionLayer::recalcSpacing: value found: " << e.getValue() << " (now have " << m_distributionMap[e.getValue()] << " of this value)" << endl;
Chris@433 268 }
Chris@433 269
Chris@433 270 int n = 0;
Chris@433 271
Chris@551 272 for (SpacingMap::const_iterator i = m_distributionMap.begin();
Chris@551 273 i != m_distributionMap.end(); ++i) {
Chris@551 274 m_spacingMap[i->first] = n++;
Chris@587 275 // SVDEBUG << "RegionLayer::recalcSpacing: " << i->first << " -> " << m_spacingMap[i->first] << endl;
Chris@433 276 }
Chris@433 277 }
Chris@433 278
Chris@411 279 bool
Chris@905 280 RegionLayer::getValueExtents(double &min, double &max,
Chris@411 281 bool &logarithmic, QString &unit) const
Chris@411 282 {
Chris@411 283 if (!m_model) return false;
Chris@411 284 min = m_model->getValueMinimum();
Chris@411 285 max = m_model->getValueMaximum();
Chris@701 286 unit = getScaleUnits();
Chris@411 287
Chris@411 288 if (m_verticalScale == LogScale) logarithmic = true;
Chris@411 289
Chris@411 290 return true;
Chris@411 291 }
Chris@411 292
Chris@411 293 bool
Chris@905 294 RegionLayer::getDisplayExtents(double &min, double &max) const
Chris@411 295 {
Chris@433 296 if (!m_model ||
Chris@433 297 m_verticalScale == AutoAlignScale ||
Chris@433 298 m_verticalScale == EqualSpaced) return false;
Chris@411 299
Chris@411 300 min = m_model->getValueMinimum();
Chris@411 301 max = m_model->getValueMaximum();
Chris@411 302
Chris@411 303 return true;
Chris@411 304 }
Chris@411 305
Chris@1428 306 EventVector
Chris@918 307 RegionLayer::getLocalPoints(LayerGeometryProvider *v, int x) const
Chris@411 308 {
Chris@1428 309 if (!m_model) return EventVector();
Chris@411 310
Chris@989 311 sv_frame_t frame = v->getFrameForX(x);
Chris@411 312
Chris@1428 313 EventVector local = m_model->getEventsCovering(frame);
Chris@1428 314 if (!local.empty()) return local;
Chris@411 315
Chris@1428 316 int fuzz = ViewManager::scalePixelSize(2);
Chris@1428 317 sv_frame_t start = v->getFrameForX(x - fuzz);
Chris@1428 318 sv_frame_t end = v->getFrameForX(x + fuzz);
Chris@411 319
Chris@1428 320 local = m_model->getEventsStartingWithin(frame, end - frame);
Chris@1428 321 if (!local.empty()) return local;
Chris@411 322
Chris@1428 323 local = m_model->getEventsSpanning(start, frame - start);
Chris@1428 324 if (!local.empty()) return local;
Chris@411 325
Chris@1428 326 return {};
Chris@411 327 }
Chris@411 328
Chris@550 329 bool
Chris@1428 330 RegionLayer::getPointToDrag(LayerGeometryProvider *v, int x, int y, Event &point) const
Chris@550 331 {
Chris@550 332 if (!m_model) return false;
Chris@550 333
Chris@989 334 sv_frame_t frame = v->getFrameForX(x);
Chris@550 335
Chris@1428 336 EventVector onPoints = m_model->getEventsCovering(frame);
Chris@550 337 if (onPoints.empty()) return false;
Chris@550 338
Chris@550 339 int nearestDistance = -1;
Chris@1428 340 for (const auto &p: onPoints) {
Chris@1428 341 int distance = getYForValue(v, p.getValue()) - y;
Chris@550 342 if (distance < 0) distance = -distance;
Chris@550 343 if (nearestDistance == -1 || distance < nearestDistance) {
Chris@550 344 nearestDistance = distance;
Chris@1428 345 point = p;
Chris@550 346 }
Chris@550 347 }
Chris@550 348
Chris@550 349 return true;
Chris@550 350 }
Chris@550 351
Chris@411 352 QString
Chris@909 353 RegionLayer::getLabelPreceding(sv_frame_t frame) const
Chris@552 354 {
Chris@552 355 if (!m_model) return "";
Chris@1428 356 EventVector points = m_model->getEventsStartingWithin
Chris@1428 357 (m_model->getStartFrame(), frame - m_model->getStartFrame());
Chris@1428 358 if (!points.empty()) {
Chris@1428 359 for (auto i = points.rbegin(); i != points.rend(); ++i) {
Chris@1428 360 if (i->getLabel() != QString()) {
Chris@1428 361 return i->getLabel();
Chris@1428 362 }
Chris@1428 363 }
Chris@552 364 }
Chris@1428 365 return QString();
Chris@552 366 }
Chris@552 367
Chris@552 368 QString
Chris@918 369 RegionLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const
Chris@411 370 {
Chris@411 371 int x = pos.x();
Chris@411 372
Chris@411 373 if (!m_model || !m_model->getSampleRate()) return "";
Chris@411 374
Chris@1428 375 EventVector points = getLocalPoints(v, x);
Chris@411 376
Chris@411 377 if (points.empty()) {
Chris@1266 378 if (!m_model->isReady()) {
Chris@1266 379 return tr("In progress");
Chris@1266 380 } else {
Chris@1266 381 return tr("No local points");
Chris@1266 382 }
Chris@411 383 }
Chris@411 384
Chris@1428 385 Event region;
Chris@1428 386 EventVector::iterator i;
Chris@411 387
Chris@413 388 //!!! harmonise with whatever decision is made about point y
Chris@413 389 //!!! coords in paint method
Chris@413 390
Chris@411 391 for (i = points.begin(); i != points.end(); ++i) {
Chris@411 392
Chris@1428 393 int y = getYForValue(v, i->getValue());
Chris@1266 394 int h = 3;
Chris@411 395
Chris@1266 396 if (m_model->getValueQuantization() != 0.0) {
Chris@1428 397 h = y - getYForValue
Chris@1428 398 (v, i->getValue() + m_model->getValueQuantization());
Chris@1266 399 if (h < 3) h = 3;
Chris@1266 400 }
Chris@411 401
Chris@1266 402 if (pos.y() >= y - h && pos.y() <= y) {
Chris@1266 403 region = *i;
Chris@1266 404 break;
Chris@1266 405 }
Chris@411 406 }
Chris@411 407
Chris@411 408 if (i == points.end()) return tr("No local points");
Chris@411 409
Chris@1428 410 RealTime rt = RealTime::frame2RealTime(region.getFrame(),
Chris@1266 411 m_model->getSampleRate());
Chris@1428 412 RealTime rd = RealTime::frame2RealTime(region.getDuration(),
Chris@1266 413 m_model->getSampleRate());
Chris@411 414
Chris@411 415 QString valueText;
Chris@411 416
Chris@1428 417 valueText = tr("%1 %2").arg(region.getValue()).arg(getScaleUnits());
Chris@411 418
Chris@411 419 QString text;
Chris@411 420
Chris@1428 421 if (region.getLabel() == "") {
Chris@1266 422 text = QString(tr("Time:\t%1\nValue:\t%2\nDuration:\t%3\nNo label"))
Chris@1266 423 .arg(rt.toText(true).c_str())
Chris@1266 424 .arg(valueText)
Chris@1266 425 .arg(rd.toText(true).c_str());
Chris@411 426 } else {
Chris@1266 427 text = QString(tr("Time:\t%1\nValue:\t%2\nDuration:\t%3\nLabel:\t%4"))
Chris@1266 428 .arg(rt.toText(true).c_str())
Chris@1266 429 .arg(valueText)
Chris@1266 430 .arg(rd.toText(true).c_str())
Chris@1428 431 .arg(region.getLabel());
Chris@411 432 }
Chris@411 433
Chris@1428 434 pos = QPoint(v->getXForFrame(region.getFrame()),
Chris@1428 435 getYForValue(v, region.getValue()));
Chris@411 436 return text;
Chris@411 437 }
Chris@411 438
Chris@411 439 bool
Chris@918 440 RegionLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
Chris@805 441 int &resolution,
Chris@414 442 SnapType snap) const
Chris@411 443 {
Chris@411 444 if (!m_model) {
Chris@1266 445 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
Chris@411 446 }
Chris@411 447
Chris@411 448 resolution = m_model->getResolution();
Chris@1428 449 EventVector points;
Chris@411 450
Chris@411 451 if (snap == SnapNeighbouring) {
Chris@1266 452
Chris@1266 453 points = getLocalPoints(v, v->getXForFrame(frame));
Chris@1266 454 if (points.empty()) return false;
Chris@1428 455 frame = points.begin()->getFrame();
Chris@1266 456 return true;
Chris@411 457 }
Chris@411 458
Chris@1428 459 //!!! I think this is not quite right - we want to be able to snap
Chris@1428 460 //!!! to events that are nearby but not covering the given frame,
Chris@1428 461 //!!! and I think that worked with the old code. Compare and
Chris@1428 462 //!!! revise.
Chris@1428 463
Chris@1428 464 points = m_model->getEventsCovering(frame);
Chris@905 465 sv_frame_t snapped = frame;
Chris@411 466 bool found = false;
Chris@411 467
Chris@1428 468 for (EventVector::const_iterator i = points.begin();
Chris@1266 469 i != points.end(); ++i) {
Chris@411 470
Chris@1266 471 if (snap == SnapRight) {
Chris@411 472
Chris@414 473 // The best frame to snap to is the end frame of whichever
Chris@414 474 // feature we would have snapped to the start frame of if
Chris@414 475 // we had been snapping left.
Chris@414 476
Chris@1428 477 if (i->getFrame() <= frame) {
Chris@1428 478 if (i->getFrame() + i->getDuration() > frame) {
Chris@1428 479 snapped = i->getFrame() + i->getDuration();
Chris@414 480 found = true; // don't break, as the next may be better
Chris@414 481 }
Chris@414 482 } else {
Chris@414 483 if (!found) {
Chris@1428 484 snapped = i->getFrame();
Chris@414 485 found = true;
Chris@414 486 }
Chris@414 487 break;
Chris@414 488 }
Chris@411 489
Chris@1266 490 } else if (snap == SnapLeft) {
Chris@411 491
Chris@1428 492 if (i->getFrame() <= frame) {
Chris@1428 493 snapped = i->getFrame();
Chris@1266 494 found = true; // don't break, as the next may be better
Chris@1266 495 } else {
Chris@1266 496 break;
Chris@1266 497 }
Chris@411 498
Chris@1266 499 } else { // nearest
Chris@411 500
Chris@1428 501 EventVector::const_iterator j = i;
Chris@1266 502 ++j;
Chris@411 503
Chris@1266 504 if (j == points.end()) {
Chris@411 505
Chris@1428 506 snapped = i->getFrame();
Chris@1266 507 found = true;
Chris@1266 508 break;
Chris@411 509
Chris@1428 510 } else if (j->getFrame() >= frame) {
Chris@411 511
Chris@1428 512 if (j->getFrame() - frame < frame - i->getFrame()) {
Chris@1428 513 snapped = j->getFrame();
Chris@1266 514 } else {
Chris@1428 515 snapped = i->getFrame();
Chris@1266 516 }
Chris@1266 517 found = true;
Chris@1266 518 break;
Chris@1266 519 }
Chris@1266 520 }
Chris@411 521 }
Chris@411 522
Chris@411 523 frame = snapped;
Chris@411 524 return found;
Chris@411 525 }
Chris@411 526
Chris@559 527 bool
Chris@918 528 RegionLayer::snapToSimilarFeature(LayerGeometryProvider *v, sv_frame_t &frame,
Chris@805 529 int &resolution,
Chris@559 530 SnapType snap) const
Chris@559 531 {
Chris@559 532 if (!m_model) {
Chris@1266 533 return Layer::snapToSimilarFeature(v, frame, resolution, snap);
Chris@559 534 }
Chris@559 535
Chris@559 536 resolution = m_model->getResolution();
Chris@559 537
Chris@1428 538 /*!!! todo: overhaul the logic of this function (and supporting
Chris@1428 539 apis in EventSeries / RegionModel)
Chris@559 540
Chris@1428 541 const EventVector &points = m_model->getPoints();
Chris@1428 542 EventVector close = m_model->getPoints(frame, frame);
Chris@1428 543 */
Chris@1428 544 EventVector points = m_model->getAllEvents();
Chris@1428 545 EventVector close = {};
Chris@1428 546
Chris@1428 547 EventVector::const_iterator i;
Chris@559 548
Chris@905 549 sv_frame_t matchframe = frame;
Chris@905 550 double matchvalue = 0.f;
Chris@559 551
Chris@559 552 for (i = close.begin(); i != close.end(); ++i) {
Chris@1428 553 if (i->getFrame() > frame) break;
Chris@1428 554 matchvalue = i->getValue();
Chris@1428 555 matchframe = i->getFrame();
Chris@559 556 }
Chris@559 557
Chris@905 558 sv_frame_t snapped = frame;
Chris@559 559 bool found = false;
Chris@559 560 bool distant = false;
Chris@905 561 double epsilon = 0.0001;
Chris@559 562
Chris@559 563 i = close.begin();
Chris@559 564
Chris@559 565 // Scan through the close points first, then the more distant ones
Chris@846 566 // if no suitable close one is found. So the while-termination
Chris@846 567 // condition here can only happen once i has passed through the
Chris@846 568 // whole of the close container and then the whole of the separate
Chris@846 569 // points container. The two iterators are totally distinct, but
Chris@846 570 // have the same type so we cheekily use the same variable and a
Chris@846 571 // single loop for both.
Chris@559 572
Chris@559 573 while (i != points.end()) {
Chris@559 574
Chris@846 575 if (!distant) {
Chris@846 576 if (i == close.end()) {
Chris@846 577 // switch from the close container to the points container
Chris@846 578 i = points.begin();
Chris@846 579 distant = true;
Chris@846 580 }
Chris@559 581 }
Chris@559 582
Chris@1266 583 if (snap == SnapRight) {
Chris@559 584
Chris@1428 585 if (i->getFrame() > matchframe &&
Chris@1428 586 fabs(i->getValue() - matchvalue) < epsilon) {
Chris@1428 587 snapped = i->getFrame();
Chris@1266 588 found = true;
Chris@1266 589 break;
Chris@1266 590 }
Chris@559 591
Chris@1266 592 } else if (snap == SnapLeft) {
Chris@559 593
Chris@1428 594 if (i->getFrame() < matchframe) {
Chris@1428 595 if (fabs(i->getValue() - matchvalue) < epsilon) {
Chris@1428 596 snapped = i->getFrame();
Chris@559 597 found = true; // don't break, as the next may be better
Chris@559 598 }
Chris@1266 599 } else if (found || distant) {
Chris@1266 600 break;
Chris@1266 601 }
Chris@559 602
Chris@1266 603 } else {
Chris@559 604 // no other snap types supported
Chris@1266 605 }
Chris@559 606
Chris@559 607 ++i;
Chris@559 608 }
Chris@559 609
Chris@559 610 frame = snapped;
Chris@559 611 return found;
Chris@559 612 }
Chris@559 613
Chris@701 614 QString
Chris@701 615 RegionLayer::getScaleUnits() const
Chris@701 616 {
Chris@701 617 if (m_model) return m_model->getScaleUnits();
Chris@701 618 else return "";
Chris@701 619 }
Chris@701 620
Chris@411 621 void
Chris@918 622 RegionLayer::getScaleExtents(LayerGeometryProvider *v, double &min, double &max, bool &log) const
Chris@411 623 {
Chris@411 624 min = 0.0;
Chris@411 625 max = 0.0;
Chris@411 626 log = false;
Chris@411 627
Chris@411 628 QString queryUnits;
Chris@701 629 queryUnits = getScaleUnits();
Chris@411 630
Chris@411 631 if (m_verticalScale == AutoAlignScale) {
Chris@411 632
Chris@411 633 if (!v->getValueExtents(queryUnits, min, max, log)) {
Chris@411 634
Chris@411 635 min = m_model->getValueMinimum();
Chris@411 636 max = m_model->getValueMaximum();
Chris@411 637
Chris@682 638 // cerr << "RegionLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << endl;
Chris@411 639
Chris@411 640 } else if (log) {
Chris@411 641
Chris@411 642 LogRange::mapRange(min, max);
Chris@411 643
Chris@682 644 // cerr << "RegionLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << endl;
Chris@411 645
Chris@411 646 }
Chris@411 647
Chris@433 648 } else if (m_verticalScale == EqualSpaced) {
Chris@433 649
Chris@433 650 if (!m_spacingMap.empty()) {
Chris@433 651 SpacingMap::const_iterator i = m_spacingMap.begin();
Chris@433 652 min = i->second;
Chris@433 653 i = m_spacingMap.end();
Chris@433 654 --i;
Chris@433 655 max = i->second;
Chris@682 656 // cerr << "RegionLayer[" << this << "]::getScaleExtents: equal spaced; min = " << min << ", max = " << max << ", log = " << log << endl;
Chris@433 657 }
Chris@433 658
Chris@411 659 } else {
Chris@411 660
Chris@411 661 min = m_model->getValueMinimum();
Chris@411 662 max = m_model->getValueMaximum();
Chris@411 663
Chris@411 664 if (m_verticalScale == LogScale) {
Chris@411 665 LogRange::mapRange(min, max);
Chris@411 666 log = true;
Chris@411 667 }
Chris@411 668 }
Chris@411 669
Chris@411 670 if (max == min) max = min + 1.0;
Chris@411 671 }
Chris@411 672
Chris@411 673 int
Chris@918 674 RegionLayer::spacingIndexToY(LayerGeometryProvider *v, int i) const
Chris@542 675 {
Chris@918 676 int h = v->getPaintHeight();
Chris@905 677 int n = int(m_spacingMap.size());
Chris@542 678 // this maps from i (spacing of the value from the spacing
Chris@542 679 // map) and n (number of region types) to y
Chris@542 680 int y = h - (((h * i) / n) + (h / (2 * n)));
Chris@542 681 return y;
Chris@542 682 }
Chris@542 683
Chris@905 684 double
Chris@918 685 RegionLayer::yToSpacingIndex(LayerGeometryProvider *v, int y) const
Chris@542 686 {
Chris@905 687 // we return an inexact result here (double rather than int)
Chris@918 688 int h = v->getPaintHeight();
Chris@905 689 int n = int(m_spacingMap.size());
Chris@551 690 // from y = h - ((h * i) / n) + (h / (2 * n)) as above (vh taking place of i)
Chris@905 691 double vh = double(2*h*n - h - 2*n*y) / double(2*h);
Chris@542 692 return vh;
Chris@542 693 }
Chris@542 694
Chris@542 695 int
Chris@918 696 RegionLayer::getYForValue(LayerGeometryProvider *v, double val) const
Chris@411 697 {
Chris@905 698 double min = 0.0, max = 0.0;
Chris@411 699 bool logarithmic = false;
Chris@918 700 int h = v->getPaintHeight();
Chris@411 701
Chris@433 702 if (m_verticalScale == EqualSpaced) {
Chris@433 703
Chris@433 704 if (m_spacingMap.empty()) return h/2;
Chris@433 705
Chris@433 706 SpacingMap::const_iterator i = m_spacingMap.lower_bound(val);
Chris@433 707 //!!! what now, if i->first != v?
Chris@433 708
Chris@542 709 int y = spacingIndexToY(v, i->second);
Chris@433 710
Chris@587 711 // SVDEBUG << "RegionLayer::getYForValue: value " << val << " -> i->second " << i->second << " -> y " << y << endl;
Chris@542 712 return y;
Chris@433 713
Chris@433 714
Chris@433 715 } else {
Chris@433 716
Chris@433 717 getScaleExtents(v, min, max, logarithmic);
Chris@411 718
Chris@682 719 // cerr << "RegionLayer[" << this << "]::getYForValue(" << val << "): min = " << min << ", max = " << max << ", log = " << logarithmic << endl;
Chris@682 720 // cerr << "h = " << h << ", margin = " << margin << endl;
Chris@411 721
Chris@433 722 if (logarithmic) {
Chris@433 723 val = LogRange::map(val);
Chris@433 724 }
Chris@433 725
Chris@433 726 return int(h - ((val - min) * h) / (max - min));
Chris@411 727 }
Chris@411 728 }
Chris@411 729
Chris@905 730 double
Chris@918 731 RegionLayer::getValueForY(LayerGeometryProvider *v, int y) const
Chris@701 732 {
Chris@701 733 return getValueForY(v, y, -1);
Chris@701 734 }
Chris@701 735
Chris@905 736 double
Chris@918 737 RegionLayer::getValueForY(LayerGeometryProvider *v, int y, int avoid) const
Chris@542 738 {
Chris@905 739 double min = 0.0, max = 0.0;
Chris@542 740 bool logarithmic = false;
Chris@918 741 int h = v->getPaintHeight();
Chris@542 742
Chris@542 743 if (m_verticalScale == EqualSpaced) {
Chris@542 744
Chris@542 745 // if we're equal spaced, we probably want to snap to the
Chris@542 746 // nearest item when close to it, and give some notification
Chris@542 747 // that we're doing so
Chris@542 748
Chris@542 749 if (m_spacingMap.empty()) return 1.f;
Chris@542 750
Chris@542 751 // n is the number of distinct regions. if we are close to
Chris@542 752 // one of the m/n divisions in the y scale, we should snap to
Chris@542 753 // the value of the mth region.
Chris@542 754
Chris@905 755 double vh = yToSpacingIndex(v, y);
Chris@542 756
Chris@542 757 // spacings in the map are integral, so find the closest one,
Chris@542 758 // map it back to its y coordinate, and see how far we are
Chris@542 759 // from it
Chris@542 760
Chris@905 761 int n = int(m_spacingMap.size());
Chris@905 762 int ivh = int(lrint(vh));
Chris@542 763 if (ivh < 0) ivh = 0;
Chris@542 764 if (ivh > n-1) ivh = n-1;
Chris@542 765 int iy = spacingIndexToY(v, ivh);
Chris@542 766
Chris@542 767 int dist = iy - y;
Chris@542 768 int gap = h / n; // between region lines
Chris@542 769
Chris@682 770 // cerr << "getValueForY: y = " << y << ", vh = " << vh << ", ivh = " << ivh << " of " << n << ", iy = " << iy << ", dist = " << dist << ", gap = " << gap << endl;
Chris@542 771
Chris@542 772 SpacingMap::const_iterator i = m_spacingMap.begin();
Chris@542 773 while (i != m_spacingMap.end()) {
Chris@542 774 if (i->second == ivh) break;
Chris@542 775 ++i;
Chris@542 776 }
Chris@542 777 if (i == m_spacingMap.end()) i = m_spacingMap.begin();
Chris@542 778
Chris@682 779 // cerr << "nearest existing value = " << i->first << " at " << iy << endl;
Chris@551 780
Chris@905 781 double val = 0;
Chris@542 782
Chris@682 783 // cerr << "note: avoid = " << avoid << ", i->second = " << i->second << endl;
Chris@551 784
Chris@551 785 if (dist < -gap/3 &&
Chris@551 786 ((avoid == -1) ||
Chris@551 787 (avoid != i->second && avoid != i->second - 1))) {
Chris@542 788 // bisect gap to prior
Chris@542 789 if (i == m_spacingMap.begin()) {
Chris@542 790 val = i->first - 1.f;
Chris@682 791 // cerr << "extended down to " << val << endl;
Chris@542 792 } else {
Chris@542 793 SpacingMap::const_iterator j = i;
Chris@542 794 --j;
Chris@542 795 val = (i->first + j->first) / 2;
Chris@682 796 // cerr << "bisected down to " << val << endl;
Chris@542 797 }
Chris@551 798 } else if (dist > gap/3 &&
Chris@551 799 ((avoid == -1) ||
Chris@551 800 (avoid != i->second && avoid != i->second + 1))) {
Chris@542 801 // bisect gap to following
Chris@542 802 SpacingMap::const_iterator j = i;
Chris@542 803 ++j;
Chris@542 804 if (j == m_spacingMap.end()) {
Chris@542 805 val = i->first + 1.f;
Chris@682 806 // cerr << "extended up to " << val << endl;
Chris@542 807 } else {
Chris@542 808 val = (i->first + j->first) / 2;
Chris@682 809 // cerr << "bisected up to " << val << endl;
Chris@542 810 }
Chris@551 811 } else {
Chris@551 812 // snap
Chris@551 813 val = i->first;
Chris@682 814 // cerr << "snapped to " << val << endl;
Chris@542 815 }
Chris@542 816
Chris@542 817 return val;
Chris@542 818
Chris@542 819 } else {
Chris@542 820
Chris@542 821 getScaleExtents(v, min, max, logarithmic);
Chris@542 822
Chris@905 823 double val = min + (double(h - y) * double(max - min)) / h;
Chris@542 824
Chris@542 825 if (logarithmic) {
Chris@905 826 val = pow(10.0, val);
Chris@542 827 }
Chris@542 828
Chris@542 829 return val;
Chris@542 830 }
Chris@542 831 }
Chris@542 832
Chris@427 833 QColor
Chris@918 834 RegionLayer::getColourForValue(LayerGeometryProvider *v, double val) const
Chris@427 835 {
Chris@905 836 double min, max;
Chris@427 837 bool log;
Chris@427 838 getScaleExtents(v, min, max, log);
Chris@427 839
Chris@427 840 if (min > max) std::swap(min, max);
Chris@427 841 if (max == min) max = min + 1;
Chris@427 842
Chris@427 843 if (log) {
Chris@427 844 LogRange::mapRange(min, max);
Chris@427 845 val = LogRange::map(val);
Chris@427 846 }
Chris@427 847
Chris@587 848 // SVDEBUG << "RegionLayer::getColourForValue: min " << min << ", max "
Chris@585 849 // << max << ", log " << log << ", value " << val << endl;
Chris@427 850
Chris@1362 851 QColor solid = ColourMapper(m_colourMap, m_colourInverted, min, max).map(val);
Chris@427 852 return QColor(solid.red(), solid.green(), solid.blue(), 120);
Chris@427 853 }
Chris@427 854
Chris@427 855 int
Chris@427 856 RegionLayer::getDefaultColourHint(bool darkbg, bool &impose)
Chris@427 857 {
Chris@427 858 impose = false;
Chris@427 859 return ColourDatabase::getInstance()->getColourIndex
Chris@427 860 (QString(darkbg ? "Bright Blue" : "Blue"));
Chris@427 861 }
Chris@427 862
Chris@411 863 void
Chris@916 864 RegionLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
Chris@411 865 {
Chris@411 866 if (!m_model || !m_model->isOK()) return;
Chris@411 867
Chris@905 868 sv_samplerate_t sampleRate = m_model->getSampleRate();
Chris@411 869 if (!sampleRate) return;
Chris@411 870
Chris@411 871 // Profiler profiler("RegionLayer::paint", true);
Chris@411 872
Chris@552 873 int x0 = rect.left() - 40, x1 = rect.right();
Chris@411 874
Chris@1409 875 sv_frame_t wholeFrame0 = v->getFrameForX(0);
Chris@1409 876 sv_frame_t wholeFrame1 = v->getFrameForX(v->getPaintWidth());
Chris@1409 877
Chris@1428 878 EventVector points(m_model->getEventsSpanning(wholeFrame0,
Chris@1428 879 wholeFrame1 - wholeFrame0));
Chris@411 880 if (points.empty()) return;
Chris@411 881
Chris@411 882 paint.setPen(getBaseQColor());
Chris@411 883
Chris@411 884 QColor brushColour(getBaseQColor());
Chris@411 885 brushColour.setAlpha(80);
Chris@411 886
Chris@587 887 // SVDEBUG << "RegionLayer::paint: resolution is "
Chris@1266 888 // << m_model->getResolution() << " frames" << endl;
Chris@411 889
Chris@905 890 double min = m_model->getValueMinimum();
Chris@905 891 double max = m_model->getValueMaximum();
Chris@411 892 if (max == min) max = min + 1.0;
Chris@411 893
Chris@411 894 QPoint localPos;
Chris@1428 895 Event illuminatePoint(0);
Chris@551 896 bool shouldIlluminate = false;
Chris@411 897
Chris@411 898 if (v->shouldIlluminateLocalFeatures(this, localPos)) {
Chris@551 899 shouldIlluminate = getPointToDrag(v, localPos.x(), localPos.y(),
Chris@551 900 illuminatePoint);
Chris@411 901 }
Chris@411 902
Chris@411 903 paint.save();
Chris@411 904 paint.setRenderHint(QPainter::Antialiasing, false);
Chris@411 905
Chris@413 906 //!!! point y coords if model does not haveDistinctValues() should
Chris@413 907 //!!! be assigned to avoid overlaps
Chris@413 908
Chris@413 909 //!!! if it does have distinct values, we should still ensure y
Chris@413 910 //!!! coord is never completely flat on the top or bottom
Chris@413 911
Chris@550 912 int fontHeight = paint.fontMetrics().height();
Chris@550 913
Chris@1428 914 for (EventVector::const_iterator i = points.begin();
Chris@1266 915 i != points.end(); ++i) {
Chris@411 916
Chris@1428 917 const Event &p(*i);
Chris@411 918
Chris@1428 919 int x = v->getXForFrame(p.getFrame());
Chris@1428 920 int w = v->getXForFrame(p.getFrame() + p.getDuration()) - x;
Chris@1428 921 int y = getYForValue(v, p.getValue());
Chris@1266 922 int h = 9;
Chris@1266 923 int ex = x + w;
Chris@427 924
Chris@1409 925 int gap = v->scalePixelSize(2);
Chris@1409 926
Chris@1428 927 EventVector::const_iterator j = i;
Chris@1266 928 ++j;
Chris@427 929
Chris@1266 930 if (j != points.end()) {
Chris@1428 931 const Event &q(*j);
Chris@1428 932 int nx = v->getXForFrame(q.getFrame());
Chris@433 933 if (nx < ex) ex = nx;
Chris@427 934 }
Chris@427 935
Chris@1266 936 if (m_model->getValueQuantization() != 0.0) {
Chris@1428 937 h = y - getYForValue
Chris@1428 938 (v, p.getValue() + m_model->getValueQuantization());
Chris@1266 939 if (h < 3) h = 3;
Chris@1266 940 }
Chris@411 941
Chris@1266 942 if (w < 1) w = 1;
Chris@411 943
Chris@1266 944 if (m_plotStyle == PlotSegmentation) {
Chris@918 945 paint.setPen(getForegroundQColor(v->getView()));
Chris@1428 946 paint.setBrush(getColourForValue(v, p.getValue()));
Chris@427 947 } else {
Chris@427 948 paint.setPen(getBaseQColor());
Chris@427 949 paint.setBrush(brushColour);
Chris@427 950 }
Chris@427 951
Chris@1266 952 if (m_plotStyle == PlotSegmentation) {
Chris@427 953
Chris@1266 954 if (ex <= x) continue;
Chris@427 955
Chris@1428 956 if (!shouldIlluminate || illuminatePoint != p) {
Chris@551 957
Chris@918 958 paint.setPen(QPen(getForegroundQColor(v->getView()), 1));
Chris@918 959 paint.drawLine(x, 0, x, v->getPaintHeight());
Chris@551 960 paint.setPen(Qt::NoPen);
Chris@552 961
Chris@552 962 } else {
Chris@918 963 paint.setPen(QPen(getForegroundQColor(v->getView()), 2));
Chris@551 964 }
Chris@427 965
Chris@1409 966 paint.drawRect(x, -1, ex - x, v->getPaintHeight() + gap);
Chris@427 967
Chris@1266 968 } else {
Chris@427 969
Chris@1428 970 if (shouldIlluminate && illuminatePoint == p) {
Chris@551 971
Chris@551 972 paint.setPen(v->getForeground());
Chris@551 973 paint.setBrush(v->getForeground());
Chris@551 974
Chris@1428 975 QString vlabel =
Chris@1428 976 QString("%1%2").arg(p.getValue()).arg(getScaleUnits());
Chris@1078 977 PaintAssistant::drawVisibleText(v, paint,
Chris@1409 978 x - paint.fontMetrics().width(vlabel) - gap,
Chris@551 979 y + paint.fontMetrics().height()/2
Chris@551 980 - paint.fontMetrics().descent(),
Chris@1078 981 vlabel, PaintAssistant::OutlinedText);
Chris@551 982
Chris@551 983 QString hlabel = RealTime::frame2RealTime
Chris@1428 984 (p.getFrame(), m_model->getSampleRate()).toText(true).c_str();
Chris@1078 985 PaintAssistant::drawVisibleText(v, paint,
Chris@551 986 x,
Chris@1409 987 y - h/2 - paint.fontMetrics().descent() - gap,
Chris@1078 988 hlabel, PaintAssistant::OutlinedText);
Chris@427 989 }
Chris@551 990
Chris@427 991 paint.drawLine(x, y-1, x + w, y-1);
Chris@427 992 paint.drawLine(x, y+1, x + w, y+1);
Chris@427 993 paint.drawLine(x, y - h/2, x, y + h/2);
Chris@427 994 paint.drawLine(x+w, y - h/2, x + w, y + h/2);
Chris@427 995 }
Chris@552 996 }
Chris@552 997
Chris@552 998 int nextLabelMinX = -100;
Chris@552 999 int lastLabelY = 0;
Chris@552 1000
Chris@1428 1001 for (EventVector::const_iterator i = points.begin();
Chris@1266 1002 i != points.end(); ++i) {
Chris@552 1003
Chris@1428 1004 const Event &p(*i);
Chris@552 1005
Chris@1428 1006 int x = v->getXForFrame(p.getFrame());
Chris@1428 1007 int w = v->getXForFrame(p.getFrame() + p.getDuration()) - x;
Chris@1428 1008 int y = getYForValue(v, p.getValue());
Chris@552 1009
Chris@1428 1010 QString label = p.getLabel();
Chris@1409 1011 if (label == "") {
Chris@1428 1012 label = QString("%1%2").arg(p.getValue()).arg(getScaleUnits());
Chris@1409 1013 }
Chris@1409 1014 int labelWidth = paint.fontMetrics().width(label);
Chris@1409 1015
Chris@1409 1016 int gap = v->scalePixelSize(2);
Chris@1409 1017
Chris@1409 1018 if (m_plotStyle == PlotSegmentation) {
Chris@1409 1019 if ((x + w < x0 && x + labelWidth + gap < x0) || x > x1) {
Chris@1409 1020 continue;
Chris@1409 1021 }
Chris@1409 1022 } else {
Chris@1409 1023 if (x + w < x0 || x - labelWidth - gap > x1) {
Chris@1409 1024 continue;
Chris@1409 1025 }
Chris@1409 1026 }
Chris@1409 1027
Chris@552 1028 bool illuminated = false;
Chris@552 1029
Chris@1266 1030 if (m_plotStyle != PlotSegmentation) {
Chris@1428 1031 if (shouldIlluminate && illuminatePoint == p) {
Chris@552 1032 illuminated = true;
Chris@552 1033 }
Chris@552 1034 }
Chris@427 1035
Chris@551 1036 if (!illuminated) {
Chris@551 1037
Chris@552 1038 int labelX, labelY;
Chris@552 1039
Chris@551 1040 if (m_plotStyle != PlotSegmentation) {
Chris@1409 1041 labelX = x - labelWidth - gap;
Chris@552 1042 labelY = y + paint.fontMetrics().height()/2
Chris@552 1043 - paint.fontMetrics().descent();
Chris@551 1044 } else {
Chris@552 1045 labelX = x + 5;
Chris@552 1046 labelY = v->getTextLabelHeight(this, paint);
Chris@552 1047 if (labelX < nextLabelMinX) {
Chris@918 1048 if (lastLabelY < v->getPaintHeight()/2) {
Chris@552 1049 labelY = lastLabelY + fontHeight;
Chris@552 1050 }
Chris@552 1051 }
Chris@552 1052 lastLabelY = labelY;
Chris@1409 1053 nextLabelMinX = labelX + labelWidth;
Chris@551 1054 }
Chris@552 1055
Chris@1409 1056 PaintAssistant::drawVisibleText(v, paint, labelX, labelY, label,
Chris@1409 1057 PaintAssistant::OutlinedText);
Chris@550 1058 }
Chris@411 1059 }
Chris@411 1060
Chris@411 1061 paint.restore();
Chris@411 1062 }
Chris@411 1063
Chris@701 1064 int
Chris@918 1065 RegionLayer::getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &paint) const
Chris@701 1066 {
Chris@701 1067 if (!m_model ||
Chris@701 1068 m_verticalScale == AutoAlignScale ||
Chris@701 1069 m_verticalScale == EqualSpaced) {
Chris@701 1070 return 0;
Chris@701 1071 } else if (m_plotStyle == PlotSegmentation) {
Chris@701 1072 if (m_verticalScale == LogScale) {
Chris@701 1073 return LogColourScale().getWidth(v, paint);
Chris@701 1074 } else {
Chris@701 1075 return LinearColourScale().getWidth(v, paint);
Chris@701 1076 }
Chris@701 1077 } else {
Chris@701 1078 if (m_verticalScale == LogScale) {
Chris@701 1079 return LogNumericalScale().getWidth(v, paint);
Chris@701 1080 } else {
Chris@701 1081 return LinearNumericalScale().getWidth(v, paint);
Chris@701 1082 }
Chris@701 1083 }
Chris@701 1084 }
Chris@701 1085
Chris@701 1086 void
Chris@918 1087 RegionLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect) const
Chris@701 1088 {
Chris@1428 1089 if (!m_model || m_model->isEmpty()) return;
Chris@701 1090
Chris@701 1091 QString unit;
Chris@905 1092 double min, max;
Chris@701 1093 bool logarithmic;
Chris@701 1094
Chris@701 1095 int w = getVerticalScaleWidth(v, false, paint);
Chris@701 1096
Chris@701 1097 if (m_plotStyle == PlotSegmentation) {
Chris@701 1098
Chris@701 1099 getValueExtents(min, max, logarithmic, unit);
Chris@701 1100
Chris@701 1101 if (logarithmic) {
Chris@701 1102 LogRange::mapRange(min, max);
Chris@701 1103 LogColourScale().paintVertical(v, this, paint, 0, min, max);
Chris@701 1104 } else {
Chris@701 1105 LinearColourScale().paintVertical(v, this, paint, 0, min, max);
Chris@701 1106 }
Chris@701 1107
Chris@701 1108 } else {
Chris@701 1109
Chris@701 1110 getScaleExtents(v, min, max, logarithmic);
Chris@701 1111
Chris@701 1112 if (logarithmic) {
Chris@701 1113 LogNumericalScale().paintVertical(v, this, paint, 0, min, max);
Chris@701 1114 } else {
Chris@701 1115 LinearNumericalScale().paintVertical(v, this, paint, 0, min, max);
Chris@701 1116 }
Chris@701 1117 }
Chris@701 1118
Chris@701 1119 if (getScaleUnits() != "") {
Chris@701 1120 int mw = w - 5;
Chris@701 1121 paint.drawText(5,
Chris@701 1122 5 + paint.fontMetrics().ascent(),
Chris@701 1123 TextAbbrev::abbreviate(getScaleUnits(),
Chris@701 1124 paint.fontMetrics(),
Chris@701 1125 mw));
Chris@701 1126 }
Chris@701 1127 }
Chris@701 1128
Chris@411 1129 void
Chris@918 1130 RegionLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e)
Chris@411 1131 {
Chris@411 1132 if (!m_model) return;
Chris@411 1133
Chris@989 1134 sv_frame_t frame = v->getFrameForX(e->x());
Chris@411 1135 if (frame < 0) frame = 0;
Chris@411 1136 frame = frame / m_model->getResolution() * m_model->getResolution();
Chris@411 1137
Chris@905 1138 double value = getValueForY(v, e->y());
Chris@411 1139
Chris@1428 1140 m_editingPoint = Event(frame, float(value), 0, "");
Chris@411 1141 m_originalPoint = m_editingPoint;
Chris@411 1142
Chris@411 1143 if (m_editingCommand) finish(m_editingCommand);
Chris@1428 1144 m_editingCommand = new ChangeEventsCommand(m_model,
Chris@543 1145 tr("Draw Region"));
Chris@1428 1146 m_editingCommand->add(m_editingPoint);
Chris@411 1147
Chris@550 1148 recalcSpacing();
Chris@550 1149
Chris@411 1150 m_editing = true;
Chris@411 1151 }
Chris@411 1152
Chris@411 1153 void
Chris@918 1154 RegionLayer::drawDrag(LayerGeometryProvider *v, QMouseEvent *e)
Chris@411 1155 {
Chris@411 1156 if (!m_model || !m_editing) return;
Chris@411 1157
Chris@905 1158 sv_frame_t frame = v->getFrameForX(e->x());
Chris@411 1159 if (frame < 0) frame = 0;
Chris@411 1160 frame = frame / m_model->getResolution() * m_model->getResolution();
Chris@411 1161
Chris@1428 1162 double newValue = m_editingPoint.getValue();
Chris@542 1163 if (m_verticalScale != EqualSpaced) newValue = getValueForY(v, e->y());
Chris@411 1164
Chris@1428 1165 sv_frame_t newFrame = m_editingPoint.getFrame();
Chris@905 1166 sv_frame_t newDuration = frame - newFrame;
Chris@411 1167 if (newDuration < 0) {
Chris@411 1168 newFrame = frame;
Chris@411 1169 newDuration = -newDuration;
Chris@411 1170 } else if (newDuration == 0) {
Chris@411 1171 newDuration = 1;
Chris@411 1172 }
Chris@411 1173
Chris@1428 1174 m_editingCommand->remove(m_editingPoint);
Chris@1428 1175 m_editingPoint = m_editingPoint
Chris@1428 1176 .withFrame(newFrame)
Chris@1428 1177 .withValue(float(newValue))
Chris@1428 1178 .withDuration(newDuration);
Chris@1428 1179 m_editingCommand->add(m_editingPoint);
Chris@550 1180
Chris@551 1181 recalcSpacing();
Chris@411 1182 }
Chris@411 1183
Chris@411 1184 void
Chris@918 1185 RegionLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *)
Chris@411 1186 {
Chris@411 1187 if (!m_model || !m_editing) return;
Chris@411 1188 finish(m_editingCommand);
Chris@1408 1189 m_editingCommand = nullptr;
Chris@411 1190 m_editing = false;
Chris@550 1191
Chris@550 1192 recalcSpacing();
Chris@411 1193 }
Chris@411 1194
Chris@411 1195 void
Chris@918 1196 RegionLayer::eraseStart(LayerGeometryProvider *v, QMouseEvent *e)
Chris@411 1197 {
Chris@411 1198 if (!m_model) return;
Chris@411 1199
Chris@550 1200 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return;
Chris@411 1201
Chris@411 1202 if (m_editingCommand) {
Chris@1266 1203 finish(m_editingCommand);
Chris@1408 1204 m_editingCommand = nullptr;
Chris@411 1205 }
Chris@411 1206
Chris@411 1207 m_editing = true;
Chris@550 1208 recalcSpacing();
Chris@411 1209 }
Chris@411 1210
Chris@411 1211 void
Chris@918 1212 RegionLayer::eraseDrag(LayerGeometryProvider *, QMouseEvent *)
Chris@411 1213 {
Chris@411 1214 }
Chris@411 1215
Chris@411 1216 void
Chris@918 1217 RegionLayer::eraseEnd(LayerGeometryProvider *v, QMouseEvent *e)
Chris@411 1218 {
Chris@411 1219 if (!m_model || !m_editing) return;
Chris@411 1220
Chris@411 1221 m_editing = false;
Chris@551 1222
Chris@1428 1223 Event p(0);
Chris@550 1224 if (!getPointToDrag(v, e->x(), e->y(), p)) return;
Chris@1428 1225 if (p.getFrame() != m_editingPoint.getFrame() ||
Chris@1428 1226 p.getValue() != m_editingPoint.getValue()) return;
Chris@411 1227
Chris@1428 1228 m_editingCommand = new ChangeEventsCommand
Chris@543 1229 (m_model, tr("Erase Region"));
Chris@411 1230
Chris@1428 1231 m_editingCommand->remove(m_editingPoint);
Chris@411 1232
Chris@411 1233 finish(m_editingCommand);
Chris@1408 1234 m_editingCommand = nullptr;
Chris@411 1235 m_editing = false;
Chris@550 1236 recalcSpacing();
Chris@411 1237 }
Chris@411 1238
Chris@411 1239 void
Chris@918 1240 RegionLayer::editStart(LayerGeometryProvider *v, QMouseEvent *e)
Chris@411 1241 {
Chris@411 1242 if (!m_model) return;
Chris@411 1243
Chris@550 1244 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) {
Chris@550 1245 return;
Chris@550 1246 }
Chris@550 1247
Chris@1428 1248 m_dragPointX = v->getXForFrame(m_editingPoint.getFrame());
Chris@1428 1249 m_dragPointY = getYForValue(v, m_editingPoint.getValue());
Chris@551 1250
Chris@411 1251 m_originalPoint = m_editingPoint;
Chris@411 1252
Chris@411 1253 if (m_editingCommand) {
Chris@1266 1254 finish(m_editingCommand);
Chris@1408 1255 m_editingCommand = nullptr;
Chris@411 1256 }
Chris@411 1257
Chris@411 1258 m_editing = true;
Chris@551 1259 m_dragStartX = e->x();
Chris@551 1260 m_dragStartY = e->y();
Chris@550 1261 recalcSpacing();
Chris@411 1262 }
Chris@411 1263
Chris@411 1264 void
Chris@918 1265 RegionLayer::editDrag(LayerGeometryProvider *v, QMouseEvent *e)
Chris@411 1266 {
Chris@411 1267 if (!m_model || !m_editing) return;
Chris@411 1268
Chris@551 1269 int xdist = e->x() - m_dragStartX;
Chris@551 1270 int ydist = e->y() - m_dragStartY;
Chris@551 1271 int newx = m_dragPointX + xdist;
Chris@551 1272 int newy = m_dragPointY + ydist;
Chris@551 1273
Chris@989 1274 sv_frame_t frame = v->getFrameForX(newx);
Chris@411 1275 if (frame < 0) frame = 0;
Chris@411 1276 frame = frame / m_model->getResolution() * m_model->getResolution();
Chris@411 1277
Chris@551 1278 // Do not bisect between two values, if one of those values is
Chris@551 1279 // that of the point we're actually moving ...
Chris@1428 1280 int avoid = m_spacingMap[m_editingPoint.getValue()];
Chris@551 1281
Chris@551 1282 // ... unless there are other points with the same value
Chris@1428 1283 if (m_distributionMap[m_editingPoint.getValue()] > 1) avoid = -1;
Chris@551 1284
Chris@905 1285 double value = getValueForY(v, newy, avoid);
Chris@411 1286
Chris@411 1287 if (!m_editingCommand) {
Chris@1428 1288 m_editingCommand = new ChangeEventsCommand(m_model,
Chris@1266 1289 tr("Drag Region"));
Chris@411 1290 }
Chris@411 1291
Chris@1428 1292 m_editingCommand->remove(m_editingPoint);
Chris@1428 1293 m_editingPoint = m_editingPoint
Chris@1428 1294 .withFrame(frame)
Chris@1428 1295 .withValue(float(value));
Chris@1428 1296 m_editingCommand->add(m_editingPoint);
Chris@550 1297 recalcSpacing();
Chris@411 1298 }
Chris@411 1299
Chris@411 1300 void
Chris@918 1301 RegionLayer::editEnd(LayerGeometryProvider *, QMouseEvent *)
Chris@411 1302 {
Chris@411 1303 if (!m_model || !m_editing) return;
Chris@411 1304
Chris@411 1305 if (m_editingCommand) {
Chris@411 1306
Chris@1266 1307 QString newName = m_editingCommand->getName();
Chris@411 1308
Chris@1428 1309 if (m_editingPoint.getFrame() != m_originalPoint.getFrame()) {
Chris@1428 1310 if (m_editingPoint.getValue() != m_originalPoint.getValue()) {
Chris@1266 1311 newName = tr("Edit Region");
Chris@1266 1312 } else {
Chris@1266 1313 newName = tr("Relocate Region");
Chris@1266 1314 }
Chris@1266 1315 } else {
Chris@1266 1316 newName = tr("Change Point Value");
Chris@1266 1317 }
Chris@411 1318
Chris@1266 1319 m_editingCommand->setName(newName);
Chris@1266 1320 finish(m_editingCommand);
Chris@411 1321 }
Chris@411 1322
Chris@1408 1323 m_editingCommand = nullptr;
Chris@411 1324 m_editing = false;
Chris@550 1325 recalcSpacing();
Chris@411 1326 }
Chris@411 1327
Chris@411 1328 bool
Chris@918 1329 RegionLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e)
Chris@411 1330 {
Chris@411 1331 if (!m_model) return false;
Chris@411 1332
Chris@1428 1333 Event region(0);
Chris@550 1334 if (!getPointToDrag(v, e->x(), e->y(), region)) return false;
Chris@550 1335
Chris@411 1336 ItemEditDialog *dialog = new ItemEditDialog
Chris@411 1337 (m_model->getSampleRate(),
Chris@411 1338 ItemEditDialog::ShowTime |
Chris@411 1339 ItemEditDialog::ShowDuration |
Chris@411 1340 ItemEditDialog::ShowValue |
Chris@411 1341 ItemEditDialog::ShowText,
Chris@701 1342 getScaleUnits());
Chris@411 1343
Chris@1428 1344 dialog->setFrameTime(region.getFrame());
Chris@1428 1345 dialog->setValue(region.getValue());
Chris@1428 1346 dialog->setFrameDuration(region.getDuration());
Chris@1428 1347 dialog->setText(region.getLabel());
Chris@411 1348
Chris@411 1349 if (dialog->exec() == QDialog::Accepted) {
Chris@411 1350
Chris@1428 1351 Event newRegion = region
Chris@1428 1352 .withFrame(dialog->getFrameTime())
Chris@1428 1353 .withValue(dialog->getValue())
Chris@1428 1354 .withDuration(dialog->getFrameDuration())
Chris@1428 1355 .withLabel(dialog->getText());
Chris@411 1356
Chris@1428 1357 ChangeEventsCommand *command = new ChangeEventsCommand
Chris@543 1358 (m_model, tr("Edit Region"));
Chris@1428 1359 command->remove(region);
Chris@1428 1360 command->add(newRegion);
Chris@411 1361 finish(command);
Chris@411 1362 }
Chris@411 1363
Chris@411 1364 delete dialog;
Chris@550 1365 recalcSpacing();
Chris@411 1366 return true;
Chris@411 1367 }
Chris@411 1368
Chris@411 1369 void
Chris@905 1370 RegionLayer::moveSelection(Selection s, sv_frame_t newStartFrame)
Chris@411 1371 {
Chris@411 1372 if (!m_model) return;
Chris@411 1373
Chris@1428 1374 ChangeEventsCommand *command =
Chris@1428 1375 new ChangeEventsCommand(m_model, tr("Drag Selection"));
Chris@411 1376
Chris@1428 1377 EventVector points =
Chris@1428 1378 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration());
Chris@411 1379
Chris@1428 1380 for (EventVector::iterator i = points.begin();
Chris@1266 1381 i != points.end(); ++i) {
Chris@411 1382
Chris@1428 1383 if (s.contains(i->getFrame())) {
Chris@1428 1384 Event newPoint = (*i)
Chris@1428 1385 .withFrame(i->getFrame() + newStartFrame - s.getStartFrame());
Chris@1428 1386 command->remove(*i);
Chris@1428 1387 command->add(newPoint);
Chris@1266 1388 }
Chris@411 1389 }
Chris@411 1390
Chris@411 1391 finish(command);
Chris@550 1392 recalcSpacing();
Chris@411 1393 }
Chris@411 1394
Chris@411 1395 void
Chris@411 1396 RegionLayer::resizeSelection(Selection s, Selection newSize)
Chris@411 1397 {
Chris@1428 1398 if (!m_model || !s.getDuration()) return;
Chris@411 1399
Chris@1428 1400 ChangeEventsCommand *command =
Chris@1428 1401 new ChangeEventsCommand(m_model, tr("Resize Selection"));
Chris@411 1402
Chris@1428 1403 EventVector points =
Chris@1428 1404 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration());
Chris@411 1405
Chris@1428 1406 double ratio = double(newSize.getDuration()) / double(s.getDuration());
Chris@1428 1407 double oldStart = double(s.getStartFrame());
Chris@1428 1408 double newStart = double(newSize.getStartFrame());
Chris@1428 1409
Chris@1428 1410 for (Event p: points) {
Chris@411 1411
Chris@1428 1412 double newFrame = (double(p.getFrame()) - oldStart) * ratio + newStart;
Chris@1428 1413 double newDuration = double(p.getDuration()) * ratio;
Chris@411 1414
Chris@1428 1415 Event newPoint = p
Chris@1428 1416 .withFrame(lrint(newFrame))
Chris@1428 1417 .withDuration(lrint(newDuration));
Chris@1428 1418 command->remove(p);
Chris@1428 1419 command->add(newPoint);
Chris@411 1420 }
Chris@411 1421
Chris@411 1422 finish(command);
Chris@550 1423 recalcSpacing();
Chris@411 1424 }
Chris@411 1425
Chris@411 1426 void
Chris@411 1427 RegionLayer::deleteSelection(Selection s)
Chris@411 1428 {
Chris@411 1429 if (!m_model) return;
Chris@411 1430
Chris@1428 1431 ChangeEventsCommand *command =
Chris@1428 1432 new ChangeEventsCommand(m_model, tr("Delete Selected Points"));
Chris@411 1433
Chris@1428 1434 EventVector points =
Chris@1428 1435 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration());
Chris@411 1436
Chris@1428 1437 for (EventVector::iterator i = points.begin();
Chris@1266 1438 i != points.end(); ++i) {
Chris@411 1439
Chris@1428 1440 if (s.contains(i->getFrame())) {
Chris@1428 1441 command->remove(*i);
Chris@411 1442 }
Chris@411 1443 }
Chris@411 1444
Chris@411 1445 finish(command);
Chris@550 1446 recalcSpacing();
Chris@411 1447 }
Chris@411 1448
Chris@411 1449 void
Chris@918 1450 RegionLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to)
Chris@411 1451 {
Chris@411 1452 if (!m_model) return;
Chris@411 1453
Chris@1428 1454 EventVector points =
Chris@1428 1455 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration());
Chris@411 1456
Chris@1428 1457 for (Event p: points) {
Chris@1428 1458 to.addPoint(p.withReferenceFrame(alignToReference(v, p.getFrame())));
Chris@411 1459 }
Chris@411 1460 }
Chris@411 1461
Chris@411 1462 bool
Chris@918 1463 RegionLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t /* frameOffset */, bool /* interactive */)
Chris@411 1464 {
Chris@411 1465 if (!m_model) return false;
Chris@411 1466
Chris@1423 1467 const EventVector &points = from.getPoints();
Chris@411 1468
Chris@411 1469 bool realign = false;
Chris@411 1470
Chris@411 1471 if (clipboardHasDifferentAlignment(v, from)) {
Chris@411 1472
Chris@411 1473 QMessageBox::StandardButton button =
Chris@918 1474 QMessageBox::question(v->getView(), tr("Re-align pasted items?"),
Chris@411 1475 tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"),
Chris@411 1476 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
Chris@411 1477 QMessageBox::Yes);
Chris@411 1478
Chris@411 1479 if (button == QMessageBox::Cancel) {
Chris@411 1480 return false;
Chris@411 1481 }
Chris@411 1482
Chris@411 1483 if (button == QMessageBox::Yes) {
Chris@411 1484 realign = true;
Chris@411 1485 }
Chris@411 1486 }
Chris@411 1487
Chris@1428 1488 ChangeEventsCommand *command =
Chris@1428 1489 new ChangeEventsCommand(m_model, tr("Paste"));
Chris@411 1490
Chris@1423 1491 for (EventVector::const_iterator i = points.begin();
Chris@411 1492 i != points.end(); ++i) {
Chris@411 1493
Chris@905 1494 sv_frame_t frame = 0;
Chris@411 1495
Chris@411 1496 if (!realign) {
Chris@411 1497
Chris@411 1498 frame = i->getFrame();
Chris@411 1499
Chris@411 1500 } else {
Chris@411 1501
Chris@1423 1502 if (i->hasReferenceFrame()) {
Chris@411 1503 frame = i->getReferenceFrame();
Chris@411 1504 frame = alignFromReference(v, frame);
Chris@411 1505 } else {
Chris@411 1506 frame = i->getFrame();
Chris@411 1507 }
Chris@411 1508 }
Chris@411 1509
Chris@1428 1510 Event p = *i;
Chris@1428 1511 Event newPoint = p;
Chris@1428 1512 if (!p.hasValue()) {
Chris@1428 1513 newPoint = newPoint.withValue((m_model->getValueMinimum() +
Chris@1428 1514 m_model->getValueMaximum()) / 2);
Chris@1428 1515 }
Chris@1428 1516 if (!p.hasDuration()) {
Chris@905 1517 sv_frame_t nextFrame = frame;
Chris@1423 1518 EventVector::const_iterator j = i;
Chris@411 1519 for (; j != points.end(); ++j) {
Chris@411 1520 if (j != i) break;
Chris@411 1521 }
Chris@411 1522 if (j != points.end()) {
Chris@411 1523 nextFrame = j->getFrame();
Chris@411 1524 }
Chris@411 1525 if (nextFrame == frame) {
Chris@1428 1526 newPoint = newPoint.withDuration(m_model->getResolution());
Chris@411 1527 } else {
Chris@1428 1528 newPoint = newPoint.withDuration(nextFrame - frame);
Chris@411 1529 }
Chris@411 1530 }
Chris@411 1531
Chris@1428 1532 command->add(newPoint);
Chris@411 1533 }
Chris@411 1534
Chris@411 1535 finish(command);
Chris@550 1536 recalcSpacing();
Chris@411 1537 return true;
Chris@411 1538 }
Chris@411 1539
Chris@411 1540 void
Chris@411 1541 RegionLayer::toXml(QTextStream &stream,
Chris@411 1542 QString indent, QString extraAttributes) const
Chris@411 1543 {
Chris@1362 1544 QString s;
Chris@1362 1545
Chris@1362 1546 s += QString("verticalScale=\"%1\" "
Chris@1362 1547 "plotStyle=\"%2\" ")
Chris@1362 1548 .arg(m_verticalScale)
Chris@1362 1549 .arg(m_plotStyle);
Chris@1362 1550
Chris@1362 1551 // New-style colour map attribute, by string id rather than by
Chris@1362 1552 // number
Chris@1362 1553
Chris@1362 1554 s += QString("fillColourMap=\"%1\" ")
Chris@1362 1555 .arg(ColourMapper::getColourMapId(m_colourMap));
Chris@1362 1556
Chris@1362 1557 // Old-style colour map attribute
Chris@1362 1558
Chris@1362 1559 s += QString("colourMap=\"%1\" ")
Chris@1362 1560 .arg(ColourMapper::getBackwardCompatibilityColourMap(m_colourMap));
Chris@1362 1561
Chris@1362 1562 SingleColourLayer::toXml(stream, indent, extraAttributes + " " + s);
Chris@411 1563 }
Chris@411 1564
Chris@411 1565 void
Chris@411 1566 RegionLayer::setProperties(const QXmlAttributes &attributes)
Chris@411 1567 {
Chris@411 1568 SingleColourLayer::setProperties(attributes);
Chris@411 1569
Chris@411 1570 bool ok;
Chris@411 1571 VerticalScale scale = (VerticalScale)
Chris@1266 1572 attributes.value("verticalScale").toInt(&ok);
Chris@411 1573 if (ok) setVerticalScale(scale);
Chris@412 1574 PlotStyle style = (PlotStyle)
Chris@1266 1575 attributes.value("plotStyle").toInt(&ok);
Chris@412 1576 if (ok) setPlotStyle(style);
Chris@1362 1577
Chris@1362 1578 QString colourMapId = attributes.value("fillColourMap");
Chris@1362 1579 int colourMap = ColourMapper::getColourMapById(colourMapId);
Chris@1362 1580 if (colourMap >= 0) {
Chris@1362 1581 setFillColourMap(colourMap);
Chris@1362 1582 } else {
Chris@1362 1583 colourMap = attributes.value("colourMap").toInt(&ok);
Chris@1362 1584 if (ok && colourMap < ColourMapper::getColourMapCount()) {
Chris@1362 1585 setFillColourMap(colourMap);
Chris@1362 1586 }
Chris@1362 1587 }
Chris@411 1588 }
Chris@411 1589
Chris@411 1590