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.
nmWATI/Include/iBase/iPlugin/ZxTableModel.h

245 lines
7.9 KiB
C

#pragma once
#include <QMap>
#include <QAbstractTableModel>
#include <QAbstractItemModel>
#include "Defines.h"
#include "iBase_global.h"
#include "iPlugin_global.h"
typedef bool(*LessThan)(const QPair<QString, int>&, const QPair<QString, int>&);
// 通用数据表数据模型对象类
class I_PLUGIN_EXPORT ZxTableModel : public QAbstractTableModel
{
Q_OBJECT
public:
ZxTableModel(int nRows, int nColumns, \
const QStringList& lstTitles, \
QObject *parent = 0);
explicit ZxTableModel(QObject *parent = 0);
virtual ~ZxTableModel();
public:
void initParas();
// 内部根据role获取对应的data角色与权限
QVariant data(const QModelIndex& index, \
int role = Qt::DisplayRole) const;
QVariant dataRoleOfIndexValue(const QModelIndex& index) const;
QVariant dataRoleOfBkColor(const QModelIndex& index) const;
QVariant dataRoleOfForeColor(const QModelIndex& index) const;
QVariant dataRoleOfAlign(const QModelIndex& index) const;
QVariant dataRoleOfFont(const QModelIndex& index) const;
QVariant dataRoleOfToolTips(const QModelIndex& index) const;
QVariant dataRoleOfCheckState(const QModelIndex& index) const;
bool setData(const QModelIndex& index, \
const QVariant& value, \
int role = Qt::EditRole);
void setData(const QModelIndex& indexFrom, \
const VVecVariant& vecData/*, int nTimes = 1*/);
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
bool setHeaderData( int section, Qt::Orientation orientation,
const QVariant & value, int role = Qt::EditRole );
// 返回指定索引编号的数值
QVariant value(const QModelIndex &index) const;
// 返回指定单元格内的文本数值
QString textValue(int row, int column) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
public:
// 函数重载,自父类
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
public:
// 标题相关转换
void setTitles(const QStringList &lstTitles);
QStringList getTitles();
void setTitle(int iColumn, const QString &sTitle);
QString getTitle(int iColumn) const;
QString title(int column) const;
int column(const QString &sTitle) const;
// 数据传递
QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex()) const;
void setData(const VVecVariant &vecsData);
void setData(const VVecFloat &vecData);
void setData(const VVecDouble &vecData);
VVecVariant getData() const;
// 返回显示的数据,考虑了小数位数之类
VVecVariant getShowData() const;
VVecVariant getValidData() const;
void setRowData(int iRow, const VecVariant &vecData);
VecVariant getRowData(int iRow) const;
VecVariant getColumnData(const QString &sTitle) const;
VecVariant getColumnData(int iColumn) const;
void setColumnData(int iColumn, const VecVariant &vecData);
QVariant getCellData(int nRow, int nColumn) const;
void setCellData(int nRow, int nColumn, const QVariant &o);
bool setCellData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
// 行
bool canEditRows();
bool insertRows ( int row, int count, const QModelIndex & parent = QModelIndex() );
bool removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() );
void changeListMems(VecInt& list, int nIndex, \
int nCount, bool bInsert);
// 列
bool canEidtColumns(int iCol, int iCount);
bool insertColumns ( int column, int count, const QModelIndex & parent = QModelIndex() );
bool removeColumns ( int column, int count, const QModelIndex & parent = QModelIndex() );
void dealColCountChanged(int nIndex, int nCount, bool bInsert);
void changeColDigits(int nIndex, int nCount, bool bInsert);
void changeColTrimRights(int nIndex, int nCount, bool bInsert);
// 删除指定数据
void removeData(int iColumn = -1, int iRow = -1);
// 清除指定数据
void clearData(int iColumn = -1, int iRow = -1);
// 行列是否不可编辑
void setRowReadonly(int n, bool bReadonly = true);
void setColReadonly(int n, bool bReadonly = true);
bool isRowReadonly(int n);
bool isColReadonly(int n);
// 设为新插入行
void setRowNew(int n, bool bNew);
bool isRowNew(int n);
// 设置/解除列锁定
void lockCol(int iCol);
void unlockCol(int iCol);
// 小数位数
void setDecimas(int n, bool bClearColDecimas = false);
int getDecimas();
void setColDecima(int nCol,int n);
int getColDecima(int nCol);
// 是否trim 0,对于小数型
void setTrimRights(bool b, bool bClearColTrimRights = false);
bool getTrimRights();
void setColTrimRight(int nCol,bool b);
bool getColTrimRight(int nCol, bool& b);
// 设置标题行的颜色
void setHeaderColor(int nColorRow ,int color);
// 设置Cell的颜色如果col=-1整行如果row=-1整列
// 内部int n = row * 1024 * 32 + c;
void setCellColor(QColor clr, int row, int col = -1);
void clearCellColors();
void setCellBackColor(QColor clr, int row, int col = -1);
void clearCellBackColors();
// Check Col设置
void setCheckCol(int nCol);
int getCheckCol();
// 如果有CheckCol时每一行的Check状态
QMap<int, int>* getMapRowCheckStates();
void setRowCheckState(int r, int n);
int getRowCheckState(int r) const;
// 每一行的状态
QVector<TableRowState>* getTableRowStatesPtr();
void setTableRowState(int nIndex, TableRowState o);
TableRowState getTableRowState(int r);
void restoreRowStates();
// 数据Mask
QMap<float, QVariant>* getMapValueMasksPtr();
bool getValueMask(float f, QVariant& o) const;
bool setValueMask(float f, QVariant o);
bool convertByMask(QVariant& v) const;
// 设置数据修改标记
void setModified(bool b = true);
bool isModified(void) const;
void dealwithPaste(const QModelIndex &topLeft, \
const QModelIndex &bottomRight);
signals:
void sigDataReset(); //每次调用setData时触发
void modified();
bool cellDataChanging(const QModelIndex& index, \
const QVariant& oOld, \
const QVariant& oNew, bool& bOK);
void dataPasted(const QModelIndex &topLeft, \
const QModelIndex &bottomRight);
protected:
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
static bool preThan(const QPair<QString, int> &l,
const QPair<QString, int> &r);
static bool proThan(const QPair<QString, int> &l,
const QPair<QString, int> &r);
protected:
// 行列数
int m_nRowCount;
int m_nColCount;
// 标题
QStringList m_listTitles;
// 数据
VVecVariant m_vvecData;
// 只读行列、锁定列
VecInt m_listColsLocked;
VecInt m_listColsReadonly;
VecInt m_listRowsReadonly;
// 新插入行号列表
VecInt m_listRowsNew;
// 小数位数
int m_nDigit; //统一
QMap<int, int> m_mapColDigits;//特殊列
// 是否trim 0,对于小数型
bool m_bTrimRight;
QMap<int, bool> m_mapColTrimRights;//特殊列
// 左/上Header颜色
QMap <int,int> m_mapHeaderColors;
// 按照Cell设置属性
// int n = row * 1024 * 32 + c;
QMap<int, QColor> m_mapCellColors;
QMap<int, QColor> m_mapCellBackColors;
// 设定Check列只允许一列
int m_nCheckCol;
QMap<int, int> m_mapRowCheckStates;
// 每一行的状态,比如显示为红色
QVector<TableRowState> m_vecRowState;
// 对于特殊标示的显示,比如-9999显示为----99999显示为空
QMap<float, QVariant> m_mapValueMasks;
// 修改标记
bool m_bModified;
};