diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e4f4c3d..95bf59db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ project(sqlitebrowser) -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.9) + +OPTION(USE_QT5 FALSE "Build with qt5") if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release") @@ -11,10 +13,15 @@ set(QHEXEDIT_DIR libs/qhexedit) add_subdirectory(${ANTLR_DIR}) add_subdirectory(${QHEXEDIT_DIR}) -find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork REQUIRED) - -include(${QT_USE_FILE}) -add_definitions(${QT_DEFINITIONS}) +if(USE_QT5) + find_package(Qt5Widgets REQUIRED) + set(CMAKE_AUTOMOC ON) + set(CMAKE_INCLUDE_CURRENT_DIR ON) +else() + find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork REQUIRED) + include(${QT_USE_FILE}) + add_definitions(${QT_DEFINITIONS}) +endif() set(SQLB_HDR src/gen_version.h @@ -85,9 +92,14 @@ set(SQLB_RESOURCES src/icons/icons.qrc ) -QT4_WRAP_CPP(SQLB_MOC ${SQLB_MOC_HDR}) -QT4_WRAP_UI(SQLB_FORM_HDR ${SQLB_FORMS}) -QT4_ADD_RESOURCES(SQLB_RESOURCES_RCC ${SQLB_RESOURCES}) +if(USE_QT5) + qt5_wrap_ui(SQLB_FORM_HDR ${SQLB_FORMS}) + qt5_add_resources(SQLB_RESOURCES_RCC ${SQLB_RESOURCES}) +else() + QT4_WRAP_CPP(SQLB_MOC ${SQLB_MOC_HDR}) + QT4_WRAP_UI(SQLB_FORM_HDR ${SQLB_FORMS}) + QT4_ADD_RESOURCES(SQLB_RESOURCES_RCC ${SQLB_RESOURCES}) +endif() # get git version hash if(EXISTS ${CMAKE_SOURCE_DIR}/.git) @@ -128,6 +140,10 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR} ${ANTLR_DIR} ${QHEXEDIT_DIR} src add_executable(${PROJECT_NAME} ${SQLB_HDR} ${SQLB_SRC} ${SQLB_FORM_HDR} ${SQLB_MOC} ${SQLB_RESOURCES_RCC}) +if(USE_QT5) + qt5_use_modules(${PROJECT_NAME} Gui Widgets Network Test) + set(QT_LIBRARIES "") +endif() add_dependencies(${PROJECT_NAME} antlr qhexedit) link_directories(${CMAKE_CURRENT_BINARY_DIR}/${ANTLR_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${QHEXEDIT_DIR}) diff --git a/libs/qhexedit/CMakeLists.txt b/libs/qhexedit/CMakeLists.txt index d637108a..cc85d751 100644 --- a/libs/qhexedit/CMakeLists.txt +++ b/libs/qhexedit/CMakeLists.txt @@ -1,9 +1,14 @@ -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.9) -find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED) - -include(${QT_USE_FILE}) -add_definitions(${QT_DEFINITIONS}) +if(USE_QT5) + set(CMAKE_AUTOMOC ON) + set(CMAKE_INCLUDE_CURRENT_DIR ON) + find_package(Qt5Widgets REQUIRED) +else() + find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED) + include(${QT_USE_FILE}) + add_definitions(${QT_DEFINITIONS}) +endif() set(QHEXEDIT_SRC src/commands.cpp @@ -22,7 +27,13 @@ set(QHEXEDIT_MOC_HDR src/qhexedit_p.h ) -QT4_WRAP_CPP(QHEXEDIT_MOC ${QHEXEDIT_MOC_HDR}) +if(NOT USE_QT5) + QT4_WRAP_CPP(QHEXEDIT_MOC ${QHEXEDIT_MOC_HDR}) +endif() add_library(qhexedit ${QHEXEDIT_SRC} ${QHEXEDIT_HDR} ${QHEXEDIT_MOC}) +if(USE_QT5) + qt5_use_modules(qhexedit Widgets) +endif() + diff --git a/libs/qhexedit/src/qhexedit.h b/libs/qhexedit/src/qhexedit.h index 484dc5a0..5e8617e3 100644 --- a/libs/qhexedit/src/qhexedit.h +++ b/libs/qhexedit/src/qhexedit.h @@ -2,6 +2,9 @@ #define QHEXEDIT_H #include +#if QT_VERSION >= 0x050000 + #include +#endif #include "qhexedit_p.h" /** \mainpage diff --git a/libs/qhexedit/src/qhexedit_p.cpp b/libs/qhexedit/src/qhexedit_p.cpp index 1401cf3b..b1a4352b 100644 --- a/libs/qhexedit/src/qhexedit_p.cpp +++ b/libs/qhexedit/src/qhexedit_p.cpp @@ -1,4 +1,7 @@ #include +#if QT_VERSION >= 0x050000 + #include +#endif #include "qhexedit_p.h" #include "commands.h" diff --git a/libs/qhexedit/src/qhexedit_p.h b/libs/qhexedit/src/qhexedit_p.h index 138139b9..ba192b09 100644 --- a/libs/qhexedit/src/qhexedit_p.h +++ b/libs/qhexedit/src/qhexedit_p.h @@ -5,6 +5,9 @@ #include +#if QT_VERSION >= 0x050000 + #include +#endif #include "xbytearray.h" class QHexEditPrivate : public QWidget diff --git a/src/FilterTableHeader.cpp b/src/FilterTableHeader.cpp index 87a18b44..c183e416 100644 --- a/src/FilterTableHeader.cpp +++ b/src/FilterTableHeader.cpp @@ -8,7 +8,11 @@ FilterTableHeader::FilterTableHeader(QTableView* parent) : QHeaderView(Qt::Horizontal, parent) { // Activate the click signals to allow sorting +#if QT_VERSION >= 0x050000 + setSectionsClickable(true); +#else setClickable(true); +#endif // Do some connects: Basically just resize and reposition the input widgets whenever anything changes connect(this, SIGNAL(sectionResized(int,int,int)), this, SLOT(adjustPositions())); diff --git a/src/main.cpp b/src/main.cpp index 731d3417..1af4177a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -80,9 +80,11 @@ int main( int argc, char ** argv ) a.setApplicationName("SQLite Database Browser"); // Set character encoding to UTF8 - QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); +#if QT_VERSION < 0x050000 + QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); +#endif // Enable translation QTranslator translator; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6bee3804..6a3a1369 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,8 @@ project(sqlb-unittests) cmake_minimum_required(VERSION 2.8.9) +OPTION(USE_QT5 FALSE "Build with qt5") + if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release") endif() @@ -8,10 +10,15 @@ endif() set(ANTLR_DIR ../libs/antlr-2.7.7) add_subdirectory(${ANTLR_DIR} ${CMAKE_CURRENT_BINARY_DIR}/antlr) -find_package(Qt4 COMPONENTS QtCore QtTest REQUIRED) - -include(${QT_USE_FILE}) -add_definitions(${QT_DEFINITIONS}) +if(USE_QT5) + find_package(Qt5Widgets REQUIRED) + set(CMAKE_AUTOMOC ON) + set(CMAKE_INCLUDE_CURRENT_DIR ON) +else() + find_package(Qt4 COMPONENTS QtCore QtTest REQUIRED) + include(${QT_USE_FILE}) + add_definitions(${QT_DEFINITIONS}) +endif() set(SQLB_SRC ../src/sqlitetypes.cpp @@ -28,11 +35,19 @@ set(SQLB_HDR set(SQLB_MOC_HDR ../src/tests/testsqlobjects.h) -QT4_WRAP_CPP(SQLB_MOC ${SQLB_MOC_HDR}) +if(NOT USE_QT5) + QT4_WRAP_CPP(SQLB_MOC ${SQLB_MOC_HDR}) +endif() include_directories(${CMAKE_CURRENT_BINARY_DIR}/${ANTLR_DIR}) add_executable(${PROJECT_NAME} ${SQLB_MOC} ${SQLB_HDR} ${SQLB_SRC}) + +if(USE_QT5) + qt5_use_modules(${PROJECT_NAME} Test) + set(QT_LIBRARIES "") +endif() + add_dependencies(${PROJECT_NAME} antlr) target_link_libraries(${PROJECT_NAME} antlr ${QT_LIBRARIES})