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

View File

@@ -33,7 +33,6 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QComboBox; class QComboBox;
class QLabel;
class QSpinBox; class QSpinBox;
class QToolBar; class QToolBar;
class QToolButton; class QToolButton;
@@ -95,11 +94,12 @@ private:
QToolBar *m_toolBar; QToolBar *m_toolBar;
QComboBox *m_entriesComboBox; QComboBox *m_entriesComboBox;
QSpinBox *m_contextSpinBox; QSpinBox *m_contextSpinBox;
QAction *m_contextSpinBoxAction = nullptr;
QAction *m_toggleSyncAction; QAction *m_toggleSyncAction;
QAction *m_whitespaceButtonAction; QAction *m_whitespaceButtonAction;
QAction *m_toggleDescriptionAction; QAction *m_toggleDescriptionAction;
QAction *m_reloadAction; QAction *m_reloadAction;
QLabel *m_contextLabel; QAction *m_contextLabelAction = nullptr;
QAction *m_viewSwitcherAction; QAction *m_viewSwitcherAction;
QPair<QString, QString> m_currentFileChunk; QPair<QString, QString> m_currentFileChunk;
int m_currentViewIndex; int m_currentViewIndex;