Skip to content

Commit

Permalink
Fix Qt4 builds.
Browse files Browse the repository at this point in the history
Make moc happy by creating the same class from two different files.
  • Loading branch information
adeas31 committed Jan 19, 2017
1 parent 0ee4ed0 commit 289fa10
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 22 deletions.
50 changes: 50 additions & 0 deletions OMEdit/OMEditGUI/Animation/GLWidget.cpp
@@ -0,0 +1,50 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE
* OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
/*
* @author Adeel Asghar <adeel.asghar@liu.se>
*/

#include "GLWidget.h"

/*!
* \class GLWidget
* \brief Qt 4 builds use this class for ViewerWidget.\n
* QOpenGLWidget is only availble from Qt 5.4
*/
/*!
* \brief GLWidget::GLWidget
* \param parent
* \param flags
*/
GLWidget::GLWidget(QWidget* parent, Qt::WindowFlags flags)
: QGLWidget(parent, nullptr, flags)
{

}
45 changes: 45 additions & 0 deletions OMEdit/OMEditGUI/Animation/GLWidget.h
@@ -0,0 +1,45 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE
* OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
/*
* @author Adeel Asghar <adeel.asghar@liu.se>
*/

#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <QGLWidget>

class GLWidget : public QGLWidget
{
public:
GLWidget(QWidget *pParent = 0, Qt::WindowFlags flags = 0);
};

#endif // GLWIDGET_H
49 changes: 49 additions & 0 deletions OMEdit/OMEditGUI/Animation/OpenGLWidget.cpp
@@ -0,0 +1,49 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE
* OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
/*
* @author Adeel Asghar <adeel.asghar@liu.se>
*/

#include "OpenGLWidget.h"

/*!
* \class GLWidget
* \brief Qt 5.4 or greater builds use this class for ViewerWidget.\n
*/
/*!
* \brief GLWidget::GLWidget
* \param parent
* \param flags
*/
GLWidget::GLWidget(QWidget* parent, Qt::WindowFlags flags)
: QOpenGLWidget(parent, flags)
{

}
45 changes: 45 additions & 0 deletions OMEdit/OMEditGUI/Animation/OpenGLWidget.h
@@ -0,0 +1,45 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE
* OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
/*
* @author Adeel Asghar <adeel.asghar@liu.se>
*/

#ifndef OPENGLWIDGET_H
#define OPENGLWIDGET_H

#include <QOpenGLWidget>

class GLWidget : public QOpenGLWidget
{
public:
GLWidget(QWidget *pParent = 0, Qt::WindowFlags flags = 0);
};

#endif // OPENGLWIDGET_H
14 changes: 2 additions & 12 deletions OMEdit/OMEditGUI/Animation/ViewerWidget.cpp
Expand Up @@ -65,15 +65,9 @@ void Viewer::setUpThreading()
* \param parent
* \param flags
*/
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
ViewerWidget::ViewerWidget(QWidget* parent, Qt::WindowFlags flags)
: QOpenGLWidget(parent, flags)
: GLWidget(parent, flags)
{
#else
ViewerWidget::ViewerWidget(QWidget* parent, Qt::WindowFlags flags)
: QGLWidget(parent, nullptr, flags)
{
#endif
mpGraphicsWindow = new osgViewer::GraphicsWindowEmbedded(x(), y(), width(), height());
mpViewer = new Viewer;
mpSceneView = new osgViewer::View();
Expand Down Expand Up @@ -255,11 +249,7 @@ void ViewerWidget::wheelEvent(QWheelEvent *event)
*/
bool ViewerWidget::event(QEvent *event)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
bool handled = QOpenGLWidget::event(event);
#else
bool handled = QGLWidget::event(event);
#endif
bool handled = GLWidget::event(event);
// This ensures that the OSG widget is always going to be repainted after the
// user performed some interaction. Doing this in the event handler ensures
// that we don't forget about some event and prevents duplicate code.
Expand Down
16 changes: 7 additions & 9 deletions OMEdit/OMEditGUI/Animation/ViewerWidget.h
Expand Up @@ -38,11 +38,15 @@
#include <osgViewer/GraphicsWindow>
#include <osgViewer/CompositeViewer>

/*!
* \note We need to create two files with same class name since Qt meta object compiler doesn't handle ifdef.
* OpenGLWidget.h uses QOpenGLWidget and GLWidget.h uses QGLWidget
*/
#include <QtGlobal>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
#include <QOpenGLWidget>
#include "OpenGLWidget.h"
#else
#include <QGLWidget>
#include "GLWidget.h"
#endif

/*!
Expand All @@ -56,15 +60,9 @@ class Viewer : public osgViewer::CompositeViewer
virtual void setUpThreading();
};

#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
class ViewerWidget : public QOpenGLWidget
class ViewerWidget : public GLWidget
{
#else
class ViewerWidget : public QGLWidget
{
#endif
Q_OBJECT

public:
ViewerWidget(QWidget *pParent = 0, Qt::WindowFlags flags = 0);
osgViewer::View* getSceneView() {return mpSceneView;}
Expand Down
14 changes: 13 additions & 1 deletion OMEdit/OMEditGUI/OMEditGUI.pro
Expand Up @@ -250,6 +250,14 @@ HEADERS += Util/Helper.h \

CONFIG(osg) {

# CONFIG += opengl
# }

greaterThan(QT_MAJOR_VERSION, 4):greaterThan(QT_MINOR_VERSION, 3) { # if Qt 5.4 or greater
SOURCES += Animation/OpenGLWidget.cpp
} else {
SOURCES += Animation/GLWidget.cpp
}
SOURCES += Animation/AbstractAnimationWindow.cpp \
Animation/ViewerWidget.cpp \
Animation/AnimationWindow.cpp \
Expand All @@ -264,7 +272,11 @@ SOURCES += Animation/AbstractAnimationWindow.cpp \
Animation/Shapes.cpp \
Animation/TimeManager.cpp


greaterThan(QT_MAJOR_VERSION, 4):greaterThan(QT_MINOR_VERSION, 3) { # if Qt 5.4 or greater
HEADERS += Animation/OpenGLWidget.h
} else {
HEADERS += Animation/GLWidget.h
}
HEADERS += Animation/AbstractAnimationWindow.h \
Animation/ViewerWidget.h \
Animation/AnimationWindow.h \
Expand Down

0 comments on commit 289fa10

Please sign in to comment.