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 <QTableWidget>
#include <QHeaderView>
#include "db/SQLHelper.h"
#include "editpatientform.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:vertical{min-height:36px;max-height:36px;}"
"QWidget#edit_patient{min-width:300px;max-width:300px;}"
// "QTableWidget{border:1px solid #323232}"
"QTableWidget{border:none}"
"QTableView{alternate-background-color: #595959;selection-color:white;selection-background-color:#0078d8}"
;
this->setStyleSheet(this->styleSheet().append(style));
//init command bar
QHBoxLayout* layout =new QHBoxLayout();
ui->commandWidget->setLayout(layout);
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(Delete,":/icons/close_circle.png");
ADD_TOOL_BTN(Select,":/icons/selected.png");
//Init content widget
QHBoxLayout* contentLayout =new QHBoxLayout();
this->ui->contentWidget->setLayout(contentLayout);
QStringList header;
header<<"ID"<<"Name"<<"Sex"<<"DOB"<<"Status"<<"Comment";
QTableWidget* table= new QTableWidget(this);
// TableView for patient
QTableView* table= new QTableView(this);
table->setAlternatingRowColors(true);
table->setSelectionMode(QAbstractItemView::SingleSelection);
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
table->setSelectionBehavior(QAbstractItemView::SelectRows);
table->setColumnCount(6);
table->verticalHeader()->setDefaultSectionSize(38);
table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
table->setHorizontalHeaderLabels(header);
table->setRowCount(3);
QTableWidgetItem* item ;
ADD_CENTER_ITEM(0,0,"Pat010012313");
ADD_CENTER_ITEM(0,1,"XXX");
ADD_CENTER_ITEM(0,2,"Female");
ADD_CENTER_ITEM(0,3,"1978/09/06");
ADD_CENTER_ITEM(0,4,"Added");
ADD_CENTER_ITEM(0,5,"");
ADD_CENTER_ITEM(1,0,"Pat0222222");
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,"");
//dat from SQLITE
SQLHelper::Open();
auto model = SQLHelper::getTable("Patient");
model->select();
model->setHeaderData(1,Qt::Horizontal,"ID");
model->setHeaderData(2,Qt::Horizontal,"Name");
model->setHeaderData(3,Qt::Horizontal,"Birth Date");
table->setModel((QAbstractItemModel*)model);
table->hideColumn(0);
table->show();
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);
edit_patient->setObjectName("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()