2025-03-24 18:13:06 +08:00
|
|
|
|
#include "attributeView.h"
|
2025-03-27 21:01:25 +08:00
|
|
|
|
#include "attributeTableDelegate.h"
|
2025-03-28 17:40:59 +08:00
|
|
|
|
#include "multiLineHeaderView.h"
|
2025-03-27 21:01:25 +08:00
|
|
|
|
#include <QHeaderView>
|
2025-03-24 18:13:06 +08:00
|
|
|
|
#include <QVBoxLayout>
|
2025-03-28 17:40:59 +08:00
|
|
|
|
#include <QTimer>
|
2025-03-24 18:13:06 +08:00
|
|
|
|
|
2025-03-25 17:58:48 +08:00
|
|
|
|
AttributeView::AttributeView(const ModelAttributeGroup& modelAttributeGroup, QWidget* parent, const QString& connection, const QString& tableName)
|
2025-03-24 18:13:06 +08:00
|
|
|
|
: QWidget(parent)
|
|
|
|
|
|
, m_connection(connection)
|
|
|
|
|
|
, m_attributeTable(tableName)
|
2025-03-25 17:58:48 +08:00
|
|
|
|
, m_modelAttributeGroup(modelAttributeGroup)
|
2025-03-24 18:13:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
m_tableView = new QTableView(this);
|
2025-04-08 20:02:38 +08:00
|
|
|
|
m_tableView->setStyleSheet("QTableView::item{padding-left:5px;} QTableView::item:selected{border:1px solid rgb(70,130,180);}");
|
2025-03-27 21:01:25 +08:00
|
|
|
|
m_tableView->verticalHeader()->setVisible(false);
|
2025-04-14 12:10:07 +08:00
|
|
|
|
m_tableView->setTabKeyNavigation(false); //关闭tab键导航,对自定义Eidtor设置焦点时(比如lineEdit)会触发tab键,目前尚未清楚为什么
|
2025-03-27 21:01:25 +08:00
|
|
|
|
|
2025-03-25 17:58:48 +08:00
|
|
|
|
m_attributeTableModel = new AttributeTableModel(m_modelAttributeGroup, this, m_connection, m_attributeTable);
|
2025-03-24 18:13:06 +08:00
|
|
|
|
m_tableView->setModel(m_attributeTableModel);
|
|
|
|
|
|
|
2025-04-11 17:14:17 +08:00
|
|
|
|
m_attributeTableDelegate = new AttributeTableDelegate(m_tableView, m_connection, m_tableView);
|
|
|
|
|
|
m_tableView->setItemDelegate(m_attributeTableDelegate);
|
2025-03-27 21:01:25 +08:00
|
|
|
|
|
2025-03-28 17:40:59 +08:00
|
|
|
|
//自定义表头
|
|
|
|
|
|
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);
|
|
|
|
|
|
//除了第一列其余列恢复可以手动调整模式
|
2025-04-08 20:02:38 +08:00
|
|
|
|
QTimer::singleShot(1000, this, [=](){
|
2025-03-28 17:40:59 +08:00
|
|
|
|
for(int i = 1; i < m_multiLinHeader->count(); i++)
|
|
|
|
|
|
m_multiLinHeader->setSectionResizeMode(i, QHeaderView::Interactive);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-03-24 18:13:06 +08:00
|
|
|
|
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()
|
|
|
|
|
|
{}
|
2025-03-25 17:58:48 +08:00
|
|
|
|
|
|
|
|
|
|
void AttributeView::active()
|
|
|
|
|
|
{
|
2025-03-25 20:53:15 +08:00
|
|
|
|
m_attributeTableModel->triggerSyncSignal();
|
2025-03-25 17:58:48 +08:00
|
|
|
|
}
|