182 lines
5.5 KiB
C++
182 lines
5.5 KiB
C++
/**
|
||
* @file PaiHeaderView.h
|
||
* @brief PaiHeaderView 是P.A.I系统定制发布的表头控件
|
||
* @attention 目前只支持水平标题,而且只在TableView使用过,如有其它控件的需求请扩展
|
||
*
|
||
*******************************************************************
|
||
* ENHANCEMENTS *
|
||
*******************************************************************
|
||
* 1.可以选择要显示或隐藏的列
|
||
* 2.可以控制列的最小宽度不小于标题文字的宽度
|
||
* @date 2012-01-11
|
||
*/
|
||
#ifndef PAI_FRAME_WIDGET_PAIHEADERVIEW_H
|
||
#define PAI_FRAME_WIDGET_PAIHEADERVIEW_H
|
||
|
||
#include <QHeaderView>
|
||
#include "Turtle.h"
|
||
|
||
class QToolButton;
|
||
class QCheckBox;
|
||
|
||
namespace pai
|
||
{
|
||
namespace gui
|
||
{
|
||
/**
|
||
* @class PaiHeaderView
|
||
* @brief 具有PAI功能的表格标题栏(目前只可应用在水平标题)
|
||
*/
|
||
class PAI_WIDGET_EXPORT PaiHeaderView: public QHeaderView
|
||
{
|
||
Q_OBJECT
|
||
public:
|
||
/**
|
||
* @brief 构造函数
|
||
* @param[in] orientation 方向
|
||
* @param[in] pParent 父窗口句柄
|
||
*/
|
||
PaiHeaderView(Qt::Orientation orientation, QWidget *pParent= NULL);
|
||
|
||
/**
|
||
* @brief 析构函数
|
||
*/
|
||
virtual ~PaiHeaderView();
|
||
|
||
/**
|
||
* @brief 设置是否可以在表格上可以有选择行的显示某些列的功能
|
||
* @param[in] selectable 是否打开该功能
|
||
*/
|
||
void SetSectionVisibleSelectable(bool selectable);
|
||
|
||
/**
|
||
* @brief 设置表头项目不可以被隐藏
|
||
* @param[in] sectionList 不可以被隐藏的表头名
|
||
*/
|
||
void SetUnselectableSections(const QStringList & sectionList);
|
||
|
||
/**
|
||
* @brief 读取PaiSettings记录,恢复未隐藏显示的列
|
||
*/
|
||
void RecallMemberedSections();
|
||
|
||
/**
|
||
* @brief 记录当前显示的表头
|
||
*/
|
||
void RememberCurrentSections();
|
||
|
||
/**
|
||
* @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);
|
||
|
||
/**
|
||
* @brief 在发生插入或删除列操作时,调整CheckBox的位置
|
||
* @param[in] insert 是否为插入操作。true表示插入操作,fasle表示删除操作
|
||
* @param[in] column 插入或删除的行序号
|
||
*/
|
||
void AdjustCheckBoxMap(bool insert, int column);
|
||
|
||
protected:
|
||
/**
|
||
* @brief 重载,在最后一列绘制可以选择显示列的按钮
|
||
* @param[in] pPainter 画笔
|
||
* @param[in] rect 区域
|
||
* @param[in] logicalIndex 逻辑索引
|
||
*/
|
||
void paintSection(QPainter *pPainter, const QRect & rect, int logicalIndex) const;
|
||
|
||
/**
|
||
* @brief 使可以控制列按当前比列增大或缩小
|
||
* @param[in] pEvent 重置大小事件
|
||
*/
|
||
void resizeEvent(QResizeEvent *pEvent);
|
||
|
||
/**
|
||
* @brief 重载鼠标事件处理函数,在右键点击时发射信号
|
||
* @param[in] pEvent 鼠标按压事件
|
||
*/
|
||
void mousePressEvent (QMouseEvent *pEvent);
|
||
|
||
private:
|
||
/**
|
||
* @brief 计算列的最合适宽度
|
||
* @param[in] logicalIndex 表头的索引号
|
||
* @return 最适宽度
|
||
*/
|
||
int SectionSuitableWidth(int logicalIndex);
|
||
|
||
/**
|
||
* @brief 获得做后一个可见列的逻辑索引(logical index)
|
||
* @return 逻辑索引
|
||
*/
|
||
int LastVisibleSection() const;
|
||
|
||
/**
|
||
* @brief If hide is true the section specified by logicalIndex is hidden; otherwise the section is shown
|
||
* @param[in] logicalIndex logical index
|
||
* @param[in] hide hidden or show
|
||
*/
|
||
void SetSectionHidden(int logicalIndex, bool hide);
|
||
|
||
private slots:
|
||
/**
|
||
* @brief 设置最小宽度为字体宽度
|
||
* @param[in] logicalIndex 表头的索引号
|
||
* @param[in] oldSize 原始大小
|
||
* @param[in] newSize 移动后获得的新尺寸
|
||
*/
|
||
void AdjustSectionSuitable(int logicalIndex, int oldSize, int newSize);
|
||
|
||
/**
|
||
* @brief 交换当前列的显示状态
|
||
*/
|
||
void ReverseSectionVisible();
|
||
|
||
/**
|
||
* @brief 弹出列选择显示菜单
|
||
*/
|
||
void ShowSectionVisibleMenu();
|
||
|
||
/**
|
||
* @brief 处理CheckBox选中信号
|
||
*/
|
||
void CheckBoxStateChanged();
|
||
|
||
private:
|
||
bool m_SectionSelectableVisible; ///< 控制是否可以在表格上可以有选择行的显示某些列的功能
|
||
QToolButton *m_pSectionSelectToolButton; ///< 选择显示列按钮
|
||
QStringList m_UnselectableSections; ///< 不可以被隐藏的表头名字列表
|
||
QMap<int, QCheckBox*> m_ColumnCheckBoxMap; ///< 列序号和对应列的CheckBox的映射
|
||
|
||
signals:
|
||
/**
|
||
* @brief 右键点击表头时发射此消息
|
||
* @param[in] logicalIndex 逻辑列序号
|
||
* @param[in] globalPos 鼠标全局坐标
|
||
*/
|
||
void TitleRightClicked(int logicalIndex, const QPoint & globalPos);
|
||
|
||
/**
|
||
* @brief 如果存在选中框,且选中框状态发生变化则释放此信号
|
||
* @param[in] logicalIndex 选中状态改变的逻辑列序号
|
||
* @param[in] checkstate 选中状态
|
||
*/
|
||
void CheckStateChanged(int logicalIndex, Qt::CheckState checkstate);
|
||
|
||
/**
|
||
* @brief 列隐藏或列显示时发送此信号
|
||
* @param[in] logicalIndex 逻辑列序号
|
||
* @param[in] visible shown or hidden
|
||
*/
|
||
void SectionVisibleChanged(int logicalIndex, bool visible);
|
||
};
|
||
|
||
}
|
||
}
|
||
|
||
#endif ///< PAI_FRAME_WIDGET_PAIHEADERVIEW_H
|