Add new components, ListBox and EditPatientDialog.
This commit is contained in:
212
src/EditPatientDialog.cpp
Normal file
212
src/EditPatientDialog.cpp
Normal file
@@ -0,0 +1,212 @@
|
||||
//
|
||||
// Created by Krad on 2022/3/21.
|
||||
//
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QDateTime>
|
||||
#include <QLineEdit>
|
||||
#include <QTextEdit>
|
||||
#include <QToolButton>
|
||||
#include <QSqlTableModel>
|
||||
#include <QUuid>
|
||||
#include "EditPatientDialog.h"
|
||||
#include "SelectDialog.h"
|
||||
#include "DateSelectDialog.h"
|
||||
#include "components/Listbox.h"
|
||||
|
||||
int queryValue(QSqlTableModel* model, int colID, QVariant var)
|
||||
{
|
||||
for (int i = 0; i < model->rowCount(); ++i) {
|
||||
if (model->data(model->index(i, colID)) == var) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
EditPatientDialog::EditPatientDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
|
||||
QVBoxLayout* layout = new QVBoxLayout(formWidget);
|
||||
layout->setSpacing(10);
|
||||
// add title
|
||||
QLabel* lbl_title = new QLabel(this);
|
||||
lbl_title->setAlignment(Qt::AlignCenter);
|
||||
lbl_title->setText(tr("Edit Patient"));
|
||||
lbl_title->setObjectName("title");
|
||||
layout->addWidget(lbl_title);
|
||||
|
||||
//add old password
|
||||
QLabel* lbl_id = new QLabel(this);
|
||||
lbl_id->setText(tr("ID"));
|
||||
le_id = new QLineEdit(this);
|
||||
layout->addWidget(lbl_id);
|
||||
layout->addWidget(le_id);
|
||||
QLabel* lbl_endline1 = new QLabel(this);
|
||||
lbl_endline1->setObjectName("endline");
|
||||
layout->addWidget(lbl_endline1);
|
||||
|
||||
QLabel* lbl_name= new QLabel(this);
|
||||
lbl_name->setText(tr("Name"));
|
||||
le_name = new QLineEdit(this);
|
||||
layout->addWidget(lbl_name);
|
||||
layout->addWidget(le_name);
|
||||
QLabel* lbl_endline2 = new QLabel(this);
|
||||
lbl_endline2->setObjectName("endline");
|
||||
layout->addWidget(lbl_endline2);
|
||||
|
||||
QLabel* lbl_sex= new QLabel(this);
|
||||
lbl_sex->setText(tr("Gender"));
|
||||
layout->addWidget(lbl_sex);
|
||||
btnSex = new Listbox(this);
|
||||
btnSex->setText(tr("Female"));
|
||||
btnSex->setProperty("idx",0);
|
||||
btnSex->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
btnSex->setLayoutDirection(Qt::RightToLeft);
|
||||
btnSex->setObjectName("editvalBtn");
|
||||
btnSex->setIcon(QIcon(":/icons/arrow-down.png"));
|
||||
btnSex->setIconSize({30, 30});
|
||||
|
||||
btnSex->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
connect(btnSex, &QToolButton::clicked,[=](){
|
||||
SelectDialog dialog(this);
|
||||
QStringList items;
|
||||
items<<tr("Female")<<tr("Male")<<tr("Other");
|
||||
dialog.setValues(items);
|
||||
dialog.setSelectedValue(items[btnSex->property("idx").toInt()]);
|
||||
dialog.setWindowModality(Qt::WindowModal);
|
||||
if (dialog.exec() == QDialog::Accepted){
|
||||
btnSex->setText(dialog.getSelectedValue());
|
||||
btnSex->setProperty("idx",items.indexOf(dialog.getSelectedValue()));
|
||||
}
|
||||
});
|
||||
layout->addWidget(btnSex);
|
||||
QLabel *lbl_endline9 = new QLabel(this);
|
||||
lbl_endline9->setFixedHeight(2);
|
||||
lbl_endline9->setObjectName("endline");
|
||||
layout->addWidget(lbl_endline9);
|
||||
|
||||
|
||||
QLabel* lbl_date = new QLabel(this);
|
||||
lbl_date->setText(tr("Birth Date"));
|
||||
|
||||
layout->addWidget(lbl_date);
|
||||
btnDate = new Listbox(this);
|
||||
btnDate->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
btnDate->setLayoutDirection(Qt::RightToLeft);
|
||||
btnDate->setObjectName("editvalBtn");
|
||||
btnDate->setIcon(QIcon(":/icons/arrow-down.png"));
|
||||
btnDate->setIconSize({30, 30});
|
||||
btnDate->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
btnDate->setText("1990-06-15");
|
||||
connect(btnDate, &QToolButton::clicked,[=](){
|
||||
DateSelectDialog dialog(this);
|
||||
dialog.setSelectedValue(btnDate->text());
|
||||
dialog.setWindowModality(Qt::WindowModal);
|
||||
if (dialog.exec() == QDialog::Accepted){
|
||||
btnDate->setText(dialog.getSelectedValue());
|
||||
}
|
||||
});
|
||||
layout->addWidget(btnDate);
|
||||
QLabel* lbl_endline5 = new QLabel(this);
|
||||
lbl_endline5->setObjectName("endline");
|
||||
layout->addWidget(lbl_endline5);
|
||||
|
||||
QLabel* lbl_comment = new QLabel(this);
|
||||
lbl_comment->setText(tr("Comment"));
|
||||
te_comment = new QTextEdit(this);
|
||||
layout->addWidget(lbl_comment);
|
||||
layout->addWidget(te_comment);
|
||||
QLabel* lbl_endline6 = new QLabel(this);
|
||||
lbl_endline6->setObjectName("endline");
|
||||
layout->addWidget(lbl_endline6);
|
||||
|
||||
lbl_error = new QLabel(this);
|
||||
lbl_error->setObjectName("warn");
|
||||
layout->addWidget(lbl_error);
|
||||
}
|
||||
|
||||
EditPatientDialog::~EditPatientDialog() {
|
||||
|
||||
}
|
||||
|
||||
void EditPatientDialog::setPatientInformation(PatientInformation* information) {
|
||||
if (information)
|
||||
{
|
||||
le_id->setText(information->ID);
|
||||
btnSex->setText(information->Sex == tr("F")?tr("Female"):(information->Sex == tr("M")?tr("Male"):tr("Other")));
|
||||
le_name->setText(information->Name);
|
||||
te_comment->setText(information->Comment);
|
||||
btnDate->setText(information->BirthDate);
|
||||
currentPatientUID = information->PatientUID;
|
||||
AddDate = information->AddDate;
|
||||
le_id->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void EditPatientDialog::clearPatientInformation() {
|
||||
le_id->setText("");
|
||||
// le_date->setText("");
|
||||
le_name->setText("");
|
||||
te_comment->setText("");
|
||||
}
|
||||
|
||||
void EditPatientDialog::storePatientInformation() {
|
||||
store.PatientUID = currentPatientUID;
|
||||
// store.AddDate = AddDate;
|
||||
store.ID = le_id->text();
|
||||
store.BirthDate = le_date->text();
|
||||
store.Name = le_name->text();
|
||||
store.Sex = le_sex->text();
|
||||
store.Comment = te_comment->toPlainText();
|
||||
}
|
||||
|
||||
bool EditPatientDialog::updateReferenceData() {
|
||||
PatientInformation* inf = getPatientInformation();
|
||||
if (le_id->text().isEmpty()){
|
||||
lbl_error->setText("ID can't be empty!");
|
||||
lbl_error->setVisible(true);
|
||||
return false;
|
||||
}
|
||||
inf->ID = le_id->text().trimmed();
|
||||
if (le_name->text().isEmpty()){
|
||||
lbl_error->setText("Patient Name can't be empty!");
|
||||
lbl_error->setVisible(true);
|
||||
return false;
|
||||
}
|
||||
inf->Name = le_name->text().trimmed();
|
||||
int selectedRow = 0;
|
||||
bool isAdd = currentPatientUID.isEmpty();
|
||||
if (isAdd) {
|
||||
int ref_rowid = queryValue(model, 1, inf->ID);
|
||||
if (ref_rowid >= 0)
|
||||
{
|
||||
lbl_error->setText("The ID is already existed!");
|
||||
lbl_error->setVisible(true);
|
||||
return false;
|
||||
}
|
||||
inf->PatientUID = QUuid::createUuid().toString();
|
||||
inf->AddDate = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");
|
||||
model->insertRow(0);
|
||||
}
|
||||
else{
|
||||
inf->PatientUID = currentPatientUID;
|
||||
selectedRow = queryValue(model, 1, inf->ID);
|
||||
inf->AddDate = AddDate;
|
||||
}
|
||||
inf->Sex = btnSex->text()==tr("Female")?"F":(tr("Male")==btnSex->text()?"M":"O");
|
||||
inf->BirthDate = btnDate->text();
|
||||
inf->Comment = te_comment->toPlainText();
|
||||
|
||||
|
||||
#define ADD_PATIENT_PROPERTY(val)\
|
||||
model->setData(model->index(selectedRow,PatientInformationEnum:: val),inf-> val);
|
||||
EDIT_PATIENT()
|
||||
#undef ADD_PATIENT_PROPERTY
|
||||
if (model->submitAll())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
lbl_error->setText("Submit to database error!");
|
||||
lbl_error->setVisible(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
53
src/EditPatientDialog.h
Normal file
53
src/EditPatientDialog.h
Normal file
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// Created by Krad on 2022/3/21.
|
||||
//
|
||||
|
||||
#ifndef GUI_EDITPATIENTDIALOG_H
|
||||
#define GUI_EDITPATIENTDIALOG_H
|
||||
|
||||
#include "GUIFormBaseDialog.h"
|
||||
#include "editpatientform.h"
|
||||
|
||||
class QLineEdit;
|
||||
class QTextEdit;
|
||||
class QLabel;
|
||||
class QToolButton;
|
||||
class QSqlTableModel;
|
||||
class EditPatientDialog :public GUIFormBaseDialog{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit EditPatientDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
~EditPatientDialog();
|
||||
|
||||
void setModel(QSqlTableModel * m){
|
||||
model=m;
|
||||
}
|
||||
|
||||
PatientInformation * getPatientInformation(){
|
||||
return &store;
|
||||
}
|
||||
void setPatientInformation(PatientInformation * information);
|
||||
void clearPatientInformation();
|
||||
void storePatientInformation();
|
||||
|
||||
|
||||
protected:
|
||||
bool updateReferenceData() override;
|
||||
|
||||
private:
|
||||
QLineEdit* le_id= nullptr;
|
||||
QLineEdit* le_name = nullptr;
|
||||
QLineEdit* le_sex = nullptr;
|
||||
QLineEdit* le_date = nullptr;
|
||||
QTextEdit* te_comment = nullptr;
|
||||
QLabel* lbl_error = nullptr;
|
||||
PatientInformation store;
|
||||
QString currentPatientUID;
|
||||
QString AddDate;
|
||||
QToolButton* btnSex = nullptr;
|
||||
QToolButton* btnDate = nullptr;
|
||||
QSqlTableModel* model = nullptr;
|
||||
};
|
||||
|
||||
|
||||
#endif //GUI_EDITPATIENTDIALOG_H
|
||||
20
src/components/Listbox.cpp
Normal file
20
src/components/Listbox.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Created by Krad on 2022/3/21.
|
||||
//
|
||||
|
||||
#include <QtWidgets/qstyleoption.h>
|
||||
#include <QPaintEvent>
|
||||
#include <QStylePainter>
|
||||
#include "Listbox.h"
|
||||
|
||||
void Listbox::paintEvent(QPaintEvent *e) {
|
||||
QString temp = this->text();
|
||||
this->setText("");
|
||||
QToolButton::paintEvent(e);
|
||||
this->setText(temp);
|
||||
QStylePainter p(this);
|
||||
QStyleOptionToolButton opt;
|
||||
initStyleOption(&opt);
|
||||
|
||||
p.drawText((size().width()-this->iconSize().width())/2-(this->text().length()*opt.font.pixelSize())/4,this->iconSize().height()+2,this->text());
|
||||
}
|
||||
21
src/components/Listbox.h
Normal file
21
src/components/Listbox.h
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// Created by Krad on 2022/3/21.
|
||||
//
|
||||
|
||||
#ifndef GUI_LISTBOX_H
|
||||
#define GUI_LISTBOX_H
|
||||
|
||||
#include <QToolButton>
|
||||
class Listbox: public QToolButton {
|
||||
public:
|
||||
explicit Listbox(QWidget* parent = nullptr){};
|
||||
virtual ~Listbox(){};
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent* e) override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif //GUI_LISTBOX_H
|
||||
Reference in New Issue
Block a user