Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mon_gui] Change font for new topics in mon_gui #1879

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ void TopicWidget::autoSizeColumns()
ui_.tree_view->resizeColumnToContents(column);
}


topic_tree_model_->removeItem(example_topic_item);
topic_tree_model_->removeItem(example_group_item);

Expand Down
39 changes: 8 additions & 31 deletions app/mon/mon_gui/src/widgets/models/topic_tree_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include "topic_tree_item.h"

#include <QColor>
#include <QFont>
#include <QString>
#include <QByteArray>
Expand All @@ -42,6 +41,7 @@ QVariant TopicTreeItem::data(int column, Qt::ItemDataRole role) const

QVariant TopicTreeItem::data(Columns column, Qt::ItemDataRole role) const
{

if (role == (Qt::ItemDataRole)ItemDataRoles::RawDataRole) //-V1016 //-V547
{
if (column == Columns::RCLOCK)
Expand Down Expand Up @@ -297,41 +297,18 @@ QVariant TopicTreeItem::data(Columns column, Qt::ItemDataRole role) const

else if (role == Qt::ItemDataRole::FontRole)
{

if ((column == Columns::HNAME)
|| (column == Columns::HGNAME)
|| (column == Columns::PNAME)
|| (column == Columns::UNAME)
|| (column == Columns::TNAME)
|| (column == Columns::DIRECTION)
|| (column == Columns::TENCODING)
|| (column == Columns::TTYPE))
{
const QString raw_data = data(column, (Qt::ItemDataRole)ItemDataRoles::RawDataRole).toString(); //-V1016
if (raw_data.isEmpty())
{
QFont font;
font.setItalic(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe don't remove the logic completely. Instead set set and unset the member font varible and return it here.

return font;
}
}
else if (column == Columns::TDESC)
{
const std::string& raw_data = topic_.tdatatype().desc();
if (raw_data.empty())
{
QFont font;
font.setItalic(true);
return font;
}
}

return QVariant(); // Invalid QVariant
return itemfont;
}

return QVariant(); // Invalid QVariant
}

bool TopicTreeItem::setFont(const QFont& font)
{
itemfont = font;
return false;
}

int TopicTreeItem::type() const
{
return (int)TreeItemType::Topic;
Expand Down
8 changes: 5 additions & 3 deletions app/mon/mon_gui/src/widgets/models/topic_tree_item.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@
#pragma once

#include "CustomQt/QAbstractTreeItem.h"
#include <QFont>

#ifdef _MSC_VER
#pragma warning(push)
Expand Down Expand Up @@ -67,6 +68,8 @@ class TopicTreeItem :

QVariant data(Columns column, Qt::ItemDataRole role = Qt::ItemDataRole::DisplayRole) const;

bool setFont(const QFont& font);

int type() const;

void update(const eCAL::pb::Topic& topic);
Expand All @@ -77,7 +80,6 @@ class TopicTreeItem :

private:
eCAL::pb::Topic topic_;

QFont itemfont;
static QString toFrequencyString(long long freq);
};

43 changes: 34 additions & 9 deletions app/mon/mon_gui/src/widgets/models/topic_tree_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* ========================= eCAL LICENSE =================================
*/

#include <QFont>

#include "topic_tree_model.h"
#include "tree_item_type.h"
#include "item_data_roles.h"
Expand Down Expand Up @@ -49,7 +51,6 @@ QVariant TopicTreeModel::headerData(int section, Qt::Orientation orientation, in
return QAbstractTreeModel::headerData(section, orientation, role);
}


int TopicTreeModel::mapColumnToItem(int model_column, int tree_item_type) const
{
switch ((TreeItemType)tree_item_type)
Expand All @@ -70,7 +71,7 @@ void TopicTreeModel::monitorUpdated(const eCAL::pb::Monitoring& monitoring_pb)
{
// Create a list of all topics to check if we have to remove them
std::map<std::string, bool> topic_still_existing;
for(const auto& topic : topic_tree_item_map_)
for (const auto& topic : topic_tree_item_map_)
{
topic_still_existing[topic.first] = false;
}
Expand All @@ -84,12 +85,35 @@ void TopicTreeModel::monitorUpdated(const eCAL::pb::Monitoring& monitoring_pb)
// Got a new topic
TopicTreeItem* topic_tree_item = new TopicTreeItem(topic);
insertItemIntoGroups(topic_tree_item);
topic_tree_item_map_[topic_id] = topic_tree_item;
STopicTreeEntry tree_entry;
tree_entry.tree_item = topic_tree_item;
topic_tree_item_map_[topic_id] = tree_entry;
auto fontrole = topic_tree_item->data(1, Qt::ItemDataRole::FontRole);
auto font = qvariant_cast<QFont>(fontrole);
font.setBold(true);
topic_tree_item->setFont(font);
}
else
{
auto& tree_entry = topic_tree_item_map_.at(topic_id);
auto topic_tree_item = tree_entry.tree_item;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'auto topic_tree_item' can be declared as 'auto *topic_tree_item' [readability-qualified-auto]

Suggested change
auto topic_tree_item = tree_entry.tree_item;
auto *topic_tree_item = tree_entry.tree_item;

if (tree_entry.tree_item_counter < 20)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of item counter, you could make it independend of the calls with a time, as the user can specify how fast the monitoring app updates the content.

{
tree_entry.tree_item_counter++;
}
else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These statements can get united together.

{
if (!tree_entry.default_font)
{
auto fontrole = topic_tree_item->data(1, Qt::ItemDataRole::FontRole);
auto font = qvariant_cast<QFont>(fontrole);
font.setBold(false);
topic_tree_item->setFont(font);
tree_entry.default_font = true;
}
}
// Update an existing topic
topic_tree_item_map_.at(topic_id)->update(topic);
topic_tree_item->update(topic);
topic_still_existing[topic_id] = true;
}
}
Expand All @@ -99,25 +123,26 @@ void TopicTreeModel::monitorUpdated(const eCAL::pb::Monitoring& monitoring_pb)
{
if (!topic.second)
{
removeItemFromGroups(topic_tree_item_map_.at(topic.first));
removeItemFromGroups(topic_tree_item_map_.at(topic.first).tree_item);
topic_tree_item_map_.erase(topic.first);
}
}

updateAll();
}

QVector<QPair<int, QString>> TopicTreeModel::getTreeItemColumnNameMapping() const

QVector<QPair<int, QVariant>> TopicTreeModel::getTreeItemColumnNameMapping() const
{
QVector<QPair<int, QString>> column_name_mapping;
QVector<QPair<int, QVariant>> column_name_mapping;

for (int i = 0; i < columnCount(); i++)
{
int column = mapColumnToItem(i, (int)TreeItemType::Topic);
if (column >= 0)
{
QString name = headerData(i, Qt::Orientation::Horizontal, Qt::ItemDataRole::DisplayRole).toString();
column_name_mapping.push_back(QPair<int, QString>(column, name));
QVariant name = headerData(i, Qt::Orientation::Horizontal, Qt::ItemDataRole::DisplayRole);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'name' of type 'QVariant' can be declared 'const' [misc-const-correctness]

Suggested change
QVariant name = headerData(i, Qt::Orientation::Horizontal, Qt::ItemDataRole::DisplayRole);
QVariant const name = headerData(i, Qt::Orientation::Horizontal, Qt::ItemDataRole::DisplayRole);

column_name_mapping.push_back(QPair<int, QVariant>(column, name));
}
}

Expand Down
10 changes: 8 additions & 2 deletions app/mon/mon_gui/src/widgets/models/topic_tree_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class TopicTreeModel : public GroupTreeModel

QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;

QVector<QPair<int, QString>> getTreeItemColumnNameMapping() const;
QVector<QPair<int, QVariant>> getTreeItemColumnNameMapping() const;

void monitorUpdated(const eCAL::pb::Monitoring& monitoring_pb) override;

Expand Down Expand Up @@ -133,5 +133,11 @@ class TopicTreeModel : public GroupTreeModel
{ Columns::DATA_FREQUENCY, (int)TopicTreeItem::Columns::DFREQ },
};

std::map<std::string, TopicTreeItem*> topic_tree_item_map_;
struct STopicTreeEntry
{
TopicTreeItem* tree_item = nullptr;
int tree_item_counter = 0;
bool default_font = false;
};
std::map<std::string, STopicTreeEntry> topic_tree_item_map_;
};
Loading