graphic openglwidget create only when realy switch to opengl

This commit is contained in:
2021-04-30 14:13:16 +03:00
parent 4880d3604f
commit c5f45b7078
2 changed files with 12 additions and 10 deletions

View File

@@ -105,12 +105,6 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
connect(&line_y_max, SIGNAL(valueChanged(double)), this, SLOT(lineYMaxChanged(double)));
connect(ui->canvas_raster, SIGNAL(paintEvent(QPaintEvent * )), this, SLOT(canvasPaintEvent()));
prepareCanvas(ui->canvas_raster);
#ifdef HAS_GL
canvas_gl = new UGLWidget();
ui->layoutCanvas->addWidget(canvas_gl);
connect(canvas_gl, SIGNAL(paintSignal()), this, SLOT(canvasPaintEvent()));
prepareCanvas(canvas_gl);
#endif
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");
@@ -870,11 +864,18 @@ void Graphic::setOpenGL(bool on) {
#ifdef HAS_GL
isOGL = on;
if (on) {
if (!canvas_gl) {
canvas_gl = new UGLWidget();
ui->layoutCanvas->addWidget(canvas_gl);
connect(canvas_gl, SIGNAL(paintSignal()), this, SLOT(canvasPaintEvent()));
prepareCanvas(canvas_gl);
}
ui->canvas_raster->hide();
canvas_gl->show();
canvas = canvas_gl;
} else {
canvas_gl->hide();
if (canvas_gl)
canvas_gl->hide();
ui->canvas_raster->show();
canvas = ui->canvas_raster;
}
@@ -1460,7 +1461,8 @@ void Graphic::setCurrentAction(GraphicAction action) {
void Graphic::setCanvasCursor(QCursor cursor) {
ui->canvas_raster->setCursor(cursor);
#ifdef HAS_GL
canvas_gl->setCursor(cursor);
if (canvas_gl)
canvas_gl->setCursor(cursor);
#endif
}
@@ -1476,7 +1478,7 @@ void Graphic::setGuidesCursor() {
void Graphic::swapToBuffer() {
QImage timg;
#ifdef HAS_GL
if (isOGL) {
if (isOGL && canvas_gl) {
timg = canvas_gl->grabFrameBuffer();
QPainter p(buffer);
p.drawImage(0, 0, timg);