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 <christian.stenger@qt.io>
This commit is contained in:
Jarek Kobus
2024-01-27 14:23:39 +01:00
parent 5c1ee4021a
commit 1ad61f8da3
4 changed files with 29 additions and 44 deletions

View File

@@ -240,7 +240,7 @@ private:
TreeModel<> *m_issuesModel = nullptr; TreeModel<> *m_issuesModel = nullptr;
int m_totalRowCount = 0; int m_totalRowCount = 0;
int m_lastRequestedOffset = 0; int m_lastRequestedOffset = 0;
TaskTreeRunner m_issuesRunner; TaskTreeRunner m_taskTreeRunner;
}; };
IssuesWidget::IssuesWidget(QWidget *parent) IssuesWidget::IssuesWidget(QWidget *parent)
@@ -385,15 +385,6 @@ void IssuesWidget::setTableDto(const Dto::TableInfoDto &dto)
int counter = 0; int counter = 0;
for (const QString &header : std::as_const(columnHeaders)) for (const QString &header : std::as_const(columnHeaders))
m_issuesView->setColumnHidden(counter++, hiddenColumns.contains(header)); 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) static QString anyToSimpleString(const Dto::Any &any)
@@ -479,20 +470,36 @@ void IssuesWidget::addIssues(const Dto::IssueTableDto &dto)
it->setLinks(linksForIssue(row)); it->setLinks(linksForIssue(row));
m_issuesModel->rootItem()->appendChild(it); m_issuesModel->rootItem()->appendChild(it);
} }
m_issuesView->hideProgressIndicator();
} }
void IssuesWidget::updateTableView() void IssuesWidget::updateTableView()
{ {
QTC_ASSERT(!m_currentPrefix.isEmpty(), return); QTC_ASSERT(!m_currentPrefix.isEmpty(), return);
// fetch table dto and apply, on done fetch first data for the selected issues // 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) void IssuesWidget::fetchIssues(const IssueListSearch &search)
{ {
const auto issuesHandler = [this](const Dto::IssueTableDto &dto) { addIssues(dto); }; 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() void IssuesWidget::fetchMoreIssues()
@@ -504,7 +511,6 @@ void IssuesWidget::fetchMoreIssues()
search.kind = m_currentPrefix; search.kind = m_currentPrefix;
m_lastRequestedOffset = m_issuesModel->rowCount(); m_lastRequestedOffset = m_issuesModel->rowCount();
search.offset = m_lastRequestedOffset; search.offset = m_lastRequestedOffset;
m_issuesView->showProgressIndicator();
fetchIssues(search); fetchIssues(search);
} }
@@ -614,12 +620,6 @@ void AxivionOutputPane::updateDashboard()
} }
} }
void AxivionOutputPane::setTableDto(const Dto::TableInfoDto &dto)
{
if (auto issues = static_cast<IssuesWidget *>(m_outputWidget->widget(1)))
issues->setTableDto(dto);
}
void AxivionOutputPane::updateAndShowRule(const QString &ruleHtml) void AxivionOutputPane::updateAndShowRule(const QString &ruleHtml)
{ {
if (auto browser = static_cast<QTextBrowser *>(m_outputWidget->widget(2))) { if (auto browser = static_cast<QTextBrowser *>(m_outputWidget->widget(2))) {

View File

@@ -37,7 +37,6 @@ public:
void updateDashboard(); void updateDashboard();
void updateAndShowRule(const QString &ruleHtml); void updateAndShowRule(const QString &ruleHtml);
void setTableDto(const Dto::TableInfoDto &dto);
private: private:
QStackedWidget *m_outputWidget = nullptr; QStackedWidget *m_outputWidget = nullptr;
}; };

View File

@@ -86,7 +86,6 @@ public:
void handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors); void handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
void onStartupProjectChanged(); void onStartupProjectChanged();
void fetchProjectInfo(const QString &projectName); void fetchProjectInfo(const QString &projectName);
void fetchIssueTableLayout(const QString &prefix);
void handleOpenedDocs(ProjectExplorer::Project *project); void handleOpenedDocs(ProjectExplorer::Project *project);
void onDocumentOpened(Core::IDocument *doc); void onDocumentOpened(Core::IDocument *doc);
void onDocumentClosed(Core::IDocument * doc); void onDocumentClosed(Core::IDocument * doc);
@@ -139,12 +138,6 @@ void fetchProjectInfo(const QString &projectName)
dd->fetchProjectInfo(projectName); dd->fetchProjectInfo(projectName);
} }
void fetchIssueTableLayout(const QString &prefix)
{
QTC_ASSERT(dd, return);
dd->fetchIssueTableLayout(prefix);
}
std::optional<Dto::ProjectInfoDto> projectInfo() std::optional<Dto::ProjectInfoDto> projectInfo()
{ {
QTC_ASSERT(dd, return {}); QTC_ASSERT(dd, return {});
@@ -427,21 +420,11 @@ void AxivionPluginPrivate::fetchProjectInfo(const QString &projectName)
m_taskTreeRunner.start(root); 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); const QUrl url = urlForProject(dd->m_currentProjectInfo.value().name + '/')
if (m_taskTreeRunner.isRunning()) { .resolved(QString("issues_meta?kind=" + prefix));
QTimer::singleShot(3000, this, [this, prefix] { fetchIssueTableLayout(prefix); }); return fetchDataRecipe<Dto::TableInfoDto>(url, handler);
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<Dto::TableInfoDto>(url, handler));
} }
void AxivionPluginPrivate::fetchRuleInfo(const QString &id) void AxivionPluginPrivate::fetchRuleInfo(const QString &id)

View File

@@ -51,13 +51,16 @@ public:
using DashboardInfoHandler = std::function<void(const Utils::expected_str<DashboardInfo> &)>; using DashboardInfoHandler = std::function<void(const Utils::expected_str<DashboardInfo> &)>;
Tasking::Group dashboardInfoRecipe(const DashboardInfoHandler &handler = {}); Tasking::Group dashboardInfoRecipe(const DashboardInfoHandler &handler = {});
// TODO: Wrap data into expected_str<>? // TODO: Wrap into expected_str<>?
using TableInfoHandler = std::function<void(const Dto::TableInfoDto &)>;
Tasking::Group tableInfoRecipe(const QString &prefix, const TableInfoHandler &handler);
// TODO: Wrap into expected_str<>?
using IssueTableHandler = std::function<void(const Dto::IssueTableDto &)>; using IssueTableHandler = std::function<void(const Dto::IssueTableDto &)>;
Tasking::Group issueTableRecipe(const IssueListSearch &search, const IssueTableHandler &handler); Tasking::Group issueTableRecipe(const IssueListSearch &search, const IssueTableHandler &handler);
void fetchProjectInfo(const QString &projectName); void fetchProjectInfo(const QString &projectName);
std::optional<Dto::ProjectInfoDto> projectInfo(); std::optional<Dto::ProjectInfoDto> projectInfo();
void fetchIssueTableLayout(const QString &prefix);
bool handleCertificateIssue(); bool handleCertificateIssue();
QIcon iconForIssue(const QString &prefix); QIcon iconForIssue(const QString &prefix);