forked from qt-creator/qt-creator
Axivion: Extract fetching issues into the reusable recipe
Get rid of public fetchIssues() method. Introduce issueTableRecipe() which takes a handler as an arg. This decouples the plugin from AxivionOutputPane's API. Change-Id: I4a4e2fd14dfd4eed2d28648a227a1ed3a5fe90f3 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -12,6 +12,8 @@
|
|||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
#include <projectexplorer/projectmanager.h>
|
#include <projectexplorer/projectmanager.h>
|
||||||
|
|
||||||
|
#include <solutions/tasking/tasktreerunner.h>
|
||||||
|
|
||||||
#include <utils/link.h>
|
#include <utils/link.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/treemodel.h>
|
#include <utils/treemodel.h>
|
||||||
@@ -32,6 +34,7 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
using namespace Tasking;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Axivion::Internal {
|
namespace Axivion::Internal {
|
||||||
@@ -219,6 +222,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void updateTableView();
|
void updateTableView();
|
||||||
|
void fetchIssues(const IssueListSearch &search);
|
||||||
void fetchMoreIssues();
|
void fetchMoreIssues();
|
||||||
|
|
||||||
QString m_currentPrefix;
|
QString m_currentPrefix;
|
||||||
@@ -236,6 +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;
|
||||||
};
|
};
|
||||||
|
|
||||||
IssuesWidget::IssuesWidget(QWidget *parent)
|
IssuesWidget::IssuesWidget(QWidget *parent)
|
||||||
@@ -484,6 +489,12 @@ void IssuesWidget::updateTableView()
|
|||||||
fetchIssueTableLayout(m_currentPrefix);
|
fetchIssueTableLayout(m_currentPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IssuesWidget::fetchIssues(const IssueListSearch &search)
|
||||||
|
{
|
||||||
|
const auto issuesHandler = [this](const Dto::IssueTableDto &dto) { addIssues(dto); };
|
||||||
|
m_issuesRunner.start(issueTableRecipe(search, issuesHandler));
|
||||||
|
}
|
||||||
|
|
||||||
void IssuesWidget::fetchMoreIssues()
|
void IssuesWidget::fetchMoreIssues()
|
||||||
{
|
{
|
||||||
if (m_lastRequestedOffset == m_issuesModel->rowCount())
|
if (m_lastRequestedOffset == m_issuesModel->rowCount())
|
||||||
@@ -609,12 +620,6 @@ void AxivionOutputPane::setTableDto(const Dto::TableInfoDto &dto)
|
|||||||
issues->setTableDto(dto);
|
issues->setTableDto(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AxivionOutputPane::addIssues(const Dto::IssueTableDto &dto)
|
|
||||||
{
|
|
||||||
if (auto issues = static_cast<IssuesWidget *>(m_outputWidget->widget(1)))
|
|
||||||
issues->addIssues(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))) {
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ QT_END_NAMESPACE
|
|||||||
namespace Axivion::Internal {
|
namespace Axivion::Internal {
|
||||||
|
|
||||||
namespace Dto {
|
namespace Dto {
|
||||||
class IssueTableDto;
|
|
||||||
class TableInfoDto;
|
class TableInfoDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +38,6 @@ public:
|
|||||||
void updateDashboard();
|
void updateDashboard();
|
||||||
void updateAndShowRule(const QString &ruleHtml);
|
void updateAndShowRule(const QString &ruleHtml);
|
||||||
void setTableDto(const Dto::TableInfoDto &dto);
|
void setTableDto(const Dto::TableInfoDto &dto);
|
||||||
void addIssues(const Dto::IssueTableDto &dto);
|
|
||||||
private:
|
private:
|
||||||
QStackedWidget *m_outputWidget = nullptr;
|
QStackedWidget *m_outputWidget = nullptr;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -87,7 +87,6 @@ public:
|
|||||||
void onStartupProjectChanged();
|
void onStartupProjectChanged();
|
||||||
void fetchProjectInfo(const QString &projectName);
|
void fetchProjectInfo(const QString &projectName);
|
||||||
void fetchIssueTableLayout(const QString &prefix);
|
void fetchIssueTableLayout(const QString &prefix);
|
||||||
void fetchIssues(const IssueListSearch &search);
|
|
||||||
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);
|
||||||
@@ -146,12 +145,6 @@ void fetchIssueTableLayout(const QString &prefix)
|
|||||||
dd->fetchIssueTableLayout(prefix);
|
dd->fetchIssueTableLayout(prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fetchIssues(const IssueListSearch &search)
|
|
||||||
{
|
|
||||||
QTC_ASSERT(dd, return);
|
|
||||||
dd->fetchIssues(search);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<Dto::ProjectInfoDto> projectInfo()
|
std::optional<Dto::ProjectInfoDto> projectInfo()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(dd, return {});
|
QTC_ASSERT(dd, return {});
|
||||||
@@ -373,6 +366,20 @@ Group dashboardInfoRecipe(const DashboardInfoHandler &handler)
|
|||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Group issueTableRecipe(const IssueListSearch &search, const IssueTableHandler &handler)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(dd->m_currentProjectInfo, return {}); // TODO: Call handler with unexpected?
|
||||||
|
|
||||||
|
const QString query = search.toQuery();
|
||||||
|
if (query.isEmpty())
|
||||||
|
return {}; // TODO: Call handler with unexpected?
|
||||||
|
|
||||||
|
const QUrl url = urlForProject(dd->m_currentProjectInfo.value().name + '/')
|
||||||
|
.resolved(QString("issues" + query));
|
||||||
|
|
||||||
|
return fetchDataRecipe<Dto::IssueTableDto>(url, handler);
|
||||||
|
}
|
||||||
|
|
||||||
void AxivionPluginPrivate::fetchProjectInfo(const QString &projectName)
|
void AxivionPluginPrivate::fetchProjectInfo(const QString &projectName)
|
||||||
{
|
{
|
||||||
if (m_taskTreeRunner.isRunning()) { // TODO: cache in queue and run when task tree finished
|
if (m_taskTreeRunner.isRunning()) { // TODO: cache in queue and run when task tree finished
|
||||||
@@ -437,28 +444,6 @@ void AxivionPluginPrivate::fetchIssueTableLayout(const QString &prefix)
|
|||||||
m_taskTreeRunner.start(fetchDataRecipe<Dto::TableInfoDto>(url, handler));
|
m_taskTreeRunner.start(fetchDataRecipe<Dto::TableInfoDto>(url, handler));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AxivionPluginPrivate::fetchIssues(const IssueListSearch &search)
|
|
||||||
{
|
|
||||||
QTC_ASSERT(m_currentProjectInfo.has_value(), return);
|
|
||||||
if (m_taskTreeRunner.isRunning()) {
|
|
||||||
QTimer::singleShot(3000, this, [this, search] { fetchIssues(search); });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString query = search.toQuery();
|
|
||||||
if (query.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
const QUrl url = urlForProject(m_currentProjectInfo.value().name + '/')
|
|
||||||
.resolved(QString("issues" + query));
|
|
||||||
|
|
||||||
const auto handler = [this](const Dto::IssueTableDto &data) {
|
|
||||||
m_axivionOutputPane.addIssues(data);
|
|
||||||
};
|
|
||||||
|
|
||||||
m_taskTreeRunner.start(fetchDataRecipe<Dto::IssueTableDto>(url, handler));
|
|
||||||
}
|
|
||||||
|
|
||||||
void AxivionPluginPrivate::fetchRuleInfo(const QString &id)
|
void AxivionPluginPrivate::fetchRuleInfo(const QString &id)
|
||||||
{
|
{
|
||||||
if (m_runningQuery) {
|
if (m_runningQuery) {
|
||||||
|
|||||||
@@ -51,10 +51,13 @@ 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<>?
|
||||||
|
using IssueTableHandler = std::function<void(const Dto::IssueTableDto &)>;
|
||||||
|
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);
|
void fetchIssueTableLayout(const QString &prefix);
|
||||||
void fetchIssues(const IssueListSearch &search);
|
|
||||||
bool handleCertificateIssue();
|
bool handleCertificateIssue();
|
||||||
|
|
||||||
QIcon iconForIssue(const QString &prefix);
|
QIcon iconForIssue(const QString &prefix);
|
||||||
|
|||||||
Reference in New Issue
Block a user