You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
5.5 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* @file FITKTableWidget.h
* @brief
* @author YanZhiHui(chanyuantiandao@126.com)
* @date 2024-10-21
*/
#ifndef FITKTableWidget_H_
#define FITKTableWidget_H_
#include <QTableWidget>
#include <QClipboard>
#include <QModelIndex>
#include "FITKWidgetAPI.h"
namespace Comp
{
/**
* @brief 自定义表格组件类
* @author YanZhiHui (chanyuantiandao@126.com)
* @date 2024-04-22
*/
class FITKWidgetAPI FITKTableWidget : public QTableWidget
{
Q_OBJECT
public:
/**
* @brief 构造函数
* @param parent 父对象
* @author YanZhiHui (chanyuantiandao@126.com)
* @date 2024-04-22
*/
explicit FITKTableWidget(QWidget *parent = nullptr);
/**
* @brief 析构函数
* @author YanZhiHui (chanyuantiandao@126.com)
* @date 2024-04-22
*/
~FITKTableWidget();
/**
* @brief 设置按回车键添加一行
* @param b 是否添加
* @author YanZhiHui (chanyuantiandao@126.com)
* @date 2024-04-22
*/
void setAppendLineByEnterPressed(bool b);
/**
* @brief 设置表格是否是单行模式默认为false
* @param[i] isAlone true开启 false关闭
* @author BaGuijun (baguijun@163.com)
* @date 2024-06-07
*/
void setIsAloneRow(bool isAlone);
/**
* @brief 表格增加一行
* @param[in] rowNum 增加行的索引
* @author yanzhihui (chanyuantiandao@126.com)
* @date 2023-08-14
*/
void addTableRowAndItem(int rowNum);
signals:
/**
* @brief 单元格按回车键被按下
* @param index 单元格索引
* @author YanZhiHui (chanyuantiandao@126.com)
* @date 2024-04-22
*/
void cellEnterPressed(QModelIndex index);
public slots:
/**
* @brief 右键菜单响应槽函数
* @param[in] 点击位置
* @author yanzhihui (chanyuantiandao@126.com)
* @date 2023-07-26
*/
void customContextMenuRequestedSlot(QPoint);
/**
* @brief 右键菜单“剪切”响应槽函数
* @author yanzhihui (chanyuantiandao@126.com)
* @date 2023-07-26
*/
void cutActionSlot();
/**
* @brief 右键菜单“拷贝”响应槽函数
* @author yanzhihui (chanyuantiandao@126.com)
* @date 2023-07-26
*/
void copyActionSlot();
/**
* @brief 右键菜单“粘贴”响应槽函数
* @author yanzhihui (chanyuantiandao@126.com)
* @date 2023-07-26
*/
void pasteActionSlot();
/**
* @brief 右键菜单“在之前插入”响应槽函数
* @author yanzhihui (chanyuantiandao@126.com)
* @date 2023-07-26
*/
void insertBeforeActionSlot();
/**
* @brief 右键菜单“在之后插入”响应槽函数
* @author yanzhihui (chanyuantiandao@126.com)
* @date 2023-07-26
*/
void insertAfterActionSlot();
/**
* @brief 右键菜单“删除行”响应槽函数
* @author yanzhihui (chanyuantiandao@126.com)
* @date 2023-07-26
*/
void deleteRowActionSlot();
/**
* @brief 右键菜单“清空内容”响应槽函数
* @author yanzhihui (chanyuantiandao@126.com)
* @date 2023-07-26
*/
void clearContentsActionSlot();
/**
* @brief 右键菜单“清理表格”响应槽函数
* @author yanzhihui (chanyuantiandao@126.com)
* @date 2023-07-26
*/
void clearTableActionSlot();
/**
* @brief 右键菜单“读取文件”响应槽函数
* @author yanzhihui (chanyuantiandao@126.com)
* @date 2023-07-26
*/
void readFileActionSlot();
protected:
/**
* @brief 重写按键事件
* @param event 事件
* @author YanZhiHui (chanyuantiandao@126.com)
* @date 2024-04-22
*/
virtual void keyPressEvent(QKeyEvent *event) override;
/**
* @brief 重写按键释放事件
* @param event 事件
* @author YanZhiHui (chanyuantiandao@126.com)
* @date 2024-04-22
*/
virtual void keyReleaseEvent(QKeyEvent *event) override;
/**
* @brief 重写方法,屏蔽编辑框的右键菜单
* @author YanZhiHui (chanyuantiandao@126.com)
* @data 2024-05-14
*/
bool edit(const QModelIndex &index, EditTrigger trigger = QAbstractItemView::SelectedClicked, QEvent *event = nullptr) override;
private:
/**
* @brief 按回车键添加一行
* @author YanZhiHui (chanyuantiandao@126.com)
* @date 2024-04-22
*/
bool _isAppendLineByEnterPressed{ false };
/**
* @brief 右键菜单
* @author yanzhihui (chanyuantiandao@126.com)
* @date 2023-08-14
*/
QMenu *_tableWidgetContextMenu{};
/**
* @brief 剪切板对象
* @author yanzhihui (chanyuantiandao@126.com)
* @date 2023-08-14
*/
QClipboard *_clipboard{};
/**
* @brief 是否为单行模式标记符
* @author BaGuijun (baguijun@163.com)
* @date 2024-04-22
*/
bool _isAloneRow = false;
};
}
#endif