Skip to content

Commit

Permalink
Merge pull request #90 from jpfeltracco/master
Browse files Browse the repository at this point in the history
Port to Qt5
  • Loading branch information
mahi97 authored Sep 1, 2019
2 parents 8da673a + bb76de2 commit 8b52868
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 83 deletions.
32 changes: 17 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,37 @@ matrix:
- os: linux
dist: trusty
sudo: required
- os: linux
dist: bionic
sudo: required
- os: linux
dist: xenial
sudo: required
- os: osx
osx_image: xcode8
osx_image: xcode11

addons:
apt:
packages:
- cmake
- libqt4-dev
- qt5-default
- libqt5opengl5-dev
- libgl1-mesa-dev
- libglu1-mesa-dev
- libprotobuf-dev
- protobuf-compiler
- libode-dev
- libboost-dev

before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update > /dev/null ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew tap cartr/qt4 ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew tap-pin cartr/qt4 ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install qt@4 ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew uninstall --ignore-dependencies python ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install protobuf ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew tap robotology/formulae ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install robotology/formulae/ode ; fi
homebrew:
taps: robotology/formulae
packages:
- qt5
- protobuf
- robotology/formulae/ode

install:
# vartypes
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then git clone https://github.com/szi/vartypes.git ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then git clone https://github.com/lordhippo/vartypes.git -b osx-fix; fi
- git clone https://github.com/jpfeltracco/vartypes.git
- cd vartypes
- mkdir build && cd build
- cmake ..
Expand All @@ -52,4 +54,4 @@ script:
- mkdir build && cd build
- cmake ..
- make
- sudo make install
- sudo make install
20 changes: 13 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,14 @@ list(APPEND libs ${OPENGL_LIBRARIES})
#include_directories(${GLUT_INCLUDE_DIR})

# Qt
set(QT_USE_QTNETWORK true)
set(QT_USE_QTOPENGL true)
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
list(APPEND libs ${QT_LIBRARIES})
if(APPLE AND EXISTS /usr/local/opt/qt)
# Homebrew installs Qt5 (up to at least 5.9.1) in
# /usr/local/qt5, ensure it can be found by CMake since
# it is not in the default /usr/local prefix.
list(APPEND CMAKE_PREFIX_PATH "/usr/local/opt/qt")
endif()
find_package(Qt5 COMPONENTS Core Widgets OpenGL Network REQUIRED)
list(APPEND libs Qt5::Core Qt5::Widgets Qt5::OpenGL Qt5::Network)

# ODE
find_package(ODE REQUIRED)
Expand Down Expand Up @@ -101,7 +104,7 @@ protobuf_generate_cpp(PROTO_CPP PROTO_H
src/proto/grSim_Packet.proto
)

qt4_add_resources(RESOURCES
qt5_add_resources(RESOURCES
resources/textures.qrc
)

Expand Down Expand Up @@ -177,6 +180,9 @@ if(APPLE)
add_executable(${app} MACOSX_BUNDLE ${srcs})
target_link_libraries(${app} ${libs})
install(TARGETS ${app} DESTINATION .)
add_executable(${app}-bin ${srcs} resources/textures.qrc)
target_link_libraries(${app}-bin ${libs})
install(TARGETS ${app}-bin DESTINATION .)
set(MACOSX_BUNDLE_ICON_FILE "${PROJECT_SOURCE_DIR}/resources/icons/grsim.icns")
set(MACOSX_BUNDLE_SHORT_VERSION_STRING ${VERSION})
set(MACOSX_BUNDLE_VERSION ${VERSION})
Expand Down Expand Up @@ -238,7 +244,7 @@ set(CPACK_RESOURCE_FILE_README "${CMAKE_BINARY_DIR}/README.txt")
#set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/WELCOME.txt")
set(CPACK_PACKAGE_VERSION ${VERSION})
# Debian based specific
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libode1 (>=0.11), vartypes (>=0.7.0), libqt4-network (>=4.8.0), libqt4-core, libqt4-gui, libqt4-opengl")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libode1 (>=0.11), vartypes (>=0.7.0)")
if(FLAVOR)
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME_LOWER}_${CPACK_PACKAGE_VERSION}-${FLAVOR}_${ARCH}")
else()
Expand Down
14 changes: 5 additions & 9 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ GrSim depends on:

