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);
this->ui->contentWidget->setLayout(contentLayout);
// TableView for patient
QTableView* table = new SlideableTableView(this);
SlideableTableView* table = new SlideableTableView(this);
table->setAlternatingRowColors(true);
table->setSelectionMode(QAbstractItemView::SingleSelection);
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
@@ -89,10 +89,6 @@ SelectFormWidget::SelectFormWidget(QWidget* parent) :
model->setHeaderData(4, Qt::Horizontal, tr("Gender"));
model->setHeaderData(5, Qt::Horizontal, tr("Add Date"));
model->setHeaderData(6, Qt::Horizontal, tr("Comment"));
QSortFilterProxyModel* proxyModel = new QSortFilterProxyModel(model); // create proxy
proxyModel->setSourceModel(model);
table->setSortingEnabled(true); // enable sortingEnabled
table->setModel((QAbstractItemModel*)model);
@@ -100,39 +96,37 @@ SelectFormWidget::SelectFormWidget(QWidget* parent) :
table->hideColumn(7);
table->show();
// table->setSortingEnabled(true);
table->setColumnWidth(1, 250);
table->setColumnWidth(2, 250);
table->setColumnWidth(3, 160);
table->setColumnWidth(4, 120);
table->setColumnWidth(5, 250);
// table->sortByColumn(5);
// table->setSortingEnabled(true);
contentLayout->addWidget(table);
QWidget* spacerLine2 = new QWidget(this);
spacerLine2->setFixedWidth(2);
spacerLine2->setObjectName("verSpaceLine");
contentLayout->addWidget(spacerLine2);
//edit panel
EditPatientForm* edit_patient = new EditPatientForm(this);
// prepare edit panel
EditPatientForm* 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("E\nd\ni\nt\nP\na\nn\ne\nl");
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();
@@ -142,29 +136,40 @@ SelectFormWidget::SelectFormWidget(QWidget* parent) :
if (model->rowCount() > 0)
{
table->selectRow(0);
currentRow = 0;
PatientInformation pat;
#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()
#undef ADD_PATIENT_PROPERTY
edit_patient->setPatientInformation(&pat);
}
//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
connect(table, &QTableView::clicked, [=](const QModelIndex& modelIndex) {
if (currentRow != modelIndex.row())
{
currentRow = modelIndex.row();
connect(table, &SlideableTableView::currentRowChanged, [=](int row) {
PatientInformation pat;
#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()
#undef ADD_PATIENT_PROPERTY
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, [=]() {
edit_patient->show();
btnShowEdit->hide();
@@ -172,6 +177,8 @@ SelectFormWidget::SelectFormWidget(QWidget* parent) :
edit_patient->setEditEnable(true);
btnSelect->setEnabled(false);
});
// btn edit slot
connect(btnEdit, &QToolButton::clicked, [=]() {
edit_patient->show();
btnShowEdit->hide();
@@ -179,11 +186,16 @@ SelectFormWidget::SelectFormWidget(QWidget* parent) :
edit_patient->setEditEnable(true);
btnSelect->setEnabled(false);
});
// btn add slot
connect(edit_patient, &EditPatientForm::editCancel, [=]() {
if (table->currentIndex().row()<0) return;
btnSelect->setEnabled(true);
});
});
// btn add slot
connect(edit_patient, &EditPatientForm::editAccept, [=](PatientInformation* inf, bool& result) {
int selectedRow = currentRow;
int selectedRow = table->currentIndex().row();
bool isAdd = inf->PatientUID.isEmpty();
if (isAdd) {
int ref_rowid = queryValue(model, 1, inf->ID);
@@ -226,69 +238,77 @@ SelectFormWidget::SelectFormWidget(QWidget* parent) :
btnSelect->setEnabled(true);
});
// btn delete slot
connect(btnDelete, &QToolButton::clicked, [=]() {
if (currentRow < 0)return;
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");
dialog.setWindowModality(Qt::WindowModal);
QString pat_name = model->index(currentRow, PatientInformationEnum::Name).data().toString();
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;
model->setData(model->index(currentRow, PatientInformationEnum::Flag), 9);
// model->removeRow(currentRow);
if (model->submitAll())
{
model->select();
if (model->rowCount() > 0)
{
table->selectRow(0);
model->selectRow(0);
currentRow = 0;
PatientInformation pat;
if (dialog.exec() != QDialog::Accepted) return;
// need delete clear edit panel detail
edit_patient->setEditEnable(false);
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);
PatientInformation pat;
#define ADD_PATIENT_PROPERTY(val)\
pat. val = model->data(model->index(0,PatientInformationEnum:: val)).toString();
EDIT_PATIENT()
EDIT_PATIENT()
#undef ADD_PATIENT_PROPERTY
edit_patient->setPatientInformation(&pat);
LOG_USER_OPERATION(DeletePatient);
}
else {
currentRow = -1;
edit_patient->editCancel();
edit_patient->clearPatientInformation();
}
}
else {
//TODO:error handle
}
edit_patient->setPatientInformation(&pat);
LOG_USER_OPERATION(DeletePatient);
}
} else {
//TODO:error handle
}
prepareButtons(false);
});
});
// btn select slot
connect(btnSelect, &QToolButton::clicked, [=]() {
if (currentRow < 0)return;
EventCenter::Default()->triggerEvent(GUIEvents::PatientSelected, nullptr, edit_patient->getPatientInformation()->Copy());
selectedPatientUID = edit_patient->getPatientInformation()->PatientUID;
LOG_USER_OPERATION(SelectPatient);
});
// btn account slot
connect(btnAccount, &QToolButton::clicked, [=]() {
AccountFormDialog dia(this);
dia.setWindowModality(Qt::WindowModal);
dia.exec();
});
// event ResponsePreview slot
connect(EventCenter::Default(), &EventCenter::ResponsePreview, [=](QObject* sender, QObject* data) {
btnSelect->setEnabled(false);
btnDelete->setEnabled(false);
btnEdit->setEnabled(false);
btnAdd->setEnabled(false);
prepareButtons(true);
});
// event ResponseStop slot
connect(EventCenter::Default(), &EventCenter::ResponseStop, [=](QObject* sender, QObject* data) {
btnSelect->setEnabled(true);
btnDelete->setEnabled(true);
btnEdit->setEnabled(true);
btnAdd->setEnabled(true);
});
prepareButtons(false);
});
// event ReloadLanguage slot;
connect(EventCenter::Default(), &EventCenter::ReloadLanguage, [=]() {
model->setHeaderData(1, Qt::Horizontal, "ID");
@@ -306,6 +326,8 @@ SelectFormWidget::SelectFormWidget(QWidget* parent) :
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
#include "tabformwidget.h"
class EditPatientForm;
class SelectFormWidget: public TabFormWidget {
Q_OBJECT
public:
@@ -13,8 +14,7 @@ public:
~SelectFormWidget();
private:
int currentRow = -1;
QString selectedPatientUID;
};