Locus No Pilotus
Project of four first grade MIPT DAFE/RSE students (for engineering practical work in the second semester) in Qt C++
Loading...
Searching...
No Matches
PlotItemArc Class Reference

Class of the arc shape. More...

#include <plot_item_arc.h>

Inheritance diagram for PlotItemArc:
Collaboration diagram for PlotItemArc:

Public Member Functions

 PlotItemArc (QCustomPlot *parentPlot)
 Creates an arc item and sets default values.
 
virtual ~PlotItemArc () override
 
QPen Pen () const
 
virtual double selectTest (const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const override
 
void SetCenterAndRadiusCoords (double center_x, double center_y, double rad)
 Sets center and radius of the arc by setting topLeft and bottomRight.
 
void SetPen (const QPen &pen)
 Sets the pen that will be used to draw the line of the arc.
 
void SetStartAndEnd (double start_angle, double end_angle)
 Sets start and end of current acr.
 
void SetStartAndEnd (std::pair< double, double > start_and_end)
 Sets start and end of current acr.
 

Public Attributes

QCPItemAnchor *const bottom
 
QCPItemAnchor *const bottomLeftRim
 
QCPItemPosition *const bottomRight
 
QCPItemAnchor *const bottomRightRim
 
QCPItemAnchor *const center
 
QCPItemAnchor *const left
 
QCPItemAnchor *const right
 
QCPItemAnchor *const top
 
QCPItemPosition *const topLeft
 
QCPItemAnchor *const topLeftRim
 
QCPItemAnchor *const topRightRim
 

Protected Types

enum  AnchorIndex {
  aiTopLeftRim , aiTop , aiTopRightRim , aiRight ,
  aiBottomRightRim , aiBottom , aiBottomLeftRim , aiLeft ,
  aiCenter
}
 

Protected Member Functions

virtual QPointF anchorPixelPosition (int anchorId) const override
 
virtual void draw (QCPPainter *painter) override
 
QBrush MainBrush () const
 Returns the brush that should be used for drawing fills of the item Returns mBrush when the item is not selected and mSelectedBrush when it is.
 
QPen MainPen () const
 Returns the pen that should be used for drawing lines Returns mPen when the item is not selected and mSelectedPen when it is.
 

Protected Attributes

QBrush mBrush
 
QPen mPen
 
QBrush mSelectedBrush
 
QPen mSelectedPen
 

Private Attributes

int arc_length_ {90}
 
int arc_start_ {0}
 

Detailed Description

Class of the arc shape.

Member Enumeration Documentation

◆ AnchorIndex

enum PlotItemArc::AnchorIndex
protected
Enumerator
aiTopLeftRim 
aiTop 
aiTopRightRim 
aiRight 
aiBottomRightRim 
aiBottom 
aiBottomLeftRim 
aiLeft 
aiCenter 
37 {
39 aiTop,
41 aiRight,
45 aiLeft,
47 };
@ aiBottomLeftRim
Definition plot_item_arc.h:44
@ aiCenter
Definition plot_item_arc.h:46
@ aiBottomRightRim
Definition plot_item_arc.h:42
@ aiTopLeftRim
Definition plot_item_arc.h:38
@ aiBottom
Definition plot_item_arc.h:43
@ aiTopRightRim
Definition plot_item_arc.h:40
@ aiRight
Definition plot_item_arc.h:41
@ aiTop
Definition plot_item_arc.h:39
@ aiLeft
Definition plot_item_arc.h:45

Constructor & Destructor Documentation

◆ PlotItemArc()

PlotItemArc::PlotItemArc ( QCustomPlot * parentPlot)
inlineexplicit

Creates an arc item and sets default values.

The created item is automatically registered with parentPlot. This QCustomPlot instance takes ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead

Parameters
parentPlot
71 : QCPAbstractItem(parentPlot),
72 topLeft(createPosition(QLatin1String("topLeft"))),
73 bottomRight(createPosition(QLatin1String("bottomRight"))),
74 topLeftRim(createAnchor(QLatin1String("topLeftRim"), aiTopLeftRim)),
75 top(createAnchor(QLatin1String("top"), aiTop)),
76 topRightRim(createAnchor(QLatin1String("topRightRim"), aiTopRightRim)),
77 right(createAnchor(QLatin1String("right"), aiRight)),
79 createAnchor(QLatin1String("bottomRightRim"), aiBottomRightRim)),
80 bottom(createAnchor(QLatin1String("bottom"), aiBottom)),
82 createAnchor(QLatin1String("bottomLeftRim"), aiBottomLeftRim)),
83 left(createAnchor(QLatin1String("left"), aiLeft)),
84 center(createAnchor(QLatin1String("center"), aiCenter)) {
85 topLeft->setCoords(0, 1);
86 bottomRight->setCoords(1, 0);
87
88 SetPen(QPen(Qt::black));
89}
void SetPen(const QPen &pen)
Sets the pen that will be used to draw the line of the arc.
Definition plot_item_arc.h:98
QCPItemAnchor *const bottomLeftRim
Definition plot_item_arc.h:28
QCPItemPosition *const topLeft
Definition plot_item_arc.h:20
QCPItemAnchor *const bottom
Definition plot_item_arc.h:27
QCPItemAnchor *const bottomRightRim
Definition plot_item_arc.h:26
QCPItemAnchor *const top
Definition plot_item_arc.h:23
QCPItemAnchor *const topLeftRim
Definition plot_item_arc.h:22
QCPItemAnchor *const topRightRim
Definition plot_item_arc.h:24
QCPItemAnchor *const right
Definition plot_item_arc.h:25
QCPItemAnchor *const left
Definition plot_item_arc.h:29
QCPItemAnchor *const center
Definition plot_item_arc.h:30
QCPItemPosition *const bottomRight
Definition plot_item_arc.h:21
Here is the call graph for this function:

