Skip to content

Commit

Permalink
qt5: full qt5 compability
Browse files Browse the repository at this point in the history
ifdef rest of the code which can't be ported 100%
add CMake option USE_QT5 to use qt5 ;)
Thanks to stretchtiberius for initial patch
  • Loading branch information
rp- committed Feb 13, 2014
1 parent 58ec477 commit de1fb9f
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 21 deletions.
32 changes: 24 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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})
Expand Down
25 changes: 18 additions & 7 deletions libs/qhexedit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
cmake_minimum_required(VERSION 2.6)

find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED)

include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})
cmake_minimum_required(VERSION 2.8.9)

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
Expand All @@ -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()

3 changes: 3 additions & 0 deletions libs/qhexedit/src/qhexedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#define QHEXEDIT_H

#include <QtGui>
#if QT_VERSION >= 0x050000
#include <QtWidgets>
#endif
#include "qhexedit_p.h"

/** \mainpage
Expand Down
3 changes: 3 additions & 0 deletions libs/qhexedit/src/qhexedit_p.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include <QtGui>
#if QT_VERSION >= 0x050000
#include <QtWidgets>
#endif

#include "qhexedit_p.h"
#include "commands.h"
Expand Down
3 changes: 3 additions & 0 deletions libs/qhexedit/src/qhexedit_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@


#include <QtGui>
#if QT_VERSION >= 0x050000
#include <QtWidgets>
#endif
#include "xbytearray.h"

class QHexEditPrivate : public QWidget
Expand Down
4 changes: 4 additions & 0 deletions src/FilterTableHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
4 changes: 3 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 20 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
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()

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
Expand All @@ -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})

Expand Down

0 comments on commit de1fb9f

Please sign in to comment.