Skip to content

Commit

Permalink
Move grid options to modified handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianFeldmann committed Feb 2, 2025
1 parent 9315f47 commit ec89168
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 44 deletions.
24 changes: 12 additions & 12 deletions YUViewLib/src/statistics/StatisticsDataPainting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ QPoint getPolygonCenter(const QPolygon &polygon)
return p;
}

Qt::PenStyle patternToQPenStyle(stats::Pattern &pattern)
Qt::PenStyle patternToQPenStyle(const stats::Pattern &pattern)
{
if (pattern == stats::Pattern::Solid)
return Qt::SolidLine;
Expand All @@ -87,7 +87,7 @@ Qt::PenStyle patternToQPenStyle(stats::Pattern &pattern)
return Qt::SolidLine;
}

QPen styleToPen(stats::LineDrawStyle &style)
QPen styleToPen(const stats::LineDrawStyle &style)
{
return QPen(functionsGui::toQColor(style.color), style.width, patternToQPenStyle(style.pattern));
}
Expand Down Expand Up @@ -361,14 +361,14 @@ void stats::paintStatisticsData(QPainter *painter,
// Set the grid color (no fill)
auto gridStyle = it->gridOptions.style;
if (it->gridOptions.scaleToZoom)
gridStyle.width = gridStyle.width * zoomFactor;
gridStyle->width = gridStyle->width * zoomFactor;

painter->setPen(styleToPen(gridStyle));
painter->setPen(styleToPen(*gridStyle));
painter->setBrush(QBrush(QColor(Qt::color0), Qt::NoBrush)); // no fill color

// Save the line width (if thicker)
if (gridStyle.width > maxLineWidth)
maxLineWidth = gridStyle.width;
if (gridStyle->width > maxLineWidth)
maxLineWidth = gridStyle->width;

painter->drawRect(displayRect);
}
Expand Down Expand Up @@ -454,14 +454,14 @@ void stats::paintStatisticsData(QPainter *painter,
// Set the grid color (no fill)
auto gridStyle = it->gridOptions.style;
if (it->gridOptions.scaleToZoom)
gridStyle.width = gridStyle.width * zoomFactor;
gridStyle->width = gridStyle->width * zoomFactor;

painter->setPen(styleToPen(gridStyle));
painter->setBrush(QBrush(QColor(Qt::color0), Qt::NoBrush)); // no fill color

// Save the line width (if thicker)
if (gridStyle.width > maxLineWidth)
maxLineWidth = gridStyle.width;
if (gridStyle->width > maxLineWidth)
maxLineWidth = gridStyle->width;

painter->drawPolygon(displayPolygon);
}
Expand Down Expand Up @@ -711,7 +711,7 @@ void stats::paintStatisticsData(QPainter *painter,
{
auto gridStyle = it->gridOptions.style;
if (it->gridOptions.scaleToZoom)
gridStyle.width = gridStyle.width * zoomFactor;
gridStyle->width = gridStyle->width * zoomFactor;

painter->setPen(styleToPen(gridStyle));
painter->setBrush(QBrush(QColor(Qt::color0), Qt::NoBrush)); // no fill color
Expand Down Expand Up @@ -818,7 +818,7 @@ void stats::paintStatisticsData(QPainter *painter,
{
auto gridStyle = it->gridOptions.style;
if (it->gridOptions.scaleToZoom)
gridStyle.width = gridStyle.width * zoomFactor;
gridStyle->width = gridStyle->width * zoomFactor;

painter->setPen(styleToPen(gridStyle));
painter->setBrush(QBrush(QColor(Qt::color0), Qt::NoBrush)); // no fill color
Expand Down Expand Up @@ -991,7 +991,7 @@ void stats::paintStatisticsData(QPainter *painter,
{
auto gridStyle = it->gridOptions.style;
if (it->gridOptions.scaleToZoom)
gridStyle.width = gridStyle.width * zoomFactor;
gridStyle->width = gridStyle->width * zoomFactor;

painter->setPen(styleToPen(gridStyle));
painter->setBrush(QBrush(QColor(Qt::color0), Qt::NoBrush)); // no fill color
Expand Down
10 changes: 5 additions & 5 deletions YUViewLib/src/statistics/StatisticsFileCSV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,11 @@ void StatisticsFileCSV::readHeaderFromFile(StatisticsData &statisticsData)
}
else if (rowItemList[1] == "gridColor")
{
auto r = (unsigned char)rowItemList[2].toInt();
auto g = (unsigned char)rowItemList[3].toInt();
auto b = (unsigned char)rowItemList[4].toInt();
auto a = 255;
type->gridOptions.style.color = Color(r, g, b, a);
auto r = (unsigned char)rowItemList[2].toInt();
auto g = (unsigned char)rowItemList[3].toInt();
auto b = (unsigned char)rowItemList[4].toInt();
auto a = 255;
type->gridOptions.style->color = Color(r, g, b, a);
}
else if (rowItemList[1] == "scaleFactor")
{
Expand Down
5 changes: 3 additions & 2 deletions YUViewLib/src/statistics/StatisticsType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ void StatisticsType::saveInitialState()
this->vectorDataOptions->mapToColor.setUnmodified();
this->vectorDataOptions->arrowHead.setUnmodified();
}

this->init.gridOptions = this->gridOptions;
this->gridOptions.render.setUnmodified();
this->gridOptions.style.setUnmodified();
this->gridOptions.scaleToZoom.setUnmodified();
}

} // namespace stats
12 changes: 3 additions & 9 deletions YUViewLib/src/statistics/StatisticsType.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ class StatisticsType

struct GridOptions
{
bool render{};
LineDrawStyle style{};
bool scaleToZoom{};
modified<bool> render{};
modified<LineDrawStyle> style{};
modified<bool> scaleToZoom{};

bool operator==(const GridOptions &rhs) const;
};
Expand All @@ -134,12 +134,6 @@ class StatisticsType

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

struct initialState
{
GridOptions gridOptions;
};
initialState init;

void saveInitialState();
};

Expand Down
17 changes: 10 additions & 7 deletions YUViewLib/src/statistics/StatisticsTypePlaylistHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,13 @@ void addModifiedValuesToElement(YUViewDomElement
}

void addModifiedValuesToElement(YUViewDomElement &element,
const StatisticsType::GridOptions &options,
const StatisticsType::GridOptions &initOptions)
const StatisticsType::GridOptions &options)
{
if (options.render != initOptions.render)
if (options.render.wasModified())
element.setAttribute("renderGrid", options.render);
if (options.style != initOptions.style)
if (options.style.wasModified())
element.setAttribute("gridStyle", convertPenToString(options.style));
if (options.scaleToZoom != initOptions.scaleToZoom)
if (options.scaleToZoom.wasModified())
element.setAttribute("scaleGridToZoom", options.scaleToZoom);
}

Expand All @@ -139,11 +138,15 @@ void StatisticsTypePlaylistHandler::saveToPlaylist(const StatisticsType &type,
type.vectorDataOptions->mapToColor.wasModified() ||
type.vectorDataOptions->arrowHead.wasModified());

const auto gridOptionsModified = type.gridOptions.render.wasModified() || //
type.gridOptions.style.wasModified() || //
type.gridOptions.scaleToZoom.wasModified();

const auto allValuesIdenticalToInitialValues = (!type.render.wasModified() && //
!type.alphaFactor.wasModified() && //
!valueDataOptionsModified && //
!vectorDataOptionsModified && //
type.init.gridOptions == type.gridOptions);
!gridOptionsModified);

if (allValuesIdenticalToInitialValues)
return;
Expand All @@ -160,7 +163,7 @@ void StatisticsTypePlaylistHandler::saveToPlaylist(const StatisticsType &type,

addModifiedValuesToElement(newChild, type.valueDataOptions);
addModifiedValuesToElement(newChild, type.vectorDataOptions);
addModifiedValuesToElement(newChild, type.gridOptions, type.init.gridOptions);
addModifiedValuesToElement(newChild, type.gridOptions);

root.appendChild(newChild);
}
Expand Down
16 changes: 8 additions & 8 deletions YUViewLib/src/ui/Statisticsstylecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ void StatisticsStyleControl::setStatsItem(stats::StatisticsType *item)

{
const auto &options = this->currentItem->gridOptions;
this->ui.frameGridColor->setPlainColor(functionsGui::toQColor(options.style.color));
this->ui.doubleSpinBoxGridLineWidth->setValue(options.style.width);
this->ui.frameGridColor->setPlainColor(functionsGui::toQColor(options.style->color));
this->ui.doubleSpinBoxGridLineWidth->setValue(options.style->width);
this->ui.checkBoxGridScaleToZoom->setChecked(options.scaleToZoom);
}

Expand Down Expand Up @@ -474,15 +474,15 @@ void StatisticsStyleControl::on_groupBoxGrid_clicked(bool check)
void StatisticsStyleControl::on_frameGridColor_clicked()
{
auto newQColor =
QColorDialog::getColor(functionsGui::toQColor(this->currentItem->gridOptions.style.color),
QColorDialog::getColor(functionsGui::toQColor(this->currentItem->gridOptions.style->color),
this,
tr("Select grid color"),
QColorDialog::ShowAlphaChannel);

auto newColor = functionsGui::toColor(newQColor);
if (newQColor.isValid() && newColor != this->currentItem->gridOptions.style.color)
if (newQColor.isValid() && newColor != this->currentItem->gridOptions.style->color)
{
this->currentItem->gridOptions.style.color = newColor;
this->currentItem->gridOptions.style->color = newColor;
this->ui.frameGridColor->setPlainColor(newQColor);
emit StyleChanged();
}
Expand All @@ -491,14 +491,14 @@ void StatisticsStyleControl::on_frameGridColor_clicked()
void StatisticsStyleControl::on_comboBoxGridLineStyle_currentIndexChanged(int index)
{
// Convert the selection to a pen style and set it
auto pattern = stats::AllPatterns.at(index);
this->currentItem->gridOptions.style.pattern = pattern;
auto pattern = stats::AllPatterns.at(index);
this->currentItem->gridOptions.style->pattern = pattern;
emit StyleChanged();
}

void StatisticsStyleControl::on_doubleSpinBoxGridLineWidth_valueChanged(double width)
{
this->currentItem->gridOptions.style.width = width;
this->currentItem->gridOptions.style->width = width;
emit StyleChanged();
}

Expand Down
2 changes: 1 addition & 1 deletion YUViewUnitTest/statistics/StatisticsFileCSVTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ TEST(StatisticsFileCSV, testCSVFileParsing)
EXPECT_EQ(t.valueDataOptions->colorMapper->valueRange.min, valueColorRangeMin[i]);
EXPECT_EQ(t.valueDataOptions->colorMapper->valueRange.max, valueColorRangeMax[i]);
EXPECT_EQ(t.valueDataOptions->colorMapper->predefinedType, stats::color::PredefinedType::Jet);
EXPECT_EQ(t.gridOptions.style.color.toHex(), valueGridColors[i]);
EXPECT_EQ(t.gridOptions.style->color.toHex(), valueGridColors[i]);
}
}

Expand Down

0 comments on commit ec89168

Please sign in to comment.