Using SQLHelper to retrieve data to dataView, add simple control to edit patient panel.

This commit is contained in:
Krad
2021-10-12 10:28:30 +08:00
parent 700282bd2f
commit d03de1009d
4 changed files with 135 additions and 31 deletions

View File

@@ -7,6 +7,7 @@
#include <QToolButton> #include <QToolButton>
#include <QTableWidget> #include <QTableWidget>
#include <QHeaderView> #include <QHeaderView>
#include "db/SQLHelper.h"
#include "editpatientform.h" #include "editpatientform.h"
#include "guimacros.h" #include "guimacros.h"
@@ -24,11 +25,12 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) :
"QHeaderView::section:horizontal{border-bottom: 1px solid rgb(0,170,255);}" "QHeaderView::section:horizontal{border-bottom: 1px solid rgb(0,170,255);}"
"QHeaderView::section:vertical{min-height:36px;max-height:36px;}" "QHeaderView::section:vertical{min-height:36px;max-height:36px;}"
"QWidget#edit_patient{min-width:300px;max-width:300px;}" "QWidget#edit_patient{min-width:300px;max-width:300px;}"
// "QTableWidget{border:1px solid #323232}"
"QTableWidget{border:none}" "QTableWidget{border:none}"
"QTableView{alternate-background-color: #595959;selection-color:white;selection-background-color:#0078d8}" "QTableView{alternate-background-color: #595959;selection-color:white;selection-background-color:#0078d8}"
; ;
this->setStyleSheet(this->styleSheet().append(style)); this->setStyleSheet(this->styleSheet().append(style));
//init command bar
QHBoxLayout* layout =new QHBoxLayout(); QHBoxLayout* layout =new QHBoxLayout();
ui->commandWidget->setLayout(layout); ui->commandWidget->setLayout(layout);
ADD_TOOL_BTN(Account,":/icons/account.png"); ADD_TOOL_BTN(Account,":/icons/account.png");
@@ -42,46 +44,60 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) :
ADD_TOOL_BTN(Edit,":/icons/details.png"); ADD_TOOL_BTN(Edit,":/icons/details.png");
ADD_TOOL_BTN(Delete,":/icons/close_circle.png"); ADD_TOOL_BTN(Delete,":/icons/close_circle.png");
ADD_TOOL_BTN(Select,":/icons/selected.png"); ADD_TOOL_BTN(Select,":/icons/selected.png");
//Init content widget
QHBoxLayout* contentLayout =new QHBoxLayout(); QHBoxLayout* contentLayout =new QHBoxLayout();
this->ui->contentWidget->setLayout(contentLayout); this->ui->contentWidget->setLayout(contentLayout);
QStringList header; // TableView for patient
header<<"ID"<<"Name"<<"Sex"<<"DOB"<<"Status"<<"Comment"; QTableView* table= new QTableView(this);
QTableWidget* table= new QTableWidget(this);
table->setAlternatingRowColors(true); table->setAlternatingRowColors(true);
table->setSelectionMode(QAbstractItemView::SingleSelection); table->setSelectionMode(QAbstractItemView::SingleSelection);
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
table->setSelectionBehavior(QAbstractItemView::SelectRows); table->setSelectionBehavior(QAbstractItemView::SelectRows);
table->setColumnCount(6);
table->verticalHeader()->setDefaultSectionSize(38); table->verticalHeader()->setDefaultSectionSize(38);
table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
table->setHorizontalHeaderLabels(header); //dat from SQLITE
table->setRowCount(3); SQLHelper::Open();
QTableWidgetItem* item ; auto model = SQLHelper::getTable("Patient");
ADD_CENTER_ITEM(0,0,"Pat010012313"); model->select();
ADD_CENTER_ITEM(0,1,"XXX"); model->setHeaderData(1,Qt::Horizontal,"ID");
ADD_CENTER_ITEM(0,2,"Female"); model->setHeaderData(2,Qt::Horizontal,"Name");
ADD_CENTER_ITEM(0,3,"1978/09/06"); model->setHeaderData(3,Qt::Horizontal,"Birth Date");
ADD_CENTER_ITEM(0,4,"Added"); table->setModel((QAbstractItemModel*)model);
ADD_CENTER_ITEM(0,5,""); table->hideColumn(0);
ADD_CENTER_ITEM(1,0,"Pat0222222"); table->show();
ADD_CENTER_ITEM(1,1,"XXX2");
ADD_CENTER_ITEM(1,2,"Female");
ADD_CENTER_ITEM(1,3,"1993/08/16");
ADD_CENTER_ITEM(1,4,"Scanned");
ADD_CENTER_ITEM(1,5,"");
ADD_CENTER_ITEM(2,0,"Pat3");
ADD_CENTER_ITEM(2,1,"XX3");
ADD_CENTER_ITEM(2,2,"Female");
ADD_CENTER_ITEM(2,3,"1999/08/16");
ADD_CENTER_ITEM(2,4,"Scanned");
ADD_CENTER_ITEM(2,5,"");
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
EditPatientForm* edit_patient= new EditPatientForm(this); EditPatientForm* edit_patient= new EditPatientForm(this);
edit_patient->setObjectName("edit_patient"); edit_patient->setObjectName("edit_patient");
contentLayout->addWidget(edit_patient); contentLayout->addWidget(edit_patient);
//events----------------------------------------------------------------------
//table current row selection changing event
connect(table,&QTableView::clicked,[=](const QModelIndex & modelIndex){
if (currentRow!=modelIndex.row())
{
PatientInformation pat;
#define ADD_PATIENT_PROPERTY(val)\
pat. val = model->data(model->index(modelIndex.row(),PatientInformationEnum:: val)).toString();
EDIT_PATIENT()
#undef ADD_PATIENT_PROPERTY
edit_patient->setPatientInformation(&pat);
}
});
connect(btnAdd, &QToolButton::clicked,[=](){
edit_patient->clearPatientInformation();
edit_patient->setEditEnable(true);
});
connect(btnEdit, &QToolButton::clicked,[=](){
table->clicked(table->currentIndex());
edit_patient->setEditEnable(true);
});
} }
SelectFormWidget::~SelectFormWidget() SelectFormWidget::~SelectFormWidget()

View File

@@ -12,6 +12,8 @@ public:
explicit SelectFormWidget(QWidget *parent = nullptr); explicit SelectFormWidget(QWidget *parent = nullptr);
~SelectFormWidget(); ~SelectFormWidget();
private:
int currentRow = -1;
}; };

View File

@@ -16,15 +16,68 @@ EditPatientForm::EditPatientForm(QWidget *parent) :
this->ui->editcmdWidget->setLayout(layout); this->ui->editcmdWidget->setLayout(layout);
ADD_TOOL_BTN(Cancel,":/icons/close_circle.png"); ADD_TOOL_BTN(Cancel,":/icons/close_circle.png");
ADD_TOOL_BTN(Accpet,":/icons/selected.png"); ADD_TOOL_BTN(Accpet,":/icons/selected.png");
btnCancel->setEnabled(false); btnCancel->setEnabled(editEnable);
btnCancel->setToolButtonStyle(Qt::ToolButtonIconOnly); btnCancel->setToolButtonStyle(Qt::ToolButtonIconOnly);
btnCancel->setIcon(QIcon(":/icons/close_circle_d.png")); btnCancel->setIcon(QIcon(editEnable?":/icons/close_circle.png":":/icons/close_circle_d.png"));
btnAccpet->setEnabled(false); btnAccpet->setEnabled(editEnable);
btnAccpet->setToolButtonStyle(Qt::ToolButtonIconOnly); btnAccpet->setToolButtonStyle(Qt::ToolButtonIconOnly);
btnAccpet->setIcon(QIcon(":/icons/selected_d.png")); btnAccpet->setIcon(QIcon(editEnable?":/icons/selected.png":":/icons/selected_d.png"));
btnEditAccept = btnAccpet;
btnEditCancel = btnCancel;
connect(btnEditCancel,&QToolButton::clicked,[=](){
clearPatientInformation();
this->setEditEnable(false);
restorePatientInformation();
});
} }
EditPatientForm::~EditPatientForm() EditPatientForm::~EditPatientForm()
{ {
delete ui; delete ui;
} }
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=="F"?"Female":(information->Name=="M"?"Male":"Other"));
currentPatientUID = information->PatientUID;
storePatientInformation();
}
}
void EditPatientForm::clearPatientInformation() {
ui->tbx_ID->setText("");
ui->tbx_Dob->setDate(QDate::currentDate());
ui->tbx_Name->setText("");
currentPatientUID = "";
}
void EditPatientForm::setEditEnable(bool enable) {
ui->tbx_ID->setEnabled(enable);
ui->tbx_Dob->setEnabled(enable);
ui->tbx_Name->setEnabled(enable);
ui->cb_Sex->setEnabled(enable);
ui->rtbx_Comment->setEnabled(enable);
btnEditAccept->setEnabled(enable);
btnEditCancel->setEnabled(enable);
btnEditCancel->setIcon(QIcon(enable?":/icons/close_circle.png":":/icons/close_circle_d.png"));
btnEditAccept->setIcon(QIcon(enable?":/icons/selected.png":":/icons/selected_d.png"));
editEnable = enable;
// ui->->setEnabled(enable);
}
void EditPatientForm::storePatientInformation() {
store.PatientUID =currentPatientUID;
store.ID = ui->tbx_ID->text();
store.BirthDate = ui->tbx_Dob->date().toString("yyyy-MM-dd");
store.Name = ui->tbx_Name->text();
}
void EditPatientForm::restorePatientInformation() {
currentPatientUID = store.PatientUID;
ui->tbx_ID->setText(store.ID);
ui->tbx_Dob->setDate(QDate::fromString(store.BirthDate,"yyyy-MM-dd"));
ui->tbx_Name->setText(store.Name);
}

View File

@@ -6,7 +6,31 @@
namespace Ui { namespace Ui {
class EditPatientForm; class EditPatientForm;
} }
#define EDIT_PATIENT()\
ADD_PATIENT_PROPERTY(PatientUID)\
ADD_PATIENT_PROPERTY(ID)\
ADD_PATIENT_PROPERTY(Name)\
ADD_PATIENT_PROPERTY(BirthDate)\
ADD_PATIENT_PROPERTY(Sex)\
ADD_PATIENT_PROPERTY(Comment)\
enum PatientInformationEnum{
#define ADD_PATIENT_PROPERTY(val) val,
EDIT_PATIENT()
#undef ADD_PATIENT_PROPERTY
};
class PatientInformation{
public:
#define ADD_PATIENT_PROPERTY(val) QString val;
EDIT_PATIENT();
#undef ADD_PATIENT_PROPERTY
};
class QToolButton;
class EditPatientForm : public QWidget class EditPatientForm : public QWidget
{ {
Q_OBJECT Q_OBJECT
@@ -14,9 +38,18 @@ class EditPatientForm : public QWidget
public: public:
explicit EditPatientForm(QWidget *parent = nullptr); explicit EditPatientForm(QWidget *parent = nullptr);
~EditPatientForm(); ~EditPatientForm();
void setPatientInformation(PatientInformation * information);
void clearPatientInformation();
void storePatientInformation();
void restorePatientInformation();
void setEditEnable(bool enable);
private: private:
Ui::EditPatientForm *ui; Ui::EditPatientForm *ui;
QString currentPatientUID;
PatientInformation store;
bool editEnable=false;
QToolButton* btnEditAccept;
QToolButton* btnEditCancel;
}; };
#endif // EDITPATIENTFORM_H #endif // EDITPATIENTFORM_H