use OutputDevice to set fileinfo,

use new connect function,
This commit is contained in:
Anakin 2017-01-29 15:19:20 +01:00
parent 98302664ca
commit 7b739ab892
6 changed files with 19 additions and 26 deletions

View File

@ -37,16 +37,11 @@ private:
public:
void drawGeometry(QOpenGLShaderProgram *program, bool wireframe);
// slots
public slots:
void loadFile(QString filePath);
// signals
signals:
void requestResetView();
void requestUpdate();
void sendFileInfo(QString name, QVector<Material>* materials, int vertices, int triangle);
};

View File

@ -58,7 +58,6 @@ private:
// functions
private:
void initShaders();
void setConnections();
void resetView();
void updateLightPosition();
@ -89,8 +88,5 @@ public slots:
void setAttFac(double value);
void setAmbCoef(double value);
// signals
signals:
void loadFile(QString);
};

View File

@ -1,6 +1,8 @@
#pragma once
#include <QObject>
struct Material;
class OutputDevice : public QObject
{
Q_OBJECT
@ -20,8 +22,11 @@ public:
};
void print(QString message, int severity) { emit sendMessage(message, severity); };
void setFileInfo(QString name, QVector<Material>* materials, int vertices, int triangle) {
emit sendFileInfo(name, materials, vertices, triangle);
};
signals:
void sendMessage(QString message, int severity);
void sendFileInfo(QString name, QVector<Material>* materials, int vertices, int triangle);
};

View File

@ -142,10 +142,6 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program, bool wireframe)
}
}
/////////////////////////////////////////////////////////////////////////
// slots
void GeometryEngine::loadFile(QString filePath)
{
// cleanup old stuff and recreate buffers
@ -215,7 +211,7 @@ void GeometryEngine::loadFile(QString filePath)
emit requestUpdate();
OutputDevice::getInstance()->print("done..", 0);
emit sendFileInfo(filePath.right(filePath.size() - filePath.lastIndexOf(QRegExp("/|\\\\")) - 1), m_materials, vertexData.size(), indexData.size() / 3);
OutputDevice::getInstance()->setFileInfo(filePath.right(filePath.size() - filePath.lastIndexOf(QRegExp("/|\\\\")) - 1), m_materials, vertexData.size(), indexData.size() / 3);
}
catch (std::invalid_argument e)
{

View File

@ -31,6 +31,7 @@ MainWindow::MainWindow(QWidget *parent)
setWindowIcon(QIcon(":/images/icon.ico"));
connect(OutputDevice::getInstance(this), &OutputDevice::sendMessage, this, &MainWindow::printMessage);
connect(OutputDevice::getInstance(this), &OutputDevice::sendFileInfo, this, &MainWindow::setFileInfo);
// setup opengl things
QSurfaceFormat format;

View File

@ -1,5 +1,6 @@
#include "..\Header\OglViewerWidget.h"
#include "..\Header\OutputDevice.h"
#include "..\Header\MainWindow.h"
#include <QMouseEvent>
#include <QDropEvent>
#include <QMimeData>
@ -17,6 +18,7 @@ OglViewerWidget::OglViewerWidget(QWidget *parent)
setFocus();
setAcceptDrops(true);
// settings window
m_settings = new SettingsWindow(m_backgroundColorOff.toVector3D() * 255, m_backgroundColorOn.toVector3D() * 255, m_light.intensities * 255, true, m_light.ambientCoefficient, m_light.attenuationFactor, 1, this);
connect(m_settings, &SettingsWindow::updateBGColorOff, this, &OglViewerWidget::setBGColorOff);
@ -60,15 +62,6 @@ void OglViewerWidget::initShaders()
close();
}
void OglViewerWidget::setConnections()
{
connect(m_dataEngine, &GeometryEngine::requestResetView, this, &OglViewerWidget::resetView);
connect(parentWidget(), SIGNAL(loadFile(QString)), m_dataEngine, SLOT(loadFile(QString)));
connect(this, SIGNAL(loadFile(QString)), m_dataEngine, SLOT(loadFile(QString)));
connect(m_dataEngine, SIGNAL(requestUpdate()), this, SLOT(update()));
connect(m_dataEngine, SIGNAL(sendFileInfo(QString, QVector<Material>*, int, int)), parentWidget(), SLOT(setFileInfo(QString, QVector<Material>*, int, int)));
}
void OglViewerWidget::resetView()
{
m_rotation = QQuaternion();
@ -107,7 +100,14 @@ void OglViewerWidget::initializeGL()
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
m_dataEngine = new GeometryEngine(this);
setConnections();
connect(m_dataEngine, &GeometryEngine::requestResetView, this, &OglViewerWidget::resetView);
connect(m_dataEngine, &GeometryEngine::requestUpdate, this, static_cast<void(OglViewerWidget::*)(void)>(&OglViewerWidget::update));
//TODO: better solution
MainWindow* parent = dynamic_cast<MainWindow*>(parentWidget());
if (parent != NULL)
connect(parent, &MainWindow::loadFile, [this](QString value) {m_dataEngine->loadFile(value); });
}
void OglViewerWidget::resizeGL(int w, int h)
@ -327,7 +327,7 @@ void OglViewerWidget::dragEnterEvent(QDragEnterEvent *e)
void OglViewerWidget::dropEvent(QDropEvent * e)
{
emit loadFile(e->mimeData()->urls().first().toLocalFile());
m_dataEngine->loadFile(e->mimeData()->urls().first().toLocalFile());
}