From acb423872a2191309ee1f4157f4b9bbcc4e0ebeb Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Wed, 5 Feb 2020 08:33:40 +0100 Subject: [PATCH] Helper function internal::setToolTip() to remove as many #ifndef QT_NO_TOOLTIP tests as possible to cleanup the code --- src/DockAreaTitleBar.cpp | 18 +++++------------- src/DockWidgetTab.cpp | 8 ++------ src/ElidingLabel.cpp | 8 ++------ src/ads_globals.h | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index 2884b45..b8cc717 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -207,9 +207,7 @@ void DockAreaTitleBarPrivate::createButtons() #endif _this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow())); TabsMenuButton->setMenu(TabsMenu); -#ifndef QT_NO_TOOLTIP - TabsMenuButton->setToolTip(QObject::tr("List all tabs")); -#endif + internal::setToolTip(TabsMenuButton, QObject::tr("List all tabs")); TabsMenuButton->setSizePolicy(ButtonSizePolicy); TopLayout->addWidget(TabsMenuButton, 0); _this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)), @@ -220,9 +218,7 @@ void DockAreaTitleBarPrivate::createButtons() UndockButton = new CTitleBarButton(testConfigFlag(CDockManager::DockAreaHasUndockButton)); UndockButton->setObjectName("undockButton"); UndockButton->setAutoRaise(true); -#ifndef QT_NO_TOOLTIP - UndockButton->setToolTip(QObject::tr("Detach Group")); -#endif + internal::setToolTip(UndockButton, QObject::tr("Detach Group")); setTitleBarButtonIcon(UndockButton, QStyle::SP_TitleBarNormalButton, ads::DockAreaUndockIcon); UndockButton->setSizePolicy(ButtonSizePolicy); TopLayout->addWidget(UndockButton, 0); @@ -233,16 +229,14 @@ void DockAreaTitleBarPrivate::createButtons() CloseButton->setObjectName("closeButton"); CloseButton->setAutoRaise(true); setTitleBarButtonIcon(CloseButton, QStyle::SP_TitleBarCloseButton, ads::DockAreaCloseIcon); -#ifndef QT_NO_TOOLTIP if (testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab)) { - CloseButton->setToolTip(QObject::tr("Close Active Tab")); + internal::setToolTip(CloseButton, QObject::tr("Close Active Tab")); } else { - CloseButton->setToolTip(QObject::tr("Close Group")); + internal::setToolTip(CloseButton, QObject::tr("Close Group")); } -#endif CloseButton->setSizePolicy(ButtonSizePolicy); CloseButton->setIconSize(QSize(16, 16)); TopLayout->addWidget(CloseButton, 0); @@ -342,9 +336,7 @@ void CDockAreaTitleBar::onTabsMenuAboutToShow() } auto Tab = d->TabBar->tab(i); QAction* Action = menu->addAction(Tab->icon(), Tab->text()); - #ifndef QT_NO_TOOLTIP - Action->setToolTip(Tab->toolTip()); - #endif + internal::setToolTip(Action, Tab->toolTip()); Action->setData(i); } diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index 50d90ef..aeea936 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -184,9 +184,7 @@ void DockWidgetTabPrivate::createLayout() CloseButton->setIcon(CloseIcon); CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); _this->onDockWidgetFeaturesChanged(); -#ifndef QT_NO_TOOLTIP - CloseButton->setToolTip(QObject::tr("Close Tab")); -#endif + internal::setToolTip(CloseButton, QObject::tr("Close Tab")); _this->connect(CloseButton, SIGNAL(clicked()), SIGNAL(closeRequested())); QFontMetrics fm(TitleLabel->font()); @@ -499,9 +497,7 @@ void CDockWidgetTab::setIcon(const QIcon& Icon) d->IconLabel = new QLabel(); d->IconLabel->setAlignment(Qt::AlignVCenter); d->IconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); - #ifndef QT_NO_TOOLTIP - d->IconLabel->setToolTip(d->TitleLabel->toolTip()); - #endif + internal::setToolTip(d->IconLabel, d->TitleLabel->toolTip()); Layout->insertWidget(0, d->IconLabel, Qt::AlignVCenter); Layout->insertSpacing(1, qRound(1.5 * Layout->contentsMargins().left() / 2.0)); } diff --git a/src/ElidingLabel.cpp b/src/ElidingLabel.cpp index c15d825..18bb2b3 100644 --- a/src/ElidingLabel.cpp +++ b/src/ElidingLabel.cpp @@ -88,9 +88,7 @@ CElidingLabel::CElidingLabel(const QString& text, QWidget* parent, Qt::WindowFla d(new ElidingLabelPrivate(this)) { d->Text = text; -#ifndef QT_NO_TOOLTIP - setToolTip(text); -#endif + internal::setToolTip(this, text); } @@ -193,9 +191,7 @@ void CElidingLabel::setText(const QString &text) else { d->Text = text; -#ifndef QT_NO_TOOLTIP - setToolTip( text ); -#endif + internal::setToolTip(this, text); d->elideText(this->size().width()); } } diff --git a/src/ads_globals.h b/src/ads_globals.h index f8c48c0..1fe5f8e 100644 --- a/src/ads_globals.h +++ b/src/ads_globals.h @@ -215,6 +215,22 @@ void setFlag(T& Flags, typename T::enum_type flag, bool on = true) #endif } + +/** + * Helper function for settings tooltips without cluttering the code with + * tests for preprocessor macros + */ +template +void setToolTip(QObjectPtr obj, const QString &tip) +{ +#ifndef QT_NO_TOOLTIP + obj->setToolTip(tip); +#else + Q_UNUSED(obj); + Q_UNUSED(tip); +#endif +} + } // namespace internal } // namespace ads