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) {
const auto it = row.find(column.key);
if (it != row.end()) {
QString value = anyToSimpleString(it->second);
QString value = anyToSimpleString(it->second, column.type, column.typeOptions);
if (column.key == "id") {
value.prepend(m_currentPrefix);
id = 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;
}
}

View File

@@ -74,41 +74,82 @@ QIcon iconForIssue(const std::optional<Dto::IssueKind> &issueKind)
return prefixToIcon.insert(*issueKind, icon.icon()).value();
}
QString anyToSimpleString(const Dto::Any &any)
static QString anyToString(const Dto::Any &any)
{
if (any.isString())
return any.getString();
if (any.isBool())
return QString("%1").arg(any.getBool());
if (any.isDouble()) {
const double value = any.getDouble();
double intPart;
const double fragPart = std::modf(value, &intPart);
if (fragPart != 0)
return QString::number(value);
return QString::number(value, 'f', 0);
if (any.isNull() || !any.isString())
return {};
return any.getString();
}
static QString anyToPathString(const Dto::Any &any)
{
const QString pathStr = anyToString(any);
if (pathStr.isEmpty())
return {};
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())
return QString(); // or NULL??
if (any.isList()) {
const std::vector<Dto::Any> anyList = any.getList();
QStringList list;
for (const Dto::Any &inner : anyList)
list << anyToSimpleString(inner);
return list.join(',');
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 (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);
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 {};
}

View File

@@ -119,7 +119,8 @@ std::optional<Dto::NamedFilterInfoDto> namedFilterInfoForKey(const QString &key,
bool handleCertificateIssue();
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 switchActiveDashboardId(const Utils::Id &toDashboardId);