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 {};
return any.getString(); return any.getString();
if (any.isBool()) }
return QString("%1").arg(any.getBool());
if (any.isDouble()) { static QString anyToPathString(const Dto::Any &any)
const double value = any.getDouble(); {
double intPart; const QString pathStr = anyToString(any);
const double fragPart = std::modf(value, &intPart); if (pathStr.isEmpty())
if (fragPart != 0) return {};
return QString::number(value); const FilePath fp = FilePath::fromUserInput(pathStr);
return QString::number(value, 'f', 0); return fp.contains("/") ? QString("%1 [%2]").arg(fp.fileName(), fp.path()) : fp.fileName();
} }
if (any.isNull())
return QString(); // or NULL?? // only the first found innerKey is used to add its value to the list
if (any.isList()) { static QString anyListOfMapToString(const Dto::Any &any, const QStringList &innerKeys)
{
if (any.isNull() || !any.isList())
return {};
const std::vector<Dto::Any> anyList = any.getList(); const std::vector<Dto::Any> anyList = any.getList();
QStringList list; QStringList list;
for (const Dto::Any &inner : anyList) for (const Dto::Any &inner : anyList) {
list << anyToSimpleString(inner); if (!inner.isMap())
return list.join(','); 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;
} }
if (any.isMap()) { // TODO
const std::map<QString, Dto::Any> anyMap = any.getMap();
auto value = anyMap.find("displayName");
if (value != anyMap.end())
return anyToSimpleString(value->second);
value = anyMap.find("name");
if (value != anyMap.end())
return anyToSimpleString(value->second);
value = anyMap.find("tag");
if (value != anyMap.end())
return anyToSimpleString(value->second);
} }
return list.join(", ");
}
static QString anyToNumberString(const Dto::Any &any)
{
if (any.isNull())
return {};
if (any.isString()) // handle Infinity/NaN/...
return any.getString();
const double value = any.getDouble();
double intPart;
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 (type == "boolean") {
if (!any.isBool())
return {};
if (options && options->size() == 2)
return any.getBool() ? options->at(1).key : options->at(0).key;
return any.getBool() ? QString("true") : QString("false");
}
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);