Files
GUI/src/AccountTableForm.cpp

48 lines
1.5 KiB
C++
Raw Normal View History

2021-12-08 15:10:56 +08:00
//
// 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() {
}