diff --git a/kx_tools/kx_pult.cpp b/kx_tools/kx_pult.cpp index 8e251dc..6b2e62d 100644 --- a/kx_tools/kx_pult.cpp +++ b/kx_tools/kx_pult.cpp @@ -206,11 +206,13 @@ void KX_Pult::setControlsEnable(bool enable) { void KX_Pult::setX(const KX_X_Data & data) { + ui->graphic->lock(); for (int i = 0; i < KX_X_PACKET_NUM; ++i) { if (!isNormalDouble(data.x_data[i])) continue; ui->graphic->addPoint(data.x_data[i], i, false); values[i]->setText(QString("(%1): %2").arg(data.x_num[i]).arg(data.x_data[i])); } + ui->graphic->unlock(); if (!isPause) { need_update = true; } diff --git a/qad_graphic/graphic.cpp b/qad_graphic/graphic.cpp index b5be13e..dcdc164 100644 --- a/qad_graphic/graphic.cpp +++ b/qad_graphic/graphic.cpp @@ -155,6 +155,7 @@ void Graphic::timerEvent(QTimerEvent * ) { void Graphic::canvasPaintEvent(QPaintEvent * ) { if (is_lines_update) return; + QMutexLocker ml(&mutex_); static int pwid = 0, phei = 0; int wid = canvas->width(), hei = canvas->height(); lastw = wid; @@ -446,6 +447,7 @@ void Graphic::setPaused(bool yes) { } for (int i = 0; i < graphics.size(); ++i) { graphics[i].polyline_pause = graphics[i].polyline; + graphics[i].polyline_pause.detach(); graphics[i].max_x_pause = graphics[i].max_x; } timer_pause = startTimer(40); @@ -456,7 +458,7 @@ void Graphic::setHistorySize(double val) { history = val; double x; for (int i = 0; i < graphics.size(); ++i) { - QList & pol(graphics[i].polyline); + QPolygonF & pol(graphics[i].polyline); if (pol.isEmpty()) continue; x = pol.back().x() - history; for (int j = pol.size() - 2; j >= 0 ; --j) @@ -538,7 +540,7 @@ void Graphic::addPoint(const QPointF & p, int graphic, bool update_) { void Graphic::setGraphicData(const QVector & g, int graphic, bool update_) { if (graphic >= graphics.size() || graphic < 0) return; graphics[graphic].polyline.clear(); - graphics[graphic].polyline = g.toList(); + graphics[graphic].polyline = g; if (graphics.at(graphic).polyline.size() == 0) { graphics[graphic].max_x = 0.; tick(graphic, false, update_); @@ -662,7 +664,7 @@ void Graphic::setHistogramData(const QVector & g, int graphic) { //if (ci >= ic) ci = ic - 1; hist[ci]++; } - QList & cpol(graphics[graphic].polyline); + QPolygonF & cpol(graphics[graphic].polyline); if (hist.size() == 1 || range == 0.) { cpol << QPointF(min - 0.5, 0.) << QPointF(min - 0.25, 0.); cpol << QPointF(min - 0.25, hist[0]) << QPointF(min + 0.25, hist[0]); @@ -684,7 +686,7 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou bool isRangeX = (start_x != end_x), isRangeY = (start_y != end_y); bool isEmpty = true, anyVisible = false, isTimeLimit = (visible_time > 0.) && !(isRangeX || isRangeY); foreach (const GraphicType & t, graphics) { - const QList & pol(pause_ ? t.polyline_pause : t.polyline); + const QPolygonF & pol(pause_ ? t.polyline_pause : t.polyline); if (!pol.isEmpty()) { isEmpty = false; break; @@ -704,7 +706,7 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou vx -= visible_time; foreach (const GraphicType & t, graphics) { if (!t.visible) continue; - const QList & pol(pause_ ? t.polyline_pause : t.polyline); + const QPolygonF & pol(pause_ ? t.polyline_pause : t.polyline); for (int i = 0; i < pol.size(); i++) { cx = pol[i].x(); cy = pol[i].y(); @@ -869,10 +871,10 @@ void Graphic::drawGraphics() { QTransform mat = painter->transform(); painter->resetTransform(); painter->setWorldMatrixEnabled(false); - QList cpol; + QPolygonF cpol; for (int i = 0; i < graphics.size(); ++i) { GraphicType & t(graphics[i]); - QList & rpol(pause_ ? t.polyline_pause : t.polyline); + QPolygonF & rpol(pause_ ? t.polyline_pause : t.polyline); if (t.visible && !rpol.isEmpty()) { pw = t.pen.widthF(); if (t.lines) { @@ -883,16 +885,16 @@ void Graphic::drawGraphics() { painter->setBrush(t.fill_color); //cpol.push_front(QPointF(cpol.front().x(), 0.)); //cpol.push_back(QPointF(cpol.back().x(), 0.)); - painter->drawPolygon(mat.map(QPolygonF(cpol.toVector()))); + painter->drawPolygon(mat.map(cpol)); } else - painter->drawPolyline(mat.map(QPolygonF(rpol.toVector()))); + painter->drawPolyline(mat.map(rpol)); } if (t.points) { if (qRound(t.pointWidth) == t.pointWidth) t.pen.setWidth(qRound(t.pointWidth)); else t.pen.setWidthF(t.pointWidth); t.pen.setCosmetic(true); painter->setPen(t.pen); - painter->drawPoints(mat.map(QPolygonF(rpol.toVector()))); + painter->drawPoints(mat.map(rpol)); if (qRound(pw) == pw) t.pen.setWidth(qRound(pw)); else t.pen.setWidthF(pw); } @@ -1093,7 +1095,7 @@ void Graphic::on_buttonAutofit_clicked() { isFit = true; bool isEmpty = true; foreach (const GraphicType & t, graphics) { - const QList & pol(pause_ ? t.polyline_pause : t.polyline); + const QPolygonF & pol(pause_ ? t.polyline_pause : t.polyline); if (!pol.isEmpty()) { isEmpty = false; break; diff --git a/qad_graphic/graphic.h b/qad_graphic/graphic.h index 3f4bc01..6f01aac 100644 --- a/qad_graphic/graphic.h +++ b/qad_graphic/graphic.h @@ -198,6 +198,8 @@ public: QWidget * viewport() const {return canvas;} QByteArray save(); void load(QByteArray ba); + void lock() {mutex_.lock();} + void unlock() {mutex_.unlock();} void reset() {mutex.lock(); clear(); mutex.unlock();} @@ -336,7 +338,7 @@ protected: QString pointCoords(QPointF point) {return "(" + QString::number(point.x(), 'f', 3) + " ; " + QString::number(point.y(), 'f', 3) + ")";} Ui::Graphic * ui; - QMutex mutex; + QMutex mutex, mutex_; QWidget * canvas; QImage * buffer; QPainter * painter; diff --git a/qad_graphic/graphic_conf.h b/qad_graphic/graphic_conf.h index d812920..6d926a6 100644 --- a/qad_graphic/graphic_conf.h +++ b/qad_graphic/graphic_conf.h @@ -32,8 +32,8 @@ struct GraphicType { } //~GraphicType() {delete pb;} QString name; - QList polyline; - QList polyline_pause; + QPolygonF polyline; + QPolygonF polyline_pause; QPen pen; QColor fill_color; bool lines;