diff --git a/src/app/qtkmainwindow.cpp b/src/app/qtkmainwindow.cpp index 945ff91..f05b54a 100644 --- a/src/app/qtkmainwindow.cpp +++ b/src/app/qtkmainwindow.cpp @@ -48,16 +48,6 @@ MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent) &Qtk::ToolBox::updateFocus); } - connect(ui_->actionDelete_Object, - &QAction::triggered, - this, - &MainWindow::deleteObject); - - connect(ui_->actionLoad_Model, - &QAction::triggered, - this, - &MainWindow::loadObject); - // TODO: Fix / use MainWindow in Qt Designer to add these dock widgets. // For now we will add them manually, but we should be able to do this in the // designer. At the moment if you edit the UI in designer the dock widget @@ -114,26 +104,6 @@ void MainWindow::refreshScene(const QString & sceneName) ui_->qtk__TreeView->updateView(getQtkWidget()->getScene()); } -void MainWindow::deleteObject() -{ - if (auto object = ui_->qtk__ToolBox->getObjectFocus(); object != Q_NULLPTR) { - auto scene = getQtkWidget()->getScene(); - switch (object->getType()) { - case Qtk::Object::Type::QTK_MESH: - scene->removeObject(dynamic_cast(object)); - ui_->qtk__ToolBox->clearFocus(); - break; - case Qtk::Object::Type::QTK_MODEL: - scene->removeObject(dynamic_cast(object)); - ui_->qtk__ToolBox->clearFocus(); - break; - default: - qDebug() << "Failed to delete model with invalid type"; - break; - } - } -} - void MainWindow::setScene(Qtk::Scene * scene) { connect(scene, diff --git a/src/app/qtkmainwindow.h b/src/app/qtkmainwindow.h index 4d41cc1..40c5df9 100644 --- a/src/app/qtkmainwindow.h +++ b/src/app/qtkmainwindow.h @@ -11,8 +11,8 @@ #include -#include #include +#include #include "designer-plugins/debugconsole.h" @@ -144,23 +144,6 @@ class MainWindow : public QMainWindow */ void refreshScene(const QString & sceneName); - - /** - * Opens a QFileDialog for selecting an object file to load into the scene. - */ - void loadObject() - { - const QUrl file = QFileDialog::getOpenFileName( - this, tr("Load Model"), QDir::homePath(), tr("Object Files (*.obj)")); - getQtkWidget()->getScene()->loadModel(file.fileName().replace(".obj", ""), - file.toString()); - } - - /** - * Deletes the currently selected object from the scene. - */ - void deleteObject(); - private: /*************************************************************************** * Private Members diff --git a/src/app/qtkmainwindow.ui b/src/app/qtkmainwindow.ui index 218d397..3078ef7 100644 --- a/src/app/qtkmainwindow.ui +++ b/src/app/qtkmainwindow.ui @@ -223,7 +223,7 @@ - true + false @@ -238,7 +238,7 @@ - true + false diff --git a/src/designer-plugins/toolbox.cpp b/src/designer-plugins/toolbox.cpp index 268e695..4d57129 100644 --- a/src/designer-plugins/toolbox.cpp +++ b/src/designer-plugins/toolbox.cpp @@ -20,7 +20,7 @@ ToolBox::ToolBox(QWidget * parent) : QDockWidget(parent), objectDetails_(this), transformPanel_(this), scalePanel_(this), vertex_(this, "Vertex Shader:"), fragment_(this, "Fragment Shader:"), properiesForm_(new QFormLayout), - shaderForm_(new QFormLayout), ui(new Ui::ToolBox), objectFocus_(Q_NULLPTR) + shaderForm_(new QFormLayout), ui(new Ui::ToolBox) { ui->setupUi(this); setMinimumWidth(350); @@ -44,24 +44,10 @@ void ToolBox::updateFocus(const QString & name) { auto object = QtkWidget::mWidgetManager.get_widget()->getScene()->getObject(name); - // If we can't find the object show a warning. - if (object == Q_NULLPTR) { - qDebug() << "Failed to find selected object: " << name - << "; Clearing object panels."; + if (object != Q_NULLPTR) { + refreshProperties(object); + refreshShaders(object); } - - // We should still pass the nullptr here if we failed to find the object - // above. - objectFocus_ = object; - refreshProperties(object); - refreshShaders(object); -} - -void ToolBox::clearFocus() -{ - objectFocus_ = Q_NULLPTR; - refreshProperties(objectFocus_); - refreshShaders(objectFocus_); } ToolBox::SpinBox3D::SpinBox3D(QWidget * parent, const char * l) : @@ -84,13 +70,6 @@ void ToolBox::SpinBox::disconnect() const void ToolBox::TransformPanel::setObject(const Qtk::Object * object) { - // Zero the panel contents if there is no object selected. - if (object == Q_NULLPTR) { - spinBox3D.clear(); - return; - } - - // Reconnect translation panel controls to the new object. const std::vector binds = {&Object::setTranslationX, &Object::setTranslationY, @@ -111,12 +90,6 @@ void ToolBox::TransformPanel::setObject(const Qtk::Object * object) void ToolBox::ScalePanel::setObject(const Qtk::Object * object) { - // Zero the panel contents if there is no object selected. - if (object == Q_NULLPTR) { - spinBox3D.clear(); - return; - } - // Reconnect scale panel controls to the new object. const std::vector binds = { &Object::setScaleX, &Object::setScaleY, &Object::setScaleZ}; @@ -150,21 +123,8 @@ void ToolBox::refreshProperties(const Object * object) void ToolBox::refreshShaders(const Object * object) { - // Zero the panel contents if there is no object selected. - if (object == Q_NULLPTR) { - vertex_.clear(); - fragment_.clear(); - return; - } - vertex_.path.setValue(object->getVertexShader().c_str()); vertex_.editor->setText(object->getVertexShaderSourceCode().c_str()); fragment_.path.setValue(object->getFragmentShader().c_str()); fragment_.editor->setText(object->getFragmentShaderSourceCode().c_str()); } - -void ToolBox::refresh(const Object * object) -{ - refreshProperties(object); - refreshShaders(object); -} diff --git a/src/designer-plugins/toolbox.h b/src/designer-plugins/toolbox.h index 9f2f621..6eb9769 100644 --- a/src/designer-plugins/toolbox.h +++ b/src/designer-plugins/toolbox.h @@ -18,8 +18,8 @@ #include #include -#include "qtk/object.h" +#include "qtk/scene.h" namespace Ui { @@ -45,13 +45,8 @@ namespace Qtk void refreshShaders(const Object * object); - void refresh(const Object * object); - void updateFocus(const QString & name); - [[nodiscard]] Object * getObjectFocus() const { return objectFocus_; } - - void clearFocus(); private: /************************************************************************* @@ -70,9 +65,9 @@ namespace Qtk { } - void setValue(const char * v) const { value->setText(tr(v)); } + void setValue(const char * v) { value->setText(tr(v)); } - void setItem(const char * l, const char * v) const + void setItem(const char * l, const char * v) { label->setText(tr(l)); value->setText(tr(v)); @@ -89,14 +84,8 @@ namespace Qtk } /// Refresh to display the new object's details - void setObject(const Qtk::Object * object) const + void setObject(const Qtk::Object * object) { - // Zero contents if there is no object selected. - if (object == Q_NULLPTR) { - name.setValue(""); - objectType.setValue("No object selected"); - return; - } name.setItem("Name:", object->getName().toStdString().c_str()); objectType.setItem( "Type:", @@ -130,15 +119,6 @@ namespace Qtk /// Assigning a QWidget to a QLayout also ensures Qt will clean up. explicit SpinBox3D(QWidget * parent, const char * l = "SpinBox3D:"); - /// Zero the SpinBox3D display. - void clear() - { - for (auto & field : fields) { - field->disconnect(); - field->spinBox->setValue(0.0); - } - } - /// The main layout for the SpinBox3D widget. QHBoxLayout * layout; @@ -196,13 +176,6 @@ namespace Qtk layout->addWidget(editor); } - /// Zero the ShaderView display. - void clear() const - { - path.setValue(""); - editor->setText(""); - } - /// The main layout for the ShaderView widget. QVBoxLayout * layout; @@ -217,8 +190,6 @@ namespace Qtk QFormLayout * properiesForm_; QFormLayout * shaderForm_; - Object * objectFocus_ {}; - Ui::ToolBox * ui; }; } // namespace Qtk diff --git a/src/qtk/scene.cpp b/src/qtk/scene.cpp index 45282b1..54fb66f 100644 --- a/src/qtk/scene.cpp +++ b/src/qtk/scene.cpp @@ -55,34 +55,6 @@ template <> Model * Scene::addObject(Model * object) return object; } -template <> void Scene::removeObject(MeshRenderer * object) -{ - auto it = std::find(mMeshes.begin(), mMeshes.end(), object); - if (it == mMeshes.end()) { - qDebug() << "[Scene::removeObject]: Failed to remove object: " - << object->getName() << " (" << object << ")"; - return; - } - - --mObjectCount[object->getName()]; - mMeshes.erase(it); - emit sceneUpdated(mSceneName); -} - -template <> void Scene::removeObject(Model * object) -{ - auto it = std::find(mModels.begin(), mModels.end(), object); - if (it == mModels.end()) { - qDebug() << "[Scene::removeObject]: Failed to remove object: " - << object->getName() << " (" << object << ")"; - return; - } - - --mObjectCount[object->getName()]; - mModels.erase(it); - emit sceneUpdated(mSceneName); -} - void Scene::draw() { if (!mInit) { diff --git a/src/qtk/scene.h b/src/qtk/scene.h index 67f14f7..a4f9180 100644 --- a/src/qtk/scene.h +++ b/src/qtk/scene.h @@ -85,16 +85,16 @@ namespace Qtk void loadModel(const QUrl & url) { - auto fileName = url.fileName().replace(".obj", ""); - auto filePath = url.toLocalFile(); + auto fileName = url.fileName().replace(".obj", "").toStdString(); + auto filePath = url.toLocalFile().toStdString(); loadModel(fileName, filePath); } - void loadModel(const QString & name, const QString & path) + void loadModel(const std::string & name, const std::string & path) { // Add the dropped model to the load queue. // This is consumed during rendering of the scene if not empty. - mModelLoadQueue.emplace(name.toStdString(), path.toStdString()); + mModelLoadQueue.emplace(name, path); } /************************************************************************* @@ -182,9 +182,8 @@ namespace Qtk /** * Adds objects to the scene. - * This template provides explicit specializations for the valid types: - * MeshRenderer, Model - * Any other object type will cause errors. + * This template provides explicit specializations for valid types. + * Adding any object other than these types will cause errors. * TODO: Refactor to use Object base class container for scene objects. * * If creating a new object type for a scene, it must inherit Qtk::Object @@ -195,17 +194,6 @@ namespace Qtk */ template T * addObject(T * object); - /** - * Removes an object from the scene. - * This template provides explicit specializations for the valid types: - * MeshRenderer, Model - * Any other object type will cause errors. - * TODO: Refactor to use Object base class container for scene objects. - * - * @param object Pointer to the object to remove from the scene. - */ - template void removeObject(T * object); - /** * @param name The name to use for this scene. */