{
m_LeftOffset = -12;
m_bResizing = false;
// 3 items : TOP BAND HEADER, CENTRAL GRID & BOTTOM FOOTER
vboxLayout->setSpacing(0);
vboxLayout->setMargin(0);
vboxLayout
->setObjectName
(QString::fromUtf8("vboxLayout"));
// TOP : Band headers
tTopBand
->setObjectName
( QString::fromUtf8 ( MTable_TOPBAND
) );
tTopBand->setMinimumHeight ( 20 );
tTopBand->setMaximumHeight ( 20 );
tTopBand->setOffset ( m_LeftOffset );
spTop.setHorizontalStretch(0);
spTop.setVerticalStretch(0);
tTopBand->setSizePolicy ( spTop );
vboxLayout->addWidget ( tTopBand );
// CENTRAL : Data & column headers
tMainGrid
->setObjectName
( QString::fromUtf8 ( MTable_CENTRAL
) );
spCentral.setHorizontalStretch(0);
spCentral.setVerticalStretch(0);
tMainGrid->setSizePolicy ( spCentral );
vboxLayout->addWidget ( tMainGrid );
tMainGrid->verticalHeader()->setDefaultSectionSize ( 20 );
tMainGrid->verticalHeader()->setMinimumSectionSize ( 20 );
tMainGrid->horizontalHeader()->setDefaultSectionSize ( 120 );
tMainGrid->horizontalHeader()->setMinimumSectionSize ( 20 );
// FOOTER : Summay @ column footers
tFooter
->setObjectName
( QString::fromUtf8 ( MTable_FOOTER
) );
tFooter->setMinimumHeight ( 20 );
tFooter->setMaximumHeight ( 20 );
tFooter->setOffset ( m_LeftOffset );
spFooter.setHorizontalStretch(0);
spFooter.setVerticalStretch(0);
tFooter->setSizePolicy ( spFooter );
vboxLayout->addWidget ( tFooter );
connect ( tMainGrid->horizontalHeader(), SIGNAL(sectionResized(int,int,int)),
this, SLOT(SectionResized(int,int,int)) );
connect ( tMainGrid
->horizontalHeader
(),
SIGNAL(sectionAutoResize
(int,
QHeaderView::ResizeMode)) ,
this,
SLOT(SectionAutoResize
(int,
QHeaderView::ResizeMode)) );
connect ( tTopBand, SIGNAL(sectionResized(int,int,int)), this, SLOT(BandSectionResized(int,int,int)) );
connect ( tMainGrid->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(ScrollHorizontal(int)) );
}
void MTableView::BandSectionResized ( int logicalIndex, int /* oldSize */, int newSize )
{
if ( m_bResizing ) return;
m_bResizing = true;
QHeaderView * pTabHeader
= this
->GetMainGrid
()->horizontalHeader
();
pTabHeader->resizeSection ( logicalIndex, newSize );
m_bResizing = false;
}
void MTableView::SectionResized ( int logicalIndex, int /* oldSize */, int newSize )
{
QHeaderView * pHeader
= qFindChild<QHeaderView
*>
( this, MTable_TOPBAND
);
pHeader->resizeSection ( logicalIndex, newSize );
pHeader = qFindChild<QHeaderView * > ( this, MTable_FOOTER );
pHeader->resizeSection ( logicalIndex, newSize );
}
void MTableView
::SectionAutoResize ( int logicalIndex,
QHeaderView::ResizeMode /* mode */ ) {
QHeaderView * pTabHeader
= this
->GetMainGrid
()->horizontalHeader
();
QHeaderView * pHeader
= qFindChild<QHeaderView
*>
( this, MTable_TOPBAND
);
pHeader->resizeSection ( logicalIndex, pTabHeader->sectionSize ( logicalIndex ) );
pHeader = qFindChild<QHeaderView * > ( this, MTable_FOOTER );
pHeader->resizeSection ( logicalIndex, pTabHeader->sectionSize ( logicalIndex ) );
}
void MTableView::ScrollHorizontal ( int /* scrollValue */ )
{
QHeaderView * pTabHeader
= this
->GetMainGrid
()->horizontalHeader
();
QHeaderView * pHeader
= qFindChild<QHeaderView
*>
( this, MTable_TOPBAND
);
pHeader->setOffset ( pTabHeader->offset() + m_LeftOffset );
pHeader = qFindChild<QHeaderView * > ( this, MTable_FOOTER );
pHeader->setOffset ( pTabHeader->offset() + m_LeftOffset );
}
MTableView::MTableView ( QWidget * parent ) : QWidget ( parent )
{
m_LeftOffset = -12;
m_bResizing = false;
// 3 items : TOP BAND HEADER, CENTRAL GRID & BOTTOM FOOTER
QVBoxLayout * vboxLayout = new QVBoxLayout ( this );
vboxLayout->setSpacing(0);
vboxLayout->setMargin(0);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
// TOP : Band headers
QHeaderView * tTopBand = new QHeaderView ( Qt::Horizontal, this );
tTopBand->setObjectName ( QString::fromUtf8 ( MTable_TOPBAND ) );
tTopBand->setMinimumHeight ( 20 );
tTopBand->setMaximumHeight ( 20 );
tTopBand->setOffset ( m_LeftOffset );
QSizePolicy spTop ( QSizePolicy::Expanding, QSizePolicy::Fixed );
spTop.setHorizontalStretch(0);
spTop.setVerticalStretch(0);
tTopBand->setSizePolicy ( spTop );
vboxLayout->addWidget ( tTopBand );
// CENTRAL : Data & column headers
QTableView * tMainGrid = new QTableView ( this );
tMainGrid->setObjectName ( QString::fromUtf8 ( MTable_CENTRAL ) );
QSizePolicy spCentral ( QSizePolicy::Expanding, QSizePolicy::Expanding );
spCentral.setHorizontalStretch(0);
spCentral.setVerticalStretch(0);
tMainGrid->setSizePolicy ( spCentral );
vboxLayout->addWidget ( tMainGrid );
tMainGrid->setSelectionBehavior ( QAbstractItemView::SelectRows );
tMainGrid->setSelectionMode ( QAbstractItemView::SingleSelection );
tMainGrid->verticalHeader()->setDefaultSectionSize ( 20 );
tMainGrid->verticalHeader()->setMinimumSectionSize ( 20 );
tMainGrid->horizontalHeader()->setDefaultSectionSize ( 120 );
tMainGrid->horizontalHeader()->setMinimumSectionSize ( 20 );
tMainGrid->setVerticalScrollMode ( QAbstractItemView::ScrollPerPixel );
// FOOTER : Summay @ column footers
QHeaderView * tFooter = new QHeaderView ( Qt::Horizontal, this );
tFooter->setObjectName ( QString::fromUtf8 ( MTable_FOOTER ) );
tFooter->setMinimumHeight ( 20 );
tFooter->setMaximumHeight ( 20 );
tFooter->setOffset ( m_LeftOffset );
tFooter->setResizeMode ( QHeaderView::Fixed );
QSizePolicy spFooter ( QSizePolicy::Expanding, QSizePolicy::Fixed );
spFooter.setHorizontalStretch(0);
spFooter.setVerticalStretch(0);
tFooter->setSizePolicy ( spFooter );
vboxLayout->addWidget ( tFooter );
connect ( tMainGrid->horizontalHeader(), SIGNAL(sectionResized(int,int,int)),
this, SLOT(SectionResized(int,int,int)) );
connect ( tMainGrid->horizontalHeader(), SIGNAL(sectionAutoResize(int,QHeaderView::ResizeMode)) ,
this, SLOT(SectionAutoResize(int,QHeaderView::ResizeMode)) );
connect ( tTopBand, SIGNAL(sectionResized(int,int,int)), this, SLOT(BandSectionResized(int,int,int)) );
connect ( tMainGrid->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(ScrollHorizontal(int)) );
}
void MTableView::BandSectionResized ( int logicalIndex, int /* oldSize */, int newSize )
{
if ( m_bResizing ) return;
m_bResizing = true;
QHeaderView * pTabHeader = this->GetMainGrid()->horizontalHeader();
pTabHeader->resizeSection ( logicalIndex, newSize );
m_bResizing = false;
}
void MTableView::SectionResized ( int logicalIndex, int /* oldSize */, int newSize )
{
QHeaderView * pHeader = qFindChild<QHeaderView *> ( this, MTable_TOPBAND );
pHeader->resizeSection ( logicalIndex, newSize );
pHeader = qFindChild<QHeaderView * > ( this, MTable_FOOTER );
pHeader->resizeSection ( logicalIndex, newSize );
}
void MTableView::SectionAutoResize ( int logicalIndex, QHeaderView::ResizeMode /* mode */ )
{
QHeaderView * pTabHeader = this->GetMainGrid()->horizontalHeader();
QHeaderView * pHeader = qFindChild<QHeaderView *> ( this, MTable_TOPBAND );
pHeader->resizeSection ( logicalIndex, pTabHeader->sectionSize ( logicalIndex ) );
pHeader = qFindChild<QHeaderView * > ( this, MTable_FOOTER );
pHeader->resizeSection ( logicalIndex, pTabHeader->sectionSize ( logicalIndex ) );
}
void MTableView::ScrollHorizontal ( int /* scrollValue */ )
{
QHeaderView * pTabHeader = this->GetMainGrid()->horizontalHeader();
QHeaderView * pHeader = qFindChild<QHeaderView *> ( this, MTable_TOPBAND );
pHeader->setOffset ( pTabHeader->offset() + m_LeftOffset );
pHeader = qFindChild<QHeaderView * > ( this, MTable_FOOTER );
pHeader->setOffset ( pTabHeader->offset() + m_LeftOffset );
}
To copy to clipboard, switch view to plain text mode
Bookmarks