git-svn-id: svn://db.shs.com.ru/libs@36 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -79,6 +79,12 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), line_x_min(this), line_x_max
|
||||
connect(ui->canvas_gl, SIGNAL(wheelEvent(QWheelEvent * )), this, SLOT(canvasWheelEvent(QWheelEvent * )));
|
||||
connect(ui->canvas_gl, SIGNAL(leaveEvent(QEvent * )), this, SLOT(canvasLeaveEvent(QEvent * )));
|
||||
connect(ui->canvas_gl, SIGNAL(keyPressEvent(QKeyEvent * )), this, SLOT(canvasKeyPressEvent(QKeyEvent * )));
|
||||
ui->canvas_raster->grabGesture(Qt::PinchGesture);
|
||||
ui->canvas_raster->grabGesture(Qt::PanGesture);
|
||||
ui->canvas_raster->installEventFilter(this);
|
||||
ui->canvas_gl->grabGesture(Qt::PinchGesture);
|
||||
ui->canvas_gl->grabGesture(Qt::PanGesture);
|
||||
ui->canvas_gl->installEventFilter(this);
|
||||
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");
|
||||
@@ -93,12 +99,12 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), line_x_min(this), line_x_max
|
||||
eminx = eminy = DBL_MAX;
|
||||
emaxx = emaxy = DBL_MIN;
|
||||
grad_x = grad_y = Auto;
|
||||
axis_type_x = Numeric;
|
||||
min_repaint_int = 25;
|
||||
inc_x = 1.;
|
||||
legy = 0;
|
||||
buffer = 0;
|
||||
gridx = 70.;
|
||||
gridy = 40.;
|
||||
gridx = gridy = 1.;
|
||||
history = 5.;
|
||||
min_int = 1;
|
||||
max_int = 200;
|
||||
@@ -155,13 +161,38 @@ void Graphic::timerEvent(QTimerEvent * ) {
|
||||
}
|
||||
|
||||
|
||||
bool Graphic::eventFilter(QObject * o, QEvent * e) {
|
||||
//qDebug() << "event" << o << e;
|
||||
if (o == canvas) {
|
||||
switch (e->type()) {
|
||||
case QEvent::Gesture:
|
||||
foreach (QGesture * g, ((QGestureEvent*)e)->gestures())
|
||||
procGesture(g);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
return QFrame::eventFilter(o, e);
|
||||
}
|
||||
|
||||
|
||||
void Graphic::procGesture(QGesture * g) {
|
||||
if (!g) return;
|
||||
qDebug() << g;
|
||||
}
|
||||
|
||||
|
||||
void Graphic::canvasPaintEvent(QPaintEvent * ) {
|
||||
if (is_lines_update) return;
|
||||
QMutexLocker ml(&mutex_);
|
||||
static int pwid = 0, phei = 0;
|
||||
//static int pwid = 0, phei = 0;
|
||||
int wid = canvas->width(), hei = canvas->height();
|
||||
lastw = wid;
|
||||
lasth = hei;
|
||||
font_sz = fontMetrics().size(0, "0");
|
||||
font_sz.setHeight(font_sz.height() * 1.);
|
||||
font_sz.setWidth(font_sz.width() * 7);
|
||||
thick = qMax<int>(qRound(font_sz.height() / 15.), 1);
|
||||
if (buffer != 0) if (buffer->width() != wid || buffer->height() != hei) {delete buffer; buffer = 0;}
|
||||
if (buffer == 0) buffer = new QImage(wid, hei, QImage::Format_RGB32);
|
||||
if (bufferActive) {
|
||||
@@ -183,8 +214,8 @@ void Graphic::canvasPaintEvent(QPaintEvent * ) {
|
||||
line_x_max.setVisible(grid);
|
||||
line_y_min.setVisible(grid);
|
||||
line_y_max.setVisible(grid);*/
|
||||
pwid = wid;
|
||||
phei = hei;
|
||||
//pwid = wid;
|
||||
//phei = hei;
|
||||
QPainter p;
|
||||
if (isOGL) {
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
@@ -192,13 +223,14 @@ void Graphic::canvasPaintEvent(QPaintEvent * ) {
|
||||
} else p.begin(buffer);
|
||||
p.fillRect(canvas->rect(), back_color);
|
||||
painter = &p;
|
||||
p.setFont(font());
|
||||
gridborder = QPoint(5, 5);
|
||||
if (grid) {
|
||||
if (hasLblY) gridborder.setX(65);
|
||||
else gridborder.setX(50);
|
||||
if (hasLblX) gridborder.setY(30);
|
||||
else gridborder.setY(15);
|
||||
gridborder += QPoint(font_sz.width(), font_sz.height());
|
||||
if (hasLblY) gridborder += QPoint(font_sz.height(), 0);
|
||||
if (hasLblX) gridborder += QPoint(0, font_sz.height());
|
||||
drawGrid();
|
||||
} else gridborder = QPoint(5, 5);
|
||||
}
|
||||
p.setRenderHint(QPainter::Antialiasing, aalias);
|
||||
if (isOGL) {
|
||||
if (aalias) glEnable(GL_MULTISAMPLE);
|
||||
@@ -803,17 +835,20 @@ void Graphic::drawGrid() {
|
||||
int gbx = gridborder.x(), gby = gridborder.y(), cwid = painter->viewport().width(), chei = painter->viewport().height() - legy;
|
||||
double px, py, range, step, start;
|
||||
int wid = cwid - gbx - 5, hei = chei - gby - 5, cx, cy, cnt;
|
||||
QFontMetrics fm(font());
|
||||
QRect rect;
|
||||
QString str;
|
||||
QPair<QString, QString> str;
|
||||
|
||||
range = selrect.bottom() - selrect.top();
|
||||
if (grad_y == Graphic::Auto) step = splitRange(range, hei / gridy);
|
||||
if (grad_y == Graphic::Auto) step = splitRange(range, hei / gridy / font_sz.height() / 1.4);
|
||||
else step = gridy;//range / hei * gridy;
|
||||
start = roundTo(canvas2realY(-hei), step) - step;
|
||||
py = start + step;
|
||||
cy = 0;
|
||||
cx = gbx - 5;
|
||||
grid_pen.setWidth(qMax<int>(qRound(thick / 1.4), 1));
|
||||
QFont nf = font(), sf = font();
|
||||
sf.setPointSizeF(sf.pointSizeF() / 1.6);
|
||||
QFontMetrics fm(nf), sfm(sf);
|
||||
if (step > 0.) {
|
||||
cnt = 1000;
|
||||
while (cnt-- > 0) {
|
||||
@@ -822,14 +857,21 @@ void Graphic::drawGrid() {
|
||||
cy = real2canvasY(py);
|
||||
if (cy < 0) continue;
|
||||
if (cy > hei + 5) break;
|
||||
/*if (agrid)*/ str.setNum(py * grid_numbers_y);
|
||||
//else str.setNum(py * grid_numbers_y, 'g', 3);
|
||||
rect = fm.boundingRect(str);
|
||||
painter->setPen(grid_pen);
|
||||
painter->drawLine(gbx, cy, cwid, cy);
|
||||
cy += 3;
|
||||
str = gridMark(py * grid_numbers_y);
|
||||
painter->setPen(text_color);
|
||||
painter->drawText(cx - rect.width(), cy, str);
|
||||
cy += font_sz.height() / 4.;
|
||||
int dx = font_sz.height() / 8.;
|
||||
if (!str.second.isEmpty()) {
|
||||
rect = sfm.boundingRect(str.second);
|
||||
painter->setFont(sf);
|
||||
painter->drawText(cx - rect.width() - dx, cy - font_sz.height() / 2.5, str.second);
|
||||
dx += rect.width() + font_sz.height() / 6.;
|
||||
}
|
||||
rect = fm.boundingRect(str.first);
|
||||
painter->setFont(nf);
|
||||
painter->drawText(cx - rect.width() - dx, cy, str.first);
|
||||
}
|
||||
}
|
||||
if (hasLblY) {
|
||||
@@ -837,14 +879,14 @@ void Graphic::drawGrid() {
|
||||
painter->save();
|
||||
painter->translate(5, hei);
|
||||
painter->rotate(-90.);
|
||||
painter->drawText(0, 0, hei, 15, Qt::AlignCenter, label_y);
|
||||
painter->drawText(0, 0, hei, font_sz.height(), Qt::AlignCenter, label_y);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
cy = chei - 2;
|
||||
if (hasLblX) cy -= 15;
|
||||
cy = chei - font_sz.height() / 4;
|
||||
if (hasLblX) cy -= font_sz.height();
|
||||
range = selrect.right() - selrect.left();
|
||||
if (grad_x == Graphic::Auto) step = splitRange(range, wid / gridx);
|
||||
if (grad_x == Graphic::Auto) step = splitRange(range, wid / gridx / font_sz.width() * 1.4);
|
||||
else step = gridx;//range / wid * gridx;
|
||||
start = roundTo(canvas2realX(wid), step) + step;
|
||||
px = start + step;
|
||||
@@ -856,24 +898,55 @@ void Graphic::drawGrid() {
|
||||
cx = real2canvasX(px);
|
||||
if (cx > cwid) continue;
|
||||
if (cx < gbx) break;
|
||||
/*if (agrid)*/ str.setNum(px * grid_numbers_x);
|
||||
//else str.setNum(px * grid_numbers_x, 'g', 3);
|
||||
painter->setPen(text_color);
|
||||
painter->drawText(cx, cy, str);
|
||||
painter->setPen(grid_pen);
|
||||
painter->drawLine(cx, hei + 5, cx, 0);
|
||||
painter->setPen(text_color);
|
||||
if (axis_type_x == Graphic::Numeric) {
|
||||
int dx = -font_sz.height() / 4.;
|
||||
str = gridMark(px * grid_numbers_x);
|
||||
rect = fm.boundingRect(str.first);
|
||||
painter->setFont(nf);
|
||||
painter->drawText(cx + dx, cy, str.first);
|
||||
dx += rect.width() + font_sz.height() / 6.;
|
||||
if (!str.second.isEmpty()) {
|
||||
rect = sfm.boundingRect(str.second);
|
||||
painter->setFont(sf);
|
||||
painter->drawText(cx + dx, cy - font_sz.height() / 2.5, str.second);
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
painter->setPen(text_color);
|
||||
painter->setFont(nf);
|
||||
if (hasLblX) {
|
||||
painter->setPen(text_color);
|
||||
painter->drawText(gbx, chei - 15, wid, 15, Qt::AlignCenter, label_x);
|
||||
painter->drawText(gbx, chei - font_sz.height(), wid, font_sz.height(), Qt::AlignCenter, label_x);
|
||||
}
|
||||
|
||||
painter->setPen(QPen(grid_pen.color()));
|
||||
painter->setPen(QPen(grid_pen.color(), thick));
|
||||
painter->drawRect(gbx, -1, wid + 6, hei + 6);
|
||||
}
|
||||
|
||||
|
||||
QPair<QString, QString> Graphic::gridMark(double v) const {
|
||||
QPair<QString, QString> ret;
|
||||
if ((qAbs(v) >= 1E+4 || qAbs(v) <= 1E-4) && v != 0.) {
|
||||
int p = qFloor(qLn(qAbs(v)) / LN10);
|
||||
v /= qPow(10., p);
|
||||
if (v == 10.) {
|
||||
v = 1.;
|
||||
p += 1;
|
||||
}
|
||||
ret.first = QString::fromUtf8("%1·10").arg(v);
|
||||
ret.second = QString::number(p);
|
||||
} else
|
||||
ret.first = QString::number(v);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void Graphic::drawGraphics() {
|
||||
if (isHover)
|
||||
ui->status->setText(tr("Cursor: ") + pointCoords(canvas2real(QPointF(curpos))));
|
||||
@@ -961,7 +1034,13 @@ double Graphic::splitRange(double range, int count) {
|
||||
//bool neg = range < 0;
|
||||
//if (neg) range = -range;
|
||||
range = qAbs<double>(range);
|
||||
tln = floor(qLn(range) / LN10);
|
||||
tln = qFloor(qLn(range) / LN10);
|
||||
/*double mul = 1.;
|
||||
if (tln >= 4) {
|
||||
mul = qPow(10, tln);
|
||||
tln = 2;
|
||||
range /= mul;
|
||||
}*/
|
||||
for (int i = 0; i <= 5; ++i) {
|
||||
digits = qPow(10., tln - i);
|
||||
step = qRound(range / count / digits);
|
||||
@@ -977,7 +1056,7 @@ double Graphic::splitRange(double range, int count) {
|
||||
double err5 = qAbs<double>(step - step5), err10 = qAbs<double>(step - step10);
|
||||
step = (err5 < err10 ? step5 : step10) * digits;
|
||||
//qDebug() << step;
|
||||
return step;
|
||||
return step;// * mul;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,11 +12,15 @@
|
||||
#include <QFileDialog>
|
||||
#include <QTime>
|
||||
#include <QTranslator>
|
||||
#include <QGestureEvent>
|
||||
#include <qmath.h>
|
||||
#include <float.h>
|
||||
#include "graphic_conf.h"
|
||||
#include "clineedit.h"
|
||||
#include "qpievaluator.h"
|
||||
#if QT_VERSION >= 0x050100
|
||||
# include <QSensorGestureManager>
|
||||
#endif
|
||||
|
||||
QT_BEGIN_HEADER
|
||||
|
||||
@@ -53,8 +57,7 @@ class Graphic: public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_FLAGS(Buttons)
|
||||
Q_ENUMS(Alignment)
|
||||
Q_ENUMS(Graduation)
|
||||
Q_ENUMS(Alignment Graduation AxisType)
|
||||
|
||||
Q_PROPERTY(QString caption READ caption WRITE setCaption)
|
||||
Q_PROPERTY(QString labelX READ labelX WRITE setLabelX)
|
||||
@@ -111,6 +114,7 @@ class Graphic: public QFrame
|
||||
Q_PROPERTY(Graduation graduationY READ graduationY WRITE setGraduationY)
|
||||
Q_PROPERTY(double graduationStepX READ graduationStepX WRITE setGraduationStepX)
|
||||
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)
|
||||
@@ -142,6 +146,7 @@ public:
|
||||
};
|
||||
enum Alignment {Left, Right};
|
||||
enum Graduation {Auto, Fixed};
|
||||
enum AxisType {Numeric, DateTime};
|
||||
Q_DECLARE_FLAGS(Buttons, Button)
|
||||
|
||||
QString caption() const;
|
||||
@@ -198,6 +203,7 @@ public:
|
||||
Graduation graduationY() const {return grad_y;}
|
||||
double graduationStepX() const {return gridx;}
|
||||
double graduationStepY() const {return gridy;}
|
||||
AxisType axisType() const {return axis_type_x;}
|
||||
QVector<QPointF> graphicData(const int index = 0) const {return graphics[index].polyline;}
|
||||
GraphicsData graphicsData() const;
|
||||
QWidget * viewport() const {return canvas;}
|
||||
@@ -278,6 +284,7 @@ public slots:
|
||||
void setGraduationStepX(double sx) {gridx = sx; if (aupdate) update();}
|
||||
void setGraduationStepY(double sy) {gridy = sy; if (aupdate) update();}
|
||||
void setGraduationSteps(double sx, double sy) {gridx = sx; gridy = sy; if (aupdate) update();}
|
||||
void setAxisType(AxisType t) {axis_type_x = t; if (aupdate) update();}
|
||||
|
||||
void addPoint(const QPointF & p, int graphic, bool update_ = true);
|
||||
void addPoint(const QPointF & p, bool update = true) {addPoint(p, curGraphic, update);}
|
||||
@@ -322,7 +329,9 @@ protected:
|
||||
virtual void resizeEvent(QResizeEvent * ) {if (leg_update) updateLegend();}
|
||||
virtual QSize sizeHint() const {return QSize(400, 300);}
|
||||
virtual void timerEvent(QTimerEvent * );
|
||||
virtual bool eventFilter(QObject * o, QEvent * e);
|
||||
|
||||
void procGesture(QGesture * g);
|
||||
void setCurrentAction(GraphicAction action);
|
||||
void findGraphicsRect(double start_x = 0., double end_x = 0., double start_y = 0., double end_y = 0.);
|
||||
void tick(int index, bool slide = true, bool update = true);
|
||||
@@ -342,6 +351,7 @@ protected:
|
||||
double roundTo(double value, double round_to);
|
||||
QPointF absPoint(QPointF point) {return QPointF(qAbs(point.x()), qAbs(point.y()));}
|
||||
QString pointCoords(QPointF point) {return "(" + QString::number(point.x(), 'f', 3) + " ; " + QString::number(point.y(), 'f', 3) + ")";}
|
||||
QPair<QString, QString> gridMark(double v) const;
|
||||
|
||||
Ui::Graphic * ui;
|
||||
QMutex mutex, mutex_;
|
||||
@@ -356,6 +366,7 @@ protected:
|
||||
GraphicAction curaction, prevaction;
|
||||
QRectF grect, rrect, selrect, limit_;
|
||||
QRect margins_;
|
||||
QSize font_sz;
|
||||
QPoint startpos, curpos, prevpos, gridborder;
|
||||
QString label_x, label_y, ppath;
|
||||
Graphic::Buttons buttons_;
|
||||
@@ -366,9 +377,10 @@ protected:
|
||||
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 eminx, eminy, emaxx, emaxy, pause_phase;
|
||||
int legy, lastw, lasth, min_repaint_int, min_int, max_int, timer_pause;
|
||||
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;
|
||||
bool hasLblX, hasLblY, navigation, only_expand_y, only_expand_x, is_lines_update, leg_update, visible_update, fullscr;
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ void RendererSimple::renderScene() {
|
||||
|
||||
|
||||
//renderObjects(GLObjectBase::Solid, l, 0, true, true, view.isFogEnabled());
|
||||
//renderObjects(GLObjectBase::Transparent, l, 0, true, true, view.isFogEnabled());
|
||||
renderObjects(GLObjectBase::Transparent, l, 0, true, true, view.isFogEnabled());
|
||||
if (passes > 1) {
|
||||
glSetLightEnabled(false);
|
||||
glSetCapEnabled(GL_BLEND);
|
||||
|
||||
Reference in New Issue
Block a user