Skip to content

Commit baa834d

Browse files
Make typeID, name and description private so they can not be changed after creation of the StatisticsType
1 parent 665c6ba commit baa834d

File tree

9 files changed

+60
-72
lines changed

9 files changed

+60
-72
lines changed

YUViewLib/src/statistics/StatisticUIHandler.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ QLayout *StatisticUIHandler::createStatisticsHandlerControls(bool recreateContro
9393

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

161161
// Append the name (with the check box to enable/disable the statistics item)
162-
QCheckBox *itemNameCheck =
163-
new QCheckBox(QString::fromStdString(statType.typeName), ui2.scrollAreaWidgetContents);
162+
QCheckBox *itemNameCheck = new QCheckBox(QString::fromStdString(statType.getTypeName()),
163+
ui2.scrollAreaWidgetContents);
164164
itemNameCheck->setChecked(statType.render);
165165
ui2.gridLayout->addWidget(itemNameCheck, int(row + 2), 0);
166166
connect(itemNameCheck,
@@ -335,7 +335,7 @@ void StatisticUIHandler::updateStatisticsHandlerControls()
335335
{
336336
for (unsigned row = 0; row < statTypes.size(); row++)
337337
{
338-
if (itemNameCheckBoxes[0][row]->text().toStdString() != statTypes[row].typeName)
338+
if (itemNameCheckBoxes[0][row]->text().toStdString() != statTypes[row].getTypeName())
339339
{
340340
// One of the statistics types changed it's name or the order of statistics types changed.
341341
// Either way, we will create new controls.
@@ -411,7 +411,7 @@ void StatisticUIHandler::updateStatisticsHandlerControls()
411411
{
412412
for (unsigned j = 0; j < statTypes.size(); j++)
413413
{
414-
if (statsTypeListBackup[i].typeName == statTypes[j].typeName)
414+
if (statsTypeListBackup[i].getTypeName() == statTypes[j].getTypeName())
415415
{
416416
// In the new list of statistics types we found one that has the same name as this one.
417417
// This is enough indication. Apply the old settings to this new type.

YUViewLib/src/statistics/StatisticsData.cpp

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ ItemLoadingState StatisticsData::needsLoading(int frameIndex) const
165165
{
166166
// If the statistics for this frame index were not loaded yet but will be rendered, load them
167167
// now.
168-
if (it->render && this->frameCache.count(it->typeID) == 0)
168+
if (it->render && this->frameCache.count(it->getTypeID()) == 0)
169169
{
170170
// Return that loading is needed before we can render the statitics.
171-
DEBUG_STATDATA("StatisticsData::needsLoading type " << it->typeID << " LoadingNeeded");
171+
DEBUG_STATDATA("StatisticsData::needsLoading type " << it->getTypeID() << " LoadingNeeded");
172172
return ItemLoadingState::LoadingNeeded;
173173
}
174174
}
@@ -184,8 +184,8 @@ std::vector<int> StatisticsData::getTypesThatNeedLoading(int frameIndex) const
184184
auto loadAll = this->frameIdx != frameIndex;
185185
for (const auto &statsType : this->statsTypes)
186186
{
187-
if (statsType.render && (loadAll || this->frameCache.count(statsType.typeID) == 0))
188-
typesToLoad.push_back(statsType.typeID);
187+
if (statsType.render && (loadAll || this->frameCache.count(statsType.getTypeID()) == 0))
188+
typesToLoad.push_back(statsType.getTypeID());
189189
}
190190

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

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

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

223223
valueList.append(
224-
QStringPair(QString::fromStdString(it->typeName), QString::fromStdString(valTxt)));
224+
QStringPair(QString::fromStdString(it->getTypeName()), QString::fromStdString(valTxt)));
225225
foundStats = true;
226226
}
227227
}
228228

229-
for (const auto &vectorItem : this->frameCache.at(it->typeID).vectorData)
229+
for (const auto &vectorItem : this->frameCache.at(it->getTypeID()).vectorData)
230230
{
231231
auto rect =
232232
QRect(vectorItem.pos[0], vectorItem.pos[1], vectorItem.size[0], vectorItem.size[1]);
@@ -245,13 +245,13 @@ QStringPairList StatisticsData::getValuesAt(const QPoint &pos) const
245245
x = double(vectorItem.point[0].x) / scale;
246246
y = double(vectorItem.point[0].y) / scale;
247247
}
248-
valueList.append(QStringPair(QString("%1").arg(QString::fromStdString(it->typeName)),
248+
valueList.append(QStringPair(QString("%1").arg(QString::fromStdString(it->getTypeName())),
249249
QString("(%1,%2)").arg(x).arg(y)));
250250
foundStats = true;
251251
}
252252
}
253253

254-
for (const auto &affineTFItem : this->frameCache.at(it->typeID).affineTFData)
254+
for (const auto &affineTFItem : this->frameCache.at(it->getTypeID()).affineTFData)
255255
{
256256
const auto rect = QRect(
257257
affineTFItem.pos[0], affineTFItem.pos[1], affineTFItem.size[0], affineTFItem.size[1]);
@@ -263,17 +263,17 @@ QStringPairList StatisticsData::getValuesAt(const QPoint &pos) const
263263
auto xScaled = float(affineTFItem.point[i].x / scale);
264264
auto yScaled = float(affineTFItem.point[i].y / scale);
265265
valueList.append(
266-
QStringPair(QString("%1_%2[x]").arg(QString::fromStdString(it->typeName)).arg(i),
266+
QStringPair(QString("%1_%2[x]").arg(QString::fromStdString(it->getTypeName())).arg(i),
267267
QString::number(xScaled)));
268268
valueList.append(
269-
QStringPair(QString("%1_%2[y]").arg(QString::fromStdString(it->typeName)).arg(i),
269+
QStringPair(QString("%1_%2[y]").arg(QString::fromStdString(it->getTypeName())).arg(i),
270270
QString::number(yScaled)));
271271
}
272272
foundStats = true;
273273
}
274274
}
275275

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

290-
for (const auto &polygonVectorItem : this->frameCache.at(it->typeID).polygonVectorData)
290+
for (const auto &polygonVectorItem : this->frameCache.at(it->getTypeID()).polygonVectorData)
291291
{
292292
if (polygonVectorItem.corners.size() < 3)
293293
continue; // need at least triangle -- or more corners
@@ -299,17 +299,19 @@ QStringPairList StatisticsData::getValuesAt(const QPoint &pos) const
299299
const auto scale = it->vectorDataOptions->scale;
300300
auto xScaled = (float)polygonVectorItem.point.x / scale;
301301
auto yScaled = (float)polygonVectorItem.point.y / scale;
302-
valueList.append(QStringPair(QString("%1[x]").arg(QString::fromStdString(it->typeName)),
303-
QString::number(xScaled)));
304-
valueList.append(QStringPair(QString("%1[y]").arg(QString::fromStdString(it->typeName)),
305-
QString::number(yScaled)));
302+
valueList.append(
303+
QStringPair(QString("%1[x]").arg(QString::fromStdString(it->getTypeName())),
304+
QString::number(xScaled)));
305+
valueList.append(
306+
QStringPair(QString("%1[y]").arg(QString::fromStdString(it->getTypeName())),
307+
QString::number(yScaled)));
306308
foundStats = true;
307309
}
308310
}
309311
}
310312

311313
if (!foundStats)
312-
valueList.append(QStringPair(QString::fromStdString(it->typeName), "-"));
314+
valueList.append(QStringPair(QString::fromStdString(it->getTypeName()), "-"));
313315
}
314316

315317
return valueList;
@@ -337,25 +339,7 @@ void StatisticsData::setFrameIndex(int frameIndex)
337339

338340
void StatisticsData::addStatType(const StatisticsType &type)
339341
{
340-
if (type.typeID == -1)
341-
{
342-
// stat source does not have type ids. need to auto assign an id for this type
343-
// check if type not already in list
344-
int maxTypeID = 0;
345-
for (auto it = this->statsTypes.begin(); it != this->statsTypes.end(); it++)
346-
{
347-
if (it->typeName == type.typeName)
348-
return;
349-
if (it->typeID > maxTypeID)
350-
maxTypeID = it->typeID;
351-
}
352-
353-
auto newType = type;
354-
newType.typeID = maxTypeID + 1;
355-
this->statsTypes.push_back(newType);
356-
}
357-
else
358-
this->statsTypes.push_back(type);
342+
this->statsTypes.push_back(type);
359343
}
360344

361345
void StatisticsData::savePlaylist(YUViewDomElement &root) const

YUViewLib/src/statistics/StatisticsDataPainting.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,10 @@ void stats::paintStatisticsData(QPainter *painter,
320320

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

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

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

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

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

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

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

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

838838
// Go through all the vector data
839-
for (const auto &vectorItem : statisticsData[it->typeID].polygonVectorData)
839+
for (const auto &vectorItem : statisticsData[it->getTypeID()].polygonVectorData)
840840
{
841841
if (vectorItem.corners.size() < 3)
842842
continue; // need at least triangle -- or more corners

YUViewLib/src/statistics/StatisticsFileCSV.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ void StatisticsFileCSV::loadStatisticData(StatisticsData &statisticsData, int po
319319
auto &statTypes = statisticsData.getStatisticsTypes();
320320
auto statIt = std::find_if(statTypes.begin(),
321321
statTypes.end(),
322-
[type](StatisticsType &t) { return t.typeID == type; });
322+
[type](StatisticsType &t) { return t.getTypeID() == type; });
323323
Q_ASSERT_X(statIt != statTypes.end(), Q_FUNC_INFO, "Stat type not found.");
324324

325325
if (vectorData && statIt->vectorDataOptions)

YUViewLib/src/statistics/StatisticsType.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ class StatisticsType
7171
friend class StatisticsTypePlaylistHandler;
7272

7373
public:
74-
int typeID{};
75-
std::string typeName{};
76-
std::string description{};
74+
int getTypeID() const { return typeID; }
75+
std::string getTypeName() const { return typeName; }
76+
std::string getDescription() const { return description; }
7777

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

@@ -131,6 +131,10 @@ class StatisticsType
131131
StatisticsType() = delete;
132132
StatisticsType(int typeId, std::string typeName);
133133

134+
int typeID{};
135+
std::string typeName{};
136+
std::string description{};
137+
134138
std::map<int, std::string> valuesToText;
135139

136140
void saveInitialState();

YUViewLib/src/ui/Statisticsstylecontrol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void StatisticsStyleControl::setStatsItem(stats::StatisticsType *item)
8787
DEBUG_STAT_STYLE("StatisticsStyleControl::setStatsItem %s", item->typeName.toStdString().c_str());
8888
this->currentItem = item;
8989
this->setWindowTitle("Edit statistics rendering: " +
90-
QString::fromStdString(this->currentItem->typeName));
90+
QString::fromStdString(this->currentItem->getTypeName()));
9191

9292
if (this->currentItem->valueDataOptions)
9393
{

YUViewUnitTest/statistics/StatisticsFileCSVTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ TEST(StatisticsFileCSV, testCSVFileParsing)
200200
{
201201
const auto &t = types[i];
202202

203-
EXPECT_EQ(t.typeID, typeIDs[i]);
204-
EXPECT_EQ(t.typeName, typeNameNames[i]);
203+
EXPECT_EQ(t.getTypeID(), typeIDs[i]);
204+
EXPECT_EQ(t.getTypeName(), typeNameNames[i]);
205205
if (t.vectorDataOptions)
206206
{
207207
EXPECT_EQ(t.vectorDataOptions->style->color.toHex(), vectorColors[i]);

YUViewUnitTest/statistics/StatisticsTypeBuilderTest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ TEST(StatisticsTypeBuilderTest, DefaultValues)
4141
{
4242
const auto statisticsType = StatisticsTypeBuilder(0, "").build();
4343

44-
EXPECT_EQ(statisticsType.typeID, 0);
45-
EXPECT_TRUE(statisticsType.typeName.empty());
46-
EXPECT_TRUE(statisticsType.description.empty());
44+
EXPECT_EQ(statisticsType.getTypeID(), 0);
45+
EXPECT_TRUE(statisticsType.getTypeName().empty());
46+
EXPECT_TRUE(statisticsType.getDescription().empty());
4747
EXPECT_FALSE(statisticsType.render);
4848
EXPECT_EQ(statisticsType.alphaFactor, 50);
4949
EXPECT_FALSE(statisticsType.valueDataOptions);
@@ -61,9 +61,9 @@ TEST(StatisticsTypeBuilderTest, SetTypeNameDescriptionAndRenderValues)
6161
.withAlphaFactor(75)
6262
.build();
6363

64-
EXPECT_EQ(statisticsType.typeID, 1);
65-
EXPECT_EQ(statisticsType.typeName, "TestType");
66-
EXPECT_EQ(statisticsType.description, "TestDescription");
64+
EXPECT_EQ(statisticsType.getTypeID(), 1);
65+
EXPECT_EQ(statisticsType.getTypeName(), "TestType");
66+
EXPECT_EQ(statisticsType.getDescription(), "TestDescription");
6767
EXPECT_TRUE(statisticsType.render);
6868
EXPECT_EQ(statisticsType.alphaFactor, 75);
6969
}

YUViewUnitTest/statistics/StatisticsTypeTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ TEST(StatisticsTypeTest, DefaultConstructorValues)
4141
{
4242
const auto statisticsType = StatisticsTypeBuilder(0, "").build();
4343

44-
EXPECT_EQ(statisticsType.typeID, 0);
45-
EXPECT_TRUE(statisticsType.typeName.empty());
46-
EXPECT_TRUE(statisticsType.description.empty());
44+
EXPECT_EQ(statisticsType.getTypeID(), 0);
45+
EXPECT_TRUE(statisticsType.getTypeName().empty());
46+
EXPECT_TRUE(statisticsType.getDescription().empty());
4747
EXPECT_FALSE(statisticsType.render);
4848
EXPECT_EQ(statisticsType.alphaFactor, 50);
4949
EXPECT_FALSE(statisticsType.valueDataOptions);

0 commit comments

Comments
 (0)