107 lines
2.8 KiB
C++
107 lines
2.8 KiB
C++
|
|
#include "formhead.h"
|
|||
|
|
#include "ui_formhead.h"
|
|||
|
|
#include <QMessageBox>
|
|||
|
|
#include <QMenu>
|
|||
|
|
#include "CallManage.h"
|
|||
|
|
|
|||
|
|
//demo画道,暂时不用
|
|||
|
|
FormHead::FormHead(QWidget *parent, int indexID) :
|
|||
|
|
QWidget(parent),
|
|||
|
|
ui(new Ui::FormHead)
|
|||
|
|
{
|
|||
|
|
ui->setupUi(this);
|
|||
|
|
|
|||
|
|
m_indexID =indexID;
|
|||
|
|
|
|||
|
|
//使能右键菜单功能
|
|||
|
|
ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
|||
|
|
|
|||
|
|
// 连接信号和槽
|
|||
|
|
connect(ui->tableWidget, &QTableWidget::itemClicked, this, &FormHead::onItemClicked);
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
FormHead::~FormHead()
|
|||
|
|
{
|
|||
|
|
delete ui;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
void FormHead::Init()
|
|||
|
|
{
|
|||
|
|
//清空
|
|||
|
|
ui->tableWidget->clearContents();
|
|||
|
|
ui->tableWidget->verticalHeader()->hide();//隐藏左侧系统序号栏
|
|||
|
|
ui->tableWidget->horizontalHeader()->hide();//隐藏上方系统序号栏
|
|||
|
|
|
|||
|
|
//因为tableWidget需要提前规定好行数与列数
|
|||
|
|
int recordcount = 0; //总行数
|
|||
|
|
ui->tableWidget->setColumnCount(1);
|
|||
|
|
ui->tableWidget->setRowCount(recordcount); //动态设置行数
|
|||
|
|
|
|||
|
|
//设置所有列均匀分布并填充满整个空间
|
|||
|
|
QHeaderView *header = ui->tableWidget->horizontalHeader();
|
|||
|
|
for (int i = 0; i < ui->tableWidget->columnCount(); ++i) {
|
|||
|
|
header->setSectionResizeMode(i, QHeaderView::Stretch);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void FormHead::Add(QString strLineName, QColor lineColor)
|
|||
|
|
{
|
|||
|
|
int row = ui->tableWidget->rowCount();
|
|||
|
|
ui->tableWidget->setRowCount(row + 1);
|
|||
|
|
|
|||
|
|
QFont font("微软雅黑", 12, QFont::Bold, false);
|
|||
|
|
//QColor _fontColor = QColor(220, 220, 220);
|
|||
|
|
|
|||
|
|
//
|
|||
|
|
QTableWidgetItem* item = new QTableWidgetItem(strLineName);
|
|||
|
|
item->setFlags(item->flags() & (~Qt::ItemIsEditable));
|
|||
|
|
item->setForeground(QBrush(lineColor));// 设置字体颜色
|
|||
|
|
item->setFont(font); // 应用新的字体
|
|||
|
|
item->setTextAlignment(Qt::AlignCenter);//居中
|
|||
|
|
//
|
|||
|
|
ui->tableWidget->setItem(row, 0, item);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 槽函数
|
|||
|
|
void FormHead::onItemClicked(QTableWidgetItem *item)
|
|||
|
|
{
|
|||
|
|
if (item) {
|
|||
|
|
// 获取 item 的位置信息
|
|||
|
|
//int row = item->row();
|
|||
|
|
//int column = item->column();
|
|||
|
|
// 处理 item 点击的逻辑
|
|||
|
|
//qDebug() << "Item at row" << row << "column" << column << "clicked.";
|
|||
|
|
|
|||
|
|
QString message = "选中项: " + item->text();
|
|||
|
|
|
|||
|
|
QMessageBox::information(this, "提示", message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
void FormHead::on_tableWidget_customContextMenuRequested(const QPoint &pos)
|
|||
|
|
{
|
|||
|
|
QMenu *menu = new QMenu(ui->tableWidget);
|
|||
|
|
QAction *actionAddLine = menu->addAction(tr("新增曲线"));
|
|||
|
|
//QAction *actionDel = menu->addAction(tr("删除道"));
|
|||
|
|
|
|||
|
|
connect(actionAddLine, SIGNAL(triggered()), this, SLOT(s_AddLine()));
|
|||
|
|
//connect(actionDel, SIGNAL(triggered()), this, SLOT(s_DelOne()));
|
|||
|
|
|
|||
|
|
menu->exec(QCursor::pos());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void FormHead::s_AddLine()
|
|||
|
|
{
|
|||
|
|
emit CallManage::getInstance()->sig_AddLine(m_indexID);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void FormHead::s_DelOne()
|
|||
|
|
{
|
|||
|
|
emit CallManage::getInstance()->sig_DelOne(m_indexID);
|
|||
|
|
}
|