Fix patient tableView selection bugs.

This commit is contained in:
Krad
2022-03-15 16:22:58 +08:00
parent 52bf2527fa
commit 5fb24642e3
2 changed files with 89 additions and 65 deletions

View File

@@ -67,7 +67,7 @@ SelectFormWidget::SelectFormWidget(QWidget* parent) :
contentLayout->setContentsMargins(5, 5, 0, 5); contentLayout->setContentsMargins(5, 5, 0, 5);
this->ui->contentWidget->setLayout(contentLayout); this->ui->contentWidget->setLayout(contentLayout);
// TableView for patient // TableView for patient
QTableView* table = new SlideableTableView(this); SlideableTableView* table = new SlideableTableView(this);
table->setAlternatingRowColors(true); table->setAlternatingRowColors(true);
table->setSelectionMode(QAbstractItemView::SingleSelection); table->setSelectionMode(QAbstractItemView::SingleSelection);
table->setEditTriggers(QAbstractItemView::NoEditTriggers); table->setEditTriggers(QAbstractItemView::NoEditTriggers);
@@ -89,10 +89,6 @@ SelectFormWidget::SelectFormWidget(QWidget* parent) :
model->setHeaderData(4, Qt::Horizontal, tr("Gender")); model->setHeaderData(4, Qt::Horizontal, tr("Gender"));
model->setHeaderData(5, Qt::Horizontal, tr("Add Date")); model->setHeaderData(5, Qt::Horizontal, tr("Add Date"));
model->setHeaderData(6, Qt::Horizontal, tr("Comment")); model->setHeaderData(6, Qt::Horizontal, tr("Comment"));
QSortFilterProxyModel* proxyModel = new QSortFilterProxyModel(model); // create proxy
proxyModel->setSourceModel(model);
table->setSortingEnabled(true); // enable sortingEnabled table->setSortingEnabled(true); // enable sortingEnabled
table->setModel((QAbstractItemModel*)model); table->setModel((QAbstractItemModel*)model);
@@ -100,39 +96,37 @@ SelectFormWidget::SelectFormWidget(QWidget* parent) :
table->hideColumn(7); table->hideColumn(7);
table->show(); table->show();
// table->setSortingEnabled(true);
table->setColumnWidth(1, 250); table->setColumnWidth(1, 250);
table->setColumnWidth(2, 250); table->setColumnWidth(2, 250);
table->setColumnWidth(3, 160); table->setColumnWidth(3, 160);
table->setColumnWidth(4, 120); table->setColumnWidth(4, 120);
table->setColumnWidth(5, 250); table->setColumnWidth(5, 250);
// table->sortByColumn(5);
// table->setSortingEnabled(true);
contentLayout->addWidget(table); contentLayout->addWidget(table);
QWidget* spacerLine2 = new QWidget(this); QWidget* spacerLine2 = new QWidget(this);
spacerLine2->setFixedWidth(2); spacerLine2->setFixedWidth(2);
spacerLine2->setObjectName("verSpaceLine"); spacerLine2->setObjectName("verSpaceLine");
contentLayout->addWidget(spacerLine2); contentLayout->addWidget(spacerLine2);
//edit panel // prepare edit panel
EditPatientForm* edit_patient = new EditPatientForm(this); EditPatientForm* edit_patient = new EditPatientForm(this);
edit_patient->setObjectName("edit_patient"); edit_patient->setObjectName("edit_patient");
edit_patient->hide(); edit_patient->hide();
contentLayout->addWidget(edit_patient); contentLayout->addWidget(edit_patient);
auto* btnShowEdit = new VerticalTextToolButton(this); auto* btnShowEdit = new VerticalTextToolButton(this);
btnShowEdit->setObjectName("showeditBtn"); btnShowEdit->setObjectName("showeditBtn");
btnShowEdit->setIcon(QIcon(":/icons/edit.png")); btnShowEdit->setIcon(QIcon(":/icons/edit.png"));
btnShowEdit->setIconSize(QSize(30, 30)); btnShowEdit->setIconSize(QSize(30, 30));
btnShowEdit->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); btnShowEdit->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
btnShowEdit->setFixedHeight(225); btnShowEdit->setFixedHeight(225);
// btnShowEdit->setVerticalText("E\nd\ni\nt\nP\na\nn\ne\nl");
btnShowEdit->setVerticalText("Patient Detail"); btnShowEdit->setVerticalText("Patient Detail");
contentLayout->addWidget(btnShowEdit); contentLayout->addWidget(btnShowEdit);
contentLayout->setAlignment(btnShowEdit, Qt::AlignmentFlag::AlignTop); contentLayout->setAlignment(btnShowEdit, Qt::AlignmentFlag::AlignTop);
// btn show slot
connect(btnShowEdit, &QToolButton::clicked, [=]() { connect(btnShowEdit, &QToolButton::clicked, [=]() {
edit_patient->show(); edit_patient->show();
btnShowEdit->hide(); btnShowEdit->hide();
}); });
//btn hide slot
connect(edit_patient, &EditPatientForm::hideBtnClicked, [=]() { connect(edit_patient, &EditPatientForm::hideBtnClicked, [=]() {
edit_patient->hide(); edit_patient->hide();
btnShowEdit->show(); btnShowEdit->show();
@@ -142,29 +136,40 @@ SelectFormWidget::SelectFormWidget(QWidget* parent) :
if (model->rowCount() > 0) if (model->rowCount() > 0)
{ {
table->selectRow(0); table->selectRow(0);
currentRow = 0;
PatientInformation pat; PatientInformation pat;
#define ADD_PATIENT_PROPERTY(val)\ #define ADD_PATIENT_PROPERTY(val)\
pat. val = model->data(model->index(currentRow,PatientInformationEnum:: val)).toString(); pat. val = model->data(model->index(table->currentIndex().row(),PatientInformationEnum:: val)).toString();
EDIT_PATIENT() EDIT_PATIENT()
#undef ADD_PATIENT_PROPERTY #undef ADD_PATIENT_PROPERTY
edit_patient->setPatientInformation(&pat); edit_patient->setPatientInformation(&pat);
} }
//events---------------------------------------------------------------------- //events----------------------------------------------------------------------
//prepare button state
auto prepareButtons = [=](bool disableALL){
bool state_flag = (table->currentIndex().row()>=0);
btnSelect->setEnabled(state_flag && !disableALL);
btnDelete->setEnabled(state_flag && !disableALL);
btnEdit->setEnabled(state_flag && !disableALL);
btnAdd->setEnabled(!disableALL);
};
//table current row selection changing event //table current row selection changing event
connect(table, &QTableView::clicked, [=](const QModelIndex& modelIndex) { connect(table, &SlideableTableView::currentRowChanged, [=](int row) {
if (currentRow != modelIndex.row())
{
currentRow = modelIndex.row();
PatientInformation pat; PatientInformation pat;
#define ADD_PATIENT_PROPERTY(val)\ #define ADD_PATIENT_PROPERTY(val)\
pat. val = model->data(model->index(modelIndex.row(),PatientInformationEnum:: val)).toString(); pat. val = model->data(model->index(row,PatientInformationEnum:: val)).toString();
EDIT_PATIENT() EDIT_PATIENT()
#undef ADD_PATIENT_PROPERTY #undef ADD_PATIENT_PROPERTY
edit_patient->setPatientInformation(&pat); edit_patient->setPatientInformation(&pat);
} prepareButtons(false);
}); });
// after sort by column
connect(table->horizontalHeader(),&QHeaderView::sectionClicked,[=](int index){
edit_patient->clearPatientInformation();
prepareButtons(false);
});
// btn add slot
connect(btnAdd, &QToolButton::clicked, [=]() { connect(btnAdd, &QToolButton::clicked, [=]() {
edit_patient->show(); edit_patient->show();
btnShowEdit->hide(); btnShowEdit->hide();
@@ -172,6 +177,8 @@ SelectFormWidget::SelectFormWidget(QWidget* parent) :
edit_patient->setEditEnable(true); edit_patient->setEditEnable(true);
btnSelect->setEnabled(false); btnSelect->setEnabled(false);
}); });
// btn edit slot
connect(btnEdit, &QToolButton::clicked, [=]() { connect(btnEdit, &QToolButton::clicked, [=]() {
edit_patient->show(); edit_patient->show();
btnShowEdit->hide(); btnShowEdit->hide();
@@ -179,11 +186,16 @@ SelectFormWidget::SelectFormWidget(QWidget* parent) :
edit_patient->setEditEnable(true); edit_patient->setEditEnable(true);
btnSelect->setEnabled(false); btnSelect->setEnabled(false);
}); });
// btn add slot
connect(edit_patient, &EditPatientForm::editCancel, [=]() { connect(edit_patient, &EditPatientForm::editCancel, [=]() {
if (table->currentIndex().row()<0) return;
btnSelect->setEnabled(true); btnSelect->setEnabled(true);
}); });
// btn add slot
connect(edit_patient, &EditPatientForm::editAccept, [=](PatientInformation* inf, bool& result) { connect(edit_patient, &EditPatientForm::editAccept, [=](PatientInformation* inf, bool& result) {
int selectedRow = currentRow; int selectedRow = table->currentIndex().row();
bool isAdd = inf->PatientUID.isEmpty(); bool isAdd = inf->PatientUID.isEmpty();
if (isAdd) { if (isAdd) {
int ref_rowid = queryValue(model, 1, inf->ID); int ref_rowid = queryValue(model, 1, inf->ID);
@@ -226,25 +238,36 @@ SelectFormWidget::SelectFormWidget(QWidget* parent) :
btnSelect->setEnabled(true); btnSelect->setEnabled(true);
}); });
// btn delete slot
connect(btnDelete, &QToolButton::clicked, [=]() { connect(btnDelete, &QToolButton::clicked, [=]() {
if (currentRow < 0)return; if (table->currentIndex().row()<0) return;
AlertDialog dialog(this); 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.setButtonMode(OkAndCancel);
dialog.setTitle("Confirm"); dialog.setTitle("Confirm");
dialog.setWindowModality(Qt::WindowModal); QString pat_name = model->index(table->currentIndex().row(), PatientInformationEnum::Name).data().toString();
QString pat_name = model->index(currentRow, PatientInformationEnum::Name).data().toString();
dialog.setAlertMessage(QString(tr("Delete Patient \"%1\" ?")).arg(pat_name)); dialog.setAlertMessage(QString(tr("Delete Patient \"%1\" ?")).arg(pat_name));
if (dialog.exec()!=QDialog::Accepted) return; if (dialog.exec() != QDialog::Accepted) return;
model->setData(model->index(currentRow, PatientInformationEnum::Flag), 9); // need delete clear edit panel detail
// model->removeRow(currentRow); edit_patient->setEditEnable(false);
if (model->submitAll()) edit_patient->clearPatientInformation();
{ model->setData(model->index(table->currentIndex().row(), PatientInformationEnum::Flag), 9);
if (model->submitAll()) {
model->select(); model->select();
if (model->rowCount() > 0) if (model->rowCount() > 0) {
{
table->selectRow(0); table->selectRow(0);
model->selectRow(0); model->selectRow(0);
currentRow = 0;
PatientInformation pat; PatientInformation pat;
#define ADD_PATIENT_PROPERTY(val)\ #define ADD_PATIENT_PROPERTY(val)\
pat. val = model->data(model->index(0,PatientInformationEnum:: val)).toString(); pat. val = model->data(model->index(0,PatientInformationEnum:: val)).toString();
@@ -253,42 +276,39 @@ SelectFormWidget::SelectFormWidget(QWidget* parent) :
edit_patient->setPatientInformation(&pat); edit_patient->setPatientInformation(&pat);
LOG_USER_OPERATION(DeletePatient); LOG_USER_OPERATION(DeletePatient);
} }
else { } else {
currentRow = -1;
edit_patient->editCancel();
edit_patient->clearPatientInformation();
}
}
else {
//TODO:error handle //TODO:error handle
} }
prepareButtons(false);
}); });
// btn select slot
connect(btnSelect, &QToolButton::clicked, [=]() { connect(btnSelect, &QToolButton::clicked, [=]() {
if (currentRow < 0)return;
EventCenter::Default()->triggerEvent(GUIEvents::PatientSelected, nullptr, edit_patient->getPatientInformation()->Copy()); EventCenter::Default()->triggerEvent(GUIEvents::PatientSelected, nullptr, edit_patient->getPatientInformation()->Copy());
selectedPatientUID = edit_patient->getPatientInformation()->PatientUID;
LOG_USER_OPERATION(SelectPatient); LOG_USER_OPERATION(SelectPatient);
}); });
// btn account slot
connect(btnAccount, &QToolButton::clicked, [=]() { connect(btnAccount, &QToolButton::clicked, [=]() {
AccountFormDialog dia(this); AccountFormDialog dia(this);
dia.setWindowModality(Qt::WindowModal); dia.setWindowModality(Qt::WindowModal);
dia.exec(); dia.exec();
}); });
// event ResponsePreview slot
connect(EventCenter::Default(), &EventCenter::ResponsePreview, [=](QObject* sender, QObject* data) { connect(EventCenter::Default(), &EventCenter::ResponsePreview, [=](QObject* sender, QObject* data) {
btnSelect->setEnabled(false); prepareButtons(true);
btnDelete->setEnabled(false);
btnEdit->setEnabled(false);
btnAdd->setEnabled(false);
}); });
// event ResponseStop slot
connect(EventCenter::Default(), &EventCenter::ResponseStop, [=](QObject* sender, QObject* data) { connect(EventCenter::Default(), &EventCenter::ResponseStop, [=](QObject* sender, QObject* data) {
btnSelect->setEnabled(true); prepareButtons(false);
btnDelete->setEnabled(true);
btnEdit->setEnabled(true);
btnAdd->setEnabled(true);
}); });
// event ReloadLanguage slot;
connect(EventCenter::Default(), &EventCenter::ReloadLanguage, [=]() { connect(EventCenter::Default(), &EventCenter::ReloadLanguage, [=]() {
model->setHeaderData(1, Qt::Horizontal, "ID"); model->setHeaderData(1, Qt::Horizontal, "ID");
@@ -306,6 +326,8 @@ SelectFormWidget::SelectFormWidget(QWidget* parent) :
btnSelect->setText(tr("Select")); btnSelect->setText(tr("Select"));
}); });
//first prepare buttons!
prepareButtons(false);
} }
@@ -313,3 +335,5 @@ SelectFormWidget::~SelectFormWidget()
{ {
} }

View File

@@ -6,6 +6,7 @@
#define GUI_SELECTFORMWIDGET_H #define GUI_SELECTFORMWIDGET_H
#include "tabformwidget.h" #include "tabformwidget.h"
class EditPatientForm;
class SelectFormWidget: public TabFormWidget { class SelectFormWidget: public TabFormWidget {
Q_OBJECT Q_OBJECT
public: public:
@@ -13,8 +14,7 @@ public:
~SelectFormWidget(); ~SelectFormWidget();
private: private:
int currentRow = -1; QString selectedPatientUID;
}; };