Qt下面窗口嵌套,嵌套窗口中包含:QGraphicsView、QGraphicsScene、QGraphicsIte

Qt系列文章目录

文章目录

  • Qt系列文章目录
  • 前言
  • 一、嵌套窗口
  • 二、注意事项

前言

我们有一个主窗口mainwindow,需要向其中放入新的界面,你可以自己定义里面内容。
Qt的嵌套布局由QDockWidget完成,用Qt Creator拖界面得到的dock布置形式比较固定,不能得想要的任意组合形式,要得到如下图所示的效果,后续布局必须通过代码来完成。dock属性随便设置,保证都任意区域可以停靠即可
由于这里不需要MainWindow的中间窗口,整个视图都由dock组成,因此先把QMainWindow的中间窗口部件去除:
在MainWindow的构造函数加入如下语句,即可把MainWindow的中间窗口去除,这时整个MainWindow只有Dock组成。其中使用了分割窗口QSplitter类。一个QSplitter是一个可以包含其他控件的控件,这些控件被一个分隔条隔开,托拽这个分隔条,可以改变splitter的子控件的大小。

QSplitter控件经常做为布局管理器使用,给用户提供更多的界面控制。

在这里插入图片描述

一、嵌套窗口

嵌套窗口最重要的就是构造窗口时,传入的父窗口之间关系,一般第一个参数就是此窗口的父类
层级关系如下:
首先是:1、class MainFramework : public QMainWindow 这时主框架窗口(标注:一)
2、左侧是QDockWidget,垂直分割成3份(标注:二)
3、中间是QDockWidget,主视口,里面包含GraphicsView、GraphicsScene、GraphicsItem(标注:三)
4、右侧也是QDockWidget,副视口,里面包含GraphicsView、GraphicsScene、GraphicsItem(标注:四)
5、右侧也是QDockWidget,(标注:五)

#ifndef FLYPROPERTYWIN_H
#define FLYPROPERTYWIN_H

#include <QWidget>
#include <QStandardPaths>
#include <QDir>
#include <QDebug>
#include "opencv2/opencv.hpp"
#include "GraphicsItem.h"
#include "GraphicsView.h"
#include "GraphicsScene.h"

using namespace cv;

#pragma execution_character_set("utf-8")

namespace Ui {
class FlyPropertyWin;
}

class FlyPropertyWin : public QWidget
{
    Q_OBJECT

public:
    explicit FlyPropertyWin(QWidget *parent = nullptr);
    ~FlyPropertyWin();
private:
    GraphicsScene* m_sceneCheck;
    GraphicsView*  m_viewCheck;
    GraphicsItem*  m_itemCheck;

    QVector<GraphicsItem*> m_itemsCheck4;
    QVector<GraphicsItem*> m_itemsCheck2;
    QVector<GraphicsItem*> m_itemsCheck5;

    QMap<QString, GraphicsItem*> m_imageItemCheckMap;
    QVBoxLayout*   m_layoutCheck;
    QSet<QString> m_totalImageNameCheckSet;

    QString m_watchPath;
    QString m_checkedPath;

private:
    void initWidget();
    void pictureSortCheck4(QVector<QString> &filesVec);
    void pictureSortCheck2();
    void pictureSortCheck5(QVector<QString> &filesVec);

    void pictureCheckRight(QVector<QString> &filesVec);
    void pictureCheckLeft(QVector<QString> &filesVec);
    void createCheckDir(const QString& checkDir);
private:
    Ui::FlyPropertyWin *ui;

public Q_SLOTS:
    void setImagePositionCheck(QVector<QString> &filesVec, QString &path, int groupType);

};

#endif // FLYPROPERTYWIN_H

二、注意事项

我们在新建窗口时如果默认不使用ui文件,我们需要手动使用布局器

FlyPropertyWin::FlyPropertyWin(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FlyPropertyWin)
{
//    ui->setupUi(this);
    initWidget();

    m_sceneCheck = new GraphicsScene(this);
    m_viewCheck = new GraphicsView;

    // 设置水平滚动条策略
    m_viewCheck->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    // 设置垂直滚动条策略
    m_viewCheck->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    //确保在内容改变时,视口始终更新整个区域,而不是仅更新已更改的部分
    m_viewCheck->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    //确保在视口大小改变时,视图中心始终保持在场景中心
    m_viewCheck->setResizeAnchor(QGraphicsView::AnchorViewCenter);

    m_viewCheck->setRenderHint(QPainter::Antialiasing);
    m_layoutCheck = new QVBoxLayout(this);
    m_layoutCheck->addWidget(m_viewCheck);
    setLayout(m_layoutCheck);

    int winWidth = 2048;  //1442  2048
    int winHeight = 1050;   //710 1050
    //    setFixedSize(winWidth, winHeight);
    resize(winWidth, winHeight);
}

这里面的代码

 ui->setupUi(this);

这行代码必须注释掉,否则窗口中包含的GraphicsView、GraphicsScene、GraphicsItem将会重新弹出窗口,而不能嵌入到三和四的窗口上

#ifndef MAINFRAMEWORK_H
#define MAINFRAMEWORK_H

#include <QMainWindow>

#include <QDockWidget>
#include <QTextEdit>
#include <QPushButton>
#include <QKeyEvent>
#include <QFileDialog>
#include <QVector>

#include "FlyPropertyWin.h"
#include "ProjectWin.h"
#include "MsgBox.h"
#include "ImageManager.h"
#include "FileMonitorMgr.h"
#include "ImageNorth.h"

#pragma execution_character_set("utf-8")

QT_BEGIN_NAMESPACE
namespace Ui { class MainFramework; }
QT_END_NAMESPACE

class MainFramework : public QMainWindow
{
    Q_OBJECT

public:
    MainFramework(QWidget *parent = nullptr);
    ~MainFramework();

Q_SIGNALS:
    void sigInitPicTree(QVector<QString> fileLst, QString filePath);
    void sigInitParaFileList(const QVector<QString>& fileLst, QString filePath);
    void sigInitNavi(const QString& file);
    void sigInitImgPos(QVector<QString> &fileLst, QString &filePath, int grouptype);
    void sigInitImgNorthPos(QVector<QString> &fileLst, QString &filePath, int grouptype);  //转正北
    void sigInitImgCheckPos(QVector<QString> &fileLst, QString &filePath, int grouptype);  //彩C校正
    void sigClearImage(bool flag);
    void sigClearImageNorth(bool flag);
private slots:
    void addLog(const QString&);

    //标题栏槽函数
    void s_showToolBar();
    void s_showPorjectWin();
    void s_showPropertyWin();
    void s_showLogWin();

    void s_close();
    void s_min();

    void s_hideProj();
    void s_propertyWinHide(bool);
    void s_logWinHide(bool);
    void s_timeout();

    void s_newProject();
    void s_saveFile();
    void s_runAc();
    void s_cesiumAc();
    void s_debugAc();
    void s_anaysisAc();
    void s_recordAc();
    void s_grabAc();
    void s_capacityAc();
    void s_paramterAc();
    void s_publishAc();
    void s_exportAc();

    void s_MonitorFolder();  //监控文件夹
    void s_toNorth();//转正北
    void s_toCheck();//彩C矫正

    void s_selectedPicCesium(const QString& pic);

private:
    void initTitleBar();
    void initLogView();
    void initWorkSpaceView();
    void initPropertyView();
    void initProjectView();
    void initToolBar();
    void dockLayout();
    void initMaxMinWin();

    void showMessageBox(const QString&);

    void readCaiCFile(const QString &folderPath);
    void readCaiCParaFile(const QString &folderPath);
    void groupStrips();
    bool sortStrips(const QString &a, const QString &b);
    QString separateFiles(const QString &files);

    void cesiumPicPath(const QString& picName);

private:
    Ui::MainFramework *ui;

    //标题栏
        QAction* m_toolBarAc = NULL;
        QAction* m_projectAc = NULL;
        QAction* m_logAc = NULL;
        QAction* m_propertyAc = NULL;

        //工具栏
        QAction* m_newAc = NULL;
        QAction* m_saveAc = NULL;
        QAction* m_runAc = NULL;
        QAction* m_stopAc = NULL;
        QAction* m_debugAc = NULL;
        QAction* m_anaysisAc = NULL;
        QAction* m_recordAc = NULL;
        QAction* m_grabAc = NULL;
        QAction* m_capacityAc = NULL;
        QAction* m_paramterAc = NULL;
        QAction* m_publishAc = NULL;
        QAction* m_exportAc = NULL;

        QDockWidget* m_logView = NULL;
        QDockWidget* m_flyPropertyView = NULL;
        QDockWidget* m_projManagerView = NULL;

        QSplitter* m_splitter;

        QTextEdit* m_logBody = NULL;
        QWidget* m_maxminWin = NULL;
        QWidget* m_workspace = NULL;
//        ProjectWin* m_projectWin = NULL;
        FlyPropertyWin* m_flyPropertyWin = NULL;
        MsgBox* m_msgBox = NULL;

        QPushButton* m_minBtn = NULL;
        QPushButton* m_closeBtn = NULL;


        QString m_strMonitorDirectory;
        QString m_currSelectedPic;

        QVector<QString> m_colorCfiles04;
        QVector<QString> m_colorCfiles02;
        QVector<QString> m_colorCfiles03;
        QVector<QString> m_colorCfiles05;
        QVector<QString> m_colorCAllFiles;
        QVector<QString> m_colorCParaFiles;
        QVector<QString> m_colorCAllFilesWithPath;
        ImageManager* m_imgMgr;
        ImageNorth*   m_imgNorth;

        FileMonitorMgr* m_fileMonitor;

};
#endif // MAINFRAMEWORK_H

#include "MainFramework.h"
#include "ui_MainFramework.h"
#include "ProjectWin.h"
#include "FlyPropertyWin.h"
#include "ImageManager.h"

#include <QDesktopWidget>
#include <QDebug>
#include <QStandardPaths>
#include <QTimer>
#include <QHBoxLayout>
#include <QSpacerItem>


#pragma execution_character_set("utf-8")

Q_DECLARE_METATYPE(QDockWidget::DockWidgetFeatures)



QString MenuBarStyle =
        "QMenuBar{background-color:#FFFFFF; font:14px; color:#232323;}"
        "QMenuBar::item{\
        min-height:40px; \
margin:1 10 0 10px; \
padding:10 10 10 10px; /* 条目内边框 */ \
background:#FFFFFF; /* 背景颜色 */ \
border-radius:4px; /* 倒角 */ \
}"
"QMenuBar::item:selected{background: #E5E5E5; }"
;

QString MenuStyle =
        "QMenu{/*整个背景*/}"
        "QMenu::item{ \
        font-size: 14px; \
color: rgb(225,225,225);  /*字体颜色*/\
border: 3px solid rgb(60,60,60);    /*item选框*/\
background-color:rgb(89,87,87); \
padding:16px 16px; /*设置菜单项文字上下和左右的内边距,效果就是菜单中的条目左右上下有了间隔*/\
margin:0px 2px;/*设置菜单项的外边距*/\
}"
"QMenu::item:selected{background-color:#1E1E1E;/*选中的样式*/}"
"QMenu::item:pressed{/*菜单项按下效果*/  border: 1px solid rgb(60,60,61); background-color: rgb(220,80,6);}"
;

QString tabBarStyle =
        "QTabBar::tab{min-height: 28px;  min-width:80px ;  font:14px; }"
        "QTabBar::tab:!selected{}"
        "QTabBar::tab:!selected:hover{ background-color: #d9fffe; color: black;}"
        "QToolBar{background-color:#e5e5e5; margin:3px;}"
        "QToolBar::separator{height:1px; background-color:#000000;}"
        "QToolBar QToolButton{min-width:60px; min-height:40px; background-color:transparent;}"
        "QToolBar QToolButton:hover{background-color:rgba(255,255,255,0.8);}"
        "QToolBar QToolButton:pressed{background-color:rgba(255,255,255,0.5);}"
        ;


MainFramework::MainFramework(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainFramework)
{
    qRegisterMetaType<QDockWidget::DockWidgetFeatures>();

    ui->setupUi(this);

    this->setWindowTitle(u8"图像处理系统");
    this->setWindowIcon(QIcon(":/images/logo.png"));
    this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
    this->setStyleSheet(tabBarStyle);
    //this->setStyleSheet("QMainWindow::separator {width: 2px;height: 2px;margin: 2px;padding: 2,2px;}");

    //On the top menu bar add toolbar,menubar and dockwidget.
    initTitleBar();
    initToolBar();
    initLogView();
    initProjectView();      //项目区初始化在前。
    initWorkSpaceView();	//工作区初始化在后。
    initPropertyView();
    dockLayout();

    // 创建 QSplitter 控件
    m_splitter = new QSplitter(Qt::Horizontal, this);
    // 将 m_projManagerView 和 m_propertyView 添加到 QSplitter
    m_splitter->addWidget(m_workspace);
    m_splitter->addWidget(m_flyPropertyView);

    // 设置 QSplitter 为中心部件
    this->setCentralWidget(m_splitter);

    this->setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North);
    //This property holds the tab shape used for tabbed dock widgets.
    this->setTabShape(QTabWidget::Triangular);
    this->statusBar()->showMessage(tr("Status Bar"));

    addLog(u8"启动完成,欢迎进入主框架!");

    m_imgMgr = new ImageManager(m_workspace);
    m_imgNorth = new ImageNorth();


    connect(this, &MainFramework::sigInitPicTree, ProjectWin::getInstance(), &ProjectWin::slotPicTree);
    connect(this, &MainFramework::sigInitParaFileList, ProjectWin::getInstance(), &ProjectWin::slotParaFileList);
    connect(this, &MainFramework::sigInitNavi, ProjectWin::getInstance(), &ProjectWin::slotNavi);
    connect(this, &MainFramework::sigInitImgPos, m_imgMgr, &ImageManager::setImagePosition);

    connect(this, &MainFramework::sigClearImage, m_imgMgr, &ImageManager::slotClearImage);
    connect(this, &MainFramework::sigClearImageNorth, m_imgNorth, &ImageNorth::slotClearImageNorth);
    connect(this, &MainFramework::sigInitImgNorthPos, m_imgNorth, &ImageNorth::setImagePositionNorth);

//    connect(m_imgMgr, &ImageManager::sigSelectedPic, this, &MainFramework::s_selectedPicCesium);
    connect(ProjectWin::getInstance(), &ProjectWin::sigSelectedPic, this, &MainFramework::s_selectedPicCesium);

    QTimer::singleShot(2, this, SLOT(s_timeout()));
}

MainFramework::~MainFramework()
{
    delete ui;
}



void MainFramework::initWorkSpaceView() {
    if (NULL == m_workspace) {
        m_workspace = new QWidget;
        m_workspace->setWindowTitle("工作区");
        this->setCentralWidget(m_workspace);
    }
    qDebug() << "工作区 id:" << m_workspace->winId() << ", name:" << m_workspace->windowTitle();
}

void MainFramework::initTitleBar()
{
    QMenuBar* m_MenuBar = this->menuBar();
    m_MenuBar->setStyleSheet(MenuBarStyle);

    QMenu* m_viewMenu = this->menuBar()->addMenu(u8"快视");
    m_viewMenu->setStyleSheet(MenuStyle);

    m_toolBarAc = new QAction(u8"工具栏");
    connect(m_toolBarAc, &QAction::triggered, this, &MainFramework::s_showToolBar);
    m_toolBarAc->setCheckable(true);
    m_toolBarAc->setChecked(true);

    m_projectAc = new QAction(u8"图像列表");
    connect(m_projectAc, &QAction::triggered, this, &MainFramework::s_showPorjectWin);
    m_projectAc->setCheckable(true);
    m_projectAc->setChecked(true);

    m_propertyAc = new QAction(u8"属性");
    connect(m_propertyAc, &QAction::triggered, this, &MainFramework::s_showPropertyWin);
    m_propertyAc->setCheckable(true);
    m_propertyAc->setChecked(true);

    m_logAc = new QAction(u8"输出");
    connect(m_logAc, &QAction::triggered, this, &MainFramework::s_showLogWin);
    m_logAc->setCheckable(true);
    m_logAc->setChecked(true);

    m_viewMenu->addAction(m_toolBarAc);
    m_viewMenu->addAction(m_projectAc);
    m_viewMenu->addAction(m_propertyAc);
    m_viewMenu->addAction(m_logAc);

    QMenu* m_setView = this->menuBar()->addMenu(u8"浏览");
    QMenu* m_toolMenu = this-> menuBar()->addMenu(u8"SAR处理");
    QMenu* m_helpMenu = this->menuBar()->addMenu(u8"帮助");

    initMaxMinWin();
}

void MainFramework::initMaxMinWin() {
    m_maxminWin = new QWidget(this);

    QHBoxLayout* horizontalLayout;
    QSpacerItem* horizontalSpacer;

    horizontalLayout = new QHBoxLayout(m_maxminWin);
    horizontalLayout->setSpacing(0);
    horizontalLayout->setContentsMargins(11, 11, 11, 11);
    horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
    horizontalLayout->setContentsMargins(0, 0, 0, 0);

    horizontalSpacer = new QSpacerItem(241, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);

    m_minBtn = new QPushButton(m_maxminWin);
    connect(m_minBtn, &QPushButton::clicked, this, &MainFramework::s_min);
    m_minBtn->setObjectName(QString::fromUtf8("minBtn"));
    m_minBtn->setMinimumSize(QSize(40, 40));
    m_minBtn->setMaximumSize(QSize(40, 40));
    m_minBtn->setStyleSheet(QString::fromUtf8("QPushButton{border:none;}\n"
                                              "QPushButton::hover{background-color:#E5E5E5;}\n"
                                              ""));
    QIcon icon;
    icon.addFile(QString::fromUtf8(":/images/min_main.png"), QSize(), QIcon::Normal, QIcon::Off);
    m_minBtn->setIcon(icon);
    m_minBtn->setIconSize(QSize(25, 25));
    m_minBtn->setAutoDefault(false);
    m_minBtn->setFlat(false);
    m_minBtn->setDefault(false);

    m_closeBtn = new QPushButton(m_maxminWin);
    connect(m_closeBtn, &QPushButton::clicked, this, &MainFramework::s_close);
    m_closeBtn->setObjectName(QString::fromUtf8("closeBtn"));
    m_closeBtn->setMinimumSize(QSize(40, 40));
    m_closeBtn->setMaximumSize(QSize(40, 40));
    m_closeBtn->setStyleSheet(QString::fromUtf8("QPushButton{border:none;}\n"
                                                "QPushButton::hover{background-color:#E81123;}\n"
                                                ));
    QIcon icon1;
    icon1.addFile(QString::fromUtf8(":/images/close_release.png"), QSize(), QIcon::Normal, QIcon::Off);
    m_closeBtn->setIcon(icon1);
    m_closeBtn->setIconSize(QSize(20, 20));
    m_closeBtn->setFlat(false);

    horizontalLayout->addItem(horizontalSpacer);
    horizontalLayout->addWidget(m_minBtn);
    horizontalLayout->addWidget(m_closeBtn);
    horizontalLayout->setStretch(0, 1);

    m_maxminWin->setLayout(horizontalLayout);
    this->menuBar()->setCornerWidget(m_maxminWin, Qt::TopRightCorner);
}

void MainFramework::s_showToolBar() {
    if (m_toolBarAc->isChecked()) {
        ui->mainToolBar->show();
        addLog(u8"显示 工具栏");
    }
    else {
        ui->mainToolBar->hide();
        addLog(u8"隐藏 工具栏");
    }
}

void MainFramework::s_showPorjectWin() {
    if (m_projectAc->isChecked()) {
        m_projManagerView->show();
        addLog(u8"显示 项目区");
    }
    else {
        m_projManagerView->hide();
        addLog(u8"隐藏 项目区");
    }
}

void MainFramework::s_showPropertyWin() {
    if (m_propertyAc->isChecked()) {
        m_flyPropertyView->show();
        addLog(u8"显示 属性区");
    }
    else {
        m_flyPropertyView->hide();
        addLog(u8"隐藏 属性区");
    }
}

void MainFramework::s_showLogWin() {
    if (m_logAc->isChecked()) {
        m_logView->show();
        addLog(u8"显示 日志区");
    }
    else {
        m_logView->hide();
        addLog(u8"隐藏 日志区");
    }
}

void MainFramework::s_timeout() {
    this->showMaximized();
}

void MainFramework::s_close() {
    this->close();
}

void MainFramework::s_min() {
    this->showMinimized();
}

void MainFramework::addLog(const QString& log)
{
    m_logBody->setReadOnly(true);
    m_logBody->append(log);
}

void MainFramework::initLogView() {
    if (NULL == m_logView) {
        m_logView = new QDockWidget(this);
        //set dock widget feature: not move, enable close.
        m_logView->setFeatures(QDockWidget::DockWidgetClosable);
        m_logView->setWindowTitle(u8"输出");

        m_logBody = new QTextEdit(this);
        m_logView->setWidget(m_logBody);
    }

    QPalette pl = m_logBody->palette();
    pl.setBrush(QPalette::Base, QBrush(QColor(255, 0, 0, 0)));
    m_logBody->setPalette(pl);
}

void MainFramework::initPropertyView() {
    if (NULL == m_flyPropertyView) {
        m_flyPropertyView = new QDockWidget(m_workspace);
        m_flyPropertyView->setFeatures(QDockWidget::DockWidgetClosable);
        m_flyPropertyView->setWindowTitle(u8"彩C校正");

        m_flyPropertyWin = new FlyPropertyWin(this);
        m_flyPropertyView->setWidget(m_flyPropertyWin);
        connect(this, &MainFramework::sigInitImgCheckPos, m_flyPropertyWin, &FlyPropertyWin::setImagePositionCheck);  //彩C校正
        qDebug() << "属性区 id:" << m_flyPropertyView->winId() << ", name:" << m_flyPropertyView->windowTitle();
    }

//    m_flyPropertyWin->resize(500, 300); // 设置初始大小为 500x300 像素
//    m_flyPropertyView->resize(500, 300); // 设置初始大小为 500x300 像素
     m_flyPropertyView->resize(280, 300); // 设置初始大小为 500x300 像素
}

void MainFramework::initProjectView() {
    if (NULL == m_projManagerView) {
        m_projManagerView = new QDockWidget(this);
        m_projManagerView->setFeatures(QDockWidget::DockWidgetClosable);
        m_projManagerView->setWindowTitle(u8"图像列表");

        delete title bar
        //QWidget* lTitleBar = m_projManagerView->titleBarWidget();
        //QWidget* lEmptyWidget = new QWidget();
        //m_projManagerView->setTitleBarWidget(lEmptyWidget);
        //delete lTitleBar;

//        m_projectWin = new ProjectWin(this);
        ProjectWin::getInstance();
        m_projManagerView->setWidget(ProjectWin::getInstance());

        qDebug() << "项目区 id:" << m_projManagerView->winId() << ", name:" << m_projManagerView->windowTitle();
    }
}

void MainFramework::dockLayout() {
    this->addDockWidget(Qt::LeftDockWidgetArea, m_projManagerView, Qt::Orientation::Vertical);
//    m_flyPropertyView->resize(50, 300);
//    m_flyPropertyView->setMinimumSize(180, 300);
//   m_flyPropertyView->setMaximumSize(180, 300);
    this->addDockWidget(Qt::RightDockWidgetArea, m_flyPropertyView, Qt::Orientation::Vertical);
    this->addDockWidget(Qt::BottomDockWidgetArea, m_logView, Qt::Orientation::Vertical);
}

void MainFramework::initToolBar() {
    QSize toolIconSize(50, 30);
    ui->mainToolBar->setIconSize(toolIconSize);   //设置工具栏图标大小

    QIcon newFileIcon(u8":/images/新建文件.png");
    QIcon openFileIcon(u8":/images/打开文件.png");
    QIcon saveFileIcon(":/images/保存.png");
    QIcon runIcon(u8":/images/运行.png");
    QIcon stopIcon(":/images/停止.png");
    QIcon debugIcon(u8":/images/调试.png");
    QIcon anaysisIcon(u8":/images/分析.png");
    QIcon recordIcon(u8":/images/录制.png");
    QIcon grabIcon(u8":/images/抓取.png");
    QIcon capacityIcon(u8":/images/应用中心.png");
    QIcon paramterIcon(u8":/images/参数.png");
    QIcon publishIcon(u8":/images/发布.png");
    QIcon exportIcon(u8":/images/导出.png");

    m_newAc = new QAction(newFileIcon, u8"新添加监控文件夹", this);
    m_saveAc = new QAction(saveFileIcon, u8"转正北", this);
    m_runAc = new QAction(runIcon, u8"矫正", this);
    m_stopAc = new QAction(stopIcon, u8"三维交互", this);
    m_debugAc = new QAction(debugIcon, u8"调试", this);
    m_anaysisAc = new QAction(anaysisIcon, u8"分析", this);
    m_recordAc = new QAction(recordIcon, u8"录制", this);
    m_grabAc = new QAction(grabIcon, u8"抓取", this);
    m_capacityAc = new QAction(capacityIcon, u8"能力中心", this);
    m_paramterAc = new QAction(paramterIcon, u8"参数", this);
    m_publishAc = new QAction(publishIcon, u8"发布", this);
    m_exportAc = new QAction(exportIcon, u8"导出", this);

    //add QAction to Widget.
    ui->mainToolBar->addAction(m_newAc);
    ui->mainToolBar->addAction(m_saveAc);
    ui->mainToolBar->addAction(m_saveAc);
    ui->mainToolBar->addSeparator();
    ui->mainToolBar->addAction(m_runAc);
    ui->mainToolBar->addAction(m_stopAc);
    ui->mainToolBar->addAction(m_debugAc);
    ui->mainToolBar->addAction(m_anaysisAc);
    ui->mainToolBar->addSeparator();
    ui->mainToolBar->addAction(m_recordAc);
    ui->mainToolBar->addAction(m_grabAc);
    ui->mainToolBar->addSeparator();
    ui->mainToolBar->addAction(m_capacityAc);
    ui->mainToolBar->addSeparator();
    ui->mainToolBar->addAction(m_paramterAc);
    ui->mainToolBar->addAction(m_publishAc);
    ui->mainToolBar->addAction(m_exportAc);
    ui->mainToolBar->addSeparator();

//    connect(m_newAc, &QAction::triggered, this, &MainFramework::s_newProject);
//    connect(m_saveAc, &QAction::triggered, this, &MainFramework::s_saveFile);
    connect(m_runAc, &QAction::triggered, this, &MainFramework::s_runAc);
    connect(m_stopAc, &QAction::triggered, this, &MainFramework::s_cesiumAc);
    connect(m_debugAc, &QAction::triggered, this, &MainFramework::s_debugAc);
    connect(m_anaysisAc, &QAction::triggered, this, &MainFramework::s_anaysisAc);
    connect(m_recordAc, &QAction::triggered, this, &MainFramework::s_recordAc);
    connect(m_grabAc, &QAction::triggered, this, &MainFramework::s_grabAc);
    connect(m_capacityAc, &QAction::triggered, this, &MainFramework::s_capacityAc);
    connect(m_paramterAc, &QAction::triggered, this, &MainFramework::s_paramterAc);
    connect(m_publishAc, &QAction::triggered, this, &MainFramework::s_publishAc);
    connect(m_exportAc, &QAction::triggered, this, &MainFramework::s_exportAc);

    connect(m_newAc, &QAction::triggered, this, &MainFramework::s_MonitorFolder);
    connect(m_saveAc, &QAction::triggered, this, &MainFramework::s_toNorth);

}

void MainFramework::s_hideProj() {
    m_projectAc->setChecked(false);
    m_projManagerView->hide();
}

void MainFramework::s_propertyWinHide(bool visible) {
    if (!visible) {
        m_propertyAc->setChecked(false);
        m_flyPropertyView->hide();
    }
}

void MainFramework::s_logWinHide(bool visible) {
    if (!visible) {
        m_logAc->setChecked(false);
        m_logView->hide();
    }
}

void MainFramework::s_newProject() {

}
void MainFramework::s_saveFile() {
    QString log = QString(u8"功能正在开发中,请耐心等待!");
    showMessageBox(log);
    addLog(log);
}
void MainFramework::s_runAc() {
    QString log = QString(u8"彩C校正");

    emit sigInitImgCheckPos(m_colorCfiles04, m_strMonitorDirectory, 4);
    emit sigInitImgCheckPos(m_colorCfiles02, m_strMonitorDirectory, 2);
    emit sigInitImgCheckPos(m_colorCfiles05, m_strMonitorDirectory, 5);
//    showMessageBox(log);
    addLog(log);
}
//三维交互
void MainFramework::s_cesiumAc() {
    QString log = QString(u8"Qt和Cesium之间传递数据!");
//    showMessageBox(log);



    addLog(log);
}
void MainFramework::s_debugAc() {
    QString log = QString(u8"功能正在开发中,请耐心等待!");
    showMessageBox(log);
    addLog(log);
}
void MainFramework::s_anaysisAc() {
    QString log = QString(u8"功能正在开发中,请耐心等待!");
    showMessageBox(log);
    addLog(log);
}
void MainFramework::s_recordAc() {
    QString log = QString(u8"功能正在开发中,请耐心等待!");
    showMessageBox(log);
    addLog(log);
}
void MainFramework::s_grabAc() {
    QString log = QString(u8"功能正在开发中,请耐心等待!");
    showMessageBox(log);
    addLog(log);
}
void MainFramework::s_capacityAc() {
    QString log = QString(u8"功能正在开发中,请耐心等待!");
    showMessageBox(log);
    addLog(log);
}
void MainFramework::s_paramterAc() {
    QString log = QString(u8"功能正在开发中,请耐心等待!");
    showMessageBox(log);
    addLog(log);
}
void MainFramework::s_publishAc() {
    QString log = QString(u8"功能正在开发中,请耐心等待!");
    showMessageBox(log);
    addLog(log);
}
void MainFramework::s_exportAc() {
    QString log = QString(u8"功能正在开发中,请耐心等待!");
    showMessageBox(log);
    addLog(log);
}


void MainFramework::showMessageBox(const QString& text) {
    if (NULL == m_msgBox) {
        m_msgBox = new MsgBox();
    }

    m_msgBox->setMsgText(text);
    m_msgBox->show();
}

QString MainFramework::separateFiles(const QString &files)
{
    return "null";
}

void MainFramework::cesiumPicPath(const QString& picName)
{

}

void MainFramework::readCaiCFile(const QString &folderPath)
{
    m_colorCfiles04.clear();
    m_colorCfiles02.clear();
    m_colorCfiles05.clear();
    m_colorCAllFiles.clear();
    m_colorCAllFilesWithPath.clear();

    QDir directory(folderPath);
    QStringList filters;
    filters << "*.jpg";

    directory.setNameFilters(filters);
    directory.setFilter(QDir::Files | QDir::NoDotAndDotDot);

    QFileInfoList fileInfoList = directory.entryInfoList();

    for (const QFileInfo &fileInfo : fileInfoList) {
//        qDebug() << "Found:" << fileInfo.absoluteFilePath();
        QString fullPath = fileInfo.absoluteFilePath();
        m_colorCAllFiles.push_back(fileInfo.fileName());
        m_colorCAllFilesWithPath.push_back(fullPath);
    }

    groupStrips();

}

void MainFramework::readCaiCParaFile(const QString &folderPath)
{
    QDir directory(folderPath);
    QStringList filters;
    filters << "*.txt";

    directory.setNameFilters(filters);
    directory.setFilter(QDir::Files | QDir::NoDotAndDotDot);

    QFileInfoList fileInfoList = directory.entryInfoList();

    for (const QFileInfo &fileInfo : fileInfoList) {
        //        qDebug() << "Found:" << fileInfo.absoluteFilePath();
        QString fullPath = fileInfo.absoluteFilePath();
        m_colorCParaFiles.push_back(fileInfo.fileName());
//        m_colorCAllFilesWithPath.push_back(fullPath);
    }
}

bool MainFramework::sortStrips(const QString &a, const QString &b)
{
    QStringList aSplit = a.split('_');
    QStringList bSplit = b.split('_');

    int aFirstPart = aSplit[0].toInt();
    int bFirstPart = bSplit[0].toInt();

    if (aFirstPart == bFirstPart) {
        int aSecondPart = aSplit[6].toInt();
        int bSecondPart = bSplit[6].toInt();
        return aSecondPart > bSecondPart;
    } else {
        return aFirstPart < bFirstPart;
    }
}

void MainFramework::groupStrips()
{
    for(const QString& fileName : m_colorCAllFiles)
    {
        if(fileName.contains("_04_")) {
            m_colorCfiles04.append(fileName);
        } else if(fileName.contains("_02_")) {
            m_colorCfiles02.append(fileName);
        } else if(fileName.contains("_05_")) {
            m_colorCfiles05.append(fileName);
        }
    }

    auto sortStripsLambda = [this](const QString &a, const QString &b) {
        return this->sortStrips(a, b);
    };

    //条带排序
    std::sort(m_colorCfiles04.begin(), m_colorCfiles04.end(), sortStripsLambda);
    std::sort(m_colorCfiles02.begin(), m_colorCfiles02.end(), sortStripsLambda);
    std::sort(m_colorCfiles05.begin(), m_colorCfiles05.end(), sortStripsLambda);
}

void MainFramework::s_MonitorFolder()
{
    m_strMonitorDirectory = QFileDialog::getExistingDirectory(this, u8"请选择共享文件夹", "./");
    QString monitorFolder = u8"开始监控文件夹:" + m_strMonitorDirectory;
//    QString monitorPaht = monitorFolder + "/";
    m_fileMonitor = new FileMonitorMgr(m_strMonitorDirectory);

//    connect(this, &MainFramework::sigInitImgPos, m_imgMgr, &ImageManager::setImagePosition);
    connect(m_fileMonitor, &FileMonitorMgr::sigAddFiles, ProjectWin::getInstance(), &ProjectWin::slotUpdatePicTree); //添加新的任务开机节点
    connect(m_fileMonitor, &FileMonitorMgr::sigAddFilesPos, m_imgMgr, &ImageManager::addNewPicResort);
//    connect(m_fileMonitor, &FileMonitorMgr::sigAddFilesTree, ProjectWin::getInstance(), &ProjectWin::slotAddNewPicNode);

//    connect(m_fileMonitor, &FileMonitorMgr::sigAddFiles, m_imgMgr, &ImageManager::slotUpdatePicTree);
    readCaiCFile(m_strMonitorDirectory);
    readCaiCParaFile(m_strMonitorDirectory);
//    emit sigClearImage(true);//清空主窗口图片
    emit sigInitParaFileList(m_colorCParaFiles, m_strMonitorDirectory);
    emit sigInitPicTree(m_colorCAllFiles, m_strMonitorDirectory);  
    emit sigInitNavi("navi");
    //emit sigInitImgPos(m_colorCAllFiles, m_strMonitorDirectory);
    //主窗口显示图片
    emit sigInitImgPos(m_colorCfiles04, m_strMonitorDirectory, 4);
    emit sigInitImgPos(m_colorCfiles02, m_strMonitorDirectory, 2);
    emit sigInitImgPos(m_colorCfiles05, m_strMonitorDirectory, 5);
    
//    emit sigInitPicTree(m_colorCfiles02, m_strMonitorDirectory);
//    emit sigInitPicTree(m_colorCfiles05, m_strMonitorDirectory);
    addLog(monitorFolder);
}

void MainFramework::s_toNorth()
{

    m_imgNorth->show();

    m_strMonitorDirectory = QFileDialog::getExistingDirectory(this, u8"请选择共享文件夹", "./");
    QString monitorFolder = u8"转正北文件夹:" + m_strMonitorDirectory;
    //    QString monitorPaht = monitorFolder + "/";
    m_fileMonitor = new FileMonitorMgr(m_strMonitorDirectory);


//    connect(m_fileMonitor, &FileMonitorMgr::sigAddFiles, ProjectWin::getInstance(), &ProjectWin::slotUpdatePicTree);
    readCaiCFile(m_strMonitorDirectory);
//    readCaiCParaFile(m_strMonitorDirectory);
//    emit sigClearImageNorth(true); //清除转正北窗口中所有图片
    emit sigInitImgNorthPos(m_colorCfiles04, m_strMonitorDirectory, 4);
    emit sigInitImgNorthPos(m_colorCfiles02, m_strMonitorDirectory, 2);
    emit sigInitImgNorthPos(m_colorCfiles05, m_strMonitorDirectory, 5);

    addLog(monitorFolder);
}

void MainFramework::s_toCheck()
{
    m_imgNorth->show();
    m_strMonitorDirectory = QFileDialog::getExistingDirectory(this, u8"请选择共享文件夹", "./");
    QString monitorFolder = u8"矫正文件夹:" + m_strMonitorDirectory;

    readCaiCFile(m_strMonitorDirectory);

    emit sigInitImgNorthPos(m_colorCfiles04, m_strMonitorDirectory, 4);
    emit sigInitImgNorthPos(m_colorCfiles02, m_strMonitorDirectory, 2);
    emit sigInitImgNorthPos(m_colorCfiles05, m_strMonitorDirectory, 5);

    addLog(monitorFolder);

}

void MainFramework::s_selectedPicCesium(const QString& pic)
{
    QString cesiumFile = "D:/filePath.txt";
//    if(QFile::exists(cesiumFile))
//    {
//        QFile::remove(cesiumFile);
//    }

    QString preMonitor = m_strMonitorDirectory + "/";
    QString monitorJpg = preMonitor + pic;


    qDebug() << "monitorJpg=" << monitorJpg;

    QString moniterTxt;
    QString moniterMark;
    int pos = pic.indexOf(".jpg");
    moniterTxt = pic.left(pos);
    moniterTxt += ".txt";
    moniterTxt = preMonitor + moniterTxt;
    qDebug() << "moniterTxt=" << moniterTxt;

    moniterMark = pic.left(pos);
    moniterMark += ".mark";
    moniterMark = preMonitor + moniterMark;
    qDebug() << "moniterMark=" << moniterMark;

    QString content = monitorJpg + "," + moniterTxt + "," + moniterMark;

    QFile file(cesiumFile);
    if(file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
    {
        QTextStream stream(&file);
        stream << content;
        file.close();
    }

}



本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/28829.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

人工智能(pytorch)搭建模型12-pytorch搭建BiGRU模型,利用正态分布数据训练该模型

大家好&#xff0c;我是微学AI&#xff0c;今天给大家介绍一下人工智能(pytorch)搭建模型12-pytorch搭建BiGRU模型&#xff0c;利用正态分布数据训练该模型。本文将介绍一种基于PyTorch的BiGRU模型应用项目。我们将首先解释BiGRU模型的原理&#xff0c;然后使用PyTorch搭建模型…

在Nginx服务器如何安装SSL证书

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言提示&#xff1a;我用的是阿里云的产品&#xff0c;就以阿里云进行的&#xff1a; 一、下载SSL证书二、安装SSL证书 前言 提示&#xff1a;我用的是阿里云的产…

二叉树及其链式结构

目录 一&#xff1a;树概念及结构 1.树的概念 2.树的相关概念 3.树的表示 二&#xff1a;二叉树的概念及结构 1.概念 2.特殊的二叉树 <1>. 满二叉树&#xff1a; <2>. 完全二叉树&#xff1a; 3.二叉树的性质 4.二叉树的存储结构 <1>.顺序结构 <…

渗透专题丨web Top10 漏洞简述(2)

文件包含漏洞 1、漏洞简述 程序在引用文件的时&#xff0c;引用的文件名&#xff0c;用户可控的情况&#xff0c;传入的文件名校验不严&#xff0c;从而操作了预想之外的文件&#xff0c;就有可能导致文件泄漏和恶意的代码注入。这是因为程序开发时候会把重复使用的函数写到归…

[笔记]pg常用命令

数据库版本 &#xff1a;9.6.6 注意 &#xff1a;PostgreSQL中的不同类型的权限有SELECT,INSERT,UPDATE,DELETE,TRUNCATE,REFERENCES,TRIGGER,CREATE,CONNECT,TEMPORARY,EXECUTE 和 USAGE。 1. 登录PG数据库 以管理员身份 postgres 登陆&#xff0c;然后通过 #psql -U postg…

新世界-旧世界

以下内容是这两天朋友问答形成的一些观点&#xff0c;堆成一篇文章。看似没有关联性&#xff0c;但你仔细品味&#xff0c;你会感觉到它们其实讲的是一个事。至于是一个啥事&#xff0c;我不说&#xff0c;你们自己猜。 &#xff08;1&#xff09; 今年年初看见篇文章&#xff…

mdBook介绍及使用——使用 Markdown 创建你自己的博客和电子书

目录 介绍一、下载与创建项目1.下载2.初始化3.结构说明 二、编写文章与启动1.编写文章2.构建3.启动 mdbook 服务 三、其他配置 介绍 mdBook 是一个使用 Markdown 创建书籍的命令行工具。它非常适合创建产品或 API 文档、教程、课程材料或任何需要清晰、易于导航和可定制的演示…

Spring中如何获取Bean方法上的自定义注解

文章目录 背景描述场景复现问题追踪解决方案扩展思考 背景描述 项目中需要扫描出来所有 标注了自定义注解A的Service里面标注了自定义注解B的方法 来做后续处理。 基本的思路就是通过Spring提供的ApplicationContext#getBeansWithAnnotation反射 来实现。 但是&#xff0c;随…

QT C++入门学习(2) QT Creator写一个简单的上位机控制LED

上位机和下位机的概念 上位机&#xff1a;指的是可以直接发送操作指令的计算机或者单片机&#xff0c;一般提供用户操作交互界面并向用户展示反馈数据。 典型设备&#xff1a;电脑、平板、手机、面板、触摸屏 下位机&#xff1a;指的是与机器相连接的计算机或者单片机&#…

SpringBoot+Vue 车辆充电桩系统

文章目录 1、效果演示效果图技术栈 2、 前言介绍&#xff08;完整源码请私聊&#xff09;3、主要技术3.4.1 数据库概念结构设计3.4.2 数据库具体设计 4 系统功能的具体实现4.1 前台功能模块4.1.1 首页功能4.1.2 用户后台管理 4.2 后台功能模块4.2.1 管理员功能4.2.2 维修员功能…

SciencePub学术 | 计算机类重点SCIEI征稿中

SciencePub学术 刊源推荐: 计算机类重点SCI&EI征稿中&#xff01;影响因子高&#xff0c;对国人非常友好。信息如下&#xff0c;录满为止&#xff1a; 一、期刊概况&#xff1a; 计算机类重点SCI&EI &#x1f4cc;【期刊简介】IF&#xff1a;7.5-8.0&#xff0c;JCR…

前端vue仿京东天猫简单好用的瀑布流瀑布流式布局列表组件waterfall

前端vue仿京东天猫简单好用的瀑布流瀑布流式布局列表组件waterfall&#xff0c; 下载完整代码请访问uni-app插件市场址:https://ext.dcloud.net.cn/plugin?id13046 效果图如下&#xff1a; #### 使用方法 使用方法 <!-- proList: 条目数组数据 goProDetail:条目点击事…

微信小程序基础使用

微信小程序的基本使用 微信小程序文件类型 微信小程序主要提供了 4 种文件类型&#xff1a; 类型名称作用是否必须存在.wxml用于页面的布局结构&#xff0c;相当于网页中 .html 文件是.wxss用于页面的样式&#xff0c;相当于网页中的 .css 文件否.js用于页面的逻辑是.json用…

1.8C++流提取运算符重载

C流提取运算符重载 在 C中&#xff0c;流提取运算符&#xff08;>>&#xff09;是用于从流中提取数据的运算符。 C中的流提取运算符可以被重载&#xff0c;使得程序员可以自定义输入对象的方式&#xff0c;更方便地输入自定义的数据类型&#xff0c;也可以使得输入更加…

数字中国,开鸿见日

讲个小故事&#xff0c;《晋书乐广传》记载&#xff0c;西晋名士乐广&#xff0c;请大文学家潘岳替自己写一篇文章。潘岳让乐广把意思完完整整告诉他&#xff0c;再由他来动笔&#xff0c;最终写成了名扬当时的《呈太尉辞河南尹表》。时人看过这篇文章&#xff0c;评价乐广是“…

传输平台太多?难以管理?看这款跨网传输系统怎样解决

传输作为企业正常运行中最日常的行为&#xff0c;也意味着出现频率最高。微信、QQ、邮件、或是钉钉等办公软件&#xff0c;每天大家上班时开着各种软件&#xff0c;进行着不同的信息交互与传输。很多员工在工作时往往是哪个软件方便顺手就用哪个传输&#xff0c;但是这样也意味…

python打包后报错,无法启动,电脑缺少api-ms-win-core-path-11-1-0.dll

参考&#xff1a;《运行打包python程序时报&#xff1a;无法启动此程序&#xff0c;因为计算机中丢失 api-ms-win-core-path-l1-1-0.dll 尝试重新安装该程序以解决此问题。》 原因&#xff1a;python版本较高&#xff0c;打包时的python版本是python3.10&#xff0c;而运行打包…

xxl-job核心源码解析

xxl-job源码解析 如何自研一个xxljob 注册服务调度服务RPC组件(基建&#xff0c;底层严重依赖)日志服务告警服务 系统架构 执行流程 各大调度中心对比 1&#xff09;服务端启动流程 首先找到配置类 XxlJobAdminConfig 可以发现该类实现 InitializingBean接口&#xff0c;…

批量生成,本地推理,人工智能声音克隆框架PaddleSpeech本地批量克隆实践(Python3.10)

云端炼丹固然是极好的&#xff0c;但不能否认的是&#xff0c;成本要比本地高得多&#xff0c;同时考虑到深度学习的训练相对于推理来说成本也更高&#xff0c;这主要是因为它需要大量的数据、计算资源和时间等资源&#xff0c;并且对超参数的调整也要求较高&#xff0c;更适合…

熬夜三晚之深度解析DuckDB MetaPipeline

深度解析DuckDB MetaPipeline 深度解析DuckDB MetaPipeline 1.导语 2.基础理论 3.HashJoin深度解析 3.1 RESULT_COLLECTOR 3.2 PROJECTION 3.3 HASH_JOIN 4.Ready 4.1 翻转 4.2 MetaPipeline与pipeline 5.汇总 1.导语 DuckDB 是…