|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <QTableView>
|
|
|
|
|
#include "Defines.h"
|
|
|
|
|
#include "iBase_global.h"
|
|
|
|
|
#include "iPlugin_global.h"
|
|
|
|
|
|
|
|
|
|
class ZxTableModel;
|
|
|
|
|
class ZxComboBoxDelegate;
|
|
|
|
|
|
|
|
|
|
/// @brief The ZxTableView class 通用数据表视图对象类
|
|
|
|
|
class I_PLUGIN_EXPORT ZxTableView : public QTableView
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
enum MenuMode
|
|
|
|
|
{
|
|
|
|
|
MTM_NONE = 0, //不显示右键
|
|
|
|
|
MTM_Readonly, //只读,只弹出部分复制类的菜单
|
|
|
|
|
MTM_Edit_Without_Row,//编辑,但不允许插入行
|
|
|
|
|
MTM_Edit_Without_Col,//编辑,但不允许插入列
|
|
|
|
|
MTM_Edit_Without_RC, //编辑,但不允许插入行列
|
|
|
|
|
MTM_Edit, //全部编辑类的菜单
|
|
|
|
|
MTM_Unknown
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
explicit ZxTableView(QWidget* parent = 0, \
|
|
|
|
|
QAbstractItemModel* model = NULL);
|
|
|
|
|
virtual ~ZxTableView();
|
|
|
|
|
|
|
|
|
|
virtual void setModel(QAbstractItemModel* model);
|
|
|
|
|
|
|
|
|
|
// initMenu
|
|
|
|
|
virtual void initContextMenu();
|
|
|
|
|
|
|
|
|
|
// 设置右键菜单模式
|
|
|
|
|
virtual void setMenuMode(MenuMode oMenuMode);
|
|
|
|
|
|
|
|
|
|
// 表格部分界面属性,Qt5必须的 部分
|
|
|
|
|
virtual void fuzzyUiOfQt5();
|
|
|
|
|
|
|
|
|
|
// 这是根据分辨率统一进行调整表格宽度,慎用
|
|
|
|
|
virtual void adjustColWidths();
|
|
|
|
|
// 对于表格,考虑分辨率比较特殊,此处单独通过函数实现
|
|
|
|
|
static int getResoSizeW(int n);
|
|
|
|
|
static int getResoSizeH(int n);
|
|
|
|
|
|
|
|
|
|
// 返回当前视图中的模型对象
|
|
|
|
|
ZxTableModel* getModel(void) const;
|
|
|
|
|
|
|
|
|
|
// 获取选中的行范围
|
|
|
|
|
bool getSelectedRowRange(int& min, int& max);
|
|
|
|
|
|
|
|
|
|
// 为表格控件的nCol列添加combobox委托
|
|
|
|
|
virtual void setComboxDelegateForColumn(const QString& sTitle, \
|
|
|
|
|
const QStringList& lstItemText);
|
|
|
|
|
virtual void resetComboxDelegate();
|
|
|
|
|
QVector<ZxComboBoxDelegate*>* getVecDelegateCmbs();
|
|
|
|
|
|
|
|
|
|
//设置是否绘制多余网格ZXF20240703
|
|
|
|
|
void setShowFreeGrid(bool bVisible);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
//绘制纵向网格
|
|
|
|
|
void drawVerGrid();
|
|
|
|
|
|
|
|
|
|
//绘制横向网格
|
|
|
|
|
void drawHorGrid();
|
|
|
|
|
|
|
|
|
|
// 重载
|
|
|
|
|
virtual void paintEvent(QPaintEvent* event);
|
|
|
|
|
virtual void dragEnterEvent(QDragEnterEvent* event);
|
|
|
|
|
virtual void dropEvent(QDropEvent* event);
|
|
|
|
|
virtual void keyPressEvent(QKeyEvent *event);
|
|
|
|
|
virtual void resizeEvent(QResizeEvent *event);
|
|
|
|
|
virtual void mouseDoubleClickEvent(QMouseEvent *);
|
|
|
|
|
virtual QModelIndex moveCursor(CursorAction cursorAction, \
|
|
|
|
|
Qt::KeyboardModifiers modifiers);
|
|
|
|
|
virtual void selectionChanged(const QItemSelection &selected, \
|
|
|
|
|
const QItemSelection &deselected);
|
|
|
|
|
virtual void scrollTo (const QModelIndex & index, \
|
|
|
|
|
ScrollHint hint = EnsureVisible);
|
|
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
|
|
|
|
|
void restoreRowStates(bool bClearSelection = false);
|
|
|
|
|
void updateCells(int r, int c = -1);
|
|
|
|
|
|
|
|
|
|
// 右键
|
|
|
|
|
virtual void showCustomContextMenu(const QPoint &pos);
|
|
|
|
|
|
|
|
|
|
// 插入行列、删除行列
|
|
|
|
|
virtual void slotInsertRowsAbove(); //批量插入行
|
|
|
|
|
virtual void slotInsertRowsBelow();
|
|
|
|
|
virtual void slotInsertRowAbove(); //单条插入行
|
|
|
|
|
virtual void slotInsertRowBelow();
|
|
|
|
|
virtual void slotInsertColumns(); //插入列
|
|
|
|
|
virtual void slotRemoveRows(); //删除行
|
|
|
|
|
virtual void slotRemoveColumns(); //删除列
|
|
|
|
|
|
|
|
|
|
// 基本编辑,针对选择单元格
|
|
|
|
|
virtual void slotCopy();
|
|
|
|
|
virtual void slotPaste();
|
|
|
|
|
virtual void slotCut();
|
|
|
|
|
virtual void slotClearData();
|
|
|
|
|
|
|
|
|
|
// 格式调整(比如小数位置、是否凑齐)
|
|
|
|
|
virtual void slotFormatColumns();
|
|
|
|
|
|
|
|
|
|
// 其它
|
|
|
|
|
virtual void slotFreezeColumn();
|
|
|
|
|
virtual void slotUnfreezeColumn();
|
|
|
|
|
virtual void slotLockColumn();
|
|
|
|
|
virtual void slotUnlockColumn();
|
|
|
|
|
|
|
|
|
|
// 保存
|
|
|
|
|
virtual void slotSaveDatabase();
|
|
|
|
|
virtual void slotExportData();
|
|
|
|
|
|
|
|
|
|
// 冻结时信号响应
|
|
|
|
|
void slotUpdateSectionWidth(int logicalIndex,int, int newSize);
|
|
|
|
|
void slotUpdateSectionHeight(int logicalIndex, int, int newSize);
|
|
|
|
|
|
|
|
|
|
// 当行列改变时,响应信号进行处理
|
|
|
|
|
void slotDataSizeChanged();
|
|
|
|
|
|
|
|
|
|
// View是否最后一列自动扩展模式
|
|
|
|
|
void slotLastColAutoExt(bool& b);
|
|
|
|
|
void slotAdjustColAutoExt(bool b);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
// 内部实现
|
|
|
|
|
virtual void _insertRows(int nCount, bool bAbove);
|
|
|
|
|
virtual void _insertCols(int nCount);
|
|
|
|
|
virtual void _freezeCols(int l, int r);
|
|
|
|
|
virtual void _copyData(bool bClearCell = false);
|
|
|
|
|
|
|
|
|
|
// 粘贴时将剪切板文本格式解析
|
|
|
|
|
VVecVariant _parseGridStrs(const QString& strText, \
|
|
|
|
|
QChar spliter = '\t');
|
|
|
|
|
|
|
|
|
|
// 删除行或列后重新计算新的选择区域
|
|
|
|
|
virtual QModelIndexList getNewSelRange(QModelIndex topLeft, \
|
|
|
|
|
QModelIndex botRight, \
|
|
|
|
|
int nCount, \
|
|
|
|
|
Qt::Orientation orientation = Qt::Horizontal);
|
|
|
|
|
|
|
|
|
|
// 冻结相关
|
|
|
|
|
void initFreezeView(int left,int right);
|
|
|
|
|
void freshFreezeView(int left, int right);
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
|
|
|
|
// 选择区域改变
|
|
|
|
|
void sigSelectionChanged();
|
|
|
|
|
|
|
|
|
|
// 增减行、增减列、剪切、粘贴、清空 等情况下触发
|
|
|
|
|
void sigViewRangeChanged(QModelIndexList indexOldSelList, \
|
|
|
|
|
QModelIndexList indexNewSelList, \
|
|
|
|
|
QModelIndex oldCurIndex);
|
|
|
|
|
void sigColInserted(int nFrom, int nCount);
|
|
|
|
|
void sigColRemoved(int nFrom, int nCount);
|
|
|
|
|
|
|
|
|
|
// 删除行,通过此信号通知调用方删除数据库数据
|
|
|
|
|
// 如果sError非常证明未删除成功
|
|
|
|
|
void sigRemovingRows(int nRowFrom, int nRowTo, QString& sError);
|
|
|
|
|
|
|
|
|
|
// 这是增加新的自定义菜单项。
|
|
|
|
|
void sigMenuItemRequested(QMenu* pMenu, int r, int c);
|
|
|
|
|
|
|
|
|
|
// 触发信号,由用户进行入库处理
|
|
|
|
|
void sigSaveDatabase();
|
|
|
|
|
|
|
|
|
|
// 这是允许外界对粘贴板内容进行解析,解析为二维表格数据
|
|
|
|
|
void sigParseContents(const QString& s, VVecVariant& vvec);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
// 右键
|
|
|
|
|
MenuMode m_oMenuMode;
|
|
|
|
|
QMenu* m_pContextMenu;
|
|
|
|
|
|
|
|
|
|
// 冻结
|
|
|
|
|
int m_nFreezeColL;
|
|
|
|
|
int m_nFreezeColR;
|
|
|
|
|
QTableView* m_pFreezeView;
|
|
|
|
|
|
|
|
|
|
// 托管
|
|
|
|
|
QMap<QString, QStringList> m_mapDelegateCols;
|
|
|
|
|
QVector<ZxComboBoxDelegate*> m_vecDelegateCmbs;
|
|
|
|
|
|
|
|
|
|
//是否显示网格
|
|
|
|
|
bool m_bShowFreeGrid;
|
|
|
|
|
};
|