pgLab/pglab/crud/DataGridWidget.cpp

35 lines
839 B
C++
Raw Normal View History

#include "DataGridWidget.h"
#include "CustomDataRole.h"
#include "ResultTableModelUtil.h"
#include "util/PgLabItemDelegate.h"
#include <QSortFilterProxyModel>
#include <QTableView>
#include <QVBoxLayout>
DataGridWidget::DataGridWidget(QWidget *parent)
: QWidget(parent)
{
auto layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
m_view = new QTableView(this);
layout->addWidget(m_view);
SetTableViewDefault(m_view);
auto delegate = new PgLabItemDelegate(m_view);
m_view->setItemDelegate(delegate);
}
void DataGridWidget::setSourceModel(QAbstractItemModel *model)
{
if (!m_proxy) {
m_proxy = new QSortFilterProxyModel(this);
m_proxy->setSortRole(CustomSortRole);
}
m_proxy->setSourceModel(model);
m_view->setModel(m_proxy);
m_view->setSortingEnabled(true);
m_proxy->sort(0, Qt::AscendingOrder);
}