Files
GUI/src/SelectFormWidget.cpp

147 lines
5.5 KiB
C++
Raw Normal View History

2021-10-09 16:38:34 +08:00
//
// Created by Krad on 2021/10/8.
//
#include "ui_tabformwidget.h"
#include "SelectFormWidget.h"
#include <QHBoxLayout>
#include <QToolButton>
#include <QTableWidget>
#include <QHeaderView>
2021-10-12 14:11:19 +08:00
#include <QUuid>
#include <QDate>
#include "db/SQLHelper.h"
2021-10-09 16:38:34 +08:00
#include "editpatientform.h"
#include "guimacros.h"
2021-10-11 09:22:31 +08:00
#define ADD_CENTER_ITEM(row,col,text)\
item = new QTableWidgetItem(text);\
item->setTextAlignment(Qt::AlignmentFlag::AlignCenter);\
table->setItem(row,col,item);
2021-10-09 16:38:34 +08:00
SelectFormWidget::SelectFormWidget(QWidget *parent) :
TabFormWidget(parent)
{
const char* style="QHeaderView::section{background-color:#595959;"
" min-height:50px;max-height:50px;"
"font-weight:Bold; font-size:16px; border:1px solid #323232;}"
"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:none}"
2021-10-12 10:26:24 +08:00
"QTableView{alternate-background-color: #595959;selection-color:white;selection-background-color:#0078d8}"
2021-10-09 16:38:34 +08:00
;
2021-10-09 16:38:34 +08:00
this->setStyleSheet(this->styleSheet().append(style));
//init command bar
2021-10-09 16:38:34 +08:00
QHBoxLayout* layout =new QHBoxLayout();
ui->commandWidget->setLayout(layout);
ADD_TOOL_BTN(Account,":/icons/account.png");
2021-10-12 10:26:24 +08:00
ADD_TOOL_BTN(Worklist,":/icons/setting.png");
2021-10-09 16:38:34 +08:00
layout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding));
QWidget* spacerLine= new QWidget(this);
spacerLine->setFixedWidth(2);
spacerLine->setObjectName("verSpaceLine");
layout->addWidget(spacerLine);
ADD_TOOL_BTN(Add,":/icons/add.png");
2021-10-12 10:26:24 +08:00
ADD_TOOL_BTN(Edit,":/icons/details.png");
2021-10-09 16:38:34 +08:00
ADD_TOOL_BTN(Delete,":/icons/close_circle.png");
ADD_TOOL_BTN(Select,":/icons/selected.png");
//Init content widget
2021-10-09 16:38:34 +08:00
QHBoxLayout* contentLayout =new QHBoxLayout();
this->ui->contentWidget->setLayout(contentLayout);
// TableView for patient
QTableView* table= new QTableView(this);
2021-10-09 16:38:34 +08:00
table->setAlternatingRowColors(true);
table->setSelectionMode(QAbstractItemView::SingleSelection);
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
2021-10-09 16:38:34 +08:00
table->setSelectionBehavior(QAbstractItemView::SelectRows);
table->verticalHeader()->setDefaultSectionSize(38);
2021-10-12 10:56:42 +08:00
table->horizontalHeader()->setStretchLastSection(true);
//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");
2021-10-12 10:56:42 +08:00
table->setModel((QAbstractItemModel*)model);
table->hideColumn(0);
2021-10-12 10:56:42 +08:00
table->show();
2021-10-12 10:56:42 +08:00
table->setColumnWidth(1,250);
table->setColumnWidth(2,250);
table->setColumnWidth(3,120);
table->setColumnWidth(4,60);
2021-10-09 16:38:34 +08:00
contentLayout->addWidget(table);
QWidget* spacerLine2= new QWidget(this);
spacerLine2->setFixedWidth(2);
spacerLine2->setObjectName("verSpaceLine");
contentLayout->addWidget(spacerLine2);
//edit panel
2021-10-09 16:38:34 +08:00
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);
});
2021-10-12 14:11:19 +08:00
connect(edit_patient, &EditPatientForm::editAccept,[=](PatientInformation* inf){
// QSqlRecord record = inf->PatientUID.isEmpty()?model->record():model->record(currentRow);
int rowCount = model->rowCount();
bool isAdd = false;
if (inf->PatientUID.isEmpty()) {
isAdd = true;
inf->PatientUID = QUuid::createUuid().toString();
printf(inf->PatientUID.toStdString().data());
model->insertRow(rowCount);
}
#define ADD_PATIENT_PROPERTY(val)\
model->setData(model->index(rowCount,PatientInformationEnum:: val),inf-> val);
// record.setValue(PatientInformationEnum:: val, inf-> val);
EDIT_PATIENT()
#undef ADD_PATIENT_PROPERTY
// model->setData(model->index(rowCount,PatientInformationEnum::BirthDate), QDate::fromString(inf->BirthDate,"yyyy/MM/dd"));
// record.setValue(PatientInformationEnum::BirthDate, QDate::fromString(inf->BirthDate,"yyyy/MM/dd"));
// if (isAdd)
// {
// model->insertRecord(1,record);
// } else{
// model->setRecord(currentRow,record);
// }
// model->database().transaction();
if (model->submitAll())
{
// model->database().commit();
}
// else{
// model->database().rollback();
// }
});
2021-10-09 16:38:34 +08:00
}
SelectFormWidget::~SelectFormWidget()
{
}