Added files and cmake for qt gui

This commit is contained in:
Hans-Christian Helltegen
2014-04-09 10:25:12 -04:00
parent 4985feb309
commit b4ebfc69ad
7 changed files with 286 additions and 11 deletions

8
gui/CMakeLists.txt Normal file
View File

@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 2.8.11)
project(GUI)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${GUI_SOURCE_DIR}/build-debug)
set(CMAKE_BUILD_TYPE Debug)
add_subdirectory(src)

20
gui/src/CMakeLists.txt Normal file
View File

@@ -0,0 +1,20 @@
# FIXME: ugly hack for linking qt5
set (CMAKE_PREFIX_PATH "/home/hhellteg/Qt/5.2.1/gcc_64")
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Find the Qt libraries
find_package(Qt5Widgets)
find_package(Qt5Network)
# Create ui_mainwindow.h file
qt5_wrap_ui(QT_UI_HEADERS mainwindow.ui)
# Tell CMake to create the executable
add_executable(gui main.cpp mainwindow.cpp ${QT_UI_HEADERS})
# Use the needed modules from Qt 5.
target_link_libraries(gui Qt5::Widgets Qt5::Network)

12
gui/src/main.cpp Normal file
View File

@@ -0,0 +1,12 @@
#include "mainwindow.h"
#include <QApplication>
#include <QFileDialog>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

109
gui/src/mainwindow.cpp Normal file
View File

@@ -0,0 +1,109 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
#include <QJsonArray>
#include <QJsonValue>
#include <QJsonObject>
#include <QJsonDocument>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
_sgctSocket(NULL) {
ui->setupUi(this);
ui->_hostEdit->setText("127.0.0.1");
setWindowTitle("OpenSpace Qt GUI");
ui->_statsCheckBox->setEnabled(false);
ui->_graphCheckBox->setEnabled(false);
ui->_renderComboBox->setEnabled(false);
// TEST JSON
// QJsonObject json, jsonObj2;
// QJsonArray jsonArr, jsonArr2;
// json["Value 1"] = (QString("Herp"));
// json["Value 2"] = (QString("Derp"));
// jsonArr.push_back(QString("val1"));
// jsonArr.push_back(QString("val2"));
// jsonArr.push_back(QString("val3"));
// jsonArr.push_back(QString("val4"));
// jsonArr.push_back(QString("val5"));
// jsonArr2.push_back(QString("val21"));
// jsonArr2.push_back(QString("val22"));
// jsonArr2.push_back(QString("val23"));
// jsonArr2.push_back(QString("val24"));
// jsonArr2.push_back(QString("val25"));
// jsonObj2["ArrayYo2"] = jsonArr2;
// jsonArr.push_back(jsonObj2);
// json["ArrayYo"] = jsonArr;
// QJsonDocument doc;
// doc.setObject(json);
// std::cout << doc.toJson().data() << std::endl;
// quick_exit(0);
}
MainWindow::~MainWindow() {
delete ui;
}
void MainWindow::on__connectButton_clicked() {
_sgctSocket = new QTcpSocket(this);
connect( _sgctSocket, SIGNAL(readyRead()), SLOT(readTcpData()) );
_sgctSocket->connectToHost(ui->_hostEdit->text(), 20500);
if (_sgctSocket->waitForConnected()) {
ui->_statsCheckBox->setEnabled(true);
ui->_graphCheckBox->setEnabled(true);
ui->_renderComboBox->setEnabled(true);
} else {
std::cout << "Connection failed" << std::endl;
ui->_statsCheckBox->setEnabled(false);
ui->_graphCheckBox->setEnabled(false);
ui->_renderComboBox->setEnabled(false);
}
}
void MainWindow::on__statsCheckBox_toggled(bool checked) {
QJsonObject json;
QJsonDocument doc;
if (checked) {
json["stats"] = 1;
} else {
json["stats"] = 0;
}
doc.setObject(json);
std::cout << "Bytes sent: " << sendToSGCT(doc.toJson()) << " " << std::flush;
}
void MainWindow::on__graphCheckBox_toggled(bool checked) {
QJsonObject json;
QJsonDocument doc;
if (checked) {
json["graph"] = 1;
} else {
json["graph"] = 0;
}
doc.setObject(json);
std::cout << "Bytes sent: " << sendToSGCT(doc.toJson()) << " " << std::flush;
}
void MainWindow::readTcpData() {
QByteArray data = _sgctSocket->readAll();
std::cout << data.data() << std::flush;
}
void MainWindow::on__renderComboBox_currentIndexChanged(const QString &arg1){
QJsonObject json;
QJsonDocument doc;
if (arg1.compare(QString("VolumeRaycaster")) == 0) {
json["renderer"] = QString("volumeraycaster");
} else if (arg1.compare(QString("Flare")) == 0) {
json["renderer"] = QString("flare");
}
doc.setObject(json);
std::cout << "Bytes sent: " << sendToSGCT(doc.toJson()) << " " << std::flush;
}
qint64 MainWindow::sendToSGCT(QByteArray data) {
return _sgctSocket->write(data + "\r\n"); // "\r\n" seperates messages
}

33
gui/src/mainwindow.h Normal file
View File

@@ -0,0 +1,33 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTcpSocket>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on__connectButton_clicked();
void on__statsCheckBox_toggled(bool checked);
void readTcpData();
void on__graphCheckBox_toggled(bool checked);
void on__renderComboBox_currentIndexChanged(const QString &arg1);
private:
qint64 sendToSGCT(QByteArray data);
Ui::MainWindow *ui;
QTcpSocket* _sgctSocket;
};
#endif // MAINWINDOW_H

102
gui/src/mainwindow.ui Normal file
View File

@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>303</width>
<height>312</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout">
<item row="5" column="2">
<widget class="QCheckBox" name="_graphCheckBox">
<property name="text">
<string>Graph</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QComboBox" name="_renderComboBox">
<item>
<property name="text">
<string>VolumeRaycaster</string>
</property>
</item>
<item>
<property name="text">
<string>Flare</string>
</property>
</item>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="_connectButton">
<property name="text">
<string>Connect</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QCheckBox" name="_statsCheckBox">
<property name="text">
<string>Stats</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="_debugLabel">
<property name="text">
<string>Debug info</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="_renderLabel">
<property name="text">
<string>Renderer</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="_hostEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="_hostLabel">
<property name="text">
<string>Host</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>303</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

View File

@@ -29,7 +29,6 @@
#include <boost/property_tree/json_parser.hpp>
#include <boost/foreach.hpp>
#include <iterator>
#include <algorithm>
namespace openspace {
@@ -46,16 +45,8 @@ void Interface::callback(const char* receivedChars) {
_nodes = std::vector<Node>();
loadIntoNodes(pt);
handleNodes();
// for (int i = 0; i < _nodes.size(); ++i) {
// std::cout << _nodes.at(i)._key << " " << _nodes.at(i)._value;
// for (int j = 0; j < _nodes.at(i)._children.size(); ++j) {
// std::cout << _nodes.at(i)._children.at(j)._value << " ";
// }
// std::cout << std::endl;
// }
_nodes.clear();
handleNodes(); // Issue commands
_nodes.clear(); // Clean up after commands are issued
}
void Interface::handleNodes() {