From 1ad61f8da32620a8472d01d6814c9a55db6e5b4e Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Sat, 27 Jan 2024 14:23:39 +0100 Subject: [PATCH] Axivion: Extract fetching table into the reusable recipe Get rid of public fetchIssueTableLayout() method. Introduce tableInfoRecipe() which takes a handler as an arg. This decouples the plugin from AxivionOutputPane's API. Change-Id: Iae3ce83e132e0769b45ed3db911bd1046cc7bcb8 Reviewed-by: Christian Stenger --- src/plugins/axivion/axivionoutputpane.cpp | 40 +++++++++++------------ src/plugins/axivion/axivionoutputpane.h | 1 - src/plugins/axivion/axivionplugin.cpp | 25 +++----------- src/plugins/axivion/axivionplugin.h | 7 ++-- 4 files changed, 29 insertions(+), 44 deletions(-) diff --git a/src/plugins/axivion/axivionoutputpane.cpp b/src/plugins/axivion/axivionoutputpane.cpp index 42c124bd4b4..4c2b4e77293 100644 --- a/src/plugins/axivion/axivionoutputpane.cpp +++ b/src/plugins/axivion/axivionoutputpane.cpp @@ -240,7 +240,7 @@ private: TreeModel<> *m_issuesModel = nullptr; int m_totalRowCount = 0; int m_lastRequestedOffset = 0; - TaskTreeRunner m_issuesRunner; + TaskTreeRunner m_taskTreeRunner; }; IssuesWidget::IssuesWidget(QWidget *parent) @@ -385,15 +385,6 @@ void IssuesWidget::setTableDto(const Dto::TableInfoDto &dto) int counter = 0; for (const QString &header : std::as_const(columnHeaders)) m_issuesView->setColumnHidden(counter++, hiddenColumns.contains(header)); - - // first time lookup... should we cache and maybe represent old data? - m_totalRowCount = 0; - m_lastRequestedOffset = 0; - IssueListSearch search; - search.kind = m_currentPrefix; - search.computeTotalRowCount = true; - m_issuesView->showProgressIndicator(); - fetchIssues(search); } static QString anyToSimpleString(const Dto::Any &any) @@ -479,20 +470,36 @@ void IssuesWidget::addIssues(const Dto::IssueTableDto &dto) it->setLinks(linksForIssue(row)); m_issuesModel->rootItem()->appendChild(it); } - m_issuesView->hideProgressIndicator(); } void IssuesWidget::updateTableView() { QTC_ASSERT(!m_currentPrefix.isEmpty(), return); // fetch table dto and apply, on done fetch first data for the selected issues - fetchIssueTableLayout(m_currentPrefix); + const auto tableHandler = [this](const Dto::TableInfoDto &dto) { setTableDto(dto); }; + const auto setupHandler = [this](TaskTree *) { m_issuesView->showProgressIndicator(); }; + const auto doneHandler = [this](DoneWith result) { + if (result == DoneWith::Error) { + m_issuesView->hideProgressIndicator(); + return; + } + // first time lookup... should we cache and maybe represent old data? + m_totalRowCount = 0; + m_lastRequestedOffset = 0; + IssueListSearch search; + search.kind = m_currentPrefix; + search.computeTotalRowCount = true; + fetchIssues(search); + }; + m_taskTreeRunner.start(tableInfoRecipe(m_currentPrefix, tableHandler), setupHandler, doneHandler); } void IssuesWidget::fetchIssues(const IssueListSearch &search) { const auto issuesHandler = [this](const Dto::IssueTableDto &dto) { addIssues(dto); }; - m_issuesRunner.start(issueTableRecipe(search, issuesHandler)); + const auto setupHandler = [this](TaskTree *) { m_issuesView->showProgressIndicator(); }; + const auto doneHandler = [this](DoneWith) { m_issuesView->hideProgressIndicator(); }; + m_taskTreeRunner.start(issueTableRecipe(search, issuesHandler), setupHandler, doneHandler); } void IssuesWidget::fetchMoreIssues() @@ -504,7 +511,6 @@ void IssuesWidget::fetchMoreIssues() search.kind = m_currentPrefix; m_lastRequestedOffset = m_issuesModel->rowCount(); search.offset = m_lastRequestedOffset; - m_issuesView->showProgressIndicator(); fetchIssues(search); } @@ -614,12 +620,6 @@ void AxivionOutputPane::updateDashboard() } } -void AxivionOutputPane::setTableDto(const Dto::TableInfoDto &dto) -{ - if (auto issues = static_cast(m_outputWidget->widget(1))) - issues->setTableDto(dto); -} - void AxivionOutputPane::updateAndShowRule(const QString &ruleHtml) { if (auto browser = static_cast(m_outputWidget->widget(2))) { diff --git a/src/plugins/axivion/axivionoutputpane.h b/src/plugins/axivion/axivionoutputpane.h index 58df206091d..5a44feba8e4 100644 --- a/src/plugins/axivion/axivionoutputpane.h +++ b/src/plugins/axivion/axivionoutputpane.h @@ -37,7 +37,6 @@ public: void updateDashboard(); void updateAndShowRule(const QString &ruleHtml); - void setTableDto(const Dto::TableInfoDto &dto); private: QStackedWidget *m_outputWidget = nullptr; }; diff --git a/src/plugins/axivion/axivionplugin.cpp b/src/plugins/axivion/axivionplugin.cpp index f35fb4f4d88..412616b81cd 100644 --- a/src/plugins/axivion/axivionplugin.cpp +++ b/src/plugins/axivion/axivionplugin.cpp @@ -86,7 +86,6 @@ public: void handleSslErrors(QNetworkReply *reply, const QList &errors); void onStartupProjectChanged(); void fetchProjectInfo(const QString &projectName); - void fetchIssueTableLayout(const QString &prefix); void handleOpenedDocs(ProjectExplorer::Project *project); void onDocumentOpened(Core::IDocument *doc); void onDocumentClosed(Core::IDocument * doc); @@ -139,12 +138,6 @@ void fetchProjectInfo(const QString &projectName) dd->fetchProjectInfo(projectName); } -void fetchIssueTableLayout(const QString &prefix) -{ - QTC_ASSERT(dd, return); - dd->fetchIssueTableLayout(prefix); -} - std::optional projectInfo() { QTC_ASSERT(dd, return {}); @@ -427,21 +420,11 @@ void AxivionPluginPrivate::fetchProjectInfo(const QString &projectName) m_taskTreeRunner.start(root); } -void AxivionPluginPrivate::fetchIssueTableLayout(const QString &prefix) +Group tableInfoRecipe(const QString &prefix, const TableInfoHandler &handler) { - QTC_ASSERT(m_currentProjectInfo.has_value(), return); - if (m_taskTreeRunner.isRunning()) { - QTimer::singleShot(3000, this, [this, prefix] { fetchIssueTableLayout(prefix); }); - return; - } - const QUrl url = urlForProject(m_currentProjectInfo.value().name + '/') - .resolved(QString("issues_meta?kind=" + prefix)); - - const auto handler = [this](const Dto::TableInfoDto &data) { - m_axivionOutputPane.setTableDto(data); - }; - - m_taskTreeRunner.start(fetchDataRecipe(url, handler)); + const QUrl url = urlForProject(dd->m_currentProjectInfo.value().name + '/') + .resolved(QString("issues_meta?kind=" + prefix)); + return fetchDataRecipe(url, handler); } void AxivionPluginPrivate::fetchRuleInfo(const QString &id) diff --git a/src/plugins/axivion/axivionplugin.h b/src/plugins/axivion/axivionplugin.h index 9e29969934e..064ba5318dc 100644 --- a/src/plugins/axivion/axivionplugin.h +++ b/src/plugins/axivion/axivionplugin.h @@ -51,13 +51,16 @@ public: using DashboardInfoHandler = std::function &)>; Tasking::Group dashboardInfoRecipe(const DashboardInfoHandler &handler = {}); -// TODO: Wrap data into expected_str<>? +// TODO: Wrap into expected_str<>? +using TableInfoHandler = std::function; +Tasking::Group tableInfoRecipe(const QString &prefix, const TableInfoHandler &handler); + +// TODO: Wrap into expected_str<>? using IssueTableHandler = std::function; Tasking::Group issueTableRecipe(const IssueListSearch &search, const IssueTableHandler &handler); void fetchProjectInfo(const QString &projectName); std::optional projectInfo(); -void fetchIssueTableLayout(const QString &prefix); bool handleCertificateIssue(); QIcon iconForIssue(const QString &prefix);