Fix showing/hiding context lines spinbox in diff editor

Widgets which were added to a toolbar can only be shown or hidden
by calling setVisible() on their respective action, which was
created while addWidget() was called.

Change-Id: If09257abf5a7a054513fe01b2a1c69d584865dfa
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2016-11-24 11:49:02 +01:00
parent 4585014b82
commit dbfb5eaba1
2 changed files with 9 additions and 10 deletions

View File

@@ -250,17 +250,16 @@ DiffEditor::DiffEditor()
this, &DiffEditor::setCurrentDiffFileIndex);
m_toolBar->addWidget(m_entriesComboBox);
m_contextLabel = new QLabel(m_toolBar);
m_contextLabel->setText(tr("Context lines:"));
m_contextLabel->setContentsMargins(6, 0, 6, 0);
m_toolBar->addWidget(m_contextLabel);
QLabel *contextLabel = new QLabel(m_toolBar);
contextLabel->setText(tr("Context lines:"));
contextLabel->setContentsMargins(6, 0, 6, 0);
m_contextLabelAction = m_toolBar->addWidget(contextLabel);
m_contextSpinBox = new QSpinBox(m_toolBar);
m_contextSpinBox->setRange(1, 100);
m_contextSpinBox->setFrame(false);
m_contextSpinBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding); // Mac Qt5
m_toolBar->addWidget(m_contextSpinBox);
m_contextSpinBoxAction = m_toolBar->addWidget(m_contextSpinBox);
m_whitespaceButtonAction = m_toolBar->addAction(tr("Ignore Whitespace"));
m_whitespaceButtonAction->setCheckable(true);
@@ -544,8 +543,8 @@ void DiffEditor::documentStateChanged()
const bool contextVisible = !m_document->isContextLineCountForced();
m_whitespaceButtonAction->setVisible(canReload);
m_contextLabel->setVisible(canReload && contextVisible);
m_contextSpinBox->setVisible(canReload && contextVisible);
m_contextLabelAction->setVisible(canReload && contextVisible);
m_contextSpinBoxAction->setVisible(canReload && contextVisible);
m_reloadAction->setVisible(canReload);
}