Skip to content

Commit cefed0c

Browse files
authored
Qt5 support (CMake option) for octovis (#152)
Set CMake option OCTOVIS_QT5 to true in order to use it. Contributed by K. Stepanas.
1 parent 817af60 commit cefed0c

File tree

8 files changed

+74
-14
lines changed

8 files changed

+74
-14
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ ENABLE_TESTING() # enable CTest environment of subprojects
55

66
option(BUILD_OCTOVIS_SUBPROJECT "Build targets from subproject octovis" ON)
77
option(BUILD_DYNAMICETD3D_SUBPROJECT "Build targets from subproject dynamicEDT3D" ON)
8+
option(OCTOVIS_QT5 "Link Octovis against Qt5?" NO)
9+
10+
if(OCTOVIS_QT5)
11+
# Compiling against QT5 requires C++11.
12+
set(CMAKE_CXX_STANDARD 11)
13+
endif(OCTOVIS_QT5)
814

915
ADD_SUBDIRECTORY( octomap )
1016

octovis/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ SET( BUILD_VIEWER 0)
6666

6767
# Look for required libraries:
6868
FIND_PACKAGE(OpenGL)
69-
FIND_PACKAGE(Qt4)
69+
if(NOT OCTOVIS_QT5)
70+
FIND_PACKAGE(Qt4)
71+
endif(NOT OCTOVIS_QT5)
7072

7173
IF (OpenGL-NOTFOUND OR Qt4-NOTFOUND)
7274
MESSAGE ( "OpenGL and QT4 are required for octovis but could not be found.")

octovis/CMakeLists_src.txt

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1-
# Qt4-support (more info: http://qtnode.net/wiki?title=Qt_with_cmake)
2-
find_package(Qt4 REQUIRED)
3-
set(QT_USE_QTOPENGL TRUE)
4-
set(QT_USE_QTXML TRUE)
5-
# include the files enabled above
6-
include(${QT_USE_FILE})
1+
2+
if(OCTOVIS_QT5)
3+
find_package(Qt5Core REQUIRED)
4+
find_package(Qt5Gui REQUIRED)
5+
find_package(Qt5OpenGL REQUIRED)
6+
find_package(Qt5Widgets REQUIRED)
7+
find_package(Qt5Xml REQUIRED)
8+
set(QT_LIBRARIES Qt5::Core Qt5::Gui Qt5::OpenGL Qt5::Widgets Qt5::Xml "${OPENGL_gl_LIBRARY}" "${OPENGL_glu_LIBRARY}")
9+
include_directories(
10+
"${Qt5Core_INCLUDE_DIRS}"
11+
"${Qt5Gui_INCLUDE_DIRS}"
12+
"${Qt5OpenGL_INCLUDE_DIRS}"
13+
"${Qt5Widgets_INCLUDE_DIRS}"
14+
"${Qt5Xml_INCLUDE_DIRS}"
15+
)
16+
else(OCTOVIS_QT5)
17+
# Qt4-support (more info: http://qtnode.net/wiki?title=Qt_with_cmake)
18+
find_package(Qt4 REQUIRED)
19+
set(QT_USE_QTOPENGL TRUE)
20+
set(QT_USE_QTXML TRUE)
21+
# include the files enabled above
22+
include(${QT_USE_FILE})
23+
endif(OCTOVIS_QT5)
724

825
# Mac OS X seems to require special linker flags:
926
IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
@@ -34,7 +51,11 @@ set(viewer_SRCS
3451
)
3552

3653
# Resource files (icons, ...)
37-
QT4_ADD_RESOURCES(viewer_RES src/icons.qrc)
54+
if(OCTOVIS_QT5)
55+
QT5_ADD_RESOURCES(viewer_RES src/icons.qrc)
56+
else(OCTOVIS_QT5)
57+
QT4_ADD_RESOURCES(viewer_RES src/icons.qrc)
58+
endif(OCTOVIS_QT5)
3859

3960
#found QGLViewer lib dir
4061
link_directories(${QGLViewer_LIBRARY_DIR})
@@ -53,7 +74,11 @@ SET(viewer_MOC_HDRS
5374
)
5475

5576
# generate list of MOC srcs:
56-
QT4_WRAP_CPP(viewer_MOC_SRCS ${viewer_MOC_HDRS})
77+
if(OCTOVIS_QT5)
78+
QT5_WRAP_CPP(viewer_MOC_SRCS ${viewer_MOC_HDRS})
79+
else(OCTOVIS_QT5)
80+
QT4_WRAP_CPP(viewer_MOC_SRCS ${viewer_MOC_HDRS})
81+
endif(OCTOVIS_QT5)
5782

5883
# let cmake generate ui*.h files from .ui files (Qt Designer):
5984
SET(viewer_UIS
@@ -62,7 +87,11 @@ SET(viewer_UIS
6287
${PROJECT_SOURCE_DIR}/include/octovis/ViewerSettingsPanel.ui
6388
${PROJECT_SOURCE_DIR}/include/octovis/ViewerSettingsPanelCamera.ui
6489
)
65-
QT4_WRAP_UI(viewer_UIS_H ${viewer_UIS})
90+
if(OCTOVIS_QT5)
91+
QT5_WRAP_UI(viewer_UIS_H ${viewer_UIS})
92+
else(OCTOVIS_QT5)
93+
QT4_WRAP_UI(viewer_UIS_H ${viewer_UIS})
94+
endif(OCTOVIS_QT5)
6695

6796
# Don't forget to include output directory, otherwise
6897
# the UI file won't be wrapped!
@@ -108,8 +137,8 @@ target_link_libraries(octovis
108137

109138
# special handling of MacOS X:
110139
IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
111-
add_custom_command(TARGET octovis POST_BUILD
112-
COMMAND install_name_tool -change libQGLViewer.2.dylib /opt/local/lib/libQGLViewer.2.dylib ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/octovis
140+
add_custom_command(TARGET octovis POST_BUILD
141+
COMMAND install_name_tool -change libQGLViewer.2.dylib /opt/local/lib/libQGLViewer.2.dylib ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/octovis
113142
)
114143
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
115144

octovis/include/octovis/SceneObject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727

2828
// fix Windows includes
2929
#include <qglobal.h>
30-
#ifdef Q_WS_WIN
30+
#if defined(Q_WS_WIN) || defined(Q_OS_WIN)
3131
#include <QtCore/qt_windows.h>
3232
#endif
3333

34-
#ifdef Q_WS_MAC
34+
#if defined(Q_WS_MAC) || defined(Q_OS_MAC)
3535
#include <OpenGL/glu.h>
3636
#else
3737
#include <GL/glu.h>

octovis/include/octovis/ViewerGui.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@
2525
#ifndef VIEWERGUI_H
2626
#define VIEWERGUI_H
2727

28+
#include <qglobal.h>
29+
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
30+
#include <QtWidgets/QMainWindow>
31+
#else // QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
2832
#include <QtGui/QMainWindow>
33+
#endif // QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
2934
#include <QFileDialog>
3035
#include <QMessageBox>
3136
#include <QDockWidget>

octovis/include/octovis/ViewerSettings.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@
2525
#ifndef VIEWERSETTINGS_H
2626
#define VIEWERSETTINGS_H
2727

28+
#include <QtGlobal>
29+
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
30+
#include <QtWidgets/QDialog>
31+
#else // QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
2832
#include <QtGui/QDialog>
33+
#endif // QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
2934
#include "ui_ViewerSettings.h"
3035

3136
class ViewerSettings : public QDialog

octovis/include/octovis/ViewerSettingsPanelCamera.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@
2525
#ifndef VIEWERSETTINGSPANELFLYMODE_H
2626
#define VIEWERSETTINGSPANELFLYMODE_H
2727

28+
#include <qglobal.h>
29+
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
30+
#include <QtWidgets/QWidget>
31+
#else
2832
#include <QtGui/QWidget>
33+
#endif
2934
#include "ui_ViewerSettingsPanelCamera.h"
3035

3136
class ViewerSettingsPanelCamera : public QWidget

octovis/src/ViewerGui.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,14 +1197,22 @@ void ViewerGui::on_action_bg_gray_triggered() {
11971197
void ViewerGui::on_savecampose_triggered() {
11981198
QString filename = QFileDialog::getSaveFileName(this, "Save Viewer State", "camera.xml", "Camera/State file (*.xml)");
11991199
if (!filename.isEmpty()) {
1200+
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
1201+
saveCameraPosition(filename.toLatin1().constData());
1202+
#else // QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
12001203
saveCameraPosition(filename.toAscii().constData());
1204+
#endif // QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
12011205
}
12021206
}
12031207

12041208
void ViewerGui::on_loadcampose_triggered() {
12051209
QString filename = QFileDialog::getOpenFileName(this, "Load Viewer State", "camera.xml", "Camera/State file (*.xml)");
12061210
if (!filename.isEmpty()) {
1211+
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
1212+
loadCameraPosition(filename.toLatin1().constData());
1213+
#else // QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
12071214
loadCameraPosition(filename.toAscii().constData());
1215+
#endif // QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
12081216
}
12091217
}
12101218

0 commit comments

Comments
 (0)