Consistently test for nullptr

m_view might be nullptr, which is checked before setting up the palette,
so don't set the QTextCharFormat up without checking first as well.

Fixes static analyzer warning 0ef07dd07bebe04b93d1fc802eddb57a

Pick-to: 6.1
Change-Id: Ia1c92eb4183c9e368e92875775cff90e2883ddaf
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
This commit is contained in:
Volker Hilsheimer 2021-02-24 13:30:02 +01:00
parent 735466ed2b
commit e38b55c47c

View File

@ -1111,16 +1111,17 @@ QTextCharFormat QCalendarModel::formatForCell(int row, int col) const
{
QPalette pal;
QPalette::ColorGroup cg = QPalette::Active;
QTextCharFormat format;
if (m_view) {
pal = m_view->palette();
if (!m_view->isEnabled())
cg = QPalette::Disabled;
else if (!m_view->isActiveWindow())
cg = QPalette::Inactive;
format.setFont(m_view->font());
}
QTextCharFormat format;
format.setFont(m_view->font());
bool header = (m_weekNumbersShown && col == HeaderColumn)
|| (m_horizontalHeaderFormat != QCalendarWidget::NoHorizontalHeader && row == HeaderRow);
format.setBackground(pal.brush(cg, header ? QPalette::AlternateBase : QPalette::Base));