diff --git a/src/SelectFormWidget.cpp b/src/SelectFormWidget.cpp index 360a266..4996fcd 100644 --- a/src/SelectFormWidget.cpp +++ b/src/SelectFormWidget.cpp @@ -29,6 +29,11 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) : "QWidget#edit_patient{min-width:300px;max-width:300px;}" "QTableWidget{border:none}" "QTableView{alternate-background-color: #595959;selection-color:white;selection-background-color:#0078d8}" + "QToolButton#sexBtn{min-width:120px;max-width:120px;font-size:20px;padding:2px;}" + "QToolButton#sexBtn:disabled{color:silver}" + "QWidget#sexpanelwidget{border:1px solid silver;}" + "QWidget#sexpanelwidget:enabled{background-color: #515151;}" + "QToolButton#sexBtn:checked{border:2px solid darkorange;padding:0px;}" ; this->setStyleSheet(this->styleSheet().append(style)); @@ -89,11 +94,12 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) : connect(table,&QTableView::clicked,[=](const QModelIndex & modelIndex){ if (currentRow!=modelIndex.row()) { + currentRow=modelIndex.row(); PatientInformation pat; -#define ADD_PATIENT_PROPERTY(val)\ + #define ADD_PATIENT_PROPERTY(val)\ pat. val = model->data(model->index(modelIndex.row(),PatientInformationEnum:: val)).toString(); EDIT_PATIENT() -#undef ADD_PATIENT_PROPERTY + #undef ADD_PATIENT_PROPERTY edit_patient->setPatientInformation(&pat); } }); @@ -107,38 +113,24 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) : edit_patient->setEditEnable(true); }); connect(edit_patient, &EditPatientForm::editAccept,[=](PatientInformation* inf){ - -// QSqlRecord record = inf->PatientUID.isEmpty()?model->record():model->record(currentRow); - int rowCount = model->rowCount(); - - bool isAdd = false; + int selectedRow = currentRow; if (inf->PatientUID.isEmpty()) { - isAdd = true; + selectedRow = model->rowCount(); inf->PatientUID = QUuid::createUuid().toString(); printf(inf->PatientUID.toStdString().data()); - model->insertRow(rowCount); + model->insertRow(selectedRow); } #define ADD_PATIENT_PROPERTY(val)\ - model->setData(model->index(rowCount,PatientInformationEnum:: val),inf-> val); -// record.setValue(PatientInformationEnum:: val, inf-> val); + model->setData(model->index(selectedRow,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(); + table->selectRow(selectedRow); + } + else{ + //TODO:add some error handle logic } -// else{ -// model->database().rollback(); -// } }); } diff --git a/src/editpatientform.cpp b/src/editpatientform.cpp index 382c6df..bd3836a 100644 --- a/src/editpatientform.cpp +++ b/src/editpatientform.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "guimacros.h" #include EditPatientForm::EditPatientForm(QWidget *parent) : @@ -10,11 +11,28 @@ EditPatientForm::EditPatientForm(QWidget *parent) : ui(new Ui::EditPatientForm) { ui->setupUi(this); - QListView* sex_v = new QListView(ui->cb_Sex); - sex_v->setItemAlignment(Qt::AlignCenter); - ui->cb_Sex->setView(sex_v); - QHBoxLayout* layout =new QHBoxLayout(); - this->ui->editcmdWidget->setLayout(layout); + QHBoxLayout* sexlayout =new QHBoxLayout(ui->sexpanelwidget); + sexlayout->setMargin(6); + ADD_TOOL_SIZE_BTN_TO_LAYOUT(F,":/icons/female_d.png",30, sexlayout); + ADD_TOOL_SIZE_BTN_TO_LAYOUT(M,":/icons/male_d.png", 30,sexlayout); +// btnFemale->setToolButtonStyle(Qt::ToolButtonIconOnly); +// btnMale->setToolButtonStyle(Qt::ToolButtonIconOnly); + btnF->setObjectName("sexBtn"); + btnM->setObjectName("sexBtn"); + btnF->setText("Female"); + btnM->setText("Male"); + ui->sexpanelwidget->setEnabled(editEnable); + btnF->setEnabled(editEnable); + btnM->setEnabled(editEnable); + btnF->setCheckable(true); + btnM->setCheckable(true); + QButtonGroup* group= new QButtonGroup(this); + group->addButton(btnF); + group->addButton(btnM); + btnF->setChecked(true); + btnFemale=btnF; + btnMale=btnM; + QHBoxLayout* layout =new QHBoxLayout(this->ui->editcmdWidget); ADD_TOOL_BTN(Cancel,":/icons/close_circle.png"); ADD_TOOL_BTN(Accpet,":/icons/selected.png"); btnCancel->setEnabled(editEnable); @@ -31,6 +49,8 @@ EditPatientForm::EditPatientForm(QWidget *parent) : restorePatientInformation(); }); connect(btnEditAccept,&QToolButton::clicked,[=](){ + if (ui->tbx_ID->text().isEmpty())return; + if (ui->tbx_Name->text().isEmpty())return; storePatientInformation(); this->setEditEnable(false); emit editAccept(getPatientInformation()); @@ -49,7 +69,8 @@ void EditPatientForm::setPatientInformation(PatientInformation *information) { ui->tbx_Dob->setDate(QDate::fromString(information->BirthDate,"yyyy-MM-dd")); ui->tbx_Name->setText(information->Name); ui->rtbx_Comment->setText(information->Comment); - ui->cb_Sex->setCurrentIndex(information->Sex=="F"?1:(information->Name=="M"?0:2)); + btnFemale->setChecked(information->Sex=="F"); + btnMale->setChecked(information->Sex!="F"); currentPatientUID = information->PatientUID; storePatientInformation(); } @@ -59,6 +80,8 @@ void EditPatientForm::clearPatientInformation() { ui->tbx_ID->setText(""); ui->tbx_Dob->setDate(QDate::currentDate()); ui->tbx_Name->setText(""); + btnFemale->setChecked(true); + btnMale->setChecked(false); ui->rtbx_Comment->setText(""); currentPatientUID = ""; } @@ -67,7 +90,11 @@ 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->sexpanelwidget->setEnabled(enable); + btnFemale->setEnabled(enable); + btnFemale->setIcon(QIcon(enable?":/icons/female.png":":/icons/female_d.png")); + btnMale->setEnabled(enable); + btnMale->setIcon(QIcon(enable?":/icons/male.png":":/icons/male_d.png")); ui->rtbx_Comment->setEnabled(enable); btnEditAccept->setEnabled(enable); btnEditCancel->setEnabled(enable); @@ -82,7 +109,7 @@ void EditPatientForm::storePatientInformation() { store.ID = ui->tbx_ID->text(); store.BirthDate = ui->tbx_Dob->date().toString("yyyy-MM-dd"); store.Name = ui->tbx_Name->text(); - store.Sex = ui->cb_Sex->currentText().left(1); + store.Sex = btnFemale->isChecked()?"F":"M"; store.Comment = ui->rtbx_Comment->toPlainText(); qDebug()<tbx_Dob->setDate(QDate::fromString(store.BirthDate,"yyyy-MM-dd")); ui->tbx_Name->setText(store.Name); ui->rtbx_Comment->setText(store.Comment); - ui->cb_Sex->setCurrentText(store.Sex=="F"?"Female":(store.Name=="M"?"Male":"Other")); + btnFemale->setChecked(store.Sex=="F"); + btnMale->setChecked(store.Sex!="F"); +// ui->cb_Sex->setCurrentText(store.Sex=="F"?"Female":(store.Name=="M"?"Male":"Other")); } diff --git a/src/editpatientform.h b/src/editpatientform.h index 0dd21eb..723cca1 100644 --- a/src/editpatientform.h +++ b/src/editpatientform.h @@ -59,6 +59,8 @@ private: bool editEnable=false; QToolButton* btnEditAccept; QToolButton* btnEditCancel; + QToolButton* btnFemale; + QToolButton* btnMale; }; #endif // EDITPATIENTFORM_H diff --git a/src/editpatientform.ui b/src/editpatientform.ui index c140d57..5f91cc4 100644 --- a/src/editpatientform.ui +++ b/src/editpatientform.ui @@ -67,35 +67,7 @@ - - - false - - - alignment:center - - - 1 - - - true - - - - Male - - - - - Female - - - - - Other - - - + diff --git a/src/guimacros.h b/src/guimacros.h index f186821..edd5958 100644 --- a/src/guimacros.h +++ b/src/guimacros.h @@ -4,15 +4,18 @@ #ifndef GUI_GUIMACROS_H #define GUI_GUIMACROS_H -#define ADD_TOOL_BTN_TO_LAYOUT(name,img,layout)\ +#define ADD_TOOL_SIZE_BTN_TO_LAYOUT(name,img,size,layout)\ QToolButton* btn##name= new QToolButton(this);\ btn##name->setToolButtonStyle(Qt::ToolButtonIconOnly);\ btn##name->setIcon(QIcon(img));\ - btn##name->setIconSize(QSize(120,120));\ + btn##name->setIconSize(QSize(size,size));\ btn##name->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);\ btn##name->setText(#name);\ layout->addWidget(btn##name); +#define ADD_TOOL_BTN_TO_LAYOUT(name,img,layout)\ + ADD_TOOL_SIZE_BTN_TO_LAYOUT(name,img,120,layout) + #define ADD_TOOL_BTN(name,img)\ ADD_TOOL_BTN_TO_LAYOUT(name,img,layout) diff --git a/src/icons/female.png b/src/icons/female.png new file mode 100644 index 0000000..16a0f9c Binary files /dev/null and b/src/icons/female.png differ diff --git a/src/icons/female_d.png b/src/icons/female_d.png new file mode 100644 index 0000000..efe77fd Binary files /dev/null and b/src/icons/female_d.png differ diff --git a/src/icons/male.png b/src/icons/male.png new file mode 100644 index 0000000..a8cb0da Binary files /dev/null and b/src/icons/male.png differ diff --git a/src/icons/male_d.png b/src/icons/male_d.png new file mode 100644 index 0000000..eeb6532 Binary files /dev/null and b/src/icons/male_d.png differ diff --git a/src/res.qrc b/src/res.qrc index cdb0d2d..3c5c923 100644 --- a/src/res.qrc +++ b/src/res.qrc @@ -22,5 +22,9 @@ icons/lock.png icons/msg.png icons/patient.png + icons/female.png + icons/male.png + icons/female_d.png + icons/male_d.png