clean qad/graphic/graphic.cpp and qad/graphic/graphic.h
This commit is contained in:
2
pip
2
pip
Submodule pip updated: 4910631ce8...d3ffc19610
@@ -5,11 +5,14 @@
|
||||
#include "ui_graphic_conf.h"
|
||||
#include <QMetaObject>
|
||||
#include <QMessageBox>
|
||||
#if QT_VERSION < 0x050000
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
# include <QTapAndHoldGesture>
|
||||
# include <QPanGesture>
|
||||
# include <QPinchGesture>
|
||||
#endif
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
# include <QRandomGenerator>
|
||||
#endif
|
||||
#ifndef Q_OS_ANDROID
|
||||
# define HAS_GL
|
||||
#endif
|
||||
@@ -25,17 +28,6 @@ __GraphicRegistrator__ __graphic_registrator__;
|
||||
|
||||
Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), line_x_max(this), line_y_min(this), line_y_max(this) {
|
||||
canvas_gl = 0;
|
||||
QTranslator * trans = new QTranslator();
|
||||
trans->load(":/lang/qad_graphic_" + QLocale::system().name().left(2));
|
||||
if (trans->isEmpty())
|
||||
trans->load("lang/qad_graphic_" + QLocale::system().name().left(2));
|
||||
#if QT_VERSION >= 0x050000
|
||||
if (!qApp->installTranslator(trans))
|
||||
delete trans;
|
||||
#else
|
||||
qApp->installTranslator(trans);
|
||||
#endif
|
||||
fullscr_dialog = 0;
|
||||
gesture_angle = 45.;
|
||||
leg_update = true;
|
||||
visible_update = fullscr = need_mouse_pan = false;
|
||||
@@ -47,10 +39,6 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
|
||||
#endif
|
||||
ui = new Ui::Graphic();
|
||||
ui->setupUi(this);
|
||||
/*line_x_min.resize(70, 22);
|
||||
line_x_max.resize(70, 22);
|
||||
line_y_min.resize(70, 22);
|
||||
line_y_max.resize(70, 22);*/
|
||||
line_x_min.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
line_x_max.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
((QBoxLayout * )ui->widgetLY->layout())->insertWidget(0, &line_y_min);
|
||||
@@ -59,8 +47,6 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
|
||||
((QBoxLayout * )ui->widgetLX->layout())->addWidget(&line_x_max);
|
||||
tm.restart();
|
||||
grid_numbers_x = grid_numbers_y = 1;
|
||||
LN2 = qLn(2.);
|
||||
LN5 = qLn(5.);
|
||||
LN10 = qLn(10.);
|
||||
line_x_min.setClearButtonVisible(true);
|
||||
line_x_max.setClearButtonVisible(true);
|
||||
@@ -84,10 +70,9 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
|
||||
icon_exp_sy = QIcon(":/icons/expand_s_y.png");
|
||||
icon_pause_b = QImage(":/icons/pause-back.png");
|
||||
icon_pause_f = QImage(":/icons/pause-front.png");
|
||||
aupdate = grid = isFit = isEmpty = navigation = true;
|
||||
aalias = mupdate = bufferActive = isOGL = cancel = isPrinting = guides = hasLblX = hasLblY = isHover = false;
|
||||
aupdate = grid = isFit = navigation = true;
|
||||
aalias = bufferActive = isOGL = cancel = guides = hasLblX = hasLblY = isHover = false;
|
||||
pause_ = only_expand_x = only_expand_y = false;
|
||||
//qDebug() << -DBL_MAX/2. << DBL_MAX/2. << DBL_MIN;
|
||||
limit_.setCoords(-DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX);
|
||||
eminx = eminy = DBL_MAX;
|
||||
emaxx = emaxy = DBL_MIN;
|
||||
@@ -99,9 +84,6 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
|
||||
buffer = 0;
|
||||
gridx = gridy = 1.;
|
||||
history = 5.;
|
||||
min_int = 1;
|
||||
max_int = 200;
|
||||
mdm = 10.;
|
||||
visible_time = -1.;
|
||||
thick = lineThickness();
|
||||
pause_phase = 0.;
|
||||
@@ -113,8 +95,6 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
|
||||
selbrush.setColor(QColor(60, 175, 255, 100));
|
||||
text_color = palette().color(QPalette::WindowText);
|
||||
grid_pen = QPen(palette().color(QPalette::Disabled, QPalette::WindowText), 0., Qt::DotLine);
|
||||
//graph_pen = QPen(Qt::red);
|
||||
//graph_pen.setCosmetic(true);
|
||||
graphics.append(GraphicType());
|
||||
curGraphic = 0;
|
||||
selpen = palette().color(QPalette::WindowText);
|
||||
@@ -162,7 +142,6 @@ void Graphic::timerEvent(QTimerEvent * ) {
|
||||
|
||||
|
||||
bool Graphic::eventFilter(QObject * o, QEvent * e) {
|
||||
//qDebug() << "event" << o << e;
|
||||
if (o == canvas) {
|
||||
switch (e->type()) {
|
||||
case QEvent::Gesture:
|
||||
@@ -192,25 +171,7 @@ bool Graphic::eventFilter(QObject * o, QEvent * e) {
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
} /*else {
|
||||
if (fullscr) {
|
||||
switch (e->type()) {
|
||||
case QEvent::KeyPress:
|
||||
if ((((QKeyEvent*)e)->key() != Qt::Key_Back) || !fullscr)
|
||||
break;
|
||||
case QEvent::Close:
|
||||
leaveFullscreen();
|
||||
return true;
|
||||
case QEvent::OrientationChange:
|
||||
case QEvent::Resize: {
|
||||
QWidget * rw = canvas->parentWidget();
|
||||
if (rw)
|
||||
canvas->setGeometry(0, 0, rw->width(), rw->height());
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
return QFrame::eventFilter(o, e);
|
||||
}
|
||||
|
||||
@@ -223,7 +184,6 @@ void Graphic::prepareCanvas(QWidget * w) {
|
||||
connect(w, SIGNAL(wheelEvent(QWheelEvent * )), this, SLOT(canvasWheelEvent(QWheelEvent * )));
|
||||
connect(w, SIGNAL(leaveEvent(QEvent * )), this, SLOT(canvasLeaveEvent(QEvent * )));
|
||||
connect(w, SIGNAL(keyPressEvent(QKeyEvent * )), this, SLOT(canvasKeyPressEvent(QKeyEvent * )));
|
||||
//w->grabGesture(Qt::TapGesture);
|
||||
w->grabGesture(Qt::TapAndHoldGesture);
|
||||
w->grabGesture(Qt::PanGesture);
|
||||
w->grabGesture(Qt::PinchGesture);
|
||||
@@ -246,7 +206,6 @@ void Graphic::procGesture(QGesture * g) {
|
||||
} break;
|
||||
case Qt::PinchGesture: {
|
||||
QPinchGesture * pg = (QPinchGesture*)g;
|
||||
//qDebug() << pg->totalRotationAngle();
|
||||
Qt::KeyboardModifiers km = Qt::NoModifier;
|
||||
if (gesture_angle <= 20.) km = Qt::ControlModifier;
|
||||
if (gesture_angle >= 70.) km = Qt::ShiftModifier;
|
||||
@@ -261,10 +220,8 @@ void Graphic::procGesture(QGesture * g) {
|
||||
QMetaObject::invokeMethod(this, "enterFullscreen", Qt::QueuedConnection);
|
||||
} break;
|
||||
default:
|
||||
qDebug() << g;
|
||||
break;
|
||||
}
|
||||
//qDebug() << g;
|
||||
}
|
||||
|
||||
|
||||
@@ -295,8 +252,6 @@ void Graphic::totalUpdate() {
|
||||
|
||||
void Graphic::canvasPaintEvent() {
|
||||
if (is_lines_update) return;
|
||||
//QMutexLocker ml(&mutex_);
|
||||
//static int pwid = 0, phei = 0;
|
||||
int wid = canvas->width(), hei = canvas->height();
|
||||
if (canvas->isHidden() || wid <= 1 || hei <= 1) return;
|
||||
lastw = wid;
|
||||
@@ -320,19 +275,6 @@ void Graphic::canvasPaintEvent() {
|
||||
drawGuides();
|
||||
return;
|
||||
}
|
||||
//if (!aupdate && !mupdate && pwid == wid && phei == hei) return;
|
||||
/*if (pwid != wid || phei != hei) {
|
||||
line_x_min.move(0, hei - 35);
|
||||
line_x_max.move(0, 0);
|
||||
line_y_min.move(70, hei - line_x_min.height());
|
||||
line_y_max.move(wid - line_y_max.width(), hei - line_x_min.height());
|
||||
}
|
||||
line_x_min.setVisible(grid);
|
||||
line_x_max.setVisible(grid);
|
||||
line_y_min.setVisible(grid);
|
||||
line_y_max.setVisible(grid);*/
|
||||
//pwid = wid;
|
||||
//phei = hei;
|
||||
QPainter p;
|
||||
#ifdef HAS_GL
|
||||
if (isOGL) {
|
||||
@@ -364,7 +306,6 @@ void Graphic::canvasPaintEvent() {
|
||||
else glDisable(GL_MULTISAMPLE);
|
||||
}
|
||||
#endif
|
||||
//p.setRenderHint(QPainter::HighQualityAntialiasing, aalias);
|
||||
fp_size.clear();
|
||||
if (!aalias) p.translate(-0.5, -0.5);
|
||||
drawGraphics();
|
||||
@@ -533,11 +474,18 @@ void Graphic::canvasMouseDoubleClickEvent(QMouseEvent * ) {
|
||||
|
||||
|
||||
void Graphic::canvasWheelEvent(QWheelEvent * e) {
|
||||
//if (curaction != gaMove) return;
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
emit graphicWheelEvent(canvas2real(e->position()), e->delta()/* TODO: test use angleDelta()*/);
|
||||
#else
|
||||
emit graphicWheelEvent(canvas2real(QPointF(e->pos())), e->delta());
|
||||
#endif
|
||||
if (gestures) return;
|
||||
if (!navigation) return;
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
procZoom(e->position(), e->delta(), e->modifiers());
|
||||
#else
|
||||
procZoom(e->pos(), e->delta(), e->modifiers());
|
||||
#endif
|
||||
totalUpdate();
|
||||
}
|
||||
|
||||
@@ -577,7 +525,6 @@ void Graphic::canvasKeyPressEvent(QKeyEvent * e) {
|
||||
|
||||
|
||||
void Graphic::clear() {
|
||||
//cout << "clear" << endl;
|
||||
for (int i = 0; i < graphics.size(); ++i) {
|
||||
graphics[i].polyline.clear();
|
||||
graphics[i].polyline_pause.clear();
|
||||
@@ -591,9 +538,6 @@ void Graphic::clear() {
|
||||
void Graphic::setAntialiasing(bool enabled) {
|
||||
if (aalias == enabled) return;
|
||||
aalias = enabled;
|
||||
/*QGLFormat f = canvas_gl->format();
|
||||
f.setSampleBuffers(enabled);
|
||||
canvas_gl->setFormat(f);*/
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -630,7 +574,6 @@ void Graphic::setHistorySize(double val) {
|
||||
x = pol.back().x() - history;
|
||||
for (int j = pol.size() - 2; j >= 0 ; --j)
|
||||
if (pol[j].x() < x) {
|
||||
//qDebug() << pol.size() << j;
|
||||
pol.erase(pol.begin(), pol.begin() + j);
|
||||
break;
|
||||
}
|
||||
@@ -747,8 +690,6 @@ void Graphic::addPoint(const QPointF & p, int graphic, bool update_) {
|
||||
if (graphic >= graphics.size() || graphic < 0) return;
|
||||
GraphicType & t(graphics[graphic]);
|
||||
if (!t.cvrect.isNull() && !pause_) {
|
||||
// if (graphics[graphic].cvrect.contains(p))
|
||||
// graphics[graphic].cvrect = QRectF();
|
||||
if (t.cvrect.top() < p.y()) t.cvrect.setTop(p.y());
|
||||
if (t.cvrect.bottom() > p.y()) t.cvrect.setBottom(p.y());
|
||||
if (t.cvrect.right() < p.x()) t.cvrect.setRight(p.x());
|
||||
@@ -815,9 +756,7 @@ void Graphic::saveImage() {
|
||||
if (str == "") return;
|
||||
ppath = str;
|
||||
QPixmap im(canvas->size());
|
||||
mupdate = true;
|
||||
canvas->render(&im);
|
||||
mupdate = false;
|
||||
im.save(ppath);
|
||||
update(true);
|
||||
}
|
||||
@@ -840,29 +779,24 @@ void Graphic::setOpenGL(bool on) {
|
||||
ui->canvas_raster->show();
|
||||
canvas = ui->canvas_raster;
|
||||
#endif
|
||||
/*line_x_min.setParent(canvas);
|
||||
line_x_max.setParent(canvas);
|
||||
line_y_min.setParent(canvas);
|
||||
line_y_max.setParent(canvas);
|
||||
line_x_min.show();
|
||||
line_x_max.show();
|
||||
line_y_min.show();
|
||||
line_y_max.show();*/
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
void Graphic::update(bool force) {
|
||||
mupdate = true;
|
||||
repaintCanvas(force);
|
||||
mupdate = false;
|
||||
}
|
||||
|
||||
|
||||
void Graphic::setGraphicsCount(int arg, bool update) {
|
||||
if (arg < 0) return;
|
||||
while (graphics.size() < arg)
|
||||
while (graphics.size() < arg) {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
graphics.append(GraphicType(tr("y(x)"), QColor::fromHsv((graphics.size() * 55) % 360, 255, 255 - QRandomGenerator::global()->generate() % 115)));
|
||||
#else
|
||||
graphics.append(GraphicType(tr("y(x)"), QColor::fromHsv((graphics.size() * 55) % 360, 255, 255 - qrand() % 115)));
|
||||
#endif
|
||||
}
|
||||
while (graphics.size() > arg) {
|
||||
delete graphics.back().pb;
|
||||
graphics.pop_back();
|
||||
@@ -879,76 +813,11 @@ void Graphic::removeGraphic(int arg, bool update) {
|
||||
}
|
||||
|
||||
|
||||
/*void Graphic::setHistogramData(const QVector<float> & g, int graphic) {
|
||||
graphics[graphic].polyline.clear();
|
||||
if (g.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
QVector<float> data = g;
|
||||
QVector<int> hist;
|
||||
int ic = max_int, ci;
|
||||
double md, cd, min, max, range, cx;
|
||||
qSort(data);
|
||||
md = DBL_MAX;
|
||||
min = max = data[0];
|
||||
for (int i = 1; i < data.size(); ++i) {
|
||||
if (min > data[i]) min = data[i];
|
||||
if (max < data[i]) max = data[i];
|
||||
cd = qAbs<float>(data[i] - data[i - 1]);
|
||||
if (md > cd && cd != 0.) md = cd;
|
||||
}
|
||||
range = max - min;
|
||||
md = mdm;
|
||||
//qDebug() << md << range << ic;
|
||||
if (md != 0.)
|
||||
ic = qRound(qMax<double>(qMin<double>(double(ic), range / md), double(min_int)));
|
||||
md = range / ic;
|
||||
hist.resize(ic);
|
||||
foreach (const float & i, data) {
|
||||
ci = qRound((i - min) / range * double(ic - 1));
|
||||
//if (ci < 0) ci = 0;
|
||||
//if (ci >= ic) ci = ic - 1;
|
||||
hist[ci]++;
|
||||
}
|
||||
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]);
|
||||
cpol << QPointF(min + 0.25, 0.) << QPointF(min + 0.5, 0.);
|
||||
} else {
|
||||
cpol << QPointF(min, 0.);
|
||||
for (int i = 0; i < hist.size(); ++i) {
|
||||
cx = i * range / ic + min;
|
||||
cpol << QPointF(cx, hist[i]) << QPointF(cx + md, hist[i]);
|
||||
}
|
||||
cpol << QPointF(range + min, 0.);
|
||||
}
|
||||
updateGraphics();
|
||||
}*/
|
||||
|
||||
|
||||
void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, double end_y) {
|
||||
double cx, cy, maxX, minX, maxY, minY, vx;
|
||||
bool isRangeX = (start_x != end_x), isRangeY = (start_y != end_y);
|
||||
// bool isEmpty = true;
|
||||
//bool fast = true;
|
||||
bool can_fast = (start_x == 0 && end_x == 0 && start_y == 0 && end_y == 0);
|
||||
bool anyVisible = false, isTimeLimit = (visible_time > 0.) && !(isRangeX || isRangeY);
|
||||
//bool force_find = (visible_time > 0.) && (history > 0.) && (visible_time < history);
|
||||
//if (force_find) can_fast = false;
|
||||
// foreach (const GraphicType & t, graphics) {
|
||||
// const QPolygonF & pol(pause_ ? t.polyline_pause : t.polyline);
|
||||
// if (!pol.isEmpty()) {
|
||||
// isEmpty = false;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (isEmpty) {
|
||||
// grect = def_rect;
|
||||
// setRectToLines();
|
||||
// return;
|
||||
// }
|
||||
// can_fast = false;
|
||||
vx = -DBL_MAX;
|
||||
minY = minX = DBL_MAX;
|
||||
maxY = maxX = -DBL_MAX;
|
||||
@@ -957,14 +826,12 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou
|
||||
if (vx < (pause_ ? t.max_x_pause : t.max_x)) vx = (pause_ ? t.max_x_pause : t.max_x);
|
||||
}
|
||||
vx -= visible_time;
|
||||
//qDebug() << "[Graphic]" << "can_fast" << can_fast;
|
||||
for (int g = 0; g < graphics.size(); g++) {
|
||||
GraphicType & t(graphics[g]);
|
||||
if (!t.visible) continue;
|
||||
const QPolygonF & pol(pause_ ? t.polyline_pause : t.polyline);
|
||||
if (pol.isEmpty()) continue;
|
||||
bool f = true;
|
||||
//qDebug() << "[Graphic]" << "cvrect:" << t.cvrect << t.cvrect.isNull();
|
||||
if (t.cvrect.isNull() || !can_fast) {
|
||||
for (int i = 0; i < pol.size(); i++) {
|
||||
cx = pol[i].x();
|
||||
@@ -981,10 +848,8 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou
|
||||
if (t.cvrect.right() < cx) t.cvrect.setRight(cx);
|
||||
if (t.cvrect.left() > cx) t.cvrect.setLeft(cx);
|
||||
}
|
||||
//fast = false;
|
||||
}
|
||||
if (f) continue;
|
||||
//qDebug() << "[Graphic]" << "2 cvrect:" << t.cvrect;
|
||||
}
|
||||
anyVisible = true;
|
||||
if (maxY < t.cvrect.top()) maxY = t.cvrect.top();
|
||||
@@ -994,13 +859,10 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou
|
||||
if (!can_fast) t.cvrect = QRectF();
|
||||
}
|
||||
if (!anyVisible) {
|
||||
//qDebug() << "[Graphic]" << "empty autofit";
|
||||
grect = def_rect;
|
||||
setRectToLines();
|
||||
return;
|
||||
}
|
||||
// if (fast) qDebug() << "[Graphic]" << "FAST autofit";
|
||||
// else qDebug() << "[Graphic]" << "autofit";
|
||||
if (maxX > limit_.right()) maxX = limit_.right();
|
||||
if (minX > limit_.right()) minX = limit_.right();
|
||||
if (minX < limit_.left()) minX = limit_.left();
|
||||
@@ -1027,7 +889,7 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou
|
||||
else if (isRangeY) selrect.setRect(minX, start_y, maxX - minX, end_y - start_y);
|
||||
else grect.setRect(minX, minY, maxX - minX, maxY - minY);
|
||||
grect = grect.normalized();
|
||||
if (isFit)/* || isRangeX || isRangeY)*/ {
|
||||
if (isFit) {
|
||||
if (visible_time > 0.) {
|
||||
if (grect.width() > visible_time)
|
||||
grect.setLeft(grect.right() - visible_time);
|
||||
@@ -1039,7 +901,6 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou
|
||||
|
||||
|
||||
void Graphic::drawAction() {
|
||||
//qDebug() << "draw action";
|
||||
int wid = canvas->width(), hei = canvas->height() - gridborder.y(), sx = startpos.x(), sy = startpos.y(), cx = curpos.x(), cy = curpos.y();
|
||||
painter->setPen(selpen);
|
||||
painter->setBrush(selbrush);
|
||||
@@ -1075,7 +936,7 @@ void Graphic::drawGrid() {
|
||||
|
||||
range = selrect.bottom() - selrect.top();
|
||||
if (grad_y == Graphic::Auto) step = splitRange(range, hei / gridy / font_sz.height() / 1.4);
|
||||
else step = gridy;//range / hei * gridy;
|
||||
else step = gridy;
|
||||
start = roundTo(canvas2realY(-hei), step) - step;
|
||||
py = start + step;
|
||||
cy = 0;
|
||||
@@ -1132,7 +993,7 @@ void Graphic::drawGrid() {
|
||||
QString df;
|
||||
if (axis_type_x == Graphic::Numeric) {
|
||||
if (grad_x == Graphic::Auto) step = splitRange(range, wid / gridx / font_sz.width() * 1.4);
|
||||
else step = gridx;//range / wid * gridx;
|
||||
else step = gridx;
|
||||
start = roundTo(canvas2realX(wid), step) + step;
|
||||
px = start + step;
|
||||
if (step > 0.) {
|
||||
@@ -1172,21 +1033,15 @@ void Graphic::drawGrid() {
|
||||
start = roundTo(canvas2realX(wid), step) + step;
|
||||
px = start + step;
|
||||
QDateTime cd = QDateTime::fromMSecsSinceEpoch(px * grid_numbers_x);
|
||||
//qDebug() << "*** start" << cd << step;
|
||||
roundDateTime(cd, cur_scl);
|
||||
//qDebug() << "*** round" << cd;
|
||||
addDateTime(cd, cur_scl);
|
||||
//qDebug() << "*** add" << cd;
|
||||
//qDebug() << "*** cur" << cur_scl[0] << cur_scl[1] << cur_scl[2] << cur_scl[3] << cur_scl[4] << cur_scl[5] << cur_scl[6];
|
||||
if (step > 0.) {
|
||||
cnt = 1000;
|
||||
while (cnt-- > 0) {
|
||||
addDateTime(cd, cur_scl, -1);
|
||||
//roundDateTime(cd, cur_scl);
|
||||
//qDebug() << "next" << cd;
|
||||
cx = real2canvasX(cd.toMSecsSinceEpoch() / grid_numbers_x);
|
||||
if (cx > cwid) continue;
|
||||
if (cx < gbx) {/*qDebug() << cx << "<" << gbx;*/ break;}
|
||||
if (cx < gbx) break;
|
||||
painter->setPen(grid_pen);
|
||||
painter->drawLine(cx, hei + 5, cx, 0);
|
||||
painter->setPen(text_color);
|
||||
@@ -1236,7 +1091,6 @@ void Graphic::drawGraphics() {
|
||||
painter->setClipping(true);
|
||||
painter->setClipRect(QRect(gridborder.x(), 0, wid - gridborder.x(), hei - gridborder.y()));
|
||||
painter->translate(gridborder.x() + margins_.left(), hei - gridborder.y() - margins_.top());
|
||||
//if (isOGL && aalias) pen.setWidthF(1.5f);
|
||||
painter->scale(sclx, -scly);
|
||||
painter->translate(srp);
|
||||
QTransform mat = painter->transform();
|
||||
@@ -1257,8 +1111,6 @@ void Graphic::drawGraphics() {
|
||||
if (t.fill) {
|
||||
cpol = rpol;
|
||||
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(cpol));
|
||||
} else
|
||||
painter->drawPolyline(mat.map(rpol));
|
||||
@@ -1350,7 +1202,6 @@ double Graphic::splitRange(double range, int count) {
|
||||
|
||||
double Graphic::splitRangeDate(double range, int count, QString * format, int step[7]) {
|
||||
double ret = splitRange(range, count);
|
||||
//qDebug() << "ret =" << ret << getScaleX();
|
||||
if (ret < 1000. * 1) {*format = "ss.zzz"; step[0] = ret;}
|
||||
else if (ret < 1000. * 60) {*format = "h:m:ss"; step[1] = qRound(ret / 1000);}
|
||||
else if (ret < 1000. * 60 * 60) {*format = "h:mm"; step[2] = qRound(ret / 1000 / 60);}
|
||||
@@ -1370,7 +1221,6 @@ double Graphic::roundTo(double value, double round_to) {
|
||||
|
||||
void Graphic::roundDateTime(QDateTime & dt, int c[7]) {
|
||||
QDate d(dt.date()); QTime t(dt.time());
|
||||
//if (c[0] != 0) t.setHMS(t.hour(), t.minute(), t.second(), 0);
|
||||
if (c[1] != 0) t.setHMS(t.hour(), t.minute(), t.second());
|
||||
if (c[2] != 0) t.setHMS(t.hour(), t.minute(), 0);
|
||||
if (c[3] != 0) t.setHMS(t.hour(), 0, 0);
|
||||
@@ -1469,7 +1319,6 @@ void Graphic::setCanvasCursor(QCursor cursor) {
|
||||
|
||||
void Graphic::swapToBuffer() {
|
||||
QImage timg;
|
||||
//qDebug() << "render start";
|
||||
#ifdef HAS_GL
|
||||
if (isOGL) {
|
||||
timg = canvas_gl->grabFrameBuffer();
|
||||
@@ -1478,16 +1327,12 @@ void Graphic::swapToBuffer() {
|
||||
p.end();
|
||||
}
|
||||
#endif
|
||||
//qDebug() << "render finish";
|
||||
bufferActive = true;
|
||||
}
|
||||
|
||||
|
||||
void Graphic::setRectToLines() {
|
||||
is_lines_update = true;
|
||||
//line_x_min.is_auto = line_x_max.is_auto = line_y_min.is_auto = line_y_max.is_auto = true;
|
||||
//qDebug() << "set to lines" << selrect;
|
||||
//line_x_min.is_reset = line_x_max.is_reset = line_y_min.is_reset = line_y_max.is_reset = isFit;
|
||||
if (line_x_min.isVisible() && line_x_max.isVisible() && line_y_min.isVisible() && line_y_max.isVisible()) {
|
||||
line_x_min.blockSignals(true); line_x_max.blockSignals(true); line_y_min.blockSignals(true); line_y_max.blockSignals(true);
|
||||
if (!line_x_min.hasFocus()) {
|
||||
@@ -1511,12 +1356,7 @@ void Graphic::setRectToLines() {
|
||||
line_y_min.setDefaultText(QString::number(grect.bottom()).toUpper());
|
||||
line_y_max.setDefaultText(QString::number(grect.top()).toUpper());
|
||||
line_x_min.blockSignals(false); line_x_max.blockSignals(false); line_y_min.blockSignals(false); line_y_max.blockSignals(false);
|
||||
// if(isFit) {
|
||||
// line_y_min.setValue(grect.left());
|
||||
// line_y_max.setValue(grect.left());
|
||||
// }
|
||||
}
|
||||
//line_x_min.is_auto = line_x_max.is_auto = line_y_min.is_auto = line_y_max.is_auto = false;
|
||||
is_lines_update = false;
|
||||
}
|
||||
|
||||
@@ -1529,7 +1369,6 @@ void Graphic::checkLines() {
|
||||
|
||||
void Graphic::tick(int index, bool slide, bool update_) {
|
||||
if (slide) {
|
||||
///mutex.lock();
|
||||
GraphicType & t(graphics[index]);
|
||||
if (history > 0.)
|
||||
while (t.polyline.size() > 1) {
|
||||
@@ -1549,17 +1388,13 @@ void Graphic::tick(int index, bool slide, bool update_) {
|
||||
}
|
||||
if (!update_) {
|
||||
if (isFit) findGraphicsRect();
|
||||
///mutex.unlock();
|
||||
return;
|
||||
}
|
||||
//polyline.push_back(QPointF(brick->time_, brick->output(port)));
|
||||
//cout << polyline.size() << endl;
|
||||
if (isFit) findGraphicsRect();
|
||||
if (!slide) {
|
||||
if (aupdate) update();
|
||||
return;
|
||||
}
|
||||
///mutex.unlock();
|
||||
if (aupdate) update();
|
||||
}
|
||||
|
||||
@@ -1650,10 +1485,8 @@ void Graphic::updateLegend(bool es) {
|
||||
}
|
||||
if (!ui->widgetLegend->isVisibleTo(this)) {
|
||||
if (es) emit graphicSettingsChanged();
|
||||
// qDebug() << "skip updateLegend";
|
||||
return;
|
||||
}
|
||||
// qDebug() << "updateLegend" << graphics.size();
|
||||
leg_update = false;
|
||||
int ps = 100;
|
||||
for (int r = 0; r < ui->layoutLegend->rowCount(); ++r)
|
||||
@@ -1669,12 +1502,10 @@ void Graphic::updateLegend(bool es) {
|
||||
for (int i = 0; i < graphics.size(); i++) {
|
||||
graphics[i].pb = new QCheckBox(graphics[i].name);
|
||||
graphics[i].pb->setIconSize(pix.size());
|
||||
//graphics[i].pb->setFlat(true);
|
||||
graphics[i].pb->setIcon(graphics[i].icon);
|
||||
graphics[i].pb->setChecked(graphics[i].visible);
|
||||
graphics[i].pb->setProperty("graphic_num", i);
|
||||
graphics[i].pb->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
//qDebug() << graphics[i].pb->actions();
|
||||
QAction * act = new QAction(tr("Check all"), 0);
|
||||
act->setCheckable(true);
|
||||
act->setChecked(true);
|
||||
@@ -1719,7 +1550,6 @@ void Graphic::graphicVisibleChange(bool checked) {
|
||||
if (isFit) on_buttonAutofit_clicked();
|
||||
else update();
|
||||
emit graphicSettingsChanged();
|
||||
//update();
|
||||
}
|
||||
|
||||
|
||||
@@ -1738,7 +1568,6 @@ void Graphic::graphicAllVisibleChange(bool checked) {
|
||||
|
||||
void Graphic::enterFullscreen() {
|
||||
if (fullscr) return;
|
||||
//QMessageBox::information(0, "", "enter");
|
||||
fullscr = true;
|
||||
canvas->hide();
|
||||
#ifdef Q_OS_ANDROID
|
||||
@@ -1750,7 +1579,6 @@ void Graphic::enterFullscreen() {
|
||||
QPushButton * btn = new QPushButton("Leave fullscreen");
|
||||
dlg.layout()->addWidget(btn);
|
||||
connect(btn, SIGNAL(clicked(bool)), this, SLOT(leaveFullscreen()));
|
||||
//connect(fullscr_dialog, SIGNAL(finished(int)), this, SLOT(leaveFullscreen()));
|
||||
canvas->show();
|
||||
dlg.showFullScreen();
|
||||
dlg.exec();
|
||||
@@ -1771,9 +1599,7 @@ void Graphic::leaveFullscreen() {
|
||||
if (tm_fscr.elapsed() < 100) return;
|
||||
#endif
|
||||
if (!fullscr) return;
|
||||
//QMessageBox::information(0, "", "leave");
|
||||
fullscr = false;
|
||||
//canvas->hide();
|
||||
#ifndef Q_OS_ANDROID
|
||||
canvas->showNormal();
|
||||
canvas->hide();
|
||||
@@ -1828,7 +1654,6 @@ QByteArray Graphic::save() {
|
||||
void Graphic::load(QByteArray ba) {
|
||||
if (ba.isEmpty()) return;
|
||||
char ver = ba[0];
|
||||
//qDebug() << "load" << (int)ver;
|
||||
switch(ver) {
|
||||
case '2': {// version '2':
|
||||
ba.remove(0, 1);
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <QDebug>
|
||||
#include <QGridLayout>
|
||||
#include <QFileDialog>
|
||||
#include <QTime>
|
||||
#include <QElapsedTimer>
|
||||
#include <QTranslator>
|
||||
#include <QGestureEvent>
|
||||
#include <qmath.h>
|
||||
@@ -113,16 +113,12 @@ class QAD_EXPORT Graphic: public QFrame
|
||||
Q_PROPERTY(double graduationStepY READ graduationStepY WRITE setGraduationStepY)
|
||||
Q_PROPERTY(AxisType axisType READ axisType WRITE setAxisType)
|
||||
|
||||
Q_PROPERTY(int histogramMinIntervals READ histogramMinIntervals WRITE setHistogramMinIntervals)
|
||||
Q_PROPERTY(int histogramMaxIntervals READ histogramMaxIntervals WRITE setHistogramMaxIntervals)
|
||||
Q_PROPERTY(double histogramMinDeltaMultiplier READ histogramMinDeltaMultiplier WRITE setHistogramMinDeltaMultiplier)
|
||||
|
||||
Q_PROPERTY(Graphic::GraphicsData graphicsData READ graphicsData WRITE setGraphicsData)
|
||||
Q_PROPERTY(QByteArray graphicsDataRaw READ graphicsDataRaw WRITE setGraphicsDataRaw)
|
||||
|
||||
public:
|
||||
Graphic(QWidget * parent = 0);
|
||||
~Graphic();
|
||||
virtual ~Graphic();
|
||||
|
||||
typedef QVector<QVector<QPointF> > GraphicsData;
|
||||
enum GraphicAction {gaNone, gaZoomInRect, gaZoomRangeX, gaZoomRangeY, gaMove};
|
||||
@@ -196,9 +192,6 @@ public:
|
||||
QRectF limit() const {return limit_;}
|
||||
QRect margins() const {return margins_;}
|
||||
int minimumRepaintInterval() const {return min_repaint_int;}
|
||||
int histogramMinIntervals() const {return min_int;}
|
||||
int histogramMaxIntervals() const {return max_int;}
|
||||
double histogramMinDeltaMultiplier() const {return mdm;}
|
||||
double gridNumbersMultiplierX() const {return grid_numbers_x;}
|
||||
double gridNumbersMultiplierY() const {return grid_numbers_y;}
|
||||
Graduation graduationX() const {return grad_x;}
|
||||
@@ -212,17 +205,11 @@ 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();}
|
||||
void reset() {clear();}
|
||||
|
||||
GraphicType graphic(int arg) {if (arg < 0 || arg >= graphics.size()) return GraphicType(); return graphics[arg];}
|
||||
const QVector<GraphicType> & allGraphics() const {return graphics;}
|
||||
void setAllGraphics(const QVector<GraphicType> & g, bool update = true) {graphics = g; if (update) updateLegend();}
|
||||
// void setHistogramData(const QVector<float> & g, int graphic);
|
||||
// void setHistogramData(const QVector<float> & g) {setHistogramData(g, curGraphic);}
|
||||
|
||||
double canvas2realX(double px) const;
|
||||
double canvas2realY(double py) const;
|
||||
@@ -295,9 +282,6 @@ public slots:
|
||||
void setOnlyExpandY(bool yes);
|
||||
void setOnlyExpandX(bool yes);
|
||||
void setGesturesNavigation(bool yes);
|
||||
void setHistogramMinIntervals(int value) {min_int = value; updateGraphics();}
|
||||
void setHistogramMaxIntervals(int value) {max_int = value; updateGraphics();}
|
||||
void setHistogramMinDeltaMultiplier(double value) {mdm = value; updateGraphics();}
|
||||
void setGraphicsData(const GraphicsData & gd);
|
||||
void setGraphicsDataRaw(const QByteArray & ba);
|
||||
|
||||
@@ -376,8 +360,6 @@ protected:
|
||||
|
||||
Ui::Graphic * ui;
|
||||
UGLWidget * canvas_gl;
|
||||
///QMutex mutex, mutex_;
|
||||
QDialog * fullscr_dialog;
|
||||
QWidget * canvas;
|
||||
QImage * buffer;
|
||||
QPainter * painter;
|
||||
@@ -387,7 +369,7 @@ protected:
|
||||
QVector<GraphicType> graphics;
|
||||
int curGraphic;
|
||||
GraphicAction curaction, prevaction;
|
||||
QRectF grect, rrect, selrect, limit_, def_rect;
|
||||
QRectF grect, selrect, limit_, def_rect;
|
||||
QRect margins_;
|
||||
QSize font_sz;
|
||||
QPoint startpos, curpos, prevpos, gridborder;
|
||||
@@ -397,15 +379,15 @@ protected:
|
||||
Graphic::Alignment align;
|
||||
GraphicConf * conf;
|
||||
EvalSpinBox line_x_min, line_x_max, line_y_min, line_y_max;
|
||||
QTime tm, tm_fscr;
|
||||
QElapsedTimer tm;
|
||||
QIcon icon_exp_x, icon_exp_y, icon_exp_sx, icon_exp_sy;
|
||||
QImage icon_pause_b, icon_pause_f;
|
||||
Graduation grad_x, grad_y;
|
||||
AxisType axis_type_x;
|
||||
double gridx, gridy, history, visible_time, inc_x, mdm, grid_numbers_x, grid_numbers_y, LN2, LN5, LN10;
|
||||
double gridx, gridy, history, visible_time, inc_x, grid_numbers_x, grid_numbers_y, LN10;
|
||||
double eminx, eminy, emaxx, emaxy, pause_phase, gesture_angle;
|
||||
int legy, lastw, lasth, min_repaint_int, min_int, max_int, timer_pause, thick;
|
||||
bool aalias, aupdate, mupdate, grid, guides, isFit, isEmpty, isOGL, isHover, bufferActive, cancel, pause_, isPrinting, gestures;
|
||||
int legy/*What is it?*/, lastw, lasth, min_repaint_int, timer_pause, thick;
|
||||
bool aalias, aupdate, grid, guides, isFit, isOGL, isHover, bufferActive, cancel, pause_, gestures;
|
||||
bool hasLblX, hasLblY, navigation, only_expand_y, only_expand_x, is_lines_update, leg_update, visible_update, fullscr, need_mouse_pan;
|
||||
|
||||
protected slots:
|
||||
@@ -424,7 +406,7 @@ protected slots:
|
||||
void lineYMinChanged(double value) {selrect.setBottom(value); checkLines();}
|
||||
void lineYMaxChanged(double value) {selrect.setTop(value); checkLines();}
|
||||
void on_buttonClose_clicked() {emit closeRequest(this);}
|
||||
void on_buttonClear_clicked() {reset(); emit cleared();}
|
||||
void on_buttonClear_clicked() {clear(); emit cleared();}
|
||||
void on_buttonAutofit_clicked();
|
||||
void on_buttonConfigure_clicked();
|
||||
void on_buttonFullscreen_clicked() {fullscreen();}
|
||||
|
||||
Reference in New Issue
Block a user