diff --git a/src/AccountTableForm.cpp b/src/AccountTableForm.cpp new file mode 100644 index 0000000..cebefc4 --- /dev/null +++ b/src/AccountTableForm.cpp @@ -0,0 +1,47 @@ +// +// Created by Krad on 2021/12/8. +// + +#include "AccountTableForm.h" +#include +#include +#include + +#include "db/SQLHelper.h" +#include "components/SlideableTableView.h" +AccountTableForm::AccountTableForm(QWidget *parent) { + layout = new QVBoxLayout(this); + QTableView* table = new SlideableTableView(this); + layout->addWidget(table); + // TableView for patient + 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("Account"); + model->sort(5,Qt::DescendingOrder); + model->select(); + model->setHeaderData(1,Qt::Horizontal,"ID"); + model->setHeaderData(2,Qt::Horizontal,"Name"); + model->setHeaderData(4,Qt::Horizontal,"Role"); + model->setHeaderData(5,Qt::Horizontal,"Comment"); + table->setModel((QAbstractItemModel*)model); + table->hideColumn(0); + table->hideColumn(3); + AccountRoleComboDelegate* comboDelegate = new AccountRoleComboDelegate(this); + table->setItemDelegateForColumn(4,comboDelegate); + table->show(); + +// table->setSortingEnabled(true); + table->setColumnWidth(1,250); + table->setColumnWidth(2,250); + table->setColumnWidth(4,150); +} + +AccountTableForm::~AccountTableForm() { + +} diff --git a/src/AccountTableForm.h b/src/AccountTableForm.h new file mode 100644 index 0000000..b75c6ba --- /dev/null +++ b/src/AccountTableForm.h @@ -0,0 +1,23 @@ +// +// Created by Krad on 2021/12/8. +// + +#ifndef GUI_ACCOUNTTABLEFORM_H +#define GUI_ACCOUNTTABLEFORM_H + +#include +class QTableView; +class QPushButton; +class QVBoxLayout; +class SelectDialog; +class AccountTableForm: public QWidget { +Q_OBJECT +public: + explicit AccountTableForm(QWidget* parent = nullptr); + ~AccountTableForm(); +private: + QVBoxLayout* layout = nullptr; +}; + + +#endif //GUI_ACCOUNTTABLEFORM_H diff --git a/src/AdminSettingForm.cpp b/src/AdminSettingForm.cpp index 6fbcbf9..6a4bf50 100644 --- a/src/AdminSettingForm.cpp +++ b/src/AdminSettingForm.cpp @@ -15,6 +15,7 @@ #include "generalform.h" #include #include "systemsettingform.h" +#include "AccountTableForm.h" AdminSettingForm::AdminSettingForm(QWidget* parent, Qt::WindowFlags f) : TabFormWidget(parent) { @@ -42,8 +43,8 @@ AdminSettingForm::AdminSettingForm(QWidget* parent, Qt::WindowFlags f) : TabForm GeneralForm* generalForm = new GeneralForm(this); stackedWidget->addWidget(generalForm); - QLabel* acc = new QLabel(this); - acc->setText("Account Manage"); + AccountTableForm* acc = new AccountTableForm(this); + stackedWidget->addWidget(acc); systemSettingForm* systemSetting = new systemSettingForm(this); diff --git a/src/components/AccountRoleComboDelegate.cpp b/src/components/AccountRoleComboDelegate.cpp new file mode 100644 index 0000000..8929a76 --- /dev/null +++ b/src/components/AccountRoleComboDelegate.cpp @@ -0,0 +1,21 @@ +// +// Created by Krad on 2021/12/8. +// + +#include "AccountRoleComboDelegate.h" +#include +#include +#include "db/SQLHelper.h" +AccountRoleComboDelegate::AccountRoleComboDelegate(QWidget *parent):QItemDelegate(parent) { + SQLHelper::QueryMap("select RoleID,RoleName from Role",map); +} + +void AccountRoleComboDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { + + QString text = index.model()->data(index, Qt::DisplayRole).toString(); + + //绘制文本 + painter->drawText(option.rect, Qt::TextWordWrap | Qt::AlignCenter , map[text].toString()); +} + + diff --git a/src/components/AccountRoleComboDelegate.h b/src/components/AccountRoleComboDelegate.h new file mode 100644 index 0000000..f533453 --- /dev/null +++ b/src/components/AccountRoleComboDelegate.h @@ -0,0 +1,23 @@ +// +// Created by Krad on 2021/12/8. +// + +#ifndef GUI_ACCOUNTROLECOMBODELEGATE_H + +#define GUI_ACCOUNTROLECOMBODELEGATE_H + +#include +#include +class AccountRoleComboDelegate:public QItemDelegate { + Q_OBJECT +public: + explicit AccountRoleComboDelegate(QWidget *parent = nullptr); + void paint(QPainter *painter, + const QStyleOptionViewItem &option, + const QModelIndex &index) const override; +private: + QAbstractItemModel* model = nullptr; + QMap map ; +}; + +#endif //GUI_ACCOUNTROLECOMBODELEGATE_H