- [CMake](https://cmake.org/) version 2.8+
- [OpenGL](https://www.opengl.org)
- [Qt4 Development Libraries](https://www.qt.io) version 4.8+
- [Qt5 Development Libraries](https://www.qt.io)
- [Open Dynamics Engine (ODE)](http://www.ode.org)
- [VarTypes Library](https://github.com/szi/vartypes)
- [VarTypes Library](https://github.com/jpfeltracco/vartypes) forked from [Szi's Vartypes](https://github.com/szi/vartypes)
- [Google Protobuf](https://github.com/google/protobuf)
- [Boost development libraries](http://www.boost.org/) (needed by VarTypes)

Expand All @@ -25,14 +25,14 @@ GrSim depends on:
If you run a Debian system, or derivative, first ensure that these dependencies are there:

```bash
$ sudo apt-get install git build-essential cmake libqt4-dev libgl1-mesa-dev libglu1-mesa-dev libprotobuf-dev protobuf-compiler libode-dev libboost-dev
$ sudo apt-get install git build-essential cmake qt5-default libqt5opengl5-dev libgl1-mesa-dev libglu1-mesa-dev libprotobuf-dev protobuf-compiler libode-dev libboost-dev
```

Next compile and install VarTypes from source. In the following we install VarTypes from source using `git`.

```bash
$ cd /tmp
$ git clone https://github.com/szi/vartypes.git
$ git clone https://github.com/jpfeltracco/vartypes.git
$ cd vartypes
$ mkdir build
$ cd build
Expand Down Expand Up @@ -83,9 +83,7 @@ First ensure the dependencies are there:
brew install cmake
brew tap robotology/formulae
brew install robotology/formulae/ode
brew tap cartr/qt4
brew tap-pin cartr/qt4
brew install qt@4
brew install qt5
brew install protobuf
```

Expand All @@ -98,8 +96,6 @@ brew doctor

Next we need to install VarTypes manually. Please refer to the documentation above for the procedure.

**IMPORTANT NOTE:** VarTypes currently does not compile on MacOS. Please use the following fork of Vartypes instead of the official repository: `https://github.com/lordhippo/vartypes.git (branch: osx-fix)`

The steps to compile grSim on Mac OS is similar to the steps outlines above for Linux:


Expand Down
7 changes: 3 additions & 4 deletions clients/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(libs)

set(QT_USE_QTNETWORK TRUE)
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
list(APPEND libs ${QT_LIBRARIES})
find_package(Qt5 COMPONENTS Core Widgets Network REQUIRED)
list(APPEND libs Qt5::Core Qt5::Widgets Qt5::Network)


find_package(Protobuf REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIRS})
Expand Down
2 changes: 1 addition & 1 deletion clients/qt/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <QtGui/QApplication>
#include <QtWidgets/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
Expand Down
4 changes: 2 additions & 2 deletions clients/qt/mainwindow.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include <QtGui/QDialog>
#include <QtWidgets/QMainWindow>
#include <QDialog>
#include <QLineEdit>
#include <QLabel>
#include <QTimer>
Expand Down
13 changes: 7 additions & 6 deletions include/configwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Copyright (C) 2011, Parsian Robotic Center (eew.aut.ac.ir/~parsian/grsim)

#include <stdint.h>
#include <stdio.h>
#include <memory>

#include <vartypes/VarTreeModel.h>
#include <vartypes/VarItem.h>
Expand Down Expand Up @@ -69,22 +70,22 @@ using namespace VarTypes;
#else

#define DEF_VALUE(type,Type,name) \
std::tr1::shared_ptr<VarTypes::Var##Type> v_##name; \
std::shared_ptr<VarTypes::Var##Type> v_##name; \
inline type name() {return v_##name->get##Type();}

#define DEF_FIELD_VALUE(type,Type,name) \
std::tr1::shared_ptr<VarTypes::Var##Type> v_DivA_##name; \
std::tr1::shared_ptr<VarTypes::Var##Type> v_DivB_##name; \
std::shared_ptr<VarTypes::Var##Type> v_DivA_##name; \
std::shared_ptr<VarTypes::Var##Type> v_DivB_##name; \
inline type name() {return (Division() == "Division A" ? v_DivA_##name: v_DivB_##name)->get##Type(); }

#define DEF_ENUM(type,name) \
std::tr1::shared_ptr<VarTypes::VarStringEnum> v_##name; \
std::shared_ptr<VarTypes::VarStringEnum> v_##name; \
type name() {if(v_##name!=NULL) return v_##name->getString();return * (new type);}

#define DEF_TREE(name) \
std::tr1::shared_ptr<VarTypes::VarList> name;
std::shared_ptr<VarTypes::VarList> name;
#define DEF_PTREE(parents, name) \
std::tr1::shared_ptr<VarTypes::VarList> parents##_##name;
std::shared_ptr<VarTypes::VarList> parents##_##name;

#endif

Expand Down
12 changes: 0 additions & 12 deletions include/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,7 @@ Copyright (C) 2011, Parsian Robotic Center (eew.aut.ac.ir/~parsian/grsim)
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#if QT_VERSION >= 0x050000
#define QT5
#endif

#ifdef QT5
#include <QMdiArea>
#else
#include <QWorkspace>
#endif

#include <QLabel>

Expand Down Expand Up @@ -77,11 +69,7 @@ public slots:
private:
int getInterval();
QTimer *timer;
#ifndef QT5
QWorkspace* workspace;
#else
QMdiArea* workspace;
#endif
GLWidget *glwidget;
ConfigWidget *configwidget;
ConfigDockWidget *dockconfig;
Expand Down
12 changes: 0 additions & 12 deletions src/configwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,12 @@ Copyright (C) 2011, Parsian Robotic Center (eew.aut.ac.ir/~parsian/grsim)

#include "configwidget.h"

#ifdef HAVE_MACOSX

#define ADD_ENUM(type,name,Defaultvalue,namestring) \
v_##name = std::shared_ptr<Var##type>(new Var##type(namestring,Defaultvalue));
#define ADD_VALUE(parent,type,name,defaultvalue,namestring) \
v_##name = std::shared_ptr<Var##type>(new Var##type(namestring,defaultvalue)); \
parent->addChild(v_##name);

#else

#define ADD_ENUM(type,name,Defaultvalue,namestring) \
v_##name = std::tr1::shared_ptr<Var##type>(new Var##type(namestring,Defaultvalue));
#define ADD_VALUE(parent,type,name,defaultvalue,namestring) \
v_##name = std::tr1::shared_ptr<Var##type>(new Var##type(namestring,defaultvalue)); \
parent->addChild(v_##name);

#endif

#define END_ENUM(parents, name) \
parents->addChild(v_##name);
#define ADD_TO_ENUM(name,str) \
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Copyright (C) 2011, Parsian Robotic Center (eew.aut.ac.ir/~parsian/grsim)
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtGui/QApplication>
#include <QtWidgets/QApplication>
#include "mainwindow.h"
#include "winmain.h"

Expand Down
14 changes: 0 additions & 14 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ Copyright (C) 2011, Parsian Robotic Center (eew.aut.ac.ir/~parsian/grsim)
#include <QDir>
#include <QClipboard>

#ifdef QT5
#include <QStatusBar>
#include <QMessageBox>
#endif

#include "mainwindow.h"
#include "logger.h"
Expand Down Expand Up @@ -64,11 +62,7 @@ MainWindow::MainWindow(QWidget *parent)
initLogger((void*)printer);

/* Init Workspace */
#ifdef QT5
workspace = new QMdiArea(this);
#else
workspace = new QWorkspace(this);
#endif
setCentralWidget(workspace);

/* Widgets */
Expand Down Expand Up @@ -174,11 +168,7 @@ MainWindow::MainWindow(QWidget *parent)
addDockWidget(Qt::BottomDockWidgetArea, statusWidget);
addDockWidget(Qt::LeftDockWidgetArea, robotwidget);

#ifdef QT5
workspace->addSubWindow(glwidget, Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint);
#else
workspace->addWindow(glwidget, Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint);
#endif

glwidget->setWindowState(Qt::WindowMaximized);

Expand Down Expand Up @@ -453,11 +443,7 @@ void MainWindow::toggleFullScreen(bool a)
}
else {
view->close();
#ifdef QT5
workspace->addSubWindow(glwidget, Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint);
#else
workspace->addWindow(glwidget, Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint);
#endif
glwidget->show();
glwidget->resize(lastSize);
glwidget->fullScreen = false;
Expand Down

0 comments on commit 8b52868

Please sign in to comment.