193 lines
4.7 KiB
C++
193 lines
4.7 KiB
C++
|
||
#ifndef PAI_FRAME_ICONSOLE_PAITABLEWIDGET_H
|
||
#define PAI_FRAME_ICONSOLE_PAITABLEWIDGET_H
|
||
|
||
#include <QTableWidget>
|
||
#include <QContextMenuEvent>
|
||
#include <QAction>
|
||
#include <QCheckBox>
|
||
namespace pai
|
||
{
|
||
namespace gui
|
||
{
|
||
|
||
//class PaiCheckBox;
|
||
|
||
/**
|
||
* @class PaiTableWidget
|
||
* @brief PaiTableWidget 是P.A.I系统定制发布的表格控件
|
||
*/
|
||
class PaiTableWidget : public QTableWidget
|
||
{
|
||
Q_OBJECT
|
||
public:
|
||
PaiTableWidget(QWidget* pParent = NULL);
|
||
virtual ~PaiTableWidget();
|
||
|
||
/**
|
||
* @brief 表格高度自增加,不会出现滚动条
|
||
* @param[in] ok 是否自动增加
|
||
* @param[in] maxRowCount 当行数超过该数字时高度不再增加,出现滚动条
|
||
*/
|
||
void SetAutoHeight(const bool ok, const int maxRowCount = 10);
|
||
|
||
/**
|
||
* @brief 删除多行
|
||
* @param[in] rowIndex 从该行开始删除
|
||
* @param[in] count 删除的行数, 如果越界将到最大行时终止
|
||
*/
|
||
void RemoveRows(const int rowIndex, const int count);
|
||
|
||
/**
|
||
* @brief 删除所有行
|
||
*/
|
||
void RemoveRows();
|
||
|
||
/**
|
||
* @brief 设置是否显示单元格边框
|
||
* @param[in] hor 水平方向线
|
||
* @param[in] ver 垂直方向线
|
||
*/
|
||
void setShowGrid(bool hor, bool ver);
|
||
|
||
/**
|
||
* @brief 设置当表格内容为空时要显示的提示字符串
|
||
* @param msg 提示信息
|
||
*/
|
||
void ShowPromptMessage(const QString &msg);
|
||
|
||
/**
|
||
* @brief 设置当表格内容为空时要显示的提示字符串
|
||
* @param str 字符串
|
||
*/
|
||
void SetFilterEmptyMessage(const QString &str);
|
||
|
||
/**
|
||
* @brief 设置是否可以在表格上可以有选择行的显示某些列的功能
|
||
* @param[in] selectable 是否打开该功能
|
||
*/
|
||
void SetColumnVisibleSelectable(bool selectable);
|
||
|
||
/**
|
||
* @brief 设置不可以被隐藏的列
|
||
* @param[in] columnList 不可以被隐藏的列的名字列表
|
||
*/
|
||
void SetUnselectableColumns(const QStringList& columnList);
|
||
|
||
/**
|
||
*@brief 恢复记录的非隐藏表头
|
||
*/
|
||
void RecallMemberedSections();
|
||
|
||
/**
|
||
* @brief 设置是否可选中列,如果可选中则会在指定列的左侧添加一个CheckBox.(只可作用于水平表头)
|
||
* @param[in] logicalIndex 目标列的逻辑索引
|
||
* @param[in] checkable 是否可选中
|
||
* @param[in] pCheckBox 需要添加的CheckBox,如果checkable为false,则可不传递此参数。
|
||
*/
|
||
void SetColumnCheckable(const int logicalIndex, const bool checkable, QCheckBox *pCheckBox = NULL);
|
||
|
||
public slots:
|
||
/**
|
||
* @brief 根据关键字搜索
|
||
* @param[in] keyword 搜索的关键字
|
||
* @param[in] col 要搜索的列
|
||
*/
|
||
void Filter(const QString & keyword, int col = 0);
|
||
|
||
/**
|
||
* @brief 根据关键字搜索
|
||
* @param[in] keyword 搜索的关键字
|
||
* @param[in] cols 要搜索的列
|
||
*/
|
||
void Filter(const QString & keyword, QList<int> cols);
|
||
|
||
/**
|
||
* @brief 重写添加列函数,使及时调整HeaderView的CheckBox
|
||
* @param[in] column 要插入的列位置
|
||
*/
|
||
void insertColumn(int column);
|
||
|
||
/**
|
||
* @brief 重写移除列函数,使及时调整HeaderView的CheckBox
|
||
* @prama[in] column 要删除的位置
|
||
*/
|
||
void removeColumn(int column);
|
||
|
||
private:
|
||
/**
|
||
*@brief 记录非隐藏表头
|
||
*/
|
||
void RememberCurrentSections();
|
||
|
||
protected:
|
||
|
||
/**
|
||
* @brief 按照上一次的过滤规则,对某一行惊醒过滤
|
||
* @param[in] rowIndex 要过滤的行索引
|
||
* @return 是否通过过滤
|
||
*/
|
||
virtual bool Filter(int rowIndex);
|
||
|
||
/**
|
||
* @brief 实现该函数用来写字符串
|
||
*/
|
||
void paintEvent(QPaintEvent *event);
|
||
|
||
/**
|
||
* @brief 实现鼠标右键菜单
|
||
*/
|
||
void contextMenuEvent(QContextMenuEvent *event);
|
||
|
||
/**
|
||
* @brief 实现快捷键功能
|
||
*/
|
||
void keyPressEvent(QKeyEvent *event);
|
||
|
||
private slots:
|
||
/**
|
||
* @brief 重新设置高度以适应自动变化
|
||
*/
|
||
void ResetTableHeight();
|
||
|
||
/**
|
||
* @brief 行数发生变化
|
||
*/
|
||
void RowCountChanged();
|
||
|
||
/**
|
||
* @brief 设置剪切板内容
|
||
*/
|
||
void setClipboard();
|
||
|
||
/**
|
||
* @brief 当单元格的数据发送改变室的槽函数
|
||
* @param[in] pItem 对应的单元格
|
||
*/
|
||
void TableItemChanged(QTableWidgetItem *pItem);
|
||
|
||
private:
|
||
bool m_AutoHeight;
|
||
bool m_ShowFilterEmptyMsg;
|
||
int m_AutoHeightMaxRowCount;
|
||
QString m_MsgWhileFilterEmpty;
|
||
QString m_PromptMsg;
|
||
|
||
QList<int> m_FilterCols; // 最近一次过滤的的列
|
||
|
||
protected:
|
||
QString m_FilterKeyword; // 最近一次过滤的关键字
|
||
|
||
signals:
|
||
/**
|
||
* @brief 行数发生变化
|
||
* @param count 变化后的行数
|
||
*/
|
||
void RowCountChanged(const int count);
|
||
};
|
||
|
||
}
|
||
}
|
||
|
||
#endif /* PAITABLEWIDGET_H_ */
|