Commit 384636ec authored by Jean-Christophe Fillion-Robin's avatar Jean-Christophe Fillion-Robin
Browse files

COMP 12945: Allow VTK to build against Qt5

Since VTK build system has been updated to make use of CMake macros
specific to Qt5, the support has to explicitly enabled configuring VTK
with -DVTK_QT_VERSION:STRING="5"

Additionally, in case Qt5 is not installed in a standard location,
a custom prefix for "find_package" should be passed.
For example:
  -DCMAKE_PREFIX_PATH:STRING=/home/jchris/Qt5.0.2/5.0.2/gcc_64/


Finally, this commit also resolves the build errors reported below.

Fix missing header build error by including Qt headers directly without
specifying the intermediate directory.

* Fix build error changing QString::toAscii into  QString::toLatin
The method "toAscii" has been deprecated and is not available in
default Qt5 distribution.
See http://qt-project.org/doc/qt-5.0/qtcore/qstring.html#toAscii

* Fix build error changing Qt::WFlags into Qt::WindowFlags
See http://qt-project.org/doc/qt-5.0/qtcore/qt-obsolete.html

* Fix build error changing QAbstractItemModel::reset() into
combo QAbstractItem...
parent 20539fbf
set(VTK_QT_VERSION "4" CACHE STRING "Expected Qt version")
mark_as_advanced(VTK_QT_VERSION)
set_property(CACHE VTK_QT_VERSION PROPERTY STRINGS 4 5)
if(NOT (VTK_QT_VERSION VERSION_EQUAL "4" OR VTK_QT_VERSION VERSION_EQUAL "5"))
message(FATAL_ERROR "Expected value for VTK_QT_VERSION is either '4' or '5'")
endif()
find_package(Qt4 REQUIRED)
set(QT_USE_QTOPENGL 1)
set(QT_USE_QTWEBKIT 1)
include(${QT_USE_FILE})
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})
endif()
find_package(OpenGL)
......
......@@ -161,7 +161,7 @@ void CustomLinkView::slotOpenXMLFile()
}
// Create XML reader
this->XMLReader->SetFileName( fileName.toAscii() );
this->XMLReader->SetFileName( fileName.toLatin1() );
this->XMLReader->ReadTagNameOff();
this->XMLReader->Update();
......
......@@ -131,7 +131,7 @@ void EasyView::slotOpenXMLFile()
}
// Create XML reader
this->XMLReader->SetFileName( fileName.toAscii() );
this->XMLReader->SetFileName( fileName.toLatin1() );
this->XMLReader->ReadTagNameOff();
this->XMLReader->Update();
......
......@@ -94,7 +94,7 @@ void StatsView::slotOpenSQLiteDB()
// Create SQLite reader
QString fullName = "sqlite://" + fileName;
vtkSQLiteDatabase* db = vtkSQLiteDatabase::SafeDownCast( vtkSQLDatabase::CreateFromURL( fullName.toAscii() ) );
vtkSQLiteDatabase* db = vtkSQLiteDatabase::SafeDownCast( vtkSQLDatabase::CreateFromURL( fullName.toLatin1() ) );
bool status = db->Open("");
if ( ! status )
{
......
include(vtkQt)
# set up sources to build
set(QVTKLibSrcs
vtkEventQtSlotConnect.cxx
......@@ -52,13 +54,23 @@ set(QVTKNonMocHeaders
QVTKInteractor.h
)
# import Qt4 build settings
set(QT_USE_QTNETWORK 1)
find_package(Qt4 REQUIRED QUIET)
mark_as_advanced(QT_QMAKE_EXECUTABLE)
include(${QT_USE_FILE})
if(VTK_QT_VERSION VERSION_GREATER "4")
find_package(Qt5Widgets REQUIRED QUIET)
include_directories(${Qt5Widgets_INCLUDE_DIRS})
add_definitions(${Qt5Widgets_DEFINITIONS})
qt5_wrap_cpp(QVTKLibMocSrcs ${QVTKMocHeaders})
set(QT_LIBRARIES ${Qt5Widgets_LIBRARIES})
else()
# import Qt4 build settings
set(QT_USE_QTNETWORK 1)
find_package(Qt4 REQUIRED QUIET)
mark_as_advanced(QT_QMAKE_EXECUTABLE)
include(${QT_USE_FILE})
qt4_wrap_cpp(QVTKLibMocSrcs ${QVTKMocHeaders})
qt4_wrap_cpp(QVTKLibMocSrcs ${QVTKMocHeaders})
endif()
foreach(opt
QT_RCC_EXECUTABLE
......@@ -94,9 +106,18 @@ if(BUILD_SHARED_LIBS)
set(PluginMocHeaders Q4VTKWidgetPlugin.h)
add_definitions(-DQT_PLUGIN)
include_directories(${QT_QTDESIGNER_INCLUDE_DIR})
qt4_wrap_cpp(PluginMocSrcs ${PluginMocHeaders})
if(VTK_QT_VERSION VERSION_GREATER "4")
find_package(Qt5Designer REQUIRED QUIET)
add_definitions(${Qt5Designer_DEFINITIONS})
include_directories(${Qt5Designer_INCLUDE_DIRS})
qt5_wrap_cpp(PluginMocSrcs ${PluginMocHeaders})
set(QT_LIBRARIES ${Qt5Designer_LIBRARIES})
else()
add_definitions(-DQT_PLUGIN)
include_directories(${QT_QTDESIGNER_INCLUDE_DIR})
qt4_wrap_cpp(PluginMocSrcs ${PluginMocHeaders})
set(QT_LIBRARIES ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
endif()
# add QVTK plugin from sources
# stand-alone as it doesn't depend on QVTK library
......@@ -109,10 +130,7 @@ if(BUILD_SHARED_LIBS)
set_target_properties(QVTKWidgetPlugin PROPERTIES COMPILE_DEFINITIONS QT_NO_DEBUG)
# link with Qt libs
target_link_libraries(QVTKWidgetPlugin
${QT_QTGUI_LIBRARY}
${QT_QTCORE_LIBRARY}
)
target_link_libraries(QVTKWidgetPlugin ${QT_LIBRARIES})
# install rules
......
......@@ -144,5 +144,7 @@ QList<QDesignerCustomWidgetInterface*> QVTKPlugin::customWidgets() const
return plugins;
}
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN(QVTKPlugin)
#endif
......@@ -27,8 +27,11 @@
#include <QDesignerCustomWidgetInterface>
#include <QDesignerCustomWidgetCollectionInterface>
#include <QtPlugin>
#include <QObject>
#if QT_VERSION >= 0x050000
# include <QtDesigner>
#endif
#include <QtPlugin>
#include <QWidget>
......@@ -54,10 +57,13 @@ class QVTKWidgetPlugin : public QDesignerCustomWidgetInterface
class QVTKPlugin : public QObject, public QDesignerCustomWidgetCollectionInterface
{
Q_OBJECT
#if QT_VERSION >= 0x050000
Q_PLUGIN_METADATA(IID "org.vtk.qvtkplugin")
#endif
Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
public:
QVTKPlugin();
~QVTKPlugin();
virtual ~QVTKPlugin();
virtual QList<QDesignerCustomWidgetInterface*> customWidgets() const;
private:
......
......@@ -74,7 +74,7 @@
#endif
/*! constructor */
QVTKWidget::QVTKWidget(QWidget* p, Qt::WFlags f)
QVTKWidget::QVTKWidget(QWidget* p, Qt::WindowFlags f)
: QWidget(p, f | Qt::MSWindowsOwnDC), mRenWin(NULL),
cachedImageCleanFlag(false),
automaticImageCache(false), maxImageCacheRenderRate(1.0),
......@@ -401,7 +401,7 @@ bool QVTKWidget::event(QEvent* e)
if(QObject::event(e))
{
return TRUE;
return true;
}
if(e->type() == QEvent::KeyPress)
......
......@@ -38,7 +38,7 @@
#include "vtkGUISupportQtModule.h" // For export macro
#include "QVTKInteractor.h"
#include <QtGui/QWidget>
#include <QWidget>
class QVTKInteractorAdapter;
......@@ -85,7 +85,7 @@ class VTKGUISUPPORTQT_EXPORT QVTKWidget : public QWidget
public:
//! constructor
QVTKWidget(QWidget* parent = NULL, Qt::WFlags f = 0);
QVTKWidget(QWidget* parent = NULL, Qt::WindowFlags f = 0);
//! destructor
virtual ~QVTKWidget();
......
include(vtkQt)
vtk_add_test_cxx(NO_VALID
TestQtDebugLeaksView.cxx
TestQtTableModelAdapter.cxx
TestQtTreeModelAdapter.cxx
)
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
if(VTK_QT_VERSION VERSION_GREATER "4")
find_package(Qt5Widgets REQUIRED)
include_directories(${Qt5Widgets_INCLUDE_DIRS})
add_definitions(${Qt5Widgets_DEFINITIONS})
else()
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
endif()
vtk_test_cxx_executable(${vtk-module}CxxTests QTestApp.cxx)
if(VTK_USE_QT5)
set_target_properties(${vtk-module}CxxTests PROPERTIES
COMPILE_FLAGS ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS})
endif()
......@@ -31,7 +31,11 @@ int QTestApp::Error = 0;
QTestApp::QTestApp(int _argc, char** _argv)
{
#if QT_VERSION >= 0x050000
qInstallMessageHandler(QTestApp::messageHandler);
#else
qInstallMsgHandler(QTestApp::messageHandler);
#endif
// CMake generated driver removes argv[0],
// so let's put a dummy back in
......@@ -51,7 +55,11 @@ QTestApp::QTestApp(int _argc, char** _argv)
QTestApp::~QTestApp()
{
delete App;
#if QT_VERSION >= 0x050000
qInstallMessageHandler(0);
#else
qInstallMsgHandler(0);
#endif
}
int QTestApp::exec()
......@@ -65,8 +73,18 @@ int QTestApp::exec()
return Error + ret;
}
#if QT_VERSION >= 0x050000
void QTestApp::messageHandler(QtMsgType type,
const QMessageLogContext & context,
const QString & message)
#else
void QTestApp::messageHandler(QtMsgType type, const char *msg)
#endif
{
#if QT_VERSION >= 0x050000
Q_UNUSED(context)
const char * msg = qPrintable(message);
#endif
switch(type)
{
case QtDebugMsg:
......
......@@ -33,7 +33,13 @@ public:
static int exec();
#if QT_VERSION >= 0x050000
static void messageHandler(QtMsgType type,
const QMessageLogContext & context,
const QString & message);
#else
static void messageHandler(QtMsgType type, const char *msg);
#endif
static void delay(int ms);
......
......@@ -111,7 +111,15 @@ public:
// We make the reset() method public because it isn't always possible for
// an adapter to know when its input has changed, so it must be callable
// by an outside entity.
void reset() { QAbstractItemModel::reset(); }
/// \sa beginResetModel, endResetModel
/// \deprecated
void reset() { QAbstractItemModel::beginResetModel(); QAbstractItemModel::endResetModel();}
// We make the beginResetModel() and endResetModel() methods public because it
// isn't always possible for an adapter to know when its input has changed,
// so it must be callable by an outside entity.
void beginResetModel() { QAbstractItemModel::beginResetModel(); }
void endResetModel() { QAbstractItemModel::endResetModel(); }
signals:
......
......@@ -75,7 +75,7 @@ void vtkQtConnection::Execute(vtkObject* caller, unsigned long e, void* call_dat
if(e == vtkCommand::DeleteEvent)
{
this->Owner->Disconnect(this->VTKObject, this->VTKEvent, this->QtObject,
this->QtSlot.toAscii().data(),
this->QtSlot.toLatin1().data(),
this->ClientData);
}
}
......@@ -145,7 +145,7 @@ void vtkQtConnection::PrintSelf(ostream& os, vtkIndent indent)
this->VTKObject->GetClassName() << ":" <<
vtkCommand::GetStringFromEventId(this->VTKEvent) << " <----> " <<
this->QtObject->metaObject()->className() << "::" <<
this->QtSlot.toAscii().data() << "\n";
this->QtSlot.toLatin1().data() << "\n";
}
}
......@@ -14,6 +14,7 @@
=========================================================================*/
#include "vtkQtDebugLeaksView.h"
#include "vtkQtDebugLeaksModel.h"
#include "vtkObjectBase.h"
#include <QCheckBox>
#include <QDesktopServices>
......
......@@ -675,7 +675,7 @@ void vtkQtTableModelAdapter::getValue(int row, int in_column, vtkVariant& v) con
strValue = strValue.remove(strValue.size()-2, 2); // remove the last comma
// Reconstruct the variant using this string value
v = vtkVariant(strValue.toAscii().data());
v = vtkVariant(strValue.toLatin1().data());
}
}
}
......
include(vtkQt)
set(MocHeaders ${QVTKMocHeaders}
QVTKGraphicsItem.h
QVTKWidget2.h
......@@ -7,12 +9,21 @@ set(LibSrcs ${QVTKLibSrcs}
QVTKWidget2.cxx
)
# import Qt4 build settings
set(QT_USE_QTOPENGL 1)
find_package(Qt4 REQUIRED QUIET)
include(${QT_USE_FILE})
if(VTK_QT_VERSION VERSION_GREATER "4")
find_package(Qt5OpenGL REQUIRED QUIET)
include_directories(${Qt5OpenGL_INCLUDE_DIRS})
add_definitions(${Qt5OpenGL_DEFINITIONS})
qt5_wrap_cpp(LibMocSrcs ${MocHeaders})
set(QT_LIBRARIES ${Qt5OpenGL_LIBRARIES})
else()
# import Qt4 build settings
set(QT_USE_QTOPENGL 1)
find_package(Qt4 REQUIRED QUIET)
include(${QT_USE_FILE})
qt4_wrap_cpp(LibMocSrcs ${MocHeaders})
qt4_wrap_cpp(LibMocSrcs ${MocHeaders})
endif()
set(${vtk-module}_NO_HeaderTest 1)
vtk_module_library(${vtk-module} ${LibSrcs} ${LibMocSrcs})
......
......@@ -26,8 +26,8 @@
#define QVTKGraphicsItem_hpp
#include "vtkGUISupportQtOpenGLModule.h" // For export macro
#include <QtGui/QGraphicsWidget>
#include <QtOpenGL/QGLContext>
#include <QGLContext>
#include <QGraphicsWidget>
#include <vtkSmartPointer.h>
#include "QVTKWin32Header.h"
class vtkEventQtSlotConnect;
......
include(vtkQt)
# set up sources to build
set(LibSrcs
vtkQtSQLDatabase.cxx
......@@ -7,10 +9,25 @@ set(LibSrcs
include_directories(${CMAKE_CURRENT_BINARY_DIR})
# import Qt4 build settings
set(QT_USE_QTSQL 1)
find_package(Qt4 REQUIRED QUIET)
include(${QT_USE_FILE})
if(VTK_QT_VERSION VERSION_GREATER "4")
find_package(Qt5Widgets REQUIRED QUIET)
find_package(Qt5Sql REQUIRED QUIET)
set(_qt_include_dirs ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Sql_INCLUDE_DIRS})
list(REMOVE_DUPLICATES _qt_include_dirs)
include_directories(${_qt_include_dirs})
set(_qt_definitions ${Qt5Widgets_DEFINITIONS} ${Qt5Sql_DEFINITIONS})
list(REMOVE_DUPLICATES _qt_definitions)
add_definitions(${_qt_definitions})
set(QT_LIBRARIES ${Qt5Widgets_LIBRARIES} ${Qt5Sql_LIBRARIES})
else()
# import Qt4 build settings
set(QT_USE_QTSQL 1)
find_package(Qt4 REQUIRED QUIET)
include(${QT_USE_FILE})
endif()
set(${vtk-module}_NO_HeaderTest 1)
vtk_module_library(${vtk-module} ${LibSrcs})
......
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