back to polygonf

git-svn-id: svn://db.shs.com.ru/libs@7 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
2015-04-17 07:19:24 +00:00
parent fd4ffc3677
commit 3abd654291
4 changed files with 20 additions and 14 deletions

View File

@@ -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;
}

View File

@@ -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<QPointF> & 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<QPointF> & 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<float> & g, int graphic) {
//if (ci >= ic) ci = ic - 1;
hist[ci]++;
}
QList<QPointF> & 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<QPointF> & 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<QPointF> & 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<QPointF> cpol;
QPolygonF cpol;
for (int i = 0; i < graphics.size(); ++i) {
GraphicType & t(graphics[i]);
QList<QPointF> & 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<QPointF> & pol(pause_ ? t.polyline_pause : t.polyline);
const QPolygonF & pol(pause_ ? t.polyline_pause : t.polyline);
if (!pol.isEmpty()) {
isEmpty = false;
break;

View File

@@ -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;

View File

@@ -32,8 +32,8 @@ struct GraphicType {
}
//~GraphicType() {delete pb;}
QString name;
QList<QPointF> polyline;
QList<QPointF> polyline_pause;
QPolygonF polyline;
QPolygonF polyline_pause;
QPen pen;
QColor fill_color;
bool lines;