Skip to content

Commit acb4238

Browse files
Helper function internal::setToolTip() to remove as many #ifndef QT_NO_TOOLTIP tests as possible to cleanup the code
1 parent 505f14a commit acb4238

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

src/DockAreaTitleBar.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,7 @@ void DockAreaTitleBarPrivate::createButtons()
207207
#endif
208208
_this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow()));
209209
TabsMenuButton->setMenu(TabsMenu);
210-
#ifndef QT_NO_TOOLTIP
211-
TabsMenuButton->setToolTip(QObject::tr("List all tabs"));
212-
#endif
210+
internal::setToolTip(TabsMenuButton, QObject::tr("List all tabs"));
213211
TabsMenuButton->setSizePolicy(ButtonSizePolicy);
214212
TopLayout->addWidget(TabsMenuButton, 0);
215213
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
@@ -220,9 +218,7 @@ void DockAreaTitleBarPrivate::createButtons()
220218
UndockButton = new CTitleBarButton(testConfigFlag(CDockManager::DockAreaHasUndockButton));
221219
UndockButton->setObjectName("undockButton");
222220
UndockButton->setAutoRaise(true);
223-
#ifndef QT_NO_TOOLTIP
224-
UndockButton->setToolTip(QObject::tr("Detach Group"));
225-
#endif
221+
internal::setToolTip(UndockButton, QObject::tr("Detach Group"));
226222
setTitleBarButtonIcon(UndockButton, QStyle::SP_TitleBarNormalButton, ads::DockAreaUndockIcon);
227223
UndockButton->setSizePolicy(ButtonSizePolicy);
228224
TopLayout->addWidget(UndockButton, 0);
@@ -233,16 +229,14 @@ void DockAreaTitleBarPrivate::createButtons()
233229
CloseButton->setObjectName("closeButton");
234230
CloseButton->setAutoRaise(true);
235231
setTitleBarButtonIcon(CloseButton, QStyle::SP_TitleBarCloseButton, ads::DockAreaCloseIcon);
236-
#ifndef QT_NO_TOOLTIP
237232
if (testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
238233
{
239-
CloseButton->setToolTip(QObject::tr("Close Active Tab"));
234+
internal::setToolTip(CloseButton, QObject::tr("Close Active Tab"));
240235
}
241236
else
242237
{
243-
CloseButton->setToolTip(QObject::tr("Close Group"));
238+
internal::setToolTip(CloseButton, QObject::tr("Close Group"));
244239
}
245-
#endif
246240
CloseButton->setSizePolicy(ButtonSizePolicy);
247241
CloseButton->setIconSize(QSize(16, 16));
248242
TopLayout->addWidget(CloseButton, 0);
@@ -342,9 +336,7 @@ void CDockAreaTitleBar::onTabsMenuAboutToShow()
342336
}
343337
auto Tab = d->TabBar->tab(i);
344338
QAction* Action = menu->addAction(Tab->icon(), Tab->text());
345-
#ifndef QT_NO_TOOLTIP
346-
Action->setToolTip(Tab->toolTip());
347-
#endif
339+
internal::setToolTip(Action, Tab->toolTip());
348340
Action->setData(i);
349341
}
350342

src/DockWidgetTab.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,7 @@ void DockWidgetTabPrivate::createLayout()
184184
CloseButton->setIcon(CloseIcon);
185185
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
186186
_this->onDockWidgetFeaturesChanged();
187-
#ifndef QT_NO_TOOLTIP
188-
CloseButton->setToolTip(QObject::tr("Close Tab"));
189-
#endif
187+
internal::setToolTip(CloseButton, QObject::tr("Close Tab"));
190188
_this->connect(CloseButton, SIGNAL(clicked()), SIGNAL(closeRequested()));
191189

192190
QFontMetrics fm(TitleLabel->font());
@@ -499,9 +497,7 @@ void CDockWidgetTab::setIcon(const QIcon& Icon)
499497
d->IconLabel = new QLabel();
500498
d->IconLabel->setAlignment(Qt::AlignVCenter);
501499
d->IconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
502-
#ifndef QT_NO_TOOLTIP
503-
d->IconLabel->setToolTip(d->TitleLabel->toolTip());
504-
#endif
500+
internal::setToolTip(d->IconLabel, d->TitleLabel->toolTip());
505501
Layout->insertWidget(0, d->IconLabel, Qt::AlignVCenter);
506502
Layout->insertSpacing(1, qRound(1.5 * Layout->contentsMargins().left() / 2.0));
507503
}

src/ElidingLabel.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ CElidingLabel::CElidingLabel(const QString& text, QWidget* parent, Qt::WindowFla
8888
d(new ElidingLabelPrivate(this))
8989
{
9090
d->Text = text;
91-
#ifndef QT_NO_TOOLTIP
92-
setToolTip(text);
93-
#endif
91+
internal::setToolTip(this, text);
9492
}
9593

9694

@@ -193,9 +191,7 @@ void CElidingLabel::setText(const QString &text)
193191
else
194192
{
195193
d->Text = text;
196-
#ifndef QT_NO_TOOLTIP
197-
setToolTip( text );
198-
#endif
194+
internal::setToolTip(this, text);
199195
d->elideText(this->size().width());
200196
}
201197
}

src/ads_globals.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,22 @@ void setFlag(T& Flags, typename T::enum_type flag, bool on = true)
215215
#endif
216216
}
217217

218+
219+
/**
220+
* Helper function for settings tooltips without cluttering the code with
221+
* tests for preprocessor macros
222+
*/
223+
template <class QObjectPtr>
224+
void setToolTip(QObjectPtr obj, const QString &tip)
225+
{
226+
#ifndef QT_NO_TOOLTIP
227+
obj->setToolTip(tip);
228+
#else
229+
Q_UNUSED(obj);
230+
Q_UNUSED(tip);
231+
#endif
232+
}
233+
218234
} // namespace internal
219235
} // namespace ads
220236

0 commit comments

Comments
 (0)