Fix patient list sort by add date.
This commit is contained in:
21
src/forms/select/PatientAddDateDelegate.cpp
Normal file
21
src/forms/select/PatientAddDateDelegate.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "PatientAddDateDelegate.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QPainter>
|
||||
|
||||
PatientAddDateDelegate::PatientAddDateDelegate(QObject* aParent)
|
||||
: QStyledItemDelegate(aParent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PatientAddDateDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
QVariant data = index.data(Qt::DisplayRole);
|
||||
if (data.isValid())
|
||||
{
|
||||
QDateTime datetime = data.toDateTime();
|
||||
QString dateStr = datetime.toString("yyyy-MM-dd HH:mm");
|
||||
painter->drawText(option.rect, Qt::AlignCenter, dateStr);
|
||||
}
|
||||
}
|
||||
15
src/forms/select/PatientAddDateDelegate.h
Normal file
15
src/forms/select/PatientAddDateDelegate.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef PATIENTADDDATEDELEGATE_H
|
||||
#define PATIENTADDDATEDELEGATE_H
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class PatientAddDateDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PatientAddDateDelegate(QObject* aParent);
|
||||
|
||||
void paint(QPainter *aPainter, const QStyleOptionViewItem &aOption, const QModelIndex &aIndex) const override;
|
||||
};
|
||||
|
||||
#endif // PATIENTADDDATEDELEGATE_H
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "dialogs/DialogManager.h"
|
||||
#include "log/UserOperationLog.h"
|
||||
#include "components/VerticalTextToolButton.h"
|
||||
#include "PatientAddDateDelegate.h"
|
||||
|
||||
SelectFormWidget::SelectFormWidget(QWidget* parent)
|
||||
: TabFormWidget(parent)
|
||||
@@ -198,7 +199,9 @@ void SelectFormWidget::initDetailPanel(QHBoxLayout *contentLayout) {// prepare e
|
||||
connect(patientDetailForm, &PatientDetailForm::deleteClicked, this, &SelectFormWidget::delPatient);
|
||||
}
|
||||
|
||||
void SelectFormWidget::initTableView(QHBoxLayout *contentLayout) {// TableView for patient
|
||||
void SelectFormWidget::initTableView(QHBoxLayout *contentLayout)
|
||||
{
|
||||
// TableView for patient
|
||||
mPatTable->setAlternatingRowColors(true);
|
||||
mPatTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
mPatTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
@@ -238,6 +241,9 @@ void SelectFormWidget::initTableView(QHBoxLayout *contentLayout) {// TableView f
|
||||
mModel->selectRow(0);
|
||||
}
|
||||
});
|
||||
|
||||
PatientAddDateDelegate* patientAddDateDelegate = new PatientAddDateDelegate(mPatTable);
|
||||
mPatTable->setItemDelegateForColumn(6, patientAddDateDelegate);
|
||||
}
|
||||
|
||||
void SelectFormWidget::initDataModel() {//TODO:单独初始化预防SQL错误
|
||||
|
||||
Reference in New Issue
Block a user