Axivion: Take column information into account

When displaying values inside the issue table we have
basic information on how to handle specific types.

Fixes: QTCREATORBUG-32023
Change-Id: I59724701868bd86fc92224b8323667ca64977411
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: Mohammad Mehdi Salem Naraghi <mehdi.salem@qt.io>
This commit is contained in:
Christian Stenger
2024-11-15 15:27:01 +01:00
parent 4a655f9254
commit fe2a3bda65
3 changed files with 74 additions and 36 deletions

View File

@@ -661,16 +661,12 @@ void IssuesWidget::addIssues(const Dto::IssueTableDto &dto, int startRow)
for (const auto &column : tableColumns) { for (const auto &column : tableColumns) {
const auto it = row.find(column.key); const auto it = row.find(column.key);
if (it != row.end()) { if (it != row.end()) {
QString value = anyToSimpleString(it->second); QString value = anyToSimpleString(it->second, column.type, column.typeOptions);
if (column.key == "id") { if (column.key == "id") {
value.prepend(m_currentPrefix); value.prepend(m_currentPrefix);
id = value; id = value;
} }
toolTips << value; toolTips << value;
if (column.key.toLower().endsWith("path")) {
const FilePath fp = FilePath::fromUserInput(value);
value = QString("%1 [%2]").arg(fp.fileName(), fp.path());
}
data << value; data << value;
} }
} }

View File

@@ -74,41 +74,82 @@ QIcon iconForIssue(const std::optional<Dto::IssueKind> &issueKind)
return prefixToIcon.insert(*issueKind, icon.icon()).value(); return prefixToIcon.insert(*issueKind, icon.icon()).value();
} }
QString anyToSimpleString(const Dto::Any &any) static QString anyToString(const Dto::Any &any)
{ {
if (any.isString()) if (any.isNull() || !any.isString())
return any.getString(); return {};
if (any.isBool()) return any.getString();
return QString("%1").arg(any.getBool()); }
if (any.isDouble()) {
const double value = any.getDouble(); static QString anyToPathString(const Dto::Any &any)
double intPart; {
const double fragPart = std::modf(value, &intPart); const QString pathStr = anyToString(any);
if (fragPart != 0) if (pathStr.isEmpty())
return QString::number(value); return {};
return QString::number(value, 'f', 0); const FilePath fp = FilePath::fromUserInput(pathStr);
return fp.contains("/") ? QString("%1 [%2]").arg(fp.fileName(), fp.path()) : fp.fileName();
}
// only the first found innerKey is used to add its value to the list
static QString anyListOfMapToString(const Dto::Any &any, const QStringList &innerKeys)
{
if (any.isNull() || !any.isList())
return {};
const std::vector<Dto::Any> anyList = any.getList();
QStringList list;
for (const Dto::Any &inner : anyList) {
if (!inner.isMap())
continue;
const std::map<QString, Dto::Any> innerMap = inner.getMap();
for (const QString &innerKey : innerKeys) {
auto value = innerMap.find(innerKey);
if (value == innerMap.end())
continue;
list << anyToString(value->second);
break;
}
} }
return list.join(", ");
}
static QString anyToNumberString(const Dto::Any &any)
{
if (any.isNull()) if (any.isNull())
return QString(); // or NULL?? return {};
if (any.isList()) { if (any.isString()) // handle Infinity/NaN/...
const std::vector<Dto::Any> anyList = any.getList(); return any.getString();
QStringList list;
for (const Dto::Any &inner : anyList) const double value = any.getDouble();
list << anyToSimpleString(inner); double intPart;
return list.join(','); const double frac = std::modf(value, &intPart);
if (frac != 0)
return QString::number(value, 'f');
return QString::number(value, 'f', 0);
}
QString anyToSimpleString(const Dto::Any &any, const QString &type,
const std::optional<std::vector<Dto::ColumnTypeOptionDto>> &options)
{
if (type == "path")
return anyToPathString(any);
if (type == "string" || type == "state")
return anyToString(any);
if (type == "tags")
return anyListOfMapToString(any, {"tag"});
if (type == "number")
return anyToNumberString(any);
if (type == "owners") {
return anyListOfMapToString(any, {"displayName", "name"});
} }
if (any.isMap()) { // TODO if (type == "boolean") {
const std::map<QString, Dto::Any> anyMap = any.getMap(); if (!any.isBool())
auto value = anyMap.find("displayName"); return {};
if (value != anyMap.end()) if (options && options->size() == 2)
return anyToSimpleString(value->second); return any.getBool() ? options->at(1).key : options->at(0).key;
value = anyMap.find("name"); return any.getBool() ? QString("true") : QString("false");
if (value != anyMap.end())
return anyToSimpleString(value->second);
value = anyMap.find("tag");
if (value != anyMap.end())
return anyToSimpleString(value->second);
} }
QTC_ASSERT(false, qDebug() << "unhandled" << type);
return {}; return {};
} }

View File

@@ -119,7 +119,8 @@ std::optional<Dto::NamedFilterInfoDto> namedFilterInfoForKey(const QString &key,
bool handleCertificateIssue(); bool handleCertificateIssue();
QIcon iconForIssue(const std::optional<Dto::IssueKind> &issueKind); QIcon iconForIssue(const std::optional<Dto::IssueKind> &issueKind);
QString anyToSimpleString(const Dto::Any &any); QString anyToSimpleString(const Dto::Any &any, const QString &type,
const std::optional<std::vector<Dto::ColumnTypeOptionDto>> &options);
void fetchIssueInfo(const QString &id); void fetchIssueInfo(const QString &id);
void switchActiveDashboardId(const Utils::Id &toDashboardId); void switchActiveDashboardId(const Utils::Id &toDashboardId);