logplus/DataMgr/src/CheckHeadView.cpp
2025-10-30 09:50:15 +08:00

67 lines
1.6 KiB
C++

#include "CheckHeadView.h"
#include <QPainter>
#include <QCheckBox>
//#include <QDebug>
CheckHeadView::CheckHeadView(QVector<int> rCheckID,Qt::Orientation orientation, QWidget* parent)
: QHeaderView(orientation, parent)
, m_rCheckIDs(rCheckID)
//, m_pCheckBox(new QCheckBox(this))
{
setHighlightSections(false);
setMouseTracking(true);
// ÏìÓ¦Êó±ê
// setSectionsClickable(true);
for (int nIndex = 0; nIndex < m_rCheckIDs.size(); ++nIndex)
{
auto pCheck = new QCheckBox(this);
m_rCheckBoxMap.insert(m_rCheckIDs[nIndex], pCheck);
pCheck->setVisible(false);
connect(pCheck, SIGNAL(clicked()), this, SLOT(OnChecked()));
pCheck->setFixedSize(QSize(25,25));
}
}
CheckHeadView::~CheckHeadView()
{
}
void CheckHeadView::OnChecked()
{
QCheckBox* pCheck = (QCheckBox*)sender();
for (auto rIter = m_rCheckBoxMap.begin(); rIter != m_rCheckBoxMap.end(); ++rIter)
{
if (rIter.value() == pCheck)
{
bool bStatus = pCheck->isChecked();
int nCol = rIter.key();
SignalStatus(nCol, bStatus);
return;
}
}
}
void CheckHeadView::paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const
{
QHeaderView::paintSection(painter, rect, logicalIndex);
//int nIndex = m_rCheckIDs.indexOf(logicalIndex);
for (auto rIter = m_rCheckBoxMap.begin(); rIter != m_rCheckBoxMap.end(); ++rIter)
{
if (rIter.key() == logicalIndex)
{
QRect centerRect = rect;
centerRect.setX(rect.x());
rIter.value()->setGeometry(centerRect);
rIter.value()->setVisible(true);
}
}
}
QCheckBox*
CheckHeadView::GetCheckBox(int nCol)
{
auto rFind= m_rCheckBoxMap.find(nCol);
if(rFind == m_rCheckBoxMap.end())
return NULL;
return rFind.value();
}