forked from qt-creator/qt-creator
TextBrowserHelpViewer: Avoid using sender()
Avoid setting / getting QAction data. Change-Id: I61d62f2376e09c1dfeadbbe5ada32938ff8bc821 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -144,8 +144,10 @@ void TextBrowserHelpViewer::addBackHistoryItems(QMenu *backMenu)
|
|||||||
for (int i = 1; i <= m_textBrowser->backwardHistoryCount(); ++i) {
|
for (int i = 1; i <= m_textBrowser->backwardHistoryCount(); ++i) {
|
||||||
auto action = new QAction(backMenu);
|
auto action = new QAction(backMenu);
|
||||||
action->setText(m_textBrowser->historyTitle(-i));
|
action->setText(m_textBrowser->historyTitle(-i));
|
||||||
action->setData(-i);
|
connect(action, &QAction::triggered, this, [this, index = i] {
|
||||||
connect(action, &QAction::triggered, this, &TextBrowserHelpViewer::goToHistoryItem);
|
for (int i = 0; i < index; ++i)
|
||||||
|
m_textBrowser->backward();
|
||||||
|
});
|
||||||
backMenu->addAction(action);
|
backMenu->addAction(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,8 +157,10 @@ void TextBrowserHelpViewer::addForwardHistoryItems(QMenu *forwardMenu)
|
|||||||
for (int i = 1; i <= m_textBrowser->forwardHistoryCount(); ++i) {
|
for (int i = 1; i <= m_textBrowser->forwardHistoryCount(); ++i) {
|
||||||
auto action = new QAction(forwardMenu);
|
auto action = new QAction(forwardMenu);
|
||||||
action->setText(m_textBrowser->historyTitle(i));
|
action->setText(m_textBrowser->historyTitle(i));
|
||||||
action->setData(i);
|
connect(action, &QAction::triggered, this, [this, index = i] {
|
||||||
connect(action, &QAction::triggered, this, &TextBrowserHelpViewer::goToHistoryItem);
|
for (int i = 0; i < index; ++i)
|
||||||
|
m_textBrowser->forward();
|
||||||
|
});
|
||||||
forwardMenu->addAction(action);
|
forwardMenu->addAction(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -242,25 +246,6 @@ void TextBrowserHelpViewer::print(QPrinter *printer)
|
|||||||
m_textBrowser->print(printer);
|
m_textBrowser->print(printer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextBrowserHelpViewer::goToHistoryItem()
|
|
||||||
{
|
|
||||||
auto action = qobject_cast<const QAction *>(sender());
|
|
||||||
QTC_ASSERT(action, return);
|
|
||||||
bool ok = false;
|
|
||||||
int index = action->data().toInt(&ok);
|
|
||||||
QTC_ASSERT(ok, return);
|
|
||||||
// go back?
|
|
||||||
while (index < 0) {
|
|
||||||
m_textBrowser->backward();
|
|
||||||
++index;
|
|
||||||
}
|
|
||||||
// go forward?
|
|
||||||
while (index > 0) {
|
|
||||||
m_textBrowser->forward();
|
|
||||||
--index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// -- private
|
// -- private
|
||||||
|
|
||||||
TextBrowserHelpWidget::TextBrowserHelpWidget(TextBrowserHelpViewer *parent)
|
TextBrowserHelpWidget::TextBrowserHelpWidget(TextBrowserHelpViewer *parent)
|
||||||
|
@@ -70,7 +70,6 @@ public:
|
|||||||
void print(QPrinter *printer) override;
|
void print(QPrinter *printer) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void goToHistoryItem();
|
|
||||||
void setFontAndScale(const QFont &font, qreal scale);
|
void setFontAndScale(const QFont &font, qreal scale);
|
||||||
|
|
||||||
TextBrowserHelpWidget *m_textBrowser;
|
TextBrowserHelpWidget *m_textBrowser;
|
||||||
|
Reference in New Issue
Block a user