#3037 Guard pointer access

This commit is contained in:
Magne Sjaastad 2018-06-11 12:39:26 +02:00
parent e370dee3b0
commit e814272bea

View File

@ -104,70 +104,73 @@ void PdmUiComboBoxEditor::configureAndUpdateUi(const QString& uiConfigName)
m_comboBox->blockSignals(false);
}
if (attributes.showPreviousAndNextButtons)
if (!m_layout.isNull())
{
if (m_previousItemButton.isNull())
if (attributes.showPreviousAndNextButtons)
{
m_previousItemButton = new QToolButton(m_placeholder);
connect(m_previousItemButton, SIGNAL(clicked()), this, SLOT(slotPreviousButtonPressed()));
if (m_previousItemButton.isNull())
{
m_previousItemButton = new QToolButton(m_placeholder);
connect(m_previousItemButton, SIGNAL(clicked()), this, SLOT(slotPreviousButtonPressed()));
m_previousItemButton->setToolTip("Previous");
}
m_previousItemButton->setToolTip("Previous");
}
if (m_nextItemButton.isNull())
{
m_nextItemButton = new QToolButton(m_placeholder);
connect(m_nextItemButton, SIGNAL(clicked()), this, SLOT(slotNextButtonPressed()));
if (m_nextItemButton.isNull())
{
m_nextItemButton = new QToolButton(m_placeholder);
connect(m_nextItemButton, SIGNAL(clicked()), this, SLOT(slotNextButtonPressed()));
m_nextItemButton->setToolTip("Next");
}
m_nextItemButton->setToolTip("Next");
}
m_layout->insertWidget(1, m_previousItemButton);
m_layout->insertWidget(2, m_nextItemButton);
m_layout->insertWidget(1, m_previousItemButton);
m_layout->insertWidget(2, m_nextItemButton);
if (m_comboBox->count() == 0 || m_comboBox->currentIndex() <= 0)
{
QIcon disabledIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowUp).pixmap(16, 16, QIcon::Disabled));
m_previousItemButton->setIcon(disabledIcon);
if (m_comboBox->count() == 0 || m_comboBox->currentIndex() <= 0)
{
QIcon disabledIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowUp).pixmap(16, 16, QIcon::Disabled));
m_previousItemButton->setIcon(disabledIcon);
}
else
{
m_previousItemButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowUp));
}
if (m_comboBox->count() == 0 || m_comboBox->currentIndex() >= m_comboBox->count() - 1)
{
QIcon disabledIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowDown).pixmap(16, 16, QIcon::Disabled));
m_nextItemButton->setIcon(disabledIcon);
}
else
{
m_nextItemButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowDown));
}
// Update button texts
if (!attributes.nextButtonText.isEmpty())
{
m_nextItemButton->setToolTip(attributes.nextButtonText);
}
if (!attributes.prevButtonText.isEmpty())
{
m_previousItemButton->setToolTip(attributes.prevButtonText);
}
}
else
{
m_previousItemButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowUp));
}
if (m_previousItemButton)
{
m_layout->removeWidget(m_previousItemButton);
m_previousItemButton->deleteLater();
}
if (m_comboBox->count() == 0 || m_comboBox->currentIndex() >= m_comboBox->count() - 1)
{
QIcon disabledIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowDown).pixmap(16, 16, QIcon::Disabled));
m_nextItemButton->setIcon(disabledIcon);
}
else
{
m_nextItemButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowDown));
}
// Update button texts
if (!attributes.nextButtonText.isEmpty())
{
m_nextItemButton->setToolTip(attributes.nextButtonText);
}
if (!attributes.prevButtonText.isEmpty())
{
m_previousItemButton->setToolTip(attributes.prevButtonText);
}
}
else
{
if (m_previousItemButton)
{
m_layout->removeWidget(m_previousItemButton);
m_previousItemButton->deleteLater();
}
if (m_nextItemButton)
{
m_layout->removeWidget(m_nextItemButton);
m_nextItemButton->deleteLater();
if (m_nextItemButton)
{
m_layout->removeWidget(m_nextItemButton);
m_nextItemButton->deleteLater();
}
}
}
}