mirror of
https://github.com/leozide/leocad.git
synced 2026-10-27 06:20:55 +00:00
Store profile enums as stable strings and harden settings reads
Persist enum preferences through named typed accessors using stable PascalCase tokens. Keep explicit legacy integer mappings so existing settings continue to load when enum members are reordered, and fall back to declared defaults for invalid values. Validate scalar conversions and reject non-finite floats while preserving unsigned color bits returned by signed native settings backends. Read fixed part colors as unsigned values and remove their override when unlocking so the unlocked state survives restart. Save both view-sphere enabled flags directly, preserving disabled spheres even when their remembered sizes are nonzero. Validation: macOS application build and temporary enum and persistence regression checks passed. Windows and Linux execution was not performed.
This commit is contained in:
1 parent
78fe37515c
commit
75dc3883da
8 files changed
+315
-35
No files matched your search
+18
-18
@@ -25,15 +25,14 @@ void lcPreferences::LoadDefaults()
|
||||
{
|
||||
mFixedAxes = lcGetProfileInt(LC_PROFILE_FIXED_AXES);
|
||||
mMouseSensitivity = lcGetProfileInt(LC_PROFILE_MOUSE_SENSITIVITY);
|
||||
mShadingMode = static_cast<lcShadingMode>(lcGetProfileInt(LC_PROFILE_SHADING_MODE));
|
||||
const int SelectionRenderMode = lcGetProfileInt(LC_PROFILE_SELECTION_RENDER_MODE);
|
||||
mSelectionRenderMode = SelectionRenderMode == static_cast<int>(lcSelectionRenderMode::Tint) ? lcSelectionRenderMode::Tint : lcSelectionRenderMode::Outline;
|
||||
mShadingMode = lcGetProfileShadingMode();
|
||||
mSelectionRenderMode = lcGetProfileSelectionRenderMode();
|
||||
mBackgroundGradient = lcGetProfileInt(LC_PROFILE_BACKGROUND_GRADIENT);
|
||||
mBackgroundSolidColor = lcGetProfileUInt(LC_PROFILE_BACKGROUND_COLOR);
|
||||
mBackgroundGradientColorTop = lcGetProfileUInt(LC_PROFILE_GRADIENT_COLOR_TOP);
|
||||
mBackgroundGradientColorBottom = lcGetProfileUInt(LC_PROFILE_GRADIENT_COLOR_BOTTOM);
|
||||
mDrawAxes = lcGetProfileInt(LC_PROFILE_DRAW_AXES);
|
||||
mAxisIconLocation = static_cast<lcAxisIconLocation>(lcGetProfileInt(LC_PROFILE_DRAW_AXES_LOCATION));
|
||||
mAxisIconLocation = lcGetProfileAxisIconLocation();
|
||||
mTextColor = lcGetProfileUInt(LC_PROFILE_TEXT_COLOR);
|
||||
mTextHaloColor = lcGetProfileUInt(LC_PROFILE_TEXT_HALO_COLOR);
|
||||
mMarqueeBorderColor = lcGetProfileUInt(LC_PROFILE_MARQUEE_BORDER_COLOR);
|
||||
@@ -57,17 +56,17 @@ void lcPreferences::LoadDefaults()
|
||||
mGridLineColor = lcGetProfileUInt(LC_PROFILE_GRID_LINE_COLOR);
|
||||
mDrawGridOrigin = lcGetProfileInt(LC_PROFILE_GRID_ORIGIN);
|
||||
mViewSphereEnabled = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_ENABLED);
|
||||
mViewSphereLocation = static_cast<lcViewSphereLocation>(lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_LOCATION));
|
||||
mViewSphereLocation = lcGetProfileViewSphereLocation();
|
||||
mViewSphereSize = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_SIZE);
|
||||
mViewSphereColor = lcGetProfileUInt(LC_PROFILE_VIEW_SPHERE_COLOR);
|
||||
mViewSphereTextColor = lcGetProfileUInt(LC_PROFILE_VIEW_SPHERE_TEXT_COLOR);
|
||||
mViewSphereHighlightColor = lcGetProfileUInt(LC_PROFILE_VIEW_SPHERE_HIGHLIGHT_COLOR);
|
||||
mAutoLoadMostRecent = lcGetProfileInt(LC_PROFILE_AUTOLOAD_MOSTRECENT);
|
||||
mRestoreTabLayout = lcGetProfileInt(LC_PROFILE_RESTORE_TAB_LAYOUT);
|
||||
mColorTheme = static_cast<lcColorTheme>(lcGetProfileInt(LC_PROFILE_COLOR_THEME));
|
||||
mColorTheme = lcGetProfileColorTheme();
|
||||
mPreviewViewSphereEnabled = lcGetProfileInt(LC_PROFILE_PREVIEW_VIEW_SPHERE_ENABLED);
|
||||
mPreviewViewSphereSize = lcGetProfileInt(LC_PROFILE_PREVIEW_VIEW_SPHERE_SIZE);
|
||||
mPreviewViewSphereLocation = static_cast<lcViewSphereLocation>(lcGetProfileInt(LC_PROFILE_PREVIEW_VIEW_SPHERE_LOCATION));
|
||||
mPreviewViewSphereLocation = lcGetProfilePreviewViewSphereLocation();
|
||||
mDrawPreviewAxis = lcGetProfileInt(LC_PROFILE_PREVIEW_DRAW_AXES);
|
||||
mStudCylinderColorEnabled = lcGetProfileInt(LC_PROFILE_STUD_CYLINDER_COLOR_ENABLED);
|
||||
mStudCylinderColor = lcGetProfileUInt(LC_PROFILE_STUD_CYLINDER_COLOR);
|
||||
@@ -92,10 +91,10 @@ void lcPreferences::SaveDefaults()
|
||||
{
|
||||
lcSetProfileInt(LC_PROFILE_FIXED_AXES, mFixedAxes);
|
||||
lcSetProfileInt(LC_PROFILE_MOUSE_SENSITIVITY, mMouseSensitivity);
|
||||
lcSetProfileInt(LC_PROFILE_SHADING_MODE, static_cast<int>(mShadingMode));
|
||||
lcSetProfileInt(LC_PROFILE_SELECTION_RENDER_MODE, static_cast<int>(mSelectionRenderMode));
|
||||
lcSetProfileShadingMode(mShadingMode);
|
||||
lcSetProfileSelectionRenderMode(mSelectionRenderMode);
|
||||
lcSetProfileInt(LC_PROFILE_DRAW_AXES, mDrawAxes);
|
||||
lcSetProfileInt(LC_PROFILE_DRAW_AXES_LOCATION, static_cast<int>(mAxisIconLocation));
|
||||
lcSetProfileAxisIconLocation(mAxisIconLocation);
|
||||
lcSetProfileUInt(LC_PROFILE_TEXT_COLOR, mTextColor);
|
||||
lcSetProfileUInt(LC_PROFILE_TEXT_HALO_COLOR, mTextHaloColor);
|
||||
lcSetProfileInt(LC_PROFILE_BACKGROUND_GRADIENT, mBackgroundGradient);
|
||||
@@ -122,17 +121,18 @@ void lcPreferences::SaveDefaults()
|
||||
lcSetProfileInt(LC_PROFILE_GRID_LINE_SPACING, mGridLineSpacing);
|
||||
lcSetProfileUInt(LC_PROFILE_GRID_LINE_COLOR, mGridLineColor);
|
||||
lcSetProfileInt(LC_PROFILE_GRID_ORIGIN, mDrawGridOrigin);
|
||||
lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_ENABLED, mViewSphereSize ? 1 : 0);
|
||||
lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_LOCATION, static_cast<int>(mViewSphereLocation));
|
||||
lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_ENABLED, mViewSphereEnabled);
|
||||
lcSetProfileViewSphereLocation(mViewSphereLocation);
|
||||
lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_SIZE, mViewSphereSize);
|
||||
lcSetProfileUInt(LC_PROFILE_VIEW_SPHERE_COLOR, mViewSphereColor);
|
||||
lcSetProfileUInt(LC_PROFILE_VIEW_SPHERE_TEXT_COLOR, mViewSphereTextColor);
|
||||
lcSetProfileUInt(LC_PROFILE_VIEW_SPHERE_HIGHLIGHT_COLOR, mViewSphereHighlightColor);
|
||||
lcSetProfileInt(LC_PROFILE_AUTOLOAD_MOSTRECENT, mAutoLoadMostRecent);
|
||||
lcSetProfileInt(LC_PROFILE_RESTORE_TAB_LAYOUT, mRestoreTabLayout);
|
||||
lcSetProfileInt(LC_PROFILE_COLOR_THEME, static_cast<int>(mColorTheme));
|
||||
lcSetProfileColorTheme(mColorTheme);
|
||||
lcSetProfileInt(LC_PROFILE_PREVIEW_VIEW_SPHERE_ENABLED, mPreviewViewSphereEnabled);
|
||||
lcSetProfileInt(LC_PROFILE_PREVIEW_VIEW_SPHERE_SIZE, mPreviewViewSphereSize);
|
||||
lcSetProfileInt(LC_PROFILE_PREVIEW_VIEW_SPHERE_LOCATION, static_cast<int>(mPreviewViewSphereLocation));
|
||||
lcSetProfilePreviewViewSphereLocation(mPreviewViewSphereLocation);
|
||||
lcSetProfileInt(LC_PROFILE_PREVIEW_DRAW_AXES, mDrawPreviewAxis);
|
||||
lcSetProfileInt(LC_PROFILE_STUD_CYLINDER_COLOR_ENABLED, mStudCylinderColorEnabled);
|
||||
lcSetProfileUInt(LC_PROFILE_STUD_CYLINDER_COLOR, mStudCylinderColor);
|
||||
@@ -381,7 +381,7 @@ lcCommandLineOptions lcApplication::ParseCommandLineOptions()
|
||||
Options.ShadingMode = Preferences.mShadingMode;
|
||||
Options.LineWidth = Preferences.mLineWidth;
|
||||
Options.AASamples = lcGetProfileInt(LC_PROFILE_ANTIALIASING_SAMPLES);
|
||||
Options.StudStyle = static_cast<lcStudStyle>(lcGetProfileInt(LC_PROFILE_STUD_STYLE));
|
||||
Options.StudStyle = lcGetProfileStudStyle();
|
||||
Options.ImageStart = 0;
|
||||
Options.ImageEnd = 0;
|
||||
Options.CameraPosition[0] = lcVector3(0.0f, 0.0f, 0.0f);
|
||||
@@ -854,7 +854,7 @@ lcCommandLineOptions lcApplication::ParseCommandLineOptions()
|
||||
Options.StdErr += Message.arg(QString("--light-dark-value %1").arg(Options.PartColorValueLDIndex));
|
||||
}
|
||||
|
||||
if (!lcIsHighContrast(Options.StudStyle) && !lcIsHighContrast(static_cast<lcStudStyle>(lcGetProfileInt(LC_PROFILE_STUD_STYLE))))
|
||||
if (!lcIsHighContrast(Options.StudStyle) && !lcIsHighContrast(lcGetProfileStudStyle()))
|
||||
{
|
||||
QString const Message = tr("High contrast stud style is required for the '%1' option but is not enabled.\n");
|
||||
|
||||
@@ -1435,7 +1435,7 @@ void lcApplication::ShowPreferencesDialog()
|
||||
lcSetProfileString(LC_PROFILE_LANGUAGE, Options.Language);
|
||||
lcSetProfileInt(LC_PROFILE_CHECK_UPDATES, Options.CheckForUpdates);
|
||||
lcSetProfileInt(LC_PROFILE_ANTIALIASING_SAMPLES, Options.AASamples);
|
||||
lcSetProfileInt(LC_PROFILE_STUD_STYLE, static_cast<int>(Options.StudStyle));
|
||||
lcSetProfileStudStyle(Options.StudStyle);
|
||||
|
||||
if (LanguageChanged || LibraryChanged || AAChanged)
|
||||
QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("Some changes will only take effect the next time you start LeoCAD."));
|
||||
@@ -1479,7 +1479,7 @@ void lcApplication::ShowPreferencesDialog()
|
||||
|
||||
if (StudStyleChanged || StudCylinderColorEnabledChanged)
|
||||
{
|
||||
lcSetProfileInt(LC_PROFILE_STUD_STYLE, static_cast<int>(Options.StudStyle));
|
||||
lcSetProfileStudStyle(Options.StudStyle);
|
||||
lcGetPiecesLibrary()->SetStudStyle(Options.StudStyle, true, Options.Preferences.mStudCylinderColorEnabled);
|
||||
}
|
||||
else if (ColorConfigChanged || EdgeColorSettingsChanged)
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
#include <variant>
|
||||
#include <cmath>
|
||||
|
||||
#if _MSC_VER
|
||||
#pragma warning(default : 4062) // enumerator 'identifier' in switch of enum 'enumeration' is not handled
|
||||
|
||||
@@ -51,7 +51,7 @@ lcPiecesLibrary::lcPiecesLibrary()
|
||||
mNumOfficialPieces = 0;
|
||||
mBuffersDirty = false;
|
||||
mHasUnofficial = false;
|
||||
mStudStyle = static_cast<lcStudStyle>(lcGetProfileInt(LC_PROFILE_STUD_STYLE));
|
||||
mStudStyle = lcGetProfileStudStyle();
|
||||
mStudCylinderColorEnabled = lcGetProfileInt(LC_PROFILE_STUD_CYLINDER_COLOR_ENABLED);
|
||||
}
|
||||
|
||||
|
||||
@@ -1597,7 +1597,7 @@ void lcMainWindow::ShowResultMessageBox(const lcResult<void>& Result, const QStr
|
||||
void lcMainWindow::SetShadingMode(lcShadingMode ShadingMode)
|
||||
{
|
||||
lcGetPreferences().mShadingMode = ShadingMode;
|
||||
lcSetProfileInt(LC_PROFILE_SHADING_MODE, static_cast<int>(ShadingMode));
|
||||
lcSetProfileShadingMode(ShadingMode);
|
||||
|
||||
UpdateShadingMode();
|
||||
|
||||
|
||||
@@ -68,22 +68,22 @@ lcPartSelectionListModel::lcPartSelectionListModel(QObject* Parent)
|
||||
mCaseSensitiveFilter = lcGetProfileInt(LC_PROFILE_PARTS_LIST_CASE_SENSITIVE_FILTER);
|
||||
mFileNameFilter = lcGetProfileInt(LC_PROFILE_PARTS_LIST_FILE_NAME_FILTER);
|
||||
mPartDescriptionFilter = lcGetProfileInt(LC_PROFILE_PARTS_LIST_PART_DESCRIPTION_FILTER);
|
||||
mPartFilterType = static_cast<lcPartFilterType>(lcGetProfileInt(LC_PROFILE_PARTS_LIST_PART_FILTER));
|
||||
mPartFilterType = lcGetProfilePartFilterType();
|
||||
|
||||
int ColorCodeInt = lcGetProfileInt(LC_PROFILE_PARTS_LIST_COLOR);
|
||||
uint ColorCode = lcGetProfileUInt(LC_PROFILE_PARTS_LIST_COLOR);
|
||||
int LockedFlag = lcGetProfileInt(LC_PROFILE_PARTS_LIST_COLOR_LOCKED);
|
||||
|
||||
if (ColorCodeInt == -1 && LockedFlag == 0)
|
||||
if (ColorCode == LC_COLOR_NOCOLOR && LockedFlag == 0)
|
||||
{
|
||||
mColorIndex = gMainWindow->mColorIndex;
|
||||
mColorLocked = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint ColorCodeValue = (ColorCodeInt == -1) ? lcGetColorCode(gMainWindow->mColorIndex) : static_cast<uint>(ColorCodeInt);
|
||||
uint ColorCodeValue = (ColorCode == LC_COLOR_NOCOLOR) ? lcGetColorCode(gMainWindow->mColorIndex) : ColorCode;
|
||||
|
||||
mColorIndex = lcGetColorIndex(ColorCodeValue);
|
||||
mColorLocked = (LockedFlag != 0) || (ColorCodeInt != -1);
|
||||
mColorLocked = (LockedFlag != 0) || (ColorCode != LC_COLOR_NOCOLOR);
|
||||
}
|
||||
|
||||
connect(lcGetPiecesLibrary()->GetThumbnailManager(), &lcThumbnailManager::ThumbnailReady, this, &lcPartSelectionListModel::ThumbnailReady);
|
||||
@@ -128,7 +128,7 @@ void lcPartSelectionListModel::ToggleColorLocked()
|
||||
else
|
||||
{
|
||||
lcSetProfileInt(LC_PROFILE_PARTS_LIST_COLOR_LOCKED, 0);
|
||||
lcSetProfileUInt(LC_PROFILE_PARTS_LIST_COLOR, 0);
|
||||
lcRemoveProfileKey(LC_PROFILE_PARTS_LIST_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -787,7 +787,7 @@ void lcPartSelectionListView::TogglePartDescriptionFilter()
|
||||
void lcPartSelectionListView::SetPartFilterType(lcPartFilterType Option)
|
||||
{
|
||||
mListModel->SetPartFilterType(Option);
|
||||
lcSetProfileInt(LC_PROFILE_PARTS_LIST_PART_FILTER, static_cast<int>(Option));
|
||||
lcSetProfilePartFilterType(Option);
|
||||
}
|
||||
|
||||
void lcPartSelectionListView::ToggleListMode()
|
||||
|
||||
+249
-6
@@ -6,6 +6,9 @@
|
||||
#include "project.h"
|
||||
#include "lc_viewsphere.h"
|
||||
#include "lc_renderdialog.h"
|
||||
#include "lc_library.h"
|
||||
#include "lc_partselectionwidget.h"
|
||||
#include "lc_colors.h"
|
||||
|
||||
lcProfileEntry::lcProfileEntry(const char* Section, const char* Key, int DefaultValue)
|
||||
{
|
||||
@@ -120,16 +123,16 @@ static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] =
|
||||
lcProfileEntry("Settings", "ImageExtension", ".png"), // LC_PROFILE_IMAGE_EXTENSION
|
||||
lcProfileEntry("Settings", "PartsListIcons", 64), // LC_PROFILE_PARTS_LIST_ICONS
|
||||
lcProfileEntry("Settings", "PartsListNames", 1), // LC_PROFILE_PARTS_LIST_NAMES
|
||||
lcProfileEntry("Settings", "PartsListFixedColor", -1), // LC_PROFILE_PARTS_LIST_COLOR
|
||||
lcProfileEntry("Settings", "PartsListFixedColor", static_cast<uint>(LC_COLOR_NOCOLOR)), // LC_PROFILE_PARTS_LIST_COLOR
|
||||
lcProfileEntry("Settings", "PartsListColorLocked", false), // LC_PROFILE_PARTS_LIST_COLOR_LOCKED
|
||||
lcProfileEntry("Settings", "PartsListDecorated", 1), // LC_PROFILE_PARTS_LIST_DECORATED
|
||||
lcProfileEntry("Settings", "PartsListAliases", 1), // LC_PROFILE_PARTS_LIST_ALIASES
|
||||
lcProfileEntry("Settings", "PartsListListMode", 0), // LC_PROFILE_PARTS_LIST_LISTMODE
|
||||
lcProfileEntry("Settings", "PartsListPartFilter", 0), // LC_PROFILE_PARTS_LIST_PART_FILTER
|
||||
lcProfileEntry("Settings", "PartsListPartFilter", static_cast<int>(lcPartFilterType::Default)), // LC_PROFILE_PARTS_LIST_PART_FILTER
|
||||
lcProfileEntry("Settings", "PartsListCaseSensitiveFilter", 0), // LC_PROFILE_PARTS_LIST_CASE_SENSITIVE_FILTER
|
||||
lcProfileEntry("Settings", "PartsListFileNameFilter", 1), // LC_PROFILE_PARTS_LIST_FILE_NAME_FILTER
|
||||
lcProfileEntry("Settings", "PartsListPartDescriptionFilter", 1), // LC_PROFILE_PARTS_LIST_PART_DESCRIPTION_FILTER
|
||||
lcProfileEntry("Settings", "StudStyle", 0), // LC_PROFILE_STUD_STYLE
|
||||
lcProfileEntry("Settings", "StudStyle", static_cast<int>(lcStudStyle::Plain)), // LC_PROFILE_STUD_STYLE
|
||||
|
||||
lcProfileEntry("Defaults", "Author", ""), // LC_PROFILE_DEFAULT_AUTHOR_NAME
|
||||
lcProfileEntry("Defaults", "AmbientColor", LC_RGB(75, 75, 75)), // LC_PROFILE_DEFAULT_AMBIENT_COLOR
|
||||
@@ -190,7 +193,20 @@ int lcGetProfileInt(LC_PROFILE_KEY Key)
|
||||
int* DefaultInt = std::get_if<int>(&Entry.mDefault);
|
||||
int DefaultValue = DefaultInt ? *DefaultInt : 0;
|
||||
|
||||
return QSettings().value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), DefaultValue).toInt();
|
||||
const QVariant Stored = QSettings().value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), DefaultValue);
|
||||
|
||||
if (Stored.userType() == QMetaType::Float || Stored.userType() == QMetaType::Double)
|
||||
return DefaultValue;
|
||||
if (Stored.userType() == QMetaType::ULongLong && Stored.toULongLong() > static_cast<qulonglong>(std::numeric_limits<int>::max()))
|
||||
return DefaultValue;
|
||||
|
||||
bool Valid = false;
|
||||
const qlonglong Value = Stored.toLongLong(&Valid);
|
||||
|
||||
if (Valid && Value >= std::numeric_limits<int>::min() && Value <= std::numeric_limits<int>::max())
|
||||
return static_cast<int>(Value);
|
||||
|
||||
return DefaultValue;
|
||||
}
|
||||
|
||||
uint lcGetProfileUInt(LC_PROFILE_KEY Key)
|
||||
@@ -199,7 +215,27 @@ uint lcGetProfileUInt(LC_PROFILE_KEY Key)
|
||||
uint* DefaultUInt = std::get_if<uint>(&Entry.mDefault);
|
||||
uint DefaultValue = DefaultUInt ? *DefaultUInt : 0;
|
||||
|
||||
return QSettings().value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), DefaultValue).toUInt();
|
||||
const QVariant Stored = QSettings().value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), DefaultValue);
|
||||
|
||||
if (Stored.userType() == QMetaType::Float || Stored.userType() == QMetaType::Double)
|
||||
return DefaultValue;
|
||||
|
||||
if (Stored.userType() == QMetaType::Int || Stored.userType() == QMetaType::LongLong)
|
||||
{
|
||||
const qlonglong Value = Stored.toLongLong();
|
||||
|
||||
if (Value >= std::numeric_limits<qint32>::min() && Value <= static_cast<qlonglong>(std::numeric_limits<uint>::max()))
|
||||
return static_cast<uint>(Value);
|
||||
return DefaultValue;
|
||||
}
|
||||
|
||||
bool Valid = false;
|
||||
const qulonglong Value = Stored.toULongLong(&Valid);
|
||||
|
||||
if (Valid && Value <= std::numeric_limits<uint>::max())
|
||||
return static_cast<uint>(Value);
|
||||
|
||||
return DefaultValue;
|
||||
}
|
||||
|
||||
float lcGetProfileFloat(LC_PROFILE_KEY Key)
|
||||
@@ -208,7 +244,10 @@ float lcGetProfileFloat(LC_PROFILE_KEY Key)
|
||||
float* DefaultFloat = std::get_if<float>(&Entry.mDefault);
|
||||
float DefaultValue = DefaultFloat ? *DefaultFloat : 0.0f;
|
||||
|
||||
return QSettings().value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), DefaultValue).toFloat();
|
||||
bool Valid = false;
|
||||
const float Value = QSettings().value(QString("%1/%2").arg(Entry.mSection, Entry.mKey), DefaultValue).toFloat(&Valid);
|
||||
|
||||
return Valid && std::isfinite(Value) ? Value : DefaultValue;
|
||||
}
|
||||
|
||||
QString lcGetProfileString(LC_PROFILE_KEY Key)
|
||||
@@ -255,6 +294,9 @@ void lcSetProfileUInt(LC_PROFILE_KEY Key, uint Value)
|
||||
|
||||
void lcSetProfileFloat(LC_PROFILE_KEY Key, float Value)
|
||||
{
|
||||
if (!std::isfinite(Value))
|
||||
return;
|
||||
|
||||
lcProfileEntry& Entry = gProfileEntries[Key];
|
||||
QSettings Settings;
|
||||
|
||||
@@ -284,3 +326,204 @@ void lcSetProfileBuffer(LC_PROFILE_KEY Key, const QByteArray& Buffer)
|
||||
|
||||
Settings.setValue(QString("%1/%2").arg(Entry.mSection, Entry.mKey), Buffer);
|
||||
}
|
||||
|
||||
template<typename Enum>
|
||||
struct lcProfileEnumValue
|
||||
{
|
||||
Enum Value;
|
||||
const char* Token;
|
||||
int LegacyValue;
|
||||
};
|
||||
|
||||
// Tokens and legacy numbers remain stable when enum members are reordered.
|
||||
constexpr lcProfileEnumValue<lcShadingMode> ShadingModeValues[] =
|
||||
{
|
||||
{ lcShadingMode::Wireframe, "Wireframe", 0 },
|
||||
{ lcShadingMode::Flat, "Flat", 1 },
|
||||
{ lcShadingMode::DefaultLights, "DefaultLights", 2 },
|
||||
{ lcShadingMode::Full, "Full", 3 }
|
||||
};
|
||||
|
||||
constexpr lcProfileEnumValue<lcSelectionRenderMode> SelectionRenderModeValues[] =
|
||||
{
|
||||
{ lcSelectionRenderMode::Outline, "Outline", 0 },
|
||||
{ lcSelectionRenderMode::Tint, "Tint", 1 }
|
||||
};
|
||||
|
||||
constexpr lcProfileEnumValue<lcAxisIconLocation> AxisIconLocationValues[] =
|
||||
{
|
||||
{ lcAxisIconLocation::TopLeft, "TopLeft", 0 },
|
||||
{ lcAxisIconLocation::TopRight, "TopRight", 1 },
|
||||
{ lcAxisIconLocation::BottomLeft, "BottomLeft", 2 },
|
||||
{ lcAxisIconLocation::BottomRight, "BottomRight", 3 }
|
||||
};
|
||||
|
||||
constexpr lcProfileEnumValue<lcViewSphereLocation> ViewSphereLocationValues[] =
|
||||
{
|
||||
{ lcViewSphereLocation::TopLeft, "TopLeft", 0 },
|
||||
{ lcViewSphereLocation::TopRight, "TopRight", 1 },
|
||||
{ lcViewSphereLocation::BottomLeft, "BottomLeft", 2 },
|
||||
{ lcViewSphereLocation::BottomRight, "BottomRight", 3 }
|
||||
};
|
||||
|
||||
constexpr lcProfileEnumValue<lcColorTheme> ColorThemeValues[] =
|
||||
{
|
||||
{ lcColorTheme::Dark, "Dark", 0 },
|
||||
{ lcColorTheme::System, "System", 1 }
|
||||
};
|
||||
|
||||
constexpr lcProfileEnumValue<lcStudStyle> StudStyleValues[] =
|
||||
{
|
||||
{ lcStudStyle::Plain, "Plain", 0 },
|
||||
{ lcStudStyle::ThinLinesLogo, "ThinLinesLogo", 1 },
|
||||
{ lcStudStyle::OutlineLogo, "OutlineLogo", 2 },
|
||||
{ lcStudStyle::SharpTopLogo, "SharpTopLogo", 3 },
|
||||
{ lcStudStyle::RoundedTopLogo, "RoundedTopLogo", 4 },
|
||||
{ lcStudStyle::FlattenedLogo, "FlattenedLogo", 5 },
|
||||
{ lcStudStyle::HighContrast, "HighContrast", 6 },
|
||||
{ lcStudStyle::HighContrastLogo, "HighContrastLogo", 7 }
|
||||
};
|
||||
|
||||
constexpr lcProfileEnumValue<lcPartFilterType> PartFilterTypeValues[] =
|
||||
{
|
||||
{ lcPartFilterType::Default, "Default", 0 },
|
||||
{ lcPartFilterType::RegularExpression, "RegularExpression", 1 }
|
||||
};
|
||||
|
||||
constexpr lcProfileEnumValue<lcPOVRayRenderQuality> RenderQualityValues[] =
|
||||
{
|
||||
{ lcPOVRayRenderQuality::Low, "Low", 0 },
|
||||
{ lcPOVRayRenderQuality::Medium, "Medium", 1 },
|
||||
{ lcPOVRayRenderQuality::High, "High", 2 }
|
||||
};
|
||||
|
||||
template<typename Enum, size_t N>
|
||||
static Enum lcReadProfileEnum(LC_PROFILE_KEY Key, const lcProfileEnumValue<Enum> (&Values)[N])
|
||||
{
|
||||
const lcProfileEntry& Entry = gProfileEntries[Key];
|
||||
const Enum Default = static_cast<Enum>(std::get<int>(Entry.mDefault));
|
||||
const QString Token = QSettings().value(QString("%1/%2").arg(Entry.mSection, Entry.mKey)).toString();
|
||||
|
||||
for (const lcProfileEnumValue<Enum>& Value : Values)
|
||||
{
|
||||
if (Token == QLatin1String(Value.Token))
|
||||
return Value.Value;
|
||||
}
|
||||
|
||||
bool Valid = false;
|
||||
const int LegacyValue = Token.toInt(&Valid);
|
||||
|
||||
if (Valid)
|
||||
{
|
||||
for (const lcProfileEnumValue<Enum>& Value : Values)
|
||||
{
|
||||
if (LegacyValue == Value.LegacyValue)
|
||||
return Value.Value;
|
||||
}
|
||||
}
|
||||
|
||||
return Default;
|
||||
}
|
||||
|
||||
template<typename Enum, size_t N>
|
||||
static void lcWriteProfileEnum(LC_PROFILE_KEY Key, Enum Value, const lcProfileEnumValue<Enum> (&Values)[N])
|
||||
{
|
||||
for (const lcProfileEnumValue<Enum>& Entry : Values)
|
||||
{
|
||||
if (Value == Entry.Value)
|
||||
{
|
||||
lcSetProfileString(Key, QString::fromLatin1(Entry.Token));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lcShadingMode lcGetProfileShadingMode()
|
||||
{
|
||||
return lcReadProfileEnum(LC_PROFILE_SHADING_MODE, ShadingModeValues);
|
||||
}
|
||||
|
||||
void lcSetProfileShadingMode(lcShadingMode Value)
|
||||
{
|
||||
lcWriteProfileEnum(LC_PROFILE_SHADING_MODE, Value, ShadingModeValues);
|
||||
}
|
||||
|
||||
lcSelectionRenderMode lcGetProfileSelectionRenderMode()
|
||||
{
|
||||
return lcReadProfileEnum(LC_PROFILE_SELECTION_RENDER_MODE, SelectionRenderModeValues);
|
||||
}
|
||||
|
||||
void lcSetProfileSelectionRenderMode(lcSelectionRenderMode Value)
|
||||
{
|
||||
lcWriteProfileEnum(LC_PROFILE_SELECTION_RENDER_MODE, Value, SelectionRenderModeValues);
|
||||
}
|
||||
|
||||
lcAxisIconLocation lcGetProfileAxisIconLocation()
|
||||
{
|
||||
return lcReadProfileEnum(LC_PROFILE_DRAW_AXES_LOCATION, AxisIconLocationValues);
|
||||
}
|
||||
|
||||
void lcSetProfileAxisIconLocation(lcAxisIconLocation Value)
|
||||
{
|
||||
lcWriteProfileEnum(LC_PROFILE_DRAW_AXES_LOCATION, Value, AxisIconLocationValues);
|
||||
}
|
||||
|
||||
lcViewSphereLocation lcGetProfileViewSphereLocation()
|
||||
{
|
||||
return lcReadProfileEnum(LC_PROFILE_VIEW_SPHERE_LOCATION, ViewSphereLocationValues);
|
||||
}
|
||||
|
||||
void lcSetProfileViewSphereLocation(lcViewSphereLocation Value)
|
||||
{
|
||||
lcWriteProfileEnum(LC_PROFILE_VIEW_SPHERE_LOCATION, Value, ViewSphereLocationValues);
|
||||
}
|
||||
|
||||
lcColorTheme lcGetProfileColorTheme()
|
||||
{
|
||||
return lcReadProfileEnum(LC_PROFILE_COLOR_THEME, ColorThemeValues);
|
||||
}
|
||||
|
||||
void lcSetProfileColorTheme(lcColorTheme Value)
|
||||
{
|
||||
lcWriteProfileEnum(LC_PROFILE_COLOR_THEME, Value, ColorThemeValues);
|
||||
}
|
||||
|
||||
lcStudStyle lcGetProfileStudStyle()
|
||||
{
|
||||
return lcReadProfileEnum(LC_PROFILE_STUD_STYLE, StudStyleValues);
|
||||
}
|
||||
|
||||
void lcSetProfileStudStyle(lcStudStyle Value)
|
||||
{
|
||||
lcWriteProfileEnum(LC_PROFILE_STUD_STYLE, Value, StudStyleValues);
|
||||
}
|
||||
|
||||
lcPartFilterType lcGetProfilePartFilterType()
|
||||
{
|
||||
return lcReadProfileEnum(LC_PROFILE_PARTS_LIST_PART_FILTER, PartFilterTypeValues);
|
||||
}
|
||||
|
||||
void lcSetProfilePartFilterType(lcPartFilterType Value)
|
||||
{
|
||||
lcWriteProfileEnum(LC_PROFILE_PARTS_LIST_PART_FILTER, Value, PartFilterTypeValues);
|
||||
}
|
||||
|
||||
lcPOVRayRenderQuality lcGetProfileRenderQuality()
|
||||
{
|
||||
return lcReadProfileEnum(LC_PROFILE_RENDER_QUALITY, RenderQualityValues);
|
||||
}
|
||||
|
||||
void lcSetProfileRenderQuality(lcPOVRayRenderQuality Value)
|
||||
{
|
||||
lcWriteProfileEnum(LC_PROFILE_RENDER_QUALITY, Value, RenderQualityValues);
|
||||
}
|
||||
|
||||
lcViewSphereLocation lcGetProfilePreviewViewSphereLocation()
|
||||
{
|
||||
return lcReadProfileEnum(LC_PROFILE_PREVIEW_VIEW_SPHERE_LOCATION, ViewSphereLocationValues);
|
||||
}
|
||||
|
||||
void lcSetProfilePreviewViewSphereLocation(lcViewSphereLocation Value)
|
||||
{
|
||||
lcWriteProfileEnum(LC_PROFILE_PREVIEW_VIEW_SPHERE_LOCATION, Value, ViewSphereLocationValues);
|
||||
}
|
||||
@@ -1,5 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
enum class lcShadingMode;
|
||||
enum class lcSelectionRenderMode;
|
||||
enum class lcAxisIconLocation;
|
||||
enum class lcViewSphereLocation;
|
||||
enum class lcColorTheme;
|
||||
enum class lcStudStyle;
|
||||
enum class lcPartFilterType;
|
||||
enum class lcPOVRayRenderQuality;
|
||||
|
||||
enum LC_PROFILE_KEY
|
||||
{
|
||||
// Settings.
|
||||
@@ -156,3 +165,30 @@ void lcSetProfileFloat(LC_PROFILE_KEY Key, float Value);
|
||||
void lcSetProfileString(LC_PROFILE_KEY Key, const QString& Value);
|
||||
void lcSetProfileStringList(LC_PROFILE_KEY Key, const QStringList& Value);
|
||||
void lcSetProfileBuffer(LC_PROFILE_KEY Key, const QByteArray& Buffer);
|
||||
|
||||
lcShadingMode lcGetProfileShadingMode();
|
||||
void lcSetProfileShadingMode(lcShadingMode Value);
|
||||
|
||||
lcSelectionRenderMode lcGetProfileSelectionRenderMode();
|
||||
void lcSetProfileSelectionRenderMode(lcSelectionRenderMode Value);
|
||||
|
||||
lcAxisIconLocation lcGetProfileAxisIconLocation();
|
||||
void lcSetProfileAxisIconLocation(lcAxisIconLocation Value);
|
||||
|
||||
lcViewSphereLocation lcGetProfileViewSphereLocation();
|
||||
void lcSetProfileViewSphereLocation(lcViewSphereLocation Value);
|
||||
|
||||
lcColorTheme lcGetProfileColorTheme();
|
||||
void lcSetProfileColorTheme(lcColorTheme Value);
|
||||
|
||||
lcStudStyle lcGetProfileStudStyle();
|
||||
void lcSetProfileStudStyle(lcStudStyle Value);
|
||||
|
||||
lcPartFilterType lcGetProfilePartFilterType();
|
||||
void lcSetProfilePartFilterType(lcPartFilterType Value);
|
||||
|
||||
lcPOVRayRenderQuality lcGetProfileRenderQuality();
|
||||
void lcSetProfileRenderQuality(lcPOVRayRenderQuality Value);
|
||||
|
||||
lcViewSphereLocation lcGetProfilePreviewViewSphereLocation();
|
||||
void lcSetProfilePreviewViewSphereLocation(lcViewSphereLocation Value);
|
||||
@@ -49,7 +49,7 @@ lcRenderDialog::lcRenderDialog(QWidget* Parent, lcRenderDialogMode RenderDialogM
|
||||
|
||||
mWidth = lcGetProfileInt(LC_PROFILE_RENDER_WIDTH);
|
||||
mHeight = lcGetProfileInt(LC_PROFILE_RENDER_HEIGHT);
|
||||
mQuality = static_cast<lcPOVRayRenderQuality>(lcGetProfileInt(LC_PROFILE_RENDER_QUALITY));
|
||||
mQuality = lcGetProfileRenderQuality();
|
||||
mScale = 1.0f;
|
||||
|
||||
ui->OutputEdit->setText(lcGetActiveProject()->GetImageFileName(false));
|
||||
@@ -862,7 +862,7 @@ void lcRenderDialog::SettingsButtonClicked()
|
||||
|
||||
lcSetProfileInt(LC_PROFILE_RENDER_WIDTH, mWidth);
|
||||
lcSetProfileInt(LC_PROFILE_RENDER_HEIGHT, mHeight);
|
||||
lcSetProfileInt(LC_PROFILE_RENDER_QUALITY, static_cast<int>(mQuality));
|
||||
lcSetProfileRenderQuality(mQuality);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user