◆ ~PlotItemArc()

PlotItemArc::~PlotItemArc ( )
inlineoverridevirtual
91{}

Member Function Documentation

◆ anchorPixelPosition()

QPointF PlotItemArc::anchorPixelPosition ( int anchorId) const
inlineoverrideprotectedvirtual
144 {
145 QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition());
146 switch (anchorId) {
147 case aiTopLeftRim:
148 return rect.center() + (rect.topLeft() - rect.center()) * 1 / qSqrt(2);
149 case aiTop:
150 return (rect.topLeft() + rect.topRight()) * 0.5;
151 case aiTopRightRim:
152 return rect.center() + (rect.topRight() - rect.center()) * 1 / qSqrt(2);
153 case aiRight:
154 return (rect.topRight() + rect.bottomRight()) * 0.5;
155 case aiBottomRightRim:
156 return rect.center() +
157 (rect.bottomRight() - rect.center()) * 1 / qSqrt(2);
158 case aiBottom:
159 return (rect.bottomLeft() + rect.bottomRight()) * 0.5;
160 case aiBottomLeftRim:
161 return rect.center() + (rect.bottomLeft() - rect.center()) * 1 / qSqrt(2);
162 case aiLeft:
163 return (rect.topLeft() + rect.bottomLeft()) * 0.5;
164 case aiCenter:
165 return (rect.topLeft() + rect.bottomRight()) * 0.5;
166 }
167
168 qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId;
169 return {};
170}

◆ draw()

void PlotItemArc::draw ( QCPPainter * painter)
inlineoverrideprotectedvirtual
112 {
113 QPointF p1 = topLeft->pixelPosition();
114 QPointF p2 = bottomRight->pixelPosition();
115
116 if (p1.toPoint() == p2.toPoint()) return;
117
118 QRectF arcRect = QRectF(p1, p2).normalized();
119
120 const int clipEnlarge = qCeil(MainPen().widthF());
121
122 QRect clip =
123 clipRect().adjusted(-clipEnlarge, -clipEnlarge, clipEnlarge, clipEnlarge);
124
125 if (arcRect.intersects(clip)) {
126 painter->setPen(MainPen());
127 painter->setBrush(MainBrush());
128#ifdef __EXCEPTIONS
129 try // drawArc sometimes throws exceptions if arc is too big
130 {
131#endif
132 painter->drawArc(arcRect, arc_start_, arc_length_);
133
134#ifdef __EXCEPTIONS
135 } catch (...) {
136 qDebug() << Q_FUNC_INFO << "Item too large for memory, setting invisible";
137 setVisible(false);
138 }
139#endif
140 }
141}
int arc_start_
Definition plot_item_arc.h:59
int arc_length_
Definition plot_item_arc.h:60
QPen MainPen() const
Returns the pen that should be used for drawing lines Returns mPen when the item is not selected and ...
Definition plot_item_arc.h:177
QBrush MainBrush() const
Returns the brush that should be used for drawing fills of the item Returns mBrush when the item is n...
Definition plot_item_arc.h:186
Here is the call graph for this function:

◆ MainBrush()

QBrush PlotItemArc::MainBrush ( ) const
inlineprotected

Returns the brush that should be used for drawing fills of the item Returns mBrush when the item is not selected and mSelectedBrush when it is.

Returns
QBrush
186 {
187 return mSelected ? mSelectedBrush : mBrush;
188}
QBrush mBrush
Definition plot_item_arc.h:50
QBrush mSelectedBrush
Definition plot_item_arc.h:50
Here is the caller graph for this function:

◆ MainPen()

QPen PlotItemArc::MainPen ( ) const
inlineprotected

Returns the pen that should be used for drawing lines Returns mPen when the item is not selected and mSelectedPen when it is.

Returns
QPen
177 {
178 return mSelected ? mSelectedPen : mPen;
179}
QPen mSelectedPen
Definition plot_item_arc.h:49
QPen mPen
Definition plot_item_arc.h:49
Here is the caller graph for this function:

◆ Pen()

QPen PlotItemArc::Pen ( ) const
inline
13{ return mPen; }

◆ selectTest()

double PlotItemArc::selectTest ( const QPointF & pos,
bool onlySelectable,
QVariant * details = nullptr ) const
inlineoverridevirtual
102 {
103 // i love qcustomplot, because it has genius solutions in code
104 Q_UNUSED(details);
105 Q_UNUSED(pos);
106 Q_UNUSED(onlySelectable);
107
108 return -1.0;
109}

◆ SetCenterAndRadiusCoords()

void PlotItemArc::SetCenterAndRadiusCoords ( double center_x,
double center_y,
double rad )
inline

Sets center and radius of the arc by setting topLeft and bottomRight.

Parameters
center_xabscissa coord of the arc
center_yordinate coord of the arc
radradius value of the arc
197 {
198 topLeft->setCoords(center_x - rad, center_y + rad);
199 bottomRight->setCoords(center_x + rad, center_y - rad);
200}

◆ SetPen()

void PlotItemArc::SetPen ( const QPen & pen)
inline

Sets the pen that will be used to draw the line of the arc.

Parameters
pen
See also
setSelectedPen, setBrush
98{ mPen = pen; }
Here is the caller graph for this function:

◆ SetStartAndEnd() [1/2]

void PlotItemArc::SetStartAndEnd ( double start_angle,
double end_angle )
inline

Sets start and end of current acr.

Parameters
start_anglestart value in degree
end_angleend value in degree
207 {
208 arc_start_ = static_cast<int>(start_angle * arc_correction_value);
209 int arc_end = static_cast<int>(end_angle * arc_correction_value);
210
211 arc_length_ = static_cast<int>(arc_end - arc_start_);
212}
static constexpr char arc_correction_value
Value for arc degree in qPainter.
Definition plot_item_arc.h:5

◆ SetStartAndEnd() [2/2]

void PlotItemArc::SetStartAndEnd ( std::pair< double, double > start_and_end)
inline

Sets start and end of current acr.

Parameters
start_and_endpair of start and end
219 {
220 arc_start_ = static_cast<int>(start_and_end.first * arc_correction_value);
221 int arc_end = static_cast<int>(start_and_end.second * arc_correction_value);
222
223 arc_length_ = static_cast<int>(arc_end - arc_start_);
224}

Member Data Documentation

◆ arc_length_

int PlotItemArc::arc_length_ {90}
private
60{90};

◆ arc_start_

int PlotItemArc::arc_start_ {0}
private
59{0};

◆ bottom

QCPItemAnchor* const PlotItemArc::bottom

◆ bottomLeftRim

QCPItemAnchor* const PlotItemArc::bottomLeftRim

◆ bottomRight

QCPItemPosition* const PlotItemArc::bottomRight

◆ bottomRightRim

QCPItemAnchor* const PlotItemArc::bottomRightRim

◆ center

QCPItemAnchor* const PlotItemArc::center

◆ left

QCPItemAnchor* const PlotItemArc::left

◆ mBrush

QBrush PlotItemArc::mBrush
protected

◆ mPen

QPen PlotItemArc::mPen
protected

◆ mSelectedBrush

QBrush PlotItemArc::mSelectedBrush
protected

◆ mSelectedPen

QPen PlotItemArc::mSelectedPen
protected

◆ right

QCPItemAnchor* const PlotItemArc::right

◆ top

QCPItemAnchor* const PlotItemArc::top

◆ topLeft

QCPItemPosition* const PlotItemArc::topLeft

◆ topLeftRim

QCPItemAnchor* const PlotItemArc::topLeftRim

◆ topRightRim

QCPItemAnchor* const PlotItemArc::topRightRim

The documentation for this class was generated from the following file: