基本完成网络设置模块,还有一些细节需要完善。

This commit is contained in:
xueyan hu
2021-12-17 18:02:39 +08:00
parent faa69197f3
commit b6475e7ed4
21 changed files with 1979 additions and 421 deletions

View File

@@ -26,226 +26,227 @@
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;
for (int i = 0; i < model->rowCount(); ++i) {
if (model->data(model->index(i, colID)) == var) return i;
}
return -1;
}
SelectFormWidget::SelectFormWidget(QWidget *parent) :
TabFormWidget(parent)
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;}"
// "QTableView{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));
//init command bar
QHBoxLayout* layout =new QHBoxLayout();
ui->commandWidget->setLayout(layout);
ADD_TOOL_BTN(Account,":/icons/account.png");
ADD_TOOL_BTN(Worklist,":/icons/setting.png");
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");
ADD_TOOL_BTN(Edit,":/icons/details.png");
ADD_TOOL_BTN(Delete,":/icons/close_circle.png");
ADD_TOOL_BTN(Select,":/icons/selected.png");
// 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;}"
// "QTableView{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));
//init command bar
QHBoxLayout* layout = new QHBoxLayout();
ui->commandWidget->setLayout(layout);
ADD_TOOL_BTN(Account, ":/icons/account.png");
ADD_TOOL_BTN(Worklist, ":/icons/setting.png");
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");
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);
// TableView for patient
QTableView* table= new SlideableTableView(this);
table->setAlternatingRowColors(true);
table->setSelectionMode(QAbstractItemView::SingleSelection);
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
table->setSelectionBehavior(QAbstractItemView::SelectRows);
table->verticalHeader()->setDefaultSectionSize(38);
table->horizontalHeader()->setStretchLastSection(true);
//data from SQLITE
//Init content widget
QHBoxLayout* contentLayout = new QHBoxLayout();
this->ui->contentWidget->setLayout(contentLayout);
// TableView for patient
QTableView* table = new SlideableTableView(this);
table->setAlternatingRowColors(true);
table->setSelectionMode(QAbstractItemView::SingleSelection);
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
table->setSelectionBehavior(QAbstractItemView::SelectRows);
table->verticalHeader()->setDefaultSectionSize(38);
table->horizontalHeader()->setStretchLastSection(true);
//data from SQLITE
auto model = SQLHelper::getTable("Patient");
model->setFilter("Flag=0");
model->sort(5,Qt::DescendingOrder);
model->select();
model->setHeaderData(1,Qt::Horizontal,"ID");
model->setHeaderData(2,Qt::Horizontal,"Name");
model->setHeaderData(3,Qt::Horizontal,"Birth Date");
model->setHeaderData(5,Qt::Horizontal,"Add Date");
table->setModel((QAbstractItemModel*)model);
table->hideColumn(0);
table->hideColumn(7);
auto model = SQLHelper::getTable("Patient");
model->setFilter("Flag=0");
model->sort(5, Qt::DescendingOrder);
model->select();
model->setHeaderData(1, Qt::Horizontal, "ID");
model->setHeaderData(2, Qt::Horizontal, "Name");
model->setHeaderData(3, Qt::Horizontal, "Birth Date");
model->setHeaderData(5, Qt::Horizontal, "Add Date");
table->setModel((QAbstractItemModel*)model);
table->hideColumn(0);
table->hideColumn(7);
table->show();
table->show();
// table->setSortingEnabled(true);
table->setColumnWidth(1,250);
table->setColumnWidth(2,250);
table->setColumnWidth(3,120);
table->setColumnWidth(4,60);
table->setColumnWidth(5,250);
// table->sortByColumn(5);
// table->setSortingEnabled(true);
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);
//select default row 0
if (model->rowCount()>0)
{
table->selectRow(0);
currentRow=0;
PatientInformation pat;
#define ADD_PATIENT_PROPERTY(val)\
// table->setSortingEnabled(true);
table->setColumnWidth(1, 250);
table->setColumnWidth(2, 250);
table->setColumnWidth(3, 120);
table->setColumnWidth(4, 60);
table->setColumnWidth(5, 250);
// table->sortByColumn(5);
// table->setSortingEnabled(true);
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);
//select default row 0
if (model->rowCount() > 0)
{
table->selectRow(0);
currentRow = 0;
PatientInformation pat;
#define ADD_PATIENT_PROPERTY(val)\
pat. val = model->data(model->index(currentRow,PatientInformationEnum:: val)).toString();
EDIT_PATIENT()
#undef ADD_PATIENT_PROPERTY
edit_patient->setPatientInformation(&pat);
}
//events----------------------------------------------------------------------
//table current row selection changing event
connect(table,&QTableView::clicked,[=](const QModelIndex & modelIndex){
if (currentRow!=modelIndex.row())
{
currentRow=modelIndex.row();
PatientInformation pat;
#define ADD_PATIENT_PROPERTY(val)\
EDIT_PATIENT()
#undef ADD_PATIENT_PROPERTY
edit_patient->setPatientInformation(&pat);
}
//events----------------------------------------------------------------------
//table current row selection changing event
connect(table, &QTableView::clicked, [=](const QModelIndex& modelIndex) {
if (currentRow != modelIndex.row())
{
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);
}
});
EDIT_PATIENT()
#undef ADD_PATIENT_PROPERTY
edit_patient->setPatientInformation(&pat);
}
});
connect(btnAdd, &QToolButton::clicked,[=](){
edit_patient->clearPatientInformation();
edit_patient->setEditEnable(true);
btnSelect->setEnabled(false);
});
connect(btnEdit, &QToolButton::clicked,[=](){
table->clicked(table->currentIndex());
edit_patient->setEditEnable(true);
btnSelect->setEnabled(false);
});
connect(edit_patient, &EditPatientForm::editCancel,[=](){
btnSelect->setEnabled(true);
});
connect(edit_patient, &EditPatientForm::editAccept,[=](PatientInformation* inf, bool& result){
int selectedRow = currentRow;
bool isAdd = inf->PatientUID.isEmpty();
if (isAdd) {
int ref_rowid = queryValue(model, 1, inf->ID);
if(ref_rowid>=0)
{
//非触屏时,如果被选中的行在选中区域外,以下代码可能会出错
//但是触屏时一般没问题
qDebug()<<ref_rowid;
table->scrollTo(model->index(ref_rowid,3));
table->selectRow(ref_rowid);
result = false;
return;
}
selectedRow = model->rowCount();
inf->PatientUID = QUuid::createUuid().toString();
inf->AddDate = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");
model->insertRow(0);
selectedRow = 0;
}
qDebug()<<inf->PatientUID<<inf->AddDate;
#define ADD_PATIENT_PROPERTY(val)\
connect(btnAdd, &QToolButton::clicked, [=]() {
edit_patient->clearPatientInformation();
edit_patient->setEditEnable(true);
btnSelect->setEnabled(false);
});
connect(btnEdit, &QToolButton::clicked, [=]() {
table->clicked(table->currentIndex());
edit_patient->setEditEnable(true);
btnSelect->setEnabled(false);
});
connect(edit_patient, &EditPatientForm::editCancel, [=]() {
btnSelect->setEnabled(true);
});
connect(edit_patient, &EditPatientForm::editAccept, [=](PatientInformation* inf, bool& result) {
int selectedRow = currentRow;
bool isAdd = inf->PatientUID.isEmpty();
if (isAdd) {
int ref_rowid = queryValue(model, 1, inf->ID);
if (ref_rowid >= 0)
{
//非触屏时,如果被选中的行在选中区域外,以下代码可能会出错
//但是触屏时一般没问题
qDebug() << ref_rowid;
table->scrollTo(model->index(ref_rowid, 3));
table->selectRow(ref_rowid);
result = false;
return;
}
selectedRow = model->rowCount();
inf->PatientUID = QUuid::createUuid().toString();
inf->AddDate = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");
model->insertRow(0);
selectedRow = 0;
}
qDebug() << inf->PatientUID << inf->AddDate;
#define ADD_PATIENT_PROPERTY(val)\
model->setData(model->index(selectedRow,PatientInformationEnum:: val),inf-> val);
EDIT_PATIENT()
#undef ADD_PATIENT_PROPERTY
if (model->submitAll())
{
table->selectRow(selectedRow);
model->selectRow(selectedRow);
}
else{
//TODO:add some error handle logic
}
if(isAdd){
LOG_USER_OPERATION(AddPatient);
}
else
{
LOG_USER_OPERATION(ChangePatientInfo);
}
btnSelect->setEnabled(true);
});
EDIT_PATIENT()
#undef ADD_PATIENT_PROPERTY
if (model->submitAll())
{
table->selectRow(selectedRow);
model->selectRow(selectedRow);
}
else {
//TODO:add some error handle logic
}
if (isAdd) {
LOG_USER_OPERATION(AddPatient);
}
else
{
LOG_USER_OPERATION(ChangePatientInfo);
}
btnSelect->setEnabled(true);
});
connect(btnDelete, &QToolButton::clicked,[=](){
if (currentRow<0)return;
model->setData(model->index(currentRow,PatientInformationEnum::Flag),9);
// model->removeRow(currentRow);
if (model->submitAll())
{
model->select();
if (model->rowCount()>0)
{
table->selectRow(0);
model->selectRow(0);
PatientInformation pat;
#define ADD_PATIENT_PROPERTY(val)\
connect(btnDelete, &QToolButton::clicked, [=]() {
if (currentRow < 0)return;
model->setData(model->index(currentRow, PatientInformationEnum::Flag), 9);
// model->removeRow(currentRow);
if (model->submitAll())
{
model->select();
if (model->rowCount() > 0)
{
table->selectRow(0);
model->selectRow(0);
PatientInformation pat;
#define ADD_PATIENT_PROPERTY(val)\
pat. val = model->data(model->index(0,PatientInformationEnum:: val)).toString();
EDIT_PATIENT()
#undef ADD_PATIENT_PROPERTY
edit_patient->setPatientInformation(&pat);
LOG_USER_OPERATION(DeletePatient);
} else{
currentRow=-1;
}
} else{
//TODO:error handle
}
EDIT_PATIENT()
#undef ADD_PATIENT_PROPERTY
edit_patient->setPatientInformation(&pat);
LOG_USER_OPERATION(DeletePatient);
}
else {
currentRow = -1;
}
}
else {
//TODO:error handle
}
});
});
connect(btnSelect, &QToolButton::clicked,[=](){
if (currentRow<0)return;
EventCenter::Default()->triggerEvent(GUIEvents::PatientSelected, nullptr,edit_patient->getPatientInformation()->Copy());
LOG_USER_OPERATION(SelectPatient);
});
connect(btnSelect, &QToolButton::clicked, [=]() {
if (currentRow < 0)return;
EventCenter::Default()->triggerEvent(GUIEvents::PatientSelected, nullptr, edit_patient->getPatientInformation()->Copy());
LOG_USER_OPERATION(SelectPatient);
});
connect(btnAccount, &QToolButton::clicked,[=](){
AccountFormDialog dia(this);
dia.setWindowModality(Qt::WindowModal);
dia.exec();
});
connect(EventCenter::Default(),&EventCenter::ResponsePreview,[=](QObject* sender,QObject* data){
btnSelect->setEnabled(false);
btnDelete->setEnabled(false);
btnEdit->setEnabled(false);
btnAdd->setEnabled(false);
});
connect(EventCenter::Default(),&EventCenter::ResponseStop,[=](QObject* sender,QObject* data){
btnSelect->setEnabled(true);
btnDelete->setEnabled(true);
btnEdit->setEnabled(true);
btnAdd->setEnabled(true);
});
connect(btnAccount, &QToolButton::clicked, [=]() {
AccountFormDialog dia(this);
dia.setWindowModality(Qt::WindowModal);
dia.exec();
});
connect(EventCenter::Default(), &EventCenter::ResponsePreview, [=](QObject* sender, QObject* data) {
btnSelect->setEnabled(false);
btnDelete->setEnabled(false);
btnEdit->setEnabled(false);
btnAdd->setEnabled(false);
});
connect(EventCenter::Default(), &EventCenter::ResponseStop, [=](QObject* sender, QObject* data) {
btnSelect->setEnabled(true);
btnDelete->setEnabled(true);
btnEdit->setEnabled(true);
btnAdd->setEnabled(true);
});
}