code format
This commit is contained in:
@@ -1,19 +1,21 @@
|
||||
#include "graphic.h"
|
||||
|
||||
#include "gif.h"
|
||||
#include "qad_types.h"
|
||||
#include "uglwidget.h"
|
||||
#include "ui_graphic.h"
|
||||
#include "ui_graphic_conf.h"
|
||||
#include <float.h>
|
||||
#include <QMetaObject>
|
||||
|
||||
#include <QActionGroup>
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QTapAndHoldGesture>
|
||||
#include <QMetaObject>
|
||||
#include <QPanGesture>
|
||||
#include <QPinchGesture>
|
||||
#include <QActionGroup>
|
||||
#include <QScrollArea>
|
||||
#include <QTapAndHoldGesture>
|
||||
#include <QTimer>
|
||||
#include <QInputDialog>
|
||||
#include "gif.h"
|
||||
#include <float.h>
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
# include <QRandomGenerator>
|
||||
#endif
|
||||
@@ -21,12 +23,12 @@
|
||||
# define NO_BUTTONS
|
||||
#else
|
||||
# ifndef FORCE_NO_GL
|
||||
# define HAS_GL
|
||||
# define HAS_GL
|
||||
# endif
|
||||
#endif
|
||||
#ifdef HAS_GL
|
||||
# ifndef GL_MULTISAMPLE
|
||||
# define GL_MULTISAMPLE 0x809D
|
||||
# define GL_MULTISAMPLE 0x809D
|
||||
# endif
|
||||
#endif
|
||||
|
||||
@@ -42,7 +44,7 @@ enum DateComponent {
|
||||
};
|
||||
|
||||
const char _button_prop_name_[] = "_button_";
|
||||
const double rad2deg_qpie = 45. / atan(1.);
|
||||
const double rad2deg_qpie = 45. / atan(1.);
|
||||
|
||||
__GraphicRegistrator__ __graphic_registrator__;
|
||||
|
||||
@@ -61,6 +63,7 @@ public:
|
||||
w->setAutoFillBackground(false);
|
||||
}
|
||||
int minimum_hei;
|
||||
|
||||
protected:
|
||||
virtual QSize sizeHint() const {
|
||||
QSize ret;
|
||||
@@ -68,26 +71,24 @@ protected:
|
||||
ret = widget()->sizeHint();
|
||||
return ret;
|
||||
}
|
||||
virtual QSize minimumSizeHint() const {
|
||||
return QSize(1, minimum_hei);
|
||||
}
|
||||
virtual QSize minimumSizeHint() const { return QSize(1, minimum_hei); }
|
||||
};
|
||||
|
||||
|
||||
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;
|
||||
canvas_gl = 0;
|
||||
timer_pause = timer_record = 0;
|
||||
gesture_angle = 45.;
|
||||
leg_update = true;
|
||||
gesture_angle = 45.;
|
||||
leg_update = true;
|
||||
visible_update = fullscr = need_mouse_pan = m_fakeGL = false;
|
||||
gestures =
|
||||
#ifdef Q_OS_ANDROID
|
||||
true;
|
||||
true;
|
||||
#else
|
||||
false;
|
||||
false;
|
||||
#endif
|
||||
func_gridMarkX = func_gridMarkY = nullptr;
|
||||
ui = new Ui::Graphic();
|
||||
ui = new Ui::Graphic();
|
||||
ui->setupUi(this);
|
||||
ui->scrollLegend->layout()->addWidget(new LegendScrollArea(ui->widgetLegend));
|
||||
ui->scrollLegend->hide();
|
||||
@@ -95,21 +96,20 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
|
||||
#ifdef NO_BUTTONS
|
||||
ui->widgetLeft->hide();
|
||||
ui->widgetRight->hide();
|
||||
QList<QToolButton*> btnlist = {
|
||||
ui->graphic_buttonAutofit,
|
||||
ui->graphic_checkGrid,
|
||||
ui->graphic_checkGuides,
|
||||
ui->graphic_buttonFullscreen,
|
||||
ui->graphic_checkBorderInputs,
|
||||
ui->graphic_checkLegend,
|
||||
ui->graphic_checkPause,
|
||||
ui->graphic_buttonConfigure,
|
||||
ui->graphic_buttonSave,
|
||||
ui->graphic_buttonExport,
|
||||
ui->graphic_buttonRecord,
|
||||
ui->graphic_buttonClear,
|
||||
ui->graphic_buttonClose};
|
||||
buttons_menu = new QMenu(this);
|
||||
QList<QToolButton *> btnlist = {ui->graphic_buttonAutofit,
|
||||
ui->graphic_checkGrid,
|
||||
ui->graphic_checkGuides,
|
||||
ui->graphic_buttonFullscreen,
|
||||
ui->graphic_checkBorderInputs,
|
||||
ui->graphic_checkLegend,
|
||||
ui->graphic_checkPause,
|
||||
ui->graphic_buttonConfigure,
|
||||
ui->graphic_buttonSave,
|
||||
ui->graphic_buttonExport,
|
||||
ui->graphic_buttonRecord,
|
||||
ui->graphic_buttonClear,
|
||||
ui->graphic_buttonClose};
|
||||
buttons_menu = new QMenu(this);
|
||||
for (auto * b: btnlist) {
|
||||
auto * a = new QAction(this);
|
||||
connect(a, SIGNAL(triggered()), b, SLOT(click()));
|
||||
@@ -120,31 +120,31 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
|
||||
}
|
||||
#endif
|
||||
QActionGroup * agroup = new QActionGroup(this);
|
||||
agroup->addAction(ui->graphic_actionGuidesFree );
|
||||
agroup->addAction(ui->graphic_actionGuidesTrace );
|
||||
agroup->addAction(ui->graphic_actionGuidesFree);
|
||||
agroup->addAction(ui->graphic_actionGuidesTrace);
|
||||
agroup->addAction(ui->graphic_actionGuidesTraceX);
|
||||
agroup->addAction(ui->graphic_actionGuidesTraceY);
|
||||
ui->graphic_actionGuidesFree ->setProperty("_value", (int)Free );
|
||||
ui->graphic_actionGuidesTrace ->setProperty("_value", (int)TraceXY);
|
||||
ui->graphic_actionGuidesTraceX->setProperty("_value", (int)TraceX );
|
||||
ui->graphic_actionGuidesTraceY->setProperty("_value", (int)TraceY );
|
||||
ui->graphic_actionGuidesFree->setProperty("_value", (int)Free);
|
||||
ui->graphic_actionGuidesTrace->setProperty("_value", (int)TraceXY);
|
||||
ui->graphic_actionGuidesTraceX->setProperty("_value", (int)TraceX);
|
||||
ui->graphic_actionGuidesTraceY->setProperty("_value", (int)TraceY);
|
||||
ui->graphic_actionGuidesFree->setChecked(true);
|
||||
connect(agroup, SIGNAL(triggered(QAction*)), this, SLOT(actionGuidesTriggered(QAction*)));
|
||||
ui->graphic_checkGuides ->addAction(ui->graphic_actionGuidesFree );
|
||||
ui->graphic_checkGuides ->addAction(ui->graphic_actionGuidesTrace );
|
||||
ui->graphic_checkGuides ->addAction(ui->graphic_actionGuidesTraceX);
|
||||
ui->graphic_checkGuides ->addAction(ui->graphic_actionGuidesTraceY);
|
||||
connect(agroup, SIGNAL(triggered(QAction *)), this, SLOT(actionGuidesTriggered(QAction *)));
|
||||
ui->graphic_checkGuides->addAction(ui->graphic_actionGuidesFree);
|
||||
ui->graphic_checkGuides->addAction(ui->graphic_actionGuidesTrace);
|
||||
ui->graphic_checkGuides->addAction(ui->graphic_actionGuidesTraceX);
|
||||
ui->graphic_checkGuides->addAction(ui->graphic_actionGuidesTraceY);
|
||||
ui->graphic_buttonAutofit->addAction(ui->graphic_actionExpandX);
|
||||
ui->graphic_buttonAutofit->addAction(ui->graphic_actionExpandY);
|
||||
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);
|
||||
((QBoxLayout * )ui->widgetLY->layout())->addWidget(&line_y_max);
|
||||
((QBoxLayout * )ui->widgetLX->layout())->insertWidget(0, &line_x_min);
|
||||
((QBoxLayout * )ui->widgetLX->layout())->addWidget(&line_x_max);
|
||||
((QBoxLayout *)ui->widgetLY->layout())->insertWidget(0, &line_y_min);
|
||||
((QBoxLayout *)ui->widgetLY->layout())->addWidget(&line_y_max);
|
||||
((QBoxLayout *)ui->widgetLX->layout())->insertWidget(0, &line_x_min);
|
||||
((QBoxLayout *)ui->widgetLX->layout())->addWidget(&line_x_max);
|
||||
tm.restart();
|
||||
grid_numbers_x = grid_numbers_y = 1;
|
||||
LN10 = qLn(10.);
|
||||
LN10 = qLn(10.);
|
||||
line_x_min.setClearButtonVisible(true);
|
||||
line_x_max.setClearButtonVisible(true);
|
||||
line_y_min.setClearButtonVisible(true);
|
||||
@@ -153,12 +153,12 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
|
||||
connect(&line_x_max, SIGNAL(valueChanged(double)), this, SLOT(lineXMaxChanged(double)));
|
||||
connect(&line_y_min, SIGNAL(valueChanged(double)), this, SLOT(lineYMinChanged(double)));
|
||||
connect(&line_y_max, SIGNAL(valueChanged(double)), this, SLOT(lineYMaxChanged(double)));
|
||||
connect(ui->canvas_raster, SIGNAL(paintEvent(QPaintEvent * )), this, SLOT(canvasPaintEvent()));
|
||||
connect(ui->canvas_raster, SIGNAL(paintEvent(QPaintEvent *)), this, SLOT(canvasPaintEvent()));
|
||||
prepareCanvas(ui->canvas_raster);
|
||||
icon_exp_x = QIcon(":/icons/expand_x.png");
|
||||
icon_exp_y = QIcon(":/icons/expand_y.png");
|
||||
icon_exp_sx = QIcon(":/icons/expand_s_x.png");
|
||||
icon_exp_sy = QIcon(":/icons/expand_s_y.png");
|
||||
icon_exp_x = QIcon(":/icons/expand_x.png");
|
||||
icon_exp_y = QIcon(":/icons/expand_y.png");
|
||||
icon_exp_sx = QIcon(":/icons/expand_s_x.png");
|
||||
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 = navigation = true;
|
||||
@@ -167,17 +167,17 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
|
||||
limit_.setCoords(-DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX);
|
||||
eminx = eminy = DBL_MAX;
|
||||
emaxx = emaxy = DBL_MIN;
|
||||
grad_x = grad_y = Auto;
|
||||
axis_type_x = Numeric;
|
||||
grad_x = grad_y = Auto;
|
||||
axis_type_x = Numeric;
|
||||
floating_axis_type = Free;
|
||||
min_repaint_int = 25;
|
||||
min_repaint_int = 25;
|
||||
lastw = lasth = 0;
|
||||
inc_x = 1.;
|
||||
//buffer = 0;
|
||||
inc_x = 1.;
|
||||
// buffer = 0;
|
||||
gridx = gridy = 1.;
|
||||
history = 5.;
|
||||
visible_time = -1.;
|
||||
thick = lineThickness(this);
|
||||
history = 5.;
|
||||
visible_time = -1.;
|
||||
thick = lineThickness(this);
|
||||
#if QT_VERSION_MAJOR >= 5
|
||||
thick *= devicePixelRatio();
|
||||
#endif
|
||||
@@ -189,13 +189,13 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
|
||||
selbrush.setStyle(Qt::SolidPattern);
|
||||
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);
|
||||
grid_pen = QPen(palette().color(QPalette::Disabled, QPalette::WindowText), 0., Qt::DotLine);
|
||||
graphics.append(GraphicType());
|
||||
curGraphic = curTrace = 0;
|
||||
selpen = palette().color(QPalette::WindowText);
|
||||
selpen = palette().color(QPalette::WindowText);
|
||||
selpen.setStyle(Qt::DashLine);
|
||||
back_color = palette().color(QPalette::Base);
|
||||
buttons_ = AllButtons;
|
||||
buttons_ = AllButtons;
|
||||
setOpenGL(false);
|
||||
setButtonsPosition(Graphic::Left);
|
||||
setAntialiasing(false);
|
||||
@@ -215,7 +215,7 @@ Graphic::~Graphic() {
|
||||
delete buttons_menu;
|
||||
#endif
|
||||
delete conf;
|
||||
//if (buffer != 0) delete buffer;
|
||||
// if (buffer != 0) delete buffer;
|
||||
}
|
||||
|
||||
|
||||
@@ -232,7 +232,7 @@ void Graphic::changeEvent(QEvent * e) {
|
||||
void Graphic::resizeEvent(QResizeEvent *) {
|
||||
if (leg_update)
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
|
||||
QTimer::singleShot(0, this, [this](){updateLegend(false);});
|
||||
QTimer::singleShot(0, this, [this]() { updateLegend(false); });
|
||||
#else
|
||||
updateLegend(false);
|
||||
#endif
|
||||
@@ -241,7 +241,7 @@ void Graphic::resizeEvent(QResizeEvent *) {
|
||||
|
||||
void Graphic::showEvent(QShowEvent *) {
|
||||
if (need_createGL && !canvas_gl) {
|
||||
//qDebug() << "create GL on show";
|
||||
// qDebug() << "create GL on show";
|
||||
canvas_gl = new UGLWidget();
|
||||
ui->layoutCanvas->addWidget(canvas_gl);
|
||||
connect(canvas_gl, SIGNAL(paintSignal()), this, SLOT(canvasPaintEvent()));
|
||||
@@ -257,8 +257,7 @@ void Graphic::showEvent(QShowEvent *) {
|
||||
void Graphic::timerEvent(QTimerEvent * e) {
|
||||
if (e->timerId() == timer_pause) {
|
||||
pause_phase += 0.02;
|
||||
if (pause_phase > 1.)
|
||||
pause_phase -= 1.;
|
||||
if (pause_phase > 1.) pause_phase -= 1.;
|
||||
update();
|
||||
}
|
||||
if (e->timerId() == timer_record) {
|
||||
@@ -274,16 +273,16 @@ bool Graphic::eventFilter(QObject * o, QEvent * e) {
|
||||
switch (e->type()) {
|
||||
case QEvent::Gesture:
|
||||
if (!navigation || !gestures) break;
|
||||
foreach (QGesture * g, ((QGestureEvent*)e)->gestures())
|
||||
foreach(QGesture * g, ((QGestureEvent *)e)->gestures())
|
||||
procGesture(g);
|
||||
break;
|
||||
case QEvent::KeyPress: {
|
||||
int k = ((QKeyEvent*)e)->key();
|
||||
int k = ((QKeyEvent *)e)->key();
|
||||
if ((k == Qt::Key_Back || k == Qt::Key_Escape) && fullscr) {
|
||||
leaveFullscreen();
|
||||
return true;
|
||||
}
|
||||
} break;
|
||||
} break;
|
||||
case QEvent::TouchBegin:
|
||||
if (!navigation || !gestures) break;
|
||||
need_mouse_pan = true;
|
||||
@@ -292,9 +291,9 @@ bool Graphic::eventFilter(QObject * o, QEvent * e) {
|
||||
if (!navigation || !gestures) break;
|
||||
QList<QTouchEvent::TouchPoint> tpl =
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
((QTouchEvent*)e)->touchPoints();
|
||||
((QTouchEvent *)e)->touchPoints();
|
||||
#else
|
||||
((QTouchEvent*)e)->points();
|
||||
((QTouchEvent *)e)->points();
|
||||
#endif
|
||||
if (tpl.size() == 2) {
|
||||
need_mouse_pan = false;
|
||||
@@ -306,7 +305,7 @@ bool Graphic::eventFilter(QObject * o, QEvent * e) {
|
||||
#endif
|
||||
gesture_angle = rad2deg_qpie * qAtan2(qAbs(dp.y()), qAbs(dp.x()));
|
||||
}
|
||||
} break;
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@@ -315,13 +314,13 @@ bool Graphic::eventFilter(QObject * o, QEvent * e) {
|
||||
|
||||
|
||||
void Graphic::prepareCanvas(QWidget * w) {
|
||||
connect(w, SIGNAL(mouseMoveEvent(QMouseEvent * )), this, SLOT(canvasMouseMoveEvent(QMouseEvent * )));
|
||||
connect(w, SIGNAL(mousePressEvent(QMouseEvent * )), this, SLOT(canvasMousePressEvent(QMouseEvent * )));
|
||||
connect(w, SIGNAL(mouseReleaseEvent(QMouseEvent * )), this, SLOT(canvasMouseReleaseEvent(QMouseEvent * )));
|
||||
connect(w, SIGNAL(mouseDoubleClickEvent(QMouseEvent*)), this, SLOT(canvasMouseDoubleClickEvent(QMouseEvent * )));
|
||||
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 * )));
|
||||
connect(w, SIGNAL(mouseMoveEvent(QMouseEvent *)), this, SLOT(canvasMouseMoveEvent(QMouseEvent *)));
|
||||
connect(w, SIGNAL(mousePressEvent(QMouseEvent *)), this, SLOT(canvasMousePressEvent(QMouseEvent *)));
|
||||
connect(w, SIGNAL(mouseReleaseEvent(QMouseEvent *)), this, SLOT(canvasMouseReleaseEvent(QMouseEvent *)));
|
||||
connect(w, SIGNAL(mouseDoubleClickEvent(QMouseEvent *)), this, SLOT(canvasMouseDoubleClickEvent(QMouseEvent *)));
|
||||
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::TapAndHoldGesture);
|
||||
w->grabGesture(Qt::PanGesture);
|
||||
w->grabGesture(Qt::PinchGesture);
|
||||
@@ -335,15 +334,15 @@ void Graphic::procGesture(QGesture * g) {
|
||||
switch (g->gestureType()) {
|
||||
case Qt::PanGesture: {
|
||||
if (need_mouse_pan) break;
|
||||
QPanGesture * pg = (QPanGesture*)g;
|
||||
QPointF dp = -pg->delta();
|
||||
QPanGesture * pg = (QPanGesture *)g;
|
||||
QPointF dp = -pg->delta();
|
||||
dp.rx() /= getScaleX();
|
||||
dp.ry() /= getScaleY();
|
||||
selrect.translate(dp);
|
||||
totalUpdate();
|
||||
} break;
|
||||
} break;
|
||||
case Qt::PinchGesture: {
|
||||
QPinchGesture * pg = (QPinchGesture*)g;
|
||||
QPinchGesture * pg = (QPinchGesture *)g;
|
||||
Qt::KeyboardModifiers km = Qt::NoModifier;
|
||||
if (gesture_angle <= 20.) km = Qt::ControlModifier;
|
||||
if (gesture_angle >= 70.) km = Qt::ShiftModifier;
|
||||
@@ -351,33 +350,33 @@ void Graphic::procGesture(QGesture * g) {
|
||||
if (!fullscr) cp = mapFromGlobal(cp);
|
||||
procZoom(cp, (pg->scaleFactor() - 1.) * 500., km);
|
||||
totalUpdate();
|
||||
} break;
|
||||
} break;
|
||||
case Qt::TapAndHoldGesture: {
|
||||
QTapAndHoldGesture * pg = (QTapAndHoldGesture*)g;
|
||||
QTapAndHoldGesture * pg = (QTapAndHoldGesture *)g;
|
||||
if (pg->state() == Qt::GestureStarted)
|
||||
QMetaObject::invokeMethod(this, [this](){showMenu();}, Qt::QueuedConnection);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this]() { showMenu(); },
|
||||
Qt::QueuedConnection);
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Graphic::procZoom(QPointF view_center, double dzoom, Qt::KeyboardModifiers km) {
|
||||
double scl, wid = canvas->width() - gridborder.x() - margins_.width() - margins_.left(), hei = canvas->height() - gridborder.y() - margins_.height() - margins_.top();
|
||||
double scl, wid = canvas->width() - gridborder.x() - margins_.width() - margins_.left(),
|
||||
hei = canvas->height() - gridborder.y() - margins_.height() - margins_.top();
|
||||
double px = view_center.x() - gridborder.x() - margins_.left(), py = hei - view_center.y() + margins_.height();
|
||||
px = px / wid * selrect.width() + selrect.x();
|
||||
py = py / hei * selrect.height() + selrect.y();
|
||||
px = px / wid * selrect.width() + selrect.x();
|
||||
py = py / hei * selrect.height() + selrect.y();
|
||||
scl = 1. - dzoom / 500.;
|
||||
if (km == Qt::NoModifier)
|
||||
selrect.setRect(px - (px - selrect.x()) * scl, py - (py - selrect.y()) * scl, selrect.width() * scl, selrect.height() * scl);
|
||||
else {
|
||||
if (km == Qt::ControlModifier)
|
||||
selrect.setRect(px - (px - selrect.x()) * scl, selrect.y(), selrect.width() * scl, selrect.height());
|
||||
if (km == Qt::ShiftModifier)
|
||||
selrect.setRect(selrect.x(), py - (py - selrect.y()) * scl, selrect.width(), selrect.height() * scl);
|
||||
if (km == Qt::AltModifier)
|
||||
selrect.translate((dzoom > 0. ? 1. : -1.) * selrect.width() / 2., 0.);
|
||||
if (km == Qt::ControlModifier) selrect.setRect(px - (px - selrect.x()) * scl, selrect.y(), selrect.width() * scl, selrect.height());
|
||||
if (km == Qt::ShiftModifier) selrect.setRect(selrect.x(), py - (py - selrect.y()) * scl, selrect.width(), selrect.height() * scl);
|
||||
if (km == Qt::AltModifier) selrect.translate((dzoom > 0. ? 1. : -1.) * selrect.width() / 2., 0.);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,23 +391,22 @@ void Graphic::totalUpdate() {
|
||||
|
||||
void Graphic::canvasPaintEvent() {
|
||||
if (is_lines_update) return;
|
||||
int wid = canvas->width (),hei = canvas->height();
|
||||
int wid = canvas->width(), hei = canvas->height();
|
||||
if (canvas->isHidden() || wid <= 1 || hei <= 1) return;
|
||||
if (!buffer.isNull()) {
|
||||
if (lastw != wid || lasth != hei)
|
||||
buffer = QPixmap();
|
||||
if (lastw != wid || lasth != hei) buffer = QPixmap();
|
||||
}
|
||||
if (buffer.isNull()) {
|
||||
#if QT_VERSION_MAJOR >= 5
|
||||
const qreal dpr = canvas->devicePixelRatio();
|
||||
buffer = QPixmap(canvas->size() * dpr);
|
||||
buffer = QPixmap(canvas->size() * dpr);
|
||||
buffer.setDevicePixelRatio(dpr);
|
||||
#else
|
||||
buffer = QPixmap(canvas->size());
|
||||
#endif
|
||||
}
|
||||
lastw = wid;
|
||||
lasth = hei;
|
||||
lastw = wid;
|
||||
lasth = hei;
|
||||
font_sz = fontMetrics().size(0, "0");
|
||||
font_sz.setHeight(font_sz.height() * 1.);
|
||||
#ifdef Q_OS_ANDROID
|
||||
@@ -452,13 +450,14 @@ void Graphic::canvasPaintEvent() {
|
||||
painter->setClipRect(QRect(gridborder.x(), 0, wid - gridborder.x(), hei - gridborder.y()));
|
||||
emit beforeGraphicPaintEvent(painter);
|
||||
painter->setClipping(false);
|
||||
if (grid)
|
||||
drawGrid();
|
||||
if (grid) drawGrid();
|
||||
p.setRenderHint(QPainter::Antialiasing, aalias);
|
||||
#ifdef HAS_GL
|
||||
if (isOGL && !m_fakeGL) {
|
||||
if (aalias) glEnable(GL_MULTISAMPLE);
|
||||
else glDisable(GL_MULTISAMPLE);
|
||||
if (aalias)
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
else
|
||||
glDisable(GL_MULTISAMPLE);
|
||||
}
|
||||
#endif
|
||||
fp_size.clear();
|
||||
@@ -476,8 +475,8 @@ void Graphic::canvasPaintEvent() {
|
||||
|
||||
|
||||
void Graphic::canvasMouseMoveEvent(QMouseEvent * e) {
|
||||
isHover = true;
|
||||
curpos = e->pos();
|
||||
isHover = true;
|
||||
curpos = e->pos();
|
||||
curpos_r = canvas2real(curpos);
|
||||
QPointF dp;
|
||||
QString cursorstr = tr("Cursor: ") + pointCoords(curpos_r);
|
||||
@@ -491,38 +490,34 @@ void Graphic::canvasMouseMoveEvent(QMouseEvent * e) {
|
||||
if (gestures) {
|
||||
if (!need_mouse_pan) return;
|
||||
curaction = gaMove;
|
||||
} else
|
||||
if (curaction != gaMove && (e->buttons() & Qt::RightButton) == Qt::RightButton) return;
|
||||
} else if (curaction != gaMove && (e->buttons() & Qt::RightButton) == Qt::RightButton)
|
||||
return;
|
||||
switch (curaction) {
|
||||
case gaZoomInRect:
|
||||
ui->status->setText(tr("Selection") + ": " + pointCoords(startpos_r) + " -> " +
|
||||
pointCoords(curpos_r) + ", " + tr("Size") + ": " + pointCoords(absPoint(curpos_r - startpos_r)));
|
||||
repaintCanvas(true);
|
||||
case gaZoomInRect:
|
||||
ui->status->setText(tr("Selection") + ": " + pointCoords(startpos_r) + " -> " + pointCoords(curpos_r) + ", " + tr("Size") + ": " +
|
||||
pointCoords(absPoint(curpos_r - startpos_r)));
|
||||
repaintCanvas(true);
|
||||
break;
|
||||
case gaZoomRangeX:
|
||||
ui->status->setText(tr("Range") + ": " + QString::number(startpos_r.x(), 'f', 3) +
|
||||
" -> " + QString::number(curpos_r.x(), 'f', 3) + ", " + tr("Length") + ": " +
|
||||
QString::number(qAbs(curpos_r.x() - startpos_r.x()), 'f', 3));
|
||||
repaintCanvas(true);
|
||||
case gaZoomRangeX:
|
||||
ui->status->setText(tr("Range") + ": " + QString::number(startpos_r.x(), 'f', 3) + " -> " + QString::number(curpos_r.x(), 'f', 3) +
|
||||
", " + tr("Length") + ": " + QString::number(qAbs(curpos_r.x() - startpos_r.x()), 'f', 3));
|
||||
repaintCanvas(true);
|
||||
break;
|
||||
case gaZoomRangeY:
|
||||
ui->status->setText(tr("Range") + ": " + QString::number(startpos_r.y(), 'f', 3) +
|
||||
" -> " + QString::number(curpos_r.y(), 'f', 3) + ", " + tr("Length") + ": " +
|
||||
QString::number(qAbs(curpos_r.y() - startpos_r.y()), 'f', 3));
|
||||
repaintCanvas(true);
|
||||
case gaZoomRangeY:
|
||||
ui->status->setText(tr("Range") + ": " + QString::number(startpos_r.y(), 'f', 3) + " -> " + QString::number(curpos_r.y(), 'f', 3) +
|
||||
", " + tr("Length") + ": " + QString::number(qAbs(curpos_r.y() - startpos_r.y()), 'f', 3));
|
||||
repaintCanvas(true);
|
||||
break;
|
||||
case gaMove:
|
||||
dp = e->pos() - prevpos;
|
||||
dp.rx() *= selrect.width() / double(gridborder.x() + 5 - lastw);
|
||||
dp.ry() *= selrect.height() / double(lasth - gridborder.y() - 5);
|
||||
if (e->modifiers() == Qt::ControlModifier)
|
||||
dp.setY(0.);
|
||||
if (e->modifiers() == Qt::ShiftModifier)
|
||||
dp.setX(0.);
|
||||
selrect.translate(dp);
|
||||
totalUpdate();
|
||||
case gaMove:
|
||||
dp = e->pos() - prevpos;
|
||||
dp.rx() *= selrect.width() / double(gridborder.x() + 5 - lastw);
|
||||
dp.ry() *= selrect.height() / double(lasth - gridborder.y() - 5);
|
||||
if (e->modifiers() == Qt::ControlModifier) dp.setY(0.);
|
||||
if (e->modifiers() == Qt::ShiftModifier) dp.setX(0.);
|
||||
selrect.translate(dp);
|
||||
totalUpdate();
|
||||
break;
|
||||
default: break;
|
||||
default: break;
|
||||
}
|
||||
prevpos = e->pos();
|
||||
}
|
||||
@@ -533,14 +528,14 @@ void Graphic::canvasMousePressEvent(QMouseEvent * e) {
|
||||
if (!navigation) return;
|
||||
if (gestures && !need_mouse_pan) return;
|
||||
setGuidesCursor();
|
||||
prevpos = e->pos();
|
||||
startpos = prevpos;
|
||||
prevpos = e->pos();
|
||||
startpos = prevpos;
|
||||
startpos_r = canvas2real(startpos);
|
||||
if (cancel || gestures) return;
|
||||
if (e->button() == QT_MID_BUTTON) curaction = gaMove;
|
||||
if (e->button() == Qt::RightButton) {
|
||||
if (bufferActive) {
|
||||
curpos = startpos;
|
||||
curpos = startpos;
|
||||
curpos_r = canvas2real(curpos);
|
||||
repaintCanvas(true);
|
||||
swapToNormal();
|
||||
@@ -553,16 +548,17 @@ void Graphic::canvasMousePressEvent(QMouseEvent * e) {
|
||||
}
|
||||
}
|
||||
if (e->button() == Qt::LeftButton) {
|
||||
if (e->modifiers() == Qt::ControlModifier) curaction = gaZoomRangeX;
|
||||
else if (e->modifiers() == Qt::ShiftModifier) curaction = gaZoomRangeY;
|
||||
else curaction = gaZoomInRect;
|
||||
if (e->modifiers() == Qt::ControlModifier)
|
||||
curaction = gaZoomRangeX;
|
||||
else if (e->modifiers() == Qt::ShiftModifier)
|
||||
curaction = gaZoomRangeY;
|
||||
else
|
||||
curaction = gaZoomInRect;
|
||||
switch (curaction) {
|
||||
case gaZoomInRect:
|
||||
case gaZoomRangeX:
|
||||
case gaZoomRangeY:
|
||||
swapToBuffer();
|
||||
break;
|
||||
default: break;
|
||||
case gaZoomInRect:
|
||||
case gaZoomRangeX:
|
||||
case gaZoomRangeY: swapToBuffer(); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
setCurrentAction(curaction);
|
||||
@@ -588,24 +584,24 @@ void Graphic::canvasMouseReleaseEvent(QMouseEvent * e) {
|
||||
}
|
||||
if (e->button() == Qt::LeftButton && (e->buttons() & Qt::RightButton) != Qt::RightButton) {
|
||||
if (curpos != startpos) {
|
||||
tlp = canvas2real(sr.topLeft());
|
||||
brp = canvas2real(sr.bottomRight());
|
||||
tlp = canvas2real(sr.topLeft());
|
||||
brp = canvas2real(sr.bottomRight());
|
||||
isFit = false;
|
||||
switch (curaction) {
|
||||
case gaZoomInRect:
|
||||
if (sr.width() <= 1 || sr.height() <= 1) break;
|
||||
selrect.setCoords(tlp.x(), brp.y(), brp.x(), tlp.y());
|
||||
setRectToLines();
|
||||
case gaZoomInRect:
|
||||
if (sr.width() <= 1 || sr.height() <= 1) break;
|
||||
selrect.setCoords(tlp.x(), brp.y(), brp.x(), tlp.y());
|
||||
setRectToLines();
|
||||
break;
|
||||
case gaZoomRangeX:
|
||||
if (sr.width() <= 1) break;
|
||||
findGraphicsRect(tlp.x(), brp.x());
|
||||
case gaZoomRangeX:
|
||||
if (sr.width() <= 1) break;
|
||||
findGraphicsRect(tlp.x(), brp.x());
|
||||
break;
|
||||
case gaZoomRangeY:
|
||||
if (sr.height() <= 1) break;
|
||||
findGraphicsRect(0., 0., brp.y(), tlp.y());
|
||||
case gaZoomRangeY:
|
||||
if (sr.height() <= 1) break;
|
||||
findGraphicsRect(0., 0., brp.y(), tlp.y());
|
||||
break;
|
||||
default: return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
swapToNormal();
|
||||
@@ -617,7 +613,7 @@ void Graphic::canvasMouseReleaseEvent(QMouseEvent * e) {
|
||||
}
|
||||
|
||||
|
||||
void Graphic::canvasMouseDoubleClickEvent(QMouseEvent * ) {
|
||||
void Graphic::canvasMouseDoubleClickEvent(QMouseEvent *) {
|
||||
if (!navigation) return;
|
||||
autofit();
|
||||
}
|
||||
@@ -641,11 +637,15 @@ void Graphic::canvasWheelEvent(QWheelEvent * e) {
|
||||
|
||||
|
||||
void Graphic::zoom(float factor) {
|
||||
double wid = canvas->width() - gridborder.x() - margins_.width() - margins_.left(), hei = canvas->height() - gridborder.y() - margins_.height() - margins_.top();
|
||||
double wid = canvas->width() - gridborder.x() - margins_.width() - margins_.left(),
|
||||
hei = canvas->height() - gridborder.y() - margins_.height() - margins_.top();
|
||||
double px = wid / 2, py = hei / 2;
|
||||
px = px / wid * selrect.width() + selrect.x();
|
||||
py = py / hei * selrect.height() + selrect.y();
|
||||
selrect.setRect(px - (px - selrect.x()) * factor, py - (py - selrect.y()) * factor, selrect.width() * factor, selrect.height() * factor);
|
||||
selrect.setRect(px - (px - selrect.x()) * factor,
|
||||
py - (py - selrect.y()) * factor,
|
||||
selrect.width() * factor,
|
||||
selrect.height() * factor);
|
||||
isFit = false;
|
||||
update(true);
|
||||
setRectToLines();
|
||||
@@ -653,12 +653,14 @@ void Graphic::zoom(float factor) {
|
||||
|
||||
|
||||
void Graphic::fullscreen() {
|
||||
if (fullscr) leaveFullscreen();
|
||||
else enterFullscreen();
|
||||
if (fullscr)
|
||||
leaveFullscreen();
|
||||
else
|
||||
enterFullscreen();
|
||||
}
|
||||
|
||||
|
||||
void Graphic::canvasLeaveEvent(QEvent * ) {
|
||||
void Graphic::canvasLeaveEvent(QEvent *) {
|
||||
isHover = false;
|
||||
if (guides) update(true);
|
||||
ui->status->setText(tr("Cursor") + ": ( ; )");
|
||||
@@ -668,8 +670,8 @@ void Graphic::canvasLeaveEvent(QEvent * ) {
|
||||
|
||||
void Graphic::canvasKeyPressEvent(QKeyEvent * e) {
|
||||
switch (e->key()) {
|
||||
case Qt::Key_Escape: leaveFullscreen();
|
||||
default: break;
|
||||
case Qt::Key_Escape: leaveFullscreen();
|
||||
default: break;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -680,7 +682,7 @@ void Graphic::clear() {
|
||||
graphics[i].polyline_pause.clear();
|
||||
graphics[i]._lod.clear();
|
||||
graphics[i]._lod_pause.clear();
|
||||
graphics[i].max_x = 0.;
|
||||
graphics[i].max_x = 0.;
|
||||
graphics[i].cvrect = QRectF();
|
||||
}
|
||||
if (isFit) on_graphic_buttonAutofit_clicked();
|
||||
@@ -725,8 +727,8 @@ void Graphic::setHistorySize(double val) {
|
||||
QPolygonF & pol(graphics[i].polyline);
|
||||
if (pol.isEmpty() || history <= 0.) continue;
|
||||
graphics[i].cvrect = QRectF();
|
||||
x = pol.back().x() - history;
|
||||
for (int j = pol.size() - 2; j >= 0 ; --j)
|
||||
x = pol.back().x() - history;
|
||||
for (int j = pol.size() - 2; j >= 0; --j)
|
||||
if (pol[j].x() < x) {
|
||||
pol.erase(pol.begin(), pol.begin() + j);
|
||||
break;
|
||||
@@ -813,8 +815,8 @@ void Graphic::setButtons(Graphic::Buttons b) {
|
||||
ui->graphic_buttonClose->setVisible(b.testFlag(Close));
|
||||
ui->graphic_checkPause->setVisible(b.testFlag(Pause));
|
||||
ui->graphic_buttonRecord->setVisible(b.testFlag(Record));
|
||||
if (ui->graphic_buttonAutofit ->isVisible() || ui->graphic_checkGrid ->isVisible() || ui->graphic_checkGuides->isVisible() ||
|
||||
ui->graphic_buttonConfigure->isVisible() || ui->graphic_buttonSave->isVisible() || ui->graphic_checkPause ->isVisible())
|
||||
if (ui->graphic_buttonAutofit->isVisible() || ui->graphic_checkGrid->isVisible() || ui->graphic_checkGuides->isVisible() ||
|
||||
ui->graphic_buttonConfigure->isVisible() || ui->graphic_buttonSave->isVisible() || ui->graphic_checkPause->isVisible())
|
||||
ui->verticalSpacer->changeSize(0, 30, QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
else
|
||||
ui->verticalSpacer->changeSize(0, 0, QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
@@ -830,13 +832,13 @@ void Graphic::setButtonsPosition(Graphic::Alignment a) {
|
||||
return;
|
||||
#endif
|
||||
switch (a) {
|
||||
case Graphic::Left:
|
||||
ui->widgetLeft->setLayout(ui->layoutButtons);
|
||||
ui->widgetLeft->show();
|
||||
case Graphic::Left:
|
||||
ui->widgetLeft->setLayout(ui->layoutButtons);
|
||||
ui->widgetLeft->show();
|
||||
break;
|
||||
case Graphic::Right:
|
||||
ui->widgetRight->setLayout(ui->layoutButtons);
|
||||
ui->widgetRight->show();
|
||||
case Graphic::Right:
|
||||
ui->widgetRight->setLayout(ui->layoutButtons);
|
||||
ui->widgetRight->show();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -862,7 +864,7 @@ void Graphic::addPoints(const QPolygonF & pts, int graphic, bool update_) {
|
||||
if (graphic >= graphics.size() || graphic < 0 || pts.isEmpty()) return;
|
||||
GraphicType & t(graphics[graphic]);
|
||||
if (!t.cvrect.isNull() && !pause_) {
|
||||
for(const QPointF & p : pts) {
|
||||
for (const QPointF & p: pts) {
|
||||
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());
|
||||
@@ -870,7 +872,8 @@ void Graphic::addPoints(const QPolygonF & pts, int graphic, bool update_) {
|
||||
}
|
||||
}
|
||||
if (t.polyline.size() == 0) t.max_x = pts.at(0).x();
|
||||
for(const QPointF & p : pts) if (t.max_x < p.x()) t.max_x = p.x();
|
||||
for (const QPointF & p: pts)
|
||||
if (t.max_x < p.x()) t.max_x = p.x();
|
||||
t.polyline << pts;
|
||||
tick(graphic, true, update_);
|
||||
}
|
||||
@@ -881,7 +884,8 @@ void Graphic::addPoints(const QVector<double> & pts, int graphic, bool update_)
|
||||
ps.reserve(pts.size());
|
||||
double stx = 0;
|
||||
if (!graphics[curGraphic].polyline.isEmpty()) stx = graphics[curGraphic].max_x;
|
||||
for (int i=0; i<pts.size(); ++i) ps << QPointF(stx + i*inc_x, pts[i]);
|
||||
for (int i = 0; i < pts.size(); ++i)
|
||||
ps << QPointF(stx + i * inc_x, pts[i]);
|
||||
addPoints(ps, graphic, update_);
|
||||
}
|
||||
|
||||
@@ -899,13 +903,17 @@ void Graphic::setGraphicData(const QVector<QPointF> & g, int graphic, bool updat
|
||||
}
|
||||
t.max_x = t.polyline[0].x();
|
||||
for (int i = 1; i < t.polyline.size(); ++i)
|
||||
if (t.max_x < t.polyline[i].x())
|
||||
t.max_x = t.polyline[i].x();
|
||||
if (t.max_x < t.polyline[i].x()) t.max_x = t.polyline[i].x();
|
||||
tick(graphic, false, update_);
|
||||
}
|
||||
|
||||
|
||||
void Graphic::setGraphicProperties(int graphic, const QString & name, const QColor& color, Qt::PenStyle style, double width, bool visible) {
|
||||
void Graphic::setGraphicProperties(int graphic,
|
||||
const QString & name,
|
||||
const QColor & color,
|
||||
Qt::PenStyle style,
|
||||
double width,
|
||||
bool visible) {
|
||||
if (graphic < 0 || graphic >= graphics.size()) return;
|
||||
graphics[graphic].name = name;
|
||||
graphics[graphic].pen.setColor(color);
|
||||
@@ -924,7 +932,7 @@ void Graphic::addGraphic(const QString & name, const QColor & color, Qt::PenStyl
|
||||
|
||||
void Graphic::setVisualRect(const QRectF & rect) {
|
||||
selrect = rect;
|
||||
isFit = false;
|
||||
isFit = false;
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -962,7 +970,7 @@ void Graphic::exportGraphics(QString filename, QChar decimal_point) {
|
||||
}
|
||||
ts << "\n";
|
||||
bool has_data = true;
|
||||
int ind = 0;
|
||||
int ind = 0;
|
||||
QString line;
|
||||
while (has_data) {
|
||||
has_data = false;
|
||||
@@ -991,8 +999,7 @@ void Graphic::exportGraphics(QString filename, QChar decimal_point) {
|
||||
}
|
||||
++ind;
|
||||
line += "\n";
|
||||
if (has_data)
|
||||
ts << line;
|
||||
if (has_data) ts << line;
|
||||
}
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
@@ -1000,14 +1007,14 @@ void Graphic::exportGraphics(QString filename, QChar decimal_point) {
|
||||
|
||||
void Graphic::setOpenGL(bool on) {
|
||||
#ifdef HAS_GL
|
||||
isOGL = on;
|
||||
isOGL = on;
|
||||
need_createGL = false;
|
||||
if (on && !m_fakeGL) {
|
||||
if (!canvas_gl) {
|
||||
if (!isVisible())
|
||||
need_createGL = true;
|
||||
else {
|
||||
//qDebug() << "create GL on setter";
|
||||
// qDebug() << "create GL on setter";
|
||||
canvas_gl = new UGLWidget();
|
||||
ui->layoutCanvas->addWidget(canvas_gl);
|
||||
connect(canvas_gl, SIGNAL(paintSignal()), this, SLOT(canvasPaintEvent()));
|
||||
@@ -1020,8 +1027,7 @@ void Graphic::setOpenGL(bool on) {
|
||||
canvas = canvas_gl;
|
||||
}
|
||||
} else {
|
||||
if (canvas_gl)
|
||||
canvas_gl->hide();
|
||||
if (canvas_gl) canvas_gl->hide();
|
||||
ui->canvas_raster->show();
|
||||
canvas = ui->canvas_raster;
|
||||
}
|
||||
@@ -1043,7 +1049,9 @@ void Graphic::setGraphicsCount(int arg, bool update) {
|
||||
if (arg < 0) return;
|
||||
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)));
|
||||
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
|
||||
@@ -1064,7 +1072,7 @@ void Graphic::removeGraphic(int arg, bool update) {
|
||||
}
|
||||
|
||||
|
||||
void Graphic::setCustomGridMarkFuncs(std::function<QString (double)> fx, std::function<QString (double)> fy) {
|
||||
void Graphic::setCustomGridMarkFuncs(std::function<QString(double)> fx, std::function<QString(double)> fy) {
|
||||
func_gridMarkX = fx;
|
||||
func_gridMarkY = fy;
|
||||
}
|
||||
@@ -1073,12 +1081,12 @@ void Graphic::setCustomGridMarkFuncs(std::function<QString (double)> fx, std::fu
|
||||
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 can_fast = (start_x == 0 && end_x == 0 && start_y == 0 && end_y == 0);
|
||||
bool can_fast = (start_x == 0 && end_x == 0 && start_y == 0 && end_y == 0);
|
||||
bool anyVisible = false, isTimeLimit = (visible_time > 0.) && !(isRangeX || isRangeY);
|
||||
vx = -DBL_MAX;
|
||||
vx = -DBL_MAX;
|
||||
minY = minX = DBL_MAX;
|
||||
maxY = maxX = -DBL_MAX;
|
||||
foreach (const GraphicType & t, graphics) {
|
||||
foreach(const GraphicType & t, graphics) {
|
||||
if (!t.visible) continue;
|
||||
if (vx < (pause_ ? t.max_x_pause : t.max_x)) vx = (pause_ ? t.max_x_pause : t.max_x);
|
||||
}
|
||||
@@ -1130,8 +1138,14 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou
|
||||
if (maxY < limit_.top()) maxY = limit_.top();
|
||||
if (minX > maxX) qSwap<double>(minX, maxX);
|
||||
if (minY > maxY) qSwap<double>(minY, maxY);
|
||||
if (qAbs<double>(minX - maxX) < 1E-60) {minX -= defaultRect().width()/2; maxX += defaultRect().width()/2;}
|
||||
if (qAbs<double>(minY - maxY) < 1E-60) {minY -= defaultRect().height()/2; maxY += defaultRect().height()/2;}
|
||||
if (qAbs<double>(minX - maxX) < 1E-60) {
|
||||
minX -= defaultRect().width() / 2;
|
||||
maxX += defaultRect().width() / 2;
|
||||
}
|
||||
if (qAbs<double>(minY - maxY) < 1E-60) {
|
||||
minY -= defaultRect().height() / 2;
|
||||
maxY += defaultRect().height() / 2;
|
||||
}
|
||||
if (only_expand_x) {
|
||||
if (minX > eminx) minX = eminx;
|
||||
if (maxX < emaxx) maxX = emaxx;
|
||||
@@ -1140,16 +1154,20 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou
|
||||
if (minY > eminy) minY = eminy;
|
||||
if (maxY < emaxy) maxY = emaxy;
|
||||
}
|
||||
eminx = minX; emaxx = maxX;
|
||||
eminy = minY; emaxy = maxY;
|
||||
if (isRangeX) selrect.setRect(start_x, minY, end_x - start_x, maxY - minY);
|
||||
else if (isRangeY) selrect.setRect(minX, start_y, maxX - minX, end_y - start_y);
|
||||
else grect.setRect(minX, minY, maxX - minX, maxY - minY);
|
||||
eminx = minX;
|
||||
emaxx = maxX;
|
||||
eminy = minY;
|
||||
emaxy = maxY;
|
||||
if (isRangeX)
|
||||
selrect.setRect(start_x, minY, end_x - start_x, maxY - minY);
|
||||
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) {
|
||||
if (visible_time > 0.) {
|
||||
if (grect.width() > visible_time)
|
||||
grect.setLeft(grect.right() - visible_time);
|
||||
if (grect.width() > visible_time) grect.setLeft(grect.right() - visible_time);
|
||||
}
|
||||
selrect = grect;
|
||||
}
|
||||
@@ -1158,28 +1176,29 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou
|
||||
|
||||
|
||||
void Graphic::drawAction() {
|
||||
int wid = canvas->width(), hei = canvas->height() - gridborder.y(), sx = startpos.x(), sy = startpos.y(), cx = curpos.x(), cy = curpos.y();
|
||||
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);
|
||||
switch (curaction) {
|
||||
case gaZoomInRect: {
|
||||
QSizeF rsz = QRectF(startpos_r, curpos_r).normalized().size();
|
||||
painter->drawRect(QRect(startpos, curpos));
|
||||
fp_size = " x " + pointCoords(QPointF(rsz.width(), rsz.height()));
|
||||
} break;
|
||||
case gaZoomRangeX:
|
||||
painter->drawLine(sx, hei, sx, 0);
|
||||
painter->drawLine(cx, hei, cx, 0);
|
||||
painter->fillRect(sx, 0, cx - sx, hei, selbrush);
|
||||
fp_size = " x " + pointCoords(QPointF(qAbs(startpos_r.x() - curpos_r.x()), 0.), true, false);
|
||||
break;
|
||||
case gaZoomRangeY:
|
||||
painter->drawLine(gridborder.x(), sy, wid, sy);
|
||||
painter->drawLine(gridborder.x(), cy, wid, cy);
|
||||
painter->fillRect(gridborder.x(), sy, wid - gridborder.x(), cy - sy, selbrush);
|
||||
fp_size = " x " + pointCoords(QPointF(0., qAbs(startpos_r.y() - curpos_r.y())), false, true);
|
||||
break;
|
||||
default: break;
|
||||
case gaZoomInRect: {
|
||||
QSizeF rsz = QRectF(startpos_r, curpos_r).normalized().size();
|
||||
painter->drawRect(QRect(startpos, curpos));
|
||||
fp_size = " x " + pointCoords(QPointF(rsz.width(), rsz.height()));
|
||||
} break;
|
||||
case gaZoomRangeX:
|
||||
painter->drawLine(sx, hei, sx, 0);
|
||||
painter->drawLine(cx, hei, cx, 0);
|
||||
painter->fillRect(sx, 0, cx - sx, hei, selbrush);
|
||||
fp_size = " x " + pointCoords(QPointF(qAbs(startpos_r.x() - curpos_r.x()), 0.), true, false);
|
||||
break;
|
||||
case gaZoomRangeY:
|
||||
painter->drawLine(gridborder.x(), sy, wid, sy);
|
||||
painter->drawLine(gridborder.x(), cy, wid, cy);
|
||||
painter->fillRect(gridborder.x(), sy, wid - gridborder.x(), cy - sy, selbrush);
|
||||
fp_size = " x " + pointCoords(QPointF(0., qAbs(startpos_r.y() - curpos_r.y())), false, true);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1192,12 +1211,14 @@ void Graphic::drawGrid() {
|
||||
QPair<QString, QString> str;
|
||||
|
||||
range = selrect.bottom() - selrect.top();
|
||||
if (grad_y == Graphic::Auto) step = splitRange(range, hei / gridy / font_sz.height() / 1.4);
|
||||
else step = gridy;
|
||||
if (grad_y == Graphic::Auto)
|
||||
step = splitRange(range, hei / gridy / font_sz.height() / 1.4);
|
||||
else
|
||||
step = gridy;
|
||||
start = roundTo(canvas2realY(-hei), step) - step;
|
||||
py = start + step;
|
||||
cy = 0;
|
||||
cx = gbx - 5;
|
||||
py = start + step;
|
||||
cy = 0;
|
||||
cx = gbx - 5;
|
||||
grid_pen.setWidth(qMax<int>(qMax<int>(qRound(thick / 1.4), 1), grid_pen.width()));
|
||||
#if QT_VERSION_MAJOR >= 5
|
||||
grid_pen.setCosmetic(true);
|
||||
@@ -1257,10 +1278,12 @@ void Graphic::drawGrid() {
|
||||
range = selrect.right() - selrect.left();
|
||||
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;
|
||||
if (grad_x == Graphic::Auto)
|
||||
step = splitRange(range, wid / gridx / font_sz.width() * 1.4);
|
||||
else
|
||||
step = gridx;
|
||||
start = roundTo(canvas2realX(right), step);
|
||||
px = start + step;
|
||||
px = start + step;
|
||||
if (step > 0.) {
|
||||
cnt = 1000;
|
||||
while (cnt-- > 0) {
|
||||
@@ -1300,10 +1323,12 @@ void Graphic::drawGrid() {
|
||||
} else {
|
||||
int dt_add[DateComponentCount];
|
||||
int dt_add_lo[DateComponentCount];
|
||||
for (int i = 0; i < DateComponentCount; ++i) dt_add_lo[i] = dt_add[i] = 0;
|
||||
for (int i = 0; i < DateComponentCount; ++i)
|
||||
dt_add_lo[i] = dt_add[i] = 0;
|
||||
DateFormats formats;
|
||||
step = splitRangeDate(range, wid / gridx / font_sz.width() / 1.5, formats, dt_add);
|
||||
for (int i = 0; i < DateComponentCount - 1; ++i) dt_add_lo[i + 1] = dt_add[i];
|
||||
for (int i = 0; i < DateComponentCount - 1; ++i)
|
||||
dt_add_lo[i + 1] = dt_add[i];
|
||||
bool is_years = formats.center.isEmpty();
|
||||
if (step > 0.) {
|
||||
int up_y = cy - font_sz.height() * 2;
|
||||
@@ -1312,7 +1337,7 @@ void Graphic::drawGrid() {
|
||||
int ddx = 0, pcx = 0;
|
||||
QDateTime cd = QDateTime::fromMSecsSinceEpoch(canvas2realX(gbx) * grid_numbers_x), cdp, cdc, cdl, cdlp;
|
||||
QString ds;
|
||||
//qDebug() << step << range << int(wid / gridx / font_sz.width() * 1.4) << cd;
|
||||
// qDebug() << step << range << int(wid / gridx / font_sz.width() * 1.4) << cd;
|
||||
if (!is_years) {
|
||||
roundDateTime(cd, dt_add);
|
||||
cdp = cdl = cdlp = cd;
|
||||
@@ -1322,13 +1347,13 @@ void Graphic::drawGrid() {
|
||||
cd.setTime(QTime(0, 0, 0));
|
||||
cd.setDate(QDate(roundTo(cd.date().year(), dt_add[6]) - dt_add[6], 1, 1));
|
||||
}
|
||||
//qDebug() << cd << cur_scl[0] << cur_scl[1] << cur_scl[2] << cur_scl[3] << cur_scl[4] << cur_scl[5] << cur_scl[6];
|
||||
// qDebug() << cd << cur_scl[0] << cur_scl[1] << cur_scl[2] << cur_scl[3] << cur_scl[4] << cur_scl[5] << cur_scl[6];
|
||||
struct Anchor {
|
||||
int x_start, x_end;
|
||||
QDateTime date;
|
||||
};
|
||||
QVector<Anchor> areas_ce, areas_lo;
|
||||
cnt = 1000;
|
||||
cnt = 1000;
|
||||
int area_start = gbx, area_start_lo = gbx;
|
||||
pcx = real2canvasX(cd.toMSecsSinceEpoch() / grid_numbers_x);
|
||||
while (cnt-- > 0) {
|
||||
@@ -1341,16 +1366,16 @@ void Graphic::drawGrid() {
|
||||
if (cx < gbx) continue;
|
||||
if (cdp != cdc) {
|
||||
int cxc = real2canvasX(cdc.toMSecsSinceEpoch() / grid_numbers_x);
|
||||
//qDebug() << cx << cxc << ddx << pcx;
|
||||
// qDebug() << cx << cxc << ddx << pcx;
|
||||
if ((qAbs(cxc - cx) < ddx) && (cx != cxc)) need_text = false;
|
||||
areas_ce << Anchor{area_start, qMin(cxc, right), cdp};
|
||||
area_start = areas_ce.back().x_end;
|
||||
cd = cdl = cdp = cdc;
|
||||
cx = cxc;
|
||||
cx = cxc;
|
||||
roundDateTime(cdl, dt_add_lo);
|
||||
if (cdlp != cdl) {
|
||||
areas_lo << Anchor{area_start_lo, qMin(cxc, right), cdlp};
|
||||
cdlp = cdl;
|
||||
cdlp = cdl;
|
||||
area_start_lo = areas_lo.back().x_end;
|
||||
}
|
||||
} else {
|
||||
@@ -1372,11 +1397,9 @@ void Graphic::drawGrid() {
|
||||
}
|
||||
}
|
||||
if (!is_years) {
|
||||
if (area_start < right)
|
||||
areas_ce << Anchor{area_start, right, cdc};
|
||||
if (area_start_lo < right)
|
||||
areas_lo << Anchor{area_start_lo, right, cdl};
|
||||
//qDebug() << areas_lo.size() << formats.upper << areas_lo[0].date;
|
||||
if (area_start < right) areas_ce << Anchor{area_start, right, cdc};
|
||||
if (area_start_lo < right) areas_lo << Anchor{area_start_lo, right, cdl};
|
||||
// qDebug() << areas_lo.size() << formats.upper << areas_lo[0].date;
|
||||
painter->setPen(grid_pen);
|
||||
for (const auto & a: areas_ce) {
|
||||
painter->drawLine(a.x_start, hei + 5, a.x_start, ce_y);
|
||||
@@ -1389,12 +1412,12 @@ void Graphic::drawGrid() {
|
||||
painter->setFont(nf);
|
||||
auto pfm = painter->fontMetrics();
|
||||
for (const auto & a: areas_ce) {
|
||||
ds = a.date.toString(formats.center);
|
||||
ds = a.date.toString(formats.center);
|
||||
auto str_rect = pfm.boundingRect(ds);
|
||||
painter->drawText(a.x_start + (a.x_end - a.x_start - str_rect.width()) / 2, ce_y, ds);
|
||||
}
|
||||
for (const auto & a: areas_lo) {
|
||||
ds = a.date.toString(formats.lower);
|
||||
ds = a.date.toString(formats.lower);
|
||||
auto str_rect = pfm.boundingRect(ds);
|
||||
painter->drawText(a.x_start + (a.x_end - a.x_start - str_rect.width()) / 2, lo_y, ds);
|
||||
}
|
||||
@@ -1426,7 +1449,7 @@ QPair<QString, QString> Graphic::gridMark(double v) const {
|
||||
v = 1.;
|
||||
p += 1;
|
||||
}
|
||||
ret.first = QString::fromUtf8("%1·10").arg(v);
|
||||
ret.first = QString::fromUtf8("%1·10").arg(v);
|
||||
ret.second = QString::number(p);
|
||||
} else
|
||||
ret.first = QString::number(v, 'g', 8);
|
||||
@@ -1437,31 +1460,30 @@ QPair<QString, QString> Graphic::gridMark(double v) const {
|
||||
void Graphic::fillDateFormats() {
|
||||
date_formats.clear();
|
||||
QString tr_ms = tr("ms"), tr_s = tr("s"), tr_m = tr("m"), tr_h = tr("h");
|
||||
auto trFunc = [&](const DateFormats & src)->DateFormats{
|
||||
auto trFunc = [&](const DateFormats & src) -> DateFormats {
|
||||
DateFormats ret;
|
||||
ret.upper = QString(src.upper ).replace("%1", tr_ms).replace("%2", tr_s).replace("%3", tr_m).replace("%4", tr_h);
|
||||
ret.upper = QString(src.upper).replace("%1", tr_ms).replace("%2", tr_s).replace("%3", tr_m).replace("%4", tr_h);
|
||||
ret.center = QString(src.center).replace("%1", tr_ms).replace("%2", tr_s).replace("%3", tr_m).replace("%4", tr_h);
|
||||
ret.lower = QString(src.lower ).replace("%1", tr_ms).replace("%2", tr_s).replace("%3", tr_m).replace("%4", tr_h);
|
||||
ret.lower = QString(src.lower).replace("%1", tr_ms).replace("%2", tr_s).replace("%3", tr_m).replace("%4", tr_h);
|
||||
return ret;
|
||||
};
|
||||
date_formats << trFunc(DateFormats{"zzz '%1'", "h '%4' mm '%3' ss '%2'", "yyyy MMM dd(ddd)"});
|
||||
date_formats << trFunc(DateFormats{"ss '%2'" , "h '%4' mm '%3'" , "yyyy MMM dd(ddd)"});
|
||||
date_formats << trFunc(DateFormats{"mm '%3'" , "h '%4'" , "yyyy MMM dd(ddd)"});
|
||||
date_formats << trFunc(DateFormats{"h '%4'" , "dd(ddd)" , "yyyy MMM" });
|
||||
date_formats << trFunc(DateFormats{"dd(ddd)" , "MMM" , "yyyy" });
|
||||
date_formats << trFunc(DateFormats{"MMM" , "yyyy" , "" });
|
||||
date_formats << trFunc(DateFormats{"yyyy" , "" , "" });
|
||||
date_formats << trFunc(DateFormats{"ss '%2'", "h '%4' mm '%3'", "yyyy MMM dd(ddd)"});
|
||||
date_formats << trFunc(DateFormats{"mm '%3'", "h '%4'", "yyyy MMM dd(ddd)"});
|
||||
date_formats << trFunc(DateFormats{"h '%4'", "dd(ddd)", "yyyy MMM"});
|
||||
date_formats << trFunc(DateFormats{"dd(ddd)", "MMM", "yyyy"});
|
||||
date_formats << trFunc(DateFormats{"MMM", "yyyy", ""});
|
||||
date_formats << trFunc(DateFormats{"yyyy", "", ""});
|
||||
}
|
||||
|
||||
|
||||
void Graphic::drawGraphics() {
|
||||
if (isHover)
|
||||
ui->status->setText(tr("Cursor: ") + pointCoords(canvas2real(QPointF(curpos))));
|
||||
if (isHover) ui->status->setText(tr("Cursor: ") + pointCoords(canvas2real(QPointF(curpos))));
|
||||
QPointF srp = -selrect.topLeft();
|
||||
double sclx, scly, wid = canvas->width(), hei = canvas->height();
|
||||
int cwid = (wid - gridborder.x() - margins_.left() - margins_.width());
|
||||
sclx = cwid / selrect.width();
|
||||
scly = (hei - gridborder.y() - margins_.top() - margins_.height()) / selrect.height();
|
||||
sclx = cwid / selrect.width();
|
||||
scly = (hei - gridborder.y() - margins_.top() - margins_.height()) / selrect.height();
|
||||
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());
|
||||
@@ -1478,23 +1500,23 @@ void Graphic::drawGraphics() {
|
||||
QVector<QPolygonF> & src_lod(pause_ ? t._lod_pause : t._lod);
|
||||
int lod = 0;
|
||||
if (m_LODOptimization) {
|
||||
int gpcnt = src_pol.size();
|
||||
int gpcnt = src_pol.size();
|
||||
qreal range = src_pol.back().x() - src_pol.front().x();
|
||||
qreal ppp = (gpcnt * selrect.width() / qMax(range, 1.E-9) / cwid);
|
||||
lod = qBound<int>(0, qFloor(log2(ppp) - 1), src_lod.size());
|
||||
//qDebug() << "draw lod" << lod << src_lod[lod - 1].size();
|
||||
qreal ppp = (gpcnt * selrect.width() / qMax(range, 1.E-9) / cwid);
|
||||
lod = qBound<int>(0, qFloor(log2(ppp) - 1), src_lod.size());
|
||||
// qDebug() << "draw lod" << lod << src_lod[lod - 1].size();
|
||||
}
|
||||
t.last_lod = lod;
|
||||
QPolygonF & rpol(lod == 0 ? src_pol : src_lod[lod - 1]);
|
||||
int ind_start = -1, ind_end = -1;
|
||||
if (m_LODOptimization) {
|
||||
qreal xs = selrect.left(), xe = selrect.right(), _offset = 2. / cwid * selrect.width();
|
||||
xs -= _offset; xe += _offset;
|
||||
xs -= _offset;
|
||||
xe += _offset;
|
||||
for (int i = 0; i < rpol.size(); ++i) {
|
||||
qreal px = rpol[i].x();
|
||||
if (px < xs) continue;
|
||||
if (ind_start < 0)
|
||||
ind_start = qMax(0, i - 1);
|
||||
if (ind_start < 0) ind_start = qMax(0, i - 1);
|
||||
if (px > xe && ind_end < 0) {
|
||||
ind_end = qMin(rpol.size(), i + 1);
|
||||
break;
|
||||
@@ -1502,10 +1524,10 @@ void Graphic::drawGraphics() {
|
||||
}
|
||||
if (ind_start < 0) ind_start = 0;
|
||||
if (ind_end < 0) ind_end = rpol.size();
|
||||
//qDebug() << "bound" << ind_start << ind_end << rpol.size();
|
||||
// qDebug() << "bound" << ind_start << ind_end << rpol.size();
|
||||
} else {
|
||||
ind_start = 0;
|
||||
ind_end = rpol.size();
|
||||
ind_end = rpol.size();
|
||||
}
|
||||
int polsize = ind_end - ind_start;
|
||||
if (polsize > 0) {
|
||||
@@ -1513,13 +1535,15 @@ void Graphic::drawGraphics() {
|
||||
if (m_LODOptimization && polsize < rpol.size()) {
|
||||
cpol.resize(polsize);
|
||||
memcpy(cpol.data(), &(rpol[ind_start]), polsize * sizeof(QPointF));
|
||||
//qDebug() << "copy" << polsize;
|
||||
// qDebug() << "copy" << polsize;
|
||||
} else {
|
||||
cpol = rpol;
|
||||
}
|
||||
pen = t.pen;
|
||||
if (qRound(pen.widthF()) == pen.widthF()) pen.setWidth(pen.width()*thick);
|
||||
else pen.setWidthF(pen.widthF()*thick);
|
||||
if (qRound(pen.widthF()) == pen.widthF())
|
||||
pen.setWidth(pen.width() * thick);
|
||||
else
|
||||
pen.setWidthF(pen.widthF() * thick);
|
||||
pen.setCosmetic(true);
|
||||
if (t.lines) {
|
||||
painter->setPen(pen);
|
||||
@@ -1530,8 +1554,10 @@ void Graphic::drawGraphics() {
|
||||
painter->drawPolyline(mat.map(cpol));
|
||||
}
|
||||
if (t.points) {
|
||||
if (qRound(t.pointWidth) == t.pointWidth) pen.setWidth(qRound(t.pointWidth*thick));
|
||||
else pen.setWidthF(t.pointWidth*thick);
|
||||
if (qRound(t.pointWidth) == t.pointWidth)
|
||||
pen.setWidth(qRound(t.pointWidth * thick));
|
||||
else
|
||||
pen.setWidthF(t.pointWidth * thick);
|
||||
painter->setPen(pen);
|
||||
painter->drawPoints(mat.map(cpol));
|
||||
}
|
||||
@@ -1549,9 +1575,9 @@ QString Graphic::pointCoords(QPointF point, bool x, bool y) {
|
||||
else
|
||||
ret +=
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
QDateTime::fromMSecsSinceEpoch(point.x()).toString(Qt::SystemLocaleShortDate);
|
||||
QDateTime::fromMSecsSinceEpoch(point.x()).toString(Qt::SystemLocaleShortDate);
|
||||
#else
|
||||
locale().toString(QDateTime::fromMSecsSinceEpoch(point.x()), QLocale::ShortFormat);
|
||||
locale().toString(QDateTime::fromMSecsSinceEpoch(point.x()), QLocale::ShortFormat);
|
||||
#endif
|
||||
}
|
||||
if (y) {
|
||||
@@ -1575,11 +1601,11 @@ void Graphic::drawGuides() {
|
||||
painter->resetTransform();
|
||||
painter->setClipping(true);
|
||||
painter->setClipRect(QRect(gridborder.x(), 0, wid - gridborder.x(), hei - gridborder.y()));
|
||||
QPoint apos = curpos;
|
||||
QPoint apos = curpos;
|
||||
QPointF rpos = canvas2real(apos);
|
||||
QString str;
|
||||
str = pointCoords(rpos) + fp_size;
|
||||
bool trace_found = false;
|
||||
str = pointCoords(rpos) + fp_size;
|
||||
bool trace_found = false;
|
||||
auto trace_axis_func = [&](bool on_x, double cursor) {
|
||||
if (curTrace >= 0 && curTrace < graphics.size()) {
|
||||
auto & t(graphics[curTrace]);
|
||||
@@ -1594,13 +1620,13 @@ void Graphic::drawGuides() {
|
||||
dist = qAbs<double>((on_x ? pol[i].x() : pol[i].y()) - cursor);
|
||||
if (min_dist > dist || min_dist < 0) {
|
||||
min_dist = dist;
|
||||
index = i;
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
if (index >= 0) {
|
||||
rpos = pol[index];
|
||||
apos = real2canvas(rpos).toPoint();
|
||||
str = pointCoords(pol[index]) + fp_size;
|
||||
rpos = pol[index];
|
||||
apos = real2canvas(rpos).toPoint();
|
||||
str = pointCoords(pol[index]) + fp_size;
|
||||
trace_found = true;
|
||||
emit graphicTraceEvent(curTrace, rpos);
|
||||
}
|
||||
@@ -1610,7 +1636,7 @@ void Graphic::drawGuides() {
|
||||
auto trace_free_func = [&](QPointF cursor) {
|
||||
double min_dist = -1;
|
||||
int gr = -1, mag_dist = fontHeight(this) * 2;
|
||||
QPointF point, scale = getScale(), dp;
|
||||
QPointF point, scale = getScale(), dp;
|
||||
for (int g = 0; g < graphics.size(); ++g) {
|
||||
auto & t(graphics[g]);
|
||||
if (t.visible) {
|
||||
@@ -1627,34 +1653,27 @@ void Graphic::drawGuides() {
|
||||
dist = QVector2D(dp).lengthSquared();
|
||||
if (min_dist > dist || min_dist < 0) {
|
||||
min_dist = dist;
|
||||
gr = g;
|
||||
rpos = point;
|
||||
gr = g;
|
||||
rpos = point;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (gr >= 0) {
|
||||
apos = real2canvas(rpos).toPoint();
|
||||
str = " " + graphics[gr].name + ": " + pointCoords(rpos) + fp_size;
|
||||
apos = real2canvas(rpos).toPoint();
|
||||
str = " " + graphics[gr].name + ": " + pointCoords(rpos) + fp_size;
|
||||
trace_found = true;
|
||||
emit graphicTraceEvent(gr, rpos);
|
||||
}
|
||||
};
|
||||
switch (floating_axis_type) {
|
||||
case TraceXY:
|
||||
trace_free_func(rpos);
|
||||
break;
|
||||
case TraceX:
|
||||
trace_axis_func(true, rpos.x());
|
||||
break;
|
||||
case TraceY:
|
||||
trace_axis_func(false, rpos.y());
|
||||
break;
|
||||
case TraceXY: trace_free_func(rpos); break;
|
||||
case TraceX: trace_axis_func(true, rpos.x()); break;
|
||||
case TraceY: trace_axis_func(false, rpos.y()); break;
|
||||
default: break;
|
||||
}
|
||||
if (was_trace && !trace_found)
|
||||
emit graphicTraceEvent(-1, QPointF());
|
||||
if (was_trace && !trace_found) emit graphicTraceEvent(-1, QPointF());
|
||||
was_trace = trace_found;
|
||||
painter->drawLine(0, apos.y(), wid, apos.y());
|
||||
painter->drawLine(apos.x(), 0, apos.x(), hei);
|
||||
@@ -1678,7 +1697,7 @@ void Graphic::drawPause() {
|
||||
painter->resetTransform();
|
||||
painter->translate(canvas->width() - icon_pause_b.width() - 6, 6);
|
||||
double o = (0.5 - pause_phase) * 2;
|
||||
painter->setOpacity(o*o);
|
||||
painter->setOpacity(o * o);
|
||||
painter->drawImage(0, 0, icon_pause_b);
|
||||
painter->setOpacity(1.);
|
||||
painter->drawImage(0, 0, icon_pause_f);
|
||||
@@ -1689,11 +1708,11 @@ void Graphic::drawPause() {
|
||||
double roundToSteps(double value, const QVector<double> & steps) {
|
||||
double ret = value, min_err = -1.;
|
||||
for (double v: steps) {
|
||||
double sv = qRound64(value / v) * v;
|
||||
double sv = qRound64(value / v) * v;
|
||||
double err = qAbs<double>(value - sv);
|
||||
if (min_err < 0 || min_err > err) {
|
||||
min_err = err;
|
||||
ret = sv;
|
||||
ret = sv;
|
||||
}
|
||||
}
|
||||
if (ret < steps[0]) ret = steps[0];
|
||||
@@ -1706,7 +1725,7 @@ double roundToNearest(double value, const QVector<double> & values) {
|
||||
double err = qAbs<double>(value - v);
|
||||
if (min_err < 0 || min_err > err) {
|
||||
min_err = err;
|
||||
ret = v;
|
||||
ret = v;
|
||||
}
|
||||
}
|
||||
if (ret < values[0]) ret = values[0];
|
||||
@@ -1717,13 +1736,13 @@ double roundToNearest(double value, const QVector<double> & values) {
|
||||
double Graphic::splitRange(double range, int count) {
|
||||
double digits, step, tln;
|
||||
range = qAbs<double>(range);
|
||||
tln = qFloor(qLn(range) / LN10);
|
||||
tln = qFloor(qLn(range) / LN10);
|
||||
for (int i = 0; i <= 5; ++i) {
|
||||
digits = qPow(10., tln - i);
|
||||
step = qRound(range / count / digits);
|
||||
step = qRound(range / count / digits);
|
||||
if (step > 0.) {
|
||||
digits = qPow(10., tln - i - 1);
|
||||
step = qRound(range / count / digits);
|
||||
step = qRound(range / count / digits);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1733,22 +1752,32 @@ double Graphic::splitRange(double range, int count) {
|
||||
|
||||
|
||||
double Graphic::splitRangeDate(double range, int count, DateFormats & formats, int step[7]) {
|
||||
static const qint64
|
||||
to_sec = 1000LL,
|
||||
to_min = 1000LL * 60,
|
||||
to_hour = 1000LL * 60 * 60,
|
||||
to_day = 1000LL * 60 * 60 * 24,
|
||||
to_month = 1000LL * 60 * 60 * 24 * 30,
|
||||
to_year = 1000LL * 60 * 60 * 24 * 30 * 12;
|
||||
double ret = splitRange(range, count);
|
||||
static const qint64 to_sec = 1000LL, to_min = 1000LL * 60, to_hour = 1000LL * 60 * 60, to_day = 1000LL * 60 * 60 * 24,
|
||||
to_month = 1000LL * 60 * 60 * 24 * 30, to_year = 1000LL * 60 * 60 * 24 * 30 * 12;
|
||||
double ret = splitRange(range, count);
|
||||
int format_index = DateYears;
|
||||
if (ret < to_sec / 1 ) {format_index = DateMSecs ; step[DateMSecs ] = qRound64(ret);}
|
||||
else if (ret < to_min / 2 ) {format_index = DateSecs ; step[DateSecs ] = roundToNearest(ret / to_sec , {1, 2, 5, 10, 15, 20, 30});}
|
||||
else if (ret < to_hour ) {format_index = DateMinutes; step[DateMinutes] = roundToNearest(ret / to_min , {1, 2, 5, 10, 15, 20, 30});}
|
||||
else if (ret < to_day ) {format_index = DateHours ; step[DateHours ] = roundToNearest(ret / to_hour , {1, 2, 3, 4, 6, 8, 12});}
|
||||
else if (ret < to_month / 1.6) {format_index = DateDays ; step[DateDays ] = roundToNearest(ret / to_day , {1, 2, 5, 10});}
|
||||
else if (ret < to_year ) {format_index = DateMonths ; step[DateMonths ] = roundToNearest(ret / to_month, {1, 2, 3, 4, 6});}
|
||||
else {format_index = DateYears ; step[DateYears ] = qRound64(ret / to_year);}
|
||||
if (ret < to_sec / 1) {
|
||||
format_index = DateMSecs;
|
||||
step[DateMSecs] = qRound64(ret);
|
||||
} else if (ret < to_min / 2) {
|
||||
format_index = DateSecs;
|
||||
step[DateSecs] = roundToNearest(ret / to_sec, {1, 2, 5, 10, 15, 20, 30});
|
||||
} else if (ret < to_hour) {
|
||||
format_index = DateMinutes;
|
||||
step[DateMinutes] = roundToNearest(ret / to_min, {1, 2, 5, 10, 15, 20, 30});
|
||||
} else if (ret < to_day) {
|
||||
format_index = DateHours;
|
||||
step[DateHours] = roundToNearest(ret / to_hour, {1, 2, 3, 4, 6, 8, 12});
|
||||
} else if (ret < to_month / 1.6) {
|
||||
format_index = DateDays;
|
||||
step[DateDays] = roundToNearest(ret / to_day, {1, 2, 5, 10});
|
||||
} else if (ret < to_year) {
|
||||
format_index = DateMonths;
|
||||
step[DateMonths] = roundToNearest(ret / to_month, {1, 2, 3, 4, 6});
|
||||
} else {
|
||||
format_index = DateYears;
|
||||
step[DateYears] = qRound64(ret / to_year);
|
||||
}
|
||||
formats = date_formats[format_index];
|
||||
return ret;
|
||||
}
|
||||
@@ -1761,25 +1790,35 @@ double Graphic::roundTo(double value, double round_to) {
|
||||
|
||||
|
||||
void Graphic::roundDateTime(QDateTime & dt, int * c) {
|
||||
QDate d(dt.date()); QTime t(dt.time());
|
||||
if (c[DateMSecs ] != 0) t.setHMS(t.hour(), t.minute(), t.second());
|
||||
if (c[DateSecs ] != 0) t.setHMS(t.hour(), t.minute(), 0);
|
||||
QDate d(dt.date());
|
||||
QTime t(dt.time());
|
||||
if (c[DateMSecs] != 0) t.setHMS(t.hour(), t.minute(), t.second());
|
||||
if (c[DateSecs] != 0) t.setHMS(t.hour(), t.minute(), 0);
|
||||
if (c[DateMinutes] != 0) t.setHMS(t.hour(), 0, 0);
|
||||
if (c[DateHours ] != 0) {t.setHMS(0, 0, 0); d.setDate(d.year(), d.month(), d.day());}
|
||||
if (c[DateDays ] != 0) {t.setHMS(0, 0, 0); d.setDate(d.year(), d.month(), 1);}
|
||||
if (c[DateMonths ] != 0 || c[DateYears] != 0) {t.setHMS(0, 0, 0); d.setDate(d.year(), 1, 1);}
|
||||
if (c[DateHours] != 0) {
|
||||
t.setHMS(0, 0, 0);
|
||||
d.setDate(d.year(), d.month(), d.day());
|
||||
}
|
||||
if (c[DateDays] != 0) {
|
||||
t.setHMS(0, 0, 0);
|
||||
d.setDate(d.year(), d.month(), 1);
|
||||
}
|
||||
if (c[DateMonths] != 0 || c[DateYears] != 0) {
|
||||
t.setHMS(0, 0, 0);
|
||||
d.setDate(d.year(), 1, 1);
|
||||
}
|
||||
dt = QDateTime(d, t);
|
||||
}
|
||||
|
||||
|
||||
void Graphic::addDateTime(QDateTime & dt, int * c, qint64 mul) {
|
||||
if (c[DateMSecs ] != 0) dt = dt.addMSecs (mul * c[DateMSecs ]);
|
||||
if (c[DateSecs ] != 0) dt = dt.addSecs (mul * c[DateSecs ]);
|
||||
if (c[DateMinutes] != 0) dt = dt.addSecs (mul * c[DateMinutes] * 60);
|
||||
if (c[DateHours ] != 0) dt = dt.addSecs (mul * c[DateHours ] * 60 * 60);
|
||||
if (c[DateDays ] != 0) dt = dt.addDays (mul * c[DateDays ]);
|
||||
if (c[DateMonths ] != 0) dt = dt.addMonths(mul * c[DateMonths ]);
|
||||
if (c[DateYears ] != 0) dt = dt.addYears (mul * c[DateYears ]);
|
||||
if (c[DateMSecs] != 0) dt = dt.addMSecs(mul * c[DateMSecs]);
|
||||
if (c[DateSecs] != 0) dt = dt.addSecs(mul * c[DateSecs]);
|
||||
if (c[DateMinutes] != 0) dt = dt.addSecs(mul * c[DateMinutes] * 60);
|
||||
if (c[DateHours] != 0) dt = dt.addSecs(mul * c[DateHours] * 60 * 60);
|
||||
if (c[DateDays] != 0) dt = dt.addDays(mul * c[DateDays]);
|
||||
if (c[DateMonths] != 0) dt = dt.addMonths(mul * c[DateMonths]);
|
||||
if (c[DateYears] != 0) dt = dt.addYears(mul * c[DateYears]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1813,7 +1852,7 @@ double Graphic::real2canvasY(double py) const {
|
||||
|
||||
QPolygonF Graphic::real2canvas(const QPolygonF & real_polygon) const {
|
||||
QPolygonF ret;
|
||||
for (int i=0; i<real_polygon.size(); ++i)
|
||||
for (int i = 0; i < real_polygon.size(); ++i)
|
||||
ret << real2canvas(real_polygon[i]);
|
||||
return ret;
|
||||
}
|
||||
@@ -1821,7 +1860,7 @@ QPolygonF Graphic::real2canvas(const QPolygonF & real_polygon) const {
|
||||
|
||||
QPolygonF Graphic::canvas2real(const QPolygonF & canvas_polygon) const {
|
||||
QPolygonF ret;
|
||||
for (int i=0; i<canvas_polygon.size(); ++i)
|
||||
for (int i = 0; i < canvas_polygon.size(); ++i)
|
||||
ret << canvas2real(canvas_polygon[i]);
|
||||
return ret;
|
||||
}
|
||||
@@ -1830,21 +1869,11 @@ QPolygonF Graphic::canvas2real(const QPolygonF & canvas_polygon) const {
|
||||
void Graphic::setCurrentAction(GraphicAction action) {
|
||||
curaction = action;
|
||||
switch (action) {
|
||||
case gaNone:
|
||||
setGuidesCursor();
|
||||
break;
|
||||
case gaZoomInRect:
|
||||
setCanvasCursor(Qt::CrossCursor);
|
||||
break;
|
||||
case gaZoomRangeX:
|
||||
setCanvasCursor(Qt::SplitHCursor);
|
||||
break;
|
||||
case gaZoomRangeY:
|
||||
setCanvasCursor(Qt::SplitVCursor);
|
||||
break;
|
||||
case gaMove:
|
||||
setCanvasCursor(Qt::SizeAllCursor);
|
||||
break;
|
||||
case gaNone: setGuidesCursor(); break;
|
||||
case gaZoomInRect: setCanvasCursor(Qt::CrossCursor); break;
|
||||
case gaZoomRangeX: setCanvasCursor(Qt::SplitHCursor); break;
|
||||
case gaZoomRangeY: setCanvasCursor(Qt::SplitVCursor); break;
|
||||
case gaMove: setCanvasCursor(Qt::SizeAllCursor); break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1852,8 +1881,7 @@ void Graphic::setCurrentAction(GraphicAction action) {
|
||||
void Graphic::setCanvasCursor(QCursor cursor) {
|
||||
ui->canvas_raster->setCursor(cursor);
|
||||
#ifdef HAS_GL
|
||||
if (canvas_gl)
|
||||
canvas_gl->setCursor(cursor);
|
||||
if (canvas_gl) canvas_gl->setCursor(cursor);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1883,28 +1911,42 @@ void Graphic::swapToBuffer() {
|
||||
void Graphic::setRectToLines() {
|
||||
is_lines_update = true;
|
||||
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);
|
||||
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()) {
|
||||
if (isFit) line_x_min.setValue(grect.left());
|
||||
else line_x_min.setValue(selrect.left());
|
||||
if (isFit)
|
||||
line_x_min.setValue(grect.left());
|
||||
else
|
||||
line_x_min.setValue(selrect.left());
|
||||
}
|
||||
if (!line_x_max.hasFocus()) {
|
||||
if(isFit) line_x_max.setValue(grect.right());
|
||||
else line_x_max.setValue(selrect.right());
|
||||
if (isFit)
|
||||
line_x_max.setValue(grect.right());
|
||||
else
|
||||
line_x_max.setValue(selrect.right());
|
||||
}
|
||||
if (!line_y_min.hasFocus()) {
|
||||
if(isFit) line_y_min.setValue(grect.bottom());
|
||||
else line_y_min.setValue(selrect.bottom());
|
||||
if (isFit)
|
||||
line_y_min.setValue(grect.bottom());
|
||||
else
|
||||
line_y_min.setValue(selrect.bottom());
|
||||
}
|
||||
if (!line_y_max.hasFocus()) {
|
||||
if(isFit) line_y_max.setValue(grect.top());
|
||||
else line_y_max.setValue(selrect.top());
|
||||
if (isFit)
|
||||
line_y_max.setValue(grect.top());
|
||||
else
|
||||
line_y_max.setValue(selrect.top());
|
||||
}
|
||||
line_x_min.setDefaultText(QString::number(grect.left()).toUpper());
|
||||
line_x_max.setDefaultText(QString::number(grect.right()).toUpper());
|
||||
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);
|
||||
line_x_min.blockSignals(false);
|
||||
line_x_max.blockSignals(false);
|
||||
line_y_min.blockSignals(false);
|
||||
line_y_max.blockSignals(false);
|
||||
}
|
||||
is_lines_update = false;
|
||||
}
|
||||
@@ -1925,10 +1967,8 @@ void Graphic::tick(int index, bool slide, bool update_) {
|
||||
/// TODO: [Graphic] fast autofit while addPoint(double y, ...)
|
||||
if (!t.cvrect.isNull()) {
|
||||
QPointF fp(t.polyline.first());
|
||||
if (qFuzzyCompare(t.cvrect.left(), fp.x()) ||
|
||||
qFuzzyCompare(t.cvrect.right(), fp.x()) ||
|
||||
qFuzzyCompare(t.cvrect.top(), fp.y()) ||
|
||||
qFuzzyCompare(t.cvrect.bottom(), fp.y())) {
|
||||
if (qFuzzyCompare(t.cvrect.left(), fp.x()) || qFuzzyCompare(t.cvrect.right(), fp.x()) ||
|
||||
qFuzzyCompare(t.cvrect.top(), fp.y()) || qFuzzyCompare(t.cvrect.bottom(), fp.y())) {
|
||||
t.cvrect = QRectF();
|
||||
}
|
||||
}
|
||||
@@ -1955,48 +1995,51 @@ void Graphic::calcLOD(int index) {
|
||||
GraphicType & t(graphics[index]);
|
||||
t._lod.clear();
|
||||
int pcnt = t.polyline.size();
|
||||
//qDebug() << "calcLOD" << index;
|
||||
// qDebug() << "calcLOD" << index;
|
||||
while (pcnt >= 10) {
|
||||
QPolygonF & pl(t._lod.isEmpty() ? t.polyline : t._lod.back());
|
||||
t._lod.append(QPolygonF());
|
||||
QPolygonF & cl(t._lod.back());
|
||||
cl << pl.front();
|
||||
int qcnt = (pl.size() + 1) / 4;
|
||||
pcnt = qcnt * 2 + 2;
|
||||
int pc = 4;
|
||||
int qcnt = (pl.size() + 1) / 4;
|
||||
pcnt = qcnt * 2 + 2;
|
||||
int pc = 4;
|
||||
qreal mx[2] = {0., 0.}, my[2] = {0., 0.}, my_x[2] = {0., 0.}, px, py;
|
||||
for (int i = 0; i < qcnt; ++i) {
|
||||
int j = i*4 + 1;
|
||||
int j = i * 4 + 1;
|
||||
if (i == qcnt - 1) pc = pl.size() - j - 1;
|
||||
mx[0] = mx[1] = my_x[0] = my_x[1] = pl[j].x(); my[0] = my[1] = pl[j].y();
|
||||
mx[0] = mx[1] = my_x[0] = my_x[1] = pl[j].x();
|
||||
my[0] = my[1] = pl[j].y();
|
||||
for (int k = 1; k < pc; ++k) {
|
||||
px = pl[j + k].x(); py = pl[j + k].y();
|
||||
mx[0] = qMin(mx[0], px); mx[1] = qMax(mx[1], px);
|
||||
px = pl[j + k].x();
|
||||
py = pl[j + k].y();
|
||||
mx[0] = qMin(mx[0], px);
|
||||
mx[1] = qMax(mx[1], px);
|
||||
if (my[0] > py) {
|
||||
my[0] = py;
|
||||
my[0] = py;
|
||||
my_x[0] = px;
|
||||
}
|
||||
if (my[1] < py) {
|
||||
my[1] = py;
|
||||
my[1] = py;
|
||||
my_x[1] = px;
|
||||
}
|
||||
}
|
||||
qreal dx =(mx[1] - mx[0]) / 4., cx = (mx[1] + mx[0]) / 2.;
|
||||
qreal dx = (mx[1] - mx[0]) / 4., cx = (mx[1] + mx[0]) / 2.;
|
||||
if (my_x[1] >= my_x[0])
|
||||
cl << QPointF(cx - dx, my[0]) << QPointF(cx + dx, my[1]);
|
||||
else
|
||||
cl << QPointF(cx - dx, my[1]) << QPointF(cx + dx, my[0]);
|
||||
}
|
||||
cl << pl.back();
|
||||
//qDebug() << "lod" << t._lod.size() << "->" << cl.size();
|
||||
// qDebug() << "lod" << t._lod.size() << "->" << cl.size();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Graphic::on_graphic_buttonAutofit_clicked() {
|
||||
isFit = true;
|
||||
isFit = true;
|
||||
bool isEmpty = true;
|
||||
foreach (const GraphicType & t, graphics) {
|
||||
foreach(const GraphicType & t, graphics) {
|
||||
const QPolygonF & pol(pause_ ? t.polyline_pause : t.polyline);
|
||||
if (!pol.isEmpty()) {
|
||||
isEmpty = false;
|
||||
@@ -2046,23 +2089,29 @@ void Graphic::on_graphic_buttonConfigure_clicked() {
|
||||
grid_pen = QPen(conf->ui->colorGrid->color(), conf->ui->spinWidthGrid->value(), (Qt::PenStyle)conf->ui->comboStyleGrid->currentIndex());
|
||||
back_color = conf->ui->colorBackground->color();
|
||||
text_color = conf->ui->colorText->color();
|
||||
grad_x = conf->ui->checkGridAutoX->isChecked() ? Auto : Fixed;
|
||||
grad_y = conf->ui->checkGridAutoY->isChecked() ? Auto : Fixed;
|
||||
gridx = conf->ui->spinGridStepX->value();
|
||||
gridy = conf->ui->spinGridStepY->value();
|
||||
grad_x = conf->ui->checkGridAutoX->isChecked() ? Auto : Fixed;
|
||||
grad_y = conf->ui->checkGridAutoY->isChecked() ? Auto : Fixed;
|
||||
gridx = conf->ui->spinGridStepX->value();
|
||||
gridy = conf->ui->spinGridStepY->value();
|
||||
setOpenGL(conf->ui->checkOGL->isChecked());
|
||||
setAntialiasing(conf->ui->checkAAlias->isChecked());
|
||||
setBorderInputsVisible(conf->ui->checkInputs->isChecked());
|
||||
setStatusVisible(conf->ui->checkStatus->isChecked());
|
||||
setLegendVisible(conf->ui->checkLegend->isChecked());
|
||||
setMargins(conf->ui->spinMarginL->value(), conf->ui->spinMarginR->value(), conf->ui->spinMarginT->value(), conf->ui->spinMarginB->value());
|
||||
setMargins(conf->ui->spinMarginL->value(),
|
||||
conf->ui->spinMarginR->value(),
|
||||
conf->ui->spinMarginT->value(),
|
||||
conf->ui->spinMarginB->value());
|
||||
updateLegend();
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
void Graphic::on_graphic_buttonSave_clicked() {
|
||||
QString f = QFileDialog::getSaveFileName(this, tr("Save Image"), ppath, "PNG(*.png);;JPEG(*.jpg *.jpeg);;BMP(*.bmp);;TIFF(*.tiff *.tif);;PPM(*.ppm)");
|
||||
QString f = QFileDialog::getSaveFileName(this,
|
||||
tr("Save Image"),
|
||||
ppath,
|
||||
"PNG(*.png);;JPEG(*.jpg *.jpeg);;BMP(*.bmp);;TIFF(*.tiff *.tif);;PPM(*.ppm)");
|
||||
if (f.isEmpty()) return;
|
||||
saveImage(f);
|
||||
}
|
||||
@@ -2072,7 +2121,8 @@ void Graphic::on_graphic_buttonExport_clicked() {
|
||||
QString f = QFileDialog::getSaveFileName(this, tr("Export graphics"), ppath, "CSV(*.csv)");
|
||||
if (f.isEmpty()) return;
|
||||
QStringList items;
|
||||
items << "." << ",";
|
||||
items << "."
|
||||
<< ",";
|
||||
bool ok;
|
||||
QString item = QInputDialog::getItem(this, tr("Select decimal point"), tr("Decimal point:"), items, 0, false, &ok);
|
||||
if (ok && !item.isEmpty()) exportGraphics(f, item.front());
|
||||
@@ -2092,15 +2142,17 @@ void Graphic::on_graphic_buttonRecord_clicked(bool checked) {
|
||||
qApp->setOverrideCursor(Qt::BusyCursor);
|
||||
GifWriter gif_writer;
|
||||
int frame_delay = 10;
|
||||
if (GifBegin(&gif_writer, f.toUtf8(), static_cast<uint32_t>(record_imgs.first().width()),
|
||||
static_cast<uint32_t>(record_imgs.first().height()),
|
||||
static_cast<uint32_t>(frame_delay))) {
|
||||
for (const QImage & im : record_imgs) {
|
||||
if (GifBegin(&gif_writer,
|
||||
f.toUtf8(),
|
||||
static_cast<uint32_t>(record_imgs.first().width()),
|
||||
static_cast<uint32_t>(record_imgs.first().height()),
|
||||
static_cast<uint32_t>(frame_delay))) {
|
||||
for (const QImage & im: record_imgs) {
|
||||
if (!GifWriteFrame(&gif_writer,
|
||||
im.convertToFormat(QImage::Format_RGBA8888).constBits(),
|
||||
static_cast<uint32_t>(im.width()),
|
||||
static_cast<uint32_t>(im.height()),
|
||||
static_cast<uint32_t>(frame_delay))) {
|
||||
im.convertToFormat(QImage::Format_RGBA8888).constBits(),
|
||||
static_cast<uint32_t>(im.width()),
|
||||
static_cast<uint32_t>(im.height()),
|
||||
static_cast<uint32_t>(frame_delay))) {
|
||||
GifEnd(&gif_writer);
|
||||
qDebug() << "GifWriteFrame ERROR";
|
||||
}
|
||||
@@ -2127,8 +2179,10 @@ void Graphic::updateLegend(bool es) {
|
||||
pix.fill(back_color);
|
||||
QPainter p(&pix);
|
||||
QPen pen = graphics[i].pen;
|
||||
if (qRound(pen.widthF()) == pen.widthF()) pen.setWidth(pen.width()*thick);
|
||||
else pen.setWidthF(pen.widthF()*thick);
|
||||
if (qRound(pen.widthF()) == pen.widthF())
|
||||
pen.setWidth(pen.width() * thick);
|
||||
else
|
||||
pen.setWidthF(pen.widthF() * thick);
|
||||
p.setPen(pen);
|
||||
p.drawLine(0, pix.height() / 2, pix.width(), pix.height() / 2);
|
||||
p.end();
|
||||
@@ -2139,7 +2193,7 @@ void Graphic::updateLegend(bool es) {
|
||||
return;
|
||||
}
|
||||
leg_update = false;
|
||||
int ps = 100;
|
||||
int ps = 100;
|
||||
for (int r = 0; r < ui->layoutLegend->rowCount(); ++r)
|
||||
for (int c = 0; c < ui->layoutLegend->columnCount(); ++c) {
|
||||
QLayoutItem * li = ui->layoutLegend->itemAtPosition(r, c);
|
||||
@@ -2167,33 +2221,36 @@ void Graphic::updateLegend(bool es) {
|
||||
if (cps > ps) ps = cps;
|
||||
}
|
||||
LegendScrollArea * leg_sa = (LegendScrollArea *)ui->scrollLegend->layout()->itemAt(0)->widget();
|
||||
int maxcol = qMax<int>(leg_sa->width() / ps - 1, 1);
|
||||
int maxcol = qMax<int>(leg_sa->width() / ps - 1, 1);
|
||||
int row = 0, col = 0;
|
||||
bool lv = ui->scrollLegend->isVisibleTo(this);
|
||||
ui->scrollLegend->hide();
|
||||
for (int i = 0; i < graphics.size(); i++) {
|
||||
ui->layoutLegend->addWidget(graphics[i].pb,row,col);
|
||||
ui->layoutLegend->addWidget(graphics[i].pb, row, col);
|
||||
QCheckBox * check = graphics[i].pb;
|
||||
check->show();
|
||||
if (leg_sa->minimum_hei == 0) {
|
||||
leg_sa->minimum_hei = ui->widgetLegend->sizeHint().height();
|
||||
/*#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
|
||||
QTimer::singleShot(0, this, [this,leg_sa,check](){
|
||||
leg_sa->minimum_hei = check->sizeHint().height();
|
||||
leg_sa->updateGeometry();
|
||||
qDebug() << leg_sa->minimum_hei << ui->widgetLegend->sizeHint();
|
||||
});
|
||||
#else
|
||||
leg_sa->minimum_hei = check->sizeHint().height();
|
||||
#endif*/
|
||||
/*#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
|
||||
QTimer::singleShot(0, this, [this,leg_sa,check](){
|
||||
leg_sa->minimum_hei = check->sizeHint().height();
|
||||
leg_sa->updateGeometry();
|
||||
qDebug() << leg_sa->minimum_hei << ui->widgetLegend->sizeHint();
|
||||
});
|
||||
#else
|
||||
leg_sa->minimum_hei = check->sizeHint().height();
|
||||
#endif*/
|
||||
}
|
||||
col++;
|
||||
if (col > maxcol) {col = 0; row++;}
|
||||
if (col > maxcol) {
|
||||
col = 0;
|
||||
row++;
|
||||
}
|
||||
}
|
||||
ui->gridLayout->invalidate();
|
||||
ui->scrollLegend->setVisible(lv);
|
||||
leg_sa->updateGeometry();
|
||||
//ui->gridLayout->invalidate();
|
||||
// ui->gridLayout->invalidate();
|
||||
leg_update = true;
|
||||
if (es) emit graphicSettingsChanged();
|
||||
}
|
||||
@@ -2212,24 +2269,30 @@ void Graphic::updateLegendChecks() {
|
||||
|
||||
void Graphic::graphicVisibleChange(bool checked) {
|
||||
if (visible_update) return;
|
||||
QCheckBox * cb = qobject_cast<QCheckBox*>(sender());
|
||||
int i = cb->property("graphic_num").toInt();
|
||||
QCheckBox * cb = qobject_cast<QCheckBox *>(sender());
|
||||
int i = cb->property("graphic_num").toInt();
|
||||
graphics[i].visible = checked;
|
||||
if (isFit) on_graphic_buttonAutofit_clicked();
|
||||
else {update();}
|
||||
if (isFit)
|
||||
on_graphic_buttonAutofit_clicked();
|
||||
else {
|
||||
update();
|
||||
}
|
||||
emit graphicSettingsChanged();
|
||||
}
|
||||
|
||||
|
||||
void Graphic::graphicAllVisibleChange(bool checked) {
|
||||
visible_update = true;
|
||||
for (int i=0; i<graphics.size(); i++) {
|
||||
for (int i = 0; i < graphics.size(); i++) {
|
||||
graphics[i].visible = checked;
|
||||
graphics[i].pb->setChecked(checked);
|
||||
}
|
||||
visible_update = false;
|
||||
if (isFit) on_graphic_buttonAutofit_clicked();
|
||||
else {update();}
|
||||
if (isFit)
|
||||
on_graphic_buttonAutofit_clicked();
|
||||
else {
|
||||
update();
|
||||
}
|
||||
emit graphicSettingsChanged();
|
||||
}
|
||||
|
||||
@@ -2319,23 +2382,22 @@ bool Graphic::legendVisible() const {
|
||||
|
||||
|
||||
QByteArray Graphic::save() {
|
||||
// QByteArray ba;
|
||||
// QDataStream s(&ba, QIODevice::ReadWrite);
|
||||
// s << openGL() << antialiasing() << borderInputsVisible() << statusVisible() << legendVisible();
|
||||
// s << graphics;
|
||||
// return ba;
|
||||
// QByteArray ba;
|
||||
// QDataStream s(&ba, QIODevice::ReadWrite);
|
||||
// s << openGL() << antialiasing() << borderInputsVisible() << statusVisible() << legendVisible();
|
||||
// s << graphics;
|
||||
// return ba;
|
||||
|
||||
// version '2':
|
||||
// version '2':
|
||||
ChunkStream cs;
|
||||
cs.add(1, antialiasing()).add(2, openGL()).add(3, borderInputsVisible()).add(4, statusVisible()).add(5, legendVisible());
|
||||
cs.add(6, backgroundColor()).add(7, textColor()).add(8, margins());
|
||||
cs.add(9, gridPen()).add(10, graduationX()).add(11, graduationY()).add(12, graduationStepX()).add(13, graduationStepY());
|
||||
cs.add(14, graphics);
|
||||
cs.add(15, isFit).add(16, visualRect());
|
||||
if (backgroundColor() == palette().color(QPalette::Base) &&
|
||||
textColor() == palette().color(QPalette::WindowText) &&
|
||||
gridColor() == palette().color(QPalette::Disabled, QPalette::WindowText))
|
||||
cs.add(17, true);
|
||||
if (backgroundColor() == palette().color(QPalette::Base) && textColor() == palette().color(QPalette::WindowText) &&
|
||||
gridColor() == palette().color(QPalette::Disabled, QPalette::WindowText))
|
||||
cs.add(17, true);
|
||||
return cs.data().prepend('2');
|
||||
}
|
||||
|
||||
@@ -2343,8 +2405,8 @@ QByteArray Graphic::save() {
|
||||
void Graphic::load(QByteArray ba) {
|
||||
if (ba.isEmpty()) return;
|
||||
char ver = ba[0];
|
||||
switch(ver) {
|
||||
case '2': {// version '2':
|
||||
switch (ver) {
|
||||
case '2': { // version '2':
|
||||
ba.remove(0, 1);
|
||||
QRectF vrect;
|
||||
ChunkStream cs(ba);
|
||||
@@ -2356,35 +2418,47 @@ void Graphic::load(QByteArray ba) {
|
||||
case 3: setBorderInputsVisible(cs.getData<bool>()); break;
|
||||
case 4: setStatusVisible(cs.getData<bool>()); break;
|
||||
case 5: setLegendVisible(cs.getData<bool>()); break;
|
||||
case 6: if (!def_colors) setBackgroundColor(cs.getData<QColor>()); break;
|
||||
case 7: if (!def_colors) setTextColor(cs.getData<QColor>()); break;
|
||||
case 6:
|
||||
if (!def_colors) setBackgroundColor(cs.getData<QColor>());
|
||||
break;
|
||||
case 7:
|
||||
if (!def_colors) setTextColor(cs.getData<QColor>());
|
||||
break;
|
||||
case 8: setMargins(cs.getData<QRect>()); break;
|
||||
case 9: if (!def_colors) setGridPen(cs.getData<QPen>()); break;
|
||||
case 9:
|
||||
if (!def_colors) setGridPen(cs.getData<QPen>());
|
||||
break;
|
||||
case 10: setGraduationX(cs.getData<Graduation>()); break;
|
||||
case 11: setGraduationY(cs.getData<Graduation>()); break;
|
||||
case 12: setGraduationStepX(cs.getData<double>()); break;
|
||||
case 13: setGraduationStepY(cs.getData<double>()); break;
|
||||
case 14: graphics = cs.getData<QVector<GraphicType> >(); break;
|
||||
case 14: graphics = cs.getData<QVector<GraphicType>>(); break;
|
||||
case 15: isFit = cs.getData<bool>(); break;
|
||||
case 16: vrect = cs.getData<QRectF>(); break;
|
||||
case 17: if(cs.getData<bool>()) {
|
||||
setTextColor(palette().color(QPalette::WindowText));
|
||||
setGridPen(QPen(palette().color(QPalette::Disabled, QPalette::WindowText), 0., Qt::DotLine));
|
||||
setBackgroundColor(palette().color(QPalette::Base));
|
||||
def_colors = true;
|
||||
} break;
|
||||
case 17:
|
||||
if (cs.getData<bool>()) {
|
||||
setTextColor(palette().color(QPalette::WindowText));
|
||||
setGridPen(QPen(palette().color(QPalette::Disabled, QPalette::WindowText), 0., Qt::DotLine));
|
||||
setBackgroundColor(palette().color(QPalette::Base));
|
||||
def_colors = true;
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
if (!isFit) setVisualRect(vrect);
|
||||
} break;
|
||||
default: {// old version 0:
|
||||
default: { // old version 0:
|
||||
QDataStream s(ba);
|
||||
bool a;
|
||||
s >> a; setOpenGL(a);
|
||||
s >> a; setAntialiasing(a);
|
||||
s >> a; setBorderInputsVisible(a);
|
||||
s >> a; setStatusVisible(a);
|
||||
s >> a;
|
||||
setOpenGL(a);
|
||||
s >> a;
|
||||
setAntialiasing(a);
|
||||
s >> a;
|
||||
setBorderInputsVisible(a);
|
||||
s >> a;
|
||||
setStatusVisible(a);
|
||||
s >> a;
|
||||
s >> graphics;
|
||||
setLegendVisible(a);
|
||||
@@ -2403,7 +2477,8 @@ void Graphic::setCaption(const QString & str) {
|
||||
void Graphic::setGraphicVisible(bool visible, int index) {
|
||||
graphics[index].visible = visible;
|
||||
updateLegendChecks();
|
||||
if (isFit) on_graphic_buttonAutofit_clicked();
|
||||
if (isFit)
|
||||
on_graphic_buttonAutofit_clicked();
|
||||
else if (aupdate)
|
||||
update();
|
||||
}
|
||||
@@ -2431,7 +2506,7 @@ void Graphic::setLegendVisible(bool visible) {
|
||||
ui->scrollLegend->setVisible(visible);
|
||||
ui->graphic_checkLegend->setChecked(visible);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
|
||||
QTimer::singleShot(0, this, [this](){updateLegend();});
|
||||
QTimer::singleShot(0, this, [this]() { updateLegend(); });
|
||||
#else
|
||||
updateLegend();
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user