Skip to content

Commit

Permalink
Make typeID, name and description private so they can not be changed …
Browse files Browse the repository at this point in the history
…after creation of the StatisticsType
  • Loading branch information
ChristianFeldmann committed Feb 10, 2025
1 parent 665c6ba commit baa834d
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 72 deletions.
12 changes: 6 additions & 6 deletions YUViewLib/src/statistics/StatisticUIHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ QLayout *StatisticUIHandler::createStatisticsHandlerControls(bool recreateContro

// Append the name (with the check box to enable/disable the statistics item)
QCheckBox *itemNameCheck =
new QCheckBox(QString::fromStdString(statType.typeName), ui.scrollAreaWidgetContents);
new QCheckBox(QString::fromStdString(statType.getTypeName()), ui.scrollAreaWidgetContents);
itemNameCheck->setChecked(statType.render);
itemNameCheck->setToolTip(QString::fromStdString(statType.description));
itemNameCheck->setToolTip(QString::fromStdString(statType.getDescription()));
ui.gridLayout->addWidget(itemNameCheck, int(row + 2), 0);
connect(itemNameCheck,
&QCheckBox::stateChanged,
Expand Down Expand Up @@ -159,8 +159,8 @@ QWidget *StatisticUIHandler::getSecondaryStatisticsHandlerControls(bool recreate
auto &statType = statTypes.at(row);

// Append the name (with the check box to enable/disable the statistics item)
QCheckBox *itemNameCheck =
new QCheckBox(QString::fromStdString(statType.typeName), ui2.scrollAreaWidgetContents);
QCheckBox *itemNameCheck = new QCheckBox(QString::fromStdString(statType.getTypeName()),
ui2.scrollAreaWidgetContents);
itemNameCheck->setChecked(statType.render);
ui2.gridLayout->addWidget(itemNameCheck, int(row + 2), 0);
connect(itemNameCheck,
Expand Down Expand Up @@ -335,7 +335,7 @@ void StatisticUIHandler::updateStatisticsHandlerControls()
{
for (unsigned row = 0; row < statTypes.size(); row++)
{
if (itemNameCheckBoxes[0][row]->text().toStdString() != statTypes[row].typeName)
if (itemNameCheckBoxes[0][row]->text().toStdString() != statTypes[row].getTypeName())
{
// One of the statistics types changed it's name or the order of statistics types changed.
// Either way, we will create new controls.
Expand Down Expand Up @@ -411,7 +411,7 @@ void StatisticUIHandler::updateStatisticsHandlerControls()
{
for (unsigned j = 0; j < statTypes.size(); j++)
{
if (statsTypeListBackup[i].typeName == statTypes[j].typeName)
if (statsTypeListBackup[i].getTypeName() == statTypes[j].getTypeName())
{
// In the new list of statistics types we found one that has the same name as this one.
// This is enough indication. Apply the old settings to this new type.
Expand Down
62 changes: 23 additions & 39 deletions YUViewLib/src/statistics/StatisticsData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ ItemLoadingState StatisticsData::needsLoading(int frameIndex) const
{
// If the statistics for this frame index were not loaded yet but will be rendered, load them
// now.
if (it->render && this->frameCache.count(it->typeID) == 0)
if (it->render && this->frameCache.count(it->getTypeID()) == 0)
{
// Return that loading is needed before we can render the statitics.
DEBUG_STATDATA("StatisticsData::needsLoading type " << it->typeID << " LoadingNeeded");
DEBUG_STATDATA("StatisticsData::needsLoading type " << it->getTypeID() << " LoadingNeeded");
return ItemLoadingState::LoadingNeeded;
}
}
Expand All @@ -184,8 +184,8 @@ std::vector<int> StatisticsData::getTypesThatNeedLoading(int frameIndex) const
auto loadAll = this->frameIdx != frameIndex;
for (const auto &statsType : this->statsTypes)
{
if (statsType.render && (loadAll || this->frameCache.count(statsType.typeID) == 0))
typesToLoad.push_back(statsType.typeID);
if (statsType.render && (loadAll || this->frameCache.count(statsType.getTypeID()) == 0))
typesToLoad.push_back(statsType.getTypeID());
}

DEBUG_STATDATA("StatisticsData::getTypesThatNeedLoading "
Expand All @@ -204,13 +204,13 @@ QStringPairList StatisticsData::getValuesAt(const QPoint &pos) const

for (auto it = this->statsTypes.rbegin(); it != this->statsTypes.rend(); it++)
{
if (it->typeID == INT_INVALID || this->frameCache.count(it->typeID) == 0)
if (it->getTypeID() == INT_INVALID || this->frameCache.count(it->getTypeID()) == 0)
// no active statistics data
continue;

// Get all value data entries
bool foundStats = false;
for (const auto &valueItem : this->frameCache.at(it->typeID).valueData)
for (const auto &valueItem : this->frameCache.at(it->getTypeID()).valueData)
{
auto rect = QRect(valueItem.pos[0], valueItem.pos[1], valueItem.size[0], valueItem.size[1]);
if (rect.contains(pos))
Expand All @@ -221,12 +221,12 @@ QStringPairList StatisticsData::getValuesAt(const QPoint &pos) const
valTxt = std::to_string(float(value) / (valueItem.size[0] * valueItem.size[1]));

valueList.append(
QStringPair(QString::fromStdString(it->typeName), QString::fromStdString(valTxt)));
QStringPair(QString::fromStdString(it->getTypeName()), QString::fromStdString(valTxt)));
foundStats = true;
}
}

for (const auto &vectorItem : this->frameCache.at(it->typeID).vectorData)
for (const auto &vectorItem : this->frameCache.at(it->getTypeID()).vectorData)
{
auto rect =
QRect(vectorItem.pos[0], vectorItem.pos[1], vectorItem.size[0], vectorItem.size[1]);
Expand All @@ -245,13 +245,13 @@ QStringPairList StatisticsData::getValuesAt(const QPoint &pos) const
x = double(vectorItem.point[0].x) / scale;
y = double(vectorItem.point[0].y) / scale;
}
valueList.append(QStringPair(QString("%1").arg(QString::fromStdString(it->typeName)),
valueList.append(QStringPair(QString("%1").arg(QString::fromStdString(it->getTypeName())),
QString("(%1,%2)").arg(x).arg(y)));
foundStats = true;
}
}

for (const auto &affineTFItem : this->frameCache.at(it->typeID).affineTFData)
for (const auto &affineTFItem : this->frameCache.at(it->getTypeID()).affineTFData)
{
const auto rect = QRect(
affineTFItem.pos[0], affineTFItem.pos[1], affineTFItem.size[0], affineTFItem.size[1]);
Expand All @@ -263,17 +263,17 @@ QStringPairList StatisticsData::getValuesAt(const QPoint &pos) const
auto xScaled = float(affineTFItem.point[i].x / scale);
auto yScaled = float(affineTFItem.point[i].y / scale);
valueList.append(
QStringPair(QString("%1_%2[x]").arg(QString::fromStdString(it->typeName)).arg(i),
QStringPair(QString("%1_%2[x]").arg(QString::fromStdString(it->getTypeName())).arg(i),
QString::number(xScaled)));
valueList.append(
QStringPair(QString("%1_%2[y]").arg(QString::fromStdString(it->typeName)).arg(i),
QStringPair(QString("%1_%2[y]").arg(QString::fromStdString(it->getTypeName())).arg(i),
QString::number(yScaled)));
}
foundStats = true;
}
}

for (const auto &valueItem : this->frameCache.at(it->typeID).polygonValueData)
for (const auto &valueItem : this->frameCache.at(it->getTypeID()).polygonValueData)
{
if (valueItem.corners.size() < 3)
continue; // need at least triangle -- or more corners
Expand All @@ -282,12 +282,12 @@ QStringPairList StatisticsData::getValuesAt(const QPoint &pos) const
int value = valueItem.value;
auto valTxt = it->getValueText(value);
valueList.append(
QStringPair(QString::fromStdString(it->typeName), QString::fromStdString(valTxt)));
QStringPair(QString::fromStdString(it->getTypeName()), QString::fromStdString(valTxt)));
foundStats = true;
}
}

for (const auto &polygonVectorItem : this->frameCache.at(it->typeID).polygonVectorData)
for (const auto &polygonVectorItem : this->frameCache.at(it->getTypeID()).polygonVectorData)
{
if (polygonVectorItem.corners.size() < 3)
continue; // need at least triangle -- or more corners
Expand All @@ -299,17 +299,19 @@ QStringPairList StatisticsData::getValuesAt(const QPoint &pos) const
const auto scale = it->vectorDataOptions->scale;
auto xScaled = (float)polygonVectorItem.point.x / scale;
auto yScaled = (float)polygonVectorItem.point.y / scale;
valueList.append(QStringPair(QString("%1[x]").arg(QString::fromStdString(it->typeName)),
QString::number(xScaled)));
valueList.append(QStringPair(QString("%1[y]").arg(QString::fromStdString(it->typeName)),
QString::number(yScaled)));
valueList.append(
QStringPair(QString("%1[x]").arg(QString::fromStdString(it->getTypeName())),
QString::number(xScaled)));
valueList.append(
QStringPair(QString("%1[y]").arg(QString::fromStdString(it->getTypeName())),
QString::number(yScaled)));
foundStats = true;
}
}
}

if (!foundStats)
valueList.append(QStringPair(QString::fromStdString(it->typeName), "-"));
valueList.append(QStringPair(QString::fromStdString(it->getTypeName()), "-"));
}

return valueList;
Expand Down Expand Up @@ -337,25 +339,7 @@ void StatisticsData::setFrameIndex(int frameIndex)

void StatisticsData::addStatType(const StatisticsType &type)
{
if (type.typeID == -1)
{
// stat source does not have type ids. need to auto assign an id for this type
// check if type not already in list
int maxTypeID = 0;
for (auto it = this->statsTypes.begin(); it != this->statsTypes.end(); it++)
{
if (it->typeName == type.typeName)
return;
if (it->typeID > maxTypeID)
maxTypeID = it->typeID;
}

auto newType = type;
newType.typeID = maxTypeID + 1;
this->statsTypes.push_back(newType);
}
else
this->statsTypes.push_back(type);
this->statsTypes.push_back(type);
}

void StatisticsData::savePlaylist(YUViewDomElement &root) const
Expand Down
22 changes: 11 additions & 11 deletions YUViewLib/src/statistics/StatisticsDataPainting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,10 @@ void stats::paintStatisticsData(QPainter *painter,

for (auto it = statsTypes.rbegin(); it != statsTypes.rend(); it++)
{
if (!it->render || !statisticsData.hasDataForTypeID(it->typeID))
if (!it->render || !statisticsData.hasDataForTypeID(it->getTypeID()))
continue;

for (const auto &valueItem : statisticsData[it->typeID].valueData)
for (const auto &valueItem : statisticsData[it->getTypeID()].valueData)
{
// Calculate the size and position of the rectangle to draw (zoomed in)
auto rect = QRect(valueItem.pos[0], valueItem.pos[1], valueItem.size[0], valueItem.size[1]);
Expand Down Expand Up @@ -380,7 +380,7 @@ void stats::paintStatisticsData(QPainter *painter,
if (valTxt.empty() && it->valueDataOptions && it->valueDataOptions->scaleToBlockSize)
valTxt = std::to_string(float(value) / (valueItem.size[0] * valueItem.size[1]));

auto typeTxt = it->typeName;
auto typeTxt = it->getTypeName();
auto statTxt = moreThanOneBlockStatRendered ? typeTxt + ":" + valTxt : valTxt;

int i = drawStatPoints.indexOf(displayRect.topLeft());
Expand All @@ -405,12 +405,12 @@ void stats::paintStatisticsData(QPainter *painter,
// drawn. This will be used as an offset.
for (auto it = statsTypes.rbegin(); it != statsTypes.rend(); it++)
{
if (!it->render || !statisticsData.hasDataForTypeID(it->typeID))
if (!it->render || !statisticsData.hasDataForTypeID(it->getTypeID()))
// This statistics type is not rendered or could not be loaded.
continue;

// Go through all the value data
for (const auto &valueItem : statisticsData[it->typeID].polygonValueData)
for (const auto &valueItem : statisticsData[it->getTypeID()].polygonValueData)
{
// Calculate the size and position of the rectangle to draw (zoomed in)
auto valuePoly = convertToQPolygon(valueItem.corners);
Expand Down Expand Up @@ -471,7 +471,7 @@ void stats::paintStatisticsData(QPainter *painter,
if (zoomFactor >= STATISTICS_DRAW_VALUES_ZOOM)
{
auto valTxt = it->getValueText(value);
auto typeTxt = it->typeName;
auto typeTxt = it->getTypeName();
auto statTxt = moreThanOneBlockStatRendered ? typeTxt + ":" + valTxt : valTxt;

int i = drawStatPoints.indexOf(getPolygonCenter(displayPolygon));
Expand Down Expand Up @@ -507,12 +507,12 @@ void stats::paintStatisticsData(QPainter *painter,
// Draw all the arrows
for (auto it = statsTypes.rbegin(); it != statsTypes.rend(); it++)
{
if (!it->render || !statisticsData.hasDataForTypeID(it->typeID))
if (!it->render || !statisticsData.hasDataForTypeID(it->getTypeID()))
// This statistics type is not rendered or could not be loaded.
continue;

// Go through all the vector data
for (const auto &vectorItem : statisticsData[it->typeID].vectorData)
for (const auto &vectorItem : statisticsData[it->getTypeID()].vectorData)
{
// Calculate the size and position of the rectangle to draw (zoomed in)
const auto rect =
Expand Down Expand Up @@ -722,7 +722,7 @@ void stats::paintStatisticsData(QPainter *painter,
}

// Go through all the affine transform data
for (const auto &affineTFItem : statisticsData[it->typeID].affineTFData)
for (const auto &affineTFItem : statisticsData[it->getTypeID()].affineTFData)
{
// Calculate the size and position of the rectangle to draw (zoomed in)
const auto rect = QRect(
Expand Down Expand Up @@ -831,12 +831,12 @@ void stats::paintStatisticsData(QPainter *painter,
// Draw all polygon vector data
for (auto it = statsTypes.rbegin(); it != statsTypes.rend(); it++)
{
if (!it->render || !statisticsData.hasDataForTypeID(it->typeID))
if (!it->render || !statisticsData.hasDataForTypeID(it->getTypeID()))
// This statistics type is not rendered or could not be loaded.
continue;

// Go through all the vector data
for (const auto &vectorItem : statisticsData[it->typeID].polygonVectorData)
for (const auto &vectorItem : statisticsData[it->getTypeID()].polygonVectorData)
{
if (vectorItem.corners.size() < 3)
continue; // need at least triangle -- or more corners
Expand Down
2 changes: 1 addition & 1 deletion YUViewLib/src/statistics/StatisticsFileCSV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ void StatisticsFileCSV::loadStatisticData(StatisticsData &statisticsData, int po
auto &statTypes = statisticsData.getStatisticsTypes();
auto statIt = std::find_if(statTypes.begin(),
statTypes.end(),
[type](StatisticsType &t) { return t.typeID == type; });
[type](StatisticsType &t) { return t.getTypeID() == type; });
Q_ASSERT_X(statIt != statTypes.end(), Q_FUNC_INFO, "Stat type not found.");

if (vectorData && statIt->vectorDataOptions)
Expand Down
10 changes: 7 additions & 3 deletions YUViewLib/src/statistics/StatisticsType.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ class StatisticsType
friend class StatisticsTypePlaylistHandler;

public:
int typeID{};
std::string typeName{};
std::string description{};
int getTypeID() const { return typeID; }
std::string getTypeName() const { return typeName; }
std::string getDescription() const { return description; }

std::string getValueText(const int val) const;

Expand Down Expand Up @@ -131,6 +131,10 @@ class StatisticsType
StatisticsType() = delete;
StatisticsType(int typeId, std::string typeName);

int typeID{};
std::string typeName{};
std::string description{};

std::map<int, std::string> valuesToText;

void saveInitialState();
Expand Down
2 changes: 1 addition & 1 deletion YUViewLib/src/ui/Statisticsstylecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void StatisticsStyleControl::setStatsItem(stats::StatisticsType *item)
DEBUG_STAT_STYLE("StatisticsStyleControl::setStatsItem %s", item->typeName.toStdString().c_str());
this->currentItem = item;
this->setWindowTitle("Edit statistics rendering: " +
QString::fromStdString(this->currentItem->typeName));
QString::fromStdString(this->currentItem->getTypeName()));

if (this->currentItem->valueDataOptions)
{
Expand Down
4 changes: 2 additions & 2 deletions YUViewUnitTest/statistics/StatisticsFileCSVTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ TEST(StatisticsFileCSV, testCSVFileParsing)
{
const auto &t = types[i];

EXPECT_EQ(t.typeID, typeIDs[i]);
EXPECT_EQ(t.typeName, typeNameNames[i]);
EXPECT_EQ(t.getTypeID(), typeIDs[i]);
EXPECT_EQ(t.getTypeName(), typeNameNames[i]);
if (t.vectorDataOptions)
{
EXPECT_EQ(t.vectorDataOptions->style->color.toHex(), vectorColors[i]);
Expand Down
12 changes: 6 additions & 6 deletions YUViewUnitTest/statistics/StatisticsTypeBuilderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ TEST(StatisticsTypeBuilderTest, DefaultValues)
{
const auto statisticsType = StatisticsTypeBuilder(0, "").build();

EXPECT_EQ(statisticsType.typeID, 0);
EXPECT_TRUE(statisticsType.typeName.empty());
EXPECT_TRUE(statisticsType.description.empty());
EXPECT_EQ(statisticsType.getTypeID(), 0);
EXPECT_TRUE(statisticsType.getTypeName().empty());
EXPECT_TRUE(statisticsType.getDescription().empty());
EXPECT_FALSE(statisticsType.render);
EXPECT_EQ(statisticsType.alphaFactor, 50);
EXPECT_FALSE(statisticsType.valueDataOptions);
Expand All @@ -61,9 +61,9 @@ TEST(StatisticsTypeBuilderTest, SetTypeNameDescriptionAndRenderValues)
.withAlphaFactor(75)
.build();

EXPECT_EQ(statisticsType.typeID, 1);
EXPECT_EQ(statisticsType.typeName, "TestType");
EXPECT_EQ(statisticsType.description, "TestDescription");
EXPECT_EQ(statisticsType.getTypeID(), 1);
EXPECT_EQ(statisticsType.getTypeName(), "TestType");
EXPECT_EQ(statisticsType.getDescription(), "TestDescription");
EXPECT_TRUE(statisticsType.render);
EXPECT_EQ(statisticsType.alphaFactor, 75);
}
Expand Down
6 changes: 3 additions & 3 deletions YUViewUnitTest/statistics/StatisticsTypeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ TEST(StatisticsTypeTest, DefaultConstructorValues)
{
const auto statisticsType = StatisticsTypeBuilder(0, "").build();

EXPECT_EQ(statisticsType.typeID, 0);
EXPECT_TRUE(statisticsType.typeName.empty());
EXPECT_TRUE(statisticsType.description.empty());
EXPECT_EQ(statisticsType.getTypeID(), 0);
EXPECT_TRUE(statisticsType.getTypeName().empty());
EXPECT_TRUE(statisticsType.getDescription().empty());
EXPECT_FALSE(statisticsType.render);
EXPECT_EQ(statisticsType.alphaFactor, 50);
EXPECT_FALSE(statisticsType.valueDataOptions);
Expand Down

0 comments on commit baa834d

Please sign in to comment.