Fix black text in Search Results toolbar

In case the LicenseChecker plugin is enabled. That runs some event loop
during initialize() and it looks like that somehow leads to a wrong
palette for these two, at that time parent-less widgets.

Creating the widgets at a later time, just before they are added to the
toolbar, helps.

Fixes: QTCREATORBUG-27200
Change-Id: I00dc9c8981a0572d7b9f726ec870eb2afb188cc1
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Eike Ziller
2022-03-18 10:04:15 +01:00
parent 689d3d528e
commit b303afa4ec

View File

@@ -111,6 +111,7 @@ namespace Internal {
void popupRequested(bool focus); void popupRequested(bool focus);
void handleExpandCollapseToolButton(bool checked); void handleExpandCollapseToolButton(bool checked);
void updateFilterButton(); void updateFilterButton();
QList<QWidget *> toolBarWidgets();
SearchResultWindow *q; SearchResultWindow *q;
QList<Internal::SearchResultWidget *> m_searchResultWidgets; QList<Internal::SearchResultWidget *> m_searchResultWidgets;
@@ -120,9 +121,9 @@ namespace Internal {
QAction *m_expandCollapseAction; QAction *m_expandCollapseAction;
static const bool m_initiallyExpand; static const bool m_initiallyExpand;
QWidget *m_spacer; QWidget *m_spacer;
QLabel *m_historyLabel; QLabel *m_historyLabel = nullptr;
QWidget *m_spacer2; QWidget *m_spacer2;
QComboBox *m_recentSearchesBox; QComboBox *m_recentSearchesBox = nullptr;
QStackedWidget *m_widget; QStackedWidget *m_widget;
QList<SearchResult *> m_searchResults; QList<SearchResult *> m_searchResults;
int m_currentIndex; int m_currentIndex;
@@ -139,20 +140,13 @@ namespace Internal {
m_expandCollapseButton(nullptr), m_expandCollapseButton(nullptr),
m_expandCollapseAction(new QAction(tr("Expand All"), window)), m_expandCollapseAction(new QAction(tr("Expand All"), window)),
m_spacer(new QWidget), m_spacer(new QWidget),
m_historyLabel(new QLabel(tr("History:"))),
m_spacer2(new QWidget), m_spacer2(new QWidget),
m_recentSearchesBox(new QComboBox),
m_widget(new QStackedWidget), m_widget(new QStackedWidget),
m_currentIndex(0), m_currentIndex(0),
m_tabWidth(8) m_tabWidth(8)
{ {
m_spacer->setMinimumWidth(30); m_spacer->setMinimumWidth(30);
m_spacer2->setMinimumWidth(5); m_spacer2->setMinimumWidth(5);
m_recentSearchesBox->setProperty("drawleftborder", true);
m_recentSearchesBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
m_recentSearchesBox->addItem(tr("New Search"));
connect(m_recentSearchesBox, QOverload<int>::of(&QComboBox::activated),
this, &SearchResultWindowPrivate::setCurrentIndexWithFocus);
m_widget->setWindowTitle(q->displayName()); m_widget->setWindowTitle(q->displayName());
@@ -194,6 +188,7 @@ namespace Internal {
void SearchResultWindowPrivate::setCurrentIndex(int index, bool focus) void SearchResultWindowPrivate::setCurrentIndex(int index, bool focus)
{ {
QTC_ASSERT(m_recentSearchesBox, return );
if (isSearchVisible()) if (isSearchVisible())
m_searchResultWidgets.at(visibleSearchIndex())->notifyVisibilityChanged(false); m_searchResultWidgets.at(visibleSearchIndex())->notifyVisibilityChanged(false);
m_currentIndex = index; m_currentIndex = index;
@@ -217,6 +212,7 @@ namespace Internal {
void SearchResultWindowPrivate::moveWidgetToTop() void SearchResultWindowPrivate::moveWidgetToTop()
{ {
QTC_ASSERT(m_recentSearchesBox, return );
auto widget = qobject_cast<SearchResultWidget *>(sender()); auto widget = qobject_cast<SearchResultWidget *>(sender());
QTC_ASSERT(widget, return); QTC_ASSERT(widget, return);
const int index = m_searchResultWidgets.indexOf(widget); const int index = m_searchResultWidgets.indexOf(widget);
@@ -458,8 +454,7 @@ QWidget *SearchResultWindow::outputWidget(QWidget *)
*/ */
QList<QWidget*> SearchResultWindow::toolBarWidgets() const QList<QWidget*> SearchResultWindow::toolBarWidgets() const
{ {
return {d->m_expandCollapseButton, d->m_filterButton, d->m_newSearchButton, d->m_spacer, return d->toolBarWidgets();
d->m_historyLabel, d->m_spacer2, d->m_recentSearchesBox};
} }
/*! /*!
@@ -497,6 +492,7 @@ SearchResult *SearchResultWindow::startNewSearch(const QString &label,
PreserveCaseMode preserveCaseMode, PreserveCaseMode preserveCaseMode,
const QString &cfgGroup) const QString &cfgGroup)
{ {
if (QTC_GUARD(d->m_recentSearchesBox)) {
if (d->m_searchResults.size() >= MAX_SEARCH_HISTORY) { if (d->m_searchResults.size() >= MAX_SEARCH_HISTORY) {
if (d->m_currentIndex >= d->m_recentSearchesBox->count() - 1) { if (d->m_currentIndex >= d->m_recentSearchesBox->count() - 1) {
// temporarily set the index to the last but one existing // temporarily set the index to the last but one existing
@@ -508,6 +504,8 @@ SearchResult *SearchResultWindow::startNewSearch(const QString &label,
delete d->m_searchResults.takeLast(); delete d->m_searchResults.takeLast();
d->m_recentSearchesBox->removeItem(d->m_recentSearchesBox->count() - 1); d->m_recentSearchesBox->removeItem(d->m_recentSearchesBox->count() - 1);
} }
d->m_recentSearchesBox->insertItem(1, tr("%1 %2").arg(label, searchTerm));
}
auto widget = new SearchResultWidget; auto widget = new SearchResultWidget;
connect(widget, &SearchResultWidget::filterInvalidated, this, [this, widget] { connect(widget, &SearchResultWidget::filterInvalidated, this, [this, widget] {
if (widget == d->m_searchResultWidgets.at(d->visibleSearchIndex())) if (widget == d->m_searchResultWidgets.at(d->visibleSearchIndex()))
@@ -532,7 +530,6 @@ SearchResult *SearchResultWindow::startNewSearch(const QString &label,
widget->setInfo(label, toolTip, searchTerm); widget->setInfo(label, toolTip, searchTerm);
auto result = new SearchResult(widget); auto result = new SearchResult(widget);
d->m_searchResults.prepend(result); d->m_searchResults.prepend(result);
d->m_recentSearchesBox->insertItem(1, tr("%1 %2").arg(label, searchTerm));
if (d->m_currentIndex > 0) if (d->m_currentIndex > 0)
++d->m_currentIndex; // so setCurrentIndex still knows about the right "currentIndex" and its widget ++d->m_currentIndex; // so setCurrentIndex still knows about the right "currentIndex" and its widget
d->setCurrentIndexWithFocus(1); d->setCurrentIndexWithFocus(1);
@@ -544,8 +541,10 @@ SearchResult *SearchResultWindow::startNewSearch(const QString &label,
*/ */
void SearchResultWindow::clearContents() void SearchResultWindow::clearContents()
{ {
if (QTC_GUARD(d->m_recentSearchesBox)) {
for (int i = d->m_recentSearchesBox->count() - 1; i > 0 /* don't want i==0 */; --i) for (int i = d->m_recentSearchesBox->count() - 1; i > 0 /* don't want i==0 */; --i)
d->m_recentSearchesBox->removeItem(i); d->m_recentSearchesBox->removeItem(i);
}
foreach (Internal::SearchResultWidget *widget, d->m_searchResultWidgets) foreach (Internal::SearchResultWidget *widget, d->m_searchResultWidgets)
widget->notifyVisibilityChanged(false); widget->notifyVisibilityChanged(false);
qDeleteAll(d->m_searchResultWidgets); qDeleteAll(d->m_searchResultWidgets);
@@ -642,6 +641,29 @@ void SearchResultWindowPrivate::updateFilterButton()
&& m_searchResultWidgets.at(visibleSearchIndex())->hasFilter()); && m_searchResultWidgets.at(visibleSearchIndex())->hasFilter());
} }
QList<QWidget *> SearchResultWindowPrivate::toolBarWidgets()
{
if (!m_historyLabel)
m_historyLabel = new QLabel(tr("History:"));
if (!m_recentSearchesBox) {
m_recentSearchesBox = new QComboBox;
m_recentSearchesBox->setProperty("drawleftborder", true);
m_recentSearchesBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
m_recentSearchesBox->addItem(tr("New Search"));
connect(m_recentSearchesBox,
QOverload<int>::of(&QComboBox::activated),
this,
&SearchResultWindowPrivate::setCurrentIndexWithFocus);
}
return {m_expandCollapseButton,
m_filterButton,
m_newSearchButton,
m_spacer,
m_historyLabel,
m_spacer2,
m_recentSearchesBox};
}
/*! /*!
\internal \internal
*/ */