Refactoring

This commit is contained in:
Kirill Polyakov
2025-12-10 15:23:22 +03:00
parent 6422ce7f78
commit 10ab7009a1
3 changed files with 49 additions and 30 deletions

View File

@ -3,6 +3,8 @@ DEPENDPATH += $$PWD
CORE_ROOT_DIR = $$PWD/../../../..
include($$CORE_ROOT_DIR/Common/3dParty/boost/boost.pri)
css_calculator_without_xhtml {
HEADERS += \
$$PWD/src/CCssCalculator_Private.h \

View File

@ -483,7 +483,7 @@ namespace NSCSS
}
CColorValue::CColorValue()
: m_eType(EColorType::ColorNone), m_oValue(std::monostate())
: m_eType(EColorType::ColorNone)
{}
CColorValue::CColorValue(const CColorValue& oValue)
@ -606,7 +606,7 @@ namespace NSCSS
void CColor::SetNone()
{
Clear();
m_oValue = CColorValue();
m_oValue.reset();
}
char NormalizeNegativeColorValue(INT nValue)
@ -761,9 +761,9 @@ namespace NSCSS
switch(m_oValue->GetType())
{
case ColorRGB:
return std::get<TRGB>(m_oValue->m_oValue).ToInt();
return boost::variant2::get<TRGB>(m_oValue->m_oValue).ToInt();
case ColorHEX:
return ConvertHEXtoRGB(std::get<std::wstring>(m_oValue->m_oValue)).ToInt();
return ConvertHEXtoRGB(boost::variant2::get<std::wstring>(m_oValue->m_oValue)).ToInt();
default:
return 0;
}
@ -781,9 +781,9 @@ namespace NSCSS
switch(m_oValue->GetType())
{
case ColorRGB: return ConvertRGBtoHEX(std::get<TRGB>(m_oValue->m_oValue));
case ColorHEX: return std::get<std::wstring>(m_oValue->m_oValue);
case ColorUrl: return std::get<CURL>(m_oValue->m_oValue).GetValue();
case ColorRGB: return ConvertRGBtoHEX(boost::variant2::get<TRGB>(m_oValue->m_oValue));
case ColorHEX: return boost::variant2::get<std::wstring>(m_oValue->m_oValue);
case ColorUrl: return boost::variant2::get<CURL>(m_oValue->m_oValue).GetValue();
default: return std::wstring();
}
}
@ -796,9 +796,9 @@ namespace NSCSS
switch(m_oValue->GetType())
{
case ColorRGB:
return ConvertRGBtoHEX(std::get<TRGB>(m_oValue->m_oValue));
return ConvertRGBtoHEX(boost::variant2::get<TRGB>(m_oValue->m_oValue));
case ColorHEX:
return std::get<std::wstring>(m_oValue->m_oValue);
return boost::variant2::get<std::wstring>(m_oValue->m_oValue);
default:
return std::wstring();
}
@ -813,8 +813,8 @@ namespace NSCSS
switch(m_oValue->GetType())
{
case ColorRGB: oCurrentColor = std::get<TRGB>(m_oValue->m_oValue); break;
case ColorHEX: oCurrentColor = ConvertHEXtoRGB(std::get<std::wstring>(m_oValue->m_oValue)); break;
case ColorRGB: oCurrentColor = boost::variant2::get<TRGB>(m_oValue->m_oValue); break;
case ColorHEX: oCurrentColor = ConvertHEXtoRGB(boost::variant2::get<std::wstring>(m_oValue->m_oValue)); break;
default: return L"none";
}
@ -843,8 +843,8 @@ namespace NSCSS
switch(m_oValue->GetType())
{
case ColorRGB: return std::get<TRGB>(m_oValue->m_oValue);
case ColorHEX: return ConvertHEXtoRGB(std::get<std::wstring>(m_oValue->m_oValue));
case ColorRGB: return boost::variant2::get<TRGB>(m_oValue->m_oValue);
case ColorHEX: return ConvertHEXtoRGB(boost::variant2::get<std::wstring>(m_oValue->m_oValue));
default: return TRGB();
}
}
@ -1390,7 +1390,7 @@ namespace NSCSS
m_oHAlign == oDisplay.m_oHAlign &&
m_oVAlign == oDisplay.m_oVAlign &&
m_oDisplay == oDisplay.m_oDisplay &&
m_eWhiteSpace == oDisplay.m_eWhiteSpace.ToInt();
m_eWhiteSpace == oDisplay.m_eWhiteSpace;
}
// STROKE

View File

@ -2,14 +2,16 @@
#define STYLEPROPERTIES_H
#include <map>
#include <optional>
#include <string>
#include <variant>
#include <vector>
#include "../../../../DesktopEditor/graphics/Matrix.h"
#include "CUnitMeasureConverter.h"
#include <boost/optional.hpp>
#include "boost/blank.hpp"
#include <boost/variant2/variant.hpp>
namespace NSCSS
{
namespace NSProperties
@ -64,6 +66,23 @@ namespace NSCSS
return oFirstValue.m_unLevel == oSecondValue.m_unLevel;
}
friend bool operator==(const CValueBase& oLeftValue, const CValueBase& oRightValue)
{
if (oLeftValue.Empty() && oRightValue.Empty())
return true;
if (( oLeftValue.Empty() && !oRightValue.Empty()) ||
(!oLeftValue.Empty() && oRightValue.Empty()))
return false;
return oLeftValue.m_oValue == oRightValue.m_oValue;
}
friend bool operator!=(const CValueBase& oLeftValue, const CValueBase& oRightValue)
{
return !(oLeftValue == oRightValue);
}
bool operator==(const T& oValue) const
{
return m_oValue == oValue;
@ -92,28 +111,18 @@ namespace NSCSS
return *this;
}
virtual bool operator==(const CValueBase& oValue) const
{
return m_oValue == oValue.m_oValue;
}
virtual bool operator!=(const CValueBase& oValue) const
{
return !(*this == oValue);
}
};
template<typename T>
class CValueOptional : public CValueBase<std::optional<T>>
class CValueOptional : public CValueBase<boost::optional<T>>
{
protected:
CValueOptional()
: CValueBase<std::optional<T>>()
: CValueBase<boost::optional<T>>()
{}
CValueOptional(const T& oValue, unsigned int unLevel, bool bImportant)
: CValueBase<std::optional<T>>(oValue, unLevel, bImportant)
: CValueBase<boost::optional<T>>(oValue, unLevel, bImportant)
{}
public:
@ -127,6 +136,14 @@ namespace NSCSS
this->m_unLevel = 0;
this->m_bImportant = false;
}
bool operator==(const T& oValue) const
{
if (!this->m_oValue.has_value())
return false;
return this->m_oValue.value() == oValue;
}
};
class CString : public CValueOptional<std::wstring>
@ -245,7 +262,7 @@ namespace NSCSS
class CColorValue
{
using color_value = std::variant<std::monostate, std::wstring, TRGB, CURL>;
using color_value = boost::variant2::variant<boost::blank, std::wstring, TRGB, CURL>;
protected:
EColorType m_eType;
public: