QTabBar/Widget: use pmf-style connects

Use pmf-style connections instead old string-based ones.

Change-Id: I592a8918f8a06315db2e08da8d4c7fa8b52aa6f8
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Christian Ehrlicher 2023-11-22 20:32:50 +01:00
parent 11d8200249
commit 323cf718f6
5 changed files with 29 additions and 30 deletions

View File

@ -366,12 +366,14 @@ void QTabBarPrivate::init()
leftB = new QToolButton(q); leftB = new QToolButton(q);
leftB->setObjectName(u"ScrollLeftButton"_s); leftB->setObjectName(u"ScrollLeftButton"_s);
leftB->setAutoRepeat(true); leftB->setAutoRepeat(true);
QObject::connect(leftB, SIGNAL(clicked()), q, SLOT(_q_scrollTabs())); QObjectPrivate::connect(leftB, &QToolButton::clicked,
this, &QTabBarPrivate::scrollTabs);
leftB->hide(); leftB->hide();
rightB = new QToolButton(q); rightB = new QToolButton(q);
rightB->setObjectName(u"ScrollRightButton"_s); rightB->setObjectName(u"ScrollRightButton"_s);
rightB->setAutoRepeat(true); rightB->setAutoRepeat(true);
QObject::connect(rightB, SIGNAL(clicked()), q, SLOT(_q_scrollTabs())); QObjectPrivate::connect(rightB, &QToolButton::clicked,
this, &QTabBarPrivate::scrollTabs);
rightB->hide(); rightB->hide();
#ifdef QT_KEYPAD_NAVIGATION #ifdef QT_KEYPAD_NAVIGATION
if (QApplicationPrivate::keypadNavigationEnabled()) { if (QApplicationPrivate::keypadNavigationEnabled()) {
@ -765,7 +767,7 @@ void QTabBarPrivate::autoHideTabs()
q->setVisible(q->count() > 1); q->setVisible(q->count() > 1);
} }
void QTabBarPrivate::_q_closeTab() void QTabBarPrivate::closeTab()
{ {
Q_Q(QTabBar); Q_Q(QTabBar);
QObject *object = q->sender(); QObject *object = q->sender();
@ -788,7 +790,7 @@ void QTabBarPrivate::_q_closeTab()
emit q->tabCloseRequested(tabToClose); emit q->tabCloseRequested(tabToClose);
} }
void QTabBarPrivate::_q_scrollTabs() void QTabBarPrivate::scrollTabs()
{ {
Q_Q(QTabBar); Q_Q(QTabBar);
const QObject *sender = q->sender(); const QObject *sender = q->sender();
@ -973,7 +975,8 @@ int QTabBar::insertTab(int index, const QIcon& icon, const QString &text)
initStyleOption(&opt, index); initStyleOption(&opt, index);
ButtonPosition closeSide = (ButtonPosition)style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, nullptr, this); ButtonPosition closeSide = (ButtonPosition)style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, nullptr, this);
QAbstractButton *closeButton = new CloseButton(this); QAbstractButton *closeButton = new CloseButton(this);
connect(closeButton, SIGNAL(clicked()), this, SLOT(_q_closeTab())); QObjectPrivate::connect(closeButton, &CloseButton::clicked,
d, &QTabBarPrivate::closeTab);
setTabButton(index, closeSide, closeButton); setTabButton(index, closeSide, closeButton);
} }
@ -2577,7 +2580,8 @@ void QTabBar::setTabsClosable(bool closable)
continue; continue;
newButtons = true; newButtons = true;
QAbstractButton *closeButton = new CloseButton(this); QAbstractButton *closeButton = new CloseButton(this);
connect(closeButton, SIGNAL(clicked()), this, SLOT(_q_closeTab())); QObjectPrivate::connect(closeButton, &CloseButton::clicked,
d, &QTabBarPrivate::closeTab);
setTabButton(i, closeSide, closeButton); setTabButton(i, closeSide, closeButton);
} }
if (newButtons) if (newButtons)

View File

@ -185,8 +185,6 @@ protected:
private: private:
Q_DISABLE_COPY(QTabBar) Q_DISABLE_COPY(QTabBar)
Q_DECLARE_PRIVATE(QTabBar) Q_DECLARE_PRIVATE(QTabBar)
Q_PRIVATE_SLOT(d_func(), void _q_scrollTabs())
Q_PRIVATE_SLOT(d_func(), void _q_closeTab())
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -187,8 +187,8 @@ public:
inline bool validIndex(int index) const { return index >= 0 && index < tabList.size(); } inline bool validIndex(int index) const { return index >= 0 && index < tabList.size(); }
void setCurrentNextEnabledIndex(int offset); void setCurrentNextEnabledIndex(int offset);
void _q_scrollTabs(); void scrollTabs();
void _q_closeTab(); void closeTab();
void moveTab(int index, int offset); void moveTab(int index, int offset);
void moveTabFinished(int index); void moveTabFinished(int index);

View File

@ -156,9 +156,9 @@ public:
QTabWidgetPrivate(); QTabWidgetPrivate();
~QTabWidgetPrivate(); ~QTabWidgetPrivate();
void updateTabBarPosition(); void updateTabBarPosition();
void _q_showTab(int); void showTab(int);
void _q_removeTab(int); void removeTab(int);
void _q_tabMoved(int from, int to); void tabMoved(int from, int to);
void init(); void init();
bool isAutoHidden() const bool isAutoHidden() const
{ {
@ -197,7 +197,7 @@ void QTabWidgetPrivate::init()
// hack so that QMacStyle::layoutSpacing() can detect tab widget pages // hack so that QMacStyle::layoutSpacing() can detect tab widget pages
stack->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::TabWidget)); stack->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::TabWidget));
QObject::connect(stack, SIGNAL(widgetRemoved(int)), q, SLOT(_q_removeTab(int))); QObjectPrivate::connect(stack, &QStackedWidget::widgetRemoved, this, &QTabWidgetPrivate::removeTab);
QTabBar *tabBar = new QTabBar(q); QTabBar *tabBar = new QTabBar(q);
tabBar->setObjectName("qt_tabwidget_tabbar"_L1); tabBar->setObjectName("qt_tabwidget_tabbar"_L1);
tabBar->setDrawBase(false); tabBar->setDrawBase(false);
@ -720,17 +720,17 @@ void QTabWidget::setTabBar(QTabBar* tb)
delete d->tabs; delete d->tabs;
d->tabs = tb; d->tabs = tb;
setFocusProxy(d->tabs); setFocusProxy(d->tabs);
connect(d->tabs, SIGNAL(currentChanged(int)), QObjectPrivate::connect(d->tabs, &QTabBar::currentChanged,
this, SLOT(_q_showTab(int))); d, &QTabWidgetPrivate::showTab);
connect(d->tabs, SIGNAL(tabMoved(int,int)), QObjectPrivate::connect(d->tabs, &QTabBar::tabMoved,
this, SLOT(_q_tabMoved(int,int))); d, &QTabWidgetPrivate::tabMoved);
connect(d->tabs, SIGNAL(tabBarClicked(int)), connect(d->tabs, &QTabBar::tabBarClicked,
this, SIGNAL(tabBarClicked(int))); this, &QTabWidget::tabBarClicked);
connect(d->tabs, SIGNAL(tabBarDoubleClicked(int)), connect(d->tabs, &QTabBar::tabBarDoubleClicked,
this, SIGNAL(tabBarDoubleClicked(int))); this, &QTabWidget::tabBarDoubleClicked);
if (d->tabs->tabsClosable()) if (d->tabs->tabsClosable())
connect(d->tabs, SIGNAL(tabCloseRequested(int)), connect(d->tabs, &QTabBar::tabCloseRequested,
this, SIGNAL(tabCloseRequested(int))); this, &QTabWidget::tabCloseRequested);
tb->setExpanding(!documentMode()); tb->setExpanding(!documentMode());
setUpLayout(); setUpLayout();
} }
@ -752,7 +752,7 @@ QTabBar* QTabWidget::tabBar() const
sized. sized.
*/ */
void QTabWidgetPrivate::_q_showTab(int index) void QTabWidgetPrivate::showTab(int index)
{ {
Q_Q(QTabWidget); Q_Q(QTabWidget);
if (index < stack->count() && index >= 0) if (index < stack->count() && index >= 0)
@ -760,7 +760,7 @@ void QTabWidgetPrivate::_q_showTab(int index)
emit q->currentChanged(index); emit q->currentChanged(index);
} }
void QTabWidgetPrivate::_q_removeTab(int index) void QTabWidgetPrivate::removeTab(int index)
{ {
Q_Q(QTabWidget); Q_Q(QTabWidget);
tabs->removeTab(index); tabs->removeTab(index);
@ -768,7 +768,7 @@ void QTabWidgetPrivate::_q_removeTab(int index)
q->tabRemoved(index); q->tabRemoved(index);
} }
void QTabWidgetPrivate::_q_tabMoved(int from, int to) void QTabWidgetPrivate::tabMoved(int from, int to)
{ {
const QSignalBlocker blocker(stack); const QSignalBlocker blocker(stack);
QWidget *w = stack->widget(from); QWidget *w = stack->widget(from);

View File

@ -141,9 +141,6 @@ protected:
private: private:
Q_DECLARE_PRIVATE(QTabWidget) Q_DECLARE_PRIVATE(QTabWidget)
Q_DISABLE_COPY(QTabWidget) Q_DISABLE_COPY(QTabWidget)
Q_PRIVATE_SLOT(d_func(), void _q_showTab(int))
Q_PRIVATE_SLOT(d_func(), void _q_removeTab(int))
Q_PRIVATE_SLOT(d_func(), void _q_tabMoved(int, int))
void setUpLayout(bool = false); void setUpLayout(bool = false);
}; };