New UI for sex choose

This commit is contained in:
Krad
2021-10-12 15:07:06 +08:00
parent 4de4cfd25a
commit 8406ac104c
10 changed files with 66 additions and 64 deletions

View File

@@ -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();
// }
});
}

View File

@@ -3,6 +3,7 @@
#include <QListView>
#include <QHBoxLayout>
#include <QToolButton>
#include <QButtonGroup>
#include "guimacros.h"
#include <qdebug.h>
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()<<store.PatientUID<<","<<store.ID<<","<<store.BirthDate<<","<<store.Name<<","<<store.Sex;
}
@@ -93,6 +120,8 @@ void EditPatientForm::restorePatientInformation() {
ui->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"));
}

View File

@@ -59,6 +59,8 @@ private:
bool editEnable=false;
QToolButton* btnEditAccept;
QToolButton* btnEditCancel;
QToolButton* btnFemale;
QToolButton* btnMale;
};
#endif // EDITPATIENTFORM_H

View File

@@ -67,35 +67,7 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="cb_Sex">
<property name="enabled">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">alignment:center</string>
</property>
<property name="currentIndex">
<number>1</number>
</property>
<property name="frame">
<bool>true</bool>
</property>
<item>
<property name="text">
<string>Male</string>
</property>
</item>
<item>
<property name="text">
<string>Female</string>
</property>
</item>
<item>
<property name="text">
<string>Other</string>
</property>
</item>
</widget>
<widget class="QWidget" name="sexpanelwidget" native="true"/>
</item>
<item>
<widget class="QLabel" name="lbl_DOB">

View File

@@ -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)

BIN
src/icons/female.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
src/icons/female_d.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
src/icons/male.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
src/icons/male_d.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@@ -22,5 +22,9 @@
<file>icons/lock.png</file>
<file>icons/msg.png</file>
<file>icons/patient.png</file>
<file>icons/female.png</file>
<file>icons/male.png</file>
<file>icons/female_d.png</file>
<file>icons/male_d.png</file>
</qresource>
</RCC>