MinimizableInfoBars: Move toolbar visibility handling

Remove some coupling between CppEditorWidget and MinimizableInfoBars by
handing the visibility of the toolbar buttons solely within
MinimizableInfoBars.

Change-Id: I5abf59187ea9b37fd13c91d63b2c82a1caa67275
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Eike Ziller
2022-05-02 17:11:18 +02:00
parent b50eb35a17
commit 8bb63ebc9a
4 changed files with 32 additions and 37 deletions

View File

@@ -424,7 +424,6 @@ public:
QAction *m_parseContextAction = nullptr; QAction *m_parseContextAction = nullptr;
ParseContextWidget *m_parseContextWidget = nullptr; ParseContextWidget *m_parseContextWidget = nullptr;
QToolButton *m_preprocessorButton = nullptr; QToolButton *m_preprocessorButton = nullptr;
MinimizableInfoBars::Actions m_showInfoBarActions;
CppLocalRenaming m_localRenaming; CppLocalRenaming m_localRenaming;
CppUseSelectionsUpdater m_useSelectionsUpdater; CppUseSelectionsUpdater m_useSelectionsUpdater;
@@ -555,11 +554,8 @@ void CppEditorWidget::finalizeInitialization()
} }
// Toolbar: Actions to show minimized info bars // Toolbar: Actions to show minimized info bars
d->m_showInfoBarActions = MinimizableInfoBars::createShowInfoBarActions([this](QWidget *w) { d->m_cppEditorDocument->minimizableInfoBars().createShowInfoBarActions(
return this->insertExtraToolBarWidget(TextEditorWidget::Left, w); [this](QWidget *w) { return this->insertExtraToolBarWidget(TextEditorWidget::Left, w); });
});
connect(&cppEditorDocument()->minimizableInfoBars(), &MinimizableInfoBars::showAction,
this, &CppEditorWidget::onShowInfoBarAction);
d->m_outlineTimer.setInterval(5000); d->m_outlineTimer.setInterval(5000);
d->m_outlineTimer.setSingleShot(true); d->m_outlineTimer.setSingleShot(true);
@@ -672,13 +668,6 @@ void CppEditorWidget::onIfdefedOutBlocksUpdated(unsigned revision,
textDocument()->setIfdefedOutBlocks(ifdefedOutBlocks); textDocument()->setIfdefedOutBlocks(ifdefedOutBlocks);
} }
void CppEditorWidget::onShowInfoBarAction(const Id &id, bool show)
{
QAction *action = d->m_showInfoBarActions.value(id);
QTC_ASSERT(action, return);
action->setVisible(show);
}
static QString getDocumentLine(QTextDocument *document, int line) static QString getDocumentLine(QTextDocument *document, int line)
{ {
if (document) if (document)

View File

@@ -136,8 +136,6 @@ private:
void onIfdefedOutBlocksUpdated(unsigned revision, void onIfdefedOutBlocksUpdated(unsigned revision,
const QList<TextEditor::BlockRange> ifdefedOutBlocks); const QList<TextEditor::BlockRange> ifdefedOutBlocks);
void onShowInfoBarAction(const Utils::Id &id, bool show);
void updateSemanticInfo(const SemanticInfo &semanticInfo, void updateSemanticInfo(const SemanticInfo &semanticInfo,
bool updateUseSelectionSynchronously = false); bool updateUseSelectionSynchronously = false);
void updatePreprocessorButtonTooltip(); void updatePreprocessorButtonTooltip();

View File

@@ -47,26 +47,33 @@ MinimizableInfoBars::MinimizableInfoBars(InfoBar &infoBar, QObject *parent)
{ {
connect(settings(), &CppToolsSettings::showNoProjectInfoBarChanged, connect(settings(), &CppToolsSettings::showNoProjectInfoBarChanged,
this, &MinimizableInfoBars::updateNoProjectConfiguration); this, &MinimizableInfoBars::updateNoProjectConfiguration);
createActions();
} }
MinimizableInfoBars::Actions MinimizableInfoBars::createShowInfoBarActions( void MinimizableInfoBars::createActions()
const ActionCreator &actionCreator)
{ {
Actions result; auto action = new QAction(this);
QTC_ASSERT(actionCreator, return result); action->setToolTip(tr("File is not part of any project."));
action->setIcon(Icons::WARNING_TOOLBAR.pixmap());
// No project configuration available connect(action, &QAction::triggered, []() { settings()->setShowNoProjectInfoBar(true); });
auto *button = new QToolButton();
button->setToolTip(tr("File is not part of any project."));
button->setIcon(Utils::Icons::WARNING_TOOLBAR.pixmap());
connect(button, &QAbstractButton::clicked, []() {
settings()->setShowNoProjectInfoBar(true);
});
QAction *action = actionCreator(button);
action->setVisible(!settings()->showNoProjectInfoBar()); action->setVisible(!settings()->showNoProjectInfoBar());
result.insert(Constants::NO_PROJECT_CONFIGURATION, action); m_actions.insert(Constants::NO_PROJECT_CONFIGURATION, action);
return result; }
void MinimizableInfoBars::createShowInfoBarActions(const ActionCreator &actionCreator) const
{
QTC_ASSERT(actionCreator, return );
for (QAction *action : m_actions) {
auto *button = new QToolButton();
button->setDefaultAction(action);
QAction *toolbarAction = actionCreator(button);
connect(action, &QAction::changed, toolbarAction, [action, toolbarAction] {
toolbarAction->setVisible(action->isVisible());
});
toolbarAction->setVisible(action->isVisible());
}
} }
void MinimizableInfoBars::processHasProjectPart(bool hasProjectPart) void MinimizableInfoBars::processHasProjectPart(bool hasProjectPart)
@@ -88,7 +95,9 @@ void MinimizableInfoBars::updateNoProjectConfiguration()
show = true; show = true;
} }
emit showAction(id, show); QAction *action = m_actions.value(id);
if (QTC_GUARD(action))
action->setVisible(show);
} }
static InfoBarEntry createMinimizableInfo(const Id &id, static InfoBarEntry createMinimizableInfo(const Id &id,

View File

@@ -46,25 +46,24 @@ class MinimizableInfoBars : public QObject
public: public:
using ActionCreator = std::function<QAction *(QWidget *widget)>; using ActionCreator = std::function<QAction *(QWidget *widget)>;
using Actions = QHash<Utils::Id, QAction *>;
static Actions createShowInfoBarActions(const ActionCreator &actionCreator);
public: public:
explicit MinimizableInfoBars(Utils::InfoBar &infoBar, QObject *parent = nullptr); explicit MinimizableInfoBars(Utils::InfoBar &infoBar, QObject *parent = nullptr);
void createShowInfoBarActions(const ActionCreator &actionCreator) const;
void processHasProjectPart(bool hasProjectPart); void processHasProjectPart(bool hasProjectPart);
signals:
void showAction(const Utils::Id &id, bool show);
private: private:
void createActions();
void updateNoProjectConfiguration(); void updateNoProjectConfiguration();
void addNoProjectConfigurationEntry(const Utils::Id &id); void addNoProjectConfigurationEntry(const Utils::Id &id);
private: private:
Utils::InfoBar &m_infoBar; Utils::InfoBar &m_infoBar;
QHash<Utils::Id, QAction *> m_actions;
bool m_hasProjectPart = true; bool m_hasProjectPart = true;
}; };