1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
| #include "ecgviewer.h"
/*!
\class ECGViewer
\brief La classe ECGViewer correspond à une extension de QML pour la mise
en place d'un noueau composant affichant la courbe d'un ECG.
Cette classe étend QML par le biais de Qt Quick et met à disposition un
composant ECGViewer dans le code QML, utilisable à même titre qu'un élément
Rectangle.
*/
/*!
\property ECGViewer::duration
\brief La durée de l'enregistrement en secondes.
*/
/*!
\property ECGViewer::yInterval
\brief L'amplitude de l'enregistrement en mV.
*/
/*!
\property ECGViewer::pWidth
\brief La taille du painter de la courbe en pixels.
*/
/*!
\property ECGViewer::color
\brief La couleur de la courbe.
*/
/*!
\fn ECGViewer::ECGViewer()
\brief Constructeur de la classe.
Construit un objet ECGViewer.
*/
ECGViewer::ECGViewer() : _duration(1), _yInterval(3),
_pWidth(3), _color(QColor("#56B058"))
{
setFlag(ItemHasNoContents, false);
}
int ECGViewer::getDuration() const
{
return _duration;
}
int ECGViewer::getYInterval() const
{
return _yInterval;
}
void ECGViewer::setDuration(const int &duration)
{
_duration = duration <= 0 ? 1 : duration;
emit durationChanged();
update();
}
void ECGViewer::setYInterval(const int &interval)
{
_yInterval = interval <= 0 ? 1 : interval;
emit yIntervalChanged();
update();
}
int ECGViewer::getPWidth() const
{
return _pWidth;
}
void ECGViewer::setPWidth(const int &width)
{
_pWidth = width;
emit pWidthChanged();
update();
}
QColor ECGViewer::getColor() const
{
return _color;
}
void ECGViewer::setColor(const QColor &color)
{
_color = color;
emit colorChanged();
update();
}
/*!
\fn ECGViewer::paint(QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*)
\brief Dessine l'ECG du patient.
Les données sont affichées selon plusieurs critères :
- L'échelle en y, déterminée selon la hauteur du composant et l'intervalle
défini par \a _yInterval.
- L'espacement entre deux points, déterminé selon le nombre de points par
seconde (une constante), la longueur du composant ainsi que la durée
\a _duration en seconde que représente le graphe de l'ECG.
La position des points à l'échelle de \a _yInterval peut être positive ou
négative, d'où le fait que l'ordonnée 0 est positionnée à mi-hauteur, dans
le composant.
*/
void ECGViewer::paint(QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*)
{
QPen pen(_color, _pWidth);
painter->setPen(pen);
painter->setRenderHint(QPainter::Antialiasing);
QPolygonF polygon;
int halfHeight = height() / 2;
float xSpacing = width() / (POINTS_PER_SECOND * _duration);
float ySpacing = height() / _yInterval;
for (int i = 0; i < _points.count(); ++i) {
polygon.append(QPointF(i * xSpacing,
halfHeight - (_points.at(i) * ySpacing)));
}
painter->drawPolyline(polygon);
}
/*!
\fn ECGViewer::addPoint(const float &y)
\brief Ajoute un point à la liste des points.
Le nombre de points maximum est déterminé par le nombre de points par
seconde multiplié par la durée en secondes affichée par le graphe. Si ce
nombre est atteint, cela supprime les premiers points jusqu'à ce que ce
seuil ne soit plus atteint (permet la réalisation de l'animation).
*/
void ECGViewer::addPoint(const float &y)
{
while (_points.count() >= (POINTS_PER_SECOND * _duration))
_points.removeFirst();
_points.append(y);
}
/*!
\fn ECGViewer::refresh()
\brief Appelle la fonction update() du composant, permettant une peinture.
*/
void ECGViewer::refresh()
{
update();
}
/*!
\fn ECGViewer::clear()
\brief Vide la liste des points et appelle la fonction update(), permettant
une peinture.
*/
void ECGViewer::clear()
{
_points.clear();
update();
} |
Partager