diff --git a/src/SelectFormWidget.cpp b/src/SelectFormWidget.cpp index 1834088..c9f1bfa 100644 --- a/src/SelectFormWidget.cpp +++ b/src/SelectFormWidget.cpp @@ -6,6 +6,7 @@ #include #include #include +#include "components/SlideableTableView.h" #include #include #include @@ -22,6 +23,15 @@ item->setTextAlignment(Qt::AlignmentFlag::AlignCenter);\ table->setItem(row,col,item); + +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; +} + SelectFormWidget::SelectFormWidget(QWidget *parent) : TabFormWidget(parent) { @@ -60,33 +70,38 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) : QHBoxLayout* contentLayout =new QHBoxLayout(); this->ui->contentWidget->setLayout(contentLayout); // TableView for patient - QTableView* table= new QTableView(this); + 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); - //dat from SQLITE + //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(6); + table->hideColumn(7); + 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); @@ -136,15 +151,28 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) : connect(edit_patient, &EditPatientForm::editCancel,[=](){ btnSelect->setEnabled(true); }); - connect(edit_patient, &EditPatientForm::editAccept,[=](PatientInformation* inf){ + 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()<scrollTo(model->index(ref_rowid,3)); + table->selectRow(ref_rowid); + result = false; + return; + } selectedRow = model->rowCount(); inf->PatientUID = QUuid::createUuid().toString(); - printf(inf->PatientUID.toStdString().data()); - model->insertRow(selectedRow); + inf->AddDate = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"); + model->insertRow(0); + selectedRow = 0; } + qDebug()<PatientUID<AddDate; #define ADD_PATIENT_PROPERTY(val)\ model->setData(model->index(selectedRow,PatientInformationEnum:: val),inf-> val); EDIT_PATIENT() @@ -221,6 +249,7 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) : } + SelectFormWidget::~SelectFormWidget() { } \ No newline at end of file diff --git a/src/SelectFormWidget.h b/src/SelectFormWidget.h index 4fc12cd..97f97bc 100644 --- a/src/SelectFormWidget.h +++ b/src/SelectFormWidget.h @@ -14,6 +14,7 @@ public: private: int currentRow = -1; + }; diff --git a/src/components/SlideableTableView.cpp b/src/components/SlideableTableView.cpp index 2e0b934..186f732 100644 --- a/src/components/SlideableTableView.cpp +++ b/src/components/SlideableTableView.cpp @@ -61,9 +61,10 @@ void SlideableTableView::mouseReleaseEvent(QMouseEvent *ev) { { isDragging = false; } - if (this->verticalScrollBar()->isVisible()) - { - QApplication::sendEvent(this->verticalScrollBar(),ev); - } + +// if (this->verticalScrollBar()->isVisible()) +// { +// QApplication::sendEvent(this->verticalScrollBar(),ev); +// } QTableView::mouseReleaseEvent(ev); } diff --git a/src/editpatientform.cpp b/src/editpatientform.cpp index cbf2729..9405748 100644 --- a/src/editpatientform.cpp +++ b/src/editpatientform.cpp @@ -11,12 +11,14 @@ EditPatientForm::EditPatientForm(QWidget *parent) : ui(new Ui::EditPatientForm) { ui->setupUi(this); + ui->lbl_Sex->setText(tr("Gender")); 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"); @@ -53,8 +55,9 @@ EditPatientForm::EditPatientForm(QWidget *parent) : if (ui->tbx_ID->text().isEmpty())return; if (ui->tbx_Name->text().isEmpty())return; storePatientInformation(); - this->setEditEnable(false); - emit editAccept(getPatientInformation()); + bool result = true; + emit editAccept(getPatientInformation(), result); + if (result) this->setEditEnable(false); }); ui->tbx_Dob->setDisplayFormat("yyyy/MM/dd"); } @@ -74,6 +77,7 @@ void EditPatientForm::setPatientInformation(PatientInformation *information) { btnFemale->setChecked(information->Sex=="F"); btnMale->setChecked(information->Sex!="F"); currentPatientUID = information->PatientUID; + AddDate = information->AddDate; storePatientInformation(); } } @@ -86,6 +90,7 @@ void EditPatientForm::clearPatientInformation() { btnMale->setChecked(false); ui->rtbx_Comment->setText(""); currentPatientUID = ""; + AddDate = ""; } void EditPatientForm::setEditEnable(bool enable) { @@ -108,6 +113,7 @@ void EditPatientForm::setEditEnable(bool enable) { void EditPatientForm::storePatientInformation() { store.PatientUID =currentPatientUID; + store.AddDate = AddDate; store.ID = ui->tbx_ID->text(); store.BirthDate = ui->tbx_Dob->date().toString("yyyy-MM-dd"); store.Name = ui->tbx_Name->text(); @@ -118,6 +124,7 @@ void EditPatientForm::storePatientInformation() { void EditPatientForm::restorePatientInformation() { currentPatientUID = store.PatientUID; + AddDate = store.AddDate; ui->tbx_ID->setText(store.ID); ui->tbx_Dob->setDate(QDate::fromString(store.BirthDate,"yyyy-MM-dd")); ui->tbx_Name->setText(store.Name); diff --git a/src/editpatientform.h b/src/editpatientform.h index 0a4214d..3db537e 100644 --- a/src/editpatientform.h +++ b/src/editpatientform.h @@ -12,6 +12,7 @@ ADD_PATIENT_PROPERTY(ID)\ ADD_PATIENT_PROPERTY(Name)\ ADD_PATIENT_PROPERTY(BirthDate)\ ADD_PATIENT_PROPERTY(Sex)\ +ADD_PATIENT_PROPERTY(AddDate)\ ADD_PATIENT_PROPERTY(Comment)\ ADD_PATIENT_PROPERTY(Flag) @@ -67,11 +68,12 @@ public: void restorePatientInformation(); void setEditEnable(bool enable); signals: - void editAccept(PatientInformation * detail); + void editAccept(PatientInformation * detail,bool & accept); void editCancel(); private: Ui::EditPatientForm *ui; QString currentPatientUID; + QString AddDate; PatientInformation store; bool editEnable=false; QToolButton* btnEditAccept;