Skip to content

Commit

Permalink
Qt5 support (CMake option) for octovis (OctoMap#152)
Browse files Browse the repository at this point in the history
Set CMake option OCTOVIS_QT5 to true in order to use it. Contributed by K. Stepanas.
  • Loading branch information
ahornung authored Mar 11, 2017
1 parent 817af60 commit cefed0c
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ ENABLE_TESTING() # enable CTest environment of subprojects

option(BUILD_OCTOVIS_SUBPROJECT "Build targets from subproject octovis" ON)
option(BUILD_DYNAMICETD3D_SUBPROJECT "Build targets from subproject dynamicEDT3D" ON)
option(OCTOVIS_QT5 "Link Octovis against Qt5?" NO)

if(OCTOVIS_QT5)
# Compiling against QT5 requires C++11.
set(CMAKE_CXX_STANDARD 11)
endif(OCTOVIS_QT5)

ADD_SUBDIRECTORY( octomap )

Expand Down
4 changes: 3 additions & 1 deletion octovis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ SET( BUILD_VIEWER 0)

# Look for required libraries:
FIND_PACKAGE(OpenGL)
FIND_PACKAGE(Qt4)
if(NOT OCTOVIS_QT5)
FIND_PACKAGE(Qt4)
endif(NOT OCTOVIS_QT5)

IF (OpenGL-NOTFOUND OR Qt4-NOTFOUND)
MESSAGE ( "OpenGL and QT4 are required for octovis but could not be found.")
Expand Down
51 changes: 40 additions & 11 deletions octovis/CMakeLists_src.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
# Qt4-support (more info: http://qtnode.net/wiki?title=Qt_with_cmake)
find_package(Qt4 REQUIRED)
set(QT_USE_QTOPENGL TRUE)
set(QT_USE_QTXML TRUE)
# include the files enabled above
include(${QT_USE_FILE})

if(OCTOVIS_QT5)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5OpenGL REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Xml REQUIRED)
set(QT_LIBRARIES Qt5::Core Qt5::Gui Qt5::OpenGL Qt5::Widgets Qt5::Xml "${OPENGL_gl_LIBRARY}" "${OPENGL_glu_LIBRARY}")
include_directories(
"${Qt5Core_INCLUDE_DIRS}"
"${Qt5Gui_INCLUDE_DIRS}"
"${Qt5OpenGL_INCLUDE_DIRS}"
"${Qt5Widgets_INCLUDE_DIRS}"
"${Qt5Xml_INCLUDE_DIRS}"
)
else(OCTOVIS_QT5)
# Qt4-support (more info: http://qtnode.net/wiki?title=Qt_with_cmake)
find_package(Qt4 REQUIRED)
set(QT_USE_QTOPENGL TRUE)
set(QT_USE_QTXML TRUE)
# include the files enabled above
include(${QT_USE_FILE})
endif(OCTOVIS_QT5)

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

# Resource files (icons, ...)
QT4_ADD_RESOURCES(viewer_RES src/icons.qrc)
if(OCTOVIS_QT5)
QT5_ADD_RESOURCES(viewer_RES src/icons.qrc)
else(OCTOVIS_QT5)
QT4_ADD_RESOURCES(viewer_RES src/icons.qrc)
endif(OCTOVIS_QT5)

#found QGLViewer lib dir
link_directories(${QGLViewer_LIBRARY_DIR})
Expand All @@ -53,7 +74,11 @@ SET(viewer_MOC_HDRS
)

# generate list of MOC srcs:
QT4_WRAP_CPP(viewer_MOC_SRCS ${viewer_MOC_HDRS})
if(OCTOVIS_QT5)
QT5_WRAP_CPP(viewer_MOC_SRCS ${viewer_MOC_HDRS})
else(OCTOVIS_QT5)
QT4_WRAP_CPP(viewer_MOC_SRCS ${viewer_MOC_HDRS})
endif(OCTOVIS_QT5)

# let cmake generate ui*.h files from .ui files (Qt Designer):
SET(viewer_UIS
Expand All @@ -62,7 +87,11 @@ SET(viewer_UIS
${PROJECT_SOURCE_DIR}/include/octovis/ViewerSettingsPanel.ui
${PROJECT_SOURCE_DIR}/include/octovis/ViewerSettingsPanelCamera.ui
)
QT4_WRAP_UI(viewer_UIS_H ${viewer_UIS})
if(OCTOVIS_QT5)
QT5_WRAP_UI(viewer_UIS_H ${viewer_UIS})
else(OCTOVIS_QT5)
QT4_WRAP_UI(viewer_UIS_H ${viewer_UIS})
endif(OCTOVIS_QT5)

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

# special handling of MacOS X:
IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
add_custom_command(TARGET octovis POST_BUILD
COMMAND install_name_tool -change libQGLViewer.2.dylib /opt/local/lib/libQGLViewer.2.dylib ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/octovis
add_custom_command(TARGET octovis POST_BUILD
COMMAND install_name_tool -change libQGLViewer.2.dylib /opt/local/lib/libQGLViewer.2.dylib ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/octovis
)
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

Expand Down
4 changes: 2 additions & 2 deletions octovis/include/octovis/SceneObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@

// fix Windows includes
#include <qglobal.h>
#ifdef Q_WS_WIN
#if defined(Q_WS_WIN) || defined(Q_OS_WIN)
#include <QtCore/qt_windows.h>
#endif

#ifdef Q_WS_MAC
#if defined(Q_WS_MAC) || defined(Q_OS_MAC)
#include <OpenGL/glu.h>
#else
#include <GL/glu.h>
Expand Down
5 changes: 5 additions & 0 deletions octovis/include/octovis/ViewerGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
#ifndef VIEWERGUI_H
#define VIEWERGUI_H

#include <qglobal.h>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QtWidgets/QMainWindow>
#else // QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QtGui/QMainWindow>
#endif // QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QFileDialog>
#include <QMessageBox>
#include <QDockWidget>
Expand Down
5 changes: 5 additions & 0 deletions octovis/include/octovis/ViewerSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
#ifndef VIEWERSETTINGS_H
#define VIEWERSETTINGS_H

#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QtWidgets/QDialog>
#else // QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QtGui/QDialog>
#endif // QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include "ui_ViewerSettings.h"

class ViewerSettings : public QDialog
Expand Down
5 changes: 5 additions & 0 deletions octovis/include/octovis/ViewerSettingsPanelCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
#ifndef VIEWERSETTINGSPANELFLYMODE_H
#define VIEWERSETTINGSPANELFLYMODE_H

#include <qglobal.h>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QtWidgets/QWidget>
#else
#include <QtGui/QWidget>
#endif
#include "ui_ViewerSettingsPanelCamera.h"

class ViewerSettingsPanelCamera : public QWidget
Expand Down
8 changes: 8 additions & 0 deletions octovis/src/ViewerGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1197,14 +1197,22 @@ void ViewerGui::on_action_bg_gray_triggered() {
void ViewerGui::on_savecampose_triggered() {
QString filename = QFileDialog::getSaveFileName(this, "Save Viewer State", "camera.xml", "Camera/State file (*.xml)");
if (!filename.isEmpty()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
saveCameraPosition(filename.toLatin1().constData());
#else // QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
saveCameraPosition(filename.toAscii().constData());
#endif // QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
}
}

void ViewerGui::on_loadcampose_triggered() {
QString filename = QFileDialog::getOpenFileName(this, "Load Viewer State", "camera.xml", "Camera/State file (*.xml)");
if (!filename.isEmpty()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
loadCameraPosition(filename.toLatin1().constData());
#else // QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
loadCameraPosition(filename.toAscii().constData());
#endif // QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
}
}

Expand Down

0 comments on commit cefed0c

Please sign in to comment.