Mercurial > hg > svgui
comparison view/Pane.cpp @ 854:c17719e488c9
Fix some potential null-pointer derefs, and simplify some logic where loops were used with an unconditional "break" that meant they could only happen once (from coverity scan)
author | Chris Cannam |
---|---|
date | Wed, 03 Sep 2014 12:04:22 +0100 |
parents | d843e6275d0f |
children | 59a22f3bf86d |
comparison
equal
deleted
inserted
replaced
853:99f96cacde36 | 854:c17719e488c9 |
---|---|
417 paint.begin(this); | 417 paint.begin(this); |
418 setPaintFont(paint); | 418 setPaintFont(paint); |
419 | 419 |
420 if (e) paint.setClipRect(r); | 420 if (e) paint.setClipRect(r); |
421 | 421 |
422 ViewManager::ToolMode toolMode = m_manager->getToolModeFor(this); | 422 ViewManager::ToolMode toolMode = ViewManager::NavigateMode; |
423 if (m_manager) toolMode = m_manager->getToolModeFor(this); | |
423 | 424 |
424 if (m_manager && | 425 if (m_manager && |
425 // !m_manager->isPlaying() && | |
426 m_mouseInWidget && | 426 m_mouseInWidget && |
427 toolMode == ViewManager::MeasureMode) { | 427 toolMode == ViewManager::MeasureMode) { |
428 | 428 |
429 for (LayerList::iterator vi = m_layerStack.end(); vi != m_layerStack.begin(); ) { | 429 for (LayerList::iterator vi = m_layerStack.end(); vi != m_layerStack.begin(); ) { |
430 --vi; | 430 --vi; |
493 } | 493 } |
494 | 494 |
495 paint.setPen(QColor(50, 50, 50)); | 495 paint.setPen(QColor(50, 50, 50)); |
496 | 496 |
497 if (waveformModel && | 497 if (waveformModel && |
498 sampleRate && | |
498 m_manager && | 499 m_manager && |
499 m_manager->shouldShowDuration()) { | 500 m_manager->shouldShowDuration()) { |
500 drawDurationAndRate(r, waveformModel, sampleRate, paint); | 501 drawDurationAndRate(r, waveformModel, sampleRate, paint); |
501 } | 502 } |
502 | 503 |
1091 return false; | 1092 return false; |
1092 } | 1093 } |
1093 | 1094 |
1094 if (m_scaleWidth > 0) { | 1095 if (m_scaleWidth > 0) { |
1095 | 1096 |
1096 for (LayerList::iterator vi = m_layerStack.end(); vi != m_layerStack.begin(); ) { | 1097 Layer *layer = getTopLayer(); |
1097 --vi; | 1098 |
1099 if (layer) { | |
1098 | 1100 |
1099 paint.save(); | 1101 paint.save(); |
1100 | 1102 |
1101 paint.setPen(getForeground()); | 1103 paint.setPen(getForeground()); |
1102 paint.setBrush(getBackground()); | 1104 paint.setBrush(getBackground()); |
1103 paint.drawRect(xorigin, -1, m_scaleWidth, height()+1); | 1105 paint.drawRect(xorigin, -1, m_scaleWidth, height()+1); |
1104 | 1106 |
1105 paint.setBrush(Qt::NoBrush); | 1107 paint.setBrush(Qt::NoBrush); |
1106 (*vi)->paintVerticalScale | 1108 layer->paintVerticalScale |
1107 (this, m_manager->shouldShowVerticalColourScale(), | 1109 (this, m_manager->shouldShowVerticalColourScale(), |
1108 paint, QRect(xorigin, 0, m_scaleWidth, height())); | 1110 paint, QRect(xorigin, 0, m_scaleWidth, height())); |
1109 | 1111 |
1110 paint.restore(); | 1112 paint.restore(); |
1111 break; | |
1112 } | 1113 } |
1113 } | 1114 } |
1114 | 1115 |
1115 return true; | 1116 return true; |
1116 } | 1117 } |
1125 height(), QImage::Format_RGB32); | 1126 height(), QImage::Format_RGB32); |
1126 | 1127 |
1127 int formerScaleWidth = m_scaleWidth; | 1128 int formerScaleWidth = m_scaleWidth; |
1128 | 1129 |
1129 if (m_manager && m_manager->shouldShowVerticalScale()) { | 1130 if (m_manager && m_manager->shouldShowVerticalScale()) { |
1130 for (LayerList::iterator vi = m_layerStack.end(); vi != m_layerStack.begin(); ) { | 1131 Layer *layer = getTopLayer(); |
1131 --vi; | 1132 if (layer) { |
1132 QPainter paint(image); | 1133 QPainter paint(image); |
1133 m_scaleWidth = (*vi)->getVerticalScaleWidth | 1134 m_scaleWidth = layer->getVerticalScaleWidth |
1134 (this, m_manager->shouldShowVerticalColourScale(), paint); | 1135 (this, m_manager->shouldShowVerticalColourScale(), paint); |
1135 break; | |
1136 } | 1136 } |
1137 } else { | 1137 } else { |
1138 m_scaleWidth = 0; | 1138 m_scaleWidth = 0; |
1139 } | 1139 } |
1140 | 1140 |
1162 QImage *image = new QImage(100, 100, QImage::Format_RGB32); | 1162 QImage *image = new QImage(100, 100, QImage::Format_RGB32); |
1163 QPainter paint(image); | 1163 QPainter paint(image); |
1164 | 1164 |
1165 int sw = 0; | 1165 int sw = 0; |
1166 if (m_manager && m_manager->shouldShowVerticalScale()) { | 1166 if (m_manager && m_manager->shouldShowVerticalScale()) { |
1167 for (LayerList::iterator vi = m_layerStack.end(); vi != m_layerStack.begin(); ) { | 1167 Layer *layer = getTopLayer(); |
1168 --vi; | 1168 if (layer) { |
1169 sw = (*vi)->getVerticalScaleWidth | 1169 sw = layer->getVerticalScaleWidth |
1170 (this, m_manager->shouldShowVerticalColourScale(), paint); | 1170 (this, m_manager->shouldShowVerticalColourScale(), paint); |
1171 break; | |
1172 } | 1171 } |
1173 } | 1172 } |
1174 | 1173 |
1175 return QSize(sw + s.width(), s.height()); | 1174 return QSize(sw + s.width(), s.height()); |
1176 } | 1175 } |
1452 } | 1451 } |
1453 | 1452 |
1454 void | 1453 void |
1455 Pane::mouseReleaseEvent(QMouseEvent *e) | 1454 Pane::mouseReleaseEvent(QMouseEvent *e) |
1456 { | 1455 { |
1457 if (e->buttons() & Qt::RightButton) { | 1456 if (e && (e->buttons() & Qt::RightButton)) { |
1458 return; | 1457 return; |
1459 } | 1458 } |
1460 | 1459 |
1461 // cerr << "mouseReleaseEvent" << endl; | 1460 // cerr << "mouseReleaseEvent" << endl; |
1462 | 1461 |
1580 } | 1579 } |
1581 | 1580 |
1582 void | 1581 void |
1583 Pane::mouseMoveEvent(QMouseEvent *e) | 1582 Pane::mouseMoveEvent(QMouseEvent *e) |
1584 { | 1583 { |
1585 if (e->buttons() & Qt::RightButton) { | 1584 if (!e || (e->buttons() & Qt::RightButton)) { |
1586 return; | 1585 return; |
1587 } | 1586 } |
1588 | 1587 |
1589 // cerr << "mouseMoveEvent" << endl; | 1588 // cerr << "mouseMoveEvent" << endl; |
1590 | 1589 |
1632 } else { | 1631 } else { |
1633 setCursor(Qt::ArrowCursor); | 1632 setCursor(Qt::ArrowCursor); |
1634 } | 1633 } |
1635 } | 1634 } |
1636 | 1635 |
1637 if (!m_manager->isPlaying()) { | 1636 if (m_manager && !m_manager->isPlaying()) { |
1638 | 1637 |
1639 bool updating = false; | 1638 bool updating = false; |
1640 | 1639 |
1641 if (getInteractionLayer() && | 1640 if (getInteractionLayer() && |
1642 m_manager->shouldIlluminateLocalFeatures()) { | 1641 m_manager->shouldIlluminateLocalFeatures()) { |
1649 update(); | 1648 update(); |
1650 updating = true; | 1649 updating = true; |
1651 } | 1650 } |
1652 } | 1651 } |
1653 | 1652 |
1654 if (!updating && mode == ViewManager::MeasureMode && | 1653 if (!updating && mode == ViewManager::MeasureMode) { |
1655 m_manager && !m_manager->isPlaying()) { | |
1656 | 1654 |
1657 Layer *layer = getTopLayer(); | 1655 Layer *layer = getTopLayer(); |
1658 if (layer && layer->nearestMeasurementRectChanged | 1656 if (layer && layer->nearestMeasurementRectChanged |
1659 (this, prevPoint, m_identifyPoint)) { | 1657 (this, prevPoint, m_identifyPoint)) { |
1660 update(); | 1658 update(); |
2125 { | 2123 { |
2126 int mouseFrame = getFrameForX(x); | 2124 int mouseFrame = getFrameForX(x); |
2127 | 2125 |
2128 bool doScroll = false; | 2126 bool doScroll = false; |
2129 if (!m_manager) doScroll = true; | 2127 if (!m_manager) doScroll = true; |
2130 if (!m_manager->isPlaying()) doScroll = true; | 2128 else if (!m_manager->isPlaying()) doScroll = true; |
2129 | |
2131 if (m_followPlay != PlaybackScrollContinuous) doScroll = true; | 2130 if (m_followPlay != PlaybackScrollContinuous) doScroll = true; |
2132 | 2131 |
2133 if (doScroll) { | 2132 if (doScroll) { |
2134 int offset = mouseFrame - getStartFrame(); | 2133 int offset = mouseFrame - getStartFrame(); |
2135 int available = getEndFrame() - getStartFrame(); | 2134 int available = getEndFrame() - getStartFrame(); |
2171 bool relocate = (mode == ViewManager::NavigateMode || | 2170 bool relocate = (mode == ViewManager::NavigateMode || |
2172 (e->buttons() & Qt::MidButton)); | 2171 (e->buttons() & Qt::MidButton)); |
2173 | 2172 |
2174 if (mode == ViewManager::SelectMode) { | 2173 if (mode == ViewManager::SelectMode) { |
2175 m_clickedInRange = false; | 2174 m_clickedInRange = false; |
2176 m_manager->clearInProgressSelection(); | 2175 if (m_manager) m_manager->clearInProgressSelection(); |
2177 emit doubleClickSelectInvoked(getFrameForX(e->x())); | 2176 emit doubleClickSelectInvoked(getFrameForX(e->x())); |
2178 return; | 2177 return; |
2179 } | 2178 } |
2180 | 2179 |
2181 if (mode == ViewManager::NavigateMode || | 2180 if (mode == ViewManager::NavigateMode || |