PowerModeler/source/attributeView.cpp

62 lines
2.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "attributeView.h"
#include "attributeTableDelegate.h"
#include "multiLineHeaderView.h"
#include <QHeaderView>
#include <QVBoxLayout>
#include <QTimer>
AttributeView::AttributeView(const ModelAttributeGroup& modelAttributeGroup, QWidget* parent, const QString& connection, const QString& tableName)
: QWidget(parent)
, m_connection(connection)
, m_attributeTable(tableName)
, m_modelAttributeGroup(modelAttributeGroup)
{
m_tableView = new QTableView(this);
m_tableView->setStyleSheet("QTableView::item{padding-left:5px;} QTableView::item:selected{border:1px solid rgb(70,130,180);}");
m_tableView->verticalHeader()->setVisible(false);
m_tableView->setTabKeyNavigation(false); //关闭tab键导航对自定义Eidtor设置焦点时(比如lineEdit)会触发tab键目前尚未清楚为什么
m_attributeTableModel = new AttributeTableModel(m_modelAttributeGroup, this, m_connection, m_attributeTable);
m_tableView->setModel(m_attributeTableModel);
m_attributeTableDelegate = new AttributeTableDelegate(m_tableView, m_connection, m_tableView);
m_tableView->setItemDelegate(m_attributeTableDelegate);
//自定义表头
m_multiLinHeader = new MultiLineHeaderView(Qt::Horizontal, this);
QColor bg(246, 246, 246);
QColor border(228, 228, 228);
m_multiLinHeader->setBackgroundColor(bg);
m_multiLinHeader->setBorderColor(border);
//主标题加粗展示
for(int i =0; i < m_attributeTableModel->columnCount(); i++)
{
HeaderLineStyle mainTitleStyle;
mainTitleStyle.font.setBold(true);
m_multiLinHeader->setSectionLineStyle(i, 0, mainTitleStyle);
HeaderLineStyle subTitleStyle;
//subTitleStyle.font.setPointSize(8);
m_multiLinHeader->setSectionLineStyle(i, 1, subTitleStyle);
}
m_tableView->setHorizontalHeader(m_multiLinHeader);
//除了第一列其余列恢复可以手动调整模式
QTimer::singleShot(1000, this, [=](){
for(int i = 1; i < m_multiLinHeader->count(); i++)
m_multiLinHeader->setSectionResizeMode(i, QHeaderView::Interactive);
});
m_vLayout = new QVBoxLayout(this);
m_vLayout->setSpacing(0);
m_vLayout->setContentsMargins(0, 0, 0, 0);
m_vLayout->addWidget(m_tableView);
this->setLayout(m_vLayout);
}
AttributeView::~AttributeView()
{}
void AttributeView::active()
{
m_attributeTableModel->triggerSyncSignal();
}