From 67e84624ee36e9b95e1a104119ea2a522b654d34 Mon Sep 17 00:00:00 2001 From: Kevin Matz Date: Sun, 16 Apr 2023 11:51:11 -0400 Subject: [PATCH] move the universe data viewer to the platform library --- example/sACN Explorer/CMakeLists.txt | 3 - example/sACN Explorer/multiversewindow.cpp | 8 ++- example/sACN Explorer/multiversewindow.h | 4 +- example/sACN Explorer/universewindow.h | 35 ------------ platform/qt/sacn/CMakeLists.txt | 3 + .../qt/sacn}/universewindow.cpp | 41 ++++++++++---- platform/qt/sacn/universewindow.h | 55 +++++++++++++++++++ .../qt/sacn}/universewindow.ui | 0 8 files changed, 95 insertions(+), 54 deletions(-) delete mode 100644 example/sACN Explorer/universewindow.h rename {example/sACN Explorer => platform/qt/sacn}/universewindow.cpp (66%) create mode 100644 platform/qt/sacn/universewindow.h rename {example/sACN Explorer => platform/qt/sacn}/universewindow.ui (100%) diff --git a/example/sACN Explorer/CMakeLists.txt b/example/sACN Explorer/CMakeLists.txt index f6e6992..886cc97 100644 --- a/example/sACN Explorer/CMakeLists.txt +++ b/example/sACN Explorer/CMakeLists.txt @@ -22,9 +22,6 @@ target_sources(${PROJECT_NAME} multiversewindow.ui sacnexplorer.h sacnexplorer.cpp - universewindow.h - universewindow.cpp - universewindow.ui ) target_link_libraries(${PROJECT_NAME} diff --git a/example/sACN Explorer/multiversewindow.cpp b/example/sACN Explorer/multiversewindow.cpp index 6ecd6bb..ef822ac 100644 --- a/example/sACN Explorer/multiversewindow.cpp +++ b/example/sACN Explorer/multiversewindow.cpp @@ -281,12 +281,16 @@ void MultiverseWindow::openUniverseEditor(const QModelIndex &index) { auto univ = data.value(); foreach (const auto & inspector, mInspectors) - if (inspector->universe() == univ) + if (inspector->universe() == univ->get()) return inspector->show(); - auto view = new UniverseWindow(nullptr, univ); + auto view = new UniverseWindow(nullptr, univ->get()); mInspectors.insert(view); connect(view, &QObject::destroyed, this, [this, view](){mInspectors.remove(view);}); connect(univ, &QObject::destroyed, view, &QMainWindow::close); + view->setWindowTitle(QString("%1 '%2' : "+tr("Universe")+" %3").arg( + univ->isEditable() ? tr("Editing") : tr("Viewing"), + univ->sourceName(), + QString::number(univ->number()))); view->setAttribute(Qt::WA_DeleteOnClose, true); view->show(); return; diff --git a/example/sACN Explorer/multiversewindow.h b/example/sACN Explorer/multiversewindow.h index 3e63aa1..632f3a1 100644 --- a/example/sACN Explorer/multiversewindow.h +++ b/example/sACN Explorer/multiversewindow.h @@ -24,8 +24,8 @@ #pragma once #include "multiversemodel.h" -#include "qsacnnode.h" -#include "universewindow.h" +#include +#include #include #include diff --git a/example/sACN Explorer/universewindow.h b/example/sACN Explorer/universewindow.h deleted file mode 100644 index e8c8372..0000000 --- a/example/sACN Explorer/universewindow.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "qsacnuniverse.h" -#include -#include - - -QT_BEGIN_NAMESPACE -namespace Ui { - class UniverseWindow; -} -QT_END_NAMESPACE - -class UniverseWindow - : public QMainWindow -{ - Q_OBJECT -public: - explicit UniverseWindow(QWidget *parent = nullptr, - QSacnUniverse* universe = nullptr); - virtual ~UniverseWindow(); - - /** - * @brief universe - * @return - */ - QSacnUniverse * universe() { return mUniverse; } - -private: - Ui::UniverseWindow *ui; - QSpinBox *prioritySpinBox; - QSacnUniverse *mUniverse; - - void update_status_(); -}; diff --git a/platform/qt/sacn/CMakeLists.txt b/platform/qt/sacn/CMakeLists.txt index 5ff68d4..75a028f 100644 --- a/platform/qt/sacn/CMakeLists.txt +++ b/platform/qt/sacn/CMakeLists.txt @@ -12,6 +12,7 @@ target_sources(${PROJECT_NAME} qsacnuniverse.h universemodel.h universestatuswidget.h + universewindow.h PRIVATE multiverseitem.h multiverseitem.cpp @@ -21,6 +22,8 @@ target_sources(${PROJECT_NAME} qsacnuniverse.cpp universemodel.cpp universestatuswidget.cpp + universewindow.cpp + universewindow.ui ) target_link_libraries(${PROJECT_NAME} diff --git a/example/sACN Explorer/universewindow.cpp b/platform/qt/sacn/universewindow.cpp similarity index 66% rename from example/sACN Explorer/universewindow.cpp rename to platform/qt/sacn/universewindow.cpp index 5bc11ba..95c756e 100644 --- a/example/sACN Explorer/universewindow.cpp +++ b/platform/qt/sacn/universewindow.cpp @@ -1,3 +1,26 @@ +/* + universewindow.h + + Copyright (c) 2022 Kevin Matz (kevin.matz@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ #include "universewindow.h" #include "ui_universewindow.h" #include "universemodel.h" @@ -12,14 +35,14 @@ * @brief UniverseWindow::UniverseWindow * @param parent */ -UniverseWindow::UniverseWindow(QWidget *parent, QSacnUniverse *universe) +UniverseWindow::UniverseWindow(QWidget *parent, std::shared_ptr universe) : QMainWindow(parent) , ui(new Ui::UniverseWindow()) - , mUniverse(universe) + , universe_(universe) { ui->setupUi(this); - auto model = new UniverseModel(this, universe->get()); + auto model = new UniverseModel(this, universe); ui->tableView->setModel(model); // update the status bar whenever the universe refreshes @@ -77,7 +100,7 @@ UniverseWindow::UniverseWindow(QWidget *parent, QSacnUniverse *universe) }); // status indicator - auto indicator = new UniverseStatusWidget(this, mUniverse->get()); + auto indicator = new UniverseStatusWidget(this, universe_); ui->statusbar->addPermanentWidget(indicator); update_status_(); @@ -98,18 +121,12 @@ UniverseWindow::~UniverseWindow() */ void UniverseWindow::update_status_() { - // window title - this->setWindowTitle(QString("%1 '%2' : "+tr("Universe")+" %3").arg( - mUniverse->isEditable() ? tr("Editing") : tr("Viewing"), - mUniverse->sourceName(), - QString::number(mUniverse->number()))); - - if (!mUniverse->isEditable()) + if (!universe_->isEditable()) { // status bar ui->statusbar->clearMessage(); QString message = QString("%1 " + tr("Hz")).arg( - QString::number(mUniverse->rxRate())); + QString::number(universe_->rxRate())); ui->statusbar->showMessage(message, 2500); } } diff --git a/platform/qt/sacn/universewindow.h b/platform/qt/sacn/universewindow.h new file mode 100644 index 0000000..e4cf7fb --- /dev/null +++ b/platform/qt/sacn/universewindow.h @@ -0,0 +1,55 @@ +/* + universewindow.h + + Copyright (c) 2022 Kevin Matz (kevin.matz@gmail.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +#pragma once + +#include +#include + +QT_BEGIN_NAMESPACE +namespace Ui { + class UniverseWindow; +} +QT_END_NAMESPACE + +class UniverseWindow + : public QMainWindow +{ + Q_OBJECT +public: + explicit UniverseWindow(QWidget *parent = nullptr, + std::shared_ptr universe = nullptr); + virtual ~UniverseWindow(); + + /** + * @brief universe + * @return + */ + std::shared_ptr universe() { return universe_; } + +private: + Ui::UniverseWindow *ui; + std::shared_ptr universe_; + + void update_status_(); +}; diff --git a/example/sACN Explorer/universewindow.ui b/platform/qt/sacn/universewindow.ui similarity index 100% rename from example/sACN Explorer/universewindow.ui rename to platform/qt/sacn/universewindow.ui