axis_rect.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "axis_rect.h"
  2. AxisRect::AxisRect(QCustomPlot* parentPlot) :
  3. QCPAxisRect(parentPlot)
  4. {
  5. setMinimumMargins(QMargins(22,10,22,10));
  6. setMinimumSize(1, 1);
  7. setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
  8. axis(QCPAxis::atRight)->setVisible(true);
  9. axis(QCPAxis::atLeft)->setVisible(false);
  10. axis(QCPAxis::atBottom)->setBasePen(Qt::NoPen);
  11. axis(QCPAxis::atRight)->setBasePen(Qt::NoPen);
  12. axis(QCPAxis::atLeft)->setBasePen(Qt::NoPen);
  13. axis(QCPAxis::atBottom)->setTickPen(Qt::NoPen);
  14. axis(QCPAxis::atRight)->setTickPen(Qt::NoPen);
  15. axis(QCPAxis::atLeft)->setTickPen(Qt::NoPen);
  16. axis(QCPAxis::atBottom)->setSubTickPen(Qt::NoPen);
  17. axis(QCPAxis::atRight)->setSubTickPen(Qt::NoPen);
  18. axis(QCPAxis::atLeft)->setSubTickPen(Qt::NoPen);
  19. axis(QCPAxis::atBottom)->grid()->setZeroLinePen(Qt::NoPen);
  20. axis(QCPAxis::atRight)->grid()->setZeroLinePen(Qt::NoPen);
  21. axis(QCPAxis::atLeft)->grid()->setZeroLinePen(Qt::NoPen);
  22. axis(QCPAxis::atRight)->ticker()->setTickCount(3);
  23. axis(QCPAxis::atLeft)->ticker()->setTickCount(3);
  24. QList<QCPAxis*> zoomableAxis;
  25. zoomableAxis.append( axis(QCPAxis::atLeft));
  26. zoomableAxis.append( axis(QCPAxis::atRight));
  27. zoomableAxis.append( axis(QCPAxis::atBottom));
  28. setRangeZoomAxes(zoomableAxis);
  29. setRangeDragAxes(zoomableAxis);
  30. }
  31. void AxisRect::clearPlottables()
  32. {
  33. QList<QCPAbstractPlottable*> plotabblesList = plottables();
  34. int c = plotabblesList.size();
  35. for (int i=c-1; i >= 0; --i)
  36. mParentPlot->removePlottable(plotabblesList[i]);
  37. }
  38. void AxisRect::setAxisColor(QColor color)
  39. {
  40. axis(QCPAxis::atBottom)->setTickLabelColor(color);
  41. axis(QCPAxis::atRight)->setTickLabelColor(color);
  42. axis(QCPAxis::atLeft)->setTickLabelColor(color);
  43. axis(QCPAxis::atBottom)->grid()->setPen(QPen(color, 0, Qt::DotLine));
  44. axis(QCPAxis::atRight)->grid()->setPen(QPen(color, 0, Qt::DotLine));
  45. axis(QCPAxis::atLeft)->grid()->setPen(QPen(color, 0, Qt::DotLine));
  46. }
  47. void AxisRect::wheelEvent(QWheelEvent *event)
  48. {
  49. if( event->modifiers() & Qt::ShiftModifier )
  50. setRangeZoom(Qt::Vertical);
  51. else if ( event->modifiers() & Qt::ControlModifier)
  52. setRangeZoom(Qt::Horizontal);
  53. else
  54. setRangeZoom(Qt::Horizontal | Qt::Vertical);
  55. QCPAxisRect::wheelEvent(event);
  56. }
  57. void AxisRect::mousePressEvent(QMouseEvent *event, const QVariant &details)
  58. {
  59. if (event->buttons() & Qt::RightButton) {
  60. event->ignore();
  61. } else {
  62. QCPAxisRect::mousePressEvent(event, details);
  63. }
  64. }