BatteryMonitor/custom/delegate.h

176 lines
5.9 KiB
C
Raw Normal View History

2024-10-31 16:48:38 +08:00
#ifndef DELEGATE_H
#define DELEGATE_H
/**
* @projectName Delegate-
* @author m晴朗
* @email mengdadae@qq.com
* 1.
* 2.
* 3.
**/
#include <QStyledItemDelegate>
#include <QAbstractItemModel>
class QComboBox;
class QProgressBar;
class QTableView;
class QPushButton;
class QLineEdit;
class QCheckBox;
class Delegate : public QStyledItemDelegate
{
Q_OBJECT
public:
Delegate(QObject *parent = nullptr);
protected:
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override;
public:
/**
*
* @param delegateType
* @return
**/
void setDelegateType(const QString &delegateType);
/**
* paint绘制的委托需要这个参数
* @param delegateColumnID
* @return
**/
void setDelegateColumn(const int delegateColumnID);
/*QSpinBox设置相关参数函数*/
void setSboxMaxValue(const int max);
void setSboxMinValue(const int min);
void setSboxPrefixStr(const QString &prefix);
void setSboxSuffixStr(const QString &suffix);
void setSboxSingleStep(const int SingleStep);
void setSboxInitValue(const int initValue);
void setSboxStepType(QAbstractSpinBox::StepType st);
/*QComboBox相关参数设置*/
void setCboxItems(const QStringList &items);
void setCboxEditable(bool editable);
/*QProgressBar设置相关参数函数*/
void setPgBarRange(const int min,const int max);
void setPgBarTextVisible(bool isTextVisible);
void setPgBarAlignment(Qt::Alignment pgbarAlignment);
void setInvertedAppearance(bool invertedAppearance);
/*QCheckBox*/
void setCheckBoxText(const QString &checkBoxChecked, const QString &checkBoxUnchecked);
/*QPixmap设置相关参数函数*/
void setImgOk(const QPixmap &imgOk);
void setImgNo(const QPixmap &imgNo);
void setImgSize(int width,int heigth);
void setJudgmentColumn(int column);
void setJudgmentValue(const QString &value);
void setJudgmentCondition(const QString &condition);
/*QLineEdit相关参数函数*/
void setDelegatePwd(bool showDelegatePwd);
/*不使用委托实现的控件*/
void setComboBox(QAbstractItemView *view,QAbstractItemModel *model);
private:
/**
*
* @param
* @return
**/
void init();
void checkData(const QString &data,bool *selse)const;
/**
* ,paint函数中调用
* @param paint函数参数保持一致
* @return
**/
void drawProgressBar(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void drawCheckBox(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void drawPushButton(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void drawPixmap(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void drawLineEdit(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
signals:
void valueChanged(QString value);
/**
*
* @param
* @return
**/
void buttonClicked(int btnIndex, const QModelIndex &index);
private slots:
/**
*
* @param
* @return
**/
void on_valueChanged(int value);
void on_valueChanged(double value);
void on_valueChanged(QString value);
private:
QString delegateType;/*委托类型*/
int delegateColumnID;/*需要委托的列*/
QTableView *view;/*在哪个表格*/
QPoint mousePoint;/*鼠标按下处坐标*/
bool mousePressed;/*鼠标是否按下*/
/*QSpinBox相关参数*/
int sboxMaxValue;/*微调框的最大值*/
int sboxMinValue;/*微调框的最小值*/
QString sboxPrefixStr;/*微调框前缀*/
QString sboxSuffixStr;/*微调框后缀*/
int sboxSingleStep;/*微调框步长*/
int sboxInitValue;/*微调框初始值*/
QAbstractSpinBox::StepType sboxStepType;/*微调框步长类型*/
QStringList cboxItems;/*下组合框项目内容*/
bool cboxEditable;/*组合框是否可以编辑*/
/*QProgressBar相关参数*/
int pgbarMax;
int pgbarMin;
Qt::Alignment pgbarAlignment;
bool isTextVisible;
bool invertedAppearance;
/*QCheckBox参数*/
QString checkedText; //存储复选框当前文字
QString checkBoxChecked; //复选框选中对应的文字
QString checkBoxUnchecked; //复选框选中对应的文字
/*QPixmap相关参数*/
QPixmap imgOk;/*表示正确的图标*/
QPixmap imgNo;/*表示错误的图标*/
int imgWidth;/*图片宽度*/
int imgHeigth;/*图片高度*/
int judgmentColumn;/*需要判断的列*/
QString judgmentValue;/*阀值*/
QString judgmentCondition;/*判断条件*/
/*QLineEdit相关参数函数*/
bool delegatePwd; //是否密码显示
/*需要paint重新绘制的委托*/
QProgressBar *pgBar;
QPushButton *button;
QCheckBox *checkBox; //复选框
};
#endif // DELEGATE_H