feat: change some display text, cause by foo
This commit is contained in:
@@ -1,17 +1,36 @@
|
||||
#include "AccountRoleComboDelegate.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
#include "db/SQLHelper.h"
|
||||
namespace
|
||||
{
|
||||
enum ROLE_STRING { ADMIN = 0, DOCTOR};
|
||||
}
|
||||
|
||||
AccountRoleComboDelegate::AccountRoleComboDelegate(QWidget *parent):QItemDelegate(parent) {
|
||||
SQLHelper::QueryMap("select RoleID,RoleName from Role", mRoleMap);
|
||||
initRoleString();
|
||||
}
|
||||
|
||||
//相较于直接在paint里面操作,这是一个更好的选择,可以直接改变Display,而不影响前后景的绘制。
|
||||
void AccountRoleComboDelegate::drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect,
|
||||
const QString &text) const {
|
||||
//绘制文本
|
||||
painter->drawText(option.rect, Qt::TextWordWrap | Qt::AlignCenter , mRoleMap[text].toString());
|
||||
QString roleString;
|
||||
switch (mRoleMap[text].toInt())
|
||||
{
|
||||
case ADMIN: roleString = tr("admin");
|
||||
break;
|
||||
case DOCTOR: roleString = tr("doctor");
|
||||
break;
|
||||
default: roleString = "unknow";
|
||||
break;
|
||||
}
|
||||
painter->drawText(option.rect, Qt::TextWordWrap | Qt::AlignCenter , roleString);
|
||||
}
|
||||
|
||||
void AccountRoleComboDelegate::initRoleString()
|
||||
{
|
||||
mRoleMap.insert("0001", ADMIN);
|
||||
mRoleMap.insert("0002", DOCTOR);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ public:
|
||||
protected:
|
||||
void drawDisplay(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QRect &rect, const QString &text) const override ;
|
||||
private:
|
||||
void initRoleString();
|
||||
|
||||
private:
|
||||
QMap<QString,QVariant> mRoleMap ;
|
||||
|
||||
Reference in New Issue
Block a user