1、美化:轮播看板+3d模型看板;

2、优化3d模型看板:使用时加载3D模型,避免内存泄漏,使用QStackedWidget进行切换;
This commit is contained in:
tangchao0503
2026-01-20 13:43:22 +08:00
parent 30306e9396
commit 30e63899a8
8 changed files with 260 additions and 61 deletions

1
.gitignore vendored
View File

@ -6,6 +6,7 @@ gdal202.dll
HPPA类图.drawio
HPPA - 副本.ui
icon
ignore_*
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

View File

@ -17,35 +17,56 @@ MyCarousel::MyCarousel(QWidget* parent)
{
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(m_stackedWidget);
layout->setContentsMargins(0, 0, 0, 0);
m_autoPlayerTimer = new QTimer(this);
connect(m_autoPlayerTimer, &QTimer::timeout,
this, &MyCarousel::slideRight);
m_nomalQSS= R"(
QPushButton {
background-color: white;
QPushButton
{
background-color: #FFFFFF;
border-radius: 5px;
border: 1px solid white;
border: 1px solid #FFFFFF;
}
QPushButton:hover {
background-color: yellow;
}
QPushButton:checked {
background-color: blue;
QPushButton:checked
{
background-color: #08F8E8;
border-radius: 5px;
border: 1px solid blue;
border: 1px solid #08F8E8;
}
)";
m_lockedQSS = R"(
QPushButton {
QPushButton:hover
{
background-color: red;
border-radius: 5px;
border: 1px solid red;
}
QPushButton:hover {
background-color: yellow;
/*QPushButton:!checked {
background-color: #FFFFFF;
border-radius: 5px;
border: 1px solid #FFFFFF;
}*/
)";
m_lockedQSS = R"(
QPushButton
{
background-color: #FFFFFF;
border-radius: 5px;
border: 1px solid #FFFFFF;
}
QPushButton:checked
{
background-color: #08F8E8;
border-radius: 5px;
border: 1px solid #08F8E8;
}
QPushButton:hover
{
background-color: red;
border-radius: 5px;
border: 1px solid red;
}
)";
}

View File

@ -122,9 +122,6 @@ HPPA::HPPA(QWidget* parent)
border-bottom-right-radius: 10px;
)";
ui.mDockWidgetSimulator->setTile(QString::fromLocal8Bit("3Dģ<EFBFBD><EFBFBD>"));
ui.mDockWidgetSpectrometer->setTile(QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
//TOC
CustomDockWidgetBase* dock_layers = new CustomDockWidgetBase(QString::fromLocal8Bit("layers"), this);
@ -293,12 +290,39 @@ HPPA::HPPA(QWidget* parent)
mPanelMenu->addAction(m_dock_carousel->toggleViewAction());
//addDockWidget(Qt::LeftDockWidgetArea, m_dock_carousel);
QWidget* carouselContainer = new QWidget();
carouselContainer->setObjectName("carouselContainer");
carouselContainer->setStyleSheet(R"(
QWidget #carouselContainer
{
background-color: #0D1233;
border-top: 1px solid #2c586b;
border-left: 1px solid #2c586b;
border-right: 1px solid #2c586b;
border-bottom: 1px solid #2c586b;
border-top-left-radius: 0px;
border-top-right-radius: 0px;
border-bottom-left-radius: 0px;
border-bottom-right-radius: 0px;
}
)");
QGridLayout* gridLayout_carouselContainer = new QGridLayout(carouselContainer);
gridLayout_carouselContainer->setSpacing(0);
gridLayout_carouselContainer->setObjectName(QString::fromUtf8("gridLayout_carouselContainer"));
gridLayout_carouselContainer->setVerticalSpacing(0);
gridLayout_carouselContainer->setContentsMargins(2, 2, 2, 2);
m_carousel = new MyCarousel();
m_carousel->setObjectName(QString::fromUtf8("carousel"));
QScrollArea* sa = new QScrollArea();
sa->setObjectName("sa");
sa->setStyleSheet(R"(
border: none;
border: none;
background-color: #0D1233;
)");
QGridLayout* gridLayout_sa = new QGridLayout(sa);
gridLayout_sa->setSpacing(6);
@ -307,33 +331,72 @@ HPPA::HPPA(QWidget* parent)
gridLayout_sa->setContentsMargins(0, 0, 0, 0);
m_cam_label = new QLabel();
m_cam_label->setAlignment(Qt::AlignHCenter);
m_cam_label->setStyleSheet(R"(
background-color: #0D1233;
)");
gridLayout_sa->addWidget(m_cam_label);
m_carousel->addWidget(sa);
m_carousel->addWidget(new QLabel("1"));
//m_carousel->addWidget(new QLabel("2"));
//m_carousel->addWidget(new QLabel("3"));
//m_carousel->addWidget(new QLabel("4"));
//m_carousel->addWidget(new QLabel("5"));
//m_carousel->addWidget(new QLabel("6"));
//m_carousel->addWidget(new QLabel("7"));
//m_carousel->addWidget(new QLabel("8"));
//m_carousel->addWidget(new QLabel("9"));
//m_carousel->addWidget(new QLabel("10"));
//m_carousel->addWidget(new QLabel("11"));
//m_carousel->addWidget(new QLabel("12"));
//m_carousel->addWidget(new QLabel("13"));
//m_carousel->addWidget(new QLabel("14"));
//m_carousel->addWidget(new QLabel("15"));
//m_carousel->addWidget(new QLabel("16"));
m_carousel->setContentsMargins(0, 0, 0, 0);
QWidget* tmp8 = new QWidget();
tmp8->setStyleSheet(R"(
background-color: #0D1233;
)");
m_carousel->addWidget(tmp8);
//m_carousel->setContentsMargins(0, 0, 0, 0);
m_carousel->play();
m_dock_carousel->setWidget(m_carousel);
gridLayout_carouselContainer->addWidget(m_carousel);
m_dock_carousel->setWidget(carouselContainer);
//<2F><><EFBFBD>ƿ<EFBFBD><C6BF><EFBFBD>
ui.mDockWidgetSpectrometer->setTile(QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
//ui.mDockWidgetSpectrometer->show();
initControlTabwidget();
m_tabManager = new TabManager(ui.controlTabWidget, this);
//3Dģ<44>Ϳ<EFBFBD><CDBF><EFBFBD>
ui.mDockWidgetSimulator->setTile(QString::fromLocal8Bit("3Dģ<EFBFBD><EFBFBD>"));
//ui.mDockWidgetSimulator->show();
m_view3DModelManager = new View3DModelManager(this);
QWidget* modelWidgetContainer = new QWidget();
modelWidgetContainer->setObjectName("modelWidgetContainer");
modelWidgetContainer->setStyleSheet(R"(
QWidget #modelWidgetContainer
{
background-color: #0E1C4C;
border-top: 1px solid #2c586b;
border-left: 1px solid #2c586b;
border-right: 1px solid #2c586b;
border-bottom: 1px solid #2c586b;
border-top-left-radius: 0px;
border-top-right-radius: 0px;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
)");
QGridLayout* gridLayout_modelWidgetContainer = new QGridLayout(modelWidgetContainer);
gridLayout_modelWidgetContainer->setSpacing(0);
gridLayout_modelWidgetContainer->setObjectName(QString::fromUtf8("gridLayout_modelWidgetContainer"));
gridLayout_modelWidgetContainer->setVerticalSpacing(0);
gridLayout_modelWidgetContainer->setContentsMargins(2, 2, 2, 2);
gridLayout_modelWidgetContainer->addWidget(m_view3DModelManager);
connect(m_view3DModelManager, SIGNAL(created3DModelPlantPhenotype()), this, SLOT(onCreated3DModelPlantPhenotype()));
connect(m_view3DModelManager, SIGNAL(created3DModelOneMotor()), this, SLOT(onCreated3DModelOneMotor()));
ui.mDockWidgetSimulator->setWidget(modelWidgetContainer);
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ű<EFBFBD>
splitDockWidget(dock_layers, dock_hyperimgViewer, Qt::Horizontal);
splitDockWidget(dock_hyperimgViewer, m_dock_carousel, Qt::Horizontal);
@ -344,10 +407,7 @@ HPPA::HPPA(QWidget* parent)
//ui.mDockWidgetRGBCamera->setMaximumHeight(498);
splitDockWidget(dock_layers, ui.mDockWidgetSimulator, Qt::Vertical);
ui.mDockWidgetSimulator->show();
splitDockWidget(m_dock_carousel, ui.mDockWidgetSpectrometer, Qt::Vertical);
ui.mDockWidgetSpectrometer->show();
setStyleSheet(R"(
QMainWindow::separator{
@ -739,6 +799,11 @@ void HPPA::selectScenario(QAction* selectedAction)
settings.sync();
}
void HPPA::onCreated3DModelOneMotor()
{
connect(m_omc, SIGNAL(broadcastLocationSignal(std::vector<double>)), m_view3DModelManager->m_viewMotor, SLOT(setLoc(std::vector<double>)));
}
void HPPA::createOneMotorScenario()
{
//if (ui.mActionOneMotorScenario->isChecked())
@ -763,20 +828,19 @@ void HPPA::createOneMotorScenario()
m_tabManager->showTab(m_omc);
//<2F>򿪶<EFBFBD>Ӧ<EFBFBD><D3A6>3Dģ<44><C4A3>
QString basePath = QCoreApplication::applicationDirPath();
QString model1 = basePath + "/3DModel/linear_stage_indoor1.obj";
QString model2 = basePath + "/3DModel/linear_stage_indoor2.obj";
m_view3DLinearStage = new View3DLinearStage(model1, model2);
m_view3DLinearStage->setViewCenter(500, 100, 500);
m_view3DLinearStage->setDistance(1000);
ui.mDockWidgetSimulator->setWidget(m_view3DLinearStage);
connect(m_omc, SIGNAL(broadcastLocationSignal(std::vector<double>)), m_view3DLinearStage, SLOT(setLoc(std::vector<double>)));
m_view3DModelManager->switchScenario(View3DModelManager::ScenarioType::OneMotor);
//<2F><><EFBFBD>Ͻ<EFBFBD><CFBD>ֲ<EFBFBD>
}
void HPPA::onCreated3DModelPlantPhenotype()
{
connect(m_tmc, SIGNAL(broadcastLocationSignal(std::vector<double>)), m_view3DModelManager->m_viewPlant, SLOT(setLoc(std::vector<double>)));
}
void HPPA::createPlantPhenotypeScenario()
{
//if (ui.mActionPlantPhenotypeScenario->isChecked())
@ -794,15 +858,9 @@ void HPPA::createPlantPhenotypeScenario()
m_tabManager->showTab(m_pc);
m_tabManager->showTab(m_tmc);
//<2F>򿪶<EFBFBD>Ӧ<EFBFBD><D3A6>3Dģ<44><C4A3>
QString basePath = QCoreApplication::applicationDirPath();
QString model1 = basePath + "/3DModel/HPPA_frame.obj";
QString model2 = basePath + "/3DModel/HPPA_camera.obj";
m_view3DPlantPhenotype = new View3DPlantPhenotype(model1, model2);
m_view3DPlantPhenotype->setViewCenter(1000, 1000, -1000);
m_view3DPlantPhenotype->setDistance(5000);
ui.mDockWidgetSimulator->setWidget(m_view3DPlantPhenotype);
connect(m_tmc, SIGNAL(broadcastLocationSignal(std::vector<double>)), m_view3DPlantPhenotype, SLOT(setLoc(std::vector<double>)));
m_view3DModelManager->switchScenario(View3DModelManager::ScenarioType::PlantPhenotype);
//<2F><><EFBFBD>Ͻ<EFBFBD><CFBD>ֲ<EFBFBD>

View File

@ -49,6 +49,8 @@
#include "View3D.h"
#include "TabManager.h"
#include "View3DModelManager.h"
#define PI 3.1415926
QT_CHARTS_USE_NAMESPACE//QChartView ʹ<><CAB9> <20><>Ҫ<EFBFBD>Ӻ꣬ <20><><EFBFBD><EFBFBD><EFBFBD>޷<EFBFBD>ʹ<EFBFBD><CAB9>
@ -239,9 +241,6 @@ private:
QPushButton* m_open_rgb_camera_btn;
QPushButton* m_close_rgb_camera_btn;
View3DPlantPhenotype* m_view3DPlantPhenotype;
View3DLinearStage* m_view3DLinearStage;
TabManager* m_tabManager;
adjustTable* m_adt;
@ -250,6 +249,8 @@ private:
OneMotorControl* m_omc;
TwoMotorControl* m_tmc;
View3DModelManager* m_view3DModelManager;
public Q_SLOTS:
void onPlotHyperspectralImageRgbImage(int fileNumber, int frameNumber);
@ -303,6 +304,8 @@ public Q_SLOTS:
void createOneMotorScenario();
void createPlantPhenotypeScenario();
void onCreated3DModelPlantPhenotype();
void onCreated3DModelOneMotor();
signals:
void StartFocusSignal();
void StartRecordSignal();

View File

@ -131,6 +131,7 @@
<ClCompile Include="TwoMotorControl.cpp" />
<ClCompile Include="utility_tc.cpp" />
<ClCompile Include="View3D.cpp" />
<ClCompile Include="View3DModelManager.cpp" />
<QtRcc Include="HPPA.qrc" />
<QtUic Include="about.ui" />
<QtUic Include="adjustTable.ui" />
@ -165,6 +166,7 @@
<QtMoc Include="image2display.h" />
</ItemGroup>
<ItemGroup>
<QtMoc Include="View3DModelManager.h" />
<QtMoc Include="View3D.h" />
<QtMoc Include="adjustTable.h" />
<QtMoc Include="PowerControl.h" />

View File

@ -145,6 +145,9 @@
<ClCompile Include="TabManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="View3DModelManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<QtMoc Include="fileOperation.h">
@ -216,6 +219,9 @@
<QtMoc Include="TabManager.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="View3DModelManager.h">
<Filter>Header Files</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
<ClInclude Include="imageProcessor.h">

View File

@ -0,0 +1,68 @@
#include "View3DModelManager.h"
View3DModelManager::View3DModelManager(QWidget* parent)
: QWidget(parent)
{
m_stackedWidget = new QStackedWidget();
m_stackedWidget->setContentsMargins(0, 0, 0, 0);
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(m_stackedWidget);
layout->setContentsMargins(0, 0, 0, 0);
}
void View3DModelManager::switchScenario(ScenarioType type)
{
if (type == ScenarioType::PlantPhenotype) {
ensurePlantPhenotypeView();
m_stackedWidget->setCurrentWidget(m_viewPlant);
}
else {
ensureOneMotorView();
m_stackedWidget->setCurrentWidget(m_viewMotor);
}
emit scenarioChanged(type);
}
void View3DModelManager::ensurePlantPhenotypeView()
{
if (m_viewPlant)
return;
QString basePath = QCoreApplication::applicationDirPath();
m_viewPlant = new View3DPlantPhenotype(
basePath + "/3DModel/HPPA_frame.obj",
basePath + "/3DModel/HPPA_camera.obj",
m_stackedWidget
);
m_viewPlant->setViewCenter(1000, 1000, -1000);
m_viewPlant->setDistance(5000);
m_stackedWidget->addWidget(m_viewPlant);
emit created3DModelPlantPhenotype();
}
void View3DModelManager::ensureOneMotorView()
{
if (m_viewMotor)
return;
QString basePath = QCoreApplication::applicationDirPath();
m_viewMotor = new View3DLinearStage(
basePath + "/3DModel/linear_stage_indoor1.obj",
basePath + "/3DModel/linear_stage_indoor2.obj",
m_stackedWidget
);
m_viewMotor->setViewCenter(500, 100, 500);
m_viewMotor->setDistance(1000);
m_stackedWidget->addWidget(m_viewMotor);
emit created3DModelOneMotor();
}

40
HPPA/View3DModelManager.h Normal file
View File

@ -0,0 +1,40 @@
#pragma once
#include <QObject>
#include <QStackedWidget>
#include <QCoreApplication>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include "View3D.h"
class View3DPlantPhenotype;
class View3DLinearStage;
class View3DModelManager : public QWidget
{
Q_OBJECT
public:
enum class ScenarioType {
PlantPhenotype,
OneMotor
};
explicit View3DModelManager(QWidget* parent = nullptr);
void switchScenario(ScenarioType type);
View3DPlantPhenotype* m_viewPlant = nullptr;
View3DLinearStage* m_viewMotor = nullptr;
signals:
void scenarioChanged(ScenarioType type);
void created3DModelPlantPhenotype();
void created3DModelOneMotor();
private:
void ensurePlantPhenotypeView();
void ensureOneMotorView();
private:
QStackedWidget* m_stackedWidget = nullptr;
};