Account Table form

This commit is contained in:
Krad
2021-12-08 15:10:56 +08:00
parent f00501f680
commit a65d293fb2
5 changed files with 117 additions and 2 deletions

47
src/AccountTableForm.cpp Normal file
View File

@@ -0,0 +1,47 @@
//
// Created by Krad on 2021/12/8.
//
#include "AccountTableForm.h"
#include <QVBoxLayout>
#include <QHeaderView>
#include <src/components/AccountRoleComboDelegate.h>
#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() {
}

23
src/AccountTableForm.h Normal file
View File

@@ -0,0 +1,23 @@
//
// Created by Krad on 2021/12/8.
//
#ifndef GUI_ACCOUNTTABLEFORM_H
#define GUI_ACCOUNTTABLEFORM_H
#include <QWidget>
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

View File

@@ -15,6 +15,7 @@
#include "generalform.h"
#include <QPushButton>
#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);

View File

@@ -0,0 +1,21 @@
//
// Created by Krad on 2021/12/8.
//
#include "AccountRoleComboDelegate.h"
#include <QComboBox>
#include <QPainter>
#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());
}

View File

@@ -0,0 +1,23 @@
//
// Created by Krad on 2021/12/8.
//
#ifndef GUI_ACCOUNTROLECOMBODELEGATE_H
#define GUI_ACCOUNTROLECOMBODELEGATE_H
#include <QAbstractItemModel>
#include <QItemDelegate>
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<QString,QVariant> map ;
};
#endif //GUI_ACCOUNTROLECOMBODELEGATE_H