一、前言

上篇博客中通过重载子窗体的构造函数将主窗体的值传入到子窗体,但是在子窗体运行过程中如何才能将值动态的传入到子窗体?可以有两种办法,1、信号和槽的方式传值;2、主窗体中将传出值设置为public

本文主要实现功能为:鼠标点击主窗体的GraphicsView中的Scene时,将对应像素处的各个波段值传递给子窗体的TabelView并显示。其中子窗体的接受主窗体的值是通过2(public)的方式,简单方便。

二、主、子窗体的设计

定义子窗体类:ShowPixelData

主要实现:1 接受主窗体传入的文件名、当前点击图像的行、列号;

2 根据传入值,读取并显示pixel data;

头文件如下:

 #ifndef SHOWPIXELDATA_H
#define SHOWPIXELDATA_H #include <QDialog>
#include <QStandardItemModel>
#include "hyperprocess.h" class HyperProcess; namespace Ui {
class ShowPixelData;
} class ShowPixelData : public QDialog
{
Q_OBJECT public:
ShowPixelData(QWidget *parent = );
~ShowPixelData(); private slots:
void receiveHyperToPixelDataSlot(); // 接受鼠标单击信号
void exitShowPixelDataSlot(); // signals:
void sendExit(); // private:
Ui::ShowPixelData *ui;
HyperProcess *ptr; QStandardItemModel *myPixelData; int currentRow; // 行
int currentCol; // 列
QString curFileName; // 文件名
}; #endif // SHOWPIXELDATA_H

源文件如下:

 #include "ShowPixelData.h"
#include "ui_ShowPixelData.h" ShowPixelData::ShowPixelData(QWidget *parent) :
QDialog(parent),
ui(new Ui::ShowPixelData)
{
ui->setupUi(this); currentRow = -;
currentCol = -;
curFileName = "";
ptr = (HyperProcess*)parentWidget(); //获得主窗体的指针 ui->pixelInfo->setText("Pixel Info");
myPixelData = new QStandardItemModel;
myPixelData->setColumnCount();
myPixelData->setHorizontalHeaderLabels(QStringList()<<QStringLiteral("Band")<<QStringLiteral("Data"));
ui->pixelDataView->setModel(myPixelData);// 初始化
ui->pixelDataView->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->pixelDataView->setColumnWidth(,);
ui->pixelDataView->setColumnWidth(,); connect(ptr,SIGNAL(sendSignalToShowPixelData()),this,SLOT(receiveHyperToPixelDataSlot()));
connect(ui->ExitButton,SIGNAL(clicked()),this,SLOT(exitShowPixelDataSlot()));
} ShowPixelData::~ShowPixelData()
{
delete ui;
} void ShowPixelData::receiveHyperToPixelDataSlot()
{
curFileName = ptr->curFileName;
currentRow = ptr->curRow;
currentCol = ptr->curCol; if(curFileName == "")
{
QMessageBox::information(this,"Message Error","Current Scene IS NULL!");
return;
} if(currentCol == - || currentRow == -)
{
QMessageBox::information(this,"Message Error","please Select A Pixel");
return;
} cv::Mat curImg = GDALOpenCV::GDAL2Mat(curFileName);
if(currentCol > curImg.cols || currentRow > curImg.rows)
return; int count = curImg.channels();
ui->pixelInfo->setText(QString("pixel:(%1,%2)").arg(currentRow+).arg(currentCol+)); std::vector<cv::Mat> curImgMat(count);
cv::split(curImg,curImgMat);
QVector<float> pixSpectralData(count); myPixelData->clear();
myPixelData->setColumnCount();
myPixelData->setHorizontalHeaderLabels(QStringList()<<QStringLiteral("Band")<<QStringLiteral("Data"));
ui->pixelDataView->setModel(myPixelData);
ui->pixelDataView->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->pixelDataView->setColumnWidth(,);
ui->pixelDataView->setColumnWidth(,);
for(int c = ;c<count;c++)
{
pixSpectralData[c] = curImgMat[c].at<float>(currentCol,currentRow);
myPixelData->setItem(c,,new QStandardItem(tr("band%1").arg(QString::number(c+, ))));
myPixelData->setItem(c,,new QStandardItem(QString("%1").arg(pixSpectralData[c])));
}
ui->pixelDataView->setModel(myPixelData); } void ShowPixelData::exitShowPixelDataSlot()
{
emit sendExit();
close();
}

主窗体类:HyperProcess

实现功能:1 传出鼠标点击信号;

2 public声明,并且动态改变相应的输出值

头文件如下:

 private slots:
void ShowPixelDataSlot(); // 显示子窗体槽
void receiveRowColSlot(int,int); // 从主窗体的GraphicsView接收行、列号,并传出信号 signals:
void sendSignalToShowPixelData(); public:
int curRow;
int curCol;
QString curFileName;

源文件:

 void HyperProcess::ShowPixelDataSlot()
{
if(currentSceneIndex == -)
{
QMessageBox::information(this,"Message Error","please Open At Least One Image!");
return;
}else
{
myShowPixelData = new ShowPixelData(this);
myShowPixelData->show();
connect(myShowPixelData,SIGNAL(sendExit()),this,SLOT(receiveShowPixelDataSlot()));
myImg->setCursor(Qt::CrossCursor);
return;
}
} void HyperProcess::receiveRowColSlot(int row,int col)
{
curCol = col;
curRow = row;
emit sendSignalToShowPixelData();
} void HyperProcess::receiveShowPixelDataSlot()
{
myImg->setCursor(Qt::ArrowCursor);
}

三、实现效果

   

最新文章

  1. Node.js学习笔记
  2. Django分析之如何自定义manage命令
  3. 推荐一个简单、轻量、功能非常强大的C#/ASP.NET定时任务执行管理器组件–FluentScheduler定时器
  4. lua 学习
  5. linux笔记-硬链接和符号链接
  6. mysql创建自定义函数与存储过程
  7. EasyUI DataGrid编辑单元格时使用combogrid
  8. Orchard 源码探索(Module,Theme,Core扩展加载概述)
  9. swift论坛正式上线
  10. 插入排序的优化非希尔【不靠谱地讲可以优化到O(nlogn)】 USACO 丑数
  11. C# - 为引用类型重定义相等性
  12. MySQL的SQL_Mode修改小计
  13. 996.icu,不加班的程序员有前途吗?
  14. less--入门
  15. Python 递归的练习
  16. pta_l1-6(连续因子)
  17. 关于easyui的问答(来自百度问答)
  18. ORA-01403:no data found 解决办法
  19. codeforces 497c//Distributing Parts// Codeforces Round #283(Div. 1)
  20. 搭建openwrt_x86虚拟机环境

热门文章

  1. jQuery.extend 和 jQuery.fn.extend
  2. 修改EF的默认约定模型的方式
  3. C# 将对象序列化为Json格式
  4. android内存优化之图片压缩和缓存
  5. js中的for-of循环遍历数组
  6. hdu 2191多重背包
  7. 使用python发邮件
  8. JDBC中PreparedStatement和Statement的区别
  9. (原)torch中显示nn.Sequential()网络的详细情况
  10. ECSHOP_百度收录网址后面有?from=rss