Refactor forms select package.
This commit is contained in:
51
src/forms/select/PatientInformation.h
Normal file
51
src/forms/select/PatientInformation.h
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// Created by Krad on 2022/6/14.
|
||||
//
|
||||
|
||||
#ifndef GUI_PATIENTINFORMATION_H
|
||||
#define GUI_PATIENTINFORMATION_H
|
||||
#define ADD_PATIENT()\
|
||||
ADD_PATIENT_PROPERTY(ID)\
|
||||
ADD_PATIENT_PROPERTY(Name)\
|
||||
ADD_PATIENT_PROPERTY(BirthDate)\
|
||||
ADD_PATIENT_PROPERTY(Sex)\
|
||||
ADD_PATIENT_PROPERTY(AddDate)\
|
||||
ADD_PATIENT_PROPERTY(Comment)\
|
||||
ADD_PATIENT_PROPERTY(Flag)
|
||||
|
||||
#define EDIT_PATIENT()\
|
||||
ADD_PATIENT_PROPERTY(PatientUID)\
|
||||
ADD_PATIENT()
|
||||
|
||||
enum PatientInformationEnum{
|
||||
#define ADD_PATIENT_PROPERTY(val) val,
|
||||
EDIT_PATIENT()
|
||||
#undef ADD_PATIENT_PROPERTY
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief this class was designed to be a edit form,
|
||||
* but now has been change to a detail display class.
|
||||
*/
|
||||
class PatientInformation:public QObject{
|
||||
Q_OBJECT
|
||||
public:
|
||||
#define ADD_PATIENT_PROPERTY(val) QString val;
|
||||
EDIT_PATIENT();
|
||||
#undef ADD_PATIENT_PROPERTY
|
||||
PatientInformation(){
|
||||
this->Flag = QString("0");
|
||||
}
|
||||
PatientInformation* Copy()
|
||||
{
|
||||
PatientInformation* n=new PatientInformation;
|
||||
n->PatientUID = this->PatientUID;
|
||||
n->ID = this->ID;
|
||||
n->Name = this->Name;
|
||||
n->BirthDate = this->BirthDate;
|
||||
n->Sex = this->Sex;
|
||||
n->Comment = this->Comment;
|
||||
return n;
|
||||
}
|
||||
};
|
||||
#endif //GUI_PATIENTINFORMATION_H
|
||||
@@ -30,285 +30,241 @@ SelectFormWidget::SelectFormWidget(QWidget* parent)
|
||||
, mBtnEdit(new QToolButton(this))
|
||||
, mBtnDelete(new QToolButton(this))
|
||||
, mBtnSelect(new QToolButton(this))
|
||||
, mPatTable(new SlideTableView(this))
|
||||
, mModel(nullptr)
|
||||
, mEditPatForm(new EditPatientForm(this))
|
||||
{
|
||||
//init command bar
|
||||
auto layout = new QHBoxLayout();
|
||||
ui->commandWidget->setLayout(layout);
|
||||
INIT_TOOL_BTN(Account, ":/icons/account.png")
|
||||
INIT_TOOL_BTN(Worklist, ":/icons/setting.png")
|
||||
mBtnAccount->setText(tr("Account"));
|
||||
mBtnWorklist->setText(tr("Worklist"));
|
||||
|
||||
layout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding));
|
||||
initGeneralButtons(layout);
|
||||
layout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding));
|
||||
addVerticalLine(layout);
|
||||
INIT_TOOL_BTN(Add, ":/icons/add.png")
|
||||
INIT_TOOL_BTN(Edit, ":/icons/details.png")
|
||||
INIT_TOOL_BTN(Delete, ":/icons/close_circle.png")
|
||||
INIT_TOOL_BTN(Select, ":/icons/selected.png")
|
||||
mBtnAdd->setText(tr("Add"));
|
||||
mBtnEdit->setText(tr("Edit"));
|
||||
mBtnDelete->setText(tr("Delete"));
|
||||
mBtnSelect->setText(tr("Select"));
|
||||
|
||||
//Init content widget
|
||||
initPatEditButtons(layout);
|
||||
initDataModel();
|
||||
//Init content widget
|
||||
auto* contentLayout = new QHBoxLayout();
|
||||
contentLayout->setContentsMargins(5, 5, 0, 5);
|
||||
this->ui->contentWidget->setLayout(contentLayout);
|
||||
// TableView for patient
|
||||
auto table = new SlideTableView(this);
|
||||
table->setAlternatingRowColors(true);
|
||||
table->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
table->verticalHeader()->setDefaultSectionSize(38);
|
||||
table->horizontalHeader()->setStretchLastSection(true);
|
||||
//data from SQLITE
|
||||
//
|
||||
//avoid pan comsumed by tableview!
|
||||
table->viewport()->ungrabGesture(Qt::PanGesture);
|
||||
|
||||
auto model = SQLHelper::getTable("Patient");
|
||||
model->setFilter("Flag=0");
|
||||
model->sort(5, Qt::DescendingOrder);
|
||||
model->select();
|
||||
model->setHeaderData(1, Qt::Horizontal, "ID");
|
||||
model->setHeaderData(2, Qt::Horizontal, tr("Name"));
|
||||
model->setHeaderData(3, Qt::Horizontal, tr("Birth Date"));
|
||||
model->setHeaderData(4, Qt::Horizontal, tr("Gender"));
|
||||
model->setHeaderData(5, Qt::Horizontal, tr("Add Date"));
|
||||
model->setHeaderData(6, Qt::Horizontal, tr("Comment"));
|
||||
table->setSortingEnabled(true); // enable sortingEnabled
|
||||
|
||||
table->setModel((QAbstractItemModel*)model);
|
||||
table->hideColumn(0);
|
||||
table->hideColumn(7);
|
||||
table->show();
|
||||
|
||||
table->setColumnWidth(1, 250);
|
||||
table->setColumnWidth(2, 250);
|
||||
table->setColumnWidth(3, 160);
|
||||
table->setColumnWidth(4, 120);
|
||||
table->setColumnWidth(5, 250);
|
||||
contentLayout->addWidget(table);
|
||||
initTableView(contentLayout);
|
||||
addVerticalLine(layout);
|
||||
// prepare edit panel
|
||||
auto edit_patient = new EditPatientForm(this);
|
||||
edit_patient->setObjectName("edit_patient");
|
||||
edit_patient->hide();
|
||||
contentLayout->addWidget(edit_patient);
|
||||
auto* btnShowEdit = new VerticalTextToolButton(this);
|
||||
btnShowEdit->setObjectName("showeditBtn");
|
||||
btnShowEdit->setIcon(QIcon(":/icons/edit.png"));
|
||||
btnShowEdit->setIconSize(QSize(30, 30));
|
||||
btnShowEdit->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
||||
btnShowEdit->setFixedHeight(225);
|
||||
btnShowEdit->setVerticalText("Patient Detail");
|
||||
contentLayout->addWidget(btnShowEdit);
|
||||
contentLayout->setAlignment(btnShowEdit, Qt::AlignmentFlag::AlignTop);
|
||||
|
||||
// btn show slot
|
||||
connect(btnShowEdit, &QToolButton::clicked, [=]() {
|
||||
edit_patient->show();
|
||||
btnShowEdit->hide();
|
||||
});
|
||||
//btn hide slot
|
||||
connect(edit_patient, &EditPatientForm::hideBtnClicked, [=]() {
|
||||
edit_patient->hide();
|
||||
btnShowEdit->show();
|
||||
});
|
||||
|
||||
//select default row 0
|
||||
if (model->rowCount() > 0)
|
||||
initDetailPanel(contentLayout);
|
||||
//select default row 0
|
||||
if (mModel->rowCount() > 0)
|
||||
{
|
||||
table->selectRow(0);
|
||||
setPatientDetail(table, model, edit_patient);
|
||||
mPatTable->selectRow(0);
|
||||
setPatientDetail(mPatTable, mModel, mEditPatForm);
|
||||
}
|
||||
//events----------------------------------------------------------------------
|
||||
//prepare button state
|
||||
auto prepareButtons = [=](bool disableALL){
|
||||
bool state_flag = (table->currentIndex().row()>=0);
|
||||
mBtnSelect->setEnabled(state_flag && !disableALL);
|
||||
mBtnDelete->setEnabled(state_flag && !disableALL);
|
||||
mBtnEdit->setEnabled(state_flag && !disableALL);
|
||||
mBtnAdd->setEnabled(!disableALL);
|
||||
};
|
||||
//table current row selection changing event
|
||||
connect(table, &SlideTableView::currentRowChanged, [=](int row) {
|
||||
setPatientDetail(table, model, edit_patient);
|
||||
prepareButtons(false);
|
||||
});
|
||||
|
||||
// after sort by column
|
||||
connect(table->horizontalHeader(),&QHeaderView::sectionClicked,[=](int index){
|
||||
edit_patient->clearPatientInformation();
|
||||
prepareButtons(false);
|
||||
if(model->rowCount()>0){
|
||||
table->selectRow(0);
|
||||
model->selectRow(0);
|
||||
}
|
||||
});
|
||||
|
||||
// btn add slot
|
||||
connect(mBtnAdd, &QToolButton::clicked, [=]() {
|
||||
EditPatientDialog dialog(this);
|
||||
dialog.clearPatientInformation();
|
||||
dialog.setWindowModality(Qt::WindowModal);
|
||||
dialog.setModel(model);
|
||||
// accept change
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
table->selectRow(0);
|
||||
model->selectRow(0);
|
||||
LOG_USER_OPERATION(AddPatient)
|
||||
mBtnSelect->setEnabled(true);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// mBtn edit slot
|
||||
connect(mBtnEdit, &QToolButton::clicked, [=]() {
|
||||
EditPatientDialog dialog(this);
|
||||
dialog.setPatientInformation(edit_patient->getPatientInformation());
|
||||
dialog.setWindowModality(Qt::WindowModal);
|
||||
dialog.setModel(model);
|
||||
// accept change
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
table->clicked(table->currentIndex());
|
||||
setPatientDetail(table, model, edit_patient);
|
||||
LOG_USER_OPERATION(AddPatient)
|
||||
mBtnSelect->setEnabled(true);
|
||||
}
|
||||
});
|
||||
|
||||
// mBtn add slot
|
||||
connect(edit_patient, &EditPatientForm::editCancel, [=]() {
|
||||
if (table->currentIndex().row()<0) return;
|
||||
mBtnSelect->setEnabled(true);
|
||||
});
|
||||
|
||||
// EditPatientForm editAccept slot
|
||||
connect(edit_patient, &EditPatientForm::editAccept, [=](PatientInformation* inf, bool& result) {
|
||||
int selectedRow = table->currentIndex().row();
|
||||
bool isAdd = inf->PatientUID.isEmpty();
|
||||
if (isAdd) {
|
||||
selectedRow = model->rowCount();
|
||||
inf->PatientUID = QUuid::createUuid().toString();
|
||||
inf->AddDate = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");
|
||||
model->insertRow(0);
|
||||
selectedRow = 0;
|
||||
}
|
||||
qDebug() << inf->PatientUID << inf->AddDate;
|
||||
#define ADD_PATIENT_PROPERTY(val)\
|
||||
model->setData(model->index(selectedRow,PatientInformationEnum:: val),inf-> val);
|
||||
EDIT_PATIENT()
|
||||
#undef ADD_PATIENT_PROPERTY
|
||||
if (model->submitAll())
|
||||
{
|
||||
table->selectRow(selectedRow);
|
||||
model->selectRow(selectedRow);
|
||||
}
|
||||
else {
|
||||
//TODO:add some error handle logic
|
||||
}
|
||||
if (isAdd) {
|
||||
LOG_USER_OPERATION(AddPatient)
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_USER_OPERATION(ChangePatientInfo)
|
||||
}
|
||||
mBtnSelect->setEnabled(true);
|
||||
});
|
||||
|
||||
// btn delete slot
|
||||
connect(mBtnDelete, &QToolButton::clicked, [=]() {
|
||||
if (table->currentIndex().row()<0) return;
|
||||
AlertDialog dialog(this);
|
||||
dialog.setWindowModality(Qt::WindowModal);
|
||||
QString pUid = model->index(table->currentIndex().row(), PatientInformationEnum::PatientUID).data().toString();
|
||||
// patient has been selected as the scan patient!
|
||||
if (selectedPatientUID == pUid){
|
||||
dialog.setButtonMode(OkOnly);
|
||||
dialog.setTitle(tr("Alert"));
|
||||
dialog.setAlertMessage(QString(tr("Can't delete selected Patient !")));
|
||||
dialog.exec();
|
||||
return;
|
||||
}
|
||||
// not the selected one, confirm!
|
||||
dialog.setButtonMode(OkAndCancel);
|
||||
dialog.setTitle("Confirm");
|
||||
QString pat_name = model->index(table->currentIndex().row(), PatientInformationEnum::Name).data().toString();
|
||||
dialog.setAlertMessage(QString(tr("Delete Patient \"%1\" ?")).arg(pat_name));
|
||||
if (dialog.exec() != QDialog::Accepted) return;
|
||||
// need delete clear edit panel detail
|
||||
edit_patient->clearPatientInformation();
|
||||
model->setData(model->index(table->currentIndex().row(), PatientInformationEnum::Flag), 9);
|
||||
|
||||
if (model->submitAll()) {
|
||||
model->select();
|
||||
if (model->rowCount() > 0) {
|
||||
table->selectRow(0);
|
||||
model->selectRow(0);
|
||||
setPatientDetail(table, model, edit_patient);
|
||||
LOG_USER_OPERATION(DeletePatient)
|
||||
}
|
||||
} else {
|
||||
//TODO:error handle
|
||||
dialog.setButtonMode(OkOnly);
|
||||
dialog.setTitle(tr("Alert"));
|
||||
dialog.setAlertMessage(QString(tr("Can't delete selected Patient , db submit error!")));
|
||||
dialog.exec();
|
||||
}
|
||||
prepareButtons(false);
|
||||
|
||||
});
|
||||
|
||||
// mBtn select slot
|
||||
connect(mBtnSelect, &QToolButton::clicked, [=]() {
|
||||
|
||||
EventCenter::Default()->triggerEvent(GUIEvents::PatientSelected, nullptr, edit_patient->getPatientInformation()->Copy());
|
||||
selectedPatientUID = edit_patient->getPatientInformation()->PatientUID;
|
||||
LOG_USER_OPERATION(SelectPatient)
|
||||
});
|
||||
|
||||
// mBtn account slot
|
||||
connect(mBtnAccount, &QToolButton::clicked, [=]() {
|
||||
AccountFormDialog dia(this);
|
||||
dia.setWindowModality(Qt::WindowModal);
|
||||
dia.exec();
|
||||
});
|
||||
|
||||
// event ResponsePreview slot
|
||||
connect(EventCenter::Default(), &EventCenter::ResponsePreview, [=](QObject* sender, QObject* data) {
|
||||
prepareButtons(true);
|
||||
});
|
||||
|
||||
// event ResponseStop slot
|
||||
connect(EventCenter::Default(), &EventCenter::ResponseStop, [=](QObject* sender, QObject* data) {
|
||||
prepareButtons(false);
|
||||
});
|
||||
|
||||
// event ReloadLanguage slot;
|
||||
connect(EventCenter::Default(), &EventCenter::ReloadLanguage, [=]() {
|
||||
|
||||
model->setHeaderData(1, Qt::Horizontal, "ID");
|
||||
model->setHeaderData(2, Qt::Horizontal, tr("Name"));
|
||||
model->setHeaderData(3, Qt::Horizontal, tr("Birth Date"));
|
||||
model->setHeaderData(4, Qt::Horizontal, tr("Gender"));
|
||||
model->setHeaderData(5, Qt::Horizontal, tr("Add Date"));
|
||||
model->setHeaderData(6, Qt::Horizontal, tr("Comment"));
|
||||
|
||||
mBtnAccount->setText(tr("Account"));
|
||||
//mBtnWorklist->setText(tr("Worklist"));
|
||||
mBtnAdd->setText(tr("Add"));
|
||||
mBtnEdit->setText(tr("Edit"));
|
||||
mBtnDelete->setText(tr("Delete"));
|
||||
mBtnSelect->setText(tr("Select"));
|
||||
});
|
||||
|
||||
connect(EventCenter::Default(), &EventCenter::ReloadLanguage, this, &SelectFormWidget::reloadLanguage);
|
||||
//first prepare buttons!
|
||||
prepareButtons(false);
|
||||
}
|
||||
|
||||
void SelectFormWidget::prepareButtons(bool disableALL) {
|
||||
bool stateFlag = (mPatTable->currentIndex().row() >= 0);
|
||||
mBtnSelect->setEnabled(stateFlag && !disableALL);
|
||||
mBtnDelete->setEnabled(stateFlag && !disableALL);
|
||||
mBtnEdit->setEnabled(stateFlag && !disableALL);
|
||||
mBtnAdd->setEnabled(!disableALL);
|
||||
}
|
||||
|
||||
void SelectFormWidget::initGeneralButtons(QHBoxLayout *layout) {
|
||||
INIT_TOOL_BTN(Account, ":/icons/account.png")
|
||||
INIT_TOOL_BTN(Worklist, ":/icons/setting.png")
|
||||
mBtnAccount->setText(tr("Account"));
|
||||
mBtnWorklist->setText(tr("Worklist"));
|
||||
// mBtn account slot
|
||||
connect(mBtnAccount, &QToolButton::clicked, [=]() {
|
||||
AccountFormDialog dialog(this);
|
||||
dialog.setWindowModality(Qt::WindowModal);
|
||||
dialog.exec();
|
||||
});
|
||||
}
|
||||
|
||||
void SelectFormWidget::initPatEditButtons(QHBoxLayout *layout) {
|
||||
INIT_TOOL_BTN(Add, ":/icons/add.png")
|
||||
INIT_TOOL_BTN(Edit, ":/icons/details.png")
|
||||
INIT_TOOL_BTN(Delete, ":/icons/close_circle.png")
|
||||
INIT_TOOL_BTN(Select, ":/icons/selected.png")
|
||||
mBtnAdd->setText(tr("Add"));
|
||||
mBtnEdit->setText(tr("Edit"));
|
||||
mBtnDelete->setText(tr("Delete"));
|
||||
mBtnSelect->setText(tr("Select"));
|
||||
|
||||
// btn add & edit slot
|
||||
connect(mBtnAdd, &QToolButton::clicked, this, &SelectFormWidget::editPatient);
|
||||
connect(mBtnEdit, &QToolButton::clicked, this, &SelectFormWidget::editPatient);
|
||||
|
||||
// btn delete slot
|
||||
connect(mBtnDelete, &QToolButton::clicked, this, &SelectFormWidget::delPatient);
|
||||
|
||||
// mBtn select slot
|
||||
connect(mBtnSelect, &QToolButton::clicked, this, &SelectFormWidget::selectPatient);
|
||||
}
|
||||
|
||||
void SelectFormWidget::editPatient() {
|
||||
bool addFlag = sender() == mBtnAdd;
|
||||
EditPatientDialog dialog(this);
|
||||
if (addFlag){
|
||||
dialog.clearPatientInformation();
|
||||
}
|
||||
else{
|
||||
dialog.setPatientInformation(mEditPatForm->getPatientInformation());
|
||||
}
|
||||
|
||||
dialog.setWindowModality(Qt::WindowModal);
|
||||
dialog.setModel(mModel);
|
||||
// accept change
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
if (addFlag){
|
||||
mPatTable->selectRow(0);
|
||||
mModel->selectRow(0);
|
||||
}
|
||||
else{
|
||||
mPatTable->clicked(mPatTable->currentIndex());
|
||||
setPatientDetail(mPatTable, mModel, mEditPatForm);
|
||||
}
|
||||
LOG_USER_OPERATION(AddPatient)
|
||||
mBtnSelect->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void SelectFormWidget::delPatient() {
|
||||
if (mPatTable->currentIndex().row() < 0) return;
|
||||
AlertDialog dialog(this);
|
||||
dialog.setWindowModality(Qt::WindowModal);
|
||||
QString pUid = mModel->index(mPatTable->currentIndex().row(), PatientUID).data().toString();
|
||||
// patient has been selected as the scan patient!
|
||||
if (selectedPatientUID == pUid){
|
||||
dialog.setButtonMode(OkOnly);
|
||||
dialog.setTitle(tr("Alert"));
|
||||
dialog.setAlertMessage(QString(tr("Can't delete selected Patient !")));
|
||||
dialog.exec();
|
||||
return;
|
||||
}
|
||||
// not the selected one, confirm!
|
||||
dialog.setButtonMode(OkAndCancel);
|
||||
dialog.setTitle("Confirm");
|
||||
QString pat_name = mModel->index(mPatTable->currentIndex().row(), Name).data().toString();
|
||||
dialog.setAlertMessage(QString(tr("Delete Patient \"%1\" ?")).arg(pat_name));
|
||||
if (dialog.exec() != QDialog::Accepted) return;
|
||||
// need delete clear edit panel detail
|
||||
mEditPatForm->clearPatientInformation();
|
||||
mModel->setData(mModel->index(mPatTable->currentIndex().row(), Flag), 9);
|
||||
|
||||
if (mModel->submitAll()) {
|
||||
mModel->select();
|
||||
if (mModel->rowCount() > 0) {
|
||||
mPatTable->selectRow(0);
|
||||
mModel->selectRow(0);
|
||||
setPatientDetail(mPatTable, mModel, mEditPatForm);
|
||||
LOG_USER_OPERATION(DeletePatient)
|
||||
}
|
||||
} else {
|
||||
//TODO:error handle
|
||||
dialog.setButtonMode(OkOnly);
|
||||
dialog.setTitle(tr("Alert"));
|
||||
dialog.setAlertMessage(QString(tr("Can't delete selected Patient , db submit error!")));
|
||||
dialog.exec();
|
||||
}
|
||||
prepareButtons(false);
|
||||
}
|
||||
|
||||
void SelectFormWidget::selectPatient() {
|
||||
EventCenter::Default()->triggerEvent(PatientSelected, nullptr, mEditPatForm->getPatientInformation()->Copy());
|
||||
selectedPatientUID = mEditPatForm->getPatientInformation()->PatientUID;
|
||||
LOG_USER_OPERATION(SelectPatient)
|
||||
}
|
||||
|
||||
void SelectFormWidget::initDetailPanel(QHBoxLayout *contentLayout) {// prepare edit panel
|
||||
mEditPatForm->setObjectName("edit_patient");
|
||||
mEditPatForm->hide();
|
||||
contentLayout->addWidget(mEditPatForm);
|
||||
auto* btnShowEdit = new VerticalTextToolButton(this);
|
||||
btnShowEdit->setObjectName("showeditBtn");
|
||||
btnShowEdit->setIcon(QIcon(":/icons/edit.png"));
|
||||
btnShowEdit->setIconSize(QSize(30, 30));
|
||||
btnShowEdit->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
||||
btnShowEdit->setFixedHeight(225);
|
||||
btnShowEdit->setVerticalText("Patient Detail");
|
||||
contentLayout->addWidget(btnShowEdit);
|
||||
contentLayout->setAlignment(btnShowEdit, Qt::AlignTop);
|
||||
|
||||
// btn show slot
|
||||
connect(btnShowEdit, &QToolButton::clicked, [=]() {
|
||||
mEditPatForm->show();
|
||||
btnShowEdit->hide();
|
||||
});
|
||||
//btn hide slot
|
||||
connect(mEditPatForm, &EditPatientForm::hideBtnClicked, [=]() {
|
||||
mEditPatForm->hide();
|
||||
btnShowEdit->show();
|
||||
});
|
||||
}
|
||||
|
||||
void SelectFormWidget::initTableView(QHBoxLayout *contentLayout) {// TableView for patient
|
||||
mPatTable->setAlternatingRowColors(true);
|
||||
mPatTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
mPatTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
mPatTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
mPatTable->verticalHeader()->setDefaultSectionSize(38);
|
||||
mPatTable->horizontalHeader()->setStretchLastSection(true);
|
||||
//data from SQLITE
|
||||
//
|
||||
//avoid pan comsumed by tableview!
|
||||
mPatTable->viewport()->ungrabGesture(Qt::PanGesture);
|
||||
|
||||
mPatTable->setSortingEnabled(true); // enable sortingEnabled
|
||||
mPatTable->setModel((QAbstractItemModel*) mModel);
|
||||
mPatTable->hideColumn(0);
|
||||
mPatTable->hideColumn(7);
|
||||
mPatTable->show();
|
||||
|
||||
mPatTable->setColumnWidth(1, 250);
|
||||
mPatTable->setColumnWidth(2, 250);
|
||||
mPatTable->setColumnWidth(3, 160);
|
||||
mPatTable->setColumnWidth(4, 120);
|
||||
mPatTable->setColumnWidth(5, 250);
|
||||
contentLayout->addWidget(mPatTable);
|
||||
//table current row selection changing event
|
||||
connect(mPatTable, &SlideTableView::currentRowChanged, [=](int row) {
|
||||
setPatientDetail(mPatTable, mModel, mEditPatForm);
|
||||
prepareButtons(false);
|
||||
});
|
||||
|
||||
// after sort by column
|
||||
connect(mPatTable->horizontalHeader(), &QHeaderView::sectionClicked, [=](int index){
|
||||
mEditPatForm->clearPatientInformation();
|
||||
prepareButtons(false);
|
||||
if(mModel->rowCount() > 0){
|
||||
mPatTable->selectRow(0);
|
||||
mModel->selectRow(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void SelectFormWidget::initDataModel() {//TODO:单独初始化预防SQL错误
|
||||
mModel = SQLHelper::getTable("Patient");
|
||||
mModel->setFilter("Flag=0");
|
||||
mModel->sort(5, Qt::DescendingOrder);
|
||||
mModel->select();
|
||||
mModel->setHeaderData(1, Qt::Horizontal, "ID");
|
||||
mModel->setHeaderData(2, Qt::Horizontal, tr("Name"));
|
||||
mModel->setHeaderData(3, Qt::Horizontal, tr("Birth Date"));
|
||||
mModel->setHeaderData(4, Qt::Horizontal, tr("Gender"));
|
||||
mModel->setHeaderData(5, Qt::Horizontal, tr("Add Date"));
|
||||
mModel->setHeaderData(6, Qt::Horizontal, tr("Comment"));
|
||||
}
|
||||
|
||||
void SelectFormWidget::setPatientDetail(const SlideTableView *table, const QSqlTableModel *model,
|
||||
EditPatientForm *edit_patient) const {
|
||||
PatientInformation pat;
|
||||
@@ -319,5 +275,21 @@ void SelectFormWidget::setPatientDetail(const SlideTableView *table, const QSqlT
|
||||
edit_patient->setPatientInformation(&pat);
|
||||
}
|
||||
|
||||
void SelectFormWidget::reloadLanguage(){
|
||||
mModel->setHeaderData(1, Qt::Horizontal, "ID");
|
||||
mModel->setHeaderData(2, Qt::Horizontal, tr("Name"));
|
||||
mModel->setHeaderData(3, Qt::Horizontal, tr("Birth Date"));
|
||||
mModel->setHeaderData(4, Qt::Horizontal, tr("Gender"));
|
||||
mModel->setHeaderData(5, Qt::Horizontal, tr("Add Date"));
|
||||
mModel->setHeaderData(6, Qt::Horizontal, tr("Comment"));
|
||||
|
||||
mBtnAccount->setText(tr("Account"));
|
||||
//mBtnWorklist->setText(tr("Worklist"));
|
||||
mBtnAdd->setText(tr("Add"));
|
||||
mBtnEdit->setText(tr("Edit"));
|
||||
mBtnDelete->setText(tr("Delete"));
|
||||
mBtnSelect->setText(tr("Select"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -26,6 +26,20 @@ private:
|
||||
QToolButton* mBtnEdit;
|
||||
QToolButton* mBtnDelete;
|
||||
QToolButton* mBtnSelect;
|
||||
SlideTableView* mPatTable;
|
||||
QSqlTableModel* mModel;
|
||||
EditPatientForm* mEditPatForm;
|
||||
|
||||
void prepareButtons(bool disableALL);
|
||||
void initGeneralButtons(QHBoxLayout *layout);
|
||||
void initPatEditButtons(QHBoxLayout *layout);
|
||||
void editPatient();
|
||||
void delPatient();
|
||||
void selectPatient();
|
||||
void initDataModel();
|
||||
void initDetailPanel(QHBoxLayout *contentLayout);
|
||||
void initTableView(QHBoxLayout *contentLayout);
|
||||
void reloadLanguage();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -9,80 +9,79 @@
|
||||
#include "event/EventCenter.h"
|
||||
|
||||
EditPatientForm::EditPatientForm(QWidget* parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::EditPatientForm)
|
||||
QWidget(parent),
|
||||
mUI(new Ui::EditPatientForm)
|
||||
{
|
||||
// this->layout()->setContentsMargins(5,5,5,5);
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->hideBtn->setSizePolicy(QSizePolicy::Policy::Expanding,QSizePolicy::Policy::Preferred);
|
||||
ui->hideBtn->setObjectName("hideeditBtn");
|
||||
ui->hideBtn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
ui->hideBtn->setIcon(QIcon(":/icons/hidearrow.png"));
|
||||
ui->hideBtn->setIconSize({30,30});
|
||||
ui->hideBtn->setText(tr(" Hide Panel"));
|
||||
connect(ui->hideBtn,&QToolButton::clicked,[=](){
|
||||
mUI->setupUi(this);
|
||||
mUI->hideBtn->setSizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Preferred);
|
||||
mUI->hideBtn->setObjectName("hideeditBtn");
|
||||
mUI->hideBtn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
mUI->hideBtn->setIcon(QIcon(":/icons/hidearrow.png"));
|
||||
mUI->hideBtn->setIconSize({30, 30});
|
||||
mUI->hideBtn->setText(tr(" Hide Panel"));
|
||||
connect(mUI->hideBtn, &QToolButton::clicked, [=](){
|
||||
emit hideBtnClicked();
|
||||
});
|
||||
ui->tbx_Dob->setDisplayFormat("yyyy/MM/dd");
|
||||
mUI->tbxDob->setDisplayFormat("yyyy/MM/dd");
|
||||
|
||||
ui->tbx_ID->setEnabled(false);
|
||||
ui->tbx_ID->setObjectName("display_tbx");
|
||||
ui->tbx_Dob->setEnabled(false);
|
||||
ui->tbx_Dob->setObjectName("display_tbx");
|
||||
ui->tbx_Name->setEnabled(false);
|
||||
ui->tbx_Name->setObjectName("display_tbx");
|
||||
ui->tbx_Sex->setEnabled(false);
|
||||
ui->tbx_Sex->setObjectName("display_tbx");
|
||||
ui->rtbx_Comment->setEnabled(false);
|
||||
ui->rtbx_Comment->setObjectName("display_tbx");
|
||||
mUI->tbxID->setEnabled(false);
|
||||
mUI->tbxID->setObjectName("display_tbx");
|
||||
mUI->tbxDob->setEnabled(false);
|
||||
mUI->tbxDob->setObjectName("display_tbx");
|
||||
mUI->tbxName->setEnabled(false);
|
||||
mUI->tbxName->setObjectName("display_tbx");
|
||||
mUI->tbxSex->setEnabled(false);
|
||||
mUI->tbxSex->setObjectName("display_tbx");
|
||||
mUI->rtbxComment->setEnabled(false);
|
||||
mUI->rtbxComment->setObjectName("display_tbx");
|
||||
|
||||
connect(EventCenter::Default(), &EventCenter::ReloadLanguage, [=]() {
|
||||
|
||||
ui->retranslateUi(this);
|
||||
ui->tbx_Sex->setText(store.Sex == "F"?tr("Female"):(store.Sex=="M"?tr("Male"):tr("Other")));
|
||||
});
|
||||
connect(EventCenter::Default(), &EventCenter::ReloadLanguage, this,EditPatientForm::reloadLanguage);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void EditPatientForm::reloadLanguage() {
|
||||
mUI->retranslateUi(this);
|
||||
mUI->tbxSex->setText(mStore.Sex == "F" ? tr("Female") : (mStore.Sex == "M" ? tr("Male") : tr("Other")));
|
||||
}
|
||||
|
||||
EditPatientForm::~EditPatientForm()
|
||||
{
|
||||
delete ui;
|
||||
delete mUI;
|
||||
}
|
||||
|
||||
void EditPatientForm::setPatientInformation(PatientInformation* information) {
|
||||
if (information)
|
||||
{
|
||||
ui->tbx_ID->setText(information->ID);
|
||||
ui->tbx_Dob->setDate(QDate::fromString(information->BirthDate, "yyyy-MM-dd"));
|
||||
ui->tbx_Name->setText(information->Name);
|
||||
ui->rtbx_Comment->setText(information->Comment);
|
||||
ui->tbx_Sex->setText(information->Sex == "F"?tr("Female"):(information->Sex=="M"?tr("Male"):tr("Other")));
|
||||
currentPatientUID = information->PatientUID;
|
||||
AddDate = information->AddDate;
|
||||
store.Sex = information->Sex;
|
||||
mUI->tbxID->setText(information->ID);
|
||||
mUI->tbxDob->setDate(QDate::fromString(information->BirthDate, "yyyy-MM-dd"));
|
||||
mUI->tbxName->setText(information->Name);
|
||||
mUI->rtbxComment->setText(information->Comment);
|
||||
mUI->tbxSex->setText(information->Sex == "F" ? tr("Female") : (information->Sex == "M" ? tr("Male") : tr("Other")));
|
||||
mCurrentPatientUID = information->PatientUID;
|
||||
mAddDate = information->AddDate;
|
||||
mStore.Sex = information->Sex;
|
||||
storePatientInformation();
|
||||
}
|
||||
}
|
||||
|
||||
void EditPatientForm::clearPatientInformation() {
|
||||
ui->tbx_ID->setText("");
|
||||
ui->tbx_Dob->setDate(QDate::currentDate());
|
||||
ui->tbx_Name->setText("");
|
||||
ui->tbx_Sex->setText("");
|
||||
ui->rtbx_Comment->setText("");
|
||||
currentPatientUID = "";
|
||||
AddDate = "";
|
||||
mUI->tbxID->setText("");
|
||||
mUI->tbxDob->setDate(QDate::currentDate());
|
||||
mUI->tbxName->setText("");
|
||||
mUI->tbxSex->setText("");
|
||||
mUI->rtbxComment->setText("");
|
||||
mCurrentPatientUID = "";
|
||||
mAddDate = "";
|
||||
}
|
||||
|
||||
void EditPatientForm::storePatientInformation() {
|
||||
store.PatientUID = currentPatientUID;
|
||||
store.AddDate = AddDate;
|
||||
store.ID = ui->tbx_ID->text();
|
||||
store.BirthDate = ui->tbx_Dob->date().toString("yyyy-MM-dd");
|
||||
store.Name = ui->tbx_Name->text();
|
||||
store.Comment = ui->rtbx_Comment->toPlainText();
|
||||
mStore.PatientUID = mCurrentPatientUID;
|
||||
mStore.AddDate = mAddDate;
|
||||
mStore.ID = mUI->tbxID->text();
|
||||
mStore.BirthDate = mUI->tbxDob->date().toString("yyyy-MM-dd");
|
||||
mStore.Name = mUI->tbxName->text();
|
||||
mStore.Comment = mUI->rtbxComment->toPlainText();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,85 +1,32 @@
|
||||
#ifndef EDITPATIENTFORM_H
|
||||
#define EDITPATIENTFORM_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class EditPatientForm;
|
||||
}
|
||||
|
||||
#define ADD_PATIENT()\
|
||||
ADD_PATIENT_PROPERTY(ID)\
|
||||
ADD_PATIENT_PROPERTY(Name)\
|
||||
ADD_PATIENT_PROPERTY(BirthDate)\
|
||||
ADD_PATIENT_PROPERTY(Sex)\
|
||||
ADD_PATIENT_PROPERTY(AddDate)\
|
||||
ADD_PATIENT_PROPERTY(Comment)\
|
||||
ADD_PATIENT_PROPERTY(Flag)
|
||||
|
||||
#define EDIT_PATIENT()\
|
||||
ADD_PATIENT_PROPERTY(PatientUID)\
|
||||
ADD_PATIENT()
|
||||
|
||||
|
||||
|
||||
|
||||
enum PatientInformationEnum{
|
||||
#define ADD_PATIENT_PROPERTY(val) val,
|
||||
EDIT_PATIENT()
|
||||
#undef ADD_PATIENT_PROPERTY
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief this class was designed to be a edit form,
|
||||
* but now has been change to a detail display class.
|
||||
*/
|
||||
class PatientInformation:public QObject{
|
||||
Q_OBJECT
|
||||
public:
|
||||
#define ADD_PATIENT_PROPERTY(val) QString val;
|
||||
EDIT_PATIENT();
|
||||
#undef ADD_PATIENT_PROPERTY
|
||||
PatientInformation(){
|
||||
this->Flag = QString("0");
|
||||
}
|
||||
PatientInformation* Copy()
|
||||
{
|
||||
PatientInformation* n=new PatientInformation;
|
||||
n->PatientUID = this->PatientUID;
|
||||
n->ID = this->ID;
|
||||
n->Name = this->Name;
|
||||
n->BirthDate = this->BirthDate;
|
||||
n->Sex = this->Sex;
|
||||
n->Comment = this->Comment;
|
||||
return n;
|
||||
}
|
||||
};
|
||||
|
||||
#include <QWidget>
|
||||
#include "PatientInformation.h"
|
||||
class QToolButton;
|
||||
class EditPatientForm : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EditPatientForm(QWidget *parent = nullptr);
|
||||
~EditPatientForm();
|
||||
void setPatientInformation(PatientInformation * information);
|
||||
PatientInformation * getPatientInformation(){
|
||||
return &store;
|
||||
return &mStore;
|
||||
}
|
||||
void clearPatientInformation();
|
||||
void storePatientInformation();
|
||||
|
||||
signals:
|
||||
void editAccept(PatientInformation * detail,bool & accept);
|
||||
void editCancel();
|
||||
signals:
|
||||
void hideBtnClicked();
|
||||
private:
|
||||
Ui::EditPatientForm *ui;
|
||||
QString currentPatientUID;
|
||||
QString AddDate;
|
||||
PatientInformation store;
|
||||
void storePatientInformation();
|
||||
void reloadLanguage();
|
||||
Ui::EditPatientForm *mUI;
|
||||
QString mCurrentPatientUID;
|
||||
QString mAddDate;
|
||||
PatientInformation mStore;
|
||||
};
|
||||
|
||||
#endif // EDITPATIENTFORM_H
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="ULineEdit" name="tbx_ID" native="true">
|
||||
<widget class="ULineEdit" name="tbxID" native="true">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@@ -46,7 +46,8 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="ULineEdit" name="tbx_Name" native="true">
|
||||
<item>
|
||||
<widget class="ULineEdit" name="tbxName" native="true">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@@ -63,7 +64,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="ULineEdit" name="tbx_Sex" native="true">
|
||||
<widget class="ULineEdit" name="tbxSex" native="true">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@@ -80,7 +81,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDateEdit" name="tbx_Dob">
|
||||
<widget class="QDateEdit" name="tbxDob">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@@ -121,7 +122,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="UTextEdit" name="rtbx_Comment">
|
||||
<widget class="UTextEdit" name="rtbxComment">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
|
||||
Reference in New Issue
Block a user