Simplify tab handling in Search widget

PR #21729.
This commit is contained in:
Chocobo1 2024-11-03 14:43:23 +08:00 committed by GitHub
parent 1a7ebfc8f0
commit 6f642776b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 13 deletions

View file

@ -120,7 +120,6 @@ SearchWidget::SearchWidget(IGUIApplication *app, MainWindow *mainWindow)
#endif
connect(m_ui->tabWidget, &QTabWidget::tabCloseRequested, this, &SearchWidget::closeTab);
connect(m_ui->tabWidget, &QTabWidget::currentChanged, this, &SearchWidget::tabChanged);
connect(m_ui->tabWidget->tabBar(), &QTabBar::tabMoved, this, &SearchWidget::tabMoved);
const auto *searchManager = SearchPluginManager::instance();
const auto onPluginChanged = [this]()
@ -260,12 +259,9 @@ void SearchWidget::tabChanged(const int index)
{
// when we switch from a tab that is not empty to another that is empty
// the download button doesn't have to be available
m_currentSearchTab = ((index < 0) ? nullptr : m_allTabs.at(m_ui->tabWidget->currentIndex()));
}
void SearchWidget::tabMoved(const int from, const int to)
{
m_allTabs.move(from, to);
m_currentSearchTab = (index >= 0)
? static_cast<SearchJobWidget *>(m_ui->tabWidget->widget(index))
: nullptr;
}
void SearchWidget::selectMultipleBox([[maybe_unused]] const int index)
@ -353,7 +349,6 @@ void SearchWidget::on_searchButton_clicked()
// Tab Addition
auto *newTab = new SearchJobWidget(searchHandler, app(), this);
m_allTabs.append(newTab);
QString tabName = pattern;
tabName.replace(QRegularExpression(u"&{1}"_s), u"&&"_s);
@ -391,9 +386,9 @@ void SearchWidget::tabStatusChanged(QWidget *tab)
}
}
void SearchWidget::closeTab(int index)
void SearchWidget::closeTab(const int index)
{
SearchJobWidget *tab = m_allTabs.takeAt(index);
const QWidget *tab = m_ui->tabWidget->widget(index);
if (tab == m_activeSearchTab)
m_ui->searchButton->setText(tr("Search"));
@ -402,6 +397,6 @@ void SearchWidget::closeTab(int index)
void SearchWidget::closeAllTabs()
{
for (int i = (m_allTabs.size() - 1); i >= 0; --i)
for (int i = (m_ui->tabWidget->count() - 1); i >= 0; --i)
closeTab(i);
}

View file

@ -66,7 +66,6 @@ private slots:
private:
bool eventFilter(QObject *object, QEvent *event) override;
void tabChanged(int index);
void tabMoved(int from, int to);
void closeTab(int index);
void closeAllTabs();
void tabStatusChanged(QWidget *tab);
@ -84,7 +83,6 @@ private:
Ui::SearchWidget *m_ui = nullptr;
QPointer<SearchJobWidget> m_currentSearchTab; // Selected tab
QPointer<SearchJobWidget> m_activeSearchTab; // Tab with running search
QList<SearchJobWidget *> m_allTabs; // To store all tabs
MainWindow *m_mainWindow = nullptr;
bool m_isNewQueryString = false;
};