From 95e2cc4eeaba04fce928e4e7b19889f9a2a8732c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 17 Apr 2017 17:32:23 -0700 Subject: [PATCH] add BakeWidget, leverage for skybox widget cancellation --- tools/oven/src/ui/BakeWidget.cpp | 46 ++++++++++++++++++++++++++ tools/oven/src/ui/BakeWidget.h | 33 ++++++++++++++++++ tools/oven/src/ui/DomainBakeWidget.cpp | 26 +-------------- tools/oven/src/ui/DomainBakeWidget.h | 9 ++--- tools/oven/src/ui/ModelBakeWidget.cpp | 25 +------------- tools/oven/src/ui/ModelBakeWidget.h | 10 ++---- tools/oven/src/ui/SkyboxBakeWidget.cpp | 11 +----- tools/oven/src/ui/SkyboxBakeWidget.h | 9 ++--- 8 files changed, 90 insertions(+), 79 deletions(-) create mode 100644 tools/oven/src/ui/BakeWidget.cpp create mode 100644 tools/oven/src/ui/BakeWidget.h diff --git a/tools/oven/src/ui/BakeWidget.cpp b/tools/oven/src/ui/BakeWidget.cpp new file mode 100644 index 0000000000..23a4822d82 --- /dev/null +++ b/tools/oven/src/ui/BakeWidget.cpp @@ -0,0 +1,46 @@ +// +// BakeWidget.cpp +// tools/oven/src/ui +// +// Created by Stephen Birarda on 4/17/17. +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include + +#include "../Oven.h" +#include "OvenMainWindow.h" + +#include "BakeWidget.h" + +BakeWidget::BakeWidget(QWidget* parent, Qt::WindowFlags flags) : + QWidget(parent, flags) +{ + +} + +BakeWidget::~BakeWidget() { + // if we're going down, our bakers are about to too + // enumerate them, send a cancelled status to the results table, and remove them + auto it = _bakers.begin(); + while (it != _bakers.end()) { + auto resultRow = it->second; + auto resultsWindow = qApp->getMainWindow()->showResultsWindow(); + + resultsWindow->changeStatusForRow(resultRow, "Cancelled"); + + it = _bakers.erase(it); + } +} + +void BakeWidget::cancelButtonClicked() { + // the user wants to go back to the mode selection screen + // remove ourselves from the stacked widget and call delete later so we'll be cleaned up + auto stackedWidget = qobject_cast(parentWidget()); + stackedWidget->removeWidget(this); + + this->deleteLater(); +} diff --git a/tools/oven/src/ui/BakeWidget.h b/tools/oven/src/ui/BakeWidget.h new file mode 100644 index 0000000000..00996128ed --- /dev/null +++ b/tools/oven/src/ui/BakeWidget.h @@ -0,0 +1,33 @@ +// +// BakeWidget.h +// tools/oven/src/ui +// +// Created by Stephen Birarda on 4/17/17. +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_BakeWidget_h +#define hifi_BakeWidget_h + +#include + +#include + +class BakeWidget : public QWidget { + Q_OBJECT +public: + BakeWidget(QWidget* parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); + ~BakeWidget(); + + void cancelButtonClicked(); + +protected: + using BakerRowPair = std::pair, int>; + using BakerRowPairList = std::list; + BakerRowPairList _bakers; +}; + +#endif // hifi_BakeWidget_h diff --git a/tools/oven/src/ui/DomainBakeWidget.cpp b/tools/oven/src/ui/DomainBakeWidget.cpp index 382e99f14e..27364a54de 100644 --- a/tools/oven/src/ui/DomainBakeWidget.cpp +++ b/tools/oven/src/ui/DomainBakeWidget.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include @@ -32,7 +31,7 @@ static const QString BROWSE_START_DIR_SETTING_KEY = "domain_search_directory"; static const QString DESTINATION_PATH_SETTING_KEY = "destination_path"; DomainBakeWidget::DomainBakeWidget(QWidget* parent, Qt::WindowFlags flags) : - QWidget(parent, flags), + BakeWidget(parent, flags), _domainNameSetting(DOMAIN_NAME_SETTING_KEY), _exportDirectory(EXPORT_DIR_SETTING_KEY), _browseStartDirectory(BROWSE_START_DIR_SETTING_KEY), @@ -41,20 +40,6 @@ DomainBakeWidget::DomainBakeWidget(QWidget* parent, Qt::WindowFlags flags) : setupUI(); } -DomainBakeWidget::~DomainBakeWidget() { - // if we're going down, our bakers are about to too - // enumerate them, send a cancelled status to the results table, and remove them - auto it = _bakers.begin(); - while (it != _bakers.end()) { - auto resultRow = it->second; - auto resultsWindow = qApp->getMainWindow()->showResultsWindow(); - - resultsWindow->changeStatusForRow(resultRow, "Cancelled"); - - it = _bakers.erase(it); - } -} - void DomainBakeWidget::setupUI() { // setup a grid layout to hold everything QGridLayout* gridLayout = new QGridLayout; @@ -296,12 +281,3 @@ void DomainBakeWidget::handleFinishedBaker() { } } } - -void DomainBakeWidget::cancelButtonClicked() { - // the user wants to go back to the mode selection screen - // remove ourselves from the stacked widget and call delete later so we'll be cleaned up - auto stackedWidget = qobject_cast(parentWidget()); - stackedWidget->removeWidget(this); - - this->deleteLater(); -} diff --git a/tools/oven/src/ui/DomainBakeWidget.h b/tools/oven/src/ui/DomainBakeWidget.h index b37ed490bc..cd8c4a012e 100644 --- a/tools/oven/src/ui/DomainBakeWidget.h +++ b/tools/oven/src/ui/DomainBakeWidget.h @@ -17,21 +17,20 @@ #include #include "../DomainBaker.h" +#include "BakeWidget.h" class QLineEdit; -class DomainBakeWidget : public QWidget { +class DomainBakeWidget : public BakeWidget { Q_OBJECT public: DomainBakeWidget(QWidget* parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); - ~DomainBakeWidget(); private slots: void chooseFileButtonClicked(); void chooseOutputDirButtonClicked(); void bakeButtonClicked(); - void cancelButtonClicked(); void outputDirectoryChanged(const QString& newDirectory); @@ -41,10 +40,6 @@ private slots: private: void setupUI(); - using BakerRowPair = std::pair, int>; - using BakerRowPairList = std::list; - BakerRowPairList _bakers; - QLineEdit* _domainNameLineEdit; QLineEdit* _entitiesFileLineEdit; QLineEdit* _outputDirLineEdit; diff --git a/tools/oven/src/ui/ModelBakeWidget.cpp b/tools/oven/src/ui/ModelBakeWidget.cpp index 7b1adf05a7..77f92c82e1 100644 --- a/tools/oven/src/ui/ModelBakeWidget.cpp +++ b/tools/oven/src/ui/ModelBakeWidget.cpp @@ -29,27 +29,13 @@ static const auto EXPORT_DIR_SETTING_KEY = "model_export_directory"; static const auto MODEL_START_DIR_SETTING_KEY = "model_search_directory"; ModelBakeWidget::ModelBakeWidget(QWidget* parent, Qt::WindowFlags flags) : - QWidget(parent, flags), + BakeWidget(parent, flags), _exportDirectory(EXPORT_DIR_SETTING_KEY), _modelStartDirectory(MODEL_START_DIR_SETTING_KEY) { setupUI(); } -ModelBakeWidget::~ModelBakeWidget() { - // if we're about to go down, whatever bakers we're managing are about to as well - // enumerate them, send the results table a cancelled status, and clean them up - auto it = _bakers.begin(); - while (it != _bakers.end()) { - auto resultRow = it->second; - auto resultsWindow = qApp->getMainWindow()->showResultsWindow(); - - resultsWindow->changeStatusForRow(resultRow, "Cancelled"); - - it = _bakers.erase(it); - } -} - void ModelBakeWidget::setupUI() { // setup a grid layout to hold everything QGridLayout* gridLayout = new QGridLayout; @@ -236,12 +222,3 @@ void ModelBakeWidget::handleFinishedBaker() { } } } - -void ModelBakeWidget::cancelButtonClicked() { - // the user wants to go back to the mode selection screen - // remove ourselves from the stacked widget and call delete later so we'll be cleaned up - auto stackedWidget = qobject_cast(parentWidget()); - stackedWidget->removeWidget(this); - - this->deleteLater(); -} diff --git a/tools/oven/src/ui/ModelBakeWidget.h b/tools/oven/src/ui/ModelBakeWidget.h index 0711417d21..b42b8725f6 100644 --- a/tools/oven/src/ui/ModelBakeWidget.h +++ b/tools/oven/src/ui/ModelBakeWidget.h @@ -18,21 +18,21 @@ #include +#include "BakeWidget.h" + class QLineEdit; class QThread; -class ModelBakeWidget : public QWidget { +class ModelBakeWidget : public BakeWidget { Q_OBJECT public: ModelBakeWidget(QWidget* parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); - ~ModelBakeWidget(); private slots: void chooseFileButtonClicked(); void chooseOutputDirButtonClicked(); void bakeButtonClicked(); - void cancelButtonClicked(); void outputDirectoryChanged(const QString& newDirectory); @@ -41,10 +41,6 @@ private slots: private: void setupUI(); - using BakerRowPair = std::pair, int>; - using BakerRowPairList = std::list; - BakerRowPairList _bakers; - QLineEdit* _modelLineEdit; QLineEdit* _outputDirLineEdit; diff --git a/tools/oven/src/ui/SkyboxBakeWidget.cpp b/tools/oven/src/ui/SkyboxBakeWidget.cpp index 1a5a53de21..d6dbb98bb7 100644 --- a/tools/oven/src/ui/SkyboxBakeWidget.cpp +++ b/tools/oven/src/ui/SkyboxBakeWidget.cpp @@ -29,7 +29,7 @@ static const auto EXPORT_DIR_SETTING_KEY = "skybox_export_directory"; static const auto SELECTION_START_DIR_SETTING_KEY = "skybox_search_directory"; SkyboxBakeWidget::SkyboxBakeWidget(QWidget* parent, Qt::WindowFlags flags) : - QWidget(parent, flags), + BakeWidget(parent, flags), _exportDirectory(EXPORT_DIR_SETTING_KEY), _selectionStartDirectory(SELECTION_START_DIR_SETTING_KEY) { @@ -221,12 +221,3 @@ void SkyboxBakeWidget::handleFinishedBaker() { } } } - -void SkyboxBakeWidget::cancelButtonClicked() { - // the user wants to go back to the mode selection screen - // remove ourselves from the stacked widget and call delete later so we'll be cleaned up - auto stackedWidget = qobject_cast(parentWidget()); - stackedWidget->removeWidget(this); - - this->deleteLater(); -} diff --git a/tools/oven/src/ui/SkyboxBakeWidget.h b/tools/oven/src/ui/SkyboxBakeWidget.h index 3dfd2fa4f8..f00ab07f33 100644 --- a/tools/oven/src/ui/SkyboxBakeWidget.h +++ b/tools/oven/src/ui/SkyboxBakeWidget.h @@ -18,9 +18,11 @@ #include +#include "BakeWidget.h" + class QLineEdit; -class SkyboxBakeWidget : public QWidget { +class SkyboxBakeWidget : public BakeWidget { Q_OBJECT public: @@ -30,7 +32,6 @@ private slots: void chooseFileButtonClicked(); void chooseOutputDirButtonClicked(); void bakeButtonClicked(); - void cancelButtonClicked(); void outputDirectoryChanged(const QString& newDirectory); @@ -39,10 +40,6 @@ private slots: private: void setupUI(); - using BakerRowPair = std::pair, int>; - using BakerRowPairList = std::list; - BakerRowPairList _bakers; - QLineEdit* _selectionLineEdit; QLineEdit* _outputDirLineEdit;