Commit eeba833c authored by Andrew Maclean's avatar Andrew Maclean
Browse files

Make Qt examples build with either Qt4 or Qt5.



1) Added conditional instructions to the CMakeList.txt files
    based on VTK_QT_VERSION.
2) Cleaned up the CmakeLists.txt files to make them more consistent.
3) Added QT_VERSION ifdefs, where appropriate, to take into account
    differences between Qt5 and Qt4.

Change-Id: I738a4782dda7ef920d7418918e6ec3938f1c2297
Signed-off-by: Andrew Maclean's avatarAndrew Maclean <andrew.amaclean@gmail.com>
parent ea31c428
# Only enable if Qt 4 is being used for now, Qt 5 will take a little more work.
if(VTK_QT_VERSION VERSION_LESS "5")
add_subdirectory(ImageViewer)
add_subdirectory(SimpleView)
add_subdirectory(Events)
add_subdirectory(FourPaneViewer)
add_subdirectory(ImageViewer)
add_subdirectory(SimpleView)
add_subdirectory(Events)
add_subdirectory(FourPaneViewer)
if(TARGET vtkGUISupportQtOpenGL)
add_subdirectory(GraphicsView)
endif()
if(TARGET vtkGUISupportQtOpenGL)
add_subdirectory(GraphicsView)
endif()
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.ctest.in"
"${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.ctest" @ONLY)
endif()
project(QtEvents)
cmake_minimum_required(VERSION 2.8)
# Eliminate a warning when building in Windows that relates
# to static linking of Qt executables to qtmain.lib.
# This policy was introduced in CMake version 2.8.11.
......@@ -17,14 +19,30 @@ if(NOT VTK_BINARY_DIR)
include(${VTK_USE_FILE})
endif()
# Use what VTK built with
set(QT_QMAKE_EXECUTABLE ${VTK_QT_QMAKE_EXECUTABLE} CACHE FILEPATH "")
set(QT_MOC_EXECUTABLE ${VTK_QT_MOC_EXECUTABLE} CACHE FILEPATH "")
set(QT_UIC_EXECUTABLE ${VTK_QT_UIC_EXECUTABLE} CACHE FILEPATH "")
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
if("${VTK_QT_VERSION}" STREQUAL "")
message(FATAL_ERROR "VTK was not built with Qt")
endif()
if(VTK_QT_VERSION VERSION_GREATER "4")
# We have ui files, this will bring in the macro: qt5_wrap_ui
find_package(QT5Widgets REQUIRED QUIET)
else()
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
# Use what VTK built with
set(QT_QMAKE_EXECUTABLE ${VTK_QT_QMAKE_EXECUTABLE} CACHE FILEPATH "")
set(QT_MOC_EXECUTABLE ${VTK_QT_MOC_EXECUTABLE} CACHE FILEPATH "")
set(QT_UIC_EXECUTABLE ${VTK_QT_UIC_EXECUTABLE} CACHE FILEPATH "")
endif()
set( Srcs main.cxx GUI4.cxx )
set(SRCS main.cxx)
set( Hdrs GUI4.h )
set( MOC_Hdrs GUI4.h )
set( UIs GUI4.ui )
# Use the include path and library for Qt that is used by VTK.
include_directories(
......@@ -32,17 +50,25 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
)
include_directories(${VTK_TDX_INCLUDE_PATH})
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
qt4_wrap_ui(UI_SRCS GUI4.ui)
qt4_wrap_cpp(MOC_SRCS GUI4.h)
list(APPEND SRCS ${MOC_SRCS} GUI4.cxx GUI4.h)
if(VTK_QT_VERSION VERSION_GREATER "4")
qt5_wrap_ui(UI_Srcs ${UIs})
add_executable(qtevents MACOSX_BUNDLE ${SRCS} ${UI_SRCS})
add_executable(qtevents
MACOSX_BUNDLE ${Srcs} ${Hdrs} ${UI_Srcs} ${MOC_Hdrs})
target_link_libraries(qtevents
${QT_LIBRARIES}
${VTK_LIBRARIES}
)
qt5_use_modules(qtevents Core Gui Widgets)
target_link_libraries(qtevents ${VTK_LIBRARIES})
else()
qt4_wrap_ui(UI_Srcs ${UIs})
add_executable(qtevents MACOSX_BUNDLE ${Srcs} ${Hdrs} ${UI_Srcs} ${MOC_Hdrs})
target_link_libraries(qtevents
${QT_LIBRARIES}
${VTK_LIBRARIES}
)
endif()
cmake_minimum_required(VERSION 2.6)
project(QtVTKRenderWindows)
cmake_minimum_required(VERSION 2.6)
# Eliminate a warning when building in Windows that relates
# to static linking of Qt executables to qtmain.lib.
# This policy was introduced in CMake version 2.8.11.
......@@ -19,36 +19,56 @@ if(NOT VTK_BINARY_DIR)
include(${VTK_USE_FILE})
endif()
# Use what VTK built with
set(QT_QMAKE_EXECUTABLE ${VTK_QT_QMAKE_EXECUTABLE} CACHE FILEPATH "")
set(QT_MOC_EXECUTABLE ${VTK_QT_MOC_EXECUTABLE} CACHE FILEPATH "")
set(QT_UIC_EXECUTABLE ${VTK_QT_UIC_EXECUTABLE} CACHE FILEPATH "")
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
if("${VTK_QT_VERSION}" STREQUAL "")
message(FATAL_ERROR "VTK was not built with Qt")
endif()
if(VTK_QT_VERSION VERSION_GREATER "4")
# We have ui files, this will bring in the macro: qt5_wrap_ui
find_package(QT5Widgets REQUIRED QUIET)
else()
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
# Use what VTK built with
set(QT_QMAKE_EXECUTABLE ${VTK_QT_QMAKE_EXECUTABLE} CACHE FILEPATH "")
set(QT_MOC_EXECUTABLE ${VTK_QT_MOC_EXECUTABLE} CACHE FILEPATH "")
set(QT_UIC_EXECUTABLE ${VTK_QT_UIC_EXECUTABLE} CACHE FILEPATH "")
endif()
# Set your files and resources here
set(QtVTKRenderWindowsSrcs QtVTKRenderWindowsApp.cxx QtVTKRenderWindows.cxx)
set(QtVTKRenderWindowsUI QtVTKRenderWindows.ui)
set(QtVTKRenderWindowsHeaders QtVTKRenderWindows.h)
set( Srcs QtVTKRenderWindowsApp.cxx QtVTKRenderWindows.cxx)
set( Hdrs QtVTKRenderWindows.h )
set( MOC_Hdrs QtVTKRenderWindows.h )
set( UIs QtVTKRenderWindows.ui )
include_directories(
${QT_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
qt4_wrap_ui(UISrcs ${QtVTKRenderWindowsUI})
qt4_wrap_cpp(MOCSrcs ${QtVTKRenderWindowsHeaders} )
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
source_group("Resources" FILES
${QtVTKRenderWindowsUI}
)
if(VTK_QT_VERSION VERSION_GREATER "4")
qt5_wrap_ui(UI_Srcs ${UIs})
source_group("Generated" FILES
${UISrcs}
${MOCSrcs}
${RCS_SOURCES}
)
# CMAKE_AUTOMOC in ON so the MocHdrs will be automatically wrapped.
add_executable(QtVTKRenderWindows ${Srcs} ${Hdrs} ${UI_Srcs} ${MOC_Hdrs})
qt5_use_modules(QtVTKRenderWindows Core Gui Widgets)
add_executable(QtVTKRenderWindows ${QtVTKRenderWindowsSrcs} ${UISrcs} ${MOCSrcs})
target_link_libraries(QtVTKRenderWindows ${QT_LIBRARIES} ${VTK_LIBRARIES})
target_link_libraries(QtVTKRenderWindows ${VTK_LIBRARIES})
else()
include_directories(
${QT_INCLUDE_DIR}
)
qt4_wrap_ui(UI_Srcs ${UIs})
add_executable(QtVTKRenderWindows ${Srcs} ${Hdrs} ${UI_Srcs} ${MOC_Hdrs})
target_link_libraries(QtVTKRenderWindows ${QT_LIBRARIES} ${VTK_LIBRARIES})
endif()
if(NOT VTK_USE_QT5)
find_package(Qt4 REQUIRED)
set(QT_USE_QTOPENGL 1)
set(QT_USE_QTWEBKIT 1)
include(${QT_USE_FILE})
else()
find_package(Qt5WebKitWidgets REQUIRED QUIET)
include_directories(${Qt5WebKitWidgets_INCLUDE_DIRS})
add_definitions(${Qt5WebKitWidgets_DEFINITIONS})
set(QT_LIBRARIES ${Qt5WebKitWidgets_LIBRARIES})
project( GraphicsView )
cmake_minimum_required(VERSION 2.8.8)
# Eliminate a warning when building in Windows that relates
# to static linking of Qt executables to qtmain.lib.
# This policy was introduced in CMake version 2.8.11.
# CMake version 2.8.11.2 warns when the policy is not set
# and uses OLD behavior.
if(POLICY CMP0020)
cmake_policy(SET CMP0020 NEW)
endif()
find_package(OpenGL)
......@@ -17,28 +18,68 @@ if(NOT VTK_BINARY_DIR)
include(${VTK_USE_FILE})
endif()
if(NOT QT_QTWEBKIT_FOUND OR QT_VERSION_MINOR LESS 6)
message(STATUS "VTK isn't configured to use QtOpenGL, QtWebKit wasn't found, or Qt 4.6 wasn't found. GraphicsView example is disabled.")
if("${VTK_QT_VERSION}" STREQUAL "")
message(FATAL_ERROR "VTK was not built with Qt")
endif()
if(VTK_QT_VERSION VERSION_GREATER "4")
find_package(Qt5WebKitWidgets REQUIRED QUIET)
else()
find_package(Qt4 REQUIRED)
set(QT_USE_QTOPENGL 1)
set(QT_USE_QTWEBKIT 1)
include(${QT_USE_FILE})
endif()
set( Srcs
main.cpp
OpenGLScene.cpp
TreeRingViewItem.cpp
GraphLayoutViewItem.cpp
WebView.cpp
)
set( Hdrs
GraphicsView.hpp
OpenGLScene.hpp
QBoolAnimation.h
TreeRingViewItem.h
GraphLayoutViewItem.h
WebView.h
)
qt4_add_resources(qrcfiles GraphicsView.qrc)
set( MOC_Hdrs
OpenGLScene.hpp
QBoolAnimation.h
WebView.h
)
qt4_wrap_cpp(mocs
OpenGLScene.hpp
QBoolAnimation.h
WebView.h
)
set( QRCs
GraphicsView.qrc
)
add_executable(qtgraphicsview
main.cpp
OpenGLScene.cpp
TreeRingViewItem.cpp
GraphLayoutViewItem.cpp
WebView.cpp
${mocs}
${qrcfiles}
)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
if(VTK_QT_VERSION VERSION_GREATER "4")
qt5_add_resources(QRC_Srcs ${QRCs} )
add_executable(qtgraphicsview MACOSX_BUNDLE
${Srcs} ${Hdrs} ${MOC_Hdrs} ${QRC_Srcs})
qt5_use_modules(qtgraphicsview Core Gui Widgets
WebKit WebKitWidgets OpenGL OpenGLExtensions)
target_link_libraries(qtgraphicsview ${VTK_LIBRARIES})
else()
if (NOT QT_QTWEBKIT_FOUND OR QT_VERSION_MINOR LESS 6)
message(STATUS "VTK isn't configured to use QtOpenGL, QtWebKit wasn't found, or Qt 4.6 wasn't found. GraphicsView example is disabled.")
else()
qt4_add_resources(QRC_Srcs ${QRCs})
qt4_wrap_cpp(MOC_Srcs ${MOC_Hdrs})
target_link_libraries(qtgraphicsview ${QT_LIBRARIES} ${VTK_LIBRARIES})
add_executable(qtgraphicsview ${Srcs} ${Hdrs} ${MOC_Hdrs} ${QRC_Srcs})
target_link_libraries(qtgraphicsview ${QT_LIBRARIES} ${VTK_LIBRARIES})
endif()
endif()
......@@ -126,8 +126,14 @@ void OpenGLScene::mousePressEvent(QGraphicsSceneMouseEvent* e)
{
QGraphicsScene::mousePressEvent(e);
// see if its under one our our deactivated items
QGraphicsItem* item = itemAt(e->scenePos());
// See if its under one our our deactivated items.
#if QT_VERSION >= 0x050000
// The transform is just the identity matrix.
QGraphicsItem* item = itemAt(e->scenePos(),QTransform());
#else
QGraphicsItem* item = itemAt(e->scenePos());
#endif
if(item == mGraphLayoutView && CurrentState != 0)
{
e->accept();
......
project(QtImageViewer)
cmake_minimum_required(VERSION 2.8)
# Eliminate a warning when building in Windows that relates
# to static linking of Qt executables to qtmain.lib.
# This policy was introduced in CMake version 2.8.11.
......@@ -17,18 +19,35 @@ if(NOT VTK_BINARY_DIR)
include(${VTK_USE_FILE})
endif()
# Use what VTK built with
set(QT_QMAKE_EXECUTABLE ${VTK_QT_QMAKE_EXECUTABLE} CACHE FILEPATH "")
set(QT_MOC_EXECUTABLE ${VTK_QT_MOC_EXECUTABLE} CACHE FILEPATH "")
set(QT_UIC_EXECUTABLE ${VTK_QT_UIC_EXECUTABLE} CACHE FILEPATH "")
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
if("${VTK_QT_VERSION}" STREQUAL "")
message(FATAL_ERROR "VTK was not built with Qt")
endif()
if(VTK_QT_VERSION VERSION_GREATER "4")
find_package(Qt5Core REQUIRED QUIET)
else()
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
# Use what VTK built with
set(QT_QMAKE_EXECUTABLE ${VTK_QT_QMAKE_EXECUTABLE} CACHE FILEPATH "")
set(QT_MOC_EXECUTABLE ${VTK_QT_MOC_EXECUTABLE} CACHE FILEPATH "")
set(QT_UIC_EXECUTABLE ${VTK_QT_UIC_EXECUTABLE} CACHE FILEPATH "")
endif()
set( Srcs main.cxx )
if(VTK_QT_VERSION VERSION_GREATER "4")
add_executable(qtimageviewer ${Srcs})
set(SRCS main.cxx)
qt5_use_modules(qtimageviewer Core Gui Widgets)
add_executable(qtimageviewer MACOSX_BUNDLE ${SRCS})
target_link_libraries(qtimageviewer ${VTK_LIBRARIES})
else()
include_directories(
${QT_INCLUDE_DIR}
)
target_link_libraries(qtimageviewer
${QT_LIBRARIES}
${VTK_LIBRARIES}
)
add_executable(qtimageviewer ${Srcs})
target_link_libraries(qtimageviewer ${QT_LIBRARIES} ${VTK_LIBRARIES})
endif()
project(SimpleView)
cmake_minimum_required(VERSION 2.8)
# Eliminate a warning when building in Windows that relates
# to static linking of Qt executables to qtmain.lib.
# This policy was introduced in CMake version 2.8.11.
......@@ -17,12 +19,21 @@ if(NOT VTK_BINARY_DIR)
include(${VTK_USE_FILE})
endif()
# Use what VTK built with
set(QT_QMAKE_EXECUTABLE ${VTK_QT_QMAKE_EXECUTABLE} CACHE FILEPATH "")
set(QT_MOC_EXECUTABLE ${VTK_QT_MOC_EXECUTABLE} CACHE FILEPATH "")
set(QT_UIC_EXECUTABLE ${VTK_QT_UIC_EXECUTABLE} CACHE FILEPATH "")
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
if("${VTK_QT_VERSION}" STREQUAL "")
message(FATAL_ERROR "VTK was not built with Qt")
endif()
if(VTK_QT_VERSION VERSION_GREATER "4")
# We have ui files, this will bring in the macro: qt5_wrap_ui
find_package(QT5Widgets REQUIRED QUIET)
else()
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
# Use what VTK built with
set(QT_QMAKE_EXECUTABLE ${VTK_QT_QMAKE_EXECUTABLE} CACHE FILEPATH "")
set(QT_MOC_EXECUTABLE ${VTK_QT_MOC_EXECUTABLE} CACHE FILEPATH "")
set(QT_UIC_EXECUTABLE ${VTK_QT_UIC_EXECUTABLE} CACHE FILEPATH "")
endif()
# Use the include path and library for Qt that is used by VTK.
include_directories(
......@@ -30,40 +41,69 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
)
# Set your files and resources here
set(SimpleViewSrcs main.cxx SimpleView.cxx)
set(SimpleViewUI SimpleView.ui)
set(SimpleViewHeaders SimpleView.h)
set(SimpleViewResources Icons/icons.qrc)
set( Srcs main.cxx SimpleView.cxx )
set( Hdrs SimpleView.h )
set( MOC_Hdrs SimpleView.h )
set( UIs SimpleView.ui )
set( QRCs Icons/icons.qrc )
source_group("Resources" FILES
${UIs}
${QRCs}
${EXE_ICON} # Not present
)
source_group("Generated" FILES
${UI_Srcs}
${MOC_Srcs}
${QRC_Srcs}
${QRC_Srcs}
)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# The rest should just work (sure...)
qt4_wrap_ui(UISrcs ${SimpleViewUI})
qt4_wrap_cpp(MOCSrcs ${SimpleViewHeaders} )
qt4_add_resources(ResourceSrcs ${SimpleViewResources})
source_group("Resources" FILES
${SimpleViewUI}
${SimpleViewResources}
${EXE_ICON}
)
if(VTK_QT_VERSION VERSION_GREATER "4")
qt5_wrap_ui(UI_Srcs ${UIs})
qt5_add_resources(QRC_Srcs ${QRCs} )
source_group("Generated" FILES
${UISrcs}
${MOCSrcs}
${ResourceSrcs}
${RCS_SOURCES}
)
add_executable(SimpleView MACOSX_BUNDLE
${Srcs} ${Hdrs} ${UI_Srcs} ${MOC_Hdrs} ${QRC_Srcs})
add_definitions(-DQT_GUI_LIBS -DQT_CORE_LIB -DQT3_SUPPORT)
qt5_use_modules(SimpleView Core Gui Widgets)
add_executable(SimpleView MACOSX_BUNDLE ${SimpleViewSrcs} ${UISrcs} ${MOCSrcs}
${ResourceSrcs})
target_link_libraries(SimpleView ${VTK_LIBRARIES})
else()
qt4_wrap_ui(UI_Srcs ${UIs})
qt4_wrap_cpp(MOC_Srcs ${MOC_Hdrs} )
qt4_add_resources(QRC_Srcs ${QRCs})
target_link_libraries(SimpleView
${QT_LIBRARIES}
${VTK_LIBRARIES}
)
source_group("Resources" FILES
${UIs}
${QRCs}
${EXE_ICON} # Not present
)
source_group("Generated" FILES
${UI_Srcs}
${QRC_Srcs}
${QRC_Srcs}
)
add_definitions(-DQT_GUI_LIBS -DQT_CORE_LIB -DQT3_SUPPORT)
add_executable(SimpleView MACOSX_BUNDLE
${Srcs} ${Hdrs} ${UI_Srcs} ${MOC_Hdrs} ${QRC_Srcs})
target_link_libraries(SimpleView
${QT_LIBRARIES}
${VTK_LIBRARIES}
)
endif()
......@@ -8,7 +8,10 @@
*/
// QT includes
#include <QApplication>
#include <QCleanlooksStyle>
#if QT_VERSION < 0x050000
#include <QCleanlooksStyle>
#endif
#include "SimpleView.h"
extern int qInitResources_icons();
......@@ -19,7 +22,11 @@ int main( int argc, char** argv )
// QT Stuff
QApplication app( argc, argv );
QApplication::setStyle(new QCleanlooksStyle);
#if QT_VERSION >= 0x050000
QApplication::setStyle("fusion");
#else
QApplication::setStyle(new QCleanlooksStyle);
#endif
qInitResources_icons();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment