Account Table form
This commit is contained in:
47
src/AccountTableForm.cpp
Normal file
47
src/AccountTableForm.cpp
Normal 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
23
src/AccountTableForm.h
Normal 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
|
||||
@@ -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);
|
||||
|
||||
21
src/components/AccountRoleComboDelegate.cpp
Normal file
21
src/components/AccountRoleComboDelegate.cpp
Normal 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());
|
||||
}
|
||||
|
||||
|
||||
23
src/components/AccountRoleComboDelegate.h
Normal file
23
src/components/AccountRoleComboDelegate.h
Normal 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
|
||||
Reference in New Issue
Block